@font-face {
  font-family: 'Pirata One';
  src: url('../../assets/fonts/pirata-one-latin-400-normal.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Barlow Condensed';
  src: url('../../assets/fonts/barlow-condensed-latin-500-normal.woff2') format('woff2');
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: 'Barlow Condensed';
  src: url('../../assets/fonts/barlow-condensed-latin-700-normal.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}
@font-face {
  font-family: 'Bangers';
  src: url('../../assets/fonts/bangers-latin-400-normal.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}

/* Palette from reference/stiltest.html. The game is always dark. */
:root {
  --bg: #110c0a;
  --panel: rgba(24, 18, 14, 0.86);
  --text: #eadfc4;
  --muted: #b5a385;
  --btn: #e8c872;
  --btn-alt: #cbbd9f;
  --accent: #c9462a;
  /* The gold the renderer marks things with (C.gold in render/palette.js), so a
     button and the rings it points at are the same colour. */
  --gold: #f2c14e;
  --ink: #000;
  --font-body: 'Barlow Condensed', 'Arial Narrow', Arial, sans-serif;
  --font-title: 'Pirata One', Georgia, 'Times New Roman', serif;
  --font-comic: Bangers, Impact, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  color-scheme: dark;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-weight: 500;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* HUD layer: transparent to input except for its interactive children. */
#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  padding: calc(12px + var(--safe-top)) calc(16px + var(--safe-right))
    calc(12px + var(--safe-bottom)) calc(16px + var(--safe-left));
}

#hud .interactive {
  pointer-events: auto;
}

/* ---------- Status bar (docs/ART.md, "Obere Statusleiste") ----------
   One dark bar across the top carrying riveted plates: the match on the left,
   the purse and the route on the right, housekeeping at the end. */

.hud-top {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 10px;
  padding: calc(6px + var(--safe-top)) calc(10px + var(--safe-right)) 6px calc(10px + var(--safe-left));
  background: linear-gradient(#241c17, #1a1410);
  border-bottom: 2px solid var(--ink);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.5);
}

.plate-row {
  display: flex;
  align-items: stretch;
  gap: 6px;
  min-width: 0;
}

/* A plate with a rivet in each corner, as on the sheet. */
.plate {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border: 2px solid var(--ink);
  border-radius: 3px;
  background: #4a4137;
  box-shadow: inset 0 1px 0 rgba(234, 223, 196, 0.12);
  color: var(--text);
  font-size: 19px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.plate::before,
.plate::after {
  content: '';
  position: absolute;
  left: 3px;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: rgba(26, 20, 16, 0.65);
  box-shadow: calc(100% + 2px) 0 0 rgba(26, 20, 16, 0.65);
}

.plate::before {
  top: 3px;
}

.plate::after {
  bottom: 3px;
}

.plate-icon {
  width: 22px;
  height: 22px;
  flex: none;
}

.plate-title {
  background: none;
  border: 0;
  box-shadow: none;
  padding-left: 4px;
}

.plate-title::before,
.plate-title::after {
  display: none;
}

.hud-title {
  font-family: var(--font-title);
  font-weight: 400;
  font-size: clamp(20px, 2.4vw, 30px);
  line-height: 1;
  margin: 0;
  text-shadow: 2px 2px 0 var(--ink);
}

.plate-wave .plate-value {
  color: var(--btn);
}

.plate-requisition .plate-value {
  color: var(--btn);
}

.plate-points .plate-value {
  color: #5fd4ff;
}

.plate-route .plate-value {
  color: var(--btn-alt);
}

/* The bastion warns before it shouts. */
.plate-lives[data-level='low'] .plate-value {
  color: #ffb13b;
}

.plate-lives[data-level='critical'] .plate-value {
  color: #ff6a4a;
}

/* The Koloss run: a warning first, then red once it is on the field. */
.plate-koloss {
  color: #ffc46a;
  border-color: #6b3a18;
}

.plate-koloss[data-stage='predicted'] {
  color: #ff9a4a;
}

.plate-koloss[data-stage='arrived'] {
  color: #1a1410;
  background: var(--accent);
}

.plate-koloss[hidden] {
  display: none;
}

/* King of the Hill: the attacking rift and the next one (M7b). */
.plate-rift .plate-value {
  white-space: nowrap;
}

.plate-rift[hidden] {
  display: none;
}

/* Codex and menu: plates that can be pressed, and therefore thumb-sized. The
   bar takes its height from them, which is why the other plates stretch. */
button.plate-button {
  min-width: 44px;
  min-height: 44px;
  justify-content: center;
  padding: 4px 10px;
  cursor: pointer;
}

button.plate-button .plate-icon {
  width: 26px;
  height: 26px;
}

button.plate-button:active {
  transform: translate(1px, 1px);
  box-shadow: none;
}

/* On a narrow screen the title gives way before any value does. */
@media (max-width: 860px) {
  .plate-title {
    display: none;
  }
}

.hud-bottom {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(12px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: min(920px, calc(100% - 24px - var(--safe-left) - var(--safe-right)));
}

/* The rating line after a wave (M6, Teil 1). It sits above the bottom bar, in
   thumb reach on a tablet, and stays quieter than the bar: a thin plate, no
   drop shadow, so it reads as a question and not as another control of the
   round. Nothing waits for an answer, so nothing here shouts for one. */
.hud-rating {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  background: rgba(36, 28, 23, 0.9);
  border: 2px solid var(--ink);
  border-radius: 4px;
  padding: 6px 12px;
  max-width: 100%;
}

/* An author rule beats the browser's own display:none for [hidden], so every
   element the code hides needs this line (the same as the panels above). */
.hud-rating[hidden] {
  display: none;
}

.hud-rating-label {
  font-size: 15px;
  font-weight: 700;
  color: var(--btn);
  margin-right: 4px;
}

/* Smaller than a button of the round, but never below the 44 pixels every
   target has to have (GDD section 13). */
button.hud-rating-answer {
  font-size: 15px;
  padding: 6px 12px;
  box-shadow: 2px 2px 0 var(--ink);
}

@media (max-width: 720px) {
  .hud-rating-label {
    width: 100%;
    margin-right: 0;
    text-align: center;
  }
}

.hud-bar {
  display: flex;
  gap: 14px;
  align-items: center;
  background: var(--panel);
  border: 2px solid var(--ink);
  box-shadow: 4px 4px 0 var(--ink);
  padding: 8px 14px;
  border-radius: 4px;
  max-width: 100%;
  flex-wrap: wrap;
  justify-content: center;
}

/* The discs on the left: supply, demolish, bulwark. */
.rune-group {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.rune-group[hidden] {
  display: none;
}

.speed-group {
  display: flex;
  gap: 4px;
}

/* Plain squares, as on the sheet; the active one is gold, not red. Red is the
   colour of a running mode, and the speed is not a mode. */
button.speed {
  min-width: 44px;
  padding: 6px 8px;
}

button.speed.on {
  background: var(--btn);
  color: #1a1410;
}

/* The one round button with a word on it: the action of the round. */
.salvo {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  width: 84px;
  height: 84px;
  padding: 0;
  border-radius: 50%;
  border: 3px solid #6a4a8a;
  box-shadow: 3px 3px 0 var(--ink);
  background: var(--btn);
}

.salvo:active {
  transform: translate(2px, 2px);
  box-shadow: none;
}

.salvo-icon {
  width: 34px;
  height: 34px;
  margin-bottom: -2px;
}

.salvo-label {
  font-family: var(--font-title);
  font-weight: 400;
  font-size: 21px;
  line-height: 1;
}

/* How many landing zones are marked, on the button they are marked for. */
.salvo-zones {
  position: absolute;
  right: -2px;
  top: 2px;
  min-width: 26px;
  padding: 0 4px;
  border: 2px solid var(--ink);
  border-radius: 11px;
  background: rgba(24, 18, 14, 0.94);
  color: var(--btn);
  font-size: 13px;
  font-weight: 700;
  line-height: 18px;
  font-variant-numeric: tabular-nums;
}

.salvo-zones[hidden] {
  display: none;
}

button {
  font-family: inherit;
  font-weight: 700;
  font-size: 17px;
  color: #1a1410;
  background: var(--btn);
  border: 2px solid var(--ink);
  border-radius: 3px;
  padding: 6px 14px;
  min-width: 44px;
  min-height: 44px;
  cursor: pointer;
  box-shadow: 2px 2px 0 var(--ink);
  touch-action: manipulation;
}

button:active {
  transform: translate(2px, 2px);
  box-shadow: none;
}

button:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}

button.alt {
  background: var(--btn-alt);
}

button.on {
  background: var(--accent);
  color: #fff;
}

button.primary {
  font-size: 19px;
  padding: 6px 20px;
}

/* The rank chances of the next supply level, in the disc's bubble. */
.supply-chances {
  margin-top: 4px;
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 22px;
}

.supply-bar {
  width: 12px;
  height: 100%;
  /* Light track on the dark bubble, so a part-filled bar reads at a glance. */
  background: rgba(234, 223, 196, 0.18);
  border: 1px solid var(--ink);
  display: flex;
  align-items: flex-end;
}

.supply-bar-fill {
  display: block;
  width: 100%;
  /* Height is the rank's percentage; a rank at 0 shows an empty slot. */
  min-height: 0;
}

button:disabled {
  opacity: 0.45;
  cursor: default;
  transform: none;
  box-shadow: 2px 2px 0 var(--ink);
}

button[hidden] {
  display: none;
}

.hud-banner {
  position: absolute;
  left: 50%;
  top: 22%;
  transform: translate(-50%, -8px) rotate(-2deg);
  font-family: var(--font-comic);
  font-size: clamp(28px, 4.5vw, 52px);
  letter-spacing: 1px;
  color: var(--btn);
  -webkit-text-stroke: 2px var(--ink);
  text-shadow: 4px 4px 0 var(--ink);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
}

.hud-banner.show {
  opacity: 1;
  transform: translate(-50%, 0) rotate(-2deg);
}

/* The Koloss warning: a red plate under the words with a yellow hazard stripe
   across the top, so it reads as a threat and not as any other announcement
   (docs/ART.md, "Zielankündigung"). */
.hud-banner.danger {
  color: #fff3d6;
  -webkit-text-stroke: 2px var(--ink);
  background: rgba(120, 16, 10, 0.92);
  border: 3px solid var(--ink);
  border-radius: 4px;
  padding: 14px 26px 10px;
  box-shadow: 4px 4px 0 var(--ink);
  text-shadow: 2px 2px 0 var(--ink);
  background-image:
    repeating-linear-gradient(
      -45deg,
      #e8b93a 0,
      #e8b93a 8px,
      var(--ink) 8px,
      var(--ink) 16px
    ),
    linear-gradient(rgba(120, 16, 10, 0.92), rgba(120, 16, 10, 0.92));
  background-size: 100% 8px, 100% 100%;
  background-position: top left, 0 0;
  background-repeat: no-repeat, no-repeat;
}

@media (prefers-reduced-motion: reduce) {
  .hud-banner {
    transition: none;
  }
}

/* Version in the bottom left corner. Quiet enough to ignore, legible enough to
   read off for a bug report. Never takes input; the bottom column is centred and
   at most 920px wide, so the two do not meet. */
.hud-version {
  position: absolute;
  left: calc(10px + var(--safe-left));
  bottom: calc(6px + var(--safe-bottom));
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  opacity: 0.55;
  text-shadow: 1px 1px 0 var(--ink);
}

.hud-debug {
  position: absolute;
  right: calc(16px + var(--safe-right));
  /* Below the status bar: the bottom column grows when the selection panel opens. */
  top: calc(58px + var(--safe-top));
  font-size: 14px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  background: var(--panel);
  border: 2px solid var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
  padding: 4px 8px;
  border-radius: 3px;
}

.loading {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: var(--bg);
  font-family: var(--font-title);
  font-size: clamp(24px, 3vw, 34px);
  text-shadow: 3px 3px 0 var(--ink);
  transition: opacity 0.3s;
  z-index: 10;
}

.loading p {
  margin: 0;
}

.loading-bar {
  width: min(320px, 70vw);
  height: 14px;
  border: 2px solid var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
  background: var(--panel);
}

.loading-bar > div {
  height: 100%;
  width: 0;
  background: var(--btn);
}

.loading.done {
  opacity: 0;
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  .loading {
    transition: none;
  }
}

/* Selection panel: five pod cards and the actions for the picked one. */
.selection {
  /* Narrow on purpose: the panel sits over the map and must hide as little of it
     as possible. Pods behind it are still reachable through the cards. */
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(112px + var(--safe-bottom));
  z-index: 4;
  width: min(620px, calc(100% - 24px));
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  background: var(--panel);
  border: 2px solid var(--ink);
  box-shadow: 4px 4px 0 var(--ink);
  border-radius: 4px;
  padding: 8px;
}

.selection[hidden] {
  display: none;
}

.selection-cards,
.selection-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}

.selection-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 0;
  min-width: 0;
  min-height: 46px;
  padding: 4px 30px 4px 9px;
  background: var(--btn-alt);
  border-left: 7px solid var(--doctrine);
  text-align: left;
  line-height: 1.1;
}

.selection-head {
  display: flex;
  align-items: baseline;
  gap: 5px;
  white-space: nowrap;
}

.selection-card.on {
  background: var(--btn);
  outline: 3px solid var(--doctrine);
  outline-offset: 1px;
}

.selection-num {
  font-family: var(--font-comic);
  font-size: 16px;
  color: #4a3f2e;
}

.selection-name {
  font-size: 17px;
}

.selection-rank {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 14px;
  font-weight: 500;
  color: #4a3f2e;
}

/* Rank marks (docs/ART.md): up to four short strokes in the doctrine's colour,
   gold at legend. No frame and no empty slots. */
.selection-rank-marks {
  display: inline-flex;
  align-items: center;
  /* A row of strokes side by side, not a stack of bars (docs/ART.md). */
  gap: 3px;
  margin-left: 3px;
}

.selection-rank-marks i {
  display: block;
  width: 11px;
  height: 3px;
  background: var(--mark);
  border-radius: 1px;
  box-shadow: 1px 1px 0 var(--ink);
}

/* A capsule that came down on rubble names the demolition it would pay for. */
.selection-cost {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: #6b5a3e;
  margin-top: 2px;
}

.selection-card.unaffordable .selection-cost {
  color: var(--accent);
}

.selection-card.unaffordable {
  opacity: 0.75;
}

.selection-warning {
  margin: 6px 0 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  text-align: center;
}

.selection-badge {
  position: absolute;
  top: 50%;
  right: 5px;
  transform: translateY(-50%);
  font-size: 12px;
  font-weight: 700;
  color: #1a1410;
  background: var(--doctrine);
  border: 2px solid var(--ink);
  border-radius: 3px;
  padding: 0 4px;
}

.selection-actions button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  line-height: 1.1;
}

.selection-note {
  font-size: 13px;
  font-weight: 500;
  opacity: 0.8;
}

/* A recipe waiting for its second tap: marked, because the tap after it builds.
   Gold like the rings around the emplacements it would eat. */
.selection-actions button.armed {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

/* Giving the salvo up: the way out when not one capsule can be paid for. Drawn
   as a plain button, not a primary one — it is a last resort, not an offer. */
.selection-forfeit {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  line-height: 1.1;
  background: var(--btn-alt);
}

.selection-hint {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

@media (max-height: 560px) {
  .selection-hint {
    display: none;
  }
}

/* Wide screens (the tablet in landscape, every desktop): the panel moves to the
   side, so the front of the map stays free and every pod can be tapped. */
@media (min-width: 1000px) and (orientation: landscape) {
  .selection {
    left: auto;
    bottom: auto;
    right: calc(16px + var(--safe-right));
    top: 50%;
    transform: translateY(-50%);
    width: 268px;
    max-height: calc(100% - 180px);
    overflow-y: auto;
    align-items: stretch;
  }

  .selection-cards,
  .selection-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .selection-card {
    width: 100%;
    box-sizing: border-box;
  }
}

/* Recipe codex: modal list of the special towers. */
.codex {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(16px + var(--safe-top)) calc(16px + var(--safe-right)) calc(16px + var(--safe-bottom))
    calc(16px + var(--safe-left));
  background: rgba(10, 6, 4, 0.72);
  z-index: 5;
}

.codex[hidden] {
  display: none;
}

.codex-panel {
  width: min(860px, 100%);
  max-height: 100%;
  overflow-y: auto;
  box-sizing: border-box;
  background: var(--panel);
  border: 2px solid var(--ink);
  box-shadow: 6px 6px 0 var(--ink);
  border-radius: 4px;
  padding: 14px 16px 18px;
}

.codex-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.codex-title {
  font-family: var(--font-title);
  font-weight: 400;
  font-size: 30px;
  margin: 0;
  text-shadow: 2px 2px 0 var(--ink);
}

.codex-intro {
  margin: 6px 0 12px;
  font-size: 15px;
  color: var(--muted);
}

.codex-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
}

.codex-card {
  background: rgba(60, 46, 34, 0.5);
  border: 2px solid var(--ink);
  border-radius: 3px;
  padding: 8px 10px;
}

.codex-name {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 19px;
  font-weight: 700;
  color: var(--btn);
}

.codex-rank {
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
}

.codex-ingredients {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin: 6px 0;
}

.codex-chip {
  font-size: 14px;
  font-weight: 700;
  color: #1a1410;
  background: var(--doctrine);
  border: 2px solid var(--ink);
  border-radius: 3px;
  padding: 1px 7px;
}

.codex-effect {
  margin: 0;
  font-size: 15px;
}

/* Command bar: four wide buttons above the bottom bar (GDD section 11). */
/* The command rail (docs/ART.md, "Rechte Kommandoleiste"): discs down the right
   edge, in unlock order. It scrolls once there are more than fit on a tablet in
   landscape, so a later command can never fall off the screen. */
.command-rail {
  position: absolute;
  right: calc(12px + var(--safe-right));
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-height: calc(100% - 210px - var(--safe-top) - var(--safe-bottom));
  padding: 4px 2px;
  overflow-y: auto;
  overflow-x: visible;
  pointer-events: none;
  scrollbar-width: thin;
}

.command-rail > * {
  pointer-events: auto;
  flex: 0 0 auto;
}

.command-rail[hidden] {
  display: none;
}


/* Info panel: top left under the match stats, never over the bottom controls. */
.info {
  position: absolute;
  left: calc(16px + var(--safe-left));
  top: calc(96px + var(--safe-top));
  width: 240px;
  box-sizing: border-box;
  background: var(--panel);
  border: 2px solid var(--ink);
  box-shadow: 4px 4px 0 var(--ink);
  border-radius: 4px;
  padding: 8px 10px;
}

.info[hidden] {
  display: none;
}

.info-head {
  display: flex;
  flex-direction: column;
  margin-bottom: 6px;
}

.info-title {
  font-size: 18px;
  font-weight: 700;
}

.info-subtitle {
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.info-list {
  display: grid;
  grid-template-columns: auto auto;
  gap: 2px 10px;
  margin: 0 0 8px;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.info-list dt {
  color: var(--muted);
}

.info-list dd {
  margin: 0;
  text-align: right;
  font-weight: 700;
}

.info-close {
  width: 100%;
  min-height: 44px;
  padding: 4px 10px;
  font-size: 15px;
}

/* Debug panel (?debug only): controls and wave statistics, right below the fps line. */
.debug-panel {
  position: absolute;
  right: calc(16px + var(--safe-right));
  top: calc(92px + var(--safe-top));
  width: 300px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 5px;
  background: var(--panel);
  border: 2px solid var(--ink);
  box-shadow: 4px 4px 0 var(--ink);
  border-radius: 4px;
  padding: 7px 8px;
  font-size: 14px;
}

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

.debug-row button {
  min-height: 32px;
  min-width: 32px;
  padding: 3px 8px;
  font-size: 14px;
}

.debug-label {
  color: var(--muted);
  min-width: 52px;
}

.debug-input {
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  min-height: 32px;
  padding: 2px 6px;
  border: 2px solid var(--ink);
  border-radius: 3px;
  background: var(--btn);
  color: var(--ink);
  width: 84px;
}

.debug-stats {
  border-top: 2px solid var(--ink);
  padding-top: 4px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.debug-stats-line {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Second line under a banner: the score after the last wave. */
.hud-banner-detail {
  font-family: var(--font-body);
  font-size: 19px;
  letter-spacing: 0;
  color: var(--text);
  -webkit-text-stroke: 0;
  text-shadow: 2px 2px 0 var(--ink);
  margin-top: 6px;
}

.hud-banner-detail:empty {
  display: none;
}

/* ---------- Menus: main, pause, settings, end screen ---------- */
.menu {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(16px + var(--safe-top)) calc(16px + var(--safe-right)) calc(16px + var(--safe-bottom))
    calc(16px + var(--safe-left));
  background: rgba(10, 6, 4, 0.78);
  z-index: 6;
}

.menu[hidden] {
  display: none;
}

.menu-panel {
  width: min(560px, 100%);
  max-height: 100%;
  overflow-y: auto;
  box-sizing: border-box;
  background: var(--panel);
  border: 2px solid var(--ink);
  box-shadow: 8px 8px 0 var(--ink);
  border-radius: 4px;
  padding: 20px 22px 24px;
  text-align: center;
}

.menu[data-menu='main'] .menu-panel {
  /* The title screen carries the game's name, so it gets more room. */
  width: min(680px, 100%);
  padding-top: 26px;
}

.menu-title {
  font-family: var(--font-title);
  font-weight: 400;
  font-size: clamp(34px, 6vw, 56px);
  line-height: 1;
  margin: 0 0 6px;
  text-shadow: 4px 4px 0 var(--ink);
}

.menu[data-menu='end'][data-result='victory'] .menu-title {
  color: var(--btn);
}

.menu[data-menu='end'][data-result='defeat'] .menu-title {
  color: #ff7a5a;
}

.menu-subtitle {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 17px;
}

.menu-section {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 18px 0 8px;
  text-align: left;
}

.menu-seed {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  margin-top: 4px;
}

.menu-seed-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  color: var(--muted);
}

.menu-seed-input {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.14em;
  width: 8em;
  min-height: 44px;
  box-sizing: border-box;
  padding: 4px 10px;
  color: #1a1410;
  background: var(--btn-alt);
  border: 2px solid var(--ink);
  border-radius: 3px;
  text-transform: uppercase;
}

.menu-test-input {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 16px;
  /* Both controls sit in a .menu-seed row, so they follow its width, and a long
     protocol line must shorten rather than push the panel wider. */
  flex: 1 1 auto;
  min-width: 0;
  max-width: 22em;
  min-height: 44px;
  box-sizing: border-box;
  padding: 4px 10px;
  color: #1a1410;
  background: var(--btn-alt);
  border: 2px solid var(--ink);
  border-radius: 3px;
}

.menu-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 18px;
}

/* Text-button fitting (docs/ART.md, "Menüs außerhalb der Partie"): a dark plate
   with a thin gold edge and a rune tick in each corner instead of a full ring,
   because here the word is the point. */
.menu-actions button,
.menu-choice button,
.menu-seed button {
  position: relative;
  min-height: 44px;
  min-width: 44px;
  background: #3c342c;
  color: var(--text);
  border: 2px solid var(--ink);
  border-radius: 4px;
  box-shadow: 0 0 0 1px rgba(232, 200, 114, 0.55) inset, 3px 3px 0 var(--ink);
  padding: 10px 20px;
}

.menu-actions button::before,
.menu-actions button::after {
  content: '';
  position: absolute;
  left: 5px;
  right: 5px;
  height: 5px;
  /* Two short rune ticks per corner, drawn with a repeating edge. */
  background:
    linear-gradient(rgba(138, 91, 192, 0.85), rgba(138, 91, 192, 0.85)) left top / 7px 1.5px no-repeat,
    linear-gradient(rgba(138, 91, 192, 0.85), rgba(138, 91, 192, 0.85)) right top / 7px 1.5px no-repeat;
  pointer-events: none;
}

.menu-actions button::before {
  top: 4px;
}

.menu-actions button::after {
  bottom: 4px;
  transform: scaleY(-1);
}

/* The one button each screen is really about, and the choice that is in force. */
.menu-actions button.menu-primary,
.menu-choice button.on,
.menu-choice button.primary {
  background: var(--btn);
  color: #1a1410;
  font-size: 19px;
}

.menu-actions button:disabled {
  opacity: 0.45;
}

.menu-primary {
  font-size: 19px;
  padding: 10px 22px;
}

/* The title screen stacks its choices, as on the sheet. */
.menu-actions-column {
  flex-direction: column;
  align-items: stretch;
  max-width: 340px;
  margin-left: auto;
  margin-right: auto;
}

/* The pause screen's bearings, under its buttons. */
.menu-status {
  margin: 16px 0 0;
  font-size: 17px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

/* A value the player can read but not change, like the language. */
.menu-readout {
  margin: 6px 0 0;
  font-size: 17px;
  font-weight: 700;
  color: var(--btn);
}

/* What the seed field answers: the seed taken, or why it was not. */
.menu-seed-message {
  margin: 10px 0 0;
  min-height: 1.2em;
  font-size: 15px;
  color: var(--btn);
}

.menu-seed-message.is-bad {
  color: #ff9a6a;
}

.menu-hint,
.menu-howto {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.35;
}

.menu-howto {
  text-align: left;
  border-top: 1px solid rgba(181, 163, 133, 0.25);
  padding-top: 12px;
  margin-top: 16px;
}

.menu-warning {
  margin: 10px 0 0;
  color: #ff9a6a;
  font-size: 15px;
}

.menu-slider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 8px 0;
  min-height: 44px;
}

.menu-slider-label {
  width: 6.5em;
  text-align: left;
  font-weight: 700;
}

.menu-slider input[type='range'] {
  flex: 1;
  accent-color: var(--btn);
  height: 24px;
}

.menu-slider-value {
  width: 4em;
  text-align: right;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.menu-choice {
  display: flex;
  gap: 8px;
  justify-content: flex-start;
  flex-wrap: wrap;
}

.menu-choice[hidden] {
  display: none;
}

/* ---------- Mode screen (M7a) ----------
   Two cards side by side in landscape, one above the other in portrait; past
   four the list scrolls inside the panel instead of pushing it off screen. */
.menu[data-menu='mode'] .menu-panel {
  width: min(720px, 100%);
}

.mode-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  text-align: left;
}

.mode-cards.is-many {
  max-height: 52vh;
  overflow-y: auto;
  padding: 2px 6px 6px 2px;
}

@media (orientation: portrait), (max-width: 560px) {
  .mode-cards {
    grid-template-columns: minmax(0, 1fr);
  }
}

button.mode-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  min-height: 44px;
  padding: 12px 14px;
  text-align: left;
  font-weight: 400;
  font-size: 16px;
  color: var(--text);
  background: #3c342c;
  border: 2px solid var(--ink);
  border-radius: 4px;
  box-shadow: 0 0 0 1px rgba(232, 200, 114, 0.35) inset, 3px 3px 0 var(--ink);
}

button.mode-card.on {
  background: #4a3d26;
  box-shadow: 0 0 0 3px var(--btn) inset, 3px 3px 0 var(--ink);
}

.mode-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
}

.mode-card-name {
  font-family: var(--font-title);
  font-size: 26px;
  line-height: 1.05;
  color: var(--btn);
}

.mode-card-badge {
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #1a1410;
  background: var(--accent);
  border: 1px solid var(--ink);
  border-radius: 2px;
  padding: 1px 6px;
}

.mode-card-body {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.mode-card-sketch {
  flex: 0 0 64px;
  line-height: 0;
}

.mode-card-desc {
  color: var(--text);
  line-height: 1.3;
}

.mode-card-best {
  color: var(--muted);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.mode-difficulty {
  justify-content: center;
  align-items: center;
  margin-top: 14px;
}

.records-modes {
  justify-content: center;
  margin-bottom: 12px;
}

.menu-score {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 16px;
  margin: 14px 0 0;
  text-align: left;
  font-size: 17px;
}

.menu-score dt {
  color: var(--muted);
}

.menu-score dd {
  margin: 0;
  text-align: right;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.menu-record {
  margin: 10px 0 0;
  font-size: 15px;
  color: var(--muted);
}

.menu-record:empty {
  display: none;
}

.menu-record.is-record {
  color: var(--btn);
  font-weight: 700;
}

/* A notice at the top of a menu panel: an update waiting, or the offer to put
   the game on the home screen. */
.menu-notice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 12px;
  margin: 0 0 16px;
  padding: 10px 14px;
  border: 2px solid var(--ink);
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.4);
  font-size: 16px;
}

.menu-notice[hidden] {
  display: none;
}

.menu-notice strong {
  color: var(--btn);
}

.menu-notice button {
  min-height: 44px;
  min-width: 44px;
}

.menu-notice-hint {
  flex-basis: 100%;
  color: var(--muted);
  font-size: 14px;
}

.menu-notice-hint[hidden] {
  display: none;
}

/* Records screen: the table stays readable on a tablet, so the seed keeps its
   own line with the date under it instead of a wide extra column. */
.menu[data-menu='records'] .menu-panel {
  width: min(620px, 100%);
}

.records-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.records-table[hidden] {
  display: none;
}

.records-table th {
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
  padding: 0 6px 6px;
  border-bottom: 2px solid var(--ink);
}

.records-table td {
  padding: 5px 6px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.5);
  vertical-align: top;
}

.records-table .num {
  text-align: right;
  white-space: nowrap;
}

.records-table .seed {
  text-align: left;
  width: 99%;
}

.records-table tr:first-child td {
  font-weight: 700;
  color: var(--btn);
}

/* The seed is a button, but it should read as a line in the table. */
.records-seed {
  background: none;
  border: 0;
  box-shadow: none;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
  letter-spacing: 0.1em;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  /* 44px of target without 44px of ink: the row grows, the text does not. */
  min-height: 44px;
}

.records-victory {
  margin-left: 6px;
  color: var(--btn);
}

.records-date {
  display: block;
  font-size: 13px;
  color: var(--muted);
  letter-spacing: 0;
  font-weight: 500;
}

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

.records-actions button {
  min-height: 44px;
  min-width: 44px;
}

.records-actions button[disabled] {
  opacity: 0.4;
  cursor: default;
}

.records-paste-label {
  margin-bottom: 6px;
  text-align: left;
}

.records-paste {
  width: 100%;
  box-sizing: border-box;
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 13px;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  border: 2px solid var(--ink);
  border-radius: 3px;
  resize: vertical;
}

.records-confirm {
  margin-top: 16px;
  padding: 12px 14px 16px;
  border: 2px solid var(--ink);
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.35);
}

.records-confirm[hidden] {
  display: none;
}

.records-confirm .menu-section {
  margin-top: 0;
}

.records-confirm .menu-score {
  font-size: 15px;
}

.records-status {
  margin: 12px 0 0;
  min-height: 1.2em;
  font-size: 15px;
  color: var(--muted);
}

.records-status[data-kind='error'] {
  color: var(--accent);
  font-weight: 700;
}

/* On a short screen the title screen has to stay scrollable and compact. */
@media (max-height: 600px) {
  .menu-title {
    font-size: clamp(26px, 5vw, 36px);
  }

  .menu-howto {
    display: none;
  }
}

/* ---------- Rune discs (docs/ART.md, "Runenscheiben-Knopf") ----------
   Stone core, gold rim, ten runes in the band, the symbol on top. The three
   states are driven by data-state; everything else is the same disc. */

.rune {
  --disc: 58px;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  width: var(--disc);
  min-width: var(--disc);
  min-height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  box-shadow: none;
  color: var(--btn);
}

.rune:active {
  transform: translate(1px, 1px);
  box-shadow: none;
}

.rune:disabled {
  /* Locked and cooling discs say so with the lock and the wedge, so they stay
     readable instead of being greyed into mush. */
  opacity: 1;
  box-shadow: none;
}

/* A ready disc that is only short of the price: dimmed, but not marked. */
.rune[data-state='ready']:disabled .rune-disc {
  opacity: 0.5;
}

/* .on is the running mode; the plain button rule would paint the square red. */
.rune.on,
.rune.on:disabled {
  background: none;
  color: var(--btn);
}

.rune-disc {
  position: relative;
  display: block;
  width: var(--disc);
  height: var(--disc);
  filter: drop-shadow(2px 2px 0 rgba(0, 0, 0, 0.55));
}

.rune-plate {
  display: block;
  width: 100%;
  height: 100%;
}

.rune-symbol {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 60%;
  height: 60%;
  transform: translate(-50%, -50%);
}

/* The wedge of the wait. It covers `--pie` of the turn, in whole waves. */
.rune-pie {
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  /* Dark enough to read as a wait, light enough to leave the symbol legible. */
  background: conic-gradient(rgba(10, 8, 6, 0.5) var(--pie, 100%), rgba(0, 0, 0, 0) 0);
}

.rune-waves {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--font-title);
  font-size: 26px;
  line-height: 1;
  color: var(--text);
  text-shadow: 2px 2px 0 var(--ink);
}

.rune-lock {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54%;
  height: 54%;
  transform: translate(-50%, -50%);
}

/* Locked: the whole disc goes dark behind the padlock. */
.rune[data-state='locked'] .rune-symbol {
  opacity: 0.35;
  filter: grayscale(1) brightness(0.6);
}

.rune[data-state='locked'] .rune-plate {
  filter: brightness(0.5);
}

/* The wedge already dims the symbol; taking more off would hide it. */

.rune-badge {
  position: absolute;
  right: -4px;
  top: -3px;
  min-width: 20px;
  padding: 0 4px;
  border: 2px solid var(--ink);
  border-radius: 11px;
  background: var(--btn);
  color: #1a1410;
  font-size: 13px;
  font-weight: 700;
  line-height: 17px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.rune-note {
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  color: var(--btn);
  text-shadow: 1px 1px 0 var(--ink);
  font-variant-numeric: tabular-nums;
}

.rune[data-state='ready']:disabled .rune-note {
  color: #d08b6a;
}

.rune[hidden],
.rune-note[hidden],
.rune-waves[hidden],
.rune-badge[hidden],
.rune-pie[hidden] {
  display: none;
}

/* The mode this disc switches is running: a gold ring around the whole thing. */
/* A disc that calls for attention (ui/nudges.js): a gold ring on the rim that
   stays, and a second one that swells out of it and fades, every 1.6 s. No glow
   filter, only rings. */
.rune.calling .rune-disc::before,
.rune.calling .rune-disc::after {
  content: '';
  position: absolute;
  inset: -4px;
  border: 3px solid var(--gold);
  border-radius: 50%;
  pointer-events: none;
}

.rune.calling .rune-disc::after {
  animation: rune-calling 1.6s ease-out infinite;
}

@keyframes rune-calling {
  0% { opacity: 0.9; transform: scale(1); }
  70% { opacity: 0; transform: scale(1.4); }
  100% { opacity: 0; transform: scale(1.4); }
}

@media (prefers-reduced-motion: reduce) {
  /* Standing still: only the ring on the rim. */
  .rune.calling .rune-disc::after {
    display: none;
  }
}

.rune.on .rune-disc {
  filter: drop-shadow(0 0 0 rgba(0, 0, 0, 0)) drop-shadow(0 0 3px var(--btn));
}

/* The name, once, when the disc unlocks; then it is bubble-only again. */
.rune-flash,
.rune-bubble {
  position: absolute;
  z-index: 2;
  pointer-events: none;
  background: rgba(24, 18, 14, 0.96);
  border: 2px solid var(--ink);
  border-radius: 4px;
  box-shadow: 3px 3px 0 var(--ink);
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
  line-height: 1.25;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.15s;
}

.rune-flash {
  left: 50%;
  bottom: calc(100% + 10px);
  transform: translateX(-50%);
  padding: 4px 10px;
  font-weight: 700;
  color: var(--btn);
}

.rune.flashing .rune-flash {
  opacity: 1;
  animation: rune-flash 2.6s ease-out forwards;
}

@keyframes rune-flash {
  0% { opacity: 0; transform: translate(-50%, 6px); }
  12% { opacity: 1; transform: translate(-50%, 0); }
  75% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, 0); }
}

.rune-bubble {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: max-content;
  max-width: 240px;
  padding: 6px 10px;
  white-space: normal;
  text-align: left;
}

.rune-bubble b {
  font-family: var(--font-title);
  font-weight: 400;
  font-size: 17px;
  color: var(--btn);
}

.rune[data-side='top'] .rune-bubble {
  left: 50%;
  bottom: calc(100% + 12px);
  transform: translateX(-50%);
}

.rune[data-side='left'] .rune-bubble {
  right: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%);
}

.rune.explaining .rune-bubble {
  opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
  .rune.flashing .rune-flash {
    animation: none;
    opacity: 1;
  }

  .rune-flash,
  .rune-bubble {
    transition: none;
  }

  .rune:active {
    transform: none;
  }
}

/* ---------- Help overlay: the "?" and its speech bubbles ---------- */

.help-button {
  position: absolute;
  left: calc(10px + var(--safe-left));
  bottom: calc(26px + var(--safe-bottom));
  z-index: 12;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  background: rgba(24, 18, 14, 0.92);
  color: var(--btn, #e8c872);
  font-family: var(--font-title);
  font-size: 26px;
  line-height: 1;
  box-shadow: 2px 2px 0 var(--ink);
  cursor: pointer;
}

.help-button[aria-pressed='true'] {
  background: var(--btn, #e8c872);
  color: var(--ink);
}

.help-layer {
  position: fixed;
  inset: 0;
  z-index: 11;
  /* The HUD layer lets clicks through to the map; this one must catch them. */
  pointer-events: auto;
  background: rgba(10, 7, 5, 0.55);
}

.help-layer[hidden] {
  display: none;
}

.help-bubble {
  position: absolute;
  box-sizing: border-box;
  width: 132px;
  padding: 4px 7px;
  background: rgba(24, 18, 14, 0.97);
  border: 2px solid var(--ink);
  border-radius: 4px;
  box-shadow: 3px 3px 0 var(--ink);
  color: var(--text);
  font-size: 12px;
  line-height: 1.2;
  pointer-events: none;
  animation: help-pop 0.18s ease-out both;
}

.help-bubble b {
  display: block;
  font-family: var(--font-title);
  font-weight: 400;
  font-size: 14px;
  color: var(--btn, #e8c872);
}

.help-button[hidden] {
  display: none;
}

.help-meta {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.help-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.help-lines line {
  stroke: var(--btn, #e8c872);
  stroke-width: 1.5;
  stroke-dasharray: 4 4;
  opacity: 0.85;
}

.help-ring {
  position: absolute;
  border: 2px solid var(--btn, #e8c872);
  border-radius: 8px;
  pointer-events: none;
}

.help-dismiss {
  position: absolute;
  left: calc(64px + var(--safe-left));
  bottom: calc(38px + var(--safe-bottom));
  color: var(--muted);
  font-size: 14px;
  pointer-events: none;
}

@keyframes help-pop {
  from { opacity: 0; transform: scale(0.92); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .help-bubble { animation: none; }
}
