:root {
  --bg: #07090d;
  --panel: #0e131a;
  --off: #151b24;
  --fg: #e6ecf2;
  --dim: #8a97a6;
  --accent: #6cc3ff;
  --danger: #ff6b6b;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
.hidden { display: none !important; }

/* The canvas */
.board { touch-action: none; user-select: none; }
.grid {
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  gap: 2px;
  width: 100%;
  aspect-ratio: var(--cols) / var(--rows);
}
.grid i, .legend i {
  display: block;
  aspect-ratio: 1;
  border-radius: 2px;
  background: var(--off);
  transition: background-color 1.4s ease-out, box-shadow 1.4s ease-out, outline-color .3s;
  outline: 2px solid transparent;
  outline-offset: -2px;
}
.grid i.on, .legend i.on { background: hsl(var(--h) 85% 56%); transition-duration: .12s; }
.grid i.ra, .legend i.ra { background: hsl(var(--h) 55% 74%); }
.grid i.fx, .legend i.fx { background: hsl(var(--h) 25% 62%); }
.grid i.un, .legend i.un { background: #6b7684; }
.grid i.hot, .legend i.hot { background: hsl(var(--h) 100% 66%); box-shadow: 0 0 6px 1px hsl(var(--h) 100% 66% / .9); }
.grid i.lk, .legend i.lk { outline-color: #fff; }

/* Colour legend (stage page); swatches reuse the grid classes above */
.legend { width: 100%; display: grid; grid-template-columns: 18px 1fr; gap: 7px 10px; align-items: center; font-size: .85rem; color: var(--dim); }
.legend i { width: 18px; height: 18px; }
.legend i.fade { background: hsl(200 45% 32%); }
.legend span { line-height: 1.2; }

/* Title slide */
body.title { overflow: hidden; }
body.title #stats { display: none; } /* the SSE patch replaces the element's class list, so hide by selector */
body.title .board.full { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 6px; }
body.title .grid { gap: 3px; width: min(100vw, 100vh * var(--cols) / var(--rows)); }
body.title .grid i { border-radius: 3px; }
body.title .overlay {
  position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  pointer-events: none; text-align: center;
}
body.title h1 {
  margin: 0; padding: .35em .8em; font-size: clamp(2.2rem, 6vw, 6rem); font-weight: 800; letter-spacing: -.02em;
  background: rgb(7 9 13 / .72); backdrop-filter: blur(6px); border-radius: .3em;
}
body.title .speaker { font-size: clamp(1.1rem, 2.4vw, 2.2rem); color: var(--fg); background: rgb(7 9 13 / .72); padding: .3em .9em; border-radius: .3em; margin: .6em 0 0; }
body.title .hint { color: var(--dim); background: rgb(7 9 13 / .72); padding: .2em .8em; border-radius: .3em; font-family: ui-monospace, monospace; }

/* Stage */
.stage-wrap { display: grid; grid-template-columns: 1fr 380px; gap: 16px; height: 100vh; padding: 12px; }
.stage .left { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.stage .board { flex: 0 0 auto; }
.stage .grid { width: min(100%, (100vh - 220px) * var(--cols) / var(--rows)); }
.stage aside { background: var(--panel); border-radius: 10px; padding: 14px; overflow: auto; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.stage .qr { width: 180px; height: 180px; border-radius: 8px; background: #fff; padding: 6px; }
.stage .url { font-family: ui-monospace, monospace; color: var(--accent); margin: 0; word-break: break-all; text-align: center; }
.controls { display: flex; flex-wrap: wrap; gap: 10px; }
.controls fieldset { border: 1px solid #243040; border-radius: 8px; padding: 8px 10px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 0; }
.controls legend { color: var(--dim); font-size: .8rem; padding: 0 4px; }
.controls label { display: flex; flex-direction: column; font-size: .8rem; color: var(--dim); gap: 2px; }
.controls input[type=range] { width: 160px; }
button {
  background: #1a2330; color: var(--fg); border: 1px solid #2b3a4d; border-radius: 6px; padding: 6px 10px;
  font: inherit; font-size: .9rem; cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.active { background: var(--accent); color: #05101a; border-color: var(--accent); }
button.danger { border-color: var(--danger); color: var(--danger); }

/* Stats panel */
.stats { width: 100%; font-size: .85rem; display: flex; flex-direction: column; gap: 4px; }
.stats .row { display: flex; justify-content: space-between; gap: 10px; }
.stats .row.big { font-size: 1.05rem; font-weight: 600; }
.stats .row.dim { color: var(--dim); font-size: .75rem; }
.stats .k { color: var(--dim); }
.stats .v { font-variant-numeric: tabular-nums; text-align: right; }
.stats .v b { color: var(--accent); font-weight: 600; }
.meter { height: 8px; border-radius: 4px; background: #1a2330; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--accent); transition: width .4s; }
.meter.mem span { background: #ffb454; }

/* Phone */
body.play { display: flex; flex-direction: column; min-height: 100vh; }
.play header { display: flex; align-items: center; gap: 10px; padding: 10px 12px; }
.play .swatch { width: 22px; height: 22px; border-radius: 6px; background: hsl(var(--h) 85% 56%); flex: none; }
.play .who { color: var(--dim); font-size: .85rem; white-space: nowrap; }
.play .msg { margin-left: auto; font-family: ui-monospace, monospace; font-size: .85rem; color: var(--accent); text-align: right; }
.play .board { padding: 0 6px; position: relative; }
.play .grid {
  gap: 1px; margin: 0 auto;
  /* Fit the header, grid and tool buttons in one screen: the grid is as wide as
     the window allows, or as wide as the height left over allows, whichever is less. */
  width: min(100%, (100vh - 150px) * var(--cols) / var(--rows));
  width: min(100%, (100dvh - 150px) * var(--cols) / var(--rows));
}
.play .grid i { border-radius: 1px; outline-width: 1px; outline-offset: -1px; }
.tools { display: flex; gap: 8px; padding: 10px 12px; }
.tools label {
  flex: 1; display: flex; flex-direction: column; align-items: center; padding: 8px 4px; border-radius: 8px;
  background: #1a2330; border: 1px solid #2b3a4d; font-weight: 600; cursor: pointer;
}
.tools label small { font-weight: 400; color: var(--dim); font-size: .7rem; }
.tools label.active { border-color: var(--accent); background: #12314a; }
.tools input { display: none; }
.play .stats { padding: 6px 12px 16px; }
/* Watch-only banner while the presenter has the audience paused. Taps pass
   through to the grid, so the server can answer with its own message. */
.gate { display: none; }
.play .gate {
  display: block; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  padding: 10px 16px; border-radius: 10px; background: rgb(7 9 13 / .85); border: 1px solid var(--accent);
  color: var(--fg); font-weight: 600; white-space: nowrap; pointer-events: none;
}
