/* ============================================================
   Ratewave — currency converter
   Dark is the primary look (money screens are dark & warm).
   Light mode is cool banknote paper, not cream.
   ============================================================ */

/* ---- Dark tokens (default) ---- */
:root {
  --ink:        #0E1A1C;   /* deep vault teal, not black */
  --surface:    #14262A;
  --surface-2:  #1B3236;
  --line:       #2A464C;
  --line-soft:  #21393E;

  --text:       #EAF2EE;   /* warm banknote white */
  --text-dim:   #9DB6B0;
  --text-faint: #6E8983;

  --gold:       #C9A96A;   /* brass / coin — hairlines, wordmark */
  --gold-dim:   #8f7a4d;

  --up:         #4ED8A0;   /* market up */
  --up-soft:    rgba(78,216,160,0.14);
  --down:       #EF6461;   /* market down */
  --down-soft:  rgba(239,100,97,0.14);

  --focus:      #7FD9C0;

  --shadow:     0 18px 50px -24px rgba(0,0,0,0.7);
  --radius:     18px;
  --radius-sm:  11px;

  --font-ui: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-display: 'Fraunces', 'Iowan Old Style', Georgia, serif;

  color-scheme: dark;
}

/* ---- Light tokens ---- */
:root[data-theme="light"] {
  --ink:        #EDF1EF;   /* cool paper */
  --surface:    #FBFCFB;
  --surface-2:  #FFFFFF;
  --line:       #D3DEDA;
  --line-soft:  #E2E9E6;

  --text:       #12262A;
  --text-dim:   #4C6560;
  --text-faint: #7B928D;

  --gold:       #9A7B39;
  --gold-dim:   #b9a06a;

  --up:         #12996B;
  --up-soft:    rgba(18,153,107,0.12);
  --down:       #CE4A45;
  --down-soft:  rgba(206,74,69,0.12);

  --focus:      #147a5c;

  --shadow:     0 18px 44px -26px rgba(20,50,54,0.35);
  color-scheme: light;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--ink);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  position: relative;
  overflow-x: hidden;
}

a { color: inherit; }

/* Guilloché — faint engraved banknote lines behind the hero */
.guilloche {
  position: fixed;
  top: -20vh; left: 50%;
  width: 140vmax; height: 90vh;
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 0;
  opacity: 0.5;
  background:
    repeating-radial-gradient(circle at 50% 22%,
      transparent 0, transparent 26px,
      color-mix(in srgb, var(--gold) 22%, transparent) 26px,
      color-mix(in srgb, var(--gold) 22%, transparent) 27px,
      transparent 27px, transparent 54px);
  -webkit-mask-image: radial-gradient(circle at 50% 22%, #000 0%, transparent 62%);
          mask-image: radial-gradient(circle at 50% 22%, #000 0%, transparent 62%);
}
:root[data-theme="light"] .guilloche { opacity: 0.32; }

/* ---- Layout ---- */
.wrap {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 940px;
  margin: 0 auto;
  padding: 8px 22px 60px;
}

.topbar {
  position: relative;
  z-index: 2;
  max-width: 940px;
  margin: 0 auto;
  padding: 20px 22px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  color: var(--text);
}
.brand-mark { color: var(--gold); flex: none; }
.brand-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 22px;
  letter-spacing: 0.2px;
}
.topbar-right { display: inline-flex; align-items: center; gap: 14px; }
.rate-date {
  font-size: 13px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.theme-toggle {
  display: inline-grid;
  place-items: center;
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-dim);
  cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
}
.theme-toggle:hover { color: var(--text); border-color: var(--gold-dim); }
.theme-toggle .i-sun { display: none; }
:root[data-theme="light"] .theme-toggle .i-sun  { display: block; }
:root[data-theme="light"] .theme-toggle .i-moon { display: none; }

/* ---- Hero / converter ---- */
.hero { padding-top: 26px; text-align: center; }
.hero-kicker {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(24px, 5vw, 38px);
  line-height: 1.08;
  letter-spacing: -0.4px;
  margin: 0 0 26px;
}

.converter {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: stretch;
  gap: 14px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}
.field { display: flex; flex-direction: column; gap: 9px; min-width: 0; }
.field-label {
  font-size: 12.5px;
  color: var(--text-dim);
  font-weight: 500;
}
.field-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--ink);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  min-height: 64px;
  transition: border-color .15s;
}
.field-row:focus-within { border-color: var(--gold-dim); }
.field-sub { font-size: 12.5px; color: var(--text-faint); padding-left: 2px; min-height: 1em; }

.ccy-picker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  padding: 4px 4px;
  border-radius: 8px;
  flex: none;
}
.ccy-picker:hover { background: color-mix(in srgb, var(--text) 7%, transparent); }
.ccy-flag {
  width: 26px; height: 20px;
  object-fit: cover;
  border-radius: 3px;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.18) inset;
  background: var(--surface-2);
  flex: none;
}
.ccy-code {
  font-weight: 600;
  font-size: 16px;
  letter-spacing: 0.3px;
}
.chev { color: var(--text-faint); flex: none; }

.amount-input {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(22px, 4.5vw, 30px);
  text-align: right;
  font-variant-numeric: tabular-nums;
  outline: none;
  padding: 0;
}
.amount-input::placeholder { color: var(--text-faint); }

.result-amount {
  flex: 1 1 auto;
  min-width: 0;
  text-align: right;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(22px, 4.5vw, 30px);
  color: var(--gold);
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.swap {
  align-self: center;
  display: inline-grid;
  place-items: center;
  width: 46px; height: 46px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text-dim);
  cursor: pointer;
  transition: transform .25s cubic-bezier(.2,.8,.3,1.4), color .15s, border-color .15s;
}
.swap:hover { color: var(--gold); border-color: var(--gold-dim); }
.swap:active { transform: rotate(180deg); }

.rate-line {
  margin: 20px 0 6px;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  min-height: 24px;
}
.rate-quote {
  font-size: 15px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.rate-quote strong { color: var(--text); font-weight: 600; }
.rate-change {
  font-size: 13.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 2px 9px;
  border-radius: 999px;
}
.rate-change.up   { color: var(--up);   background: var(--up-soft); }
.rate-change.down { color: var(--down); background: var(--down-soft); }
.rate-change.flat { color: var(--text-dim); background: color-mix(in srgb, var(--text) 8%, transparent); }

/* Popular pairs */
.pairs {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 18px;
}
.pair-chip {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text-dim);
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
  transition: color .15s, border-color .15s, background .15s;
}
.pair-chip:hover { color: var(--text); border-color: var(--gold-dim); }
.pair-chip.active {
  color: var(--ink);
  background: var(--gold);
  border-color: var(--gold);
}
:root[data-theme="light"] .pair-chip.active { color: #fff; }

/* ---- Panels ---- */
.panel {
  margin-top: 30px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}
.panel-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 20px;
  margin: 0;
  letter-spacing: -0.2px;
}

.ranges { display: inline-flex; gap: 2px; background: var(--ink); border: 1px solid var(--line-soft); border-radius: 999px; padding: 3px; }
.ranges button {
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
  transition: color .15s, background .15s;
}
.ranges button:hover { color: var(--text); }
.ranges button[aria-selected="true"] {
  color: var(--ink);
  background: var(--gold);
}
:root[data-theme="light"] .ranges button[aria-selected="true"] { color: #fff; }

/* Chart */
.chart-wrap {
  position: relative;
  width: 100%;
  height: 300px;
}
.chart { width: 100%; height: 100%; display: block; overflow: visible; }
.chart-line { fill: none; stroke-width: 2.25; stroke-linecap: round; stroke-linejoin: round; }
.chart-dot { r: 4.5; stroke: var(--surface); stroke-width: 2.5; }
.chart-grid { stroke: var(--line-soft); stroke-width: 1; }
.chart-axislabel { fill: var(--text-faint); font-size: 11px; font-family: var(--font-ui); }
.chart-crosshair { stroke: var(--gold-dim); stroke-width: 1; stroke-dasharray: 3 3; opacity: 0; }
.chart-cursor { r: 4; fill: var(--gold); stroke: var(--surface); stroke-width: 2; opacity: 0; }

.chart-tip {
  position: absolute;
  z-index: 4;
  transform: translate(-50%, -120%);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 7px 10px;
  font-size: 12.5px;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: 0 8px 22px -10px rgba(0,0,0,0.5);
}
.chart-tip .tip-rate { font-weight: 600; font-variant-numeric: tabular-nums; }
.chart-tip .tip-date { color: var(--text-dim); font-size: 11.5px; }

.chart-state {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
  padding: 20px;
}
.chart-state button {
  margin-top: 10px;
  border: 1px solid var(--gold-dim);
  background: transparent;
  color: var(--gold);
  padding: 7px 16px;
  border-radius: 999px;
  font: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer;
}

/* Stats row */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  margin-top: 18px;
  background: var(--line-soft);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.stat {
  background: var(--surface);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.stat-k { font-size: 12px; color: var(--text-faint); }
.stat-v { font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat-v.up { color: var(--up); }
.stat-v.down { color: var(--down); }

/* Majors grid */
.majors-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1px;
  background: var(--line-soft);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.major {
  background: var(--surface);
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 12px 15px;
  cursor: pointer;
  border: 0;
  width: 100%;
  text-align: left;
  color: inherit;
  font: inherit;
  transition: background .15s;
}
.major:hover { background: var(--surface-2); }
.major .ccy-flag { width: 24px; height: 18px; }
.major-code { font-weight: 600; font-size: 14px; }
.major-name { font-size: 12px; color: var(--text-faint); margin-top: 1px; }
.major-mid { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }
.major-name, .major-code { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.major-rate { font-weight: 600; font-size: 15px; font-variant-numeric: tabular-nums; text-align: right; }
.major-rate small { display:block; font-weight: 500; font-size: 11.5px; color: var(--text-faint); }

/* Footer */
.foot {
  position: relative; z-index: 1;
  max-width: 720px;
  margin: 30px auto 0;
  padding: 0 22px 44px;
  text-align: center;
}
.foot p { font-size: 12.5px; color: var(--text-faint); line-height: 1.6; margin: 0; }
.foot a { color: var(--text-dim); text-decoration: underline; text-underline-offset: 2px; }

/* ---- Currency picker sheet ---- */
.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop {
  position: absolute; inset: 0;
  background: rgba(6,14,15,0.55);
  backdrop-filter: blur(2px);
  animation: fade .18s ease;
}
.sheet-panel {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: min(440px, calc(100vw - 32px));
  max-height: min(560px, calc(100vh - 48px));
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: pop .2s cubic-bezier(.2,.8,.3,1.2);
}
.sheet-head { display: flex; gap: 8px; padding: 14px; border-bottom: 1px solid var(--line-soft); }
.sheet-search {
  flex: 1 1 auto;
  background: var(--ink);
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
  font: inherit;
  outline: none;
}
.sheet-search:focus { border-color: var(--gold-dim); }
.sheet-close {
  flex: none;
  width: 40px; border-radius: 10px;
  border: 1px solid var(--line-soft);
  background: transparent; color: var(--text-dim);
  cursor: pointer; font-size: 15px;
}
.sheet-close:hover { color: var(--text); }
.sheet-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; }
.sheet-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
}
.sheet-item:hover, .sheet-item.hi { background: var(--surface-2); }
.sheet-item[aria-selected="true"] { outline: 1px solid var(--gold-dim); }
.sheet-item .ccy-flag { width: 26px; height: 20px; }
.sheet-item .si-code { font-weight: 600; font-size: 14px; width: 42px; flex: none; }
.sheet-item .si-name { font-size: 13px; color: var(--text-dim); }

@keyframes fade { from { opacity: 0; } }
@keyframes pop  { from { opacity: 0; transform: translate(-50%, -46%) scale(.97); } }

/* Focus visibility */
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }

.loading { opacity: .5; }

/* ---- Responsive ---- */
@media (max-width: 620px) {
  .converter {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 16px;
  }
  .swap {
    justify-self: center;
    transform: rotate(90deg);
    margin: -2px 0;
  }
  .swap:active { transform: rotate(270deg); }
  .amount-input, .result-amount { font-size: 26px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .majors-grid { grid-template-columns: 1fr; }
  .panel, .converter { border-radius: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
