:root {
  --bg: #090c11;
  --panel: #11161e;
  --panel-2: #1a2029;
  --line: rgba(255, 255, 255, 0.08);
  --ice: #e8f2ff;
  --muted: rgba(232, 242, 255, 0.55);
  --accent: #7bd9ff;
  --save: #29c778;
  --goal: #f2454a;
  --mark: #fab529;
  --ink: #0f1013;
  --live: #ff454d;
  --warn: #ff9933;
  --radius: 18px;
  --display: "Barlow Condensed", "Arial Narrow", system-ui, sans-serif;
  --body: "Inter", system-ui, -apple-system, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ice);
  font: 15px/1.4 var(--body);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

/* ---------- top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 0 14px; }
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand-mark {
  width: 18px; height: 18px; align-self: center;
  border-radius: 50% 50% 4px 4px;
  background: linear-gradient(180deg, #5aa9ff 0%, #2f6fd6 100%);
  box-shadow: inset 0 -5px 0 var(--goal);
}
.brand-name { font: 800 24px/1 var(--display); letter-spacing: 0.02em; text-transform: uppercase; }
.brand-sub { font: 700 13px/1 var(--display); letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); }

.link {
  display: inline-flex; align-items: center; gap: 9px;
  padding: 7px 12px; border-radius: 999px; background: var(--panel-2);
  font-size: 13px; font-weight: 600; color: var(--ice); white-space: nowrap;
}
.bars { display: inline-flex; align-items: flex-end; gap: 2px; height: 14px; }
.bars i { display: block; width: 4px; border-radius: 1px; background: rgba(255, 255, 255, 0.18); }
.bars i:nth-child(1) { height: 25%; } .bars i:nth-child(2) { height: 50%; }
.bars i:nth-child(3) { height: 75%; } .bars i:nth-child(4) { height: 100%; }
.link[data-grade="1"] .bars i:nth-child(-n+1) { background: var(--warn); }
.link[data-grade="2"] .bars i:nth-child(-n+2) { background: var(--mark); }
.link[data-grade="3"] .bars i:nth-child(-n+3),
.link[data-grade="4"] .bars i:nth-child(-n+4) { background: var(--save); }
.link[data-grade="0"] { color: var(--muted); }

.banner {
  margin: 0 0 14px; padding: 12px 14px; border-radius: 14px; font-weight: 600; font-size: 14px;
  background: rgba(250, 181, 41, 0.16); border: 1px solid rgba(250, 181, 41, 0.45); color: var(--ice);
}
.banner.offline { background: rgba(255, 153, 51, 0.18); border-color: rgba(255, 153, 51, 0.55); }
.link-detail { color: var(--muted); font-size: 12px; margin-top: -6px; }

/* ---------- layout */
.layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
@media (min-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1.35fr) minmax(340px, 1fr); align-items: start; gap: 24px; }
}
.left, .right { display: grid; gap: 14px; min-width: 0; }

/* ---------- camera bar */
.camera-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.camera-select select {
  appearance: none; -webkit-appearance: none;
  background: var(--panel-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23e8f2ff' stroke-width='2' fill='none'/%3E%3C/svg%3E") no-repeat right 12px center;
  border: 1px solid var(--line); border-radius: 12px;
  padding: 9px 36px 9px 12px; font-weight: 600; max-width: 100%;
}
.camera-meta { color: var(--muted); font-size: 13px; display: flex; gap: 12px; flex-wrap: wrap; }
.camera-meta .ok { color: var(--save); }
.camera-meta .warn { color: var(--mark); }
.camera-meta .bad { color: var(--warn); font-weight: 600; }

/* ---------- camera battery */
.battery {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 12px;
  background: var(--panel-2); font: 700 15px/1 var(--body); font-variant-numeric: tabular-nums;
}
.battery .cap { font-size: 10px; letter-spacing: 0.12em; color: var(--muted); font-weight: 800; }
.battery.low { color: var(--warn); background: rgba(255, 153, 51, 0.16); }
.battery.mid { color: var(--mark); }
.battery.charging { color: var(--save); }
.banner.battery-low { background: rgba(255, 153, 51, 0.18); border-color: rgba(255, 153, 51, 0.55); }

/* ---------- preview */
.preview-off {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%;
  padding: 12px 16px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--panel); text-align: left;
}
.preview-off .po-title { font-weight: 700; }
.preview-off .po-sub { font-size: 12px; color: var(--muted); }
.preview-hide {
  position: absolute; top: 10px; right: 10px; z-index: 2; border: 0; border-radius: 999px; padding: 5px 10px;
  background: rgba(0, 0, 0, 0.6); color: #fff; font: 700 12px/1 var(--body);
}
.preview {
  position: relative; aspect-ratio: 16 / 9; border-radius: var(--radius);
  background: #000; overflow: hidden; border: 1px solid var(--line);
}
.preview img { width: 100%; height: 100%; object-fit: contain; display: block; }
.preview-empty {
  position: absolute; inset: 0; display: grid; place-content: center; text-align: center; gap: 6px; padding: 24px;
  background: radial-gradient(ellipse at 50% 120%, rgba(123, 217, 255, 0.12), transparent 60%);
}
.empty-title { font: 700 22px/1.1 var(--display); text-transform: uppercase; letter-spacing: 0.04em; }
.empty-sub { color: var(--muted); font-size: 14px; max-width: 34ch; }
.preview-badge {
  position: absolute; top: 10px; left: 10px; display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 9px; border-radius: 999px; background: rgba(0, 0, 0, 0.6);
  font: 700 12px/1 var(--display); letter-spacing: 0.12em;
}
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--live); animation: pulse 1.6s ease-in-out infinite; }
.preview-badge.stale .live-dot { background: var(--muted); animation: none; }
@keyframes pulse { 50% { opacity: 0.3; } }

/* ---------- scoreboard */
.scoreboard {
  display: grid; grid-template-columns: 1fr repeat(3, auto); gap: 22px; align-items: center;
  padding: 14px 18px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line);
}
.game { min-width: 0; }
.game-title { font: 700 22px/1.1 var(--display); text-transform: uppercase; letter-spacing: 0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.game-goalie { color: var(--muted); font-size: 13px; }
.stat { text-align: center; }
.stat-value { font: 800 30px/1 var(--display); font-variant-numeric: tabular-nums; }
.stat-value.save { color: var(--save); }
.stat-value.goal { color: var(--goal); }
.stat-label { font-size: 10px; font-weight: 700; letter-spacing: 0.14em; color: var(--muted); text-transform: uppercase; margin-top: 3px; }

/* ---------- capture buttons */
.captures { display: grid; gap: 12px; }
.capture {
  position: relative; display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 16px; align-items: center;
  text-align: left; border: 0; border-radius: 22px; padding: 18px 22px; min-height: 104px;
  color: var(--ink); touch-action: manipulation; user-select: none; -webkit-user-select: none;
  transition: transform 0.12s ease, filter 0.12s ease, box-shadow 0.2s ease;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 8px 24px -12px rgba(0, 0, 0, 0.8);
}
.capture svg { grid-row: 1 / 3; width: 40px; height: 40px; fill: currentColor; }
.capture-label { font: 800 40px/0.95 var(--display); text-transform: uppercase; letter-spacing: 0.03em; }
.capture-sub { font-size: 13px; font-weight: 600; opacity: 0.72; }
.capture-key {
  position: absolute; top: 12px; right: 14px; font: 700 12px/1 var(--body);
  padding: 4px 7px; border-radius: 6px; background: rgba(0, 0, 0, 0.14); opacity: 0.7;
}
@media (hover: none) { .capture-key { display: none; } }
.capture.save { background: linear-gradient(180deg, #33d485, #22a864); }
.capture.goal { background: linear-gradient(180deg, #f75a5e, #d7353a); }
.capture.mark { background: linear-gradient(180deg, #ffc443, #e79f10); }
.capture:active, .capture.pressed { transform: scale(0.97); filter: brightness(0.92); }
.capture.fired { animation: fired 0.5s ease-out; }
@keyframes fired {
  0% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.7); }
  100% { box-shadow: 0 0 0 18px rgba(255, 255, 255, 0); }
}
.captures.no-camera .capture { filter: saturate(0.25) brightness(0.7); }
.window-hint { margin: -2px 4px 0; color: var(--muted); font-size: 13px; }

/* ---------- period + undo */
.controls { display: flex; gap: 10px; align-items: stretch; }
.periods { display: flex; gap: 4px; padding: 4px; border-radius: 14px; background: var(--panel-2); flex: 1; }
.periods button {
  flex: 1; border: 0; background: transparent; border-radius: 10px; padding: 10px 0;
  font: 700 18px/1 var(--display); letter-spacing: 0.05em; color: var(--muted);
}
.periods button[aria-checked="true"] { background: var(--ice); color: var(--ink); }
.undo {
  border: 1px solid var(--line); background: var(--panel-2); border-radius: 14px; padding: 0 16px;
  font-weight: 600; font-size: 14px; white-space: nowrap;
}
.undo.armed { background: var(--warn); color: var(--ink); border-color: transparent; }

/* ---------- activity */
.feed-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.feed-head { display: flex; justify-content: space-between; align-items: center; font: 700 13px/1 var(--display); letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.room-chip {
  border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 4px 10px;
  font: 600 12px/1 var(--body); letter-spacing: 0.02em; text-transform: none; color: var(--muted);
}
.feed { list-style: none; margin: 0; padding: 0; display: grid; }
.feed li { display: grid; grid-template-columns: 10px 1fr auto; gap: 12px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.feed li:first-child { border-top: 0; }
.feed .swatch { width: 10px; height: 10px; border-radius: 3px; background: var(--muted); }
.feed .swatch.save { background: var(--save); }
.feed .swatch.goal { background: var(--goal); }
.feed .swatch.mark { background: var(--mark); }
.feed .title { font-weight: 600; }
.feed .detail { color: var(--muted); font-size: 13px; }
.feed .state { font-size: 12px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; padding: 4px 8px; border-radius: 999px; background: var(--panel-2); color: var(--muted); }
.feed .state.saved { color: var(--save); background: rgba(41, 199, 120, 0.12); }
.feed .state.failed, .feed .state.noreply { color: var(--warn); background: rgba(255, 153, 51, 0.14); }
.feed .state.received, .feed .state.sent, .feed .state.retrying, .feed .state.queued { color: var(--mark); }
.feed li.undone .title { text-decoration: line-through; color: var(--muted); }
.feed-empty { color: var(--muted); font-size: 14px; padding: 6px 0 2px; }

/* ---------- toast + dialog */
.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line); padding: 12px 18px; border-radius: 999px;
  font-weight: 600; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5); max-width: calc(100% - 32px);
}
.toast.error { background: #3a2410; border-color: rgba(255, 153, 51, 0.55); }

dialog {
  border: 1px solid var(--line); border-radius: 20px; background: var(--panel); color: var(--ice);
  padding: 24px; width: min(420px, calc(100% - 32px));
}
dialog::backdrop { background: rgba(0, 0, 0, 0.7); }
dialog h2 { margin: 0 0 6px; font: 800 26px/1 var(--display); text-transform: uppercase; }
dialog p { color: var(--muted); margin: 0 0 16px; }
dialog input { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); margin-bottom: 12px; }
dialog button { width: 100%; padding: 12px; border: 0; border-radius: 12px; background: var(--accent); color: var(--ink); font-weight: 700; }

@media (max-width: 420px) {
  .scoreboard { gap: 14px; padding: 12px 14px; }
  .stat-value { font-size: 26px; }
  .capture { min-height: 92px; }
  .capture-label { font-size: 36px; }
}
