/* Tally — brand D2 "Post Night" — A.B.M. Forensics */
@font-face { font-family: 'Michroma'; font-weight: 400; font-display: swap; src: url('/vendor/fonts/michroma/michroma-latin-400-normal.woff2') format('woff2'); }
@font-face { font-family: 'Saira'; font-weight: 400; font-display: swap; src: url('/vendor/fonts/saira/saira-latin-400-normal.woff2') format('woff2'); }
@font-face { font-family: 'Saira'; font-weight: 500; font-display: swap; src: url('/vendor/fonts/saira/saira-latin-500-normal.woff2') format('woff2'); }
@font-face { font-family: 'Saira'; font-weight: 600; font-display: swap; src: url('/vendor/fonts/saira/saira-latin-600-normal.woff2') format('woff2'); }
@font-face { font-family: 'Saira'; font-weight: 700; font-display: swap; src: url('/vendor/fonts/saira/saira-latin-700-normal.woff2') format('woff2'); }

:root {
  --night: #16191C;
  --panel: #1F2327;
  --gunmetal: #23272B;
  --line: #30363C;
  --line-strong: #454C54;
  --text: #E9ECEF;
  --muted: #A3ADB8;
  --accent: #C8F031;
  --accent-ink: #16191C;
  --danger: #FF6B5E;
  --video: #0E1012;
  --radius: 16px;
  --radius-sm: 10px;
  --wide: 'Michroma', 'Eurostile', 'Microgramma', 'Arial Black', sans-serif;
  --ui: 'Saira', 'Bahnschrift', 'DIN Alternate', 'Segoe UI', system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--night);
  color: var(--text);
  font-family: var(--ui);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
a:hover { color: #E4FF8A; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- brand ---------- */
.brand { display: inline-flex; align-items: center; gap: 12px; color: var(--text); text-decoration: none; }
.brand:hover { color: var(--text); }
.brand svg { flex: none; }
.wordmark { font-family: var(--wide); letter-spacing: 0.04em; font-size: 20px; line-height: 1; }
.endorse { font-size: 11px; font-weight: 600; letter-spacing: 0.14em; color: var(--muted); }

/* ---------- top bar ---------- */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px 24px;
  padding: 12px 24px; border-bottom: 1px solid var(--line); background: var(--night);
}
.topbar nav { display: flex; flex-wrap: wrap; gap: 4px; flex: 1; }
.topbar nav a {
  display: inline-flex; align-items: center; height: 40px; padding: 0 14px; border-radius: 999px;
  color: var(--muted); text-decoration: none; font-weight: 500;
}
.topbar nav a:hover { color: var(--text); background: var(--panel); }
.topbar nav a[aria-current='page'] { color: var(--text); background: var(--gunmetal); }
.topbar form { margin: 0; }

/* ---------- buttons, inputs ---------- */
.btn, .btn-ghost, .btn-danger {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 20px; border-radius: 999px; border: 1px solid transparent;
  font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn { background: var(--accent); color: var(--accent-ink); }
.btn:hover { background: #D8FF4F; color: var(--accent-ink); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--line-strong); }
.btn-ghost:hover { background: var(--panel); color: var(--text); }
.btn-danger { background: transparent; color: var(--danger); border-color: #5A2E2A; }
.btn-danger:hover { background: #2A1A19; }
.btn:disabled, .btn-ghost:disabled, .btn-danger:disabled { opacity: 0.5; cursor: default; }
.icon-btn {
  width: 44px; height: 44px; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
.icon-btn:hover { background: var(--gunmetal); }
.icon-btn:not(.is-muted) .x { display: none; }

label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 500; color: var(--muted); }
input[type='text'], input[type='password'], input[type='search'], select, textarea {
  min-height: 44px; padding: 8px 14px; border-radius: var(--radius-sm); border: 1px solid var(--line-strong);
  background: var(--night); color: var(--text); font-size: 16px; width: 100%;
}
input[readonly] { color: var(--text); background: var(--video); font-family: ui-monospace, 'Cascadia Mono', Menlo, Consolas, monospace; font-size: 14px; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px; }

/* ---------- layout ---------- */
.page { max-width: 1280px; margin: 0 auto; padding: 28px 24px 64px; display: flex; flex-direction: column; gap: 24px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; }
.page-head h1 { margin: 0; font-family: var(--wide); font-weight: 400; font-size: 22px; letter-spacing: 0.04em; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.panel.stack h2 { margin-bottom: 0; }
.panel h2 { margin: 0 0 12px; font-size: 13px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
form.row { align-items: flex-end; gap: 14px; }
.row .grow { flex: 1 1 280px; min-width: 0; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, 'Cascadia Mono', Menlo, Consolas, monospace; font-variant-numeric: tabular-nums; }
.notice { padding: 12px 16px; border-radius: var(--radius-sm); background: var(--gunmetal); border: 1px solid var(--line-strong); }
.notice.error { border-color: #5A2E2A; color: #FFB4AC; background: #241717; }

/* ---------- live layout ---------- */
.live-layout { max-width: 1600px; margin: 0 auto; padding: 20px 24px 40px; display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px; align-items: start; }
@media (max-width: 1040px) { .live-layout { grid-template-columns: minmax(0, 1fr); } }

.stage {
  position: relative; width: 100%; aspect-ratio: 16 / 9; background: var(--video);
  border-radius: 14px; overflow: hidden; border: 1px solid var(--line);
}
.stage:fullscreen { border-radius: 0; border: 0; aspect-ratio: auto; }
.stage video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: var(--video); }
.hud-top {
  position: absolute; left: 16px; right: 16px; top: 14px; display: flex; align-items: center; gap: 12px;
  font-weight: 600; font-size: 15px; pointer-events: none; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}
.hud-top .spacer { flex: 1; }
.badge {
  display: inline-flex; align-items: center; height: 26px; padding: 0 12px; border-radius: 999px;
  font-weight: 700; letter-spacing: 0.1em; font-size: 13px; text-shadow: none;
  background: var(--gunmetal); color: var(--muted); border: 1px solid var(--line-strong);
}
.badge.live { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.badge.connecting { color: var(--text); }
.rec { display: inline-flex; align-items: center; gap: 6px; }
.rec::before { content: ''; width: 9px; height: 9px; border-radius: 999px; background: var(--danger); }

.overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; text-align: center; padding: 24px; background: var(--video);
}
.overlay svg { opacity: 0.9; }
.overlay .title { font-family: var(--wide); font-size: 18px; letter-spacing: 0.04em; margin: 8px 0 0; }
.overlay .sub { color: var(--muted); margin: 0; max-width: 460px; }
.overlay .pulse { animation: pulse 2.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 0.35; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .overlay .pulse { animation: none; } }

.controls {
  position: absolute; left: 12px; right: 12px; bottom: 12px; min-height: 52px; padding: 4px 6px 4px 14px;
  border-radius: var(--radius-sm); background: rgba(31, 35, 39, 0.92); display: flex; align-items: center; gap: 10px;
}
.controls .label { font-size: 15px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.controls .spacer { flex: 1; }
.controls .mode { font-size: 12px; letter-spacing: 0.1em; color: var(--muted); }
.controls { transition: opacity 0.3s; }
.stage:not(.playing) .controls { display: none; }
.stage.idle .controls { opacity: 0; pointer-events: none; }
.stage.idle { cursor: none; }

dl.stats { margin: 0; display: grid; grid-template-columns: 1fr; gap: 0; }
dl.stats div { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
dl.stats div:last-child { border-bottom: 0; }
dl.stats dt { color: var(--muted); }
dl.stats dd { margin: 0; font-weight: 600; text-align: right; overflow-wrap: anywhere; }
.ok { color: var(--accent); }
.warn { color: #FFD23F; }
.bad { color: var(--danger); }

.result { display: flex; gap: 8px; }
.result input { flex: 1; min-width: 0; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
tr:last-child td { border-bottom: 0; }
td.actions { text-align: right; white-space: nowrap; }
td.actions > * { margin-left: 6px; }
.pill { display: inline-flex; align-items: center; height: 24px; padding: 0 10px; border-radius: 999px; font-size: 12px; font-weight: 600; letter-spacing: 0.06em; border: 1px solid var(--line-strong); color: var(--muted); }
.pill.active { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.note-input { min-height: 36px; padding: 4px 10px; font-size: 14px; }

.player-panel video { width: 100%; max-height: 70vh; background: var(--video); border-radius: var(--radius-sm); display: block; }

details summary { cursor: pointer; color: var(--muted); min-height: 44px; display: flex; align-items: center; }
details[open] summary { margin-bottom: 8px; }
.hash { font-family: ui-monospace, 'Cascadia Mono', Menlo, Consolas, monospace; font-size: 12px; color: var(--muted); word-break: break-all; display: block; margin-top: 4px; }

/* ---------- pilot ---------- */
.steps { margin: 0; padding-left: 22px; display: flex; flex-direction: column; gap: 10px; }
.steps li::marker { color: var(--accent); font-weight: 700; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 20px; align-items: start; }

/* ---------- sign in / watch ---------- */
.center-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 22px; }
.login-card .brand-block { display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; }
.login-card .wordmark { font-size: 34px; }
.tagline { color: var(--muted); margin: 0; }

.footer-note { color: var(--muted); font-size: 13px; margin: 0; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--gunmetal); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: 999px; padding: 10px 18px; font-weight: 500; z-index: 10;
}

@media (max-width: 640px) {
  .topbar { padding: 10px 14px; }
  .page, .live-layout, .watch-main { padding-left: 14px; padding-right: 14px; }
  .controls .label { display: none; }
  .controls { left: 8px; right: 8px; bottom: 8px; min-height: 48px; padding: 2px 4px 2px 10px; }
  .hud-top { font-size: 13px; left: 10px; right: 10px; top: 10px; }
  .overlay { gap: 4px; }
  .overlay svg { width: 44px; height: 44px; }
  .overlay .title { font-size: 14px; margin-top: 4px; }
  .overlay .sub { font-size: 13px; }
}

/* =====================================================================
   v1.1 — console additions
   ===================================================================== */
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.center { text-align: center; align-items: center; }
.row.end { justify-content: flex-end; }
.row.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
label.check { flex-direction: row; align-items: center; gap: 10px; color: var(--text); font-size: 15px; min-height: 44px; cursor: pointer; }
label.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.small-btn { min-height: 36px; padding: 0 14px; font-size: 14px; }

.nav-status {
  display: inline-flex; align-items: center; gap: 8px; height: 30px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--line-strong); color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: 0.1em; text-decoration: none;
}
.nav-status::before { content: ''; width: 8px; height: 8px; border-radius: 999px; background: var(--line-strong); }
.nav-status.on { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.nav-status.on::before { background: var(--accent-ink); }
.nav-status:hover { color: var(--text); }
.nav-status.on:hover { color: var(--accent-ink); }

.share-out { display: flex; flex-direction: column; gap: 6px; }
.share-label { font-size: 12px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
output.code, .code {
  font-family: ui-monospace, 'Cascadia Mono', Menlo, Consolas, monospace; font-size: 24px; font-weight: 700; letter-spacing: 0.08em;
  color: var(--accent); display: inline-flex; align-items: center; min-height: 44px; margin-right: 8px;
}
.result .code { flex: 1; }
.grow { flex: 1 1 auto; min-width: 0; }

ul.people, ul.device-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
ul.people li, ul.device-list li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
ul.people li:last-child, ul.device-list li:last-child { border-bottom: 0; }
ul.device-list li.removed { opacity: 0.55; }
.dot { flex: none; width: 9px; height: 9px; border-radius: 999px; background: var(--accent); }
.dot.off { background: var(--line-strong); }

.link-card { display: flex; flex-direction: column; gap: 16px; }
.link-card.closed { opacity: 0.7; }
.link-head { display: flex; align-items: flex-start; gap: 12px; }
.link-head h3 { margin: 0; font-size: 18px; font-weight: 600; }
.link-grid { display: grid; grid-template-columns: auto minmax(0, 1.4fr) auto; gap: 16px 28px; align-items: start; }
@media (max-width: 760px) { .link-grid { grid-template-columns: minmax(0, 1fr); } }
.pill.active { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.pill.locked { color: #FFD9D5; background: #4A1D19; border-color: #7A2E27; }

dl.stats.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); column-gap: 32px; }

/* frozen picture: never let a stuck frame look live */
.badge.frozen { background: var(--danger); color: #16191C; border-color: var(--danger); }
.stage.frozen { border-color: var(--danger); box-shadow: inset 0 0 0 3px var(--danger); }
.stale {
  position: absolute; left: 50%; top: 52px; transform: translateX(-50%); max-width: calc(100% - 32px);
  padding: 8px 14px; border-radius: 999px; background: rgba(42, 18, 16, 0.92); color: #FFD9D5;
  font-weight: 600; font-size: 14px; text-align: center;
}

.icon-btn[aria-pressed='true'] { background: var(--gunmetal); color: var(--accent); }
@media (pointer: coarse) {
  .icon-btn { width: 52px; height: 52px; }
  .controls { min-height: 60px; }
}

/* =====================================================================
   Share-link viewer: built for phones and tablets in the field
   ===================================================================== */
body.watch { min-height: 100vh; min-height: 100dvh; }
.watch-top {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px;
  padding: max(10px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
}
.watch-top .wordmark { font-size: 16px; }
.watch-title { font-weight: 600; font-size: 17px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.watch-top .meta { color: var(--muted); font-size: 14px; white-space: nowrap; }
.watch-main {
  max-width: 1600px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px;
  padding: 16px max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.watch .stage { max-height: calc(100dvh - 120px); }
.watch-info { display: flex; flex-direction: column; gap: 6px; }
.watch-info p { margin: 0; }
.rotate-tip { display: none; }

.gate { display: flex; justify-content: center; padding: 8px 0 24px; }
.gate .panel { width: 100%; max-width: 440px; }
.gate h1 { margin: 0; font-family: var(--wide); font-weight: 400; font-size: 20px; letter-spacing: 0.04em; }
.gate p { margin: 0; }
.gate-mark { display: flex; }
.gate input { min-height: 52px; font-size: 18px; }
input.code-input {
  font-family: ui-monospace, 'Cascadia Mono', Menlo, Consolas, monospace; font-size: 30px; font-weight: 700;
  letter-spacing: 0.2em; text-align: center; min-height: 64px;
}
.btn.big { min-height: 56px; font-size: 18px; }

/* phones, portrait: video runs edge to edge */
@media (max-width: 700px) {
  .watch-main { padding-left: 0; padding-right: 0; padding-top: 0; gap: 0; }
  .watch .stage { border-radius: 0; border-left: 0; border-right: 0; border-top: 0; }
  .watch-info { padding: 14px 16px; }
  .gate { padding: 16px; }
  .rotate-tip { display: block; }
}
/* phones, portrait: controls sit under the picture instead of covering it */
@media (max-width: 700px) and (orientation: portrait) {
  .watch .stage { aspect-ratio: auto; height: calc(100vw * 9 / 16 + 64px); max-height: none; }
  .watch .stage video { height: calc(100% - 64px); }
  .watch .stage .controls { left: 0; right: 0; bottom: 0; border-radius: 0; min-height: 64px; background: var(--panel); border-top: 1px solid var(--line); }
  .watch .stage.idle .controls { opacity: 1; pointer-events: auto; }
  .watch .stage.idle { cursor: auto; }
  .watch .stale { top: 44px; font-size: 13px; padding: 6px 12px; }
}
/* phones, landscape: the video is the whole screen */
@media (orientation: landscape) and (max-height: 560px) {
  body.watch .watch-top, body.watch .watch-info { display: none; }
  body.watch .watch-main { padding: 0; max-width: none; gap: 0; }
  body.watch .stage { height: 100vh; height: 100dvh; max-height: none; aspect-ratio: auto; border: 0; border-radius: 0; }
  body.watch .gate { padding: 12px; }
  body.watch .controls { left: max(8px, env(safe-area-inset-left)); right: max(8px, env(safe-area-inset-right)); bottom: max(8px, env(safe-area-inset-bottom)); }
  body.watch .hud-top { left: max(12px, env(safe-area-inset-left)); right: max(12px, env(safe-area-inset-right)); }
}

/* =====================================================================
   Night mode: dim red, to protect night vision and cut screen glow
   ===================================================================== */
html.night {
  --night: #000000; --panel: #0A0505; --gunmetal: #160A09; --line: #2A1311; --line-strong: #4A1F1B;
  --text: #FF5A4D; --muted: #C24A40; --accent: #FF3B2F; --accent-ink: #000000; --danger: #FFB000; --video: #000000;
  color-scheme: dark;
}
html.night .stage video { filter: brightness(0.55) contrast(1.1); }
html.night [stroke='#C8F031'] { stroke: var(--accent); }
html.night [fill='#C8F031'] { fill: var(--accent); }
html.night [fill='#23272B'] { fill: var(--gunmetal); }
html.night .controls { background: rgba(10, 5, 5, 0.92); }
html.night .btn:hover { background: #FF5A4D; }
html.night .stale { background: rgba(40, 20, 0, 0.92); color: #FFB000; }

.gate-card { max-width: 420px; align-items: center; }
.gate-card .wordmark { font-size: 26px; }
.gate-card p { margin: 0; }
