/* ────────────────────────────────────────────────────────────
   PARITY — a precision instrument for money.
   Braun ET66 energy: graphite body, sculpted keys, one amber
   accent, LCD digits behind recessed glass.
   ──────────────────────────────────────────────────────────── */

:root {
  --bg:          #101113;
  --body:        #232528;
  --body-edge:   #2e3134;
  --panel:       #1a1c1e;
  --lcd:         #0d0f0d;
  --lcd-glow:    #f5b94e;
  --lcd-dim:     #8a7a55;
  --amber:       #f0a73c;
  --amber-hot:   #ffc25e;
  --oxide:       #a03f35;
  --oxide-hot:   #c05246;
  --key:         #3a3d42;
  --key-hi:      #46494f;
  --key-steel:   #56595f;
  --ink:         #e8e6e0;
  --ink-dim:     #9a9890;
  --ink-faint:   #5d5c57;
  --green:       #76c893;
  --red:         #e07a6b;
  --radius:      26px;
  --font-ui:     "Archivo", system-ui, sans-serif;
  --font-mono:   "Chivo Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font-ui);
  background:
    radial-gradient(120% 90% at 50% 0%, #1a1c20 0%, var(--bg) 55%, #0a0b0c 100%);
  color: var(--ink);
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 24px 12px;
  -webkit-font-smoothing: antialiased;
}

/* film grain over everything, very low */
body::before {
  content: "";
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 50;
  opacity: .05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ── the device ─────────────────────────────────────────── */

.device {
  width: min(420px, 100%);
  height: min(880px, 100dvh - 24px);
  display: flex;
  flex-direction: column;
  background: linear-gradient(178deg, var(--body-edge) 0%, var(--body) 8%, #1f2124 100%);
  border-radius: var(--radius);
  border: 1px solid #3a3d41;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.07),
    0 2px 6px rgba(0,0,0,.5),
    0 24px 60px -12px rgba(0,0,0,.75);
  overflow: hidden;
  animation: device-in .6s cubic-bezier(.2,.9,.25,1) both;
}

@keyframes device-in {
  from { opacity: 0; transform: translateY(14px) scale(.985); }
}

/* ── status bar ─────────────────────────────────────────── */

.statusbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 18px 9px;
  background: #0b0c0d;
  border-bottom: 1px solid #000;
  box-shadow: inset 0 -1px 0 rgba(255,255,255,.04);
  font-family: var(--font-mono);
  font-size: 12.5px;
  letter-spacing: .06em;
}

.statusbar__pair { color: var(--lcd-glow); text-shadow: 0 0 12px rgba(245,185,78,.35); }

.statusbar__meta {
  display: flex; align-items: center; gap: 7px;
  color: var(--ink-faint);
  font-size: 10.5px;
  text-transform: uppercase;
}

.dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
}

.installbtn {
  margin-left: 4px;
  padding: 3px 8px;
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: .14em;
  color: var(--amber);
  background: rgba(240,167,60,.08);
  border: 1px solid rgba(240,167,60,.35);
  border-radius: 6px;
  cursor: pointer;
}
.installbtn:hover { background: rgba(240,167,60,.2); }
.installbtn:active { transform: translateY(1px); }

.hint__steps {
  margin: 4px 0 6px 22px;
  display: flex;
  flex-direction: column;
  gap: 11px;
  font-size: 14.5px;
  line-height: 1.45;
  color: var(--ink);
}
.hint__steps li::marker { color: var(--amber); font-weight: 700; }
.dot.is-err { background: var(--red); box-shadow: 0 0 8px var(--red); }

@keyframes pulse { 50% { opacity: .35; } }

/* ── search bar ─────────────────────────────────────────── */

.searchbar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 14px 4px;
  padding: 0 14px;
  height: 46px;
  background: linear-gradient(180deg, #141517, #1b1d1f);
  border: 1px solid #0a0a0b;
  border-radius: 13px;
  box-shadow: inset 0 2px 6px rgba(0,0,0,.55), 0 1px 0 rgba(255,255,255,.05);
}

.searchbar:focus-within { border-color: #4a3c20; box-shadow: inset 0 2px 6px rgba(0,0,0,.55), 0 0 0 3px rgba(240,167,60,.13); }

.searchbar__icon { width: 16px; height: 16px; color: var(--ink-faint); flex: none; }

.searchbar input {
  flex: 1;
  height: 100%;
  background: none;
  border: none;
  outline: none;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  letter-spacing: .01em;
}
.searchbar input::placeholder { color: var(--ink-faint); }
.searchbar input[readonly] { cursor: pointer; }

.results__item {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 9px 10px;
  background: none;
  border: none;
  border-radius: 9px;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}
.results__item:hover, .results__item.is-hot { background: rgba(240,167,60,.1); }
.results__item .code { font-family: var(--font-mono); font-weight: 600; font-size: 13px; width: 44px; flex: none; }
.results__item .name { color: var(--ink-dim); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.results__item .add  { color: var(--amber); font-weight: 700; font-size: 16px; }
.results__item.is-saved { opacity: .45; }
.results__item.is-saved .add { color: var(--green); }
.results__empty { padding: 14px; color: var(--ink-faint); font-size: 13px; text-align: center; }

/* ── currency rows ──────────────────────────────────────── */

.rows {
  flex: 1;
  overflow-y: auto;
  padding: 8px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scrollbar-width: thin;
  scrollbar-color: #3a3d42 transparent;
}

.row {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 10px 8px 12px;
  border-radius: 15px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: border-color .18s, background .18s;
}

/* entrance animation only on first paint / newly added rows —
   re-renders must never replay it (it reads as flicker) */
.rows--anim .row {
  animation: row-in .45s cubic-bezier(.2,.9,.3,1) both;
  animation-delay: calc(var(--i) * 55ms);
}
.row--new { animation: row-in .35s cubic-bezier(.2,.9,.3,1) both; }

@keyframes row-in {
  from { opacity: 0; transform: translateX(-10px); }
}

.row:hover { background: rgba(255,255,255,.025); }

.row.is-active {
  background: linear-gradient(180deg, rgba(240,167,60,.08), rgba(240,167,60,.03));
  border-color: rgba(240,167,60,.28);
}

.row__flag {
  width: 38px; height: 38px;
  flex: none;
  display: grid;
  place-items: center;
  font-size: 23px;
  background: linear-gradient(180deg, #303338, #232528);
  border: 1px solid #44474c;
  border-radius: 50%;
  box-shadow: 0 2px 5px rgba(0,0,0,.4), inset 0 1px 0 rgba(255,255,255,.08);
  user-select: none;
}
.row__flag .mono {
  font-family: var(--font-mono);
  font-size: 15px; font-weight: 700;
  color: var(--amber);
}

.row__id { width: 52px; flex: none; }
.row__code { font-weight: 800; font-size: 15.5px; letter-spacing: .03em; display: block; }
.row__name {
  display: block;
  font-size: 9.5px;
  color: var(--ink-faint);
  letter-spacing: .04em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* the LCD window */
.row__lcd {
  flex: 1;
  min-width: 0;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 12px;
  background:
    linear-gradient(180deg, rgba(255,255,255,.045), transparent 30%),
    var(--lcd);
  border: 1px solid #000;
  border-radius: 10px;
  box-shadow:
    inset 0 3px 9px rgba(0,0,0,.8),
    0 1px 0 rgba(255,255,255,.06);
  font-family: var(--font-mono);
  font-size: 19px;
  font-weight: 500;
  color: var(--lcd-dim);
  overflow: hidden;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.row.is-active .row__lcd {
  color: var(--lcd-glow);
  text-shadow: 0 0 14px rgba(245,185,78,.4);
}

/* solid block cursor marks the input row — deliberately static,
   any blinking here reads as flicker */
.row.is-active .row__lcd::after {
  content: "";
  display: inline-block;
  width: 9px; height: 22px;
  margin-left: 5px;
  background: var(--lcd-glow);
  opacity: .85;
}

.row__lcd.is-overflow { font-size: 15px; }

/* fully-selected value — typing replaces it, terminal-selection style.
   Negative margins cancel the padding so glyphs don't shift. */
.row__lcd.is-sel [data-val] {
  background: var(--lcd-glow);
  color: #221703;
  text-shadow: none;
  padding: 1px 5px;
  margin: 0 -5px;
  border-radius: 4px;
}
.row.is-active .row__lcd.is-sel::after { display: none; }

/* pending arithmetic operator, pinned to the left of the LCD */
.row__lcd-op {
  margin-right: auto;
  padding-right: 8px;
  color: var(--amber);
  opacity: .85;
  font-size: 16px;
  font-weight: 600;
}

/* row buttons */
.row__btns { display: flex; flex-direction: column; gap: 3px; flex: none; }

.iconbtn {
  width: 30px; height: 26px;
  display: grid; place-items: center;
  background: linear-gradient(180deg, var(--key-hi), var(--key));
  border: 1px solid #1c1d1f;
  border-radius: 7px;
  color: var(--ink-dim);
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,.4), inset 0 1px 0 rgba(255,255,255,.09);
  transition: color .15s;
}
.iconbtn:hover { color: var(--amber-hot); }
.iconbtn:active { transform: translateY(1px); box-shadow: 0 0 1px rgba(0,0,0,.4); }
.iconbtn svg { width: 15px; height: 15px; }

/* ── currency manager ───────────────────────────────────── */

.modal__panel--mgr {
  display: flex;
  flex-direction: column;
  max-height: min(640px, 86dvh);
}

.searchbar--mgr { margin: 0 0 12px; flex: none; }

.mgrlist {
  flex: 1;
  min-height: 120px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
  scrollbar-width: thin;
  scrollbar-color: #3a3d42 transparent;
}

.mgr {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 6px 8px 4px;
  border-radius: 10px;
}
.mgr:hover { background: rgba(255,255,255,.03); }

.check {
  width: 22px; height: 22px;
  flex: none;
  display: grid;
  place-items: center;
  background: #17181a;
  border: 1px solid #4a4d52;
  border-radius: 6px;
  color: transparent;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.check::after { content: "✓"; }
.check.is-on {
  background: linear-gradient(180deg, var(--amber-hot), var(--amber));
  border-color: #cc8526;
  color: #2b1c05;
}

.mgr__flag { width: 28px; text-align: center; font-size: 19px; flex: none; user-select: none; }
.mgr__flag .mono { font-family: var(--font-mono); font-weight: 700; font-size: 13px; color: var(--amber); }

.mgr__id { flex: 1; min-width: 0; }
.mgr__id b { display: block; font-size: 14px; letter-spacing: .03em; }
.mgr__id i {
  display: block;
  font-style: normal;
  font-size: 9.5px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--ink-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mgr.is-off .mgr__flag, .mgr.is-off .mgr__id { opacity: .38; }

.mgr__btns { display: flex; gap: 5px; flex: none; }
.mgr__btns .iconbtn { width: 28px; height: 26px; font-size: 9px; }
.mgr__btns .iconbtn:disabled { opacity: .22; pointer-events: none; }
.mgr__rm:hover { color: var(--red); }

/* ── keypad ─────────────────────────────────────────────── */

.keypad {
  flex: none;
  display: grid;
  grid-template-areas:
    "kc kr kb kdiv"
    "k7 k8 k9 kmul"
    "k4 k5 k6 ksub"
    "k1 k2 k3 kadd"
    "ka k0 kd keq";
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: 48px;
  gap: 8px;
  padding: 12px 14px;
  background:
    linear-gradient(180deg, rgba(255,255,255,.04), transparent 12%),
    repeating-linear-gradient(90deg, #26282b 0 2px, #242629 2px 4px),
    #242629;
  border-top: 1px solid #0c0d0e;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.05);
}

.key {
  font-family: var(--font-ui);
  font-size: 21px;
  font-weight: 700;
  color: var(--ink);
  background: linear-gradient(180deg, var(--key-hi) 0%, var(--key) 55%, #313438 100%);
  border: 1px solid #17181a;
  border-radius: 14px;
  cursor: pointer;
  box-shadow:
    0 4px 7px -1px rgba(0,0,0,.55),
    inset 0 1.5px 0 rgba(255,255,255,.13),
    inset 0 -2px 3px rgba(0,0,0,.3);
  transition: transform .06s, box-shadow .06s, filter .15s;
  display: grid;
  place-items: center;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.key:hover { filter: brightness(1.09); }

.key:active, .key.is-pressed {
  transform: translateY(2px);
  box-shadow:
    0 1px 2px rgba(0,0,0,.5),
    inset 0 1px 0 rgba(255,255,255,.07),
    inset 0 2px 5px rgba(0,0,0,.35);
}

.key svg { width: 21px; height: 21px; }

.key--steel { background: linear-gradient(180deg, #63666c 0%, var(--key-steel) 55%, #44474c 100%); }

.key--danger {
  background: linear-gradient(180deg, var(--oxide-hot) 0%, var(--oxide) 60%, #82332b 100%);
  color: #ffe9e4;
  text-shadow: 0 1px 2px rgba(0,0,0,.35);
}

/* the hero key — equals, like the ET66's big yellow one */
.key--accent {
  background:
    radial-gradient(120% 90% at 50% 0%, var(--amber-hot) 0%, var(--amber) 45%, #cc8526 100%);
  color: #2b1c05;
  font-size: 27px;
  font-weight: 800;
}

/* arithmetic operators — recessed dark keys with amber glyphs */
.key--op {
  background: linear-gradient(180deg, #303236 0%, #26282b 60%, #202225 100%);
  border-color: #101113;
  color: var(--amber);
  font-size: 24px;
  font-weight: 500;
}

/* add-currency shortcut */
.key--cur {
  background: linear-gradient(180deg, #303236 0%, #26282b 60%, #202225 100%);
  border-color: #101113;
  color: var(--amber);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
}
.key--cur__plus { font-size: 21px; line-height: 1; font-weight: 800; }
.key--cur__label { font-size: 8px; font-weight: 700; letter-spacing: .16em; opacity: .6; }

/* ── engraving ──────────────────────────────────────────── */

.engraving {
  flex: none;
  padding: 7px 0 9px;
  background: #1d1f21;
  text-align: center;
  font-size: 8px;
  letter-spacing: .3em;
  color: #55585c;
  text-shadow: 0 1px 0 rgba(0,0,0,.6);
  border-top: 1px solid #141517;
}

/* ── graph modal ────────────────────────────────────────── */

.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px; }
.modal[hidden] { display: none; }

.modal__scrim {
  position: absolute; inset: 0;
  background: rgba(5,5,6,.72);
  backdrop-filter: blur(6px);
  animation: fade .25s both;
}
@keyframes fade { from { opacity: 0; } }

.modal__panel {
  position: relative;
  width: min(460px, 100%);
  background: linear-gradient(178deg, var(--body-edge), #1e2023 90%);
  border: 1px solid #3c3f44;
  border-radius: 20px;
  padding: 20px;
  box-shadow: 0 30px 80px -10px rgba(0,0,0,.9), inset 0 1px 0 rgba(255,255,255,.07);
  animation: panel-in .32s cubic-bezier(.2,.9,.3,1.1) both;
}
@keyframes panel-in { from { opacity: 0; transform: translateY(16px) scale(.96); } }

.modal__head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 14px; }
.modal__title { font-size: 19px; font-weight: 800; letter-spacing: .02em; }
.modal__title .arrow { color: var(--amber); }
.modal__sub { font-family: var(--font-mono); font-size: 12px; color: var(--ink-dim); margin-top: 3px; }

.modal__close {
  width: 32px; height: 32px;
  background: linear-gradient(180deg, var(--key-hi), var(--key));
  border: 1px solid #17181a;
  border-radius: 9px;
  color: var(--ink-dim);
  font-size: 19px;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0,0,0,.4), inset 0 1px 0 rgba(255,255,255,.1);
}
.modal__close:hover { color: var(--ink); }
.modal__close:active { transform: translateY(1px); }

.ranges { display: flex; gap: 7px; margin-bottom: 13px; }

.range {
  flex: 1;
  padding: 7px 0;
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .1em;
  color: var(--ink-dim);
  background: #1a1c1e;
  border: 1px solid #2c2e31;
  border-radius: 9px;
  cursor: pointer;
  transition: all .15s;
}
.range:hover { color: var(--ink); }
.range.is-on {
  color: #2b1c05;
  background: linear-gradient(180deg, var(--amber-hot), var(--amber));
  border-color: #cc8526;
  font-weight: 700;
}

.chartwrap {
  position: relative;
  height: 240px;
  background:
    linear-gradient(180deg, rgba(255,255,255,.04), transparent 25%),
    var(--lcd);
  border: 1px solid #000;
  border-radius: 13px;
  box-shadow: inset 0 3px 10px rgba(0,0,0,.8);
  overflow: hidden;
}

#chart {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  touch-action: none; /* let touch-drag scrub the crosshair, not scroll */
}

.chartwrap__loading {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: .25em;
  color: var(--lcd-dim);
  background: var(--lcd);
  animation: pulse 1.2s ease-in-out infinite;
}
.chartwrap__loading[hidden] { display: none; }

.modal__stats {
  display: flex;
  justify-content: space-between;
  margin-top: 13px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-dim);
}
.modal__stats b { color: var(--ink-faint); font-size: 9.5px; letter-spacing: .15em; margin-right: 5px; }
.modal__stats .up { color: var(--green); }
.modal__stats .down { color: var(--red); }

/* ── small screens: fill the viewport, drop the bezel ──── */

@media (max-width: 460px) {
  body { padding: 0; }
  .device { height: 100dvh; border-radius: 0; border: none; }
  /* installed-PWA mode: keep content clear of the notch / home bar */
  .statusbar { padding-top: calc(10px + env(safe-area-inset-top)); }
  .engraving { padding-bottom: calc(9px + env(safe-area-inset-bottom)); }
}

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

:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
