:root {
  --unusable-opacity: 0.45;
  --awaiting: #f39c12;
  --attacker: #c0392b;
  --defender: #1f6fd1;
  --bg: #f6f5f2;
  --panel: #ffffff;
  --text: #1d1d1b;
  --muted: #6b6a66;
  --line: #dddbd5;
  --accent: #2f5fb3;
  --accent-text: #ffffff;
  --selected: #e6edf9;
  --stage: #e9e7e2;
  --error: #a3261b;
  --error-bg: #fbeceb;
  /* Send moves while there are moves to send: white text on it at least 4.5:1, light or dark. */
  --unsent: #c0392b;
  --warning: #e07800;
  --cell: #ff6a00;
  --adjacent: #1f8fff;
  --sidebar-width: 260px;
  --play-log-width: 280px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1c1e;
    --panel: #232427;
    --text: #e8e6e1;
    /* At least 4.5:1 on --selected as well as --panel and --bg. */
    --muted: #a3a19b;
    --line: #3a3b3f;
    --accent: #7aa2ec;
    --accent-text: #10151f;
    --selected: #2c3646;
    --stage: #141516;
    --error: #f09389;
    --error-bg: #3a2220;
    --warning: #ffa94d;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

/* Read by screen readers, not shown. */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

html, body { height: 100%; margin: 0; }

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.module-info { flex: 0 1 auto; min-width: 0; }
/* The sides the player plays in an online game, after the module's name. */
.playing-side { flex: none; font-weight: 600; white-space: nowrap; }
.playing-side[hidden] { display: none; }
/* Whose turn it is and the button ending the phase, between the module's name and the menus on the right. */
.phase-bar { flex: none; display: flex; align-items: center; gap: 10px; }
.phase-bar[hidden] { display: none; }
/* The buttons and slider stepping through a log and the moves made, in the toolbar after the zoom. */
.step-bar { flex: none; display: flex; align-items: center; gap: 6px; }
.step-bar[hidden] { display: none; }
.step-bar .button { white-space: nowrap; }
.step-bar input[type="range"] { width: 160px; margin: 0 4px; }
.step-bar input[type="range"][aria-disabled="true"] { opacity: 0.35; cursor: default; }
.turn-status { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
/* On the color of the side whose turn it is, which the code sets. */
.turn-status.side-colored { padding: 3px 10px; border-radius: 4px; }
/* Muted, online, while it isn't the player's turn. */
.turn-status.not-yours { opacity: 0.55; font-weight: 400; }
/* A bubble holding a location's overlapping stacks side by side, joined to the location by a line. */
.stack-bubble { fill: var(--panel); fill-opacity: 0.92; stroke: var(--text); stroke-width: 2; }
.stack-bubble-line { stroke: var(--text); stroke-width: 2; }
/* The badge on overlapping stacks, saying how many, clicked to open or close their bubble. */
.stack-badge { cursor: pointer; }
.stack-badge circle { fill: var(--accent); stroke: var(--panel); stroke-width: 2; }
.stack-badge.open circle { fill: var(--text); }
.stack-badge text { fill: var(--accent-text); font: 600 16px system-ui, sans-serif; text-anchor: middle; pointer-events: none; }
/* The count on a stack of how many units it holds: plain, as it isn't clicked, and sized by the code to the stack. */
.stack-count { pointer-events: none; }
.stack-count circle { fill: #1d1d1b; fill-opacity: 0.85; stroke: #fff; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.stack-count text { fill: #fff; font-family: system-ui, sans-serif; font-weight: 700; text-anchor: middle; }
.topbar-spacer { flex: 1 1 0; }
.module-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.module-detail { color: var(--muted); font-size: 12px; }
/* A menu: a button opening a list of choices below it, closed by choosing one or clicking elsewhere. */
.menu { position: relative; }
.menu[hidden] { display: none; }
.menu > summary { list-style: none; cursor: pointer; white-space: nowrap; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-list {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 20;
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 4px 0;
  list-style: none;
  min-width: 200px;
  max-width: 60vw;
  max-height: 60vh;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}
/* In the sidebar a menu opens to the right, over the map, rather than off the page's left edge. */
.sidebar .menu-list { right: auto; left: 0; }
.menu-item, .module-document-list a {
  display: block;
  width: 100%;
  padding: 4px 12px;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  text-decoration: none;
  overflow-wrap: anywhere;
  cursor: pointer;
}
.menu-item[hidden] { display: none; }
.menu-item:hover:not(:disabled):not([aria-disabled="true"]), .menu-item:focus-visible, .module-document-list a:hover, .module-document-list a:focus { background: var(--selected); }
.menu-item:disabled, .menu-item[aria-disabled="true"] { color: var(--muted); cursor: default; }
/* Why the item above can't be used, under it in the menu. */
.menu-note { margin: 0 12px 4px; max-width: 280px; }
.menu-list select { margin: 4px 12px; }

.button {
  font: inherit;
  padding: 4px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}
.button:hover { border-color: var(--muted); }
/* Raised: lit from above, with a bevel and a shadow beneath; pressed, it sinks in. The overlays work in both themes. */
.button {
  background-image: linear-gradient(to bottom, rgba(255, 255, 255, 0.22), rgba(0, 0, 0, 0.08));
  border-bottom-color: rgba(0, 0, 0, 0.35);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 2px 0 rgba(0, 0, 0, 0.18), 0 3px 4px rgba(0, 0, 0, 0.15);
  transition: transform 60ms, box-shadow 60ms;
}
.button:hover:not(:disabled):not([aria-disabled="true"]) { background-image: linear-gradient(to bottom, rgba(255, 255, 255, 0.32), rgba(0, 0, 0, 0.04)); }
.button:active:not(:disabled):not([aria-disabled="true"]) {
  transform: translateY(2px);
  background-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.1), rgba(255, 255, 255, 0.1));
  box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.25);
}
.button:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.button.primary { background-color: var(--accent); border-color: var(--accent); border-bottom-color: rgba(0, 0, 0, 0.45); color: var(--accent-text); }
/* Moves not yet sent: Send moves is red, its ring and focus outline too. */
.send-moves.primary { --accent: var(--unsent); --accent-text: #ffffff; }
/* Moves not yet sent: Send moves pulses once, a ring spreading from it, as the first is made; still for reduced motion. */
.button.primary.attention { animation: send-attention 0.9s ease-out 2; }
@keyframes send-attention {
  from { box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 2px 0 rgba(0, 0, 0, 0.18), 0 0 0 0 var(--accent); }
  to { box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 2px 0 rgba(0, 0, 0, 0.18), 0 0 0 10px transparent; }
}
@media (prefers-reduced-motion: reduce) { .button.primary.attention { animation: none; } }
.button.icon { flex: none; width: 30px; padding: 4px 0; }
#toggle-play-log .arrow { display: inline-block; }
#toggle-play-log.below .arrow { transform: rotate(90deg); }

.workspace { flex: 1; display: flex; min-height: 0; }

.sidebar {
  width: var(--sidebar-width);
  flex: none;
  overflow-y: auto;
  padding: 12px 16px;
  border-right: 1px solid var(--line);
  background: var(--panel);
}
body.sidebar-closed .sidebar { display: none; }

/* A handle on a panel's border, dragged to change the panel's width; it takes no room of its own. */
.resizer { flex: none; width: 8px; margin: 0 -4px; position: relative; z-index: 3; cursor: col-resize; touch-action: none; }
.resizer:hover, .resizer.dragging { background: var(--accent); opacity: 0.4; }
.resizer:focus-visible { outline: none; background: var(--accent); opacity: 0.8; }
body.sidebar-closed #sidebar-resizer, body:not(.has-module) #sidebar-resizer { display: none; }
.play-log-resizer { display: none; }
.map-area.dialog-right .play-log-resizer { display: block; }
body.resizing { cursor: col-resize; user-select: none; }

.sidebar h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 4px 0 8px; }

.field[hidden] { display: none; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.field.slider { margin: 12px 0 0; }
.field span { font-size: 12px; color: var(--muted); }
select { font: inherit; padding: 4px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: var(--text); }

.game-options, .refusal-dialog { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--text); padding: 16px 20px; max-width: min(480px, calc(100vw - 32px)); }
.game-options::backdrop, .refusal-dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
.game-options h2 { font-size: 15px; margin: 0 0 12px; }
.game-options .field { margin-bottom: 12px; }
.refusal-dialog .game-messages { margin: 0 0 12px; }
/* The popup saying it has become the player's turn, online, and the one asking if the player is finished with the phase. */
.turn-message { margin: 0 0 12px; font-weight: 600; }
.dialog-buttons { display: flex; justify-content: flex-end; gap: 8px; }
/* The note over the map of the movement points the units picked up have left: it takes no focus, and the map stays
   usable around it. */
.still-moving { position: absolute; top: 12px; left: 12px; right: 12px; width: fit-content; max-width: 560px; margin-inline: auto; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px 12px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--text); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3); }
.still-moving[hidden] { display: none; }
.still-moving-message { margin: 0; flex: 1 1 240px; }
.still-moving-buttons { display: flex; gap: 8px; flex-shrink: 0; }

.check { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.check[hidden] { display: none; }
.check:has(input:disabled) { color: var(--muted); }
.note { color: var(--muted); font-size: 12px; margin: 4px 0 8px; }
.note:empty { display: none; }
/* A status region: kept in the page while empty, taking no room, so that a screen reader is told when it speaks. */
.note.sign-in-to-play:empty { display: block; margin: 0; }
.settings-save { margin: 6px 0 8px; }
.settings-save .note { margin: 4px 0 0; }
/* Kept in the page while empty, so that a screen reader hears it once it is filled. */
.settings-save .note:empty { display: block; margin: 0; }
.sign-in-status > p { margin: 0; }
/* Empty, the sign-in status is only visually hidden, so that its live regions are in the accessibility tree before
   text comes. */
.sign-in-status:not(:has(> :not(:empty))) { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); border: 0; }

.stage { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.zoom-level { min-width: 48px; text-align: center; font-variant-numeric: tabular-nums; }
/* Clear and Redo at the right of the toolbar. */
.clear-trails { margin-left: auto; }
.undo-move[hidden], .redo-move[hidden], .clear-trails[hidden], .hand-over[hidden], .send-moves[hidden] { display: none; }

.message { padding: 6px 12px; border-bottom: 1px solid var(--line); background: var(--selected); }
.message.error { background: var(--error-bg); color: var(--error); }
/* Always in the page, so that what it says is announced; empty, it takes no room. Empty, it is only visually hidden, so
   that its live regions are in the accessibility tree before text comes. */
.message:not(:has(> :not(:empty))) { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); border: 0; }

/* The map, with what the game's rules said beside it or below it, wherever there is more room. */
.map-area { flex: 1; display: flex; min-height: 0; position: relative; }
.map-area.dialog-bottom { flex-direction: column; }
/* A double tap on the map doesn't zoom the page, nor does a tap wait for one; a finger still scrolls and pinch-zooms. */
.viewport { flex: 1; min-width: 0; min-height: 0; overflow: auto; position: relative; background: var(--stage); cursor: crosshair; touch-action: manipulation; }
.viewport:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.viewport.over-piece { cursor: grab; }
.viewport.panning, .viewport.moving { cursor: grabbing; }
.viewport.choosing-combat.over-piece { cursor: pointer; }
/* Pieces picked up by clicking: the next click on the map is where they go. */
.viewport.holding, .viewport.holding.over-piece { cursor: crosshair; }
.viewport.over-tombstone, .viewport.choosing-combat.over-tombstone { cursor: pointer; }
.canvas { display: inline-block; padding: 16px; }
.canvas svg.map { display: block; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25); }

.empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 16px;
  text-align: center;
  cursor: default;
}
.empty-buttons { display: flex; gap: 8px; }
.empty-title { font-size: 18px; font-weight: 600; margin: 0 0 4px; }
/* The page's text, not --muted: muted on the stage is under 4.5:1 in the light scheme. */
.empty .note { color: var(--text); }
.has-module .empty { display: none; }
/* A game the url names is opened straight on its module: no module list or open buttons on the way. */
.empty-opening {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 16px;
  font-size: 18px;
  /* The page's text, not --muted: muted on the stage is under 4.5:1 in the light scheme. */
  color: var(--text);
  cursor: default;
}
.opening-game .empty { display: none; }
.opening-game:not(.has-module) .empty-opening { display: flex; }
.site-module-list { margin: 8px 0 16px; }
.empty-heading { font-weight: 600; margin: 8px 0 4px; }
.site-module-list[hidden], .site-modules[hidden] { display: none; }
.site-module-table { border-collapse: collapse; margin: 0 auto; text-align: left; }
.site-module-table th, .site-module-table td { padding: 4px 8px; }
.site-module-table th { border-bottom: 1px solid var(--line); }
.site-module-table .sort { background: none; border: none; padding: 0; font: inherit; font-weight: 600; color: inherit; cursor: pointer; }
body:not(.has-module) .toolbar, body:not(.has-module) .sidebar { visibility: hidden; }

.game-dialog { flex: none; overflow-y: auto; padding: 8px 12px; background: var(--panel); font-size: 13px; overflow-wrap: anywhere; }
.game-dialog[hidden] { display: none; }
.map-area.dialog-right .game-dialog { width: var(--play-log-width); border-left: 1px solid var(--line); }
.map-area.dialog-bottom .game-dialog { height: 140px; border-top: 1px solid var(--line); }
.game-dialog-title { display: flex; align-items: center; gap: 8px; margin: 0 0 6px; }
.game-dialog h2 { flex: 1; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0; }
.game-messages { list-style: none; margin: 0; padding: 0; }
.game-messages .entry { margin: 0 0 8px; }
.game-messages .entry p { margin: 2px 0 0; }
.game-messages .entry-title { font-weight: 600; }
.game-messages .illegal .entry-title { color: var(--error); }
.game-messages .entry p.warning { padding-left: 6px; border-left: 3px solid var(--warning); }
.game-messages .placeholder { color: var(--muted); }
.game-messages .more-problems summary { cursor: pointer; color: var(--muted); margin: 2px 0 0; }
/* The selected location's panel keeps clear of them. */
.map-area.dialog-right ~ .selection { right: calc(var(--play-log-width) + 16px); }
.map-area.dialog-bottom ~ .selection { bottom: 184px; }

/* One line high whatever it says, cut short if it's longer, so that the map doesn't move as the pointer does. */
.status {
  height: 28px;
  box-sizing: border-box;
  padding: 4px 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-top: 1px solid var(--line);
  background: var(--panel);
  font-variant-numeric: tabular-nums;
}
/* On a narrow screen, a phone's, there is no pointer to move and no hover to show the rest: it wraps instead. One line
   is as high as the empty bar (a 19 px line, its padding and border), so only a second line moves the map; a narrow
   window with a mouse refits it only when what the pointer is over wraps. */
@media (max-width: 700px) {
  .status { height: auto; min-height: 28px; line-height: 19px; white-space: normal; overflow-wrap: anywhere; }
}

/* The id of the grid location under the pointer, beside the pointer. */
.location-id {
  position: fixed;
  z-index: 1;
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
}
.location-id { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; max-width: 32em; }
/* What the location's terrain costs to enter, and each of its borders that has a terrain, a line each. */
.location-id .terrain-cost { color: var(--muted); }
.location-id .border-cost { flex-basis: 100%; white-space: normal; }
.location-id[hidden] { display: none; }

/* What the game's rules warn of at the location under the pointer, under the location and any stack row below it. */
.location-warning {
  position: fixed;
  z-index: 6;
  max-width: 320px;
  padding: 4px 8px;
  border: 1px solid var(--warning);
  border-left-width: 4px;
  border-radius: 4px;
  background: var(--panel);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  font-size: 12px;
  pointer-events: none;
}
.location-warning p { margin: 0; }
.location-warning p + p { margin-top: 2px; }
.location-warning[hidden] { display: none; }

/* A stack's pieces in a row beside it, to select, reorder and drag out; and the pieces dragged from it. */
/* The row of a stack's pieces, and above it, where several stacks share the location, which of them it is and the
   buttons going to the others. */
.stack-row-box {
  position: fixed;
  z-index: 5;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}
.stack-row-switch { display: flex; align-items: center; gap: 4px; padding: 2px 4px 0; font-size: 12px; }
.stack-row-switch .button { width: auto; min-width: 24px; min-height: 24px; padding: 0 4px; }
.stack-row-place { white-space: nowrap; }
.stack-row-box[hidden], .stack-row-switch[hidden], .stack-row[hidden], .piece-ghost[hidden] { display: none; }
.stack-row-pieces { display: block; }
.stack-row.movable { cursor: grab; }
.stack-row.dragging { cursor: grabbing; }
/* Pieces dragged out of the row: the row is hidden, but stays where it was, the drag's source, until the drag ends. */
.stack-row-box.dragged-out { visibility: hidden; pointer-events: none; }
.explained { fill: none; pointer-events: all; }
.stack-row .selected-piece { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
.stack-row .active-piece { fill: none; stroke: var(--text); stroke-width: 2; stroke-dasharray: 4 2; vector-effect: non-scaling-stroke; }
.stack-row:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.stack-row .piece-caption { fill: var(--text); pointer-events: none; }
.stack-row .insert-mark { stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
.piece-ghost {
  position: fixed;
  z-index: 5;
  opacity: 0.75;
  pointer-events: none;
}

/* The selected location's terrain and its borders', for the user to choose. */
.selection {
  position: absolute;
  right: 16px;
  bottom: 44px;
  z-index: 1;
  width: 260px;
  max-height: 60%;
  overflow: auto;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}
.selection[hidden] { display: none; }
.selection-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.selection-title { flex: 1; }
.selection-sub { margin: 8px 0 2px; color: var(--muted); font-size: 12px; }
.selection-piece { font-size: 13px; padding: 1px 0; overflow-wrap: anywhere; }
.selection-row { display: flex; align-items: center; gap: 8px; padding: 1px 0; }
.selection-row > span { flex: none; min-width: 64px; font-size: 13px; }
/* Where a side's victory points come from: each source and its points, then the total. */
.points-row { display: flex; align-items: baseline; gap: 8px; padding: 1px 0; font-size: 13px; }
.points-source { flex: 1; min-width: 0; }
.points-value { flex: none; font-variant-numeric: tabular-nums; }
/* A line whose points need explaining, such as points withheld: its tooltip explains them. */
.points-row.explained .points-source { text-decoration: underline dotted; cursor: help; }
.points-row.points-total { margin-top: 4px; padding-top: 4px; border-top: 1px solid var(--line); font-weight: 600; }
.terrain-text { flex: 1; min-width: 0; font-size: 13px; }
.terrain-select { flex: 1; min-width: 0; font-size: 13px; padding: 2px; }
/* A terrain the user chose, in place of its colors'. */
.terrain-select.chosen { border-color: var(--accent); font-weight: 600; }
.chosen-mark { color: var(--muted); font-style: italic; }
.location-id-input, .points-input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 13px;
  padding: 2px 4px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  color: var(--text);
}
/* An id the user gave, in place of the grid's. */
.location-id-input.chosen { border-color: var(--accent); font-weight: 600; }
/* Victory points the user gave a location: a narrow field for a whole number. */
.points-input { flex: none; width: 5em; }
.points-input.chosen { border-color: var(--accent); font-weight: 600; }
.points-text, .control-text { font-size: 13px; }

/* The colors a location shows: its class larger, outlined. */
.swatch { display: inline-block; flex: none; width: 10px; height: 10px; border: 1px solid var(--line); border-radius: 2px; }
.swatch.class { width: 14px; height: 14px; border-color: var(--text); }

.sidebar h2.section { margin-top: 20px; }
.color-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.color-item { display: flex; align-items: center; gap: 6px; padding: 2px 4px; border-radius: 6px; }
.color-item:hover { background: var(--bg); }
.color-item .swatch { width: 16px; height: 16px; }
.color-name {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 13px;
  padding: 2px 4px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: none;
  color: var(--text);
}
.color-name::placeholder { font-family: ui-monospace, monospace; font-size: 12px; color: var(--muted); }
.color-name:hover { border-color: var(--line); }
.color-name:focus { outline: none; border-color: var(--accent); background: var(--panel); }
.terrain-name { font-weight: 600; }
.file-buttons { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.log-steps { margin: 8px 0; }
.log-steps[hidden], .log-steps .check[hidden] { display: none; }
.moves { margin: 0 0 8px; }
.moves[hidden] { display: none; }
.terrain-controls[hidden] { display: none; }
.move-buttons { display: flex; flex-wrap: wrap; gap: 6px; }
.step-detail { margin: 0; padding-left: 18px; font-size: 13px; overflow-wrap: anywhere; }
.color-count { flex: none; min-width: 28px; color: var(--muted); font-size: 12px; text-align: right; font-variant-numeric: tabular-nums; }
/* A border color's count of what it would mark if it were named. */
.color-count.unnamed { font-style: italic; opacity: 0.7; }
.button.small { width: 24px; padding: 0; }
/* A terrain added by hand: its color picker in place of a swatch. */
.swatch-input { flex: none; width: 18px; height: 18px; padding: 0; border: 1px solid var(--line); border-radius: 2px; background: none; cursor: pointer; }
.swatch-input::-webkit-color-swatch-wrapper { padding: 0; }
.swatch-input::-webkit-color-swatch { border: none; border-radius: 1px; }
.swatch-input::-moz-color-swatch { border: none; border-radius: 1px; }
.add-terrain fieldset { display: flex; gap: 6px; min-width: 0; margin: 4px 0 0; padding: 0 4px; border: none; }
.add-terrain .color-name { border-color: var(--line); }
.button:disabled, .button[aria-disabled="true"] { opacity: 0.35; cursor: default; }

.drop-target {
  display: none;
  position: fixed;
  inset: 12px;
  align-items: center;
  justify-content: center;
  border: 3px dashed var(--accent);
  border-radius: 12px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  font-size: 20px;
  font-weight: 600;
  pointer-events: none;
}
.dragging .drop-target { display: flex; }

/* The map: VASSAL draws grid lines one pixel wide at any zoom. */
.map .lines { fill: none; stroke-width: 1; vector-effect: non-scaling-stroke; shape-rendering: crispEdges; }
.map .outline { fill: none; stroke-width: 1.5; stroke-dasharray: 6 4; vector-effect: non-scaling-stroke; }
.map .label { font-family: Dialog, "DejaVu Sans", Arial, sans-serif; text-anchor: middle; }
.map .label.halo { paint-order: stroke; stroke-width: 3px; stroke-linejoin: round; }
.map .pieces { pointer-events: none; opacity: var(--unit-opacity, 1); }
/* A unit that can't be used in the game's phase: dimmed, on the map and in a stack's row, its marks drawn above it. */
.map .pieces .unusable, .stack-row .unusable { opacity: var(--unusable-opacity); }
/* Units chosen for the combat being declared, and those in combats declared, outlined above the pieces. */
.map .combat { pointer-events: none; }
.map .combat rect { fill: none; stroke-width: 3; vector-effect: non-scaling-stroke; }
.map .combat .combat-attacker { stroke: var(--attacker); }
.map .combat .combat-defender { stroke: var(--defender); }
.map .combat .in-combat { stroke: var(--muted); stroke-dasharray: 4 3; }
/* The units of the new combat selected on the battle board: a halo in the colour that marks it there. */
/* The pieces picked up to move by clicking where they go. */
.map .combat .picked-up { fill: var(--accent); fill-opacity: 0.2; stroke: var(--accent); stroke-width: 4; vector-effect: non-scaling-stroke; }
.map .combat .selected-combat { fill: var(--accent); fill-opacity: 0.25; stroke: var(--accent); stroke-width: 4; }
/* A unit a combat's result waits for a move of, such as a retreat: a thick amber outline, marching, and a badge. */
.map .combat .awaiting-outline { stroke: var(--awaiting); stroke-width: 5; stroke-dasharray: 10 5; animation: awaiting-march 0.8s linear infinite; }
.map .combat .awaiting-badge { fill: var(--awaiting); stroke: #1d1d1b; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.map .combat .awaiting-mark { fill: #1d1d1b; font-weight: 700; font-family: system-ui, sans-serif; text-anchor: middle; dominant-baseline: central; }
@keyframes awaiting-march { to { stroke-dashoffset: -15; } }
@media (prefers-reduced-motion: reduce) { .map .combat .awaiting-outline { animation: none; } }
/* The locations a unit a combat's result waits for can go to, such as where it can retreat, under the pieces. */
.map .destinations { pointer-events: none; }
/* Where the pieces picked up were when they were picked up, as long as they stay picked up. */
.map .picked-up-from { fill: color-mix(in srgb, var(--accent) 20%, transparent); stroke: var(--accent); stroke-width: 3; stroke-dasharray: 6 4; vector-effect: non-scaling-stroke; }
.map .destination { fill: color-mix(in srgb, var(--awaiting) 30%, transparent); stroke: var(--awaiting); stroke-width: 3; vector-effect: non-scaling-stroke; }
/* A tombstone over a unit that can't retreat anywhere: clicked, it sends the unit to its graveyard. */
.map .combat .tombstone { pointer-events: auto; }
.map .combat .tombstone-back { fill: rgb(29 29 27 / 0.75); stroke: var(--awaiting); stroke-width: 2; vector-effect: non-scaling-stroke; }
.map .combat .tombstone-stone { fill: #b9b6ad; stroke: #f4f2ec; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.map .combat .tombstone-cross, .map .combat .tombstone-ground { fill: none; stroke: #1d1d1b; stroke-width: 2; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.map .combat .tombstone-ground { stroke: #f4f2ec; }
.pieces-hidden .map .pieces { display: none; }
.map .piece-label.halo { paint-order: stroke; stroke-width: 3px; stroke-linejoin: round; }
.map .missing { fill: #c8c5bd; }
.map .missing-label { font: 24px system-ui, sans-serif; text-anchor: middle; fill: #4a4944; }
.map .cell { fill: color-mix(in srgb, var(--cell) 15%, transparent); stroke: var(--cell); stroke-width: 2; vector-effect: non-scaling-stroke; pointer-events: none; }
/* The locations of the color under the pointer in the color list. */
.map .matching { fill: color-mix(in srgb, var(--cell) 30%, transparent); stroke: var(--cell); stroke-width: 1.5; vector-effect: non-scaling-stroke; pointer-events: none; }
/* The locations adjacent to the one under the pointer. */
.map .adjacent { fill: color-mix(in srgb, var(--adjacent) 25%, transparent); stroke: var(--adjacent); stroke-width: 1.5; vector-effect: non-scaling-stroke; pointer-events: none; }
/* The borders with a terrain around the location under the pointer, and those of the color under the pointer in the
   border color list. */
.map .border { stroke: var(--adjacent); stroke-width: 5; stroke-linecap: round; vector-effect: non-scaling-stroke; pointer-events: none; }
/* The map's cursor, moved by the keyboard: its location outlined, or its point off every location. */
.map .key-cursor { fill: color-mix(in srgb, var(--accent) 20%, transparent); stroke: var(--accent); stroke-width: 4; vector-effect: non-scaling-stroke; pointer-events: none; }
.map .selected { fill: none; stroke: var(--accent); stroke-width: 3; vector-effect: non-scaling-stroke; pointer-events: none; }
.map .matching-border { stroke: var(--cell); stroke-width: 4; stroke-linecap: round; vector-effect: non-scaling-stroke; pointer-events: none; }
/* A unit at a problem's location when a phase end is refused, the only unit marked then. */
.map .combat .problem-unit { stroke: var(--error); stroke-width: 5; }
/* The locations of the problems the game's rules found, under the pieces. */
.map .problems { pointer-events: none; }
.map .problem { fill: color-mix(in srgb, var(--error) 35%, transparent); stroke: var(--error); stroke-width: 2.5; vector-effect: non-scaling-stroke; }
/* The locations of the game's warnings, such as a stack over its limit, outlined under the pieces. */
.map .warnings { pointer-events: none; }
.map .warning { fill: none; stroke: var(--warning); stroke-width: 4; vector-effect: non-scaling-stroke; }
/* The paths pieces went by, as the game's rules found them, the latest standing out. */
.map .paths { pointer-events: none; }
.map .path { --path: var(--adjacent); opacity: 0.6; }
.map .path.latest { --path: var(--cell); opacity: 1; }
.map .path-line { fill: none; stroke: var(--path); stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.map .path-dot, .map .path-arrow { fill: var(--path); stroke: white; stroke-width: 1; vector-effect: non-scaling-stroke; }

@media (max-width: 700px) {
  .workspace { flex-direction: column; }
  .sidebar { width: auto; max-height: 40vh; border-right: 0; border-bottom: 1px solid var(--line); }
  #sidebar-resizer { display: none; }
  /* The top bar's parts wrap onto lines of their own rather than run off the screen. */
  .topbar { gap: 6px 12px; padding: 6px 12px; }
  .module-name { white-space: normal; }
  .phase-bar { flex: 0 1 auto; flex-wrap: wrap; min-width: 0; }
  .phase-bar .button { white-space: normal; text-align: left; }
  .step-bar { flex-wrap: wrap; }
  .step-bar input[type="range"] { width: auto; flex: 1 1 120px; }
}


/* The battle board: the phase's combats as matchups, in a window over the map that its title bar moves. */
.battle-board {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 4;
  width: min(360px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  font-size: 13px;
}
.battle-board[hidden] { display: none; }
/* Once moved, the board is placed in the page's window, so it can go over the sidebar and the top bar too. */
.battle-board.floating { position: fixed; max-height: calc(100vh - 24px); }
/* While its own window opens, the board is not shown over the map. */
.battle-board.opening { visibility: hidden; }
/* The board in a window of its own, filling it. */
body.battle-board-window { margin: 0; height: 100vh; overflow: hidden; background: var(--panel); }
.battle-board-window .battle-board, .battle-board-window .battle-board.floating { position: static; width: 100%; height: 100%; max-height: none; border: 0; border-radius: 0; box-shadow: none; }
.battle-board-window .battle-board-title { cursor: default; }
.battle-board-window .battle-board-body { flex: 1; }
/* A unit double-clicked or hovered over, enlarged beside it, in the board's own window. */
.battle-zoom { position: fixed; z-index: 6; padding: 4px; border: 1px solid var(--line); border-radius: 4px; background: var(--panel); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3); pointer-events: none; }
.battle-zoom[hidden] { display: none; }
.battle-zoom svg { display: block; }
.battle-board-title { display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 12px; border-bottom: 1px solid var(--line); cursor: move; user-select: none; }
.battle-board-title h2 { flex: 1; margin: 0; font-size: 14px; }
.battle-board-body { overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 8px; }
.battle-board-body > .note { margin: 0; }
.battle { border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; }
.battle.drop-over { border-color: var(--accent); background: var(--selected); }
/* Set back on the page's background, not faded: a fade takes the muted text under 4.5:1. Its stage says it is done. */
.battle.completed { background: var(--bg); }
.battle.resolving { border-color: var(--accent); }
.battle.has-awaiting { border-color: var(--awaiting); border-width: 2px; }
.declared-battle { cursor: pointer; }
/* The combat declared selected, its units highlighted on the map: ringed in the colour of their halo there. */
.declared-battle.selected { box-shadow: 0 0 0 2px var(--accent); }
/* A combat declared being amended while combats are resolved: open to units dropped and clicked, as a new one. */
.declared-battle.amending { border-style: dashed; border-color: var(--accent); background: var(--selected); }
.battle-awaiting { display: flex; align-items: center; gap: 6px; margin: 4px 0 0; font-weight: 600; overflow-wrap: anywhere; }
.battle-awaiting-text { flex: 1; min-width: 0; }
/* An action another player makes, online. */
.battle-awaiting.others .battle-awaiting-text { color: var(--muted); }
.battle-decline { flex: none; font-weight: normal; }
.battle-awaiting-mark { flex: none; display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; background: var(--awaiting); color: #1d1d1b; font-weight: 700; font-size: 12px; }
.battle-unit.awaiting { outline: 3px dashed var(--awaiting); outline-offset: 2px; border-radius: 3px; }
/* A cemetery: units dropped on it, such as those an exchange loses, go to their graveyard. */
.battle-cemetery { flex: none; display: inline-grid; place-items: center; width: 34px; height: 34px; padding: 0; border: 2px dashed var(--awaiting); border-radius: 6px; background: rgb(29 29 27 / 0.75); cursor: pointer; }
.battle-cemetery.drop-over { border-style: solid; border-color: var(--accent); background: var(--accent); }
.battle-cemetery svg { display: block; }
.battle-cemetery .cemetery-stone { fill: #b9b6ad; stroke: #f4f2ec; stroke-width: 1.5; }
.battle-cemetery .cemetery-cross, .battle-cemetery .cemetery-ground { fill: none; stroke: #1d1d1b; stroke-width: 2; stroke-linecap: round; }
.battle-cemetery .cemetery-ground { stroke: #f4f2ec; }
.battle-unit.clickable { cursor: pointer; }
/* A unit picked up from the board, to move by clicking where it goes on the map: filled as it is on the map. */
.battle-unit.held { background: color-mix(in srgb, var(--accent) 25%, transparent); outline: 3px solid var(--accent); }
.new-battle { border-style: dashed; cursor: pointer; }
.new-battle.current { border-color: var(--accent); border-style: solid; }
.new-battle.refused { border-color: var(--error); }
.battle-problem { margin: 4px 0 0; color: var(--error); overflow-wrap: anywhere; }
.empty-battle .battle-name { color: var(--muted); font-weight: normal; }
/* The button starting a new combat, at the end of the new combats. */
.new-combat { flex: none; }
.battle-heading { display: flex; align-items: center; gap: 8px; min-height: 28px; }
.battle-name { font-weight: 600; white-space: nowrap; }
.battle-odds { font-variant-numeric: tabular-nums; white-space: nowrap; }
.battle-stage { flex: 1; min-width: 0; color: var(--muted); overflow-wrap: anywhere; }
.new-battle .battle-name { flex: 1; }
.new-battle .battle-heading .button.icon { flex: none; }
.battle-resolve svg { display: block; }
.battle-resolve .die-face { fill: var(--panel); stroke: currentColor; stroke-width: 1.3; }
.battle-resolve .die-pip { fill: currentColor; }
.battle-resolve .die-number { fill: currentColor; font-size: 8px; font-weight: 600; }
/* The die just clicked, spinning until the server's roll comes. */
.battle-resolve.rolling:disabled { opacity: 1; }
.battle-resolve.rolling svg { animation: die-spin 0.9s linear infinite; }
@keyframes die-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .battle-resolve.rolling svg { animation: none; } }
.matchup { display: grid; grid-template-columns: 1fr auto 1fr; gap: 6px; align-items: center; margin-top: 4px; }
.versus { color: var(--muted); font-size: 12px; }
.battle-side { display: flex; flex-wrap: wrap; gap: 4px; min-height: 44px; align-items: center; padding: 2px 4px; border-left: 3px solid; border-radius: 3px; }
.battle-side.attackers { border-color: var(--attacker); }
.battle-side.defenders { border-color: var(--defender); }
.battle-none, .battle-hint { color: var(--muted); }
.battle-hint { margin: 4px 0 0; }
.battle-unit { display: inline-flex; align-items: center; padding: 0; border: 0; background: none; color: inherit; font: inherit; user-select: none; }
.battle-unit svg { display: block; }
button.battle-unit { cursor: pointer; border-radius: 3px; }
button.battle-unit:hover, button.battle-unit:focus-visible { outline: 2px solid var(--accent); }
/* A defender whose defence factor its terrain, or the border it's attacked across, changes: badged with the multiplier. */
.battle-unit.terrain-affected { position: relative; }
.battle-terrain { position: absolute; top: -6px; right: -6px; min-width: 16px; padding: 0 3px; border-radius: 8px; background: var(--defender); color: #fff; font-size: 11px; font-weight: 700; line-height: 16px; text-align: center; box-shadow: 0 0 0 1.5px var(--panel, #fff); pointer-events: none; }

/* Playing online: the lobby and an online game's panel in the sidebar, New game, signing in and the player's games. */
.online { margin-top: 12px; }
.online input[type="text"], .online input[type="email"], .online input[type="password"], .online select {
  width: 100%; box-sizing: border-box; margin-bottom: 6px; font: inherit; padding: 4px 6px;
}
.game-options input[type="text"] { font: inherit; padding: 4px 6px; }
.new-game { margin-top: 12px; }
.new-game > summary { display: inline-block; }
.game-link { display: inline-block; color: inherit; text-decoration: none; }
.game-link[hidden] { display: none; }
/* The online game's buttons, laid out among the sidebar's others before Save game. */
.online-buttons { display: contents; }
.sign-in { display: flex; flex-direction: column; }
.sign-in .button { align-self: flex-start; }
.online-games { list-style: none; padding: 0; margin: 0; }
.online-games li { margin: 2px 0; }
.button.link { background: none; border: none; padding: 2px 0; color: var(--accent); cursor: pointer; font: inherit; text-align: left; }
.button.link:hover { text-decoration: underline; }
.online-game { margin-bottom: 8px; }
.online-state { font-weight: 600; margin: 4px 0; }
.online-title { font-weight: 600; margin: 4px 0; }
.online-clock { font-variant-numeric: tabular-nums; margin: 4px 0; }
.online-back { display: block; margin: 4px 0; }
.online-back[hidden] { display: none; }
.online-live { font-weight: 400; font-size: 0.85em; opacity: 0.7; margin-left: 6px; }

/* A touch screen: whatever is tapped at least 44 pixels high (and an icon button as wide), and text fields at 16
   pixels, which phones don't zoom into when they are focused. */
@media (pointer: coarse) {
  .button, .menu > summary.button, .menu-item, .module-document-list a { min-height: 44px; }
  .button, .button.icon, .button.small { min-width: 44px; }
  .menu-item, .module-document-list a { display: flex; align-items: center; }
  .check { min-height: 44px; margin-top: 0; }
  .check input[type="checkbox"] { width: 22px; height: 22px; margin: 0; }
  .swatch-input { width: 32px; height: 32px; }
  input[type="text"], input[type="email"], input[type="password"], input[type="number"], select, textarea,
  .color-name, .terrain-select, .location-id-input, .points-input, .online input, .online select,
  .game-options input[type="text"] { font-size: 16px; }
  select, .online input, .game-options input[type="text"] { min-height: 44px; }
  /* A slider (Unit opacity, the log's stepper) taken by a finger anywhere in a 44 pixel band, its track as it was. */
  input[type="range"] { min-height: 44px; }
  /* A battle board unit to pick or remove: its box grown round its picture, which stays as it is. */
  button.battle-unit { min-width: 44px; min-height: 44px; justify-content: center; }
  .stack-row-switch .button { min-width: 44px; min-height: 44px; }
}
