:root {
  --bg: #07101f;
  --bg-2: #0e1730;
  --panel: rgba(17, 29, 56, 0.92);
  --panel-2: #162447;
  --ink: #f5f8ff;
  --muted: #a9b4cf;
  --line: rgba(255,255,255,.09);
  --purple: #8b5cf6;
  --blue: #38bdf8;
  --green: #34d399;
  --yellow: #fbbf24;
  --red: #fb7185;
  --shadow: 0 22px 60px rgba(0,0,0,.34);
  --radius: 22px;
}

* { box-sizing: border-box; }
html { color-scheme: dark; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 12%, rgba(56,189,248,.15), transparent 28rem),
    radial-gradient(circle at 85% 18%, rgba(139,92,246,.17), transparent 30rem),
    linear-gradient(160deg, #06101c, #0a1024 60%, #101431);
  font-family: Inter, ui-rounded, "SF Pro Rounded", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .48; }

.app-shell { max-width: 1440px; margin: 0 auto; padding: 0 22px 48px; }
.site-header {
  height: 78px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.brand {
  color: var(--ink);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
}

.brand-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--blue), var(--purple));
  box-shadow: 0 10px 24px rgba(56,189,248,.2);
}

.header-actions { display: flex; gap: 8px; }

.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.05);
  color: white;
}

.screen { display: none; padding-top: 34px; }
.screen-active { display: block; }

#menuScreen.screen-active {
  display: grid;
  grid-template-columns: 1.4fr .8fr;
  gap: 28px;
  align-items: stretch;
}

.hero-card,
.feature-card,
.panel,
.board-panel,
.side-panel > div,
.rack-panel,
.submitted-panel {
  border: 1px solid var(--line);
  background: linear-gradient(160deg, rgba(20,33,66,.95), rgba(12,22,44,.95));
  box-shadow: var(--shadow);
}

.hero-card {
  border-radius: 32px;
  padding: clamp(26px,4vw,54px);
}

.eyebrow {
  color: #93c5fd;
  font-size: .76rem;
  text-transform: uppercase;
  letter-spacing: .16em;
  font-weight: 900;
}

h1 {
  font-size: clamp(3rem, 7vw, 6.6rem);
  line-height: .9;
  margin: 18px 0;
  letter-spacing: -.06em;
}

h1 span {
  background: linear-gradient(90deg, #67e8f9, #a78bfa 55%, #f9a8d4);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero-copy {
  max-width: 650px;
  color: #c6d0e8;
  font-size: 1.08rem;
  line-height: 1.65;
}

.menu-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap: 12px;
  margin-top: 34px;
}

.menu-card {
  text-align: left;
  min-height: 98px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: rgba(255,255,255,.045);
  border-radius: 18px;
  padding: 18px;
  display: flex;
  align-items: center;
  gap: 15px;
  transition: .18s ease;
}

.menu-card:hover {
  transform: translateY(-3px);
  border-color: rgba(103,232,249,.4);
  background: rgba(255,255,255,.08);
}

.menu-card.primary-card {
  background: linear-gradient(135deg, rgba(56,189,248,.18), rgba(139,92,246,.22));
}

.menu-icon { font-size: 1.8rem; width: 42px; }
.menu-card strong, .menu-card small { display: block; }
.menu-card strong { font-size: 1rem; }

.menu-card small {
  margin-top: 5px;
  color: var(--muted);
  line-height: 1.25;
}

.how-link,
.back-link,
.text-btn {
  color: #9bdcf8;
  border: 0;
  background: transparent;
  padding: 14px 0;
  font-weight: 800;
}

.menu-side {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.feature-card {
  border-radius: 28px;
  padding: 28px;
  flex: 1;
  overflow: hidden;
}

.feature-badge {
  display: inline-flex;
  color: #052014;
  background: #6ee7b7;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: .68rem;
  letter-spacing: .12em;
  font-weight: 1000;
}

.feature-card h2 { font-size: 2rem; margin: 22px 0 8px; }
.feature-card p { color: var(--muted); line-height: 1.55; }

.mini-board {
  display: grid;
  grid-template-columns: repeat(4,1fr);
  gap: 8px;
  margin-top: 28px;
  transform: rotate(-2deg);
}

.mini-board span {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: #12203c;
  font-weight: 1000;
  background: linear-gradient(145deg,#fff7d8,#ffd86b);
  box-shadow: inset 0 -5px 0 rgba(125,74,0,.12), 0 8px 15px rgba(0,0,0,.15);
}

.stat-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.stat-preview span {
  flex: 1;
  min-width: 110px;
  text-align: center;
  padding: 14px 10px;
  border-radius: 15px;
  background: rgba(255,255,255,.05);
  border: 1px solid var(--line);
  color: #cbd5e1;
  font-size: .82rem;
}

.panel {
  max-width: 840px;
  margin: 30px auto;
  border-radius: var(--radius);
  padding: 32px;
}

.panel.narrow { max-width: 520px; }
.panel h2 { font-size: 2.4rem; margin: 9px 0; }
.panel p { color: var(--muted); line-height: 1.55; }

.field { display: block; margin: 22px 0; }
.field span {
  display: block;
  font-size: .82rem;
  font-weight: 800;
  margin-bottom: 8px;
  color: #cbd5e1;
}

.field input {
  width: 100%;
  border: 1px solid var(--line);
  background: #0b1530;
  color: white;
  border-radius: 14px;
  padding: 14px 15px;
  outline: none;
}

#gameCodeInput {
  text-transform: uppercase;
  letter-spacing: .18em;
  font-weight: 900;
}

.field input:focus {
  border-color: #67e8f9;
  box-shadow: 0 0 0 3px rgba(103,232,249,.12);
}

.host-code-box {
  margin: 22px 0;
  padding: 19px;
  border: 1px dashed rgba(103,232,249,.35);
  border-radius: 17px;
  text-align: center;
  background: rgba(56,189,248,.06);
}

.host-code-box small,
.host-code-box span {
  display: block;
  color: var(--muted);
}

.host-code-box strong {
  display: block;
  margin: 8px;
  font-size: 2rem;
  letter-spacing: .2em;
}

.status-line { min-height: 1.5em; }

.btn {
  border: 0;
  border-radius: 14px;
  padding: 13px 18px;
  font-weight: 900;
  color: white;
  transition: transform .15s ease, filter .15s ease;
}

.btn:hover:not(:disabled) {
  transform: translateY(-2px);
  filter: brightness(1.08);
}

.btn-primary {
  background: linear-gradient(135deg,#0ea5e9,#7c3aed);
  box-shadow: 0 12px 28px rgba(59,130,246,.2);
}

.btn-secondary {
  background: rgba(255,255,255,.09);
  border: 1px solid var(--line);
}

.btn-warning {
  background: linear-gradient(135deg,#d97706,#f59e0b);
  color: #1a1200;
}

.btn-wide { width: 100%; }

.game-topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  margin-bottom: 18px;
}

.round-label { margin-top: 5px; color: var(--muted); }

.phase-pill {
  padding: 9px 14px;
  border-radius: 999px;
  background: rgba(103,232,249,.1);
  border: 1px solid rgba(103,232,249,.22);
  color: #a5f3fc;
  font-size: .82rem;
  font-weight: 900;
}

.score-box {
  justify-self: end;
  text-align: right;
}

.score-box small { display: block; color: var(--muted); }
.score-box strong { font-size: 2rem; }

.game-layout {
  display: grid;
  grid-template-columns: minmax(0,1fr) 260px;
  gap: 18px;
}

.board-panel {
  border-radius: 24px;
  padding: 18px;
  min-width: 0;
}

.board-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  margin-bottom: 16px;
}

.board-head h2 {
  margin: 0 0 4px;
  font-size: clamp(1.25rem,2.2vw,1.8rem);
}

.board-head p {
  margin: 0;
  color: var(--muted);
  font-size: .9rem;
}

.timer-orb {
  flex: 0 0 auto;
  width: 70px;
  height: 70px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%,#67e8f9,#2563eb 65%,#312e81);
  border: 3px solid rgba(255,255,255,.22);
  box-shadow: 0 0 0 7px rgba(59,130,246,.09), 0 12px 30px rgba(37,99,235,.28);
}

.timer-orb span {
  font-size: 1.8rem;
  font-weight: 1000;
}

.timer-orb.pulse { animation: timerPulse .5s ease; }

@keyframes timerPulse {
  50% {
    transform: scale(1.12);
    box-shadow: 0 0 0 14px rgba(59,130,246,.05);
  }
}

.tile-board {
  --cols: 10;
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0,1fr));
  gap: clamp(4px,.65vw,9px);
  perspective: 1000px;
}

.tile {
  position: relative;
  aspect-ratio: 1;
  border: 0;
  background: transparent;
  padding: 0;
  border-radius: 13px;
  transform-style: preserve-3d;
  transition: transform .45s cubic-bezier(.2,.8,.2,1), opacity .25s ease;
}

.tile-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform .46s cubic-bezier(.2,.8,.2,1);
}

.tile.face-down .tile-inner { transform: rotateY(180deg); }

.tile-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: inherit;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255,255,255,.28);
}

.tile-front {
  color: #18213d;
  background: linear-gradient(145deg,#fff7da,#f8c84f);
  box-shadow: inset 0 -5px 0 rgba(133,86,9,.16), 0 5px 12px rgba(0,0,0,.18);
}

.tile-front .letter {
  font-weight: 1000;
  font-size: clamp(.74rem,2.0vw,1.55rem);
  line-height: 1;
}

.tile-front .points {
  position: absolute;
  right: 7px;
  bottom: 5px;
  font-size: clamp(.42rem,.8vw,.62rem);
  font-weight: 1000;
  opacity: .7;
}

.tile-back {
  transform: rotateY(180deg);
  background:
    linear-gradient(135deg, rgba(255,255,255,.12) 25%, transparent 25%) -5px 0/10px 10px,
    linear-gradient(225deg, rgba(255,255,255,.1) 25%, transparent 25%) -5px 0/10px 10px,
    linear-gradient(135deg,#0ea5e9,#6d28d9);
  box-shadow: inset 0 0 0 4px rgba(6,15,35,.25), 0 6px 12px rgba(0,0,0,.2);
}

.tile.can-grab:hover {
  transform: translateY(-3px) scale(1.05);
  filter: brightness(1.16);
}

.tile.claimed {
  opacity: 0;
  transform: scale(.6) translateY(18px);
  pointer-events: none;
}

.tile.failed { animation: tileFail .35s ease; }

@keyframes tileFail {
  25%,75% { transform: translateX(-4px); }
  50% { transform: translateX(5px); }
}

.board-message {
  margin-top: 14px;
  padding: 11px 14px;
  border-radius: 12px;
  text-align: center;
  font-weight: 900;
  background: rgba(52,211,153,.11);
  color: #a7f3d0;
  border: 1px solid rgba(52,211,153,.22);
}

.hidden { display: none !important; }

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.players-card,
.round-stats-card {
  border-radius: 20px;
  padding: 16px;
}

.card-title-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.card-title-row h3 { margin: 0; }
.card-title-row > span {
  color: var(--muted);
  font-size: .78rem;
}

.connection-badge { color: #bbf7d0 !important; }

.players-list {
  margin-top: 14px;
  display: grid;
  gap: 10px;
}

.player-row {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  gap: 9px;
  align-items: center;
  background: rgba(255,255,255,.04);
  border-radius: 11px;
  padding: 10px;
}

.player-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
}

.player-row small { color: var(--muted); }

.round-stats-card dl { margin: 12px 0 0; }

.round-stats-card dl div {
  display: flex;
  justify-content: space-between;
  border-top: 1px solid var(--line);
  padding: 10px 0;
}

.round-stats-card dt { color: var(--muted); }
.round-stats-card dd { margin: 0; font-weight: 900; }

.rack-panel,
.submitted-panel {
  margin-top: 18px;
  border-radius: 22px;
  padding: 18px;
}

.rack-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
}

.rack-head h3 { margin: 3px 0 0; }

.word-slots {
  min-height: 64px;
  margin: 16px 0 11px;
  padding: 10px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  border: 1px dashed rgba(255,255,255,.16);
  border-radius: 14px;
  background: rgba(0,0,0,.11);
}

.word-slot,
.rack-tile {
  min-width: 43px;
  height: 43px;
  border: 0;
  border-radius: 10px;
  display: grid;
  place-items: center;
  color: #14213d;
  background: linear-gradient(145deg,#fff7d8,#f9cd55);
  font-weight: 1000;
  box-shadow: inset 0 -4px 0 rgba(125,74,0,.13);
}

.word-slot {
  position: relative;
  padding-right: 11px;
}

.word-slot small {
  position: absolute;
  bottom: 3px;
  right: 5px;
  font-size: .5rem;
}

.player-rack {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 46px;
}

.rack-tile {
  cursor: pointer;
  position: relative;
}

.rack-tile small {
  position: absolute;
  right: 5px;
  bottom: 2px;
  font-size: .5rem;
}

.rack-tile.selected {
  opacity: .28;
  transform: scale(.94);
}

.word-actions {
  display: flex;
  gap: 9px;
  justify-content: flex-end;
  margin-top: 16px;
}

.word-feedback {
  min-height: 24px;
  margin-top: 10px;
  font-weight: 800;
  color: #bae6fd;
}

.word-feedback.good { color: #86efac; }
.word-feedback.bad { color: #fda4af; }

.submitted-words {
  margin-top: 13px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.submitted-chip {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  padding: 8px 11px;
  border-radius: 999px;
  background: rgba(52,211,153,.09);
  border: 1px solid rgba(52,211,153,.17);
}

.submitted-chip strong { color: #86efac; }
.empty-copy { color: var(--muted); font-size: .88rem; }

.results-panel {
  text-align: center;
  max-width: 700px;
}

.result-burst {
  width: 74px;
  height: 74px;
  display: grid;
  place-items: center;
  margin: 0 auto 18px;
  border-radius: 24px;
  background: linear-gradient(145deg,#fbbf24,#f97316);
  color: #381800;
  font-size: 2.1rem;
  transform: rotate(8deg);
  box-shadow: 0 14px 34px rgba(249,115,22,.22);
}

.results-panel h2 { margin-bottom: 0; }

.final-score { margin: 28px auto; }
.final-score small { display: block; color: var(--muted); }

.final-score strong {
  font-size: 4.8rem;
  letter-spacing: -.06em;
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(4,1fr);
  gap: 10px;
}

.results-grid div {
  border: 1px solid var(--line);
  background: rgba(255,255,255,.04);
  border-radius: 15px;
  padding: 15px 8px;
}

.results-grid small,
.results-grid strong {
  display: block;
}

.results-grid small {
  color: var(--muted);
  font-size: .72rem;
}

.results-grid strong {
  margin-top: 7px;
  font-size: 1.2rem;
}

.result-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 27px;
}

.modal {
  width: min(630px, calc(100vw - 28px));
  border: 1px solid var(--line);
  color: white;
  padding: 26px;
  border-radius: 24px;
  background: #101b36;
  box-shadow: var(--shadow);
}

.modal::backdrop {
  background: rgba(0,0,0,.72);
  backdrop-filter: blur(5px);
}

.modal-close {
  float: right;
  border: 0;
  background: rgba(255,255,255,.08);
  color: white;
  border-radius: 10px;
  width: 36px;
  height: 36px;
  font-size: 1.4rem;
}

.modal h2 { margin-top: 8px; }
.modal p,
.modal li {
  color: #c3cce1;
  line-height: 1.6;
}

.modal-stat-grid {
  display: grid;
  grid-template-columns: repeat(2,1fr);
  gap: 10px;
}

.modal-stat-grid div {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  background: rgba(255,255,255,.04);
}

.modal-stat-grid small,
.modal-stat-grid strong {
  display: block;
}

.modal-stat-grid small { color: var(--muted); }
.modal-stat-grid strong {
  font-size: 1.35rem;
  margin-top: 4px;
}

@media (max-width: 960px) {
  #menuScreen.screen-active { grid-template-columns: 1fr; }
  .game-layout { grid-template-columns: 1fr; }
  .side-panel { display: grid; grid-template-columns: 1fr 1fr; }
  .tile-board { --cols: 8; }
}

@media (max-width: 620px) {
  .app-shell { padding-inline: 12px; }
  .site-header { height: 65px; }
  .brand span:last-child { font-size: .9rem; }
  .screen { padding-top: 20px; }
  .menu-grid { grid-template-columns: 1fr; }
  .hero-card { border-radius: 22px; }

  .game-topbar {
    grid-template-columns: 1fr auto;
    gap: 10px;
  }

  .phase-pill {
    grid-row: 2;
    grid-column: 1 / -1;
    justify-self: stretch;
    text-align: center;
  }

  .score-box {
    grid-column: 2;
    grid-row: 1;
  }

  .tile-board {
    --cols: 8;
    gap: 4px;
  }

  .board-panel { padding: 11px; }
  .tile-front .points { right: 4px; bottom: 3px; }
  .side-panel { grid-template-columns: 1fr; }

  .word-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .word-actions .btn-warning {
    grid-column: 1 / -1;
  }

  .results-grid { grid-template-columns: 1fr 1fr; }
  .final-score strong { font-size: 4rem; }
}

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

/* =========================================================
   WORD GRAB — FIXED ONE-SCREEN GAME
   Keeps board, rack, word controls and submitted words visible
   without page scrolling during gameplay.
   ========================================================= */

html,
body {
  width: 100%;
  min-height: 100%;
}

body:has(#gameScreen.screen-active) {
  height: 100dvh;
  min-height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}

body:has(#gameScreen.screen-active) .app-shell {
  height: 100dvh;
  max-height: 100dvh;
  padding-bottom: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

body:has(#gameScreen.screen-active) .site-header {
  flex: 0 0 clamp(44px, 7vh, 64px);
  height: auto;
  min-height: 0;
}

body:has(#gameScreen.screen-active) main {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

#gameScreen.screen-active {
  height: 100%;
  min-height: 0;
  padding-top: clamp(4px, .8vh, 10px);
  padding-bottom: clamp(4px, .8vh, 10px);
  display: grid;
  grid-template-rows:
    auto
    minmax(0, 1fr)
    auto
    auto;
  gap: clamp(4px, .7vh, 9px);
  overflow: hidden;
}

/* ---------- Top status ---------- */

#gameScreen .game-topbar {
  min-height: 0;
  margin: 0;
  gap: 8px;
}

#gameScreen .eyebrow {
  font-size: clamp(.55rem, 1.15vh, .72rem);
}

#gameScreen .round-label {
  margin-top: 1px;
  font-size: clamp(.62rem, 1.35vh, .85rem);
}

#gameScreen .phase-pill {
  padding: clamp(4px, .65vh, 7px) 11px;
  font-size: clamp(.58rem, 1.2vh, .78rem);
}

#gameScreen .score-box small {
  font-size: clamp(.52rem, 1.05vh, .7rem);
}

#gameScreen .score-box strong {
  font-size: clamp(1.1rem, 2.8vh, 1.65rem);
  line-height: 1;
}

/* ---------- Board + side stats ---------- */

#gameScreen .game-layout {
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(150px, 18vw, 225px);
  gap: clamp(5px, .8vw, 12px);
  overflow: hidden;
}

#gameScreen .board-panel {
  position: relative;
  min-width: 0;
  min-height: 0;
  height: 100%;
  padding: clamp(5px, .75vh, 10px);
  border-radius: clamp(12px, 2vh, 20px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#gameScreen .board-head {
  flex: 0 0 auto;
  min-height: 0;
  margin-bottom: clamp(3px, .55vh, 7px);
  gap: 8px;
}

#gameScreen .board-head h2 {
  margin: 0 0 1px;
  font-size: clamp(.76rem, 1.8vh, 1.25rem);
  line-height: 1.05;
}

#gameScreen .board-head p {
  font-size: clamp(.5rem, 1.05vh, .72rem);
  line-height: 1.1;
}

#gameScreen .timer-orb {
  width: clamp(29px, 5.3vh, 48px);
  height: clamp(29px, 5.3vh, 48px);
  border-width: 2px;
  box-shadow: 0 0 0 4px rgba(59,130,246,.09), 0 6px 18px rgba(37,99,235,.24);
}

#gameScreen .timer-orb span {
  font-size: clamp(.8rem, 2vh, 1.2rem);
}

/*
  The board is always exactly 10 columns x 8 rows for 80 tiles.
  Rows share the available height, so the board shrinks instead
  of pushing the rack below the viewport.
*/
#gameScreen .tile-board {
  --cols: 10;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  gap: clamp(2px, .35vmin, 5px);
  overflow: hidden;
}

#gameScreen .tile {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  aspect-ratio: auto;
  border-radius: clamp(5px, .8vh, 10px);
}

#gameScreen .tile-front .letter {
  font-size: clamp(.58rem, 2.15vh, 1.35rem);
}

#gameScreen .tile-front .points {
  right: clamp(2px, .35vw, 5px);
  bottom: clamp(1px, .25vh, 3px);
  font-size: clamp(.34rem, .75vh, .54rem);
}

#gameScreen .board-message {
  position: absolute;
  z-index: 20;
  left: 50%;
  bottom: clamp(5px, 1vh, 10px);
  transform: translateX(-50%);
  width: min(92%, 620px);
  margin: 0;
  padding: clamp(5px, .8vh, 9px) 10px;
  font-size: clamp(.55rem, 1.2vh, .78rem);
  pointer-events: none;
}

/* ---------- Side panel ---------- */

#gameScreen .side-panel {
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-rows: minmax(0, auto) minmax(0, 1fr);
  gap: clamp(4px, .65vh, 8px);
  overflow: hidden;
}

#gameScreen .players-card,
#gameScreen .round-stats-card {
  min-height: 0;
  padding: clamp(6px, .8vh, 10px);
  border-radius: clamp(10px, 1.6vh, 16px);
  overflow: hidden;
}

#gameScreen .card-title-row {
  gap: 5px;
}

#gameScreen .card-title-row h3,
#gameScreen .round-stats-card h3 {
  margin: 0;
  font-size: clamp(.62rem, 1.4vh, .88rem);
}

#gameScreen .card-title-row > span {
  font-size: clamp(.48rem, .95vh, .65rem);
}

#gameScreen .players-list {
  margin-top: clamp(3px, .55vh, 7px);
  gap: 3px;
}

#gameScreen .player-row {
  grid-template-columns: 7px 1fr auto;
  gap: 5px;
  padding: clamp(3px, .5vh, 6px);
  font-size: clamp(.52rem, 1.15vh, .74rem);
}

#gameScreen .player-row small {
  font-size: clamp(.42rem, .85vh, .6rem);
}

#gameScreen .player-dot {
  width: 6px;
  height: 6px;
}

#gameScreen .round-stats-card dl {
  margin: clamp(3px, .55vh, 7px) 0 0;
}

#gameScreen .round-stats-card dl div {
  padding: clamp(3px, .65vh, 7px) 0;
  font-size: clamp(.52rem, 1.15vh, .76rem);
}

/* ---------- Rack / word builder ---------- */

#gameScreen .rack-panel {
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: clamp(5px, .7vh, 9px);
  border-radius: clamp(11px, 1.7vh, 17px);
  display: grid;
  grid-template-columns:
    minmax(92px, .55fr)
    minmax(160px, 1fr)
    minmax(180px, 1.25fr);
  grid-template-rows: auto auto;
  grid-template-areas:
    "head word rack"
    "feedback actions actions";
  align-items: center;
  column-gap: clamp(5px, .8vw, 10px);
  row-gap: clamp(3px, .45vh, 6px);
  overflow: hidden;
}

#gameScreen .rack-head {
  grid-area: head;
  min-width: 0;
  align-items: center;
}

#gameScreen .rack-head h3 {
  margin: 1px 0 0;
  font-size: clamp(.62rem, 1.35vh, .86rem);
  white-space: nowrap;
}

#gameScreen .rack-head .eyebrow {
  font-size: clamp(.44rem, .9vh, .58rem);
}

#gameScreen .text-btn {
  padding: 3px 0;
  font-size: clamp(.5rem, 1.05vh, .7rem);
}

#gameScreen .word-slots {
  grid-area: word;
  min-width: 0;
  min-height: clamp(29px, 5.3vh, 45px);
  height: clamp(29px, 5.3vh, 45px);
  margin: 0;
  padding: 3px;
  flex-wrap: nowrap;
  gap: 3px;
  overflow: hidden;
}

#gameScreen .player-rack {
  grid-area: rack;
  min-width: 0;
  min-height: clamp(29px, 5.3vh, 45px);
  height: clamp(29px, 5.3vh, 45px);
  flex-wrap: nowrap;
  align-items: center;
  gap: 3px;
  overflow: hidden;
}

#gameScreen .word-slot,
#gameScreen .rack-tile {
  flex: 1 1 0;
  min-width: 0;
  max-width: 45px;
  width: auto;
  height: clamp(25px, 4.7vh, 40px);
  border-radius: clamp(5px, .8vh, 8px);
  font-size: clamp(.58rem, 1.7vh, 1rem);
}

#gameScreen .word-slot small,
#gameScreen .rack-tile small {
  right: 3px;
  bottom: 1px;
  font-size: clamp(.32rem, .65vh, .46rem);
}

#gameScreen .word-actions {
  grid-area: actions;
  min-width: 0;
  margin: 0;
  justify-content: flex-end;
  gap: 4px;
}

#gameScreen .word-actions .btn {
  min-height: clamp(25px, 4.2vh, 35px);
  padding: clamp(3px, .5vh, 6px) clamp(6px, .7vw, 10px);
  border-radius: 8px;
  font-size: clamp(.5rem, 1.08vh, .7rem);
  line-height: 1;
}

#gameScreen .word-feedback {
  grid-area: feedback;
  min-width: 0;
  min-height: 1em;
  margin: 0;
  font-size: clamp(.45rem, .95vh, .64rem);
  line-height: 1.05;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Submitted words ---------- */

#gameScreen .submitted-panel {
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: clamp(4px, .6vh, 8px) clamp(6px, .8vw, 10px);
  border-radius: clamp(10px, 1.5vh, 15px);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  overflow: hidden;
}

#gameScreen .submitted-panel .card-title-row {
  white-space: nowrap;
}

#gameScreen .submitted-panel .card-title-row h3 {
  font-size: clamp(.54rem, 1.1vh, .72rem);
}

#gameScreen .submitted-panel .card-title-row > span {
  display: none;
}

#gameScreen .submitted-words {
  min-width: 0;
  margin: 0;
  flex-wrap: nowrap;
  gap: 4px;
  overflow: hidden;
}

#gameScreen .submitted-chip {
  flex: 0 0 auto;
  padding: clamp(2px, .35vh, 4px) 6px;
  gap: 4px;
  font-size: clamp(.45rem, .95vh, .62rem);
}

#gameScreen .empty-copy {
  font-size: clamp(.45rem, .95vh, .65rem);
  white-space: nowrap;
}

/* ---------- Medium / narrow screens ---------- */

@media (max-width: 960px) {
  #gameScreen .game-layout {
    grid-template-columns: minmax(0, 1fr) clamp(125px, 20vw, 180px);
  }

  #gameScreen .side-panel {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  #gameScreen .tile-board {
    --cols: 10;
    grid-template-columns: repeat(10, minmax(0, 1fr));
    grid-template-rows: repeat(8, minmax(0, 1fr));
  }
}

/* ---------- Phone portrait ---------- */

@media (max-width: 620px) {
  body:has(#gameScreen.screen-active) .app-shell {
    padding-inline: 6px;
  }

  body:has(#gameScreen.screen-active) .site-header {
    flex-basis: clamp(38px, 6.5vh, 48px);
  }

  body:has(#gameScreen.screen-active) .brand-mark {
    width: 28px;
    height: 28px;
    border-radius: 8px;
  }

  body:has(#gameScreen.screen-active) .brand span:last-child {
    font-size: .72rem;
  }

  body:has(#gameScreen.screen-active) .icon-btn {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    font-size: .75rem;
  }

  #gameScreen.screen-active {
    padding-top: 3px;
    padding-bottom: 3px;
    gap: 3px;
    grid-template-rows:
      auto
      minmax(0, 1fr)
      auto
      auto;
  }

  #gameScreen .game-topbar {
    grid-template-columns: 1fr auto auto;
    gap: 5px;
  }

  #gameScreen .phase-pill {
    grid-row: auto;
    grid-column: auto;
    justify-self: center;
    padding: 3px 6px;
  }

  #gameScreen .score-box {
    grid-column: auto;
    grid-row: auto;
  }

  /*
    Keep the side statistics beside the board even on phones.
    This prevents them from consuming an entire vertical row.
  */
  #gameScreen .game-layout {
    grid-template-columns: minmax(0, 1fr) clamp(82px, 24vw, 112px);
    gap: 3px;
  }

  #gameScreen .board-panel {
    padding: 3px;
  }

  #gameScreen .board-head {
    margin-bottom: 2px;
  }

  #gameScreen .board-head p {
    display: none;
  }

  #gameScreen .timer-orb {
    width: 27px;
    height: 27px;
  }

  #gameScreen .tile-board {
    gap: 1.5px;
  }

  #gameScreen .tile {
    border-radius: 4px;
  }

  #gameScreen .tile-front .letter {
    font-size: clamp(.5rem, 1.9vh, .8rem);
  }

  #gameScreen .tile-front .points {
    right: 1px;
    bottom: 0;
    font-size: clamp(.28rem, .6vh, .4rem);
  }

  #gameScreen .players-card,
  #gameScreen .round-stats-card {
    padding: 4px;
    border-radius: 7px;
  }

  #gameScreen .connection-badge,
  #gameScreen .player-row small {
    display: none;
  }

  #gameScreen .player-row {
    padding: 3px;
    grid-template-columns: 5px 1fr auto;
    gap: 3px;
  }

  #gameScreen .round-stats-card dl div {
    padding: 3px 0;
  }

  #gameScreen .rack-panel {
    padding: 3px;
    grid-template-columns: minmax(64px, .4fr) minmax(100px, 1fr) minmax(120px, 1.2fr);
    column-gap: 3px;
    row-gap: 2px;
  }

  #gameScreen .rack-head h3 {
    font-size: .56rem;
  }

  #gameScreen .rack-head .eyebrow {
    display: none;
  }

  #gameScreen .word-slots,
  #gameScreen .player-rack {
    min-height: 27px;
    height: 27px;
  }

  #gameScreen .word-slot,
  #gameScreen .rack-tile {
    height: 24px;
    border-radius: 4px;
    font-size: .6rem;
  }

  #gameScreen .word-actions {
    gap: 2px;
  }

  #gameScreen .word-actions .btn {
    min-height: 23px;
    padding: 2px 4px;
    border-radius: 5px;
    font-size: .46rem;
  }

  #gameScreen .submitted-panel {
    padding: 3px 4px;
    gap: 4px;
  }
}

/* ---------- Very short screens ---------- */

@media (max-height: 650px) {
  body:has(#gameScreen.screen-active) .site-header {
    flex-basis: 40px;
  }

  body:has(#gameScreen.screen-active) .brand-mark {
    width: 28px;
    height: 28px;
  }

  body:has(#gameScreen.screen-active) .icon-btn {
    width: 30px;
    height: 30px;
  }

  #gameScreen .board-head p {
    display: none;
  }

  #gameScreen .players-list {
    margin-top: 2px;
  }

  #gameScreen .player-row {
    padding-block: 2px;
  }

  #gameScreen .rack-head .eyebrow {
    display: none;
  }

  #gameScreen .submitted-panel .card-title-row {
    display: none;
  }

  #gameScreen .submitted-panel {
    grid-template-columns: 1fr;
  }
}

/* ---------- Extremely short landscape screens ---------- */

@media (max-height: 500px) {
  body:has(#gameScreen.screen-active) .site-header {
    flex-basis: 34px;
  }

  body:has(#gameScreen.screen-active) .brand-mark {
    width: 24px;
    height: 24px;
  }

  body:has(#gameScreen.screen-active) .header-actions {
    gap: 3px;
  }

  body:has(#gameScreen.screen-active) .icon-btn {
    width: 26px;
    height: 26px;
  }

  #gameScreen .game-topbar .eyebrow,
  #gameScreen .connection-badge,
  #gameScreen .player-row small {
    display: none;
  }

  #gameScreen .game-layout {
    grid-template-columns: minmax(0, 1fr) clamp(100px, 17vw, 145px);
  }

  #gameScreen .timer-orb {
    width: 24px;
    height: 24px;
  }

  #gameScreen .timer-orb span {
    font-size: .7rem;
  }

  #gameScreen .rack-panel {
    grid-template-columns: minmax(70px, .4fr) minmax(120px, 1fr) minmax(150px, 1.2fr);
  }

  #gameScreen .word-slots,
  #gameScreen .player-rack {
    min-height: 24px;
    height: 24px;
  }

  #gameScreen .word-slot,
  #gameScreen .rack-tile {
    height: 22px;
  }

  #gameScreen .word-actions .btn {
    min-height: 21px;
    padding-block: 2px;
  }

  #gameScreen .word-feedback {
    font-size: .42rem;
  }
}

/* Prevent touch/trackpad overscroll during the arcade round. */
#gameScreen,
#gameScreen .tile-board,
#gameScreen .player-rack,
#gameScreen .word-slots {
  overscroll-behavior: none;
}

#gameScreen .tile,
#gameScreen .rack-tile {
  touch-action: manipulation;
}

