:root {
  --bg: #0b1220;
  --panel: #111a2e;
  --line: #1f2b45;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --blue: #2563eb;
  --red: #dc2626;
  --green: #16a34a;
  --yellow: #eab308;
  --gold: #f59e0b;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button { font: inherit; color: inherit; cursor: pointer; border: 1px solid var(--line);
  background: #18233b; border-radius: 10px; padding: .6rem 1rem; min-height: 44px; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--blue); border-color: var(--blue); font-weight: 600; }
button.ghost { background: transparent; }
button.small { min-height: 32px; padding: .25rem .6rem; font-size: .85rem; }
button.danger { color: #fca5a5; border-color: #7f1d1d; }
button.big { font-size: 1.3rem; padding: 1rem 2rem; background: var(--blue); border: 0; }
input, select { font: inherit; color: var(--text); background: #0b1428; border: 1px solid var(--line);
  border-radius: 8px; padding: .5rem .6rem; width: 100%; min-height: 40px; }
label { display: block; color: var(--muted); font-size: .85rem; margin: .5rem 0; }
label input, label select { margin-top: .25rem; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.hint { color: var(--muted); font-size: .85rem; }
.error { color: #fca5a5; min-height: 1em; }

.topbar { display: flex; align-items: center; gap: 1rem; padding: .5rem 1rem; height: 56px;
  background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; letter-spacing: .02em; }
.modes { display: flex; gap: .25rem; margin-left: auto; }
.mode.active { background: var(--blue); border-color: var(--blue); }
.status { display: flex; align-items: center; gap: .4rem; color: var(--muted); font-size: .85rem; min-width: 110px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #475569; }
.dot.ok { background: var(--green); }
.dot.err { background: var(--red); }

.layout { display: grid; grid-template-columns: 1fr 320px; height: calc(100% - 56px); }
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; height: auto; }
}
.stage-wrap { display: flex; align-items: center; justify-content: center; padding: .5rem; min-height: 0; overflow: hidden; }
.stage { position: relative; display: inline-block; line-height: 0; }
#view { display: block; max-width: 100%; max-height: calc(100vh - 72px); width: auto; height: auto;
  border-radius: var(--radius); background: #000; touch-action: none; user-select: none; -webkit-user-select: none; }
@media (max-width: 900px) { #view { max-height: 62vh; } }
#video { display: none; }
body.setup #view { cursor: crosshair; outline: 2px dashed #334155; outline-offset: 2px; }

.start-overlay { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: .5rem; background: rgba(2, 6, 23, .75); border-radius: var(--radius); line-height: 1.4; }
.start-overlay.hidden { display: none; }

.alarm-flash { position: absolute; inset: 0; pointer-events: none; border-radius: var(--radius); opacity: 0; }
body.alarm .alarm-flash { animation: flash .5s steps(1) infinite; box-shadow: inset 0 0 0 10px var(--red); }
@keyframes flash { 0% { opacity: 1; background: rgba(220, 38, 38, .35); } 50% { opacity: 0; } }

.panel { background: var(--panel); border-left: 1px solid var(--line); padding: 1rem; overflow-y: auto; }
@media (max-width: 900px) { .panel { border-left: 0; border-top: 1px solid var(--line); } }
.panel h2 { margin: 0 0 .75rem; font-size: 1.1rem; }

.counters { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.counter { position: relative; background: #0b1428; border: 2px solid var(--line); border-radius: var(--radius); padding: .7rem; }
.counter.left { border-top-color: var(--blue); }
.counter.right { border-top-color: var(--red); }
.counter-title { color: var(--muted); font-size: .85rem; display: flex; align-items: center; gap: .4rem; }
.counter-value { font-size: 2.4rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; margin: .2rem 0 .4rem; }
.counter-value small { font-size: 1.1rem; color: var(--muted); font-weight: 600; }
.badge { display: none; position: absolute; top: .5rem; right: .5rem; font-size: .7rem; font-weight: 800;
  padding: .15rem .45rem; border-radius: 6px; letter-spacing: .05em; }
.badge.full { background: var(--gold); color: #1c1917; }
.badge.wrong { background: var(--red); color: #fff; }
.counter.is-full { border-color: var(--gold); box-shadow: 0 0 18px rgba(245, 158, 11, .35); }
.counter.is-full .badge.full { display: block; }
.counter.is-wrong { border-color: var(--red); }
.counter.is-wrong .badge.wrong { display: block; }
.counter.is-wrong .badge.full { display: none; }

.alarm-banner { display: none; margin: .75rem 0; padding: .7rem; border-radius: var(--radius);
  background: rgba(220, 38, 38, .2); border: 1px solid var(--red); color: #fecaca; font-weight: 700; }
body.alarm .alarm-banner { display: block; }
.alarm-banner button { margin-top: .4rem; display: block; }
.notice { margin: .75rem 0; padding: .7rem; border-radius: var(--radius); background: rgba(234, 179, 8, .12);
  border: 1px solid #854d0e; color: #fde68a; }
.controls { margin-top: 1rem; display: grid; gap: .5rem; }
.legend { margin-top: 1rem; color: var(--muted); font-size: .85rem; }
.legend ul { padding-left: 0; list-style: none; }
.legend li { display: flex; align-items: center; gap: .5rem; margin: .3rem 0; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; flex: none; }
.swatch.blue { background: var(--blue); } .swatch.red { background: var(--red); }
.swatch.yellow { background: var(--yellow); } .swatch.green { background: var(--green); }
.debug { margin-top: .75rem; font: 12px/1.4 ui-monospace, monospace; color: #64748b; white-space: pre-wrap; }

.steps { display: grid; gap: .4rem; margin-bottom: .5rem; }
.step { display: flex; align-items: center; gap: .6rem; text-align: left; }
.step .num { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: #334155; font-size: .8rem; font-weight: 700; }
.step.done .num { background: var(--green); }
.step.active { border-color: var(--blue); background: rgba(37, 99, 235, .18); }
#nextBtn { width: 100%; margin-top: 1rem; }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius);
  width: min(92vw, 420px); padding: 1.25rem; }
dialog::backdrop { background: rgba(2, 6, 23, .7); }
dialog h2 { margin-top: 0; font-size: 1.15rem; }
dialog details { margin: .75rem 0; color: var(--muted); }

.login-body { display: grid; place-items: center; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 2rem; width: min(92vw, 380px); }
.login-card h1 { font-size: 1.3rem; margin-top: 0; margin-bottom: .25rem; }
.login-tabs { display: flex; gap: .4rem; margin-bottom: 1.25rem; border-bottom: 1px solid var(--line); padding-bottom: .6rem; }
.tab-btn { flex: 1; min-height: 38px; padding: .4rem .6rem; font-size: .88rem; background: transparent; border: 1px solid transparent; border-radius: 8px; color: var(--muted); }
.tab-btn.active { background: #18233b; border-color: var(--line); color: #fff; font-weight: 600; }
.user-badge { display: flex; align-items: center; gap: .5rem; font-size: .85rem; color: var(--muted); margin-left: auto; }
.user-badge a { color: #94a3b8; text-decoration: none; padding: .2rem .4rem; border-radius: 4px; border: 1px solid var(--line); }
.user-badge a:hover { color: #fff; border-color: #475569; }
.camera-badge { display: inline-flex; align-items: center; gap: .35rem; font-size: .8rem; padding: .2rem .5rem; border-radius: 6px; background: #18233b; border: 1px solid var(--line); color: var(--muted); }
.camera-badge.live { color: #86efac; border-color: #166534; background: rgba(22, 101, 52, 0.25); }
