:root {
  color-scheme: light;
  font-family: system-ui, sans-serif;
  color: #221f1a;
  background: #f4f0e6;
  --paper: #fffdf7;
  --table: #ddd5c3;
  --muted: #675f50;
  --line: #cbc2ad;
  --ink: #221f1a;
  --error: #9e251d;
  --pitch: 80px;
  --base-pitch: 80px;
  --inset: 3px;
  --corner: 6px;
}
* { box-sizing: border-box; }
body, p, h1, ol { margin: 0; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
button, input, select { font: inherit; }
button, select { cursor: pointer; }
button {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .55rem .8rem;
  min-height: 44px;
  background: var(--paper);
  color: var(--ink);
  font-weight: 650;
}
button:focus-visible, summary:focus-visible, input:focus-visible, select:focus-visible, #viewport:focus-visible {
  outline: 3px solid #285ba9;
  outline-offset: -3px;
}
main, main * { touch-action: manipulation; }
button:disabled { opacity: .48; cursor: default; }
button[aria-pressed="true"] { background: #e4ece5; border-color: var(--ink); }
.primary { background: var(--active, var(--ink)); color: var(--active-ink, white); border-color: var(--active, var(--ink)); }
.brand { font-weight: 850; letter-spacing: -.045em; font-size: 1.35rem; color: var(--ink); }
#setup, .lan-panel {
  max-width: 33rem;
  margin: clamp(14px, 5dvh, 55px) auto;
  padding: clamp(15px, 4vw, 34px);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 22px;
  display: grid;
  gap: 18px;
}
#setup h1 { margin: 0 0 6px; font-size: clamp(2.2rem, 7vw, 3rem); letter-spacing: -.06em; line-height: 1; }
#setup p, small { color: var(--muted); }
.setup-hero { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.setup-title p { max-width: 19rem; }
.setup-map { flex: none; display: grid; grid-template-columns: repeat(4, var(--map-tile, 46px)); grid-auto-rows: var(--map-tile, 46px); gap: 1px; padding: 6px; border-radius: 10px; background: var(--table); transform: rotate(-4deg); }
.setup-map .tile { border-radius: 3px; }
.card-button { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 12px; width: 100%; padding: 12px 14px; border-radius: 14px; text-align: start; }
.card-button strong, .card-button small, .mode-choices strong, .mode-choices small, .river-option small { display: block; }
.card-button small, .mode-choices small { margin-top: 2px; font-weight: 450; }
.card-button .arrow { font-size: 1.3rem; }
#resume { grid-template-columns: minmax(0, 1fr) auto; border: 2px solid var(--ink); }
.card-button.learn { background: #fff4c4; border-color: #e2cd78; }
.card-tile, .option-tile { flex: none; width: 46px; height: 46px; overflow: hidden; border-radius: 6px; }
.play-modes h2 { margin: 0 0 8px; font-size: 1rem; }
.mode-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.mode-choices > button, .choice { padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); text-align: start; cursor: pointer; }
.choice { position: relative; font-weight: 650; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice:has(input:checked) { background: #e4ece5; border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.choice:has(input:focus-visible) { outline: 3px solid #285ba9; outline-offset: -3px; }
.mode-choices > button[aria-pressed="true"] { background: #e4ece5; border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.quiet { justify-self: center; min-height: 44px; border: 0; background: none; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.lan-panel h1, #lan-waiting h2 { margin: 8px 0 4px; }
#lan-form, .lan-details { display: grid; gap: 14px; }
.lan-details > label:not(.river-option) { display: grid; gap: 4px; font-weight: 650; }
.lan-details input:not([type="checkbox"], [type="radio"]) { width: 100%; min-height: 44px; padding: .55rem; border: 1px solid var(--line); border-radius: 8px; background: white; }
#lan-room-code { display: block; margin-top: 6px; font-size: 2rem; letter-spacing: .14em; font-variant-numeric: tabular-nums; }
#lan-match-status { display: block; overflow-wrap: anywhere; }
#guide { width: min(36rem, calc(100% - 24px)); max-height: calc(100dvh - 24px); padding: 0; border: 1px solid var(--line); border-radius: 16px; color: var(--ink); background: var(--paper); overflow: hidden; }
#guide[open] { display: flex; flex-direction: column; }
#guide::backdrop { background: #221f1a80; }
#guide > header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
#guide h2 { margin: 0; }
.guide-content { overflow: auto; overscroll-behavior: contain; padding: 12px 16px 16px; line-height: 1.5; }
.guide-content details { margin-top: 10px; border: 1px solid var(--line); border-radius: 9px; }
.guide-content summary { padding: 10px; font-weight: 700; cursor: pointer; }
.guide-content details > :not(summary) { margin: 0 10px 10px; }
.guide-content ol { padding-inline-start: 24px; }
.guide-content li + li { margin-top: 6px; }
.guide-content h3 { margin: 0; font-size: 1.1rem; }
.guide-content p { margin: 0; }
.guide-content details p + p { margin-top: 8px; }
.guide-tabs, .score-choices { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin-top: 12px; }
.score-choices.two { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 0; }
.guide-tabs button, .score-choices button { padding-inline: 6px; }
#guide button { -webkit-tap-highlight-color: transparent; }
.guide-tabs [aria-selected="true"] { background: #e4ece5; border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.guide-panel { display: grid; gap: 12px; margin-top: 14px; }
.practice-step p, #score-text { color: var(--muted); }
.practice-board, .score-board { --pitch: min(88px, calc((100vw - 96px) / 3)); justify-self: center; display: grid; grid-template-columns: repeat(var(--columns, 3), var(--pitch)); padding: 10px; border-radius: 12px; background: var(--table); }
span.cell { display: block; }
.score-badge { position: absolute; top: 7px; left: 7px; z-index: 4; display: grid; place-items: center; min-width: 24px; height: 24px; padding: 0 5px; border: 2px solid var(--paper); border-radius: 12px; color: white; background: var(--ink); font-size: 13px; font-weight: 800; line-height: 1; }
.score-badge.shield { top: auto; left: auto; right: 7px; bottom: 7px; background: #6b3fa0; }
.score-sum { font-size: 1.15rem; font-weight: 800; }
.practice-dock { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 8px 12px; padding: 12px; border: 1px solid var(--line); border-top: 5px solid var(--active); border-radius: 12px; }
.practice-dock .actions { grid-column: 1 / -1; }
.practice-dock .primary { flex: 1; }
.practice-who { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; font-size: 12px; color: var(--muted); }
.practice-who strong { color: var(--ink); font-size: 14px; }
.practice-who .initial { width: 18px; height: 18px; font-size: 10px; color: var(--active-ink); background: var(--active); }
.practice-next { display: grid; gap: 8px; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { margin-bottom: 8px; font-weight: 700; }
.segments { display: grid; gap: 8px; grid-template-columns: repeat(4, 1fr); }
#profiles { display: grid; gap: 14px; }
.profile { display: grid; gap: 8px; padding-left: 10px; border-left: 4px solid var(--player); }
.profile label { display: grid; gap: 4px; font-size: .83rem; font-weight: 650; }
.profile input { width: 100%; min-width: 0; min-height: 42px; padding: .5rem; color: inherit; border: 1px solid var(--line); border-radius: 8px; background: white; font-size: .95rem; }
.color-choices { display: grid; grid-template-columns: repeat(9, minmax(0, 36px)); gap: 5px; }
.color-choices legend { margin-bottom: 6px; font-weight: 650; }
.profile .color-choices legend { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.color-choice { position: relative; display: block; aspect-ratio: 1; border: 3px solid var(--paper); border-radius: 50%; background: var(--swatch); box-shadow: 0 0 0 1px #2228; cursor: pointer; }
.color-choice.auto { background: conic-gradient(#24252a, #f5ca35, #37b85e, #2563eb, #8b5cf6, #d62948, #ff8d32, #ea65a6, #24252a); }
.color-choice input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: inherit; }
.color-choice:has(input:checked) { box-shadow: 0 0 0 2px var(--ink); }
.color-choice:has(input:disabled) { cursor: default; box-shadow: 0 0 0 1px #2224; }
.color-choice:has(input:disabled)::after { content: ""; position: absolute; inset: 0; border-radius: 50%; background: linear-gradient(135deg, transparent 45%, var(--paper) 45% 55%, transparent 55%), #fffdf7a8; }
.color-choice:has(input:focus-visible) { outline: 3px solid #285ba9; outline-offset: 2px; }
.match-options { display: grid; }
.river-option { display: flex; align-items: center; gap: 12px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.river-option input { flex: none; width: 20px; height: 20px; margin: 0; accent-color: var(--ink); }
#match {
  height: 100dvh;
  display: grid;
  grid-template: "board players" auto "board history" minmax(0, 1fr) "dock history" auto / minmax(0, 1fr) clamp(310px, 30vw, 348px);
  overflow: hidden;
}
#players {
  grid-area: players;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  border-left: 2px solid var(--line);
  min-width: 0;
}
.player {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 4px 6px;
  padding: 10px 12px;
  min-width: 0;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
}
.player.active { border-color: var(--player); background: var(--player); color: var(--player-ink); }
.initial {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--player);
  color: var(--player-ink);
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  box-shadow: 0 0 0 2px var(--paper);
}
.player.active .initial { box-shadow: 0 0 0 2px var(--player-ink); }
.player-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reserve { grid-column: 1 / 3; grid-row: 2; display: flex; align-items: center; gap: 6px; font-size: 12px; }
.reserve small { color: inherit; font-size: inherit; }
.dots { display: flex; gap: 2px; }
.dots .meeple { width: 7px; height: 7px; border: 0; }
.dots .out { background: none; box-shadow: inset 0 0 0 1.5px var(--player); opacity: .55; }
.player.active .dots .meeple { background: var(--player-ink); }
.player.active .dots .out { background: none; box-shadow: inset 0 0 0 1.5px var(--player-ink); }
.points { grid-column: 3; grid-row: 1 / 3; align-self: center; font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.points small { color: inherit; font-size: 11px; margin-left: 2px; }
.board { grid-area: board; position: relative; min-height: 0; }
#viewport {
  --inset: var(--zoom-inset, 3px);
  height: 100%;
  overflow: auto;
  overflow-anchor: none;
  overscroll-behavior: contain;
  background: var(--table);
}
#grid { display: grid; width: max-content; position: relative; }
.cell {
  width: var(--pitch);
  height: var(--pitch);
  min-height: 0;
  position: relative;
  border: 0;
  padding: var(--inset);
  border-radius: 0;
  background: radial-gradient(circle, #b9af98 1.5px, transparent 2px);
}
.cell:has(.tile) { background: transparent; }
.cell.adjacent:not(.preview)::before, .cell.river-next::before {
  content: "";
  position: absolute;
  inset: 5px;
  border: 2px dashed #8f856e;
  background: rgb(255 253 247 / .45);
  border-radius: 6px;
  pointer-events: none;
}
.cell.adjacent.fit:not(.preview)::before { border-style: solid; border-color: var(--active); background: rgb(255 253 247 / .85); }
.cell.river-next:not(.preview)::before { border: 2px dashed #2468ad; }
@media (hover: hover) { .cell.adjacent:not(:has(.tile)):hover { background-color: rgb(255 253 247 / .35); } }
.tile { display: block; position: relative; width: 100%; height: 100%; border-radius: var(--corner); background: #61994d url("../tiles.svg"); }
.cell.preview .tile, .cell.counted .tile { outline: 3px solid var(--active, #285ba9); outline-offset: -3px; }
.cell.preview .tile { box-shadow: 0 0 0 2px var(--active), 0 4px 12px #342b244d; }
.cell.counted .tile { outline-color: #ffcf24; box-shadow: 0 0 0 1px var(--ink); }
.cell.dim .tile, .cell.dim .token { opacity: .3; }
.joined .cell:not(.preview) .tile { box-shadow: inset 0 0 0 .5px #0005; }
.cell.claiming .tile { box-shadow: inset 0 0 0 2px var(--active); }
.joined { --corner: 0px; }
.joined #viewport { --inset: 0px; }
.cell.refused:not(.preview)::after {
  content: "";
  position: absolute;
  inset: 4px;
  border: 3px solid var(--error);
  border-radius: 6px;
  pointer-events: none;
  z-index: 2;
}
.cell.preview.refused .tile { outline-color: var(--error); box-shadow: 0 0 0 2px var(--error), 0 4px 12px #342b244d; }
.cell.river-directed.river-next::before { border: 3px solid #2468ad; background: #d8eafb; }
.collision {
  position: absolute;
  z-index: 3;
  pointer-events: none;
  border-radius: 3px;
  background: var(--error);
  box-shadow: 0 0 0 1px var(--paper);
}
.collision.north, .collision.south { left: 5px; right: 5px; height: 5px; }
.collision.west, .collision.east { top: 5px; bottom: 5px; width: 5px; }
.collision.north { top: var(--inset); }
.collision.south { bottom: var(--inset); }
.collision.west { left: var(--inset); }
.collision.east { right: var(--inset); }
#board-error {
  position: absolute;
  z-index: 6;
  transform: translate(-50%, -100%);
  width: max-content;
  max-width: min(250px, calc(100% - 16px));
  padding: 7px 10px;
  color: white;
  background: var(--error);
  border-radius: 10px;
  box-shadow: 0 4px 12px #342b244d;
  font-size: 13px;
  font-weight: 650;
  line-height: 1.25;
  text-align: center;
  pointer-events: none;
}
#board-error.below { transform: translateX(-50%); }
#board-error::after {
  content: "";
  position: absolute;
  left: var(--arrow-x, 50%);
  top: 100%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--error);
}
#board-error.below::after { top: auto; bottom: 100%; border-top-color: transparent; border-bottom-color: var(--error); }
.region-target {
  position: absolute;
  z-index: 4;
  display: grid;
  place-items: center;
  min-height: 0;
  width: clamp(20px, calc(var(--pitch) * .38), 38px);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border: 3px solid var(--active, var(--ink));
  border-radius: 50%;
  color: var(--ink);
  background: var(--paper);
  box-shadow: 0 2px 5px #342b2440;
  padding: 0;
}
.region-target::before, .region-target::after {
  content: "";
  grid-area: 1 / 1;
  width: 48%;
  height: 3px;
  border-radius: 2px;
  background: currentColor;
}
.region-target::after { transform: rotate(90deg); }
.region-target.blocked { border-color: #746b57; background: #e9e4d6; color: #675f50; }
.region-target.blocked::before { transform: rotate(45deg); }
.region-target.blocked::after { transform: rotate(-45deg); }
.region-target.mine { border-color: white; background: transparent; }
.region-target.mine::before, .region-target.mine::after { content: none; }
.region-target.refused, .region-target.blocked:hover { border-color: var(--error); }
.region-target.monastery, .token.monastery.meeple { border-radius: 25%; }
.cell.claim-owner .tile { outline: 3px solid var(--owner); outline-offset: -3px; }
.token { position: absolute; z-index: 3; width: calc(var(--pitch) * .34); height: calc(var(--pitch) * .34); transform: translate(-50%, -50%); pointer-events: none; display: grid; place-items: center; font-size: calc(var(--pitch) * .2); line-height: 1; font-weight: 800; color: var(--player-ink); }
.meeple { border: 2px solid white; border-radius: 50%; background: var(--player); }
#handoff {
  position: absolute;
  z-index: 5;
  top: 24%;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: min(290px, calc(100% - 24px));
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  color: var(--active-ink, white);
  background: var(--active, var(--ink));
  border-radius: 12px;
  box-shadow: 0 0 0 2px var(--paper), 0 6px 16px #342b244d;
  pointer-events: none;
}
#handoff small, #handoff strong { display: block; color: inherit; overflow-wrap: anywhere; }
.board-tools, .map-controls {
  position: absolute;
  top: 8px;
  z-index: 5;
}
.board-tools { right: 8px; }
.board-tools, .board-tools * { -webkit-user-select: none; user-select: none; }
.board-tools summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  background: var(--paper);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.25;
  cursor: pointer;
  list-style: none;
}
.board-tools summary::-webkit-details-marker { display: none; }
.chevron {
  display: grid;
  flex: 0 0 16px;
  width: 16px;
  height: 16px;
  place-items: center;
}
.chevron::before {
  content: "";
  width: 7px;
  height: 7px;
  border: solid currentColor;
  border-width: 0 2px 2px 0;
  transform: translateY(-2px) rotate(45deg);
}
.board-tools[open] summary .chevron,
#history-toggle[aria-expanded="true"] .chevron { transform: rotate(180deg); }
.tool-list {
  position: absolute;
  inset: calc(100% + 6px) 0 auto auto;
  display: grid;
  width: min(224px, calc(100vw - 24px));
  max-height: calc(100dvh - 128px);
  overflow: auto;
  gap: 2px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  box-shadow: 0 8px 20px #342b2426;
}
.tool-list button { border: 0; text-align: left; font-size: 14px; }
.tool-list button:hover { background: #f2ede1; }
.tool-list button[aria-pressed="true"] { background: #eae3d5; }
.map-controls {
  left: 8px;
  display: flex;
  gap: 2px;
  padding: 2px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.map-controls button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-width: 44px; border: 0; padding: 4px 8px; font-size: 14px; }
.map-controls svg { width: 20px; height: 20px; flex: none; }
@media (max-width: 360px) {
  .map-controls #zoom-fit span { display: none; }
}
#hints { font-size: 13px; background: var(--paper); }
#hints { font-size: 13px; background: var(--paper); }
#hints { position: absolute; bottom: 8px; right: 8px; border: 2px solid var(--line); border-radius: 999px; }
#hints[aria-pressed="true"] { border-color: var(--active); }
#return { position: absolute; bottom: 8px; left: 8px; z-index: 5; background: #fff4c4; }
aside, .dock { min-width: 0; background: var(--paper); }
aside { grid-area: history; display: grid; grid-template-rows: auto minmax(0, 1fr); border-left: 2px solid var(--line); border-top: 2px solid var(--line); overflow: hidden; }
.history-header { display: grid; min-width: 0; gap: 4px; padding: 7px 12px; border-bottom: 1px solid #e9e1d1; }
#history-toggle { display: flex; align-items: center; gap: 8px; border: 0; text-align: left; padding-inline: 4px; line-height: 1.25; }
#history-toggle .chevron { margin-left: auto; }
#history-count { display: grid; place-items: center; min-height: 20px; padding: 0 8px; border-radius: 999px; color: white; background: var(--ink); font-size: 12px; line-height: 1; }
#history-latest { min-width: 0; padding: 0 4px 3px; overflow-wrap: anywhere; font-size: 13px; color: var(--muted); }
#history-toggle[aria-expanded="true"] + #history-latest { display: none; }
#history-body { min-width: 0; overflow: hidden auto; overscroll-behavior: contain; padding: 8px 8px 10px; }
aside:has(#history-toggle[aria-expanded="false"]) #history-body { display: none; }
#history { display: grid; gap: 5px; list-style: none; padding: 0; }
.history-row {
  width: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  font-size: 14px;
  font-weight: 500;
  text-align: left;
}
.history-row { border: 1px solid #e9e1d1; border-radius: 10px; background: #fbf8f0; }
button.history-row:hover { border-color: #b9a989; }
.history-row[aria-pressed="true"] { border-color: var(--ink); background: #fff4c4; }
.history-turn { flex: 0 0 22px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.history-players { display: flex; flex: 0 0 auto; flex-wrap: wrap; max-width: 48px; gap: 3px; }
.history-thumb { position: relative; width: 22px; height: 22px; flex: none; }
.history-thumb .tile { border-radius: 2px; }
.history-copy { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.history-copy > span { display: block; font-weight: 650; line-height: 1.2; margin-bottom: 2px; }
.score-detail { display: block; color: var(--muted); font-size: 12px; }
.score-row { background: #f3eedf; }
.history-gain { flex: none; align-self: center; padding: 3px 6px; border-radius: 6px; background: #e9dec6; font-size: 13px; font-weight: 800; }
.dock {
  grid-area: dock;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px 12px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 5px solid var(--active, var(--ink));
}
#turn-tile, .turn-tile { width: 64px; height: 64px; padding: 0; border: 2px solid var(--active, var(--ink)); border-radius: 6px; overflow: hidden; }
#turn-tile:disabled, .turn-tile:disabled { opacity: 1; }
#turn-tile .tile, .turn-tile .tile { border-radius: 0; }
#turn-player { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; overflow-wrap: anywhere; font-size: 12px; color: var(--muted); }
#turn-player strong { color: var(--ink); font-size: 14px; }
#turn-player .initial { width: 18px; height: 18px; font-size: 10px; }
#turn-status, .turn-status { font-size: 18px; font-weight: 800; line-height: 1.2; margin-top: 2px; overflow-wrap: anywhere; }
#feedback, .feedback { font-size: 13px; line-height: 1.3; color: var(--muted); }
#feedback.error, .feedback.error { color: var(--error); }
.actions { display: flex; gap: 8px; }
.actions button { min-height: 48px; border: 2px solid var(--active, var(--ink)); border-radius: 12px; }
#advance { min-width: clamp(130px, 15vw, 220px); }
#advance:disabled, #practice-advance:disabled { border-color: var(--line); background: #e9e4d6; color: var(--muted); opacity: 1; }
.dock:has(#turn-tile[hidden]) .turn-copy { grid-column: 1 / 3; }
main:has(:is(#save-status, #file-status):not([hidden])) {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}
main:has(:is(#save-status, #file-status):not([hidden])):has(#match:not([hidden])) { height: 100dvh; }
:is(#save-status, #file-status):not([hidden]) ~ #match { flex: 1; min-height: 0; height: auto; }
#save-status, #file-status {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  color: white;
  background: var(--error);
  font-size: 14px;
  font-weight: 650;
}
#save-status button { min-height: 36px; padding: .3rem .7rem; }
#replace { max-width: min(26rem, calc(100% - 32px)); padding: 20px; border: 1px solid var(--line); border-radius: 16px; background: var(--paper); color: var(--ink); }
#replace::backdrop { background: #221f1a80; }
#replace h2 { margin: 0 0 8px; font-size: 1.25rem; }
#replace p { color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.danger { background: var(--error); border-color: var(--error); color: white; }
@media (max-width: 899px) {
  :root { --pitch: 60px; --base-pitch: 60px; }
  #viewport.claim-zoom { --base-pitch: 100px; }
  #match { grid-template: "players" auto "board" minmax(0, 1fr) "history" auto "dock" auto / minmax(0, 1fr); }
  #players { flex-direction: row; overflow-x: auto; padding: 8px 8px 6px; border: 0; }
  .player { min-width: 105px; flex: 1; padding: 6px 8px; }
  .player.active { min-width: 130px; flex: 1.5; }
  .points { font-size: 16px; }
  .points small, .reserve small { display: none; }
  aside { border-left: 0; }
  #history-body { max-height: min(30dvh, 220px); }
  .dock { grid-template-columns: auto minmax(0, 1fr); padding: 10px 12px; }
  .actions { grid-column: 1 / -1; }
  #advance { flex: 1; }
  #setup, .lan-panel { margin-inline: auto; width: calc(100% - 20px); }
}
@media (max-width: 440px) {
  .setup-hero { --map-tile: 30px; }
  .setup-map { transform: rotate(-4deg) translateX(6px); }
}
@media (max-width: 899px) and (max-height: 500px) and (orientation: landscape) {
  #match { grid-template: "board players" auto "board history" minmax(0, 1fr) "dock history" auto / minmax(0, 1fr) minmax(9rem, 28vw); }
  #players { flex-direction: column; max-height: 40dvh; overflow: auto; }
  .player, .player.active { min-width: 0; }
  #history-body { max-height: none; }
  .dock { grid-template-columns: auto minmax(0, 1fr) auto; gap: 6px; padding: 6px 10px; }
  .actions { grid-column: auto; }
}
@media (max-width: 620px) and (max-height: 500px) and (orientation: landscape) {
  .dock { grid-template-columns: auto minmax(0, 1fr); gap: 4px 6px; padding-block: 4px; }
  #turn-tile { width: 44px; height: 44px; }
  #turn-status { font-size: 15px; }
  .actions { grid-column: 1 / -1; }
  .actions button { min-height: 44px; padding-block: 4px; }
}
