:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --text: #121213;
  --muted: #6a6a6a;
  --line: #d3d6da;
  --line-strong: #878a8c;
  --key: #d3d6da;
  --correct: #6aaa64;
  --present: #c9b458;
  --absent: #787c7e;
  --danger: #b3261e;
  --shadow: 0 18px 55px rgba(18, 18, 19, .12);
}

html[data-theme="dark"] {
  --bg: #121213;
  --surface: #1b1b1d;
  --text: #f8f8f8;
  --muted: #a7a7a7;
  --line: #3a3a3c;
  --line-strong: #818384;
  --key: #818384;
  --absent: #3a3a3c;
  --shadow: 0 18px 55px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; }
button { color: inherit; }
.hidden { display: none !important; }

.app-shell { min-height: 100vh; }
.site-header {
  height: 58px;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 0 max(12px, env(safe-area-inset-left));
}
.brand {
  justify-self: center;
  color: var(--text);
  text-decoration: none;
  font-size: 25px;
  line-height: 1;
  font-weight: 900;
  letter-spacing: -.7px;
}
.brand span:last-child { color: var(--correct); }
.icon-button {
  width: 40px; height: 40px; border: 0; background: transparent; padding: 8px;
  display: grid; place-items: center; cursor: pointer; border-radius: 50%;
}
.icon-button:hover { background: color-mix(in srgb, var(--text) 7%, transparent); }
.icon-button svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

.home-view {
  min-height: calc(100vh - 59px);
  max-width: 640px;
  margin: 0 auto;
  padding: 10vh 24px 48px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.word-mark, .example-row { display: flex; gap: 5px; }
.mini-tile {
  width: 44px; height: 44px; border: 2px solid var(--line);
  display: grid; place-items: center; font-weight: 800; font-size: 23px; color: var(--text);
}
.mini-tile.correct, .tile.correct { background: var(--correct); border-color: var(--correct); color: #fff; }
.mini-tile.present, .tile.present { background: var(--present); border-color: var(--present); color: #fff; }
.mini-tile.absent, .tile.absent { background: var(--absent); border-color: var(--absent); color: #fff; }
.home-view h1 { font-size: clamp(38px, 7vw, 58px); line-height: .98; letter-spacing: -2.3px; margin: 34px 0 20px; }
.home-copy { max-width: 510px; color: var(--muted); font-size: 18px; line-height: 1.55; margin: 0; }
.home-actions { display: flex; gap: 12px; margin-top: 34px; }
.primary-button, .secondary-button {
  min-height: 50px; padding: 0 24px; border-radius: 999px; border: 1px solid var(--text);
  font-weight: 750; cursor: pointer; transition: transform .12s, opacity .12s, background .12s;
}
.primary-button { background: var(--text); color: var(--bg); }
.secondary-button { background: transparent; color: var(--text); }
.primary-button:hover, .secondary-button:hover { transform: translateY(-1px); }
.primary-button:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.tiny-note { margin-top: 20px; color: var(--muted); font-size: 12px; }

.setup-view { max-width: 520px; margin: 0 auto; padding: 30px 20px 60px; }
.back-button { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 8px 0; }
.setup-card { margin-top: 28px; padding: 35px; border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); background: var(--surface); }
.eyebrow { color: var(--correct); font-weight: 800; font-size: 11px; letter-spacing: 1.6px; margin: 0 0 7px; }
.setup-card h1 { margin: 0 0 10px; font-size: 31px; letter-spacing: -1px; }
.setup-card > p:not(.eyebrow) { color: var(--muted); line-height: 1.45; margin-top: 0; }
form label { display: block; margin: 21px 0 7px; font-weight: 700; font-size: 13px; }
input, select {
  width: 100%; min-height: 50px; border: 2px solid var(--line); border-radius: 7px;
  background: var(--bg); color: var(--text); padding: 0 14px; outline: none;
}
input:focus, select:focus { border-color: var(--correct); }
.code-input { letter-spacing: 6px; font-weight: 800; text-transform: uppercase; }
.full-width { width: 100%; margin-top: 27px; border-radius: 7px; }

.game-view { max-width: 1120px; margin: 0 auto; display: grid; grid-template-columns: minmax(510px, 1fr) 320px; min-height: calc(100vh - 59px); }
.game-main { border-right: 1px solid var(--line); padding: 0 30px 35px; }
.room-strip { min-height: 61px; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; color: var(--muted); font-size: 12px; font-weight: 700; }
.status-dot { width: 8px; height: 8px; display: inline-block; border-radius: 50%; background: var(--present); margin-right: 7px; }
.status-dot.live { background: var(--correct); box-shadow: 0 0 0 4px color-mix(in srgb, var(--correct) 18%, transparent); }
.room-code-button { justify-self: center; border: 1px solid var(--line); background: var(--surface); display: flex; align-items: center; gap: 8px; border-radius: 7px; height: 38px; padding: 0 11px; cursor: pointer; }
.room-code-button span { font-size: 9px; letter-spacing: 1px; color: var(--muted); }
.room-code-button strong { letter-spacing: 2px; font-size: 13px; }
.room-code-button svg { width: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.timer { justify-self: end; color: var(--text); font-size: 16px; font-variant-numeric: tabular-nums; font-weight: 800; }
.timer.urgent { color: var(--danger); animation: pulse 1s infinite; }

.play-panel { display: flex; flex-direction: column; align-items: center; }
.round-label { color: var(--muted); font-size: 10px; letter-spacing: 1.4px; font-weight: 800; margin: 20px 0 12px; }
.board { width: min(350px, 100%); height: 420px; display: grid; grid-template-rows: repeat(6, 1fr); gap: 5px; padding: 0 0 14px; }
.board-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; }
.tile { border: 2px solid var(--line); display: grid; place-items: center; font-size: 30px; font-weight: 800; text-transform: uppercase; user-select: none; }
.tile.filled { border-color: var(--line-strong); animation: pop .08s ease-in-out; }
.tile.reveal { animation: flip .55s ease both; }
.board.shake { animation: shake .35s; }
.keyboard { width: min(510px, 100%); display: flex; flex-direction: column; gap: 7px; margin-top: 3px; }
.key-row { display: flex; justify-content: center; gap: 5px; }
.key {
  height: 54px; flex: 1; max-width: 43px; border: 0; border-radius: 4px; background: var(--key); color: var(--text);
  font-size: 13px; font-weight: 800; cursor: pointer; text-transform: uppercase; padding: 0 2px;
}
.key.wide { max-width: 65px; font-size: 10px; }
.key.correct { background: var(--correct); color: #fff; }
.key.present { background: var(--present); color: #fff; }
.key.absent { background: var(--absent); color: #fff; }

.lobby-panel, .results-panel { min-height: 610px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 35px 20px; }
.lobby-icon { display: flex; gap: 6px; margin-bottom: 25px; }
.lobby-icon span { width: 54px; height: 54px; display: grid; place-items: center; background: var(--correct); color: #fff; font-size: 27px; font-weight: 900; transform: rotate(-3deg); }
.lobby-icon span:last-child { background: var(--present); transform: rotate(4deg); }
.lobby-panel h1, .results-panel h1 { font-size: 35px; letter-spacing: -1.2px; margin: 0 0 8px; }
.lobby-panel > p, .results-panel > p { color: var(--muted); max-width: 390px; line-height: 1.5; }
.lobby-panel .primary-button, .results-panel .primary-button { margin-top: 20px; min-width: 180px; }
.host-note { font-size: 12px !important; }
.answer-word { color: var(--text); letter-spacing: 5px; margin-left: 5px; }
.result-board { display: flex; gap: 3px; margin: 16px 0 0; }
.result-board span { width: 28px; height: 28px; background: var(--line); }

.players-panel { padding: 28px 24px; background: color-mix(in srgb, var(--surface) 96%, var(--text)); }
.players-heading { display: flex; align-items: end; justify-content: space-between; margin-bottom: 20px; }
.players-heading h2 { margin: 0; font-size: 22px; }
.player-count { color: var(--muted); font-size: 12px; font-weight: 700; }
.players-list { display: flex; flex-direction: column; gap: 8px; }
.player-card { display: grid; grid-template-columns: 37px 1fr auto; gap: 10px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.avatar { width: 37px; height: 37px; border-radius: 50%; display: grid; place-items: center; background: color-mix(in srgb, var(--correct) 20%, var(--bg)); color: var(--correct); font-weight: 850; }
.player-name { display: flex; align-items: center; gap: 5px; font-size: 13px; font-weight: 750; min-width: 0; }
.player-name span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crown { color: var(--present); font-size: 12px; }
.online-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--correct); }
.player-meta { margin-top: 5px; display: flex; gap: 3px; }
.progress-square { width: 9px; height: 9px; border-radius: 1px; background: var(--line); }
.progress-square.used { background: var(--absent); }
.progress-square.solved { background: var(--correct); }
.player-score { text-align: right; font-weight: 850; font-size: 14px; }
.player-score small { display: block; font-size: 8px; color: var(--muted); letter-spacing: .8px; margin-top: 2px; }
.score-help { border-top: 1px solid var(--line); margin-top: 22px; padding-top: 16px; display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--muted); line-height: 1.4; }
.score-help strong { color: var(--text); font-size: 12px; }

.help-dialog { width: min(520px, calc(100% - 28px)); color: var(--text); background: var(--surface); border: 0; border-radius: 12px; padding: 30px; box-shadow: var(--shadow); }
.help-dialog::backdrop { background: rgba(0, 0, 0, .5); }
.help-dialog h2 { margin-top: 0; }
.help-dialog p { line-height: 1.5; font-size: 14px; }
.help-dialog .example-row { margin-top: 22px; }
.help-dialog .mini-tile { width: 38px; height: 38px; font-size: 20px; }
.help-dialog hr { border: 0; border-top: 1px solid var(--line); margin: 24px 0; }
.muted { color: var(--muted); }
.dialog-close { float: right; border: 0; background: none; color: var(--muted); font-size: 28px; cursor: pointer; }
.toast { position: fixed; left: 50%; top: 75px; transform: translate(-50%, -15px); background: var(--text); color: var(--bg); border-radius: 6px; padding: 11px 15px; font-size: 13px; font-weight: 750; opacity: 0; pointer-events: none; transition: .2s; z-index: 10; box-shadow: var(--shadow); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes pop { 50% { transform: scale(1.08); } }
@keyframes flip { 0% { transform: rotateX(0); } 45% { transform: rotateX(90deg); } 55% { transform: rotateX(90deg); } 100% { transform: rotateX(0); } }
@keyframes shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }
@keyframes pulse { 50% { opacity: .55; } }

@media (max-width: 820px) {
  .game-view { grid-template-columns: 1fr; }
  .game-main { border-right: 0; padding: 0 12px 24px; }
  .players-panel { border-top: 1px solid var(--line); padding: 22px 16px 40px; }
  .players-list { display: grid; grid-template-columns: repeat(2, 1fr); }
  .board { height: min(390px, 50vh); }
}

@media (max-width: 520px) {
  .site-header { height: 51px; }
  .brand { font-size: 21px; }
  .home-view { min-height: calc(100vh - 52px); padding-top: 8vh; }
  .word-mark .mini-tile { width: 37px; height: 37px; font-size: 19px; }
  .home-view h1 { font-size: 39px; }
  .home-copy { font-size: 16px; }
  .home-actions { width: 100%; flex-direction: column; }
  .home-actions button { width: 100%; }
  .setup-card { padding: 25px 20px; box-shadow: none; }
  .room-strip { grid-template-columns: 1fr auto; }
  .room-strip > div:first-child { display: none; }
  .room-code-button { justify-self: start; }
  .board { width: min(330px, 100%); height: min(396px, 49vh); }
  .tile { font-size: 26px; }
  .key { height: 52px; font-size: 12px; }
  .players-list { grid-template-columns: 1fr; }
  .lobby-panel, .results-panel { min-height: 520px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
