/* ── GerdQuest franchise typography (bible §3) ──────────────
   All self-hosted woff2, all OFL, no CDN.

   The split is semantic and worth preserving:
     display for voice, body for fiction,
     mono for anything a player counts.
   Unit counts, dice totals and scores are always mono,
   tabular-lined.                                             */

@font-face {
  font-family: 'Metamorphous';
  src: url('../fonts/metamorphous-400.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Spectral';
  src: url('../fonts/spectral-400.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Spectral';
  src: url('../fonts/spectral-400-italic.woff2') format('woff2');
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: 'Spectral';
  src: url('../fonts/spectral-600.woff2') format('woff2');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
/* JetBrains Mono ships as a variable font — one file covers 400–700. */
@font-face {
  font-family: 'JetBrains Mono';
  src: url('../fonts/jetbrains-mono.woff2') format('woff2');
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

/* ── GerdQuest franchise palette (bible §3) ─────────────────
   Canonical source: notequest_browser src/ui/theme/tokens.css

   Committed dark. There is no light mode and no theme toggle —
   this is one lit scene, not a document that inverts.

   Title-specific exception, documented in CLAUDE.md: the board
   keeps its ocean identity. Franchise tokens dress the chrome;
   the sea and the islands stay Isle Raid's own.               */
:root {
  color-scheme: dark;

  --font-display: 'Metamorphous', serif;              /* voice   */
  --font-body:    'Spectral', Georgia, serif;         /* fiction */
  --font-mono:    'JetBrains Mono', ui-monospace,
                  SFMono-Regular, Menlo, monospace;   /* counted */

  --bg-0:         #0a0807;   /* page background, near-black   */
  --bg-1:         #17110d;   /* raised dark surfaces          */
  --torch-core:   #ffc06a;   /* brightest flame               */
  --torch-mid:    #d9791f;   /* flame body, glows             */
  --ember:        #b8481f;   /* dying flame                   */
  --gold:         #b8862f;   /* borders, interactive          */
  --gold-bright:  #e0ac48;   /* wordmark, emphasis            */
  --parchment:    #e9ddc2;   /* primary paper surface         */
  --parchment-2:  #ddcca2;
  --parchment-3:  #cbb686;
  --ink:          #2a2016;   /* body text on parchment        */
  --ink-soft:     #5a4b38;   /* secondary text on parchment   */
  --danger:       #a63c1d;   /* damage, loss, warnings        */
  --focus:        #f2c265;   /* focus ring — never removed    */

  /* Isle Raid exception: the sea. */
  --map-bg: linear-gradient(145deg, #0096c7 0%, #0077b6 40%, #023e8a 100%);

  /* This title's parchment is a photographic texture (largeimage.jpg,
     roughly #c9ab80) — darker than the franchise --parchment #e9ddc2.
     --danger reads at only 2.9:1 on it, so danger *text* on parchment
     uses a deepened variant. Surfaces and borders still use --danger. */
  --danger-deep: #6e2412;

  /* Derived from the tokens above; alpha variants CSS can't mix inline. */
  --setup-group-bg:       rgba(255, 255, 255, 0.05);
  --setup-group-border:   rgba(184, 134, 47, 0.28);
  --setup-label-color:    rgba(224, 172, 72, 0.75);
  --footer-text:          rgba(233, 221, 194, 0.45);
  --footer-link:          var(--gold-bright);
  --version-color:        rgba(224, 172, 72, 0.70);
  --version-border:       rgba(184, 134, 47, 0.35);
  --version-hover-color:  var(--gold-bright);
  --version-hover-border: var(--gold);

  /* Fixed-width flanks of the one-screen grid; the map takes the rest. */
  --col-word: 260px;
  --col-side: 310px;
}

/* §3: the focus ring is always visible and never removed. */
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ── One-screen shell ──────────────────────────────────────
   The whole game fits the viewport: the body never scrolls, and
   every region that can outgrow its cell scrolls inside itself.
   Below 680px this is abandoned deliberately — see the phone
   breakpoint, where stacking and scrolling beat cramming.     */
body{
  background: linear-gradient(to bottom, var(--bg-1), var(--bg-0));
  margin: 0;
  height: 100dvh;
  overflow: hidden;
  font-family: var(--font-body);
}
/* ── Wordmark (bible §2) ───────────────────────────────────
   One <h1> holding both halves, so the accessible name and the
   document title are the complete phrase. The series prefix is
   small, uppercase and letter-spaced above the installment name,
   which takes the display size. The prefix is constant across
   GerdQuest titles; only the second line changes.

   The full title always travels together — a live Google Play
   island-conquest game owns the bare name "Isle Raid" (#43).   */
.wordmark {
  grid-area: word;
  align-self: center;
  text-align: center;
  min-width: 0;
}
.wordmark h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 2.1rem;
  font-weight: 400;
  line-height: 1.1;
  color: var(--gold-bright);
  text-shadow: 2px 2px 6px rgba(0, 0, 0, 0.7);
}
.wordmark h1 small {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.34em;
  font-weight: 400;
  letter-spacing: 0.34em;
  text-indent: 0.34em;          /* balances the trailing letter-space */
  text-transform: uppercase;
  color: var(--gold);
  text-shadow: none;
  margin-bottom: 0.5em;
}
.wordmark img {
  width: 66px;
  vertical-align: middle;
  margin-right: 10px;
  filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.35));
}
/* The cell the map lives in. `container-type: size` makes its own
   measured width and height queryable as cqw/cqh, which is what lets
   the square board pick the smaller of the two in pure CSS — no
   resize listener, no magic number for the chrome above it. */
.map-area {
  grid-area: map;
  container-type: size;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
.map{
  padding: clamp(10px, 3cqmin, 28px);
  box-sizing: border-box;
  background: var(--map-bg);
  position:relative;
  width:  min(100cqw, 100cqh);
  height: min(100cqw, 100cqh);
  border-radius: 5%;
  display: grid;
  grid-template-columns: repeat(var(--grid-cols, 4), 1fr);
  gap: clamp(5px, 1.4cqmin, 12px);
  align-content: center;
  margin: 0;
  overflow: hidden;
}
.container {
  display: grid;
  grid-template-columns: minmax(0, var(--col-word)) minmax(0, 1fr) var(--col-side);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "word top  top"
    "map  map  side"
    "foot foot foot";
  gap: 6px 14px;
  height: 100dvh;
  max-width: 1600px;
  margin: 0 auto;
  box-sizing: border-box;
  padding: 8px 14px 4px;
}

#top-bar {
  grid-area: top;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  min-width: 0;
}

.space {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 40% 35%, #3ecf7a, #1a6e3a);
  border-radius: 20%;
  box-shadow: 0 0 0 3px rgba(210, 180, 120, 0.5),
              5px 6px 18px rgba(0, 0, 0, 0.55);
  text-align: center;
  cursor:pointer;
  overflow: hidden;
  box-sizing: border-box;
}
.space h2 {
  margin: 0;
  /* Scales with the board, so a 6×6 on a short screen still reads as
     a number rather than overflowing its island. */
  font-size: clamp(0.8rem, calc(14cqmin / var(--grid-cols, 4)), 1.9rem);
  text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.7);
  color: #f0ece0;
  /* A number the player counts — §3 wants these mono and tabular. */
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}
/* Unclaimed islands still show their garrison — §5.4 wants the
   bookkeeping visible — but a mono 0 reads as data where the old
   display face rendered it as a decorative dot. Dim it so the eye
   finds the islands that actually hold units first. */
.space:not(.player1):not(.player2):not(.player3):not(.player4) h2 {
  opacity: 0.4;
  font-weight: 400;
}

.player1{
  background: radial-gradient(circle at 40% 35%, #a0b4c0, #3a5260);
  box-shadow: 0 0 0 3px rgba(160, 180, 192, 0.5), 5px 6px 18px rgba(0,0,0,0.55);
}
.player2{
  background: radial-gradient(circle at 40% 35%, #e05530, #7a1a08);
  box-shadow: 0 0 0 3px rgba(224, 85, 48, 0.5), 5px 6px 18px rgba(0,0,0,0.55);
}
.player3 {
  background: radial-gradient(circle at 40% 35%, #22d3ee, #0e7490);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.5), 5px 6px 18px rgba(0,0,0,0.55);
}
.player4 {
  background: radial-gradient(circle at 40% 35%, #c084fc, #581c87);
  box-shadow: 0 0 0 3px rgba(192, 132, 252, 0.5), 5px 6px 18px rgba(0,0,0,0.55);
}

.button {
  width: 100%;
  box-sizing: border-box;
  border-radius: 0;
  border: none;
  border-bottom: 3px solid black;
  text-align: center;
  padding: 22px 15px;
  cursor: pointer;
  background-color: var(--parchment-2);
  color: var(--ink);
  box-shadow: inset 0 0 24px 2px rgba(0, 0, 0, 0.65);
  font-family: var(--font-display);
  font-size: 1.15em;
  letter-spacing: 0.04em;
  transition: background-color 0.15s, box-shadow 0.15s;
}
.button:hover {
  background-color: var(--parchment);
  box-shadow: inset 0 0 24px 2px rgba(0, 0, 0, 0.5),
              0 0 12px rgba(184, 134, 47, 0.45);
}
.clicked-space{
  box-shadow: 0 0 0 3px white, 0 0 20px rgba(255, 255, 255, 0.6),
              5px 6px 18px rgba(0, 0, 0, 0.55);
}
.new-space{
  border: 3px solid var(--gold-bright);
  box-shadow: 0 0 14px rgba(224, 172, 72, 0.5), 5px 6px 18px rgba(0, 0, 0, 0.55);
}

/* Parchment panels. `color-scheme: dark` makes the UA default text
   colour white, so anything sitting on parchment must set ink itself. */
.turns, .scores, .rules {
  color: var(--ink);
}

.turns{
  width: 100%;
  box-sizing: border-box;
  background: url(../images/largeimage.jpg);
  border: none;
  border-bottom: 3px solid black;
  text-align: center;
  padding: 12px 15px;
}

/* Player color indicator on the turns panel */
.turns[data-player="player1"] {
  box-shadow: inset 0 0 0 10px slategrey;
}
.turns[data-player="player2"] {
  box-shadow: inset 0 0 0 10px #673131;
}
.turns[data-player="player3"] {
  box-shadow: inset 0 0 0 10px #0e7490;
}
.turns[data-player="player4"] {
  box-shadow: inset 0 0 0 10px #581c87;
}

#round-counter {
  color: var(--ink);
  font-size: 0.8em;
  padding: 4px 0 0;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.side-bar{
  grid-area: side;
  border: 3px solid var(--gold);
  display: flex;
  margin: 0;
  border-radius: 10px;
  flex-direction: column;
  justify-content: flex-start;
  align-self: stretch;
  width: auto;
  min-height: 0;
  /* Taller than its cell on a short screen — scroll here, not the page. */
  overflow-y: auto;
  overflow-x: hidden;
}

.button:active {
  background-color: var(--gold);
  color: var(--bg-0);
  transform: translateY(3px);
  box-shadow: inset 0 0 18px 2px rgba(0, 0, 0, 0.5);
}

.scores{
  width: 100%;
  box-sizing: border-box;
  background: url(../images/largeimage.jpg);
  border: none;
  border-bottom: 3px solid black;
  text-align: center;
  padding: 12px 15px;
  /* Unit totals — counted, so mono. */
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.85em;
}

.rules{
  width: 100%;
  box-sizing: border-box;
  /* Takes the slack so the parchment runs to the foot of the sidebar. */
  flex: 1 1 auto;
  min-height: 120px;
  background: url(../images/largeimage.jpg);
  border: none;
  text-align: center;
  padding: 10px 15px;
}

#warning {
  width: 100%;
  box-sizing: border-box;
  background: url(../images/largeimage.jpg);
  border: 2px solid rgba(166, 60, 29, 0.75);
  text-align: center;
  padding: 10px 15px;
  color: var(--danger-deep);
  font-size: 1.05em;
  animation: warning-fade-in 0.2s ease,
             warning-blink   0.4s ease 0.2s 5;
}

@keyframes warning-fade-in {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes warning-blink {
  0%, 100% { border-color: rgba(166, 60, 29, 0.75); }
  50%       { border-color: rgba(166, 60, 29, 0.05); }
}

#dice-result {
  width: 100%;
  box-sizing: border-box;
  background: url(../images/largeimage.jpg);
  border: none;
  border-bottom: 3px solid black;
  text-align: center;
  padding: 10px 15px;
  font-size: 0.8em;
  color: var(--ink);
  /* Dice totals — counted, so mono. */
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

#dice-attacker,
#dice-defender {
  margin: 4px 0;
}

#dice-outcome {
  font-weight: bold;
  margin-top: 6px;
  color: var(--ink);
}
/* Red is reserved for harm — a raid that failed. */
#dice-outcome.held {
  color: var(--danger-deep);
}

#setup {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: center;
  gap: 6px;
  padding: 0;
  margin: 0;
}

.setup-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  background: var(--setup-group-bg);
  border: 1px solid var(--setup-group-border);
  border-radius: 8px;
  padding: 6px 10px 8px;
}

.setup-label {
  font-family: var(--font-mono);
  font-size: 0.7em;
  color: var(--setup-label-color);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.setup-btns {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
}

/* Shared button base — all types consolidated */
.size-btn, .player-btn, .shape-btn, .island-btn, .bot-btn {
  font-family: var(--font-display);
  font-size: 0.85em;
  padding: 5px 14px;
  background-color: var(--parchment-2);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  box-shadow: inset 0 0 8px 1px rgba(0,0,0,0.5);
  color: var(--ink);
}
.size-btn:hover, .player-btn:hover, .shape-btn:hover, .island-btn:hover, .bot-btn:hover {
  background-color: var(--gold);
  color: var(--bg-0);
}
.size-btn:active, .player-btn:active, .shape-btn:active, .island-btn:active, .bot-btn:active {
  transform: translate(2px, 2px);
}
.size-btn.active, .player-btn.active, .shape-btn.active, .island-btn.active, .bot-btn.active {
  background-color: var(--gold);
  color: var(--bg-0);
}

.bot-rows {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.bot-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 5px;
}

.bot-player-label {
  font-family: var(--font-mono);
  font-size: 0.8em;
  font-weight: bold;
  width: 22px;
  text-align: right;
  flex-shrink: 0;
}
.bot-p2 { color: #8a5050; }
.bot-p3 { color: #3d7a4a; }
.bot-p4 { color: #6b4a8a; }

/* ── Score bar ─────────────────────────────────── */
#score-bar {
  display: flex;
  flex: 0 0 auto;
  height: 12px;
  border-radius: 4px;
  overflow: hidden;
  margin: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

.score-segment {
  height: 100%;
  width: 0;
  transition: width 0.4s ease;
}

#seg-player1 { background: linear-gradient(90deg, #3a5260, #a0b4c0); }
#seg-player2 { background: linear-gradient(90deg, #7a1a08, #e05530); }
#seg-player3 { background: linear-gradient(90deg, #0e7490, #22d3ee); }
#seg-player4 { background: linear-gradient(90deg, #581c87, #c084fc); }

/* ── Hex map layout ───────────────────────────── */
.map.hex-mode {
  display: flex;
  align-items: center;
  justify-content: center;
}

.hex-grid-wrapper {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.hex-row {
  display: flex;
  flex-direction: row;
  gap: var(--hex-gap, 0px);
  margin-bottom: var(--hex-row-offset, -30px);
}

.hex-row-odd {
  margin-left: var(--hex-half-w, 68px);
}

.hex-mode .space {
  flex: 0 0 auto;
  width: var(--hex-w, 138px);
  height: var(--hex-h, 159px);
  aspect-ratio: unset;
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  border-radius: 0;
  box-shadow: none;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.5));
}

/* Inset box-shadow renders inside clip-path; z-index elevates over sibling hexes */
.hex-mode .clicked-space {
  box-shadow: inset 0 0 35px rgba(255, 255, 255, 0.9);
  filter: drop-shadow(0 0 10px white) drop-shadow(0 0 5px white);
  z-index: 2;
}
.hex-row:has(.clicked-space) { z-index: 2; }

.hex-mode .new-space {
  border: none;
  box-shadow: inset 0 0 28px rgba(255, 215, 0, 0.9);
  filter: drop-shadow(0 0 8px gold) drop-shadow(0 0 4px gold);
  z-index: 1;
}
.hex-row:has(.new-space) { z-index: 1; }

/* ── Triangle map layout ──────────────────────── */
.map.tri-mode {
  display: flex;
  align-items: center;
  justify-content: center;
}

.tri-grid-wrapper {
  position: relative;
  width: var(--tri-row-w);
  height: var(--tri-total-h);
}

.tri-mode .space {
  position: absolute;
  width: var(--tri-w);
  height: var(--tri-h);
  aspect-ratio: unset;
  border-radius: 0;
  box-shadow: none;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.5));
  display: flex;
  justify-content: center;
}

.tri-mode [data-orientation="up"] {
  clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
  align-items: flex-end;
  padding-bottom: 10%;
}

.tri-mode [data-orientation="down"] {
  clip-path: polygon(0% 0%, 100% 0%, 50% 100%);
  align-items: flex-start;
  padding-top: 10%;
}

.tri-mode .clicked-space {
  box-shadow: inset 0 0 35px rgba(255, 255, 255, 0.9);
  filter: drop-shadow(0 0 10px white) drop-shadow(0 0 5px white);
  z-index: 2;
}

.tri-mode .new-space {
  border: none;
  box-shadow: inset 0 0 28px rgba(255, 215, 0, 0.9);
  filter: drop-shadow(0 0 8px gold) drop-shadow(0 0 4px gold);
  z-index: 1;
}


.p3-control {
  display: none;
}

.p4-control {
  display: none;
}

.footer {
  grid-area: foot;
  box-sizing: border-box;
  width: 100%;
  padding: 4px 6px 2px;
  font-size: 0.75em;
  color: var(--footer-text);
}
.footer a {
  color: var(--footer-link);
}
#version {
  cursor: pointer;
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--version-color);
  border: 1px solid var(--version-border);
  padding: 2px 10px;
  border-radius: 3px;
  letter-spacing: 0.08em;
  transition: color 0.15s, border-color 0.15s;
}
#version:hover {
  color: var(--version-hover-color);
  border-color: var(--version-hover-border);
  text-decoration: none;
}

/* ── Changelog modal ───────────────────────────────── */
#changelog-modal {
  position: fixed;
  inset: 0;
  background: rgba(10, 8, 7, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: modal-backdrop-in 0.2s ease;
}
#changelog-modal[hidden] {
  display: none;
}
#changelog-dialog {
  position: relative;
  width: min(460px, 92vw);
  max-height: 80vh;
  background: url(../images/largeimage.jpg);
  border: 3px double rgba(184, 134, 47, 0.75);
  border-radius: 4px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.75), inset 0 0 60px rgba(0, 0, 0, 0.12);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modal-dialog-in 0.22s ease;
}
#changelog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px 10px;
  border-bottom: 2px solid rgba(184, 134, 47, 0.45);
}
#changelog-header h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1em;
  color: var(--ink);
  text-shadow: 1px 1px 4px rgba(0, 0, 0, 0.45);
  letter-spacing: 0.05em;
}
#changelog-close {
  background: none;
  border: 1px solid rgba(184, 134, 47, 0.45);
  color: var(--ink-soft);
  font-family: var(--font-display);
  font-size: 0.95em;
  width: 28px;
  height: 28px;
  border-radius: 3px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
#changelog-close:hover {
  background: rgba(184, 134, 47, 0.25);
}
#changelog-body {
  overflow-y: auto;
  padding: 14px 20px 20px;
  color: var(--ink);
}
#changelog-body h3 {
  font-family: var(--font-display);
  font-size: 0.8em;
  color: var(--ink-soft);
  margin: 14px 0 6px;
  letter-spacing: 0.04em;
}
#changelog-body h3:first-child {
  margin-top: 0;
}
#changelog-body ul {
  margin: 0 0 4px;
  padding-left: 18px;
}
#changelog-body li {
  font-size: 0.88em;
  line-height: 1.55;
  margin-bottom: 2px;
}
@keyframes modal-backdrop-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes modal-dialog-in {
  from { opacity: 0; transform: scale(0.93) translateY(-10px); }
  to   { opacity: 1; transform: scale(1)    translateY(0); }
}

/* ── Responsive breakpoints ───────────────────── */

/* Short screens: the chrome gives up height before the board does. */
@media (max-height: 820px) {
  .wordmark h1     { font-size: 1.65rem; }
  .wordmark img    { width: 48px; margin-right: 8px; }
  .button          { padding: 14px 15px; }
  .turns           { padding: 8px 15px; }
  .scores          { padding: 8px 15px; }
  .setup-group     { padding: 4px 8px 5px; }
  .size-btn, .player-btn, .shape-btn, .island-btn, .bot-btn {
    padding: 3px 11px;
  }
}

@media (max-width: 1100px) {
  :root { --col-word: 210px; --col-side: 260px; }
}

@media (max-width: 900px) {
  /* Not enough width for a wordmark column — give the whole top row
     to the setup strip and let the title sit above it. */
  .container {
    grid-template-columns: minmax(0, 1fr) var(--col-side);
    grid-template-areas:
      "word word"
      "top  top"
      "map  side"
      "foot foot";
    grid-template-rows: auto auto minmax(0, 1fr) auto;
  }
}

/* Phones: stop pretending one screen is the right shape. Stack it,
   let the page scroll, and size the board from its width alone. */
@media (max-width: 680px) {
  body {
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }

  .container {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "word"
      "top"
      "map"
      "side"
      "foot";
    grid-template-rows: auto auto auto auto auto;
    height: auto;
    gap: 10px 0;
    padding: 10px 12px 20px;
  }

  .map-area {
    container-type: inline-size;
    overflow: visible;
  }

  .map {
    width: 100%;
    height: auto;
    aspect-ratio: 1;
    padding: 16px;
    gap: 8px;
  }

  /* Width-only container here, so cqmin has no height axis to read. */
  .space h2 {
    font-size: clamp(0.8rem, calc(14cqw / var(--grid-cols, 4)), 1.9rem);
  }

  .side-bar {
    width: 100%;
    margin: 0;
    overflow: visible;
    border-radius: 10px;
  }

  #setup {
    gap: 6px;
    padding: 0;
  }

  .setup-group {
    padding: 5px 8px 6px;
  }

  .size-btn, .bot-btn, .player-btn, .shape-btn, .island-btn {
    padding: 4px 10px;
    font-size: 0.8em;
  }

  .button { padding: 18px 12px; }
  .rules  { min-height: 100px; }

  .wordmark h1     { font-size: 1.5rem; }
  .wordmark h1 small { letter-spacing: 0.24em; text-indent: 0.24em; }
  .wordmark img    { width: 46px; margin-right: 7px; }
}

@media (max-width: 400px) {
  #setup { gap: 5px; }
  .setup-group { padding: 4px 6px 5px; }
  .size-btn, .bot-btn, .player-btn, .shape-btn, .island-btn { padding: 3px 7px; font-size: 0.75em; }
}