:root {
  --bg: #0e1320;
  --panel: #171e2e;
  --panel-2: #1d2537;
  --tile: #2a3349;
  --tile-hi: #35405c;
  --ink: #e6ebf5;
  --muted: #8fa0bd;
  --p0: #2f6fdd;
  --p1: #e07f16;
  --p2: #d23c3c;
  --p3: #2f9e44;
  /* bright variants: readable as TEXT on dark panels; board fills stay dark */
  --p0-bright: #5b8cff;
  --p1-bright: #ffa02e;
  --p2-bright: #ff5d5d;
  --p3-bright: #35cf72;
  --accent: #10b981;
  --gold: #ffd75e;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* uniform digit widths everywhere: phone fonts (e.g. Apple SF) draw
     proportional figures by default, which wrapped "LEVEL n OF 6" for wide
     digits and makes ticking clocks / scores jitter */
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid #232c42;
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0.5px;
}

.topbar h1 span {
  background: linear-gradient(90deg, var(--p0), var(--p1));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

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

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}

button {
  font: inherit;
  color: var(--ink);
  background: var(--panel-2);
  border: 1px solid #33405f;
  border-radius: 8px;
  padding: 8px 16px;
  cursor: pointer;
}

/* hover styling only where a real hover exists — on touch screens the
   browser keeps :hover applied after a tap, leaving a stuck highlight */
@media (hover: hover) {
  button:hover:not(:disabled) { background: var(--tile-hi); }
}
/* likewise no focus ring left behind by a tap/click; keyboard users
   (:focus-visible) still get the browser's ring */
button:focus:not(:focus-visible) { outline: none; }
button { -webkit-tap-highlight-color: transparent; }
button:disabled { opacity: 0.55; cursor: default; }

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #06251b;
  font-weight: 700;
}

@media (hover: hover) {
  button.primary:hover:not(:disabled) { background: #34d39b; }
}

/* ---- setup (design 3b: labeled 6-notch sliders, surprise, link levels) ---- */

#setup, #mp-create, #qm-name, #qm-wait, #qm-go {
  width: min(430px, 100vw - 32px);
  margin: max(16px, 6vh) auto 24px;
  background: var(--panel);
  border: 1px solid #232c42;
  border-radius: 22px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  text-align: center;
}

.title-block { display: flex; flex-direction: column; gap: 6px; }

#setup h2, .title-block h2 { margin: 0; font-size: 28px; font-weight: 800; letter-spacing: 0.01em; }

#setup .tagline, .title-block .tagline { margin: 0; font-size: 14px; color: var(--muted); }
/* instruction line under the device picker (solo setup + mp create) */
.mp-instruction { margin: 0; font-size: 15px; }

/* Create a Game Room form (moved from mp.css with the create section) */
.mp-name-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  text-align: left;
}

.mp-name-row input {
  font: inherit;
  font-size: 17px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #33405f;
  background: var(--panel-2);
  color: var(--ink);
  text-align: center;
}

.mp-err { color: #ff8f8f; font-size: 14px; margin: 0; }

/* Your Games list (P4.3). All row rules carry the .overlay-card prefix so
   they outrank the .overlay-card button padding + p margin resets. */
.yourgames-card { min-width: 320px; max-width: 400px; text-align: left; }
.overlay-card #yg-list { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.overlay-card .yg-row {
  display: flex;
  flex-wrap: wrap; /* two lines: name (+ ✕) on top, status · created below */
  align-items: center;
  gap: 4px 12px;
  padding: 12px 14px;
  border: 1px solid #33405f;
  border-radius: 12px;
  background: var(--panel-2);
  font: inherit;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.overlay-card .yg-row:hover { border-color: var(--accent); }
.overlay-card .yg-row:disabled { opacity: 0.6; cursor: default; }
.overlay-card .yg-row .yg-who { flex: 1; font-weight: 600; }
.overlay-card .yg-row .yg-state { width: 100%; font-size: 13px; color: var(--muted); }
.overlay-card .yg-row .yg-state.turn { color: var(--accent); font-weight: 700; }
.overlay-card .yg-row .yg-x {
  flex: none;
  padding: 2px 8px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
}
.overlay-card .yg-row .yg-x:hover { color: #ff8f8f; background: rgba(255, 143, 143, 0.12); }

/* "(optional)" hint on the room-name field */
.mp-name-row .mp-optional { color: var(--muted); font-weight: 400; }

/* pill rows: player count / board size / timer */

.size-picker { display: flex; gap: 8px; margin: 0; }

.size-picker button {
  flex: 1;
  padding: 10px 0;
  font-size: 14px;
  border-radius: 12px;
  border: 1px solid #33405f;
  background: transparent;
  color: var(--muted);
}

.size-picker button.active {
  border-color: var(--accent);
  background: rgba(16, 185, 129, 0.08);
  color: var(--ink);
  font-weight: 600;
}

.count-pills button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 9px 0;
}

.pill-dots { display: flex; gap: 4px; }

.pill-dots i { width: 7px; height: 7px; border-radius: 50%; }

.p0-bg { background: var(--p0); }
.p1-bg { background: var(--p1); }
.p2-bg { background: var(--p2); }
.p3-bg { background: var(--p3); }

.picker-block { display: flex; flex-direction: column; gap: 8px; }

.section-label {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

#btn-start {
  width: 100%;
  padding: 14px 0;
  font-size: 17px;
  font-weight: 800;
  border-radius: 14px;
}

/* Escape hatch back to an unfinished game (shown only when one is saved). */
#btn-setup-resume {
  width: 100%;
  padding: 12px 0;
  font-size: 15px;
  font-weight: 700;
  border-radius: 14px;
  background: var(--panel-2);
  border-color: #33405f;
  margin-top: -8px;
}
/* .primary (games waiting) must go green here too: the ID rule above
   outranks button.primary, which otherwise leaves .primary's dark text
   on the dark panel — invisible (iPhone field report, 2026-07-19). Colors
   only; no box-model properties. */
#btn-setup-resume.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #06251b;
}

/* seat cards */

#seats { display: flex; flex-direction: column; gap: 8px; }

.seat-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg);
  border: 1px solid #232c42;
  border-radius: 14px;
  padding: 12px 14px;
}

/* wrap only ever triggers on narrow phones: the toggle drops to its own line */
.seat-head { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; row-gap: 8px; }

.seat-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

.seat-player { font-size: 14px; font-weight: 600; color: #c6d2ee; white-space: nowrap; }

.seat-chip {
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.p0-chip { background: rgba(47, 111, 221, 0.16); }
.p1-chip { background: rgba(224, 127, 22, 0.16); }
.p2-chip { background: rgba(210, 60, 60, 0.16); }
.p3-chip { background: rgba(47, 158, 68, 0.16); }

.mode-toggle {
  margin-left: auto;
  display: flex;
  border: 1px solid #33405f;
  border-radius: 10px;
  overflow: hidden;
}

.mode-toggle button {
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
}

.mode-toggle button.active {
  background: rgba(16, 185, 129, 0.16);
  color: #34d39b;
}

/* difficulty block */

.difficulty {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 4px 4px;
}

.diff-label {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--muted);
  text-align: left;
}

/* wrap is the overflow escape hatch for odd fonts/widths; phones get the
   two-line layout deterministically via the 414px media query below */
.diff-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }

.diff-slider {
  position: relative;
  flex: 1;
  min-width: 150px;
  height: 44px;
  display: flex;
  align-items: center;
  touch-action: pan-y;
  cursor: pointer;
}

.diff-track,
.diff-fill {
  position: absolute;
  left: 2px;
  height: 4px;
  border-radius: 2px;
}

.diff-track { right: 2px; background: #20304f; }

.diff-fill { background: var(--accent); }

.diff-slider.surprise .diff-fill {
  background: repeating-linear-gradient(45deg, #33436b 0 6px, #242f4f 6px 12px);
}

.diff-notches {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.diff-notch {
  width: 24px;
  height: 44px;
  padding: 0;
  border: none;
  background: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.diff-notch:hover:not(:disabled) { background: none; }
.diff-notch:hover i { filter: brightness(1.25); }

.diff-notch i {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #16203a;
  border: 1px solid #2c3d66;
}

.diff-notch.filled i {
  background: var(--accent);
  border: none;
}

.diff-notch.selected i {
  width: 18px;
  height: 18px;
  box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.2);
}

.diff-readout {
  display: flex;
  flex-direction: column;
  gap: 1px;
  text-align: right;
}

.diff-name { font-size: 15px; font-weight: 700; color: var(--ink); white-space: nowrap; }

.diff-sub { font-size: 10.5px; letter-spacing: 0.08em; color: var(--muted); white-space: nowrap; }

.surprise-btn {
  position: relative;
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  margin-left: auto; /* no-op on one line (slider absorbs slack); pins "?" right when the row wraps */
  padding: 0;
  border-radius: 9px;
  border: 1px dashed #3a4a72;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
  line-height: 1;
}

/* invisible padding so the touch target clears 44px */
.surprise-btn::after { content: ''; position: absolute; inset: -8px; }

.surprise-btn:hover:not(:disabled) { background: rgba(124, 108, 240, 0.15); }

.surprise-btn.on {
  background: #7c6cf0;
  border: none;
  color: #0a0f1c;
}

.surprise-btn.on:hover:not(:disabled) { background: #8d7ef5; }

/* link levels + hint */

.link-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 0 6px;
  border: none;
  background: none;
  font-size: 13px;
  color: #c6d2ee;
}

.link-row:hover:not(:disabled) { background: none; }

.switch {
  position: relative;
  width: 36px;
  height: 20px;
  border-radius: 999px;
  background: #2a3860;
  transition: background 0.15s;
  flex-shrink: 0;
}

.switch i {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #eef3ff;
  transition: left 0.15s;
}

.switch.on { background: var(--accent); }
.switch.on i { left: 18px; }

.seat-hint { font-size: 12px; color: var(--muted); }

@media (max-width: 400px) {
  #setup, #mp-create, #qm-name, #qm-wait, #qm-go { padding: 20px; }
  .seat-card { padding: 10px 12px; }
}

/* phones: one-line is only 0-4px from overflowing at 375-412px (slider min
   150px + font-dependent readout), so force the designed two-line layout —
   slider owns line 1; readout left + "?" right (via its auto margin) below */
@media (max-width: 414px) {
  .diff-slider { flex-basis: 100%; }
  .diff-readout { text-align: left; }
}
/* ---- game layout ---- */

#game {
  display: flex;
  flex-direction: column;
  gap: 18px;
  align-items: center;
}

/* Board and tray live in one column with a fixed gap — the words panel is a
   sibling column, so a long word list runs down the page instead of pushing
   the tray away from the board. */
.play-col {
  display: flex;
  flex-direction: column;
  gap: 18px;
  align-items: center;
}

@media (min-width: 920px) {
  #game {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 18px;
    align-items: start;
    justify-items: center;
  }
  .hud { grid-column: 1 / -1; }
  .play-col { grid-column: 1; }
  .words-panel { grid-column: 2; grid-row: 2; }
}

/* ---- hud ---- */

.hud { width: 100%; max-width: 640px; position: relative; }

.pill {
  display: inline-block;
  padding: 5px 14px;
  border-radius: 999px;
  font-weight: 700;
  margin-bottom: 10px;
  color: #fff;
}

.pill.p0 { background: var(--p0); }
.pill.p1 { background: var(--p1); }
.pill.p2 { background: var(--p2); }
.pill.p3 { background: var(--p3); }

#clocks { display: inline-block; margin-left: 10px; }

.clock {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid #33405f;
  margin-right: 6px;
  opacity: 0.6;
}

.clock.active { opacity: 1; color: var(--ink); }
.clock.p0.active { border-color: var(--p0); }
.clock.p1.active { border-color: var(--p1); }
.clock.p2.active { border-color: var(--p2); }
.clock.p3.active { border-color: var(--p3); }
.clock.dead { text-decoration: line-through; opacity: 0.35; }

.clock.low.active {
  color: #ff6b6b;
  border-color: #ff6b6b;
  animation: lowpulse 1s ease infinite;
}

@keyframes lowpulse {
  50% { opacity: 0.55; }
}

.scorebar {
  display: flex;
  height: 12px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--tile);
}

.scorebar div { transition: width 0.5s ease; }
.seg.p0 { background: var(--p0); }
.seg.p1 { background: var(--p1); }
.seg.p2 { background: var(--p2); }
.seg.p3 { background: var(--p3); }

.score-labels {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--muted);
  margin-top: 5px;
}

/* ---- board ---- */

#board {
  --n: 7;
  --cell: min(56px, calc(86vmin / var(--n)), calc(92vw / var(--n)));
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--n), var(--cell));
  gap: 4px;
  padding: 10px;
  background: var(--panel);
  border: 1px solid #232c42;
  border-radius: 12px;
  user-select: none;
}

.cell {
  width: var(--cell);
  height: var(--cell);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--tile);
  border-radius: 6px;
  font-size: calc(var(--cell) * 0.48);
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
  position: relative;
  transition: background-color 0.45s ease, transform 0.15s ease;
}

.cell:hover { transform: scale(1.06); }

#word-lines {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
}

#word-lines line {
  stroke: rgba(0, 0, 0, 0.55);
  stroke-width: 3;
  stroke-linecap: round;
}

.cell.p0 { background: var(--p0); color: #fff; }
.cell.p1 { background: var(--p1); color: #fff; }
.cell.p2 { background: var(--p2); color: #fff; }
.cell.p3 { background: var(--p3); color: #fff; }

.cell.placed { outline: 2px dashed var(--gold); outline-offset: -2px; }
.cell.p0-tint { background: color-mix(in srgb, var(--p0) 45%, var(--tile)); color: #fff; }
.cell.p1-tint { background: color-mix(in srgb, var(--p1) 45%, var(--tile)); color: #fff; }
.cell.p2-tint { background: color-mix(in srgb, var(--p2) 45%, var(--tile)); color: #fff; }
.cell.p3-tint { background: color-mix(in srgb, var(--p3) 45%, var(--tile)); color: #fff; }

.cell.locked::after {
  content: '';
  position: absolute;
  inset: 3px;
  border: 2px solid rgba(255, 255, 255, 0.75);
  border-radius: 4px;
  pointer-events: none;
}

@keyframes flashpop {
  0% { transform: scale(1); }
  45% { transform: scale(1.18); box-shadow: 0 0 14px rgba(255, 215, 94, 0.8); }
  100% { transform: scale(1); }
}

.cell.flash { animation: flashpop 0.7s ease; }

@keyframes badbounce {
  0%, 100% { transform: none; }
  20% { transform: translateY(-14px); }
  45% { transform: none; }
  65% { transform: translateY(-7px); }
  85% { transform: none; }
}

.cell.bad {
  outline: 3px solid #ff5a5a !important;
  outline-offset: -3px;
  animation: badbounce 0.9s ease 3;
}

/* ---- tray ---- */

.tray-wrap {
  width: 100%;
  max-width: 640px;
  background: var(--panel);
  border: 1px solid #232c42;
  border-radius: 12px;
  padding: 14px;
}

#tray {
  /* a full 7-tile tray must fit a phone: 100vw minus main padding (32),
     tray-wrap padding (28), and the six 8px gaps (48) */
  --t: min(52px, calc((100vw - 108px) / 7));
  display: flex;
  gap: 8px;
  justify-content: center;
  min-height: var(--t);
  margin-bottom: 12px;
  user-select: none;
}

#tray.thinking {
  opacity: 0.45;
  pointer-events: none;
}

.tile {
  width: var(--t, 52px);
  height: var(--t, 52px);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-size: calc(var(--t, 52px) * 0.5);
  font-weight: 800;
  text-transform: uppercase;
  cursor: pointer;
  color: #fff;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
  transition: transform 0.12s ease;
}

.tile.p0 { background: var(--p0); }
.tile.p1 { background: var(--p1); }
.tile.p2 { background: var(--p2); }
.tile.p3 { background: var(--p3); }
.tile:hover { transform: translateY(-3px); }

.tile.selected {
  outline: 3px solid var(--gold);
  transform: translateY(-6px);
}

.tile { touch-action: none; }

.tile.dragging {
  opacity: 0.75;
  transform: scale(1.12);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.5);
  cursor: grabbing;
}

.controls {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

/* Five buttons + gaps outgrow the tray below ~510px, wrapping Submit into a
   small centered orphan. Force the designed two-line layout instead (same
   pattern as the 414px diff-slider rule): Swap/Recall/Shuffle/Check stretch
   edge-to-edge across line 1 (tighter padding guarantees four-up at 360px;
   truly tiny screens wrap to two full-width pairs), Submit full-width
   below — everything as wide as the tray it acts on. */
@media (max-width: 520px) {
  .controls button { flex: 1 1 auto; padding: 8px; }
  #btn-submit { flex: 1 1 100%; margin-top: 8px; }
}

/* ---- words panel ---- */

.words-panel {
  width: 100%;
  max-width: 640px;
  background: var(--panel);
  border: 1px solid #232c42;
  border-radius: 12px;
  padding: 14px 16px;
}

.words-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.words-head h3 { margin: 0; font-size: 15px; color: var(--muted); }

.sort-toggle { display: flex; gap: 4px; }

.sort-toggle button {
  padding: 3px 9px;
  font-size: 12px;
  border-radius: 6px;
  color: var(--muted);
}

.sort-toggle button.active {
  border-color: var(--accent);
  color: var(--ink);
}

#word-list { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  color: #fff;
}

.chip.p0 { background: var(--p0); }
.chip.p1 { background: var(--p1); }
.chip.p2 { background: var(--p2); }
.chip.p3 { background: var(--p3); }

/* A–Z sort: white separator pill marking where each starting letter begins */
.chip.letter-sep {
  background: #fff;
  color: #10141f;
  font-weight: 800;
}

.muted { color: var(--muted); font-size: 14px; }

.site-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  padding: 16px 12px 20px;
}

/* Strategy Guide link stacked above the copyright line (design pass,
   2026-07-21; spec colors mapped onto the site palette) */
.site-footer .footer-strategy {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 1px solid var(--tile-hi);
  padding-bottom: 2px;
}

.site-footer .footer-strategy:hover {
  color: var(--ink);
  border-bottom-color: var(--muted);
}

/* the copyright line is a tap target for the About dialog, but should keep
   looking like plain footer text (dimmed below the strategy link) */
.site-footer button {
  background: none;
  border: none;
  border-radius: 6px;
  padding: 4px 10px;
  color: rgba(143, 160, 189, 0.55);
  font-size: 12px;
}

.site-footer button:hover:not(:disabled) { background: none; color: var(--ink); }

/* ---- overlays ---- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 11, 20, 0.62);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

/* Pause: rough colors show through, letters are unreadable */
.pause-overlay {
  background: rgba(10, 14, 24, 0.35);
  backdrop-filter: blur(16px);
  z-index: 60;
}

/* anchored to the hud's right edge (= the territory bar's right edge, above
   the "N free" label) so the turn pill changing width never moves it */
.pause-btn {
  position: absolute;
  top: 0;
  right: 0;
  padding: 5px 12px;
  font-size: 13px;
}

table.stats { border-collapse: collapse; margin: 14px auto; }
table.stats th, table.stats td { border: 1px solid #33405f; padding: 5px 14px; font-size: 14px; }
table.stats th { color: var(--muted); font-weight: 600; }

/* shared base for every <dialog> (wordcheck, help, passconfirm) */
dialog {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid #33405f;
  border-radius: 14px;
  padding: 26px 30px;
}

dialog::backdrop { background: rgba(8, 11, 20, 0.6); backdrop-filter: blur(3px); }

#wordcheck {
  width: 340px;
  text-align: center;
}

/* Phones: the keyboard + Safari's accessory bar cover the bottom ~half of
   the screen, and the body is scroll-pinned while a modal is up — a
   UA-centered dialog lands with its input and Done button underneath them.
   Launch Word Check near the top instead, where the keyboard can't reach
   (horizontal centering stays from the UA's margin:auto). */
@media (max-width: 520px) {
  #wordcheck { margin-top: 7vh; margin-bottom: auto; }
}

#wc-input {
  font: inherit;
  font-size: 20px;
  text-transform: uppercase;
  text-align: center;
  letter-spacing: 2px;
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #33405f;
  background: var(--panel-2);
  color: var(--ink);
  outline: none;
}

#wc-input:focus { border-color: var(--accent); }

#wc-result { min-height: 1.4em; font-weight: 600; }
#wc-result.good { color: var(--accent); }
#wc-result.bad { color: #ff6b6b; }

#about {
  width: 360px;
  max-width: 92vw;
  text-align: center;
}

#about h2 { margin: 0 0 4px; }
#about p { margin: 10px 0; }
#about a { color: var(--accent); }

#about .about-tagline {
  color: var(--muted);
  font-size: 13.5px;
  margin: 0 0 18px;
}

#about .about-credits {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
  margin-top: 20px;
}

#about .about-version {
  color: var(--muted);
  font-size: 11px;
  margin: 14px 0 0;
  opacity: 0.75;
}

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

.overlay-card {
  position: relative; /* anchors .overlay-close */
  background: var(--panel);
  border: 1px solid #33405f;
  border-radius: 14px;
  padding: 32px 40px;
  text-align: center;
  min-width: 320px; /* keeps "<Name>'s turn" titles on one line */
  max-width: 90vw;
}

/* .overlay-card .overlay-close: must OUTRANK ".overlay-card button" below,
   whose padding:10px 26px was inflating the 32px square into a wide pill
   (game-over field screenshot, 2026-07-16) */
.overlay-card .overlay-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  box-sizing: border-box;
  padding: 0;
  line-height: 1;
  border-radius: 8px;
  background: var(--panel-2);
  border: 1px solid #33405f;
  font-size: 14px;
  line-height: 1;
}

.overlay-card h2 { margin: 8px 0 20px; font-size: 30px; }

/* .overlay-card … selectors outrank the .overlay-card p { margin: 0 } reset */
.overlay-card .go-hint { margin-top: 26px; font-size: 12.5px; }

.overlay-card .go-bots { margin: -12px 0 24px; font-size: 13.5px; }
.overlay-card p { color: var(--muted); margin: 0; }
.overlay-card button { font-size: 16px; padding: 10px 26px; }

.p0-text { color: var(--p0-bright); }
.p1-text { color: var(--p1-bright); }
.p2-text { color: var(--p2-bright); }
.p3-text { color: var(--p3-bright); }

/* ---- help dialog (4a sectioned sheet) ---- */

/* [open] keeps the closed dialog display:none (a bare #help rule would
   override the UA's dialog:not([open]) and leave a click-eating ghost) */
#help[open] {
  padding: 0;
  width: min(560px, 92vw);
  max-height: min(560px, 82vh);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.help-head,
.help-foot {
  flex-shrink: 0;
  padding: 14px 20px;
}

.help-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #232c42;
  font-size: 18px;
  font-weight: 700;
}

.help-head button {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 8px;
  background: var(--panel-2);
  border: 1px solid #33405f;
  font-size: 14px;
  line-height: 1;
}

.help-foot { border-top: 1px solid #232c42; }
.help-foot button { width: 100%; padding: 11px 0; font-size: 15px; }

/* the ONLY scrolling element — page behind never moves */
.help-body {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.help-body section { display: flex; flex-direction: column; gap: 8px; }

.help-label {
  margin: 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

.help-body p { margin: 0; font-size: 14px; line-height: 1.5; color: #c3cee4; }
.help-body strong { color: var(--ink); }

.help-steps {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.help-steps li {
  display: flex;
  gap: 10px;
  align-items: baseline;
  font-size: 14px;
  line-height: 1.5;
  color: #c3cee4;
}

.help-steps li i {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--panel-2);
  border: 1px solid #33405f;
  font-style: normal;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transform: translateY(3px);
}

/* wrap: the 7-tile FRIENDS row + caption can't fit one line on phones */
.demo-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 2px; }
.demo-tiles { display: flex; gap: 4px; }
.demo-cap { font-size: 12px; color: var(--muted); }

.mini-tile {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-style: normal;
  font-size: 15px;
  font-weight: 800;
  color: #fff;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
}

.mt-b { background: var(--p0-bright); }
.mt-o { background: var(--p1-bright); }
.mt-r { background: var(--p2-bright); }
.mt-g { background: var(--p3-bright); }

.defend-grid {
  display: grid;
  grid-template-columns: repeat(3, 24px);
  gap: 3px;
  margin-top: 2px;
}

.defend-grid i {
  width: 24px;
  height: 24px;
  border-radius: 5px;
  background: var(--p0-bright);
}

.defend-grid i.lock { box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.85); }

/* ---- welcome splash (5a) ---- */

#splash {
  width: min(480px, 92vw);
  margin: 8vh auto 0;
  background: var(--panel);
  border: 1px solid #33405f;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.splash-head {
  padding: 16px 20px;
  border-bottom: 1px solid #232c42;
  text-align: center;
  font-size: 18px;
  font-weight: 700;
}

.splash-body {
  padding: 36px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
}

.splash-tagline { margin: 0; font-size: 15px; color: #c3cee4; }

.wordmark { display: flex; flex-direction: column; gap: 6px; align-items: center; }
.wm-row { display: flex; gap: 6px; }

.wm-tile {
  width: 52px;
  height: 52px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: 800;
  color: #fff;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
}

.wm-b { background: var(--p0-bright); }
.wm-o { background: var(--p1-bright); }

.splash-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 16px 20px 20px;
}


/* first-visit welcome popup on the New Game menu */
.welcome-card { max-width: 360px; text-align: left; padding: 28px 30px; }
.welcome-card h2 { margin: 0; font-size: 24px; }
/* .overlay-card prefix: outranks the .overlay-card p { margin: 0 } reset */
.overlay-card .welcome-line { margin: 18px 0 0; font-size: 15px; line-height: 1.45; }
.welcome-actions { display: flex; gap: 10px; margin-top: 22px; }
.welcome-actions button { flex: 1; }
/* the create heads-up: muted top/bottom lines, the key middle sentence
   all-bold in full white so it's the thing people read */
#roomhint .welcome-line strong { color: #fff; }
.overlay-card .yg-caps {
  margin: 6px 0 0; font-size: 12.5px; line-height: 1.4; color: var(--muted);
}
.overlay-card .rh-check {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin-top: 18px; font-size: 13px; color: var(--muted); cursor: pointer;
}
.overlay-card .rh-check input { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }

.splash-foot button { flex: 1; padding: 12px 0; font-size: 15px; }
.splash-foot #btn-splash-help { background: var(--panel-2); border-color: #33405f; }

@media (max-width: 380px) {
  .wm-tile { width: 44px; height: 44px; font-size: 22px; }
}

/* page behind a modal must not scroll (iOS lets it through the backdrop).
   NO position:fixed here — pinning the body at an offset desyncs iOS
   Safari's hit-testing from the rendered dialog (frozen, untappable About
   when opened from the scrolled-down footer — phone field report, 2026-07-15).
   The keyboard may nudge the page under the backdrop instead; ui.js
   restores the exact scroll position when the dialog closes. */
body.modal-open { overflow: hidden; }

/* ---- toast ---- */

/* Toasts are zoned + color-coded by what they say (design call, 2026-07-15):
   green/top    = move summaries & system notices (the info ticker)
   yellow/mid   = board-tap guidance ("Pick a tile from your tray…")
   red/bottom   = pinned submit errors (player just tapped Submit down there)
   Every toast taps to dismiss; timed ones also auto-dismiss as before. */
#toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  background: #0b0f1a;
  border: 1px solid var(--accent);
  color: var(--ink);
  padding: 10px 18px;
  border-radius: 10px;
  max-width: 90vw;
  z-index: 60;
  font-size: 15px;
  text-align: center;
  cursor: pointer;
}

#toast.toast-top { top: max(14px, env(safe-area-inset-top)); }
#toast.toast-mid {
  top: 50%;
  transform: translate(-50%, -50%);
  border-color: var(--gold);
}
#toast.toast-bottom {
  bottom: 26px;
  border-color: #d23c3c;
}

#toast-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  margin-left: 12px;
  padding: 0 2px;
  cursor: pointer;
  vertical-align: middle;
}
