:root {
  --bg: #070a10;
  --panel: #0e1420;
  --panel-2: #121a2b;
  --line: #1c2638;
  --line-2: #2a3857;
  --text: #e6ecf7;
  --muted: #8b98b3;
  --accent: #3fe0b8;
  --chute: #f5b544;
  --bad: #ff5a6a;
  --good: #57e38a;
  --shard: #7cc8ff;
  --radius: 14px;
  --mono: ui-monospace, "SFMono-Regular", "Cascadia Code", Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }

body {
  background:
    radial-gradient(1100px 520px at 85% -10%, rgba(63, 224, 184, 0.07), transparent 60%),
    radial-gradient(800px 480px at -10% 110%, rgba(124, 200, 255, 0.06), transparent 60%),
    var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}

.mono { font-family: var(--mono); }
[hidden] { display: none !important; }

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px 16px 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* header */
.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 14px; }
.mark {
  width: 38px; height: 38px; border-radius: 10px; position: relative;
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  box-shadow: 0 0 24px rgba(63, 224, 184, 0.22);
}
.mark::before {
  content: ""; position: absolute; left: 11px; top: 9px; width: 14px; height: 14px;
  border-radius: 4px; background: var(--text); box-shadow: 0 0 0 2px var(--accent);
}
.mark::after {
  content: ""; position: absolute; left: 6px; right: 6px; bottom: 5px; height: 3px;
  border-radius: 2px; background: var(--accent);
}
h1 { margin: 0; font-size: 22px; letter-spacing: -0.01em; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.hud { display: flex; gap: 6px; flex-wrap: wrap; }
.stat {
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 6px 12px; min-width: 64px;
}
.label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.val { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.pip {
  margin-top: 5px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--shard); box-shadow: 0 0 10px rgba(124, 200, 255, 0.6);
  transition: background 0.15s, box-shadow 0.15s;
}
.pip.is-spent { background: transparent; box-shadow: inset 0 0 0 2px rgba(255, 90, 106, 0.6); }

/* board */
.stage { display: flex; flex-direction: column; gap: 10px; }
.board-wrap {
  position: relative; width: 100%;
  border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--line-2);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.04);
  background: var(--bg);
}
canvas { display: block; width: 100%; touch-action: none; }
canvas:focus { outline: none; }
canvas:focus-visible, .btn:focus-visible, .room:focus-visible, .dpad button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

.overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  background: rgba(7, 10, 16, 0.72);
  backdrop-filter: blur(4px);
  overflow-y: auto;
}
.card {
  width: min(440px, 100%);
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line-2); border-radius: var(--radius);
  padding: 22px 22px 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  margin: auto;
}
.card--wide { width: min(720px, 100%); }
.kicker { margin: 0; font: 600 11px var(--mono); text-transform: uppercase; letter-spacing: 0.12em; color: var(--accent); }
.card h2 { margin: 4px 0 8px; font-size: 26px; letter-spacing: -0.02em; }
.lede { margin: 0 0 16px; color: var(--muted); font-size: 14px; max-width: 60ch; }
.note { margin: 12px 0 0; color: var(--muted); font-size: 13px; }

.rooms {
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px;
  margin-bottom: 16px;
}
.room {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 10px; cursor: pointer; min-width: 0;
  font: inherit;
  transition: border-color 0.15s, transform 0.15s, background 0.15s;
}
.room:hover:not(:disabled) { border-color: var(--accent); transform: translateY(-1px); }
.room__n { font-size: 11px; color: var(--muted); }
.room__name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.room__meta { font-size: 10.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.room.is-done { border-color: rgba(63, 224, 184, 0.35); }
.room.is-done .room__n { color: var(--accent); }
.room.is-current { box-shadow: inset 0 0 0 1px var(--chute); }
.room.is-locked { opacity: 0.4; cursor: not-allowed; }

.row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text);
  font: 600 14px var(--sans); padding: 9px 16px; border-radius: 10px; cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #04140f; border-color: var(--accent); }
.btn.primary:hover { background: #6cf0cf; }
.btn.small { font-size: 12.5px; padding: 6px 10px; }
kbd {
  font: 600 10.5px var(--mono); color: var(--muted);
  border: 1px solid var(--line-2); border-radius: 4px; padding: 0 4px; margin-left: 4px;
}

.tally {
  display: grid; grid-template-columns: auto 1fr; gap: 6px 18px;
  margin: 8px 0 0; padding: 12px 14px;
  background: rgba(0, 0, 0, 0.2); border: 1px solid var(--line); border-radius: 10px;
}
.tally dt { color: var(--muted); font-size: 13px; }
.tally dd { margin: 0; text-align: right; font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.card .row { margin-top: 16px; }

.toast {
  position: absolute; left: 50%; top: 14px; transform: translate(-50%, -8px);
  background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 999px;
  padding: 5px 14px; font: 600 12px var(--mono); color: var(--text);
  opacity: 0; pointer-events: none; transition: opacity 0.18s, transform 0.18s;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

.bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.hint { margin: 0; color: var(--muted); font-size: 13.5px; min-height: 1.5em; flex: 1 1 280px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* touch controls: only shown on coarse pointers */
.dpad { display: none; }
.is-touch .dpad {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
}
.dpad button {
  height: 54px; border-radius: 12px; font-size: 20px;
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line-2);
  touch-action: manipulation; -webkit-user-select: none; user-select: none;
}
.dpad button:active { background: var(--line-2); border-color: var(--accent); }

/* legend */
.legend {
  display: flex; flex-wrap: wrap; gap: 8px 18px;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); color: var(--muted); font-size: 12.5px;
}
.legend div { display: flex; align-items: center; gap: 8px; }
.sw { width: 14px; height: 14px; display: inline-block; border-radius: 3px; flex: none; }
.sw-spike { background: var(--bad); clip-path: polygon(0 100%, 25% 0, 50% 100%, 75% 0, 100% 100%); border-radius: 0; }
.sw-chute { background: rgba(245, 181, 68, 0.18); box-shadow: inset 0 0 0 2px var(--chute); }
.sw-saw { background: #e9edf5; border-radius: 50%; }
.sw-flag { background: var(--good); clip-path: polygon(0 0, 100% 35%, 0 70%); border-radius: 0; }
.sw-shard { background: var(--shard); clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); border-radius: 0; }
.sw-exit { border-radius: 50%; box-shadow: inset 0 0 0 2px var(--accent), 0 0 8px rgba(63, 224, 184, 0.6); }

@media (max-width: 760px) {
  .rooms { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hud { width: 100%; }
  .stat { flex: 1 1 0; min-width: 0; padding: 5px 8px; }
  .card { padding: 16px; }
  .card h2 { font-size: 22px; }
  .overlay { position: fixed; z-index: 10; align-items: flex-start; }
}

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