:root {
  color-scheme: light;
  --paper: #f4eddd;
  --ink: #182a3b;
  --navy: #142337;
  --muted: #526172;
  --border: #d4c9b6;
  --gold: #f0bc5a;
  font: 16px/1.45 system-ui, sans-serif;
  background: var(--paper);
  color: var(--ink);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
p, h1, h2 { margin: 0; }
h1 { font-family: Georgia, serif; line-height: 1.06; font-weight: 600; }
h2 { font-size: 1.12rem; line-height: 1.25; }

.match-shell {
  --edge-top: max(8px, env(safe-area-inset-top));
  --edge-right: max(8px, env(safe-area-inset-right));
  --edge-bottom: max(8px, env(safe-area-inset-bottom));
  --edge-left: max(8px, env(safe-area-inset-left));
}
.match-shell main {
  max-inline-size: 1110px;
  block-size: 100vh;
  block-size: 100dvh;
  padding: var(--edge-top) var(--edge-right) var(--edge-bottom) var(--edge-left);
  margin: auto;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
}
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  min-inline-size: 0;
  border-bottom: 1px solid var(--border);
}
.page-header h1 {
  min-inline-size: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: clamp(1rem, 3vw, 2rem);
  white-space: nowrap;
}
.header-actions, .match-actions {
  display: flex;
  align-items: center;
  gap: 5px;
}
.match-actions { flex-wrap: wrap; }
.match-actions .actions { display: contents; }
.shell-link {
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  min-block-size: 44px;
  padding-inline: 7px;
  white-space: nowrap;
}
.header-actions button:not(.cell), .match-actions button:not(.cell) {
  min-block-size: 44px;
  padding: 4px 8px;
  font-size: .85rem;
}
.header-actions .shell-link { font-size: .85rem; }
.header-actions { flex-shrink: 0; }
@media (max-width: 370px) {
  .header-actions { gap: 3px; }
  .header-actions button:not(.cell), .header-actions .shell-link { padding-inline: 5px; }
}

.arena {
  display: grid;
  grid-template: "heading" auto "board" minmax(0, 1fr) "controls" auto / minmax(0, 1fr);
  gap: 7px;
  min-inline-size: 0;
  min-block-size: 0;
}
.arena-header {
  grid-area: heading;
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 8px;
  min-inline-size: 0;
}
.match-heading { min-inline-size: 0; }
.arena-header h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.label {
  text-transform: uppercase;
  letter-spacing: .1em;
  font-size: .66rem;
  font-weight: 750;
  color: var(--muted);
}
.dimensions { font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; font-size: .78rem; }
.arena-controls {
  grid-area: controls;
  min-inline-size: 0;
  display: grid;
  gap: 4px;
  overflow-wrap: anywhere;
  line-height: 1.25;
  font-size: .83rem;
}
.arena-controls p:empty { display: none; }
.status, #roll-note, .online-connection { color: var(--muted); }
.board-viewport {
  grid-area: board;
  position: relative;
  overflow: clip;
  min-inline-size: 0;
  min-block-size: 0;
  container-type: size;
  display: grid;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  place-items: center;
}
@media (min-width: 760px), (orientation: landscape) and (min-width: 520px) {
  .arena {
    grid-template:
      "board heading" auto
      "board controls" auto
      "board ." minmax(0, 1fr)
      / minmax(0, 1fr) clamp(196px, 32vw, 260px);
    column-gap: 12px;
  }
}
@media (orientation: landscape) and (min-width: 520px) and (max-height: 400px) {
  .arena { grid-template-columns: minmax(0, 1fr) clamp(228px, 44vw, 260px); }
}

.board-viewport.board-panning { touch-action: none; cursor: grab; }
.board-viewport.board-panning:active { cursor: grabbing; }
.board-viewport:focus-visible { outline-offset: -3px; }
#board-pan-exit {
  position: absolute;
  inset-block-start: 4px;
  inset-inline-end: 4px;
  z-index: 4;
  min-height: 44px;
  max-inline-size: calc(100% - 8px);
}
#players-dialog .panel-actions { flex-wrap: wrap; }
.board-tool-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; }
.board-tool-controls button:not(.cell) { min-height: 44px; }
#board-zoom-level { min-width: 3.5ch; text-align: center; font-variant-numeric: tabular-nums; }
.board-tool-hint { margin-top: 10px; font-size: .88rem; color: var(--muted); }

.board {
  --size: 11;
  inline-size: min(100cqw, 100cqh);
  block-size: min(100cqw, 100cqh);
  transform-origin: center;
  overflow: clip;
  border-radius: 9px;
  background: var(--navy);
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--size), minmax(0, 1fr));
  grid-template-rows: repeat(var(--size), minmax(0, 1fr));
  isolation: isolate;
  user-select: none;
}
.cell {
  min-width: 0; min-height: 0; display: grid; place-items: center; padding: 0;
  border: 0; border-right: 1px solid #51677a; border-bottom: 1px solid #51677a;
  border-radius: 0; background: #20344a; color: white; container-type: size;
}
.cell:nth-child(even) { background: #223950; }
.cell.goal { position: relative; background: var(--gold); color: #382813; font-size: 0; }
.cell.goal:not(:has(.pawn))::before {
  content: "";
  position: absolute;
  inset-block-start: 50%;
  inset-inline-start: 50%;
  transform: translate(-50%, -50%);
  width: 21%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: currentColor;
}
.cell .pawn { pointer-events: none; font-size: min(47cqw, 1rem); line-height: 1; }
.pawn {
  display: inline-grid; place-items: center; width: 70%; aspect-ratio: 1;
  max-width: 2.25rem; color: #132337; font-weight: 800; border-radius: 50%;
  background: var(--pawn); font-variant-numeric: tabular-nums;
}
.cell.active .pawn {
  outline: clamp(1px, 6cqw, 2px) solid white;
  outline-offset: min(4cqw, 2px);
}
.cell.target { cursor: pointer; }
.cell.target::after { content: ""; width: 25%; aspect-ratio: 1; border-radius: 50%; background: #92dbc4; }
.cell.jump-target::after { background: transparent; border: 2px solid #92dbc4; width: 34%; }
.cell.target.goal::after { display: none; }
.cell.target.goal { box-shadow: inset 0 0 0 2px #fff2c6; }
.cell.target:hover { background: #34566b; }
.cell.target.goal:hover { background: #ffd17a; }
.wall-segment { position: absolute; z-index: 2; pointer-events: none; background: #ffd59a; border-radius: 2px; }
.wall-segment.horizontal { width: calc(100% / var(--size)); height: clamp(1px, .6cqw, 4px); transform: translateY(-50%); }
.wall-segment.vertical { height: calc(100% / var(--size)); width: clamp(1px, .6cqw, 4px); transform: translateX(-50%); }
.wall-segment.preview { z-index: 3; background: #8ee1ca; outline: 1px dashed #133629; }
.wall-segment.invalid { background: #ffa594; outline-color: #612519; }
.board.wall-mode { cursor: crosshair; }

button:not(.cell), input {
  font: inherit; background: #faf5e9; color: var(--ink); border: 1px solid #a59780;
  border-radius: 7px; min-height: 42px;
}
button:not(.cell) { padding: 7px 12px; font-weight: 650; cursor: pointer; }
button.primary { color: white; background: #1f4d4b; border-color: #1f4d4b; }
button[aria-pressed="true"] { background: #cce6db; border-color: #648d80; }
button:not(.cell):disabled { cursor: default; opacity: .56; }
:focus-visible { outline: 3px solid #148776; outline-offset: 3px; }
.board:focus-visible, .board :focus-visible { outline-color: #f9eac3; outline-offset: -2px; }

.match-panel {
  --panel-top: var(--edge-top);
  position: fixed;
  inset: var(--panel-top) var(--edge-right) var(--edge-bottom) var(--edge-left);
  inline-size: min(32rem, calc(100% - var(--edge-left) - var(--edge-right)));
  max-inline-size: none;
  block-size: fit-content;
  max-block-size: calc(100vh - var(--panel-top) - var(--edge-bottom));
  max-block-size: calc(100dvh - var(--panel-top) - var(--edge-bottom));
  padding: 0;
  margin: auto;
  color: var(--ink);
  background: #faf5e9;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: clip;
}
.match-panel[open] { display: flex; flex-direction: column; }
.match-panel::backdrop { background: #14233766; }
.panel-title { flex-shrink: 0; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.panel-content { padding: 12px 14px; min-block-size: 0; overflow: auto; overscroll-behavior: contain; }
.panel-content:focus-visible { outline-offset: -3px; }
.panel-content .fields:first-child { margin-top: 0; }
.panel-actions {
  display: flex;
  justify-content: end;
  flex-shrink: 0;
  gap: 8px;
  padding: 8px 14px;
  border-top: 1px solid var(--border);
}
.panel-actions button:not(.cell) { min-block-size: 44px; }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 14px 0 8px; }
.fields label { display: grid; gap: 4px; font-size: .88rem; font-weight: 650; }
.fields input { min-width: 0; width: 100%; padding: 5px 7px; font-size: 1rem; }
.options { display: grid; gap: 5px; font-size: .91rem; margin-bottom: 13px; }
.options label { display: flex; align-items: center; gap: 8px; }
.options input { min-height: 0; width: 17px; height: 17px; margin: 3px 0; accent-color: #1f4d4b; }
.roster { display: grid; gap: 5px; padding: 0; margin: 0; list-style: none; }
.roster li { display: flex; align-items: center; gap: 9px; min-height: 32px; padding: 3px 6px; border-radius: 5px; font-size: .89rem; }
.roster li.current { background: #dbeae1; }
.roster .pawn { flex: 0 0 24px; max-width: 24px; font-size: .72rem; }
.roster .meta { margin-left: auto; color: var(--muted); white-space: nowrap; }
.roster li > span:nth-child(2) { overflow-wrap: anywhere; }

.online .online-name { grid-column: 1 / -1; }
.online .turn-clock { color: var(--muted); font-variant-numeric: tabular-nums; font-size: .85rem; }
.online .clock-warning { color: #7a341b; font-weight: 650; font-size: .83rem; overflow-wrap: anywhere; }
.online:has(#turn-clock:not([hidden])) .match-panel { --panel-top: calc(var(--edge-top) + 9rem); }
.online .turn-settings { margin: 0 0 12px; }
.online #invite-panel, .online .invite-share-field { display: grid; gap: 8px; }
.online #invite-panel { gap: 14px; }
.online #invite-code { font-variant-numeric: tabular-nums; }
.online #invite-panel input { min-width: 0; width: 100%; padding: 5px 7px; font-size: 1rem; }
.online #invite-panel button { justify-self: start; }
.match-panel > .status:empty { display: none; }
.match-panel > .status:not(:empty) { padding: 8px 14px; overflow-wrap: anywhere; }
.discovery-actions { margin-bottom: 12px; }
.public-rooms { display: grid; gap: 12px; margin: 0; padding: 0; list-style: none; }
.public-rooms li { display: grid; gap: 6px; padding-block-end: 10px; border-bottom: 1px solid var(--border); }
.public-rooms li:last-child { padding-block-end: 0; border-bottom: 0; }
.public-room-name, .roster-group li, .online .player-name { overflow-wrap: anywhere; }
.public-room-details { font-size: .86rem; color: var(--muted); }
.roster-group { margin-top: 12px; }
.roster-group h3 { margin: 0 0 5px; font-size: .95rem; }
#public-rooms-dialog .panel-actions { flex-wrap: wrap; }
.bot-settings { display: flex; flex-wrap: wrap; align-items: end; gap: 6px; }
.bot-settings label { display: grid; gap: 4px; font-size: .88rem; font-weight: 650; }
.bot-settings select {
  min-height: 44px; padding: 5px 7px; font: inherit; font-size: 1rem;
  background: #faf5e9; color: var(--ink); border: 1px solid #a59780; border-radius: 7px;
}
.bot-settings button:not(.cell) { min-height: 44px; }
.bot-settings button[aria-disabled="true"] { opacity: .56; cursor: default; }
#bot-configurations { display: grid; gap: 8px; margin: 8px 0 0; padding: 0; list-style: none; }
#bot-status:not(:empty) { margin-top: 6px; }

#setup .play-mode { grid-column: 1 / -1; }
#setup .fields select {
  min-width: 0; min-height: 42px; padding: 5px 7px; font: inherit; font-size: 1rem;
  background: #faf5e9; color: var(--ink); border: 1px solid #a59780; border-radius: 7px;
}
