/* ═══════════════════════════════════════════════════════════════════════════
   Noughts and Crosses — black and green, like every other game in this room.
   ═══════════════════════════════════════════════════════════════════════════ */

/* THE RULE THAT MATTERS. Panels in this page are marked hidden BOTH by the
   `hidden` attribute and by a class, so this must win over any display rule the
   rest of the file sets — otherwise toggling the attribute alone leaves a panel
   stuck on screen (or, worse, never appearing). This bit this repo once already,
   on a cue that must never be invisible. */
[hidden] { display: none !important; }

*,
*::before,
*::after { box-sizing: border-box; }

:root {
  --bg: #000000;
  --surface: #121212;
  --surface-2: #181818;
  --surface-3: #282828;
  --border: #282828;
  --border-2: #404040;
  --text: #ffffff;
  --muted: #a7a7a7;
  --green: #1db954;
  --green-bright: #1ed760;
  --green-dim: rgba(29, 185, 84, 0.12);
  --green-glow: rgba(29, 185, 84, 0.28);
  --danger: #e91429;
  --amber: #e3a900;
  --radius: 10px;
  --mono: 'DM Mono', ui-monospace, monospace;
}

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', system-ui, -apple-system, sans-serif;
  font-size: 15px;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse 70% 50% at 12% 0%, rgba(29, 185, 84, 0.09) 0%, transparent 62%);
  pointer-events: none;
  z-index: 0;
}

.shell {
  position: relative;
  z-index: 1;
  max-width: 1080px;
  margin: 0 auto;
  padding: 20px 20px 40px;
}

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); }
.hidden { display: none !important; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }

/* ── header ─────────────────────────────────────────────────────────────── */

.header { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }

.home-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 1.5px;
  color: var(--muted);
  text-decoration: none;
  border: 1px solid var(--border-2);
  border-radius: 999px;
  padding: 5px 12px 5px 8px;
  transition: color .2s, border-color .2s;
}
.home-btn:hover { color: var(--green); border-color: var(--green); }
.home-btn svg { width: 14px; height: 14px; }

.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 2px solid var(--green);
  color: var(--green);
  font-family: var(--mono);
  font-size: 15px;
  box-shadow: 0 0 14px var(--green-glow);
}
.brand-text {
  font-family: 'Bebas Neue', sans-serif;
  letter-spacing: 2.5px;
  font-size: 17px;
}

.header-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.user-badge { font-family: var(--mono); font-size: 11px; color: var(--green); }

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border-2);
  background: var(--surface-2);
  color: var(--muted);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: border-color .2s, color .2s, background .2s;
}
.icon-btn:hover { border-color: var(--green); color: var(--green); background: var(--green-dim); }
.icon-btn svg { width: 17px; height: 17px; }

/* ── screens ────────────────────────────────────────────────────────────── */

.screen { display: none; }
.screen.active { display: block; }

.screen-title {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 34px;
  letter-spacing: 1px;
  margin: 0 0 6px;
}
.screen-sub { color: var(--muted); max-width: 70ch; margin: 0 0 18px; line-height: 1.5; }
.screen-sub strong { color: var(--green); }

/* The honesty notice about Sharp. Loud on purpose: a player who never wins has
   to know why before they conclude the game is broken. */
.honesty {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border: 1px solid var(--green);
  background: var(--green-dim);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 18px;
  font-size: 13.5px;
  line-height: 1.5;
}
.honesty-icon {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--green);
  color: #000;
  font-weight: 700;
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-size: 12px;
}
.honesty strong { color: var(--green-bright); }

/* ── menu ───────────────────────────────────────────────────────────────── */

.menu-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.mode-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.mode-card:hover { border-color: var(--border-2); }
.mode-icon { font-size: 26px; line-height: 1; }
.mode-name { font-family: 'Bebas Neue', sans-serif; font-size: 20px; letter-spacing: 1px; }
.mode-desc { color: var(--muted); font-size: 13px; line-height: 1.5; flex: 1; }
.mode-form { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.field-label { font-family: var(--mono); font-size: 10.5px; letter-spacing: 1.2px; color: var(--muted); }
.join-row { display: flex; gap: 8px; }

select, input[type="text"] {
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 14px;
  width: 100%;
}
select:focus, input[type="text"]:focus { outline: none; border-color: var(--green); }
#join-code { letter-spacing: 4px; font-family: var(--mono); max-width: 110px; }

.btn {
  background: var(--surface-3);
  border: 1px solid var(--border-2);
  color: var(--text);
  border-radius: 999px;
  padding: 9px 16px;
  font-family: inherit;
  font-size: 13.5px;
  cursor: pointer;
  transition: background .18s, border-color .18s, color .18s;
}
.btn:hover { border-color: var(--green); color: var(--green); background: var(--green-dim); }
.btn-primary { background: var(--green); border-color: var(--green); color: #04170a; font-weight: 600; }
.btn-primary:hover { background: var(--green-bright); color: #04170a; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn-danger:hover { border-color: var(--danger); color: var(--danger); background: rgba(233, 20, 41, 0.12); }

.banner {
  margin-top: 14px;
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border-2);
  font-size: 13px;
}
.banner.good { border-color: var(--green); color: var(--green); background: var(--green-dim); }
.banner.error { border-color: var(--danger); color: var(--danger); background: rgba(233, 20, 41, 0.1); }

/* ── the game screen ────────────────────────────────────────────────────── */

.hud {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 12px;
}
.hud-left { display: flex; align-items: center; gap: 10px; }
.turn-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 12px var(--green-glow);
}
.turn-dot.o { background: var(--amber); box-shadow: 0 0 12px rgba(227, 169, 0, 0.35); }
.hud-turns { display: flex; flex-direction: column; }
.hud-label { font-family: var(--mono); font-size: 10px; letter-spacing: 1.2px; color: var(--muted); }
.hud-value { font-family: 'Bebas Neue', sans-serif; font-size: 22px; letter-spacing: 1px; }
.hud-stats { display: flex; gap: 18px; flex-wrap: wrap; }
.hud-stat { display: flex; flex-direction: column; }
.hud-mode { font-size: 13.5px; }
.hud-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.online-strip {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 16px;
  margin-bottom: 12px;
  font-size: 13px;
}
.online-strip strong { font-family: var(--mono); color: var(--green); letter-spacing: 3px; }

.board-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 18px;
  align-items: start;
}

.board-holder { position: relative; }

.board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.square {
  position: relative;
  aspect-ratio: 1 / 1;
  /* The square shows its own number while it is empty, which is how the keyboard
     mapping teaches itself: the digit you press is the digit you can see. */
  display: grid;
  place-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: 'Bebas Neue', sans-serif;
  font-size: clamp(38px, 12vw, 66px);
  line-height: 1;
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s, box-shadow .15s;
  user-select: none;
}
.square::after {
  content: attr(data-label);
  position: absolute;
  left: 8px;
  bottom: 6px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--border-2);
}
.square[data-mark="X"], .square[data-mark="O"] { cursor: default; }
.square.x { color: var(--green); }
.square.o { color: var(--amber); }
.square:not(.taken):hover { border-color: var(--green); background: var(--green-dim); }
.square.locked { cursor: default; }
.square.locked:not(.taken):hover { border-color: var(--border); background: var(--surface); }
.square.cursor { border-color: var(--green); box-shadow: inset 0 0 0 2px var(--green-glow); }
.square.win {
  border-color: var(--green);
  background: var(--green-dim);
  box-shadow: 0 0 22px var(--green-glow);
  color: var(--green-bright);
}
.square.win.o { color: var(--green-bright); }

/* The winning line, struck through. */
.strike-layer { position: absolute; inset: 0; pointer-events: none; }
.strike {
  position: absolute;
  background: var(--green);
  border-radius: 4px;
  box-shadow: 0 0 12px var(--green-glow);
}
.strike.row {
  left: 3%;
  width: 94%;
  height: 5px;
  top: calc((100% / 3) * (var(--row) + 0.5));
  transform: translateY(-50%);
}
.strike.col {
  top: 3%;
  height: 94%;
  width: 5px;
  left: calc((100% / 3) * (var(--col) + 0.5));
  transform: translateX(-50%);
}
.strike.diag-down { left: 4%; top: 50%; width: 92%; height: 5px; transform: rotate(45deg); }
.strike.diag-up { left: 4%; top: 50%; width: 92%; height: 5px; transform: rotate(-45deg); }

/* ── the side panel: the teacher and the move list ──────────────────────── */

.side-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.panel-title {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 1.5px;
  color: var(--muted);
  margin: 0;
  text-transform: uppercase;
}

.teacher {
  border: 1px solid var(--green);
  background: var(--green-dim);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.teacher-value { font-family: 'Bebas Neue', sans-serif; font-size: 22px; letter-spacing: 1px; color: var(--green-bright); }
.teacher-count { font-family: var(--mono); font-size: 11.5px; color: var(--text); }
.teacher-note { margin: 0; font-size: 13px; color: var(--muted); line-height: 1.45; }

.move-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 220px;
  overflow-y: auto;
  font-family: var(--mono);
  font-size: 12.5px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.move-row { display: grid; grid-template-columns: 28px 1fr 1fr; gap: 6px; }
.mv-no { color: var(--muted); }
.mv-x { color: var(--green); }
.mv-o { color: var(--amber); }
.move-empty { color: var(--muted); font-size: 12.5px; }

/* ── overlay ────────────────────────────────────────────────────────────── */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 20px;
}
.overlay-card {
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: 14px;
  padding: 22px;
  max-width: 420px;
  text-align: center;
}
.overlay.win-x .overlay-card { border-color: var(--green); box-shadow: 0 0 30px var(--green-glow); }
.overlay.win-o .overlay-card { border-color: var(--amber); }
.overlay-title { font-family: 'Bebas Neue', sans-serif; font-size: 28px; letter-spacing: 1px; margin: 0 0 8px; }
.overlay-body { color: var(--muted); font-size: 13.5px; line-height: 1.55; margin: 0 0 16px; }
.overlay-actions { display: flex; gap: 10px; justify-content: center; }

/* ── settings ───────────────────────────────────────────────────────────── */

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
}
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.radio-row, .checkbox-row { display: flex; align-items: center; gap: 9px; font-size: 13.5px; }
.radio-row input, .checkbox-row input { accent-color: var(--green); width: 16px; height: 16px; }
.radio-row label, .checkbox-row label { cursor: pointer; }
.radio-row span { color: var(--text); }

/* ── phones ─────────────────────────────────────────────────────────────── */

@media (max-width: 780px) {
  .menu-grid { grid-template-columns: minmax(0, 1fr); }
  .board-wrap { grid-template-columns: minmax(0, 1fr); }
  .hud-actions { margin-left: 0; }
  .hud { gap: 12px; }
  .square { font-size: clamp(44px, 20vw, 70px); }
}

/* ── light mode ─────────────────────────────────────────────────────────── */

[data-theme="light"] {
  --bg: #ffffff;
  --surface: #f5f5f5;
  --surface-2: #eeeeee;
  --surface-3: #e0e0e0;
  --border: #d5d5d5;
  --border-2: #b4b4b4;
  --text: #101010;
  --muted: #555555;
  --green-dim: rgba(29, 185, 84, 0.14);
}
[data-theme="light"] .btn-primary { color: #ffffff; }
[data-theme="light"] .square.cursor { box-shadow: inset 0 0 0 2px rgba(29, 185, 84, 0.4); }
