:root {
  color-scheme: dark;
  --bg: #05070d;
  --bg-gradient: radial-gradient(ellipse 130% 75% at 50% 60%, #1c5fe6 0%, #0e3386 26%, #0a1c46 42%, #050a18 68%, #000000 100%);
  --panel-bg: #1c1c1e;
  --panel-bg-active: #262628;
  --divider: #303032;
  --text: #f5f5f7;
  --text-dim: #a9b6cc;
  --key-bg: #48484c;
  --key-bg-num: #3a3a3d;
  --key-text: #ffffff;
  --op-bg: #ff9f0a;
  --op-text: #1c1c1e;
  --accent: #34c759;
  --danger: #ff453a;

  /* Liquid-glass surfaces: translucent panels/keys that let the background
     glow show through, with a soft light border standing in for a real
     specular highlight. */
  --glass-bg: rgba(150, 180, 230, 0.10);
  /* A lighter, neutral (not blue-tinted) fog for C / ⌫ / ⇅ specifically,
     so they read as a distinct row of "function" keys rather than blending
     in with the digit keys below them. */
  --glass-bg-strong: rgba(255, 255, 255, 0.16);
  --glass-border: rgba(255, 255, 255, 0.22);
  --glass-blur: 20px;
  --text-glow: 0 0 10px rgba(255, 255, 255, 0.55);
  /* Halfway between the original strong glow (10px/55%) and the too-subtle
     follow-up (3px/9%) used just for the big calculator numbers. */
  --amount-glow: 0 0 6.5px rgba(255, 255, 255, 0.32);

  /* Subtle top-to-bottom sheen for the operator column — one gradient
     spread across the whole ÷ × − + = column, not repeated per key. */
  --op-column-gradient: linear-gradient(180deg, #ffcf5c 0%, #ff9f0a 50%, #e8790a 100%);
  --op-glow: 0 0 18px rgba(255, 159, 10, 0.45);

  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

html, body {
  margin: 0;
  height: 100%;
  /* Same gradient as .app (not the flat --bg): if .app's height ever comes
     up even a pixel short of the real screen — an iOS standalone-mode
     quirk we've hit before — this shows through at the edges instead of a
     jarring plain-dark seam. */
  background: var(--bg-gradient);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overscroll-behavior: none;
  user-select: none;
  touch-action: manipulation;
}

/* Belt-and-braces: WebKit has had bugs where touch-action set only via the
   universal selector doesn't reliably propagate through flex/grid
   containers (our .app, .panel, and .keypad are all flex/grid). Setting it
   again directly on every actually-interactive element removes any doubt. */
button, input, a, .app, .panel, .panel-currency, .key, .icon-btn {
  touch-action: manipulation;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  /* No top padding here — .header-bar (now the first child) handles the
     safe-top inset itself, since it needs to sit right at the screen edge
     under the status bar rather than have empty .app padding above it. */
  padding-bottom: var(--safe-bottom);
  background: var(--bg-gradient);
  /* In a regular browser tab (no safe-top inset), the gap above the header
     text works out to ~19.75px — header-bar's 10px padding-top plus ~9.75px
     of centering slack, since the row's height is set by the 36px icon
     buttons rather than the shorter rate-line text. That's bigger than the
     10px gap between keypad buttons, so the whole app reads top-heavy. A
     plain transform (not a resize/scale) shifts the header+panels+keypad
     block up by that same 9.75px, closing the top gap to match the 10px
     button rhythm and letting the freed space collect at the bottom
     instead — the background is unaffected since html/body paint the same
     --bg-gradient behind it, and that gradient is already solid dark at
     the very bottom, so the sliver this reveals is seamless. */
  transform: translateY(-9.75px);
}

/* Current iOS Safari has an active, unresolved regression where 100dvh
   under-reports height specifically in standalone (home-screen) mode,
   leaving a gap at the bottom — see
   https://developer.apple.com/forums/thread/803987. Standalone mode has no
   browser toolbar to begin with, so there's nothing for dvh to be "more
   correct" about there anyway: falling back to plain vh only in this mode
   sidesteps the bug without touching normal browser-tab behavior. */
@media (display-mode: standalone) {
  .app {
    height: 100vh;
    /* The translateY(-9.75px) above is kept here too, not cancelled: the
       9.75px it removes is fixed text-centering slack inside header-bar's
       row, not part of the safe-top inset itself (that's the separate
       "+ var(--safe-top)" term in header-bar's padding-top). So this still
       lands exactly 10px below the safe-area boundary here, same rhythm as
       the plain-10px gap it produces in a regular browser tab — it never
       reaches back up into the actual status-bar area. */
  }
}

.panel {
  width: auto;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  /* 5px top + 5px bottom = a 10px gap between the two panels, matching the
     10px gap between keypad buttons — same rhythm throughout. The first
     panel's own top margin is pulled up separately below to match that
     same 10px gap under the header (its text sits vertically centered in
     a row tall enough for the icon buttons, so naturally leaves more
     space below it than a plain 5px margin would close on its own). */
  margin: 5px 12px;
  border-radius: 24px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  -webkit-backdrop-filter: blur(var(--glass-blur));
  backdrop-filter: blur(var(--glass-blur));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), 0 8px 24px rgba(0, 0, 0, 0.35);
  color: var(--text);
  font: inherit;
  text-align: left;
}

#panelFrom {
  margin-top: 0.25px; /* closes the gap to exactly 10px — see .panel comment above */
}

.panel-currency {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  padding: 8px 10px;
  border-radius: 12px;
}

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

.flag {
  font-size: 34px;
  line-height: 1;
  filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.25));
}

.code {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text);
  text-shadow: var(--text-glow);
}

.panel-amount {
  font-size: clamp(32px, 11vw, 52px);
  font-weight: 500;
  letter-spacing: -0.01em;
  text-align: right;
  flex: 1;
  min-width: 0;
  /* app.js drives the actual sizing: it shrinks font-size to keep this on
     one line for as long as possible, only wrapping to a 2nd line once
     even the smallest readable size can't fit it on one — then caps
     max-height there and scrolls to the bottom, so only the oldest
     (topmost) line gets hidden while what you're currently typing stays
     in view. */
  overflow-y: hidden;
  overflow-wrap: anywhere;
  white-space: normal;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  text-shadow: var(--amount-glow);
}

/* The two panels are now separate floating glass cards with their own
   spacing/border, so the hairline that used to sit between them isn't
   needed any more. */
.divider {
  display: none;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: 1fr;
  flex: 0 0 52%;
  gap: 10px;
  /* +5px top so the gap above the keypad matches the panel's own 5px
     bottom margin, keeping the same 10px rhythm as everywhere else. */
  padding: 5px 12px 10px;
  background: transparent;
}

.key {
  appearance: none;
  border: 1px solid var(--glass-border);
  border-radius: 18px;
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(var(--glass-blur));
  backdrop-filter: blur(var(--glass-blur));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), 0 4px 14px rgba(0, 0, 0, 0.3);
  color: var(--key-text);
  font-size: clamp(20px, 6vw, 28px);
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  text-shadow: var(--text-glow);
}

.key.fn {
  background: var(--glass-bg-strong);
  font-size: clamp(16px, 5vw, 22px);
}

/* The operator column (÷ × − + =) shares ONE gradient stretched over all
   five keys, rather than each key repeating its own copy: the image is
   sized to 5x the height of one key, and each key is scrolled to its own
   1/5 slice via background-position, so the shading flows continuously
   from ÷ at the top down to = at the bottom. */
.key.op {
  background-image: var(--op-column-gradient);
  background-repeat: no-repeat;
  background-size: 100% 500%;
  border-color: rgba(255, 200, 120, 0.5);
  box-shadow: var(--op-glow), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  color: var(--op-text);
  font-weight: 600;
  text-shadow: 0 0 10px rgba(255, 200, 100, 0.7);
}

.keypad > .key.op:nth-child(4)  { background-position-y: 0%; }   /* ÷ */
.keypad > .key.op:nth-child(8)  { background-position-y: 25%; }  /* × */
.keypad > .key.op:nth-child(12) { background-position-y: 50%; }  /* − */
.keypad > .key.op:nth-child(16) { background-position-y: 75%; }  /* + */
.keypad > .key.op:nth-child(20) { background-position-y: 100%; } /* = */

.key:active, .icon-btn:active {
  filter: brightness(1.25);
}

.header-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(10px + var(--safe-top)) 16px 0;
  background: transparent;
}

.header-info {
  flex: 1;
  text-align: center;
  min-width: 0;
}

.rate-line {
  font-size: 14px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: var(--text-glow);
}

.icon-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-dim);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
}

/* ---------- Bottom sheet ---------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 50;
}

.sheet-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.sheet {
  width: 100%;
  max-width: 480px;
  /* Fixed height (not max-height): the search box sits right near the top,
     and if the sheet shrank to fit fewer filtered results — since the
     whole thing is bottom-anchored — that box would visibly drift downward
     as you type, eventually sliding under the keyboard. A fixed height
     keeps the search box locked in place; the results list just scrolls
     (or shows blank space) beneath it instead. */
  height: 70vh;
  background: rgba(8, 14, 28, 0.82);
  border: 1px solid var(--glass-border);
  border-bottom: none;
  -webkit-backdrop-filter: blur(var(--glass-blur));
  backdrop-filter: blur(var(--glass-blur));
  border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(16px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.25s ease;
}

.sheet-backdrop.open .sheet {
  transform: translateY(0);
}

.sheet-search {
  appearance: none;
  border: none;
  border-radius: 10px;
  background: var(--key-bg-num);
  color: var(--text);
  font-size: 16px;
  padding: 10px 12px;
  margin-bottom: 8px;
  flex-shrink: 0;
  user-select: text;
}

.sheet-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.sheet-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--divider);
  cursor: pointer;
}

.sheet-item .flag { font-size: 26px; }

.sheet-item .item-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sheet-item .item-code { font-weight: 600; font-size: 15px; }
.sheet-item .item-name {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sheet-item.selected { background: rgba(255,255,255,0.05); }

.sheet-close {
  appearance: none;
  border: none;
  background: var(--key-bg);
  color: var(--text);
  padding: 12px;
  border-radius: 12px;
  font-size: 16px;
  margin-top: 8px;
  cursor: pointer;
}

/* ---------- History graph modal (centered) ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 60;
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.history-modal {
  width: 100%;
  max-width: 420px;
  background: rgba(8, 14, 28, 0.82);
  border: 1px solid var(--glass-border);
  -webkit-backdrop-filter: blur(var(--glass-blur));
  backdrop-filter: blur(var(--glass-blur));
  border-radius: 18px;
  padding: 18px 18px calc(16px + var(--safe-bottom));
  transform: scale(0.94);
  opacity: 0;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.modal-backdrop.open .history-modal {
  transform: scale(1);
  opacity: 1;
}

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

.history-title {
  font-size: 16px;
  font-weight: 600;
}

.modal-close {
  appearance: none;
  border: none;
  background: var(--key-bg);
  color: var(--text);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.range-buttons {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.range-buttons button {
  appearance: none;
  border: none;
  background: var(--key-bg-num);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 0;
  flex: 1;
  min-width: 42px;
  border-radius: 8px;
  cursor: pointer;
}

.range-buttons button.active {
  background: var(--op-bg);
  color: var(--op-text);
}

.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
  min-height: 18px;
}

/* While scrubbing the chart, this row shows the date + value under the
   finger instead of the range label + trend — emphasize it a touch so it
   reads clearly as a live readout. */
.chart-header.reading #chartRangeLabel {
  color: var(--text);
  font-weight: 600;
}

.trend-badge.reading-value {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.trend-badge {
  font-weight: 600;
  font-size: 12px;
}

.trend-badge.up { color: var(--accent); }
.trend-badge.down { color: var(--danger); }
.trend-badge.flat { color: var(--text-dim); }

.chart-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 300 / 140;
  touch-action: none;
}

#chartSvg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}

#crosshairLine {
  stroke: var(--text-dim);
  stroke-width: 1;
  stroke-dasharray: 3 3;
  display: none;
}

#crosshairDot {
  fill: var(--text);
  display: none;
}

.chart-message {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0 20px;
  font-size: 13px;
  color: var(--text-dim);
}

.chart-message.visible { display: flex; }

.chart-hint {
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 8px;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0 10px;
  font-size: 14px;
}

.switch-hint {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--glass-border);
}

.switch {
  position: relative;
  width: 46px;
  height: 28px;
  flex-shrink: 0;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}

.switch-slider {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  transition: background 0.2s ease;
  pointer-events: none;
}

.switch-slider::before {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  left: 2px;
  top: 2px;
  background: #ffffff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  transition: transform 0.2s ease;
}

.switch input:checked + .switch-slider {
  background: var(--accent);
}

.switch input:checked + .switch-slider::before {
  transform: translateX(18px);
}

/* TEMPORARY install-instructions block in the info popup — see the matching
   HTML comment in index.html for removal notes. */
.install-guide {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--glass-border);
}

.install-guide-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 10px;
}

.install-step {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 12.5px;
  color: var(--text-dim);
  line-height: 1.5;
  margin-bottom: 10px;
}

.install-step:last-child {
  margin-bottom: 0;
}

.install-step-icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  color: var(--text);
  margin-top: 1px;
}

.install-step strong {
  color: var(--text);
}

/* Small icon dropped inline within the instruction text itself (as
   opposed to .install-step-icon, which sits in the left-hand column). */
.inline-icon {
  display: inline-block;
  width: 13px;
  height: 13px;
  vertical-align: -2px;
  color: var(--text);
}

.data-source {
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 14px;
  line-height: 1.5;
}

.app-version {
  text-align: center;
  font-size: 10px;
  color: var(--text-dim);
  opacity: 0.6;
  margin-top: 6px;
}
