/* app.css: the bench page. Neutral: no maker's look; light and dark follow the viewer. */
:root {
  --bg: #f5f6f8; --fg: #16191d; --muted: #5d6673; --card: #ffffff; --line: #d9dde3; --accent: #2457c5;
  --accent-fg: #fff; --ok: #187a3e; --warn: #9a5b00; --bad: #b3261e; --live: #187a3e; --virtual: #6a4bc4;
  --screen: #0b0d10; --radius: 10px; --gap: 14px;
  /* the sticky header's height: the page's own top spacing (scroll padding) keeps content out from under it */
  --header-h: 57px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101317; --fg: #e7eaee; --muted: #9aa3ae; --card: #181c22; --line: #2a3038; --accent: #6f9bff;
    --accent-fg: #0b0d10; --ok: #4cc27a; --warn: #e0a640; --bad: #ff7a70; --live: #4cc27a; --virtual: #a78bfa;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-padding-top: calc(var(--header-h) + 8px); }
html, body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { padding: env(safe-area-inset-top, 0) 0 env(safe-area-inset-bottom, 0); }
#app { min-height: 100vh; display: flex; flex-direction: column; }
main { flex: 1; padding: var(--gap) max(16px, env(safe-area-inset-left, 0)); }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.spacer { flex: 1; }
button, select, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 6px 12px; min-height: 36px; }
button:focus-visible, [tabindex]:focus-visible, select:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
button.primary.active { background: var(--ok); border-color: var(--ok); }
button.ghost { background: transparent; }
.top { display: flex; align-items: center; gap: var(--gap); padding: 0 16px; height: var(--header-h); border-bottom: 1px solid var(--line); background: var(--card); position: sticky; top: 0; z-index: 5; }
h1, h2, .bench-bar, .tile { scroll-margin-top: calc(var(--header-h) + 8px); }
.brand { font-weight: 650; text-decoration: none; color: var(--fg); }
.foot { padding: 10px 16px; font-size: 0.8rem; }
.notice { padding: 12px 14px; border-radius: var(--radius); background: var(--card); border: 1px solid var(--line); }
.notice.bad { border-color: var(--bad); color: var(--bad); }
.badge { font-size: 0.72rem; font-weight: 650; letter-spacing: 0.04em; text-transform: uppercase; padding: 2px 8px; border-radius: 99px; border: 1px solid currentColor; }
.badge.live { color: var(--live); }
.badge.virtual { color: var(--virtual); }
.chip { font-size: 0.8rem; padding: 2px 10px; border-radius: 99px; background: var(--bg); border: 1px solid var(--line); }
.chip.ctl { background: var(--ok); color: #fff; border-color: var(--ok); }
.demo-banner { display: flex; gap: 12px; align-items: center; padding: 8px 16px; background: var(--accent); color: var(--accent-fg); }
.demo-banner button { color: inherit; border-color: currentColor; }
.demo-banner button.small { margin-left: auto; padding: 2px 10px; }
.demo-banner .tier-badge { padding: 1px 8px; border: 1px solid currentColor; border-radius: 999px; font-size: 0.85em; }
.bench-list { list-style: none; padding: 0; display: grid; gap: 8px; }
a.button { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; min-height: 36px; text-decoration: none; color: var(--fg); background: var(--card); }
a.button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0; }
.row input { flex: 1 1 220px; min-height: 36px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.card { margin-top: var(--gap); }
.signin { max-width: 560px; margin: 0 auto; }
.signin h2 { margin-top: 18px; }
.codes { columns: 2; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.form label { display: grid; gap: 4px; margin-bottom: 10px; font-size: 0.9rem; }
.form textarea, .form input { width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.who { font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
@media (max-width: 480px) { .who { display: none; } }
.bench-list li { display: flex; gap: 10px; align-items: center; padding: 12px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }

/* the bench: focus + companion (>= 1280 px side by side; tablet stacked; phone: the card is a bottom sheet) */
.bench-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: var(--gap); }
.bench-grid { display: grid; gap: var(--gap); grid-template-columns: minmax(0, 1fr) minmax(320px, 420px); grid-template-areas: "focus companion" "thumbs thumbs"; align-items: start; }
.focus-box { grid-area: focus; min-width: 0; }
.companion { grid-area: companion; display: flex; flex-direction: column; gap: var(--gap); }
.thumbs { grid-area: thumbs; display: flex; gap: var(--gap); overflow-x: auto; padding-bottom: 4px; }
@media (max-width: 1279px) {
  .bench-grid { grid-template-columns: minmax(0, 1fr); grid-template-areas: "focus" "companion" "thumbs"; }
}
@media (max-width: 767px) {
  main { padding: 8px 0; }
  .bench-bar { padding: 0 12px; }
  .bench-grid { grid-template-areas: "thumbs" "focus"; gap: 8px; }
  .thumbs { padding: 0 12px; }
  .thumbs .thumb { width: auto; }
  .thumbs .thumb .tile { display: none; }
  .thumbs .thumb::after { content: attr(title); }
  .companion { position: fixed; left: 0; right: 0; bottom: 0; z-index: 4; max-height: 70vh; overflow-y: auto; background: var(--card); border-top: 1px solid var(--line); border-radius: 16px 16px 0 0; padding: 0 12px calc(12px + env(safe-area-inset-bottom, 0)); box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.25); }
  .companion.collapsed > :not(.sheet-handle) { display: none; }
  .focus-box { padding-bottom: 72px; }
}
.sheet-handle { display: none; }
@media (max-width: 767px) { .sheet-handle { display: block; width: 100%; border: 0; background: transparent; padding: 10px; font-weight: 600; } }
.companion:not(.has-bench) .wiring, .companion.has-bench .empty-bench { display: none; }

.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.tile.controlling { border-color: var(--ok); }
.tile-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 10px; }
.tile-name { border: 0; background: transparent; font-weight: 650; padding: 0; min-height: 0; }
.status { color: var(--muted); font-size: 0.85rem; }
.screen-box { position: relative; background: var(--screen); }
.screen { display: block; width: 100%; height: auto; aspect-ratio: 1024 / 600; image-rendering: auto; }
.screen.pixelated { image-rendering: pixelated; }
.overlay { position: absolute; inset: 0; display: grid; place-items: center; color: #cfd6df; font-size: 1.1rem; background: rgba(11, 13, 16, 0.6); }
.tile-tools { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 10px; border-top: 1px solid var(--line); }
.thumb { flex: 0 0 auto; width: 260px; cursor: pointer; border-radius: var(--radius); }
.thumb .tile-tools, .thumb .panel-box { display: none; }
.thumb.current { display: none; }
@media (max-width: 767px) { .thumb.current { display: block; } .thumb { padding: 6px 12px; border: 1px solid var(--line); background: var(--card); } }

/* the front panel, from the device's Caps */
.panel-box { padding: 10px; border-top: 1px solid var(--line); }
.panel-dials { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 10px; }
.dial { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 72px; }
.dial-face { width: 56px; height: 56px; border-radius: 50%; padding: 0; position: relative; background: radial-gradient(circle at 35% 30%, var(--card), var(--bg)); touch-action: none; }
.dial-mark { position: absolute; left: 50%; top: 6px; width: 4px; height: 16px; margin-left: -2px; border-radius: 2px; background: var(--accent); transform-origin: 2px 22px; }
.dial-label { font-size: 0.72rem; text-align: center; color: var(--muted); }
.panel-keys { display: flex; flex-wrap: wrap; gap: 6px; }
.key { min-width: 64px; font-size: 0.85rem; touch-action: none; user-select: none; }
.key.down { background: var(--accent); color: var(--accent-fg); }
.key.arming { outline: 2px dashed var(--warn); }
.panel-off { opacity: 0.6; }

/* the generator card */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.gen-channels { display: grid; gap: 12px; }
.gen-ch { border: 1px solid var(--line); border-radius: 8px; padding: 10px; display: grid; gap: 10px; }
.gen-ch-head { display: flex; align-items: center; justify-content: space-between; }
.out-toggle { min-width: 120px; font-weight: 650; }
.out-toggle.on { background: var(--ok); color: #fff; border-color: var(--ok); }
.out-toggle.pending, .pending .vd-value, .seg .pending { opacity: 0.6; }
.seg { display: flex; flex-wrap: wrap; gap: 4px; }
.seg button { min-height: 32px; padding: 4px 10px; }
.seg button[aria-checked="true"] { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.gen-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.vd { display: flex; flex-direction: column; gap: 2px; }
.vd-label { font-size: 0.75rem; color: var(--muted); }
.vd-face { border: 1px solid var(--line); border-radius: 8px; padding: 8px; background: var(--bg); cursor: ns-resize; touch-action: none; user-select: none; }
.vd-big .vd-value { font-size: 1.35rem; font-variant-numeric: tabular-nums; font-weight: 600; }
.vd-input { width: 100%; border: 0; background: transparent; font-size: 1.2rem; }
.vd-range { font-size: 0.7rem; color: var(--muted); }
.vd-note { font-size: 0.75rem; }
.vd-note.warn, .gen-msg.warn { color: var(--warn); }
.vd-note.bad, .gen-msg.bad { color: var(--bad); }
.vd.disabled .vd-face { cursor: not-allowed; opacity: 0.7; }
.gen.readonly .out-toggle, .gen.readonly .seg button { opacity: 0.7; }
.gen-more summary { cursor: pointer; color: var(--muted); }
.gen-msg { min-height: 1.2em; margin: 8px 0 0; font-size: 0.85rem; }

/* the wiring strip */
.wiring { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.cables { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.cable { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 0.9rem; }
.cable .end { font-weight: 600; }
.cable .note { color: var(--muted); font-size: 0.8rem; }
.cable-line { width: 60px; height: 10px; }
.cable-line line { stroke: var(--line); stroke-width: 3; }
.cable-line path { fill: var(--line); }
.cable.live .cable-line line { stroke: var(--ok); stroke-dasharray: 6 4; animation: flow 0.8s linear infinite; }
.cable.live .cable-line path { fill: var(--ok); }
.cable.live .end { color: var(--ok); }
@keyframes flow { to { stroke-dashoffset: -10; } }
@media (prefers-reduced-motion: reduce) { .cable.live .cable-line line { animation: none; } }

/* dialogs and toasts */
.dlg { border: 1px solid var(--line); border-radius: 14px; background: var(--card); color: var(--fg); max-width: min(520px, calc(100vw - 32px)); padding: 18px; }
.dlg::backdrop { background: rgba(0, 0, 0, 0.5); }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.dlg textarea { width: 100%; }
.code { font-size: 2.6rem; font-weight: 700; letter-spacing: 0.12em; font-variant-numeric: tabular-nums; text-align: center; margin: 10px 0; }
.check { display: flex; gap: 8px; align-items: flex-start; margin-top: 8px; font-size: 0.9rem; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 20; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--accent); padding: 10px 12px; border-radius: 8px; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2); }
.toast.warn { border-left-color: var(--warn); }
.toast.bad { border-left-color: var(--bad); }
