:root {
  --bg: #242424;
  --divider: #343434;
  --grid-line: #2b2b2b;
  --key-util: #4c4c4c;
  --key-util-active: #606060;
  --key-num: #636363;
  --key-num-active: #7a7a7a;
  --key-op: #f39221;
  --key-op-active: #ffa944;
  --search-bg: #363636;
  --search-ph: #7a7a7a;
  --gold: #e2be68;
  --muted: #8e8e93;
  --mint: #48bd9c;
  --amber: #ebb348;
  --text: #f2f2f2;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
}

.app {
  position: relative;
  width: 100%;
  max-width: 480px;
  height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
  overflow: hidden;
}

.main-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* Top two currency rows */
.display-section {
  flex: 0 0 30%;
  min-height: 196px;
  display: flex;
  flex-direction: column;
}

.currency-row {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 18px;
  min-height: 0;
}

.row-divider {
  height: 1px;
  background: var(--divider);
  flex-shrink: 0;
}

.currency-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 56px;
  padding: 2px;
  background: none;
  border: 0;
  color: var(--text);
  cursor: pointer;
}

.flag-circle {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 46px;
  line-height: 1;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 0 0 0.5px rgba(255, 255, 255, 0.14);
}

.currency-code {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.amount-btn {
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  background: none;
  border: 0;
  padding: 0;
  color: rgba(242, 242, 242, 0.92);
  cursor: pointer;
  text-align: right;
}

.amount-btn.active {
  color: #ffffff;
}

.amount-text {
  font-size: clamp(24px, 9.5vw, 42px);
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 4x5 Calculator Keypad */
.keypad {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: 1px;
  background: var(--grid-line);
}

.key {
  border: 0;
  margin: 0;
  padding: 0;
  color: #ffffff;
  font-family: var(--font);
  font-size: 30px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 70ms ease-out;
}

.key-util {
  background: var(--key-util);
  font-size: 28px;
}
.key-util:active { background: var(--key-util-active); }

.key-num {
  background: var(--key-num);
}
.key-num:active { background: var(--key-num-active); }

.key-op {
  background: var(--key-op);
  font-size: 34px;
}
.key-op:active { background: var(--key-op-active); }
.key-op.selected {
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.45);
}

.key-icon {
  width: 26px;
  height: 26px;
}

/* Bottom Bar */
.bottom-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg);
}

.bar-btn {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 0;
  color: #ffffff;
  cursor: pointer;
  padding: 0;
}

.bar-icon {
  width: 24px;
  height: 24px;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2.2px solid rgba(255, 255, 255, 0.28);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.rate-status {
  text-align: center;
  line-height: 1.25;
}

.rate-line {
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.freshness-line {
  margin-top: 3px;
  font-size: 15px;
  font-weight: 500;
  color: var(--mint);
}

.freshness-line.fallback {
  color: var(--amber);
}

/* Currencies Picker (image1.jpeg) */
.picker-view {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.picker-view[hidden] {
  display: none;
}

.picker-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 52px;
  padding: 0 12px;
  flex-shrink: 0;
}

.back-btn {
  position: absolute;
  left: 10px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  background: none;
  border: 0;
  color: var(--gold);
  cursor: pointer;
  padding: 0 4px;
}

.back-icon {
  width: 26px;
  height: 26px;
}

.picker-title {
  margin: 0;
  font-size: 19px;
  font-weight: 600;
  color: var(--text);
}

.search-wrap {
  position: relative;
  margin: 4px 16px 12px;
  flex-shrink: 0;
}

.search-input {
  width: 100%;
  height: 44px;
  padding: 0 38px 0 16px;
  border: 0;
  border-radius: 12px;
  background: var(--search-bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 18px;
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}

.search-input::placeholder {
  color: var(--search-ph);
}

.search-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 0;
  background: rgba(255, 255, 255, 0.16);
  color: var(--text);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}

.currency-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 24px;
}

.currency-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  background: none;
  border: 0;
  color: var(--text);
  font-family: var(--font);
  text-align: left;
  cursor: pointer;
}

.currency-item:active {
  background: rgba(255, 255, 255, 0.06);
}

.currency-item .flag-circle {
  width: 42px;
  height: 42px;
  font-size: 42px;
  flex-shrink: 0;
}

.currency-name {
  flex: 1;
  font-size: 19px;
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.currency-item-code {
  font-size: 16px;
  font-weight: 600;
  color: var(--muted);
  flex-shrink: 0;
}

.currency-item-code.pinned {
  color: var(--gold);
}

/* Info Sheet */
.sheet-backdrop {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet-backdrop[hidden] {
  display: none;
}

.sheet {
  width: 100%;
  background: #1c1c1e;
  border-radius: 20px 20px 0 0;
  padding: 16px 16px calc(24px + env(safe-area-inset-bottom, 0px));
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.sheet-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.sheet-done {
  background: none;
  border: 0;
  color: var(--gold);
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
}

.sheet-card {
  background: #2c2c2e;
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 18px;
}

.sheet-row {
  display: flex;
  justify-content: space-between;
  padding: 12px 14px;
  font-size: 15px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sheet-val {
  color: var(--muted);
}

.sheet-action {
  width: 100%;
  padding: 13px 14px;
  background: none;
  border: 0;
  color: #4da3ff;
  font-size: 15px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}

.sheet-label {
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 8px 6px;
  letter-spacing: 0.04em;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 3px;
  background: #2c2c2e;
  border-radius: 10px;
}

.seg-btn {
  padding: 9px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
}

.seg-btn.active {
  background: #48484a;
}
