:root {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #f7f7f5;
  background: #101110;
  font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at 20% 0%, #242824 0, #101110 42%); }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }

.app-shell { width: min(1480px, 96vw); margin: 0 auto; padding: 28px 0 48px; }
.topbar { display: flex; justify-content: space-between; align-items: end; gap: 24px; margin-bottom: 20px; }
h1 { margin: 2px 0 0; font-size: clamp(2rem, 4vw, 3.5rem); letter-spacing: -.055em; }
h2 { margin: 0; letter-spacing: -.025em; }
.tagline { margin: 4px 0 0; color: #adb4ad; }
.eyebrow { font-size: .72rem; font-weight: 800; letter-spacing: .15em; color: #8f9b90; }
.alpha-note { padding: 8px 12px; border: 1px solid #393f39; border-radius: 999px; color: #b7c0b7; font-size: .82rem; }

.panel { background: rgba(27, 29, 27, .96); border: 1px solid #343834; border-radius: 18px; box-shadow: 0 18px 45px rgba(0,0,0,.18); }
.hidden { display: none !important; }
.muted { color: #8f978f; font-size: .86rem; }

.setup-panel { max-width: 720px; padding: 28px; }
.setup-panel h2 { margin-bottom: 18px; }
.setup-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 18px; }
label { display: grid; gap: 7px; color: #aab1aa; font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; }
input { width: 100%; border: 1px solid #3b423b; background: #151715; color: #fff; border-radius: 10px; padding: 12px; outline: none; }
input:focus { border-color: #8fa98e; box-shadow: 0 0 0 3px rgba(143,169,142,.12); }

button { border: 0; border-radius: 10px; padding: 11px 14px; font-weight: 750; transition: transform .12s ease, background .12s ease, border-color .12s ease; }
button:active { transform: translateY(1px); }
.primary { background: #e7f36b; color: #181a13; }
.primary:hover { background: #f0fb7c; }
.secondary, .mode { background: #242824; color: #d6dbd6; border: 1px solid #3b413b; }
.secondary:hover, .mode:hover { background: #2e332e; }
.mode.active { background: #e5eadf; color: #171a17; border-color: #e5eadf; }
.wide { width: 100%; }

.scorebar { display: grid; grid-template-columns: 1fr 1.1fr 1fr; overflow: hidden; margin-bottom: 14px; }
.player-card, .turn-card { padding: 15px 18px; min-height: 76px; display: flex; flex-direction: column; justify-content: center; }
.player-card:last-child { text-align: right; }
.player-card.active { background: #232923; }
.player-name { font-weight: 800; }
.player-score { font-size: 1.65rem; font-weight: 900; letter-spacing: -.04em; }
.turn-card { align-items: center; border-left: 1px solid #343834; border-right: 1px solid #343834; text-align: center; }

.game-grid { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 14px; align-items: start; }
.board-panel { padding: 16px; min-width: 0; }
.board-heading { display: flex; justify-content: space-between; gap: 16px; align-items: center; margin-bottom: 12px; }
.legend { display: flex; flex-wrap: wrap; gap: 10px; color: #8d958d; font-size: .7rem; }
.legend span { display: flex; align-items: center; gap: 5px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.letter { background: #526c86; }.dot.word { background: #806548; }.dot.define { background: #695785; }.dot.start { background: #7b8148; }

.board { width: 100%; aspect-ratio: 1; display: grid; grid-template-columns: repeat(13, 1fr); gap: 3px; background: #0f110f; border-radius: 12px; padding: 5px; user-select: none; }
.cell { position: relative; min-width: 0; border: 1px solid #313631; border-radius: 5px; background: #1a1d1a; color: #697269; display: grid; place-items: center; font-size: clamp(.45rem, .65vw, .7rem); font-weight: 800; overflow: hidden; }
.cell:hover { border-color: #5c685c; }
.cell.bonus-LETTER_BOOST { background: #202a34; color: #8da4ba; }
.cell.bonus-WORD_BOOST { background: #332a21; color: #b39779; }
.cell.bonus-DEFINE_BOOST { background: #2f273b; color: #a593be; }
.cell.bonus-START { background: #30321f; color: #b4bb72; }
.tile { width: 86%; height: 86%; display: grid; place-items: center; border-radius: 7px; background: #e7dfc6; color: #1e211d; font-size: clamp(.7rem, 1.7vw, 1.3rem); font-weight: 900; box-shadow: inset 0 -2px 0 rgba(0,0,0,.15), 0 2px 4px rgba(0,0,0,.25); position: relative; }
.tile .value { position: absolute; right: 5px; bottom: 2px; font-size: .48em; }
.tile.pending { outline: 2px solid #e7f36b; background: #f3eccf; }

.controls-panel { padding: 20px; display: grid; gap: 15px; position: sticky; top: 12px; }
.rack { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; min-height: 52px; }
.rack-tile { aspect-ratio: .85; border-radius: 8px; border: 2px solid transparent; background: #e7dfc6; color: #1d201d; padding: 0; font-size: 1.15rem; font-weight: 900; position: relative; }
.rack-tile .value { position: absolute; right: 4px; bottom: 2px; font-size: .55rem; }
.rack-tile.selected { border-color: #e7f36b; transform: translateY(-3px); }
.rack-tile.used { opacity: .28; }
.rack-tile.exchange-selected { border-color: #c486ff; transform: translateY(-3px); }
.mode-row, .action-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.selection-summary { min-height: 36px; padding: 10px 11px; border-radius: 9px; background: #151715; border: 1px solid #303530; }
.message { min-height: 0; border-radius: 10px; padding: 0; font-size: .86rem; line-height: 1.35; }
.message:not(:empty) { padding: 11px 12px; background: #151715; border: 1px solid #343934; }
.message.good { border-color: #637a54; color: #cce8bd; }
.message.bad { border-color: #825452; color: #f0bdb8; }
.history-block { border-top: 1px solid #343834; padding-top: 14px; }
.history { display: grid; gap: 7px; margin-top: 8px; max-height: 170px; overflow: auto; }
.history-row { display: flex; justify-content: space-between; gap: 12px; color: #abb2ab; font-size: .8rem; }
.history-row strong { color: #eef1ee; }

.modal { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(4,5,4,.78); backdrop-filter: blur(8px); z-index: 50; padding: 20px; }
.modal-card { width: min(700px, 95vw); background: #1d201d; border: 1px solid #444b44; border-radius: 20px; padding: 24px; box-shadow: 0 30px 90px rgba(0,0,0,.5); }
.definition-head { display: flex; justify-content: space-between; align-items: start; gap: 20px; margin-bottom: 18px; }
.definition-head h2 { margin-top: 4px; font-size: 2.25rem; }
.pos-pill { display: inline-block; margin-top: 6px; border: 1px solid #414741; color: #aab1aa; border-radius: 999px; padding: 4px 8px; font-size: .7rem; }
.timer { min-width: 82px; text-align: center; font-size: 2rem; font-weight: 900; border-radius: 12px; padding: 8px; background: #121412; color: #e7f36b; font-variant-numeric: tabular-nums; }
.timer.danger { color: #ff8b82; }
.definition-options { display: grid; gap: 9px; }
.definition-option { text-align: left; background: #292d29; color: #f1f3f1; border: 1px solid #414741; padding: 14px 15px; line-height: 1.35; }
.definition-option:hover { background: #343934; border-color: #697469; }

@media (max-width: 980px) {
  .game-grid { grid-template-columns: 1fr; }
  .controls-panel { position: static; }
  .rack { max-width: 520px; }
}

@media (max-width: 620px) {
  .app-shell { width: 98vw; padding-top: 14px; }
  .topbar { align-items: start; flex-direction: column; gap: 10px; padding: 0 10px; }
  .alpha-note { font-size: .7rem; }
  .setup-grid { grid-template-columns: 1fr; }
  .scorebar { grid-template-columns: 1fr 1fr; }
  .turn-card { grid-column: 1 / -1; grid-row: 2; border: 0; border-top: 1px solid #343834; }
  .board-panel { padding: 6px; border-radius: 10px; }
  .board-heading { padding: 8px; margin-bottom: 2px; }
  .legend { display: none; }
  .board { gap: 1px; padding: 2px; }
  .cell { border-radius: 2px; font-size: 0; }
  .tile { border-radius: 3px; font-size: .72rem; }
  .tile .value { right: 2px; bottom: 0; }
  .controls-panel { border-radius: 12px; }
}

/* Keep rack slots stable while planned tiles are on the board. */
.opponent-planning .rack-tile.used { visibility: hidden; }

.opponent-planning .controls-panel .selection-summary { display: block; min-height: 0; padding: 6px 8px; font-size: .75rem; }
