:root {
  --bg: #121213; --panel: #1c1c1f; --line: #3a3a3c; --text: #f2f2f2; --dim: #9a9aa0;
  --green: #538d4e; --yellow: #b59f3b; --gray: #3a3a3c; --key: #818384; --red: #c0453a; --accent: #4f8cff;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { overscroll-behavior: none; }
#app { min-height: 100dvh; display: flex; flex-direction: column; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; border-radius: 6px; padding: 10px 14px; background: var(--line); font-weight: 600; touch-action: manipulation; }
button.primary { background: var(--green); }
button.danger { background: var(--red); }
button.link { background: none; padding: 4px 6px; color: var(--accent); font-weight: 500; }
button:disabled { opacity: .5; cursor: default; }
input, select { background: #0b0b0c; border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; width: 100%; }
label { display: block; font-size: 14px; color: var(--dim); margin: 10px 0 4px; }
h1 { font-size: 28px; margin: 0 0 4px; letter-spacing: .5px; }
h2 { font-size: 18px; margin: 0 0 10px; }
p { margin: 6px 0; }
.dim { color: var(--dim); }
.small { font-size: 13px; }
.wrap { width: 100%; max-width: 980px; margin: 0 auto; padding: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }
.grid2 { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
@media (max-width: 640px) { .grid2 { grid-template-columns: 1fr; } }

/* Top bar */
.bar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.bar .code { font-weight: 800; letter-spacing: 3px; font-size: 18px; }
.bar .timer { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 800; font-size: 20px; }
.timer.low { color: #ff6b5e; }
.pill { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--line); color: var(--text); text-transform: uppercase; letter-spacing: .5px; }

/* Players */
.players { list-style: none; padding: 0; margin: 0; }
.players li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid #2a2a2d; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #555; flex: none; }
.dot.on { background: #4cd964; }
.you { color: var(--accent); }

/* Game layout */
.game { flex: 1; display: grid; grid-template-columns: 1fr 300px; gap: 12px; padding: 8px 12px 0; max-width: 1100px; width: 100%; margin: 0 auto; min-height: 0; }
.play { display: flex; flex-direction: column; align-items: center; min-height: 0; }
.side { overflow: auto; }
.status { display: flex; gap: 10px; align-items: center; justify-content: center; margin: 4px 0 8px; flex-wrap: wrap; }
.board { display: grid; grid-template-rows: repeat(6, 1fr); gap: 5px; width: min(330px, 78vw, calc((100dvh - 330px) * 5 / 6)); min-width: 200px; aspect-ratio: 5 / 6; }
.brow { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; }
.tile { border: 2px solid var(--line); display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: clamp(18px, 6vw, 30px); text-transform: uppercase; user-select: none; }
.tile.filled { border-color: #565758; }
.t2 { background: var(--green); border-color: var(--green); }
.t1 { background: var(--yellow); border-color: var(--yellow); }
.t0 { background: var(--gray); border-color: var(--gray); }
.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

/* Keyboard */
.kb { width: 100%; max-width: 500px; margin: 10px auto 0; padding-bottom: max(8px, env(safe-area-inset-bottom)); user-select: none; }
.kr { display: flex; gap: 5px; margin-bottom: 6px; justify-content: center; }
.k { flex: 1; height: 54px; padding: 0; background: var(--key); border-radius: 4px; font-size: 14px; text-transform: uppercase; min-width: 0; }
.k.wide { flex: 1.5; font-size: 12px; }
.k.t2 { background: var(--green); } .k.t1 { background: var(--yellow); } .k.t0 { background: #3a3a3c; }
@media (max-height: 640px) { .k { height: 42px !important; } .kr { margin-bottom: 4px; } }

/* Standings */
.stand { list-style: none; margin: 0; padding: 0; }
.stand li { padding: 7px 6px; border-bottom: 1px solid #2a2a2d; display: grid; grid-template-columns: 28px 1fr auto; gap: 4px 8px; align-items: center; }
.stand .place { font-weight: 800; color: var(--dim); }
.stand .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stand .score { font-weight: 700; font-variant-numeric: tabular-nums; }
.stand .prog { grid-column: 2 / 4; display: flex; gap: 6px; align-items: center; }
.bar-bg { flex: 1; height: 6px; background: #2a2a2d; border-radius: 3px; overflow: hidden; }
.bar-fg { height: 100%; background: var(--green); }
.mini { display: inline-grid; grid-template-columns: repeat(5, 7px); gap: 1px; }
.mini i { width: 7px; height: 7px; background: #2a2a2d; }
.mini i.t2 { background: var(--green); } .mini i.t1 { background: var(--yellow); } .mini i.t0 { background: #555; }

/* Overlays */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.75); display: flex; align-items: center; justify-content: center; z-index: 20; padding: 16px; }
.big { font-size: 96px; font-weight: 900; }
.reveal { text-align: center; }
.reveal .word { font-size: 44px; font-weight: 900; letter-spacing: 8px; text-transform: uppercase; color: #8fd18a; }
.toast { position: fixed; top: 64px; left: 50%; transform: translateX(-50%); background: #f2f2f2; color: #111; font-weight: 700; padding: 10px 16px; border-radius: 6px; z-index: 30; max-width: 90vw; }

/* Results */
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 6px 8px; border-bottom: 1px solid #2a2a2d; text-align: left; white-space: nowrap; }
th { color: var(--dim); font-weight: 600; }
.scroll { overflow-x: auto; }
td.ok { color: #8fd18a; } td.miss { color: #ff8a80; }
.winner { font-size: 22px; font-weight: 800; }
.modes { display: grid; gap: 8px; }
.mode { border: 1px solid var(--line); border-radius: 8px; padding: 10px; text-align: left; background: #0f0f10; font-weight: 400; }
.mode.sel { border-color: var(--green); background: #16231a; }
.mode b { display: block; margin-bottom: 2px; }

/* Phones: everything above the keyboard has to fit on one screen. */
@media (max-width: 820px) {
  .game { grid-template-columns: 1fr; padding: 4px 8px 0; gap: 4px; }
  .side { order: -1; max-height: 17dvh; padding: 2px 10px !important; }
  .stand li { padding: 3px 4px; grid-template-columns: 22px 1fr auto auto; }
  .stand .prog { grid-column: auto; }
  .stand .bar-bg { display: none; }
  .status { margin: 2px 0 4px; }
  .board { width: min(330px, 78vw, calc((100dvh - 440px) * 5 / 6)); min-width: 170px; gap: 4px; }
  .brow { gap: 4px; }
  .kb { margin-top: 6px; }
  .k { height: 50px; }
  .bar { flex-wrap: nowrap; gap: 6px; padding: 6px 8px; }
  .bar .code { font-size: 16px; letter-spacing: 2px; }
  .bar .pill { font-size: 10px; padding: 2px 6px; }
  .bar .timer { font-size: 18px; }
}
