/* TENFOUR pad — identity v3: the Aurora skin.

   The pad wears the same design language as the in-game alert card
   (web/src/variations/V1Aurora.css, tokens from nn_policejob/DESIGN.md):
   smoked near-opaque panels on a blued near-black chassis, a 1px specular
   ring catching light from the top-left, and ONE hue per surface carrying
   its priority — red alarms, amber cautions, patrol blue acts, grey informs.
   Signal yellow stays the product's own colour: it marks TENFOUR itself,
   never an action.

   Type: Chakra Petch for the console, Rajdhani for reading, JetBrains Mono
   for codes, timestamps and anything a radio says.

   Themes are custom-property sets on :root, swapped by [data-theme]. The
   chassis is shared; a trade swaps the accent and the glow. The game server
   picks with Config.Link.Brand.theme and may still override the single
   action colour with Brand.accent.

   No chrome bar — the unit strip at the top carries identity, connection,
   clock and the two toggles. One column on a phone; at 720px the dispatch
   board docks under the console; at 960px it docks on the right. */

/* ── chassis ───────────────────────────────────────────────────────────── */
:root {
  --ink: #f2f5fb;
  --sec: #8ea0c0;
  --dim: rgba(234, 240, 250, 0.32);
  --line: rgba(255, 255, 255, 0.1);
  --line-hi: rgba(255, 255, 255, 0.16);
  --signal: #ffd23f;               /* the product colour — the pulse on the mark */
  --red: #fa4039;
  --red-deep: #d63029;
  --red-edge: #7d1a20;
  --amber: #ffc24b;
  --green: #34ff93;
  --display: 'Chakra Petch', 'Rajdhani', system-ui, sans-serif;
  --body: 'Rajdhani', system-ui, sans-serif;
  --mono: 'JetBrains Mono', Consolas, monospace;
  --r: 13px;
  --r-sm: 8px;
  --pad-x: 16px;

  /* the Aurora edge: a 1px ring catching light at 145deg, punched hollow */
  --spec-a: rgba(186, 208, 255, 0.5);
  --spec-b: rgba(80, 132, 255, 0.3);
}

/* priority — one hue per rung, it moves chip, wash and lamp at once */
.p0 { --pri: var(--red);    --pri-ink: #ffb3b0; --pri-fill: rgba(250, 64, 57, 0.14); }
.p1 { --pri: var(--amber);  --pri-ink: #ffdd9a; --pri-fill: rgba(255, 194, 75, 0.12); }
.p2 { --pri: var(--accent); --pri-ink: var(--accent-hi); --pri-fill: rgba(47, 107, 255, 0.12); }
.p3 { --pri: #7d8aa8;       --pri-ink: #a9b4cc; --pri-fill: rgba(125, 138, 168, 0.1); }

/* ── themes — shared chassis, per-trade accent ─────────────────────────── */
:root, :root[data-theme='police'] {
  --bg: #0a0f1e;
  --bg-2: #0d1426;
  --panel: #101728;
  --panel-hi: #16203a;
  --card: #0a0e1a;
  --glow: rgba(47, 107, 255, 0.16);
  --accent: #2f6bff;
  --accent-mid: #2453c9;
  --accent-deep: #1b3a8f;
  --accent-hi: #6c9bff;

  /* neutral priority defaults — .p0–.p3 on an element override these */
  --pri: var(--dim);
  --pri-ink: var(--sec);
  --pri-fill: transparent;
}
/* EMS wears nn_ems's dispatch housing: cool graphite, device ink, and signal
   cyan as the one colour that acts, so a routine key never reads as the red
   that alarms. The red itself is already nn_ems's #fa4039. */
:root[data-theme='ems'] {
  --ink: #e7edf2;
  --sec: #93a3ad;
  --bg: #0b0d0f;
  --bg-2: #0f1215;
  --panel: #14171a;
  --panel-hi: #1b1f23;
  --card: #0a0c0e;
  --glow: rgba(88, 198, 240, 0.12);
  --accent: #58c6f0;
  --accent-mid: #1f86b3;
  --accent-deep: #0f4a66;
  --accent-hi: #9adcf6;
  --spec-a: rgba(206, 236, 250, 0.45);
  --spec-b: rgba(88, 198, 240, 0.26);
}
:root[data-theme='ems'] .p2 { --pri-fill: rgba(88, 198, 240, 0.12); }
/* signal cyan is a light hue: it carries dark ink, and the button stays light enough to hold it */
:root[data-theme='ems'] .side-tab.active .n { color: #062230; }
:root[data-theme='ems'] .btn.primary {
  color: #062230;
  background: linear-gradient(180deg, #8ad8f6 0%, var(--accent) 55%, #3aa9d9 100%);
}
:root[data-theme='fire'] {
  --glow: rgba(255, 122, 41, 0.15);
  --accent: #ff7a29;
  --accent-mid: #d95f16;
  --accent-deep: #8f3410;
  --accent-hi: #ffa25e;
}
:root[data-theme='mechanic'] {
  --glow: rgba(255, 178, 46, 0.13);
  --accent: #ffb02e;
  --accent-mid: #d98f1b;
  --accent-deep: #7c5a17;
  --accent-hi: #ffcb6e;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
/* The root paints the same ground as the page, so a window taller than the
   layout — Stage Manager, a resized PWA, an overscroll — shows more of the same
   navy and never a strip of something else. */
html { min-height: 100%; background: var(--bg); }
body {
  min-height: 100dvh;
  min-height: 100%;
  background:
    radial-gradient(120% 45% at 50% -10%, var(--glow) 0%, transparent 55%),
    var(--bg);
  color: var(--ink);
  font-family: var(--display);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; touch-action: manipulation; }
input, select { font: inherit; color: inherit; }
svg { display: block; }

.app {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: max(12px, env(safe-area-inset-top)) var(--pad-x) max(16px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* the specular ring, shared by every smoked surface */
.key::before, .call::before, .unit::before, .card::before, .hero::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(
    145deg,
    var(--spec-a) 0%,
    rgba(255, 255, 255, 0.08) 20%,
    rgba(255, 255, 255, 0) 44%,
    rgba(255, 255, 255, 0.05) 68%,
    var(--spec-b) 100%
  );
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  mask-composite: exclude;
  pointer-events: none;
}

/* ── shared controls ───────────────────────────────────────────────────── */
.bar-clock {
  display: none;
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.03em;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  flex: none;
}
.pill {
  flex: none;
  display: flex; align-items: center; gap: 7px;
  height: 37px;
  padding: 0 13px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--sec);
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); }
.pill.on  { color: var(--green); border-color: rgba(52, 255, 147, 0.35); }
.pill.on  .dot { background: var(--green); box-shadow: 0 0 8px var(--green); animation: pulse 2s ease-in-out infinite; }
.pill.off { color: var(--red); border-color: rgba(250, 64, 57, 0.4); }
.pill.off .dot { background: var(--red); box-shadow: 0 0 8px var(--red); animation: blink 1.1s steps(1, end) infinite; }
@keyframes pulse { 0%, 100% { opacity: 1 } 50% { opacity: 0.45 } }
@keyframes blink { 0%, 55% { opacity: 1 } 56%, 100% { opacity: 0.3 } }
.bar-btn {
  flex: none;
  width: 42px; height: 42px;
  display: grid; place-items: center;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--sec);
}
.bar-btn svg { width: 21px; height: 21px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.bar-btn:active { background: var(--panel-hi); color: var(--ink); }
.bar-btn.active { color: var(--accent-hi); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.bar-btn.panel-only { display: none; }

/* ── unit strip — the top row: who you are, connection, the two toggles ── */
.unit {
  position: relative;
  isolation: isolate;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--r);
  background: linear-gradient(180deg, var(--panel-hi) 0%, var(--card) 100%);
  border: 1px solid var(--line);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
.unit-ava {
  flex: none;
  width: 46px; height: 46px;
  display: grid; place-items: center;
  border-radius: 11px;
  background: color-mix(in srgb, var(--accent) 16%, var(--card));
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  color: var(--accent-hi);
}
.unit-ava svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.unit-id { min-width: 0; flex: 1 1 auto; }
.unit-name { font-size: 19px; font-weight: 700; letter-spacing: 0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.unit-line {
  margin-top: 1px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--sec);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.unit-last { text-align: right; display: none; flex-direction: column; align-items: flex-end; gap: 3px; flex: 0 1 auto; min-width: 0; overflow: hidden; }
.unit-last-tx { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
/* the strip measures itself: when the console column is narrow the last
   transmission steps out rather than squeezing the officer's name to "Sina…" */
.unit { container-type: inline-size; }
@container (max-width: 640px) { .unit-last { display: none !important; } }
@container (min-width: 641px) { .unit-id { min-width: 132px; } }
.unit-last-cap { font-family: var(--mono); font-size: 9px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--dim); }
.unit-last-tx { font-size: 15px; font-weight: 700; white-space: nowrap; }
.unit-last-tx small { font-family: var(--mono); font-size: 10.5px; font-weight: 500; color: var(--sec); margin-left: 6px; }

/* ── the panic bar — red is alarm, and nothing else ────────────────────── */
.hero {
  position: relative;
  isolation: isolate;
  min-height: 122px;
  padding: 16px 20px;
  border-radius: var(--r);
  border: 1px solid rgba(255, 150, 158, 0.5);
  background: linear-gradient(180deg, #fb5b54 0%, var(--red) 55%, var(--red-deep) 100%);
  box-shadow: 0 4px 0 var(--red-edge), 0 14px 40px -14px rgba(250, 64, 57, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.3);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 16px;
  text-align: left;
  overflow: hidden;
  transition: transform 80ms ease, box-shadow 80ms ease, filter 120ms ease;
  --p: 0;
}
.hero::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(-45deg, rgba(255, 255, 255, 0.045) 0 16px, transparent 16px 32px);
  pointer-events: none;
}
.hero > * { position: relative; }
.hero:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--red-edge), 0 8px 24px -12px rgba(250, 64, 57, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.3); }
.hero-ico { width: 42px; height: 42px; stroke: #fff; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.hero-txt { flex: 1; min-width: 0; }
.hero-code { font-family: var(--mono); font-size: 12px; font-weight: 700; letter-spacing: 0.18em; opacity: 0.9; }
.hero-label { font-size: 29px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; line-height: 1.02; margin-top: 2px; }
.hero-hint { font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.16em; text-transform: uppercase; opacity: 0.85; margin-top: 5px; }
.hero-ring {
  flex: none;
  width: 54px; height: 54px;
  border-radius: 50%;
  background: conic-gradient(#fff calc(var(--p) * 1%), rgba(255, 255, 255, 0.25) 0);
  -webkit-mask: radial-gradient(circle, transparent 56%, #000 58%);
  mask: radial-gradient(circle, transparent 56%, #000 58%);
}
.hero.holding { filter: brightness(1.08); }
.hero.sent { outline: 3px solid var(--green); outline-offset: -3px; }
.hero.failed { outline: 3px solid #fff; outline-offset: -3px; }
.hero.busy { opacity: 0.6; pointer-events: none; }
.hero[disabled] { opacity: 0.45; pointer-events: none; filter: saturate(0.5); }
.hero.tap .hero-ring { display: none; }

/* ── groups + keys ─────────────────────────────────────────────────────── */
.grp { display: flex; flex-direction: column; gap: 9px; }
.grp-cap {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--sec);
  padding: 2px 2px 0;
}
.grp-cap::before { content: ''; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.grp-cap::after { content: ''; flex: 1; height: 1px; background: var(--line); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(152px, 1fr));
  gap: 10px;
}

/* the last group drinks whatever vertical space is left, so a tall screen
   with few keys is a bigger console, not a dark void */
.body { flex: 1; display: flex; flex-direction: column; }
.maincol { flex: 1; }
.grp:last-child { flex: 1; }
.grp:last-child .grid { flex: 1; grid-auto-rows: minmax(100px, 1fr); }

.key {
  position: relative;
  isolation: isolate;
  min-height: 100px;
  padding: 12px 14px;
  border-radius: var(--r);
  border: 1px solid var(--line);
  background:
    radial-gradient(130% 100% at 0% 0%, var(--pri-fill) 0%, transparent 55%),
    linear-gradient(180deg, var(--panel-hi) 0%, var(--card) 100%);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  text-align: left;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 9px;
  overflow: hidden;
  transition: transform 80ms ease, box-shadow 80ms ease, filter 120ms ease, opacity 160ms ease;
}
.key:active { transform: translateY(3px); box-shadow: 0 0 0 rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.08); filter: brightness(1.15); }
.key-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.key-code {
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--pri-ink);
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
}
.key.p0 .key-code, .key.p1 .key-code, .key.p2 .key-code, .key.p3 .key-code {
  border-color: color-mix(in srgb, var(--pri) 38%, transparent);
  background: color-mix(in srgb, var(--pri) 12%, transparent);
}
.key-ico { width: 22px; height: 22px; stroke: var(--sec); fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.key-label { font-size: 18px; font-weight: 700; line-height: 1.1; letter-spacing: 0.015em; }
.key.busy { opacity: 0.55; pointer-events: none; }
.key.sent { outline: 2px solid var(--green); outline-offset: -2px; }
.key.failed { outline: 2px solid var(--red); outline-offset: -2px; }
.key[disabled] { opacity: 0.38; pointer-events: none; filter: saturate(0.35); }

/* ── the side panel: live calls + this device's log ────────────────────── */
.maincol { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.side { display: none; }

/* ── generic surfaces ──────────────────────────────────────────────────── */
.card {
  position: relative;
  isolation: isolate;
  background: linear-gradient(180deg, var(--panel-hi) 0%, var(--card) 100%);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 16px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
.card h2 {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--sec);
  margin-bottom: 11px;
}
.card p { font-family: var(--body); color: var(--sec); font-size: 17px; font-weight: 500; line-height: 1.45; }
.card p + p { margin-top: 8px; }
.card .title { font-size: 24px; font-weight: 700; color: var(--ink); line-height: 1.1; margin-bottom: 8px; }
.center { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; gap: 14px; padding: 24px var(--pad-x); max-width: 460px; margin: 0 auto; width: 100%; }

/* the brand, where it is the whole point: pairing */
.brandlock {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 13px;
  padding: 14px 0 22px;
}
.brandlock img { width: 110px; height: 110px; object-fit: contain; filter: drop-shadow(0 16px 36px rgba(255, 210, 63, 0.16)); }
.wordmark {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: 0.3em;
  padding-left: 0.3em;               /* optical: cancel the trailing tracking */
  text-transform: uppercase;
  line-height: 1;
}
.wordmark b { color: var(--signal); font-weight: inherit; }
.tagline {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: var(--sec);
}

/* numbered steps on the enter screen */
.steps { display: flex; flex-direction: column; gap: 9px; margin-top: 4px; }
.step { display: flex; align-items: baseline; gap: 10px; font-family: var(--body); font-size: 17px; font-weight: 500; color: var(--sec); line-height: 1.4; }
.step b {
  flex: none;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent-hi);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  border-radius: 6px;
  padding: 1px 6px;
  transform: translateY(-1px);
}
.step code { font-family: var(--mono); color: var(--ink); font-size: 0.85em; }

.row { display: flex; align-items: center; gap: 12px; }
.row + .row { margin-top: 10px; }
.row .grow { flex: 1; min-width: 0; }
.row .meta { font-family: var(--mono); font-size: 11px; color: var(--sec); letter-spacing: 0.05em; margin-top: 2px; }
.row .name { font-size: 16.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .name small { font-weight: 500; color: var(--sec); margin-left: 6px; }

.btn {
  height: 46px;
  padding: 0 18px;
  border-radius: 10px;
  border: 1px solid var(--line-hi);
  background: var(--panel-hi);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.4);
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: transform 80ms ease, box-shadow 80ms ease, filter 120ms ease;
}
.btn svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn:active { transform: translateY(2px); box-shadow: none; filter: brightness(1.15); }
.btn.primary {
  border-color: color-mix(in srgb, var(--accent-hi) 42%, transparent);
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-mid) 55%, var(--accent-deep) 100%);
  color: #fff;
  box-shadow: 0 2px 0 var(--accent-deep), 0 8px 22px -10px var(--accent), inset 0 1px 0 rgba(255, 255, 255, 0.28);
}
.btn.primary:active { box-shadow: 0 0 0 var(--accent-deep), inset 0 1px 0 rgba(255, 255, 255, 0.28); }
.btn.danger { color: #ff8a86; border-color: rgba(250, 64, 57, 0.4); }
.btn.ghost { color: var(--sec); box-shadow: none; background: transparent; }
.btn.block { width: 100%; }
.btn.small { height: 34px; padding: 0 12px; font-size: 10.5px; border-radius: 8px; }

.field {
  width: 100%;
  height: 64px;
  padding: 0 16px;
  border-radius: var(--r);
  border: 1px solid var(--line-hi);
  background: rgba(0, 0, 0, 0.4);
  font-family: var(--mono);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  text-align: center;
  outline: none;
}
.field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.select {
  height: 46px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--line-hi);
  background: var(--panel-hi);
  font-size: 15px;
  font-weight: 600;
}
.url {
  display: block;
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.4);
  font-family: var(--mono);
  font-size: 12px;
  color: var(--sec);
  word-break: break-all;
  -webkit-user-select: all;
  user-select: all;
}
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.14);
  border-top-color: var(--accent-hi);
  animation: spin 900ms linear infinite;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }
.ok { color: var(--green); }
.bad { color: var(--red); }

/* a toggle row in settings */
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.toggle .name { font-size: 16.5px; font-weight: 600; }
.toggle .meta { font-family: var(--mono); font-size: 11px; color: var(--sec); margin-top: 2px; }
.switch {
  flex: none;
  width: 52px; height: 30px;
  border-radius: 999px;
  border: 1px solid var(--line-hi);
  background: var(--card);
  position: relative;
  transition: background 140ms ease, border-color 140ms ease;
}
.switch::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--sec);
  transition: transform 140ms ease, background 140ms ease;
}
.switch.on { background: color-mix(in srgb, var(--accent) 40%, var(--card)); border-color: var(--accent); }
.switch.on::after { transform: translateX(22px); background: var(--accent-hi); }

/* ── the sheet: settings, out of the way until asked for ───────────────── */
.veil {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(4, 6, 12, 0.65);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity 180ms ease;
}
.veil.show { opacity: 1; }
.sheet {
  position: fixed;
  z-index: 21;
  left: 0; right: 0; bottom: 0;
  max-height: 86dvh;
  overflow-y: auto;
  padding: 14px var(--pad-x) max(18px, env(safe-area-inset-bottom));
  border-radius: 18px 18px 0 0;
  background: var(--bg-2);
  border-top: 1px solid var(--line-hi);
  box-shadow: 0 -20px 60px -20px rgba(0, 0, 0, 0.85);
  transform: translateY(100%);
  transition: transform 220ms cubic-bezier(0.2, 0.7, 0.3, 1);
  display: flex; flex-direction: column; gap: 11px;
}
.sheet.show { transform: none; }
.sheet-hd { display: flex; align-items: center; gap: 10px; }
.sheet-hd .title { flex: 1; font-size: 17px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.sheet-grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line-hi); margin: 0 auto 2px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 30;
  transform: translateX(-50%) translateY(20px);
  padding: 11px 17px;
  border-radius: 10px;
  background: var(--panel-hi);
  border: 1px solid var(--line-hi);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.4), 0 12px 32px -10px rgba(0, 0, 0, 0.7);
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  opacity: 0;
  transition: opacity 160ms ease, transform 160ms ease;
  pointer-events: none;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.ok { border-color: rgba(52, 255, 147, 0.45); }
.toast.bad { border-color: rgba(250, 64, 57, 0.55); }

.foot {
  margin-top: auto;
  padding-top: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--dim);
}
.foot img { width: 16px; height: 16px; object-fit: contain; border-radius: 4px; opacity: 0.8; }
.foot b { color: var(--signal); font-weight: 700; }

/* ── shapes of screen ──────────────────────────────────────────────────── */

/* phone on its side: everything shorter, more keys per row */
@media (orientation: landscape) and (max-height: 520px) {
  .app { gap: 8px; padding-top: max(8px, env(safe-area-inset-top)); }
  .bar-clock { font-size: 13px; padding: 5px 9px; }
  .bar-btn { width: 32px; height: 32px; }
  .bar-btn svg { width: 17px; height: 17px; }
  .pill { height: 28px; padding: 0 10px; font-size: 9px; }
  .unit { padding: 7px 11px; gap: 9px; }
  .unit-ava { width: 32px; height: 32px; }
  .unit-ava svg { width: 18px; height: 18px; }
  .unit-name { font-size: 15px; }
  .unit-line { font-size: 9px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(136px, 1fr)); gap: 8px; }
  .key { min-height: 66px; padding: 8px 11px; gap: 6px; }
  .grp:last-child .grid { grid-auto-rows: minmax(66px, 1fr); }
  .key-label { font-size: 15px; }
  .key-ico { width: 18px; height: 18px; }
  .key-code { font-size: 10px; }
  .hero { min-height: 64px; padding: 10px 16px; }
  .hero-label { font-size: 20px; }
  .hero-hint { display: none; }
  .hero-ico { width: 30px; height: 30px; }
  .hero-ring { width: 40px; height: 40px; }
  .app { padding-left: max(var(--pad-x), env(safe-area-inset-left)); padding-right: max(var(--pad-x), env(safe-area-inset-right)); }
}

/* tablets and desktops: roomier, the sheet becomes a drawer */
@media (min-width: 720px) {
  :root { --pad-x: 22px; }
  .bar-clock { display: block; }
  .unit-last { display: flex; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
  .key { min-height: 108px; }
  .key-label { font-size: 19px; }
  .hero { min-height: 130px; }
  .hero-label { font-size: 32px; }
  .hero-ico { width: 48px; height: 48px; }
  .sheet {
    left: auto; top: 0; bottom: 0;
    width: min(440px, 92vw);
    max-height: none;
    border-radius: 18px 0 0 18px;
    border-top: none;
    border-left: 1px solid var(--line-hi);
    padding-top: max(18px, env(safe-area-inset-top));
    transform: translateX(100%);
  }
  .sheet-grab { display: none; }
}

/* tablet portrait: the board docks UNDER the console and fills the rest of
   the screen, so a tall tablet is calls, not oversized keys */
@media (min-width: 720px) and (max-width: 959px) {
  .grp:last-child { flex: none; }
  .grp:last-child .grid { flex: none; grid-auto-rows: minmax(108px, 160px); }
  .app.panel-open .side {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 240px;
    border-radius: var(--r);
    border: 1px solid var(--line);
    background: var(--panel);
    overflow: hidden;
  }
}

/* wide enough for the console and the panel side by side.

   A desktop is not a big phone: the pad takes the window it was given. The
   chassis is one screenful with no page scroll, the board is a full-height
   column beside it, and the keys grow with the glass rather than leaving a
   lit strip in the middle of a dark screen. Everything that grows is a
   clamp, so the same rules carry a 1024 laptop and a 1440p monitor. */
@media (min-width: 960px) {
  .bar-btn.panel-only { display: grid; }
  .app { max-width: min(96vw, 1800px); height: 100dvh; min-height: 0; }
  /* with the board away the console is a reading column again, not a slab */
  .app:not(.panel-open) { max-width: min(94vw, 1080px); }
  .body { min-height: 0; }
  .app.panel-open .body { flex-direction: row; justify-content: center; gap: 14px; align-items: stretch; }
  /* the console keeps a hand's width whatever the monitor does — the rest of
     the glass goes to the board, which has something to say with it. It
     scrolls inside itself; the window never does */
  .maincol {
    justify-content: flex-start;
    min-height: 0;
    max-width: clamp(780px, 46vw, 1080px);
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .grid {
    grid-template-columns: repeat(auto-fill, minmax(clamp(170px, 13vw, 236px), 1fr));
    grid-auto-rows: minmax(108px, clamp(108px, 15vh, 220px));
  }
  /* every key the same size, whichever group it is in: a console reads as one
     keyboard, not as a tall group and a short one */
  .grp:last-child { flex: none; }
  .grp:last-child .grid { flex: none; grid-auto-rows: minmax(108px, clamp(108px, 15vh, 220px)); }

  .hero { min-height: clamp(122px, 16vh, 240px); }
  .hero-label { font-size: clamp(32px, 3.6vh, 52px); }
  .hero-ico { width: clamp(48px, 5vh, 74px); height: clamp(48px, 5vh, 74px); }
  .hero-ring { width: clamp(54px, 6vh, 88px); height: clamp(54px, 6vh, 88px); }

  .app.panel-open .side {
    display: flex;
    flex-direction: column;
    flex: none;
    width: clamp(340px, 25vw, 640px);
    align-self: stretch;
    min-height: 0;
    border-radius: var(--r);
    border: 1px solid var(--line);
    background: var(--panel);
    overflow: hidden;
  }
}

/* a monitor, not a laptop lid */
@media (min-width: 1600px) {
  .app:not(.panel-open) { max-width: min(92vw, 1180px); }
}
.side-hd { padding: 13px 15px 0; }
.side-title { font-size: 15px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.side-tabs { display: flex; gap: 6px; margin-top: 10px; }
.side-tab {
  flex: 1;
  height: 38px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--bg-2);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--sec);
  display: flex; align-items: center; justify-content: center; gap: 7px;
}
.side-tab .n {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--panel-hi);
  color: var(--sec);
}
.side-tab.active { color: var(--ink); border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--bg-2)); }
.side-tab.active .n { background: var(--accent); color: #fff; }
.side-list { flex: 1; overflow-y: auto; padding: 11px 11px 13px; display: flex; flex-direction: column; gap: 8px; }
.side-list { min-height: 0; }
.side-list > * { flex: none; }
.side-empty { padding: 26px 16px; text-align: center; font-family: var(--mono); font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--dim); line-height: 1.7; }
.side-ft { padding: 10px 15px; border-top: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.side-ft .meta { font-family: var(--mono); font-size: 10px; letter-spacing: 0.08em; color: var(--dim); text-transform: uppercase; }

/* a call, wearing the alert card's face: one hue, a lamp, a specular ring */
.call {
  position: relative;
  isolation: isolate;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background:
    radial-gradient(140% 120% at 0% 0%, var(--pri-fill) 0%, transparent 60%),
    var(--card);
  overflow: hidden;
}
.call-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.call-title { font-size: 15.5px; font-weight: 700; line-height: 1.2; display: flex; align-items: center; gap: 8px; min-width: 0; }
.call-title::before {
  content: '';
  flex: none;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--pri);
  box-shadow: 0 0 8px var(--pri);
}
.call.p0 .call-title::before { animation: blink 1.05s steps(1, end) infinite; }
.call-time { flex: none; font-family: var(--mono); font-size: 10.5px; color: var(--sec); letter-spacing: 0.06em; font-variant-numeric: tabular-nums; }
.call-meta { margin-top: 3px; font-family: var(--mono); font-size: 11px; letter-spacing: 0.08em; color: var(--pri-ink); text-transform: uppercase; }
.call-msg { margin-top: 5px; font-family: var(--body); font-size: 15px; font-weight: 500; color: var(--sec); line-height: 1.4; }

.logrow { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); }
.logrow .tick { flex: none; width: 8px; height: 8px; border-radius: 50%; }
.logrow .tick.ok { background: var(--green); box-shadow: 0 0 6px var(--green); }
.logrow .tick.bad { background: var(--red); box-shadow: 0 0 6px var(--red); }
.logrow .what { flex: 1; min-width: 0; font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logrow .what small { font-family: var(--mono); font-weight: 500; font-size: 10.5px; color: var(--sec); margin-left: 6px; }
.logrow .when { flex: none; font-family: var(--mono); font-size: 10.5px; color: var(--sec); font-variant-numeric: tabular-nums; }

@media (prefers-reduced-motion: reduce) {
  .pill.on .dot, .pill.off .dot, .call.p0 .call-title::before { animation: none; }
  .sheet, .veil, .toast, .key, .hero, .btn { transition: none; }
}

/* ── cooldown — the key counts down its own lockout ──────────────────────
   Dimmed less than a dead key: it is not broken, it is busy. The server keeps
   the same clock, so the number is a promise the pad can keep. */
.key.cooling, .hero.cooling { filter: saturate(0.55); }
.key.cooling[disabled], .hero.cooling[disabled] { opacity: 0.72; }
.cd {
  position: absolute;
  right: 10px;
  bottom: 9px;
  min-width: 34px;
  padding: 3px 7px;
  border-radius: 6px;
  text-align: center;
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  color: var(--ink);
  background: rgba(0, 0, 0, 0.42);
  border: 1px solid rgba(255, 255, 255, 0.14);
  pointer-events: none;
}
.hero .cd { right: 18px; bottom: auto; top: 12px; font-size: 13px; }

/* ── drawn glyphs — white alpha PNGs, sized like the strokes they replace ──
   The surface supplies the colour context: on the red hero the beacon is
   white; on a smoked key it is the same white the strokes use. */
img.glyph { object-fit: contain; -webkit-user-drag: none; user-select: none; }
.hero-ico.glyph { width: 52px; height: 52px; filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.25)); }
.key-ico.glyph { width: 22px; height: 22px; opacity: 0.9; }
@media (min-width: 720px) { .hero-ico.glyph { width: 60px; height: 60px; } }
@media (min-width: 960px) { .hero-ico.glyph { width: clamp(60px, 6vh, 92px); height: clamp(60px, 6vh, 92px); } }
