/*
 * Design tokens follow the coffee-tracker palette: warm neutral surfaces, one
 * brand red (the KN logo red) that pops, slate for structure, and mint/sun/sky
 * as supporting accents. Window colors keep the semantics of slide 47.
 */
:root {
  --brand: #c2284a;
  --brand-2: #a62c4d;
  --brand-deep: #961d33;
  --accent: #e97991;
  --rose-soft: #f4d9df;
  --mint: #44c7a4;
  --sun: #ffd166;
  --sky: #65c7f7;

  --bg: #f7f3ea;
  --card: #fffdf8;
  --card-2: #f3ece0;
  --line: #eadfce;
  --ink: #161922;
  --ink-2: #2c303a;
  --muted: #6b6f7a;
  --on-brand: #ffffff;
  --focus: #ffd166;

  /* packets & diagram */
  --c-data: #c2284a;
  --c-data-band: rgba(194, 40, 74, 0.07);
  --c-ack: #17876a;
  --c-nak: #b07800;
  --c-timer: #2b8fd6;
  --c-timer-soft: rgba(43, 143, 214, 0.18);
  --c-lost: #161922;
  --c-corrupt: #d48a00;
  --c-error: #c2284a;
  --c-lifeline: #2c303a;
  --c-grid: #eadfce;
  --c-now: #c2284a;

  /* windows (slide 47) */
  --w-acked: #65c7f7;
  --w-acked-ink: #0d2a3a;
  --w-sent: #f4d9df;
  --w-sent-stroke: #c2284a;
  --w-usable: #2c303a;
  --w-usable-ink: #ffffff;
  --w-unusable: #fffdf8;
  --w-unusable-stroke: #d9ccb6;
  --w-delivered: #cdeee3;
  --w-delivered-stroke: #44c7a4;
  --w-buffered: #a62c4d;
  --w-buffered-ink: #ffffff;
  --w-expected: #9aa0ab;
  --w-acceptable: #65c7f7;
  --w-frame: #161922;

  --shadow-soft: 0 18px 45px rgb(15 23 42 / 10%);
  --shadow-button: 0 4px 0 rgb(111 20 48 / 18%), 0 8px 18px rgb(111 20 48 / 12%);
  --radius: 2rem;
  --radius-sm: 1rem;
  --font-sans: 'Plus Jakarta Sans', ui-sans-serif, system-ui, sans-serif;
  --font-display: 'Manrope', ui-sans-serif, system-ui, sans-serif;
  --font-mono: ui-monospace, 'SFMono-Regular', 'JetBrains Mono', Menlo, Consolas, monospace;
  --diagram-scale: 1;
  color-scheme: light;
}

/* Dark tokens: defined twice (auto via media query, explicit via data-theme). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand: #e97991;
    --brand-2: #e06482;
    --brand-deep: #e97991;
    --rose-soft: #3a1d27;
    --bg: #0d0f16;
    --card: #161922;
    --card-2: #1e222d;
    --line: #2a2f3b;
    --ink: #e9ebf1;
    --ink-2: #c9ccd6;
    --muted: #9aa0ad;
    --on-brand: #161922;
    --c-data: #f0708c;
    --c-data-band: rgba(240, 112, 140, 0.09);
    --c-ack: #44c7a4;
    --c-nak: #ffd166;
    --c-timer: #65c7f7;
    --c-timer-soft: rgba(101, 199, 247, 0.2);
    --c-lost: #e9ebf1;
    --c-corrupt: #ffd166;
    --c-error: #ff7a96;
    --c-lifeline: #9aa0ad;
    --c-grid: #232733;
    --c-now: #e97991;
    --w-acked: #3d9fd0;
    --w-acked-ink: #06131b;
    --w-sent: #3a1d27;
    --w-sent-stroke: #f0708c;
    --w-usable: #5a6072;
    --w-usable-ink: #ffffff;
    --w-unusable: #161922;
    --w-unusable-stroke: #343947;
    --w-delivered: #173a31;
    --w-delivered-stroke: #44c7a4;
    --w-buffered: #e06482;
    --w-buffered-ink: #161922;
    --w-expected: #7c8293;
    --w-acceptable: #3d9fd0;
    --w-frame: #e9ebf1;
    --shadow-soft: 0 18px 45px rgb(0 0 0 / 35%);
    --shadow-button: 0 4px 0 rgb(0 0 0 / 30%);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --brand: #e97991;
  --brand-2: #e06482;
  --brand-deep: #e97991;
  --rose-soft: #3a1d27;
  --bg: #0d0f16;
  --card: #161922;
  --card-2: #1e222d;
  --line: #2a2f3b;
  --ink: #e9ebf1;
  --ink-2: #c9ccd6;
  --muted: #9aa0ad;
  --on-brand: #161922;
  --c-data: #f0708c;
  --c-data-band: rgba(240, 112, 140, 0.09);
  --c-ack: #44c7a4;
  --c-nak: #ffd166;
  --c-timer: #65c7f7;
  --c-timer-soft: rgba(101, 199, 247, 0.2);
  --c-lost: #e9ebf1;
  --c-corrupt: #ffd166;
  --c-error: #ff7a96;
  --c-lifeline: #9aa0ad;
  --c-grid: #232733;
  --c-now: #e97991;
  --w-acked: #3d9fd0;
  --w-acked-ink: #06131b;
  --w-sent: #3a1d27;
  --w-sent-stroke: #f0708c;
  --w-usable: #5a6072;
  --w-usable-ink: #ffffff;
  --w-unusable: #161922;
  --w-unusable-stroke: #343947;
  --w-delivered: #173a31;
  --w-delivered-stroke: #44c7a4;
  --w-buffered: #e06482;
  --w-buffered-ink: #161922;
  --w-expected: #7c8293;
  --w-acceptable: #3d9fd0;
  --w-frame: #e9ebf1;
  --shadow-soft: 0 18px 45px rgb(0 0 0 / 35%);
  --shadow-button: 0 4px 0 rgb(0 0 0 / 30%);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.45;
}

body.presenter { font-size: 18px; --diagram-scale: 1.3; }

button, select, input { font: inherit; color: inherit; }

button:focus-visible, select:focus-visible, input:focus-visible, a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

::selection { color: #fff; background: #c2284a; }

[hidden] { display: none !important; }

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; gap: 12px; align-items: center; min-width: 0; }
.logo { height: 45px; width: auto; flex: none; }
:root[data-theme="dark"] .logo { filter: brightness(1.75) saturate(0.85); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .logo { filter: brightness(1.75) saturate(0.85); } }

h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.3rem;
  letter-spacing: -0.01em;
  color: var(--brand-deep);
}
.subtitle { margin: 0; color: var(--muted); font-size: 0.82rem; }
.kicker { margin: 0 0 1px; font-size: 0.66rem; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; color: var(--brand-deep); opacity: 0.85; }

.pickers { display: flex; flex-wrap: wrap; gap: 10px; flex: 1 1 420px; justify-content: center; }
.field { display: flex; flex-direction: column; gap: 2px; font-size: 0.72rem; font-weight: 800;
  text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); min-width: 0; flex: 1 1 200px; max-width: 360px; }
.field select, .setting select, .setting input[type="number"] {
  min-height: 40px;
  padding: 0 12px;
  border: 2px solid color-mix(in srgb, var(--brand) 14%, var(--line));
  border-radius: 14px;
  background: var(--card);
  font-weight: 700;
  font-size: 0.9rem;
  text-transform: none;
  letter-spacing: 0;
  color: var(--ink);
  width: 100%;
}
.field select:focus, .setting select:focus { border-color: var(--brand); }

.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.pill {
  min-height: 38px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: var(--card);
  box-shadow: var(--shadow-soft);
  font-weight: 800;
  font-size: 0.85rem;
  color: var(--ink-2);
  cursor: pointer;
}
.pill:hover { color: var(--brand); }
.pill.on { background: var(--brand); color: var(--on-brand); }
.pill.icon { width: 38px; padding: 0; }

/* ---------- layout ---------- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 410px);
  gap: 16px;
  padding: 16px 20px 8px;
  align-items: start;
}
body.presenter .layout { grid-template-columns: minmax(0, 1fr) minmax(320px, 470px); }

.card {
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
}

.stage { padding: 14px 16px 12px; min-width: 0; }
.side { padding: 10px; min-width: 0; position: sticky; top: 84px; max-height: calc(100vh - 100px); display: flex; flex-direction: column; }

@media (max-width: 1000px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 12px 16px; }
  .side { position: static; max-height: none; }
}

/* ---------- toolbar ---------- */

.toolbar { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; }
.transport { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 42px;
  min-width: 42px;
  justify-content: center;
  padding: 0 12px;
  border-radius: 16px;
  border: 2px solid transparent;
  background: var(--card-2);
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease;
}
.btn:active { transform: translateY(2px); }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linejoin: round; stroke-linecap: round; }
.btn.primary { background: var(--brand); color: var(--on-brand); box-shadow: var(--shadow-button); min-width: 108px; }
.btn.primary svg { fill: currentColor; stroke: none; }
.btn.primary .i-pause { display: none; }
.btn.primary.playing .i-pause { display: block; }
.btn.primary.playing .i-play { display: none; }
.btn.ghost.on { color: var(--brand); border-color: color-mix(in srgb, var(--brand) 30%, transparent); }
#btn-quick { margin-left: auto; font-size: 1.1rem; }
#btn-quick + .segmented { margin-left: 0; }
.btn.ghost:hover { border-color: color-mix(in srgb, var(--brand) 30%, transparent); color: var(--brand); }
.btn.mint { background: var(--mint); color: #0d0f16; font-family: var(--font-mono); font-size: 0.85rem; }
.btn.mint:hover { filter: brightness(1.05); }
.btn:disabled { opacity: 0.4; cursor: default; transform: none; }

.speed, .clock, .zoom { display: flex; align-items: center; gap: 8px; font-size: 0.8rem; font-weight: 700; color: var(--muted); }
.speed input { width: 110px; }
.speed output, .clock output { font-family: var(--font-mono); color: var(--ink); font-weight: 700; min-width: 4.5em; }
input[type="range"] { accent-color: var(--brand); }

.segmented { display: inline-flex; padding: 3px; border-radius: 999px; background: var(--card-2); margin-left: auto; }
.segmented button {
  border: 0; background: transparent; padding: 6px 14px; border-radius: 999px;
  font-weight: 800; font-size: 0.82rem; color: var(--muted); cursor: pointer;
}
.segmented button.on { background: var(--card); color: var(--brand); box-shadow: 0 2px 8px rgb(0 0 0 / 8%); }

/* ---------- quick settings ---------- */

.quick {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 6px 14px;
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--card-2);
  align-items: end;
}
.qs { display: grid; grid-template-columns: 1fr auto; gap: 0 6px; align-items: baseline; font-size: 0.74rem; min-width: 0; }
.qs > span { font-weight: 800; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qs output { font-family: var(--font-mono); font-size: 0.74rem; color: var(--brand); font-weight: 700; }
.qs input[type="range"] { grid-column: 1 / -1; width: 100%; margin: 2px 0 0; }
.qs select { grid-column: 1 / -1; min-height: 30px; margin-top: 2px; padding: 0 8px; border-radius: 10px;
  border: 2px solid color-mix(in srgb, var(--brand) 14%, var(--line)); background: var(--card); font-weight: 700; font-size: 0.78rem; }
.qs.off > span { color: var(--muted); font-weight: 700; }
.qs.off output { color: var(--muted); }
.quick .more { min-height: 34px; font-size: 0.78rem; justify-self: start; align-self: center; }
.quick .warnline { grid-column: 1 / -1; margin: 0; }

/* ---------- banners ---------- */

.banner {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--card-2);
  font-size: 0.88rem;
}
.banner b { font-family: var(--font-display); }
.banner .slide { display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 999px;
  background: var(--brand); color: var(--on-brand); font-size: 0.7rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; }
.banner.status { background: var(--rose-soft); color: var(--ink); font-weight: 700; }
.banner.status.warn { background: color-mix(in srgb, var(--sun) 35%, var(--card)); }

/* ---------- views ---------- */

.viewport { margin-top: 12px; }
.diagram { display: block; width: 100%; user-select: none; -webkit-user-select: none; }
#seq-svg { height: min(64vh, 720px); min-height: 360px; touch-action: pan-x; }
#win-svg { height: min(62vh, 640px); min-height: 380px; }
body.presenter #seq-svg { height: 70vh; }

.seq-tools { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; margin-top: 6px; font-size: 0.8rem; color: var(--muted); font-weight: 700; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.check input { accent-color: var(--brand); width: 16px; height: 16px; }

.foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 16px; margin-top: 8px; }
.hint { margin: 0; font-size: 0.8rem; color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 0.76rem; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; width: 14px; height: 14px; border-radius: 4px; border: 2px solid transparent; }
.legend i.line { height: 3px; border-radius: 2px; border: 0; }

/* SVG diagram styles (shared) */
.diagram text { font-family: var(--font-sans); fill: var(--ink); }
.diagram .mono { font-family: var(--font-mono); }
.diagram .muted { fill: var(--muted); }
.diagram .lifeline { stroke: var(--c-lifeline); stroke-width: 2; }
.diagram .grid { stroke: var(--c-grid); stroke-width: 1; }
.diagram .now { stroke: var(--c-now); stroke-width: 1.5; stroke-dasharray: 5 4; }
.diagram .now-label { fill: var(--c-now); font-weight: 800; }
.diagram .pkt-data { stroke: var(--c-data); fill: none; stroke-width: 2; }
.diagram .pkt-band { fill: var(--c-data-band); stroke: none; }
.diagram .pkt-ack { stroke: var(--c-ack); fill: none; stroke-width: 2; }
.diagram .pkt-nak { stroke: var(--c-nak); fill: none; stroke-width: 2; }
.diagram .pkt-retx { stroke-dasharray: 7 4; }
.diagram .lbl-data { fill: var(--c-data); font-weight: 800; }
.diagram .lbl-ack { fill: var(--c-ack); font-weight: 800; }
.diagram .lbl-nak { fill: var(--c-nak); font-weight: 800; }
.diagram .head rect { stroke: var(--card); stroke-width: 2; }
.diagram .head.data rect { fill: var(--c-data); }
.diagram .head.ack rect { fill: var(--c-ack); }
.diagram .head.nak rect { fill: var(--c-nak); }
.diagram .head text { fill: var(--on-brand); font-weight: 800; }
.diagram .head.ack text, .diagram .head.nak text { fill: #fff; }
:root[data-theme="dark"] .diagram .head.ack text, :root[data-theme="dark"] .diagram .head.nak text { fill: #0d0f16; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .diagram .head.ack text, :root:not([data-theme="light"]) .diagram .head.nak text { fill: #0d0f16; } }
.diagram .head:hover rect { stroke: var(--focus); stroke-width: 3; }
.diagram .hit { fill: transparent; }
.diagram .hit-line { stroke: transparent; stroke-width: 24; stroke-linecap: round; }
.diagram .head { cursor: crosshair; }
.diagram .lost { stroke: var(--c-lost); stroke-width: 3.5; stroke-linecap: round; }
.diagram .lost-text { fill: var(--c-lost); font-weight: 800; }
.diagram .corrupt { fill: var(--c-corrupt); stroke: var(--card); stroke-width: 1.5; }
.diagram .timer { stroke: var(--c-timer); stroke-width: 3; stroke-linecap: round; }
.diagram .timer-future { stroke: var(--c-timer); stroke-width: 1.5; stroke-dasharray: 2 4; opacity: 0.7; }
.diagram .timer-fired { fill: var(--c-timer); }
.diagram .timer-text { fill: var(--c-timer); font-weight: 800; }
.diagram .ev-dot { fill: var(--c-lifeline); }
.diagram .ev-text { font-size: calc(12.5px * var(--diagram-scale)); }
.diagram .ev-text.error { fill: var(--c-error); font-weight: 800; }
.diagram .ev-text.warn { fill: var(--ink); font-weight: 700; }
.diagram .ev-text.muted { fill: var(--muted); }
.diagram .snap { font-family: var(--font-mono); font-size: calc(10.5px * var(--diagram-scale)); fill: var(--muted); }
.diagram .leader { stroke: var(--line); stroke-width: 1; }
.diagram .lane-title { font-family: var(--font-display); font-weight: 800; fill: var(--ink); }

/* window slots */
.diagram .slot { stroke-width: 2; }
.diagram .mini .slot { stroke-width: 1.2; }
.diagram .mini .frame { stroke-width: 1.6; }
.diagram .s-acked { fill: var(--w-acked); stroke: var(--w-acked); }
.diagram .s-sent { fill: var(--w-sent); stroke: var(--w-sent-stroke); }
.diagram .s-usable { fill: var(--w-usable); stroke: var(--w-usable); }
.diagram .s-unusable { fill: var(--w-unusable); stroke: var(--w-unusable-stroke); }
.diagram .s-delivered { fill: var(--w-delivered); stroke: var(--w-delivered-stroke); }
.diagram .s-buffered { fill: var(--w-buffered); stroke: var(--w-buffered); }
.diagram .s-expected { fill: var(--w-expected); stroke: var(--w-expected); }
.diagram .s-acceptable { fill: var(--w-acceptable); stroke: var(--w-acceptable); }
.diagram .t-acked { fill: var(--w-acked-ink); }
.diagram .t-usable { fill: var(--w-usable-ink); }
.diagram .t-buffered { fill: var(--w-buffered-ink); }
.diagram .t-expected { fill: #fff; }
.diagram .t-acceptable { fill: var(--w-acked-ink); }
.diagram .slot-label { font-family: var(--font-mono); font-weight: 800; }
.diagram .slot-sub { font-family: var(--font-mono); font-size: 9px; fill: var(--muted); }
.diagram .frame { fill: none; stroke: var(--w-frame); stroke-width: 2.5; }
.diagram .pointer { fill: var(--ink-2); font-family: var(--font-mono); font-weight: 700; }
.diagram .pointer-line { stroke: var(--ink-2); stroke-width: 1.5; }
.diagram .pie { fill: var(--c-timer); }
.diagram .pie-bg { fill: var(--c-timer-soft); }
.diagram .ring { fill: none; stroke: var(--c-timer); stroke-width: 5; }
.diagram .ring-bg { fill: none; stroke: var(--c-timer-soft); stroke-width: 5; }
.diagram .err-mark { fill: var(--c-error); font-weight: 800; }

@keyframes pulse { from { opacity: 0.25; } to { opacity: 1; } }

/* ---------- side panel ---------- */

.tabs { display: flex; gap: 2px; padding: 4px; border-radius: 999px; background: var(--card-2); overflow-x: auto; scrollbar-width: none; }
.tabs button {
  flex: 1 1 auto; border: 0; background: transparent; padding: 7px 8px; border-radius: 999px;
  font-weight: 800; font-size: 0.78rem; color: var(--muted); cursor: pointer; white-space: nowrap;
}
.tabs button.on { background: var(--card); color: var(--brand); box-shadow: 0 2px 8px rgb(0 0 0 / 8%); }
.tabs .expand { flex: 0 0 auto; font-size: 1rem; line-height: 1; }
.layout.wide { grid-template-columns: minmax(0, 1fr) minmax(320px, 46%); }
@media (max-width: 1000px) { .layout.wide { grid-template-columns: minmax(0, 1fr); } }
.tab-body { padding: 12px 6px 6px; overflow: auto; min-height: 0; flex: 1; }

h2, h3 { font-family: var(--font-display); margin: 0 0 8px; }
h3 { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.panel-section + .panel-section { margin-top: 18px; }

/* FSM */
.fsm-svg { width: 100%; height: auto; display: block; margin: 0 auto; }
.fsm-svg .state circle { fill: var(--card); stroke: var(--ink-2); stroke-width: 2; }
.fsm-svg .state text { font-size: 11.5px; font-weight: 800; fill: var(--ink); }
.fsm-svg .state.on circle { fill: var(--brand); stroke: var(--brand); }
.fsm-svg .state.on text { fill: var(--on-brand); }
.fsm-svg .edge path { fill: none; stroke: var(--muted); stroke-width: 1.5; }
.fsm-svg .edge text { font-size: 12px; font-family: var(--font-mono); fill: var(--ink-2); }
.fsm-svg .edge.note path { stroke-dasharray: 4 3; }
.fsm-svg .edge.on path { stroke: var(--brand); stroke-width: 3; animation: pulse 0.5s ease 2 alternate; }
.fsm-svg .edge.on text { fill: var(--brand); font-weight: 800; }
.fsm-svg .init { stroke: var(--ink-2); stroke-width: 1.5; stroke-dasharray: 4 3; fill: none; }
.fsm-svg .arrowhead { fill: var(--muted); }
.fsm-svg .arrowhead.on { fill: var(--brand); }

.trans-card {
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  white-space: pre-wrap;
  background: var(--card);
  transition: border-color 0.2s ease, background 0.2s ease;
}
.trans-card + .trans-card { margin-top: 6px; }
.trans-card .ev { font-weight: 800; padding-bottom: 4px; border-bottom: 1.5px solid currentColor; margin-bottom: 4px; }
.trans-card .act { color: var(--ink-2); }
.trans-card.note { opacity: 0.75; font-style: italic; }
.trans-card.on { border-color: var(--brand); background: var(--rose-soft); animation: pulse 0.4s ease 1; }
.trans-card.on .ev { color: var(--brand); }
.init-card { font-family: var(--font-mono); font-size: 0.74rem; color: var(--muted); white-space: pre-wrap; margin: 0 0 8px; }
.vars { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 8px; }
.var { font-family: var(--font-mono); font-size: 0.76rem; background: var(--card-2); padding: 2px 8px; border-radius: 999px; }
.var b { color: var(--brand); }

/* log */
.log { list-style: none; margin: 0; padding: 0; font-size: 0.8rem; }
.log li {
  display: grid; grid-template-columns: 4.2em 1.8em 1fr; gap: 6px; padding: 4px 6px;
  border-radius: 8px; cursor: pointer; align-items: baseline;
}
.log li:hover { background: var(--card-2); }
.log li.cur { background: var(--rose-soft); }
.log .t { font-family: var(--font-mono); color: var(--muted); font-size: 0.72rem; }
.log .side { font-weight: 800; font-size: 0.7rem; text-align: center; border-radius: 6px; }
.log .side.S { color: var(--c-data); }
.log .side.R { color: var(--c-ack); }
.log .side.C { color: var(--muted); }
.log li.muted .txt { color: var(--muted); }
.log li.warn .txt { font-weight: 700; }
.log li.error .txt { color: var(--c-error); font-weight: 800; }

/* stats */
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.tile { background: var(--card-2); border-radius: var(--radius-sm); padding: 8px 12px; }
.tile .k { font-size: 0.72rem; color: var(--muted); font-weight: 700; }
.tile .v { font-family: var(--font-display); font-size: 1.35rem; font-weight: 800; }
.tile.bad .v { color: var(--c-error); }
.big { background: var(--card-2); border-radius: var(--radius-sm); padding: 10px 14px; margin-top: 8px; }
.big .row { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.big .v { font-family: var(--font-display); font-weight: 800; font-size: 1.2rem; }
.bar { height: 8px; border-radius: 4px; background: var(--line); margin: 4px 0 6px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: 4px; }
.bar.formula > i { background: var(--ink-2); }
.formula-text { font-family: var(--font-mono); font-size: 0.74rem; color: var(--muted); }
.calc { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.calc label { display: flex; flex-direction: column; font-size: 0.72rem; color: var(--muted); font-weight: 700; gap: 2px; }
.calc input { min-height: 34px; border: 2px solid var(--line); border-radius: 10px; background: var(--card); padding: 0 8px; font-family: var(--font-mono); }

/* settings */
.setting { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: center; margin: 8px 0; font-size: 0.84rem; }
.setting > span { font-weight: 700; }
.setting output { font-family: var(--font-mono); font-size: 0.8rem; color: var(--ink-2); }
.setting input[type="range"] { grid-column: 1 / -1; width: 100%; }
.setting select, .setting input[type="number"] { grid-column: 1 / -1; min-height: 36px; }
.setting.toggle { grid-template-columns: auto 1fr; }
.setting.toggle input { accent-color: var(--brand); width: 18px; height: 18px; }
.setting .note { grid-column: 1 / -1; font-size: 0.72rem; color: var(--muted); font-style: italic; }
.setting.off > span { color: var(--muted); }
.warnline { font-size: 0.78rem; color: var(--c-error); font-weight: 700; margin: 4px 0; }
.restart-note { font-size: 0.74rem; color: var(--muted); margin: 0 0 6px; }

/* ---------- footer, toast ---------- */

.pagefoot { padding: 6px 20px 22px; color: var(--muted); font-size: 0.76rem; text-align: center; }
.pagefoot p { margin: 2px 0; }
.pagefoot .legal { font-weight: 700; color: var(--ink-2); }
.pagefoot a { color: inherit; text-decoration: underline; text-decoration-color: color-mix(in srgb, currentColor 40%, transparent); text-underline-offset: 2px; }
.pagefoot a:hover { color: var(--brand); }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: var(--card); padding: 10px 18px; border-radius: 999px; font-weight: 800;
  box-shadow: var(--shadow-soft); z-index: 50;
}

@media (max-width: 640px) {
  .topbar { padding: 8px 16px; }
  .subtitle { display: none; }
  .kicker { font-size: 0.6rem; }
  .segmented { margin-left: 0; }
  .stage { padding: 12px; }
  .layout { padding: 10px 16px; }
}

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