:root {
  --bg: #07111c;
  --panel: #0f2133;
  --line: #1f3d57;
  --text: #e8f4ff;
  --muted: #8fa6bb;
  --accent: #38e8ff;
  --accent-ink: #032530;
  --gold: #ffe066;
  --danger: #ff6b8a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, "Segoe UI", Roboto, sans-serif;
}

canvas { display: none; }
body.playing canvas { display: block; }
body.playing #lobby { display: none; }

.card {
  max-width: 460px;
  margin: 40px auto;
  padding: 28px 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
}

h1 { margin: 0; font-size: 2.2rem; letter-spacing: 0.02em; }
h1 span { color: var(--accent); }
.tag { margin: 4px 0 22px; color: var(--muted); }

label { display: block; margin: 14px 0 6px; font-weight: 600; }
label small { font-weight: 400; color: var(--muted); }

input {
  width: 100%;
  padding: 14px;
  font-size: 1.2rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
}
input:focus { outline: 2px solid var(--accent); }
input.code { text-transform: uppercase; letter-spacing: 0.3em; }

button {
  display: block;
  width: 100%;
  margin-top: 14px;
  padding: 16px;
  font-size: 1.15rem;
  font-weight: 700;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
}
button:disabled { opacity: 0.4; cursor: default; }
.primary { background: var(--accent); color: var(--accent-ink); }
.secondary { background: transparent; color: var(--text); border: 1px solid var(--line); }
.danger { background: var(--danger); color: #2a0610; }

.status { min-height: 1.4em; color: var(--muted); }

details { margin-top: 18px; color: var(--muted); }
summary { cursor: pointer; color: var(--text); font-weight: 600; }
details li { margin: 6px 0; }
.pu { font-weight: 700; }
.pu.cyan { color: #3cf0ff; }
.pu.green { color: #5cff7a; }
.pu.orange { color: #ffa63c; }

.foot { margin-top: 22px; text-align: center; }
a { color: var(--accent); }

.exit {
  display: none;
  position: fixed;
  top: 12px;
  right: 12px;
  width: auto;
  margin: 0;
  padding: 8px 16px;
  font-size: 0.95rem;
  background: rgba(15, 33, 51, 0.85);
  color: var(--text);
  border: 1px solid var(--line);
}
body.playing .exit { display: block; }

/* ---- teacher screen ---- */
body.teacher { padding: 24px; }

.t-head {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  justify-content: space-between;
  align-items: flex-end;
}
.t-label { color: var(--muted); font-size: 1.1rem; text-transform: uppercase; letter-spacing: 0.08em; }
.t-code { font-size: clamp(3rem, 10vw, 6.5rem); font-weight: 900; letter-spacing: 0.15em; color: var(--accent); }
.t-link { color: var(--muted); font-size: 0.95rem; word-break: break-all; }
.t-timer-box { text-align: right; }
.t-timer { font-size: clamp(3rem, 10vw, 6.5rem); font-weight: 900; color: var(--gold); font-variant-numeric: tabular-nums; }

.t-controls { display: flex; flex-wrap: wrap; gap: 10px; margin: 20px 0; }
.t-controls button { width: auto; margin: 0; padding: 12px 18px; font-size: 1rem; }

.setup { max-width: 640px; margin: 20px 0; }

.board { width: 100%; border-collapse: collapse; font-size: clamp(1.1rem, 2.4vw, 1.8rem); }
.board th { text-align: left; color: var(--muted); font-weight: 600; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.board td { padding: 10px 12px; border-bottom: 1px solid var(--line); }
.board .rank { color: var(--gold); font-weight: 800; width: 3ch; }
.board .score { font-weight: 800; font-variant-numeric: tabular-nums; }
.board .lives { color: var(--danger); letter-spacing: 0.1em; }
.board .tag { color: var(--muted); font-size: 0.7em; }
.board tr.offline td { opacity: 0.45; }
.board .empty { color: var(--muted); text-align: center; padding: 30px; }
.board tbody tr:first-child:not(.offline) .rank::after { content: " \2605"; }

/* ---- spectator view ---- */
body.spectator {
  height: 100vh;
  overflow: hidden;
  background: radial-gradient(ellipse at center, #0c2236 0%, #050c14 100%);
}
body.spectator canvas {
  display: block;
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 0;
}
.s-head {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  z-index: 3;
}
.s-title { font-size: 1.3rem; font-weight: 700; }
.s-title span { color: var(--accent); }
.s-title b { color: var(--accent); letter-spacing: 0.12em; }
.s-round { font-size: 1.5rem; font-weight: 800; color: var(--gold); font-variant-numeric: tabular-nums; }
.s-grid {
  position: fixed;
  top: 56px;
  left: 0;
  right: 0;
  bottom: 0;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  grid-auto-rows: min-content;
  justify-content: center;
  align-content: center;
  gap: 12px;
  padding: 12px;
}
.s-view {
  position: relative;
  aspect-ratio: 16 / 10;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: zoom-in;
}
.s-view[hidden] { display: none; }
.s-label, .s-sub {
  position: absolute;
  left: 10px;
  right: 10px;
  display: flex;
  gap: 10px;
  align-items: baseline;
  z-index: 3;
  text-shadow: 0 1px 3px #000;
  pointer-events: none;
}
.s-label { top: 8px; font-size: 1.15rem; font-weight: 700; }
.s-sub { bottom: 8px; font-size: 0.95rem; color: var(--muted); }
.s-rank { color: var(--gold); }
.s-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.s-score { font-variant-numeric: tabular-nums; }
body.focus .s-view:not(.focused) { visibility: hidden; }
.s-view.focused {
  position: fixed;
  inset: 56px 0 0 0;
  aspect-ratio: auto;
  border-radius: 0;
  cursor: zoom-out;
}
.s-view.focused .s-label { font-size: 2rem; top: 16px; left: 24px; right: 24px; }
.s-view.focused .s-sub { font-size: 1.3rem; bottom: 16px; left: 24px; }
.s-empty {
  position: fixed;
  top: 45%;
  left: 0;
  right: 0;
  text-align: center;
  color: var(--muted);
  font-size: 1.3rem;
}
.s-empty[hidden] { display: none; }
.t-controls a.button {
  display: inline-block;
  padding: 12px 18px;
  font-size: 1rem;
  font-weight: 700;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  text-decoration: none;
}
