/* ============ base ============ */
:root {
  --bg: #0a0a0b;
  --text: #f5f5f7;
  --text-dim: #9a9aa1;
  --line: rgba(255, 255, 255, 0.1);
  --line-strong: rgba(255, 255, 255, 0.18);
  --glass: rgba(24, 24, 27, 0.66);
  --glass-heavy: rgba(32, 32, 36, 0.85);
  --fill: rgba(255, 255, 255, 0.06);
  --fill-hover: rgba(255, 255, 255, 0.11);
  --ink: #f5f5f7;
  --ink-text: #0a0a0b;
  --me: #f5f5f7;
  --them: #6e6e73;
  --good: #5aa671;
  --bad: #cf6a5b;
  --radius: 22px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
  background:
    radial-gradient(900px 600px at 15% 0%, rgba(255, 255, 255, 0.045), transparent 60%),
    radial-gradient(900px 700px at 90% 100%, rgba(255, 255, 255, 0.035), transparent 60%),
    var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; cursor: pointer; border: none; color: inherit; background: none; }
input { font: inherit; }
[hidden] { display: none !important; }

.screen { position: fixed; inset: 0; display: flex; flex-direction: column; }

.glass {
  background: var(--glass);
  backdrop-filter: blur(24px) saturate(1.3);
  -webkit-backdrop-filter: blur(24px) saturate(1.3);
  border: 1px solid var(--line);
}

/* ============ buttons ============ */
.btn {
  border-radius: 999px;
  padding: 10px 24px;
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
  transition: transform 0.12s ease, background 0.12s ease, opacity 0.12s ease;
  user-select: none;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.35; cursor: default; }
.btn-primary { background: var(--ink); color: var(--ink-text); }
.btn-primary:hover:not(:disabled) { background: #dcdce0; }
.btn-ghost { background: var(--fill); color: var(--text); border: 1px solid var(--line); }
.btn-ghost:hover:not(:disabled) { background: var(--fill-hover); }
.btn-big { font-size: 1.05rem; padding: 14px 36px; }
.btn-tiny { font-size: 0.8rem; padding: 6px 14px; }

/* ============ home ============ */
#screen-home { align-items: center; justify-content: center; }

.home-card {
  text-align: center;
  max-width: 480px;
  width: calc(100% - 40px);
  padding: 56px 44px;
  border-radius: 36px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.5);
  display: flex; flex-direction: column; gap: 20px; align-items: center;
}
.logo-big { font-size: 2.7rem; font-weight: 800; letter-spacing: -0.03em; }
.logo-big span, .logo-small span { color: var(--text-dim); font-weight: 600; }
.tagline { color: var(--text-dim); font-size: 1.05rem; font-weight: 500; line-height: 1.5; letter-spacing: -0.01em; }
.home-games-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.home-game-chip {
  background: var(--fill); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 16px; font-size: 0.85rem; font-weight: 600; color: var(--text-dim);
}
.fineprint { color: var(--text-dim); font-size: 0.78rem; font-weight: 500; }

#friend-box { display: flex; flex-direction: column; gap: 12px; width: 100%; }
.friend-hint { color: var(--text-dim); font-size: 0.9rem; font-weight: 500; }
.friend-link-row { display: flex; gap: 8px; }
.friend-link-row input {
  flex: 1; min-width: 0; background: var(--fill); border: 1px solid var(--line);
  border-radius: 999px; padding: 10px 18px; color: var(--text); font-size: 0.88rem; outline: none;
}
.friend-waiting { color: var(--text-dim); font-weight: 600; font-size: 0.88rem; display: flex; align-items: center; gap: 8px; justify-content: center; }
.pulse-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-dim); animation: pulse 1.4s infinite; flex-shrink: 0; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

/* ============ topbar ============ */
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 20px;
  border-left: none; border-right: none; border-top: none;
}
.logo-small { font-size: 1.15rem; font-weight: 800; letter-spacing: -0.02em; }
.status-pill {
  display: flex; align-items: center; gap: 8px;
  background: var(--fill); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 16px; font-size: 0.82rem; color: var(--text-dim); font-weight: 600;
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-dim); }
.status-dot.live { background: var(--good); }
.scoreboard {
  margin-left: auto;
  display: flex; align-items: center; gap: 8px;
  background: var(--fill); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 18px;
}
.score-name { font-size: 0.78rem; color: var(--text-dim); font-weight: 600; }
.score-num { font-size: 0.95rem; font-weight: 800; }
.score-dash { color: var(--text-dim); }

/* ============ layout ============ */
.layout {
  flex: 1; display: grid; gap: 14px; padding: 14px;
  grid-template-columns: 300px 1fr 300px;
  min-height: 0;
}

/* ---- videos ---- */
.video-col { display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.video-tile {
  position: relative; border-radius: var(--radius); overflow: hidden;
  background: #161618; border: 1px solid var(--line);
}
.remote-tile { flex: 1.4; min-height: 120px; }
.local-tile { flex: 1; min-height: 90px; }
.video-tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.local-tile video { transform: scaleX(-1); }
.video-label {
  position: absolute; left: 10px; bottom: 8px;
  background: rgba(20, 20, 22, 0.72); backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: 999px; padding: 3px 12px; font-size: 0.72rem; font-weight: 700; color: var(--text);
}
.video-overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px;
  background: #131315;
  color: var(--text-dim); font-weight: 600; font-size: 0.9rem; text-align: center; padding: 12px;
}

.controls { display: flex; gap: 8px; }
.ctrl-btn {
  flex: 1; padding: 12px 6px; border-radius: 999px;
  background: var(--glass-heavy); backdrop-filter: blur(12px);
  border: 1px solid var(--line);
  font-size: 0.85rem; font-weight: 700;
  transition: background 0.12s ease, transform 0.12s ease;
}
.ctrl-btn:hover { background: var(--fill-hover); }
.ctrl-btn:active { transform: scale(0.96); }
.ctrl-skip { background: var(--ink); color: var(--ink-text); border-color: var(--ink); }
.ctrl-skip:hover { background: #dcdce0; }

/* ---- stage ---- */
.stage {
  border-radius: var(--radius);
  display: flex; align-items: stretch; justify-content: center; min-height: 0; overflow: auto;
}
.stage-panel {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; padding: 28px; text-align: center;
}
.stage-panel h2 { font-weight: 800; letter-spacing: -0.02em; }
.stage-title { font-size: 1.5rem; }
.stage-sub, #stage-idle-sub { color: var(--text-dim); font-size: 0.95rem; font-weight: 500; }
#stage-idle-title { font-size: 1.7rem; }

.gamebox-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px; width: 100%; max-width: 580px;
}
.game-card {
  background: var(--glass-heavy); border: 1px solid var(--line); border-radius: 20px;
  padding: 26px 16px; display: flex; flex-direction: column; gap: 6px; align-items: center;
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}
.game-card:hover {
  transform: translateY(-3px); border-color: var(--line-strong);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
}
.game-card .gc-name { font-weight: 800; font-size: 1.02rem; letter-spacing: -0.01em; }
.game-card .gc-desc { font-size: 0.78rem; color: var(--text-dim); font-weight: 500; line-height: 1.4; }

/* ---- active game ---- */
.stage-game { justify-content: flex-start; gap: 12px; }
.game-header { width: 100%; display: flex; align-items: center; gap: 10px; }
.game-header h2 { font-size: 1.1rem; margin-right: auto; }
.game-turn, .game-timer {
  font-size: 0.8rem; font-weight: 700; border-radius: 999px; padding: 5px 14px;
  background: var(--fill); border: 1px solid var(--line); color: var(--text-dim);
}
.game-turn.mine { background: var(--ink); color: var(--ink-text); border-color: var(--ink); }
.game-timer {
  position: relative; overflow: hidden;
  min-width: 64px; text-align: center; font-variant-numeric: tabular-nums;
}
.game-timer-fill {
  position: absolute; inset: 0; width: 100%;
  background: var(--ink); transition: width 0.1s linear;
}
.game-timer-num { position: relative; color: #fff; mix-blend-mode: difference; }
.game-timer.low { border-color: var(--bad); }
.game-timer.low .game-timer-fill { background: var(--bad); }
.game-timer.low .game-timer-num { mix-blend-mode: normal; color: var(--bad); }
.game-banner {
  display: flex; align-items: center; gap: 7px;
  font-size: 0.78rem; font-weight: 800; letter-spacing: 0.12em;
  text-transform: uppercase; color: #fff; white-space: nowrap;
}
.game-banner .banner-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
#game-area { flex: 1; width: 100%; display: flex; align-items: center; justify-content: center; min-height: 0; }

.result-text { font-size: 1.6rem; }
.result-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

/* ---- 8-ball pool ---- */
.pool-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; width: 100%; }
.pool-canvas {
  width: 100%; max-width: 760px; border-radius: 18px;
  border: 1px solid var(--line);
  touch-action: none; display: block; cursor: crosshair;
}
.pool-status { font-size: 0.85rem; color: var(--text-dim); font-weight: 600; min-height: 1.2em; }

/* ---- connect four ---- */
.c4-wrap { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.c4-board {
  display: grid; grid-template-columns: repeat(7, minmax(32px, 52px)); gap: 8px;
  background: #14141a; border: 4px solid #2c2c38;
  padding: 16px; border-radius: 26px;
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.5), 0 8px 26px rgba(0, 0, 0, 0.45);
}
.c4-cell {
  aspect-ratio: 1; border-radius: 50%; background: #0c0c11;
  border: 1px solid var(--line);
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.6);
  transition: background 0.15s ease, box-shadow 0.15s ease;
}
.c4-cell.playable:hover { cursor: pointer; background: #1a1a22; }
/* Disc colour comes from red/blue so both players see the same board. */
.c4-cell.red { background: #c0453a; border-color: #d1584d; box-shadow: inset 0 3px 6px rgba(0, 0, 0, 0.35); }
.c4-cell.blue { background: #3f6fb5; border-color: #5484c8; box-shadow: inset 0 3px 6px rgba(0, 0, 0, 0.35); }
/* Translucent hover drop preview in the landing cell (desktop only). */
.c4-cell.ghost { border-style: dashed; }
.c4-cell.ghost.red { background: rgba(192, 69, 58, 0.35); border-color: rgba(209, 88, 77, 0.6); }
.c4-cell.ghost.blue { background: rgba(63, 111, 181, 0.35); border-color: rgba(84, 132, 200, 0.6); }
.c4-cell.win { box-shadow: 0 0 0 3px var(--good); }

/* ---- wordle ---- */
.wordle-wrap { display: flex; gap: 30px; align-items: flex-start; justify-content: center; flex-wrap: wrap; }
.wordle-side { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.wordle-side-label { font-size: 0.72rem; font-weight: 700; color: var(--text-dim); letter-spacing: 0.08em; }
.wordle-board { display: grid; grid-template-rows: repeat(6, auto); gap: 5px; }
.wordle-row { display: grid; grid-template-columns: repeat(5, auto); gap: 5px; }
.wordle-tile {
  width: 42px; height: 42px; border-radius: 10px;
  border: 1px solid var(--line-strong); background: var(--fill);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 1.1rem; text-transform: uppercase;
}
.wordle-board.mini .wordle-tile { width: 19px; height: 19px; border-radius: 6px; font-size: 0; }
.wordle-tile.filled { border-color: var(--text-dim); }
.wordle-tile.g { background: #5a9a55; border-color: #5a9a55; color: #fff; }
.wordle-tile.y { background: #b5a04c; border-color: #b5a04c; color: #fff; }
.wordle-tile.b { background: #3a3a3e; border-color: #3a3a3e; color: #9a9aa1; }
.wordle-kb { display: flex; flex-direction: column; gap: 5px; align-items: center; margin-top: 6px; }
.wordle-kb-row { display: flex; gap: 4px; }
.wordle-key {
  min-width: 29px; padding: 9px 6px; border-radius: 8px;
  background: var(--fill); border: 1px solid var(--line);
  font-size: 0.75rem; font-weight: 700; text-transform: uppercase;
}
.wordle-key:hover { background: var(--fill-hover); }
.wordle-key.wide { min-width: 50px; }
.wordle-key.g { background: #5a9a55; border-color: #5a9a55; color: #fff; }
.wordle-key.y { background: #b5a04c; border-color: #b5a04c; color: #fff; }
.wordle-key.b { background: #232326; border-color: #232326; color: #66666c; }
.wordle-status { font-size: 0.82rem; color: var(--text-dim); font-weight: 600; min-height: 1.2em; }
.wordle-clock {
  flex-basis: 100%; text-align: center; order: -1;
  font-size: 1.5rem; font-weight: 800; letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums; color: var(--text);
  background: var(--glass-heavy); border: 1px solid var(--line);
  border-radius: 999px; padding: 5px 0; margin-bottom: 4px;
}
.wordle-clock.urgent { color: #fff; background: var(--bad, #c0453a); border-color: var(--bad, #c0453a); }

/* ---- chat ---- */
.chat-col { display: flex; flex-direction: column; min-height: 0; border-radius: var(--radius); overflow: hidden; }
.chat-head { padding: 13px 18px; font-weight: 800; font-size: 0.95rem; border-bottom: 1px solid var(--line); }
.chat-messages { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 85%; padding: 8px 14px; border-radius: 18px; font-size: 0.88rem; font-weight: 500; line-height: 1.4; overflow-wrap: break-word; }
.msg.me { align-self: flex-end; background: var(--ink); color: var(--ink-text); border-bottom-right-radius: 5px; }
.msg.them { align-self: flex-start; background: var(--fill); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.msg.sys { align-self: center; background: none; color: var(--text-dim); font-size: 0.75rem; text-align: center; }
.chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.chat-form input {
  flex: 1; min-width: 0; background: var(--fill); border: 1px solid var(--line);
  border-radius: 999px; padding: 9px 18px; color: var(--text); outline: none;
}
.chat-form input:focus { border-color: var(--line-strong); background: var(--fill-hover); }
.btn-send { padding: 9px 18px; font-size: 0.85rem; }

/* ============ modal ============ */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(10px);
  display: flex; align-items: center; justify-content: center;
}
.modal {
  border-radius: 30px;
  background: var(--glass-heavy);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
  padding: 40px 36px; max-width: 400px; width: calc(100% - 40px);
  display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center;
  animation: pop 0.16s ease;
}
.modal h2 { font-size: 1.3rem; font-weight: 800; letter-spacing: -0.02em; }
@keyframes pop { from { transform: scale(0.94); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-sub { color: var(--text-dim); font-size: 0.88rem; font-weight: 500; }
.modal-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 8px; }

/* ============ misc ============ */
.spinner {
  width: 30px; height: 30px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--text-dim);
  animation: spin 0.9s linear infinite;
}
.spinner.big { width: 48px; height: 48px; border-width: 4px; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--ink-text);
  border-radius: 999px; padding: 11px 24px; font-weight: 600; font-size: 0.9rem; z-index: 60;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  animation: pop 0.16s ease;
}

/* ---- hangman ---- */
.hm-wrap { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.hm-cat { font-size: 0.78rem; font-weight: 800; letter-spacing: 0.1em; color: var(--text-dim); }
.hm-svg { width: 180px; height: 200px; }
.hm-frame { stroke: var(--text-dim); stroke-width: 4; stroke-linecap: round; }
.hm-part { stroke: var(--text); stroke-width: 4; stroke-linecap: round; fill: none; }
.hm-count { font-size: 0.95rem; font-weight: 800; color: var(--bad); letter-spacing: 0.04em; }
.hm-word { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.hm-blank {
  width: 30px; height: 42px; border-bottom: 3px solid var(--line-strong);
  display: flex; align-items: flex-end; justify-content: center;
  font-weight: 800; font-size: 1.5rem; text-transform: uppercase; line-height: 1;
}
.hm-blank.filled { border-bottom-color: var(--good); }
.hm-status { font-size: 0.82rem; color: var(--text-dim); font-weight: 600; min-height: 1.2em; text-align: center; }
.hm-kb { display: flex; flex-direction: column; gap: 5px; align-items: center; }
.hm-kb-row { display: flex; gap: 4px; }
.hm-key {
  min-width: 30px; padding: 10px 6px; border-radius: 8px;
  background: var(--fill); border: 1px solid var(--line);
  font-size: 0.8rem; font-weight: 700; text-transform: uppercase;
}
.hm-key:hover:not(:disabled) { background: var(--fill-hover); }
.hm-key:disabled { cursor: default; }
.hm-key.good { background: #3d6a3a; border-color: #3d6a3a; color: #fff; }
.hm-key.bad { background: #1c1c1f; border-color: #1c1c1f; color: #5a5a60; }

/* ============ responsive ============ */
@media (max-width: 1020px) {
  body { overflow: auto; }
  .screen { position: static; min-height: 100dvh; }
  .layout { grid-template-columns: 1fr; grid-template-rows: auto auto 320px; }
  .video-col { flex-direction: row; height: 190px; }
  .video-tile { flex: 1; }
  .controls { flex-direction: column; width: 76px; }
  .ctrl-btn { padding: 8px 4px; font-size: 0.78rem; }
  .stage { min-height: 440px; }
  .scoreboard { padding: 4px 12px; }
  .wordle-tile { width: 34px; height: 34px; font-size: 0.95rem; }
}
