:root {
  --ink: #181814;
  --paper: #f4e7c3;
  --gold: #d8a93d;
  --gold-soft: #ffe19a;
  --red: #9c3830;
  --green: #3e7c52;
  --blue: #2f5d82;
  --shadow: rgba(16, 14, 10, 0.38);
  --line: rgba(255, 225, 154, 0.32);
  --text: #f9edcc;
  --muted: #cbb98e;

  /* Game screen panels. */
  --panel-bg: rgba(10, 20, 38, 0.8);
  --panel-edge: rgba(216, 169, 61, 0.5);
  --panel-radius: 10px;
  --display-font: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  /* Sizes follow the viewport height so the layout fills 1080p and 4K alike. */
  --game-text: clamp(17px, 2.3vh, 44px);
  --message-bar-height: clamp(150px, 16vh, 360px);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  overflow-x: hidden;
  color: var(--text);
  background: #0d1a2e;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  font: inherit;
}

/* ---------------------------------------------------------------------------
   Sea: procedural water drawn by sea.js (WebGL, no image files): moving swells,
   sun glints, and shallows with foam along the coast of the map on screen.
   Canvas2D keeps the sea moving without WebGL; this gradient is the last resort.
   --------------------------------------------------------------------------- */
.sea {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
  background:
    radial-gradient(circle at 22% 18%, #123a5c 0%, transparent 55%),
    radial-gradient(circle at 78% 76%, #0f3a55 0%, transparent 52%),
    linear-gradient(180deg, #062038 0%, #0b3150 45%, #051a30 100%);
}

.sea-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: none;
}

.sea.has-webgl .sea-canvas,
.sea.has-fallback .sea-canvas {
  display: block;
}

.app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
}

.screen {
  display: none;
  min-height: 100vh;
}

.screen.is-active {
  display: block;
}

/* ---------------------------------------------------------------------------
   Boot + menus: the same navy panels and gold trim as the campaign
   --------------------------------------------------------------------------- */
.screen-boot {
  place-items: center;
  padding: 32px;
}

.screen-boot.is-active {
  display: grid;
}

.boot-layout {
  width: min(760px, 100%);
  display: grid;
  gap: 28px;
  justify-items: center;
  padding: 38px;
  border: 1px solid var(--line);
  border-radius: var(--panel-radius);
  background: var(--panel-bg);
  box-shadow: 0 30px 80px var(--shadow);
}

.boot-logo {
  width: min(420px, 100%);
  height: auto;
  filter: drop-shadow(0 16px 18px rgba(0, 0, 0, 0.38));
}

.boot-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 18px;
  justify-items: center;
}

.boot-title {
  font-weight: 900;
  letter-spacing: 0.04em;
  color: var(--gold-soft);
}

.boot-meter {
  width: 100%;
  height: 10px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.34);
}

.boot-meter span {
  display: block;
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--red), var(--gold));
}

.primary-button,
.ghost-button,
.toolbar-button,
.command-button,
.scenario-button,
.family-card {
  cursor: pointer;
  border: 1px solid var(--line);
  color: var(--text);
  background: rgba(14, 33, 57, 0.92);
}

.primary-button,
.ghost-button,
.toolbar-button {
  padding: 8px 14px;
}

.primary-button {
  border-color: rgba(255, 225, 154, 0.55);
  background: linear-gradient(180deg, #284f78, #173451);
  font-weight: 800;
}

.ghost-button,
.toolbar-button {
  background: rgba(10, 20, 38, 0.9);
}

.primary-button:hover,
.ghost-button:hover,
.toolbar-button:hover,
.command-button:hover,
.scenario-button:hover,
.family-card:hover {
  border-color: var(--gold-soft);
}

.screen-menu {
  min-height: 100vh;
  padding: clamp(16px, 3vw, 40px);
}

.screen-menu.is-active {
  display: grid;
  align-content: safe center;
  /* Scroll long setup screens above the badge, not underneath its hit target. */
  height: calc(100dvh - 64px - env(safe-area-inset-bottom));
  min-height: 0;
  overflow-y: auto;
}

.menu-stage {
  display: grid;
  grid-template-columns: minmax(340px, 420px) minmax(320px, 1fr);
  gap: 28px;
  align-items: center;
  width: min(1280px, 100%);
  margin: 0 auto;
}

.intro-stage {
  width: min(1050px, 100%);
  margin: auto;
  padding: clamp(20px, 3vw, 36px);
  border: 1px solid var(--panel-edge);
  border-radius: var(--panel-radius);
  background: var(--panel-bg);
  display: grid;
  gap: 22px;
}
.intro-heading { display: flex; align-items: center; gap: 20px; }
.intro-crest { width: 56px; height: 72px; object-fit: contain; }
.intro-eyebrow { color: var(--muted); margin-bottom: 6px; }
.intro-context { font-size: 17px; line-height: 1.6; max-width: 85ch; }
.intro-dialogue { display: grid; gap: 14px; }
.intro-dialogue-card {
  display: flex; align-items: center; gap: 24px;
  padding: 16px; border: 1px solid var(--line); border-radius: 8px;
  background: rgba(14, 35, 61, .7);
}
.intro-dialogue-card img { width: 112px; height: 112px; object-fit: contain; flex: none; }
.intro-dialogue-card h2 { color: var(--gold-soft); font-size: 21px; margin-bottom: 8px; }
.intro-dialogue-card p { font-family: var(--display-font); font-size: 21px; line-height: 1.45; }
.intro-actions { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
@media (max-width: 600px) {
  .intro-dialogue-card { gap: 14px; padding: 12px; align-items: flex-start; }
  .intro-dialogue-card img { width: 76px; height: 76px; }
  .intro-dialogue-card p { font-size: 18px; }
  .intro-context { font-size: 16px; }
}

.menu-left,
.family-stage {
  display: grid;
  gap: 16px;
  align-content: start;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--panel-radius);
  background: var(--panel-bg);
}

.menu-logo {
  width: min(280px, 70%);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
  letter-spacing: 0.02em;
  color: var(--gold-soft);
}

.scenario-list {
  display: grid;
  gap: 10px;
}

.scenario-button {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  text-align: left;
}

.scenario-number {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  font-weight: 900;
  color: var(--gold-soft);
}

.scenario-name {
  display: block;
  font-weight: 900;
  font-size: 17px;
}

.scenario-era {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
}

.scenario-count {
  color: var(--muted);
  font-size: 12px;
}

.menu-map-wrap {
  display: grid;
  place-items: center;
}

/* ---------------------------------------------------------------------------
   Map (scenario preview and game). Catie's 512x512 map art, shown as the band
   y 80..426 that holds the land (MAP_ART in app.js). The sea behind it is the
   CSS/JS water, so the map has no background of its own. Marker sizes are in
   cqw, i.e. a share of the map's width, so crests stay small at any size.
   --------------------------------------------------------------------------- */
.world-map {
  position: relative;
  aspect-ratio: 512 / 346;
  container-type: inline-size;
  overflow: hidden;
}

.world-map-art {
  position: absolute;
  left: 0;
  top: calc(-80 / 346 * 100%);
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  image-rendering: pixelated;
  /* Slight contact shade only: the island sits in the water, not above it. */
  filter: drop-shadow(0 0.15cqw 0.35cqw rgba(0, 20, 30, 0.35));
  pointer-events: none;
}

.map-frame {
  width: min(100%, 980px);
}

.map-marker {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: flex-end;
  gap: 0.25cqw;
  border: 0;
  padding: 0.2cqw 0.35cqw;
  border-radius: 0.8cqw;
  color: #fff;
  background: transparent;
  font: inherit;
  line-height: 1;
}

button.map-marker {
  cursor: pointer;
}

.marker-id {
  font-family: var(--display-font);
  font-size: 2.1cqw;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 0 0.3cqw #000, 0 0.12cqw 0.2cqw #000;
}

/* Crests are Catie's remastered art (square to 3:4); every crest sits in a
   3:4 box so they read at one size whatever their proportions. */
.marker-crest {
  height: 2.5cqw;
  aspect-ratio: 3 / 4;
  object-fit: contain;
  filter: drop-shadow(0 0.1cqw 0.2cqw rgba(0, 0, 0, 0.7));
}

.map-marker.open .marker-id {
  color: rgba(255, 255, 255, 0.78);
}

button.map-marker:hover,
button.map-marker:focus-visible {
  outline: none;
  background: rgba(10, 20, 38, 0.45);
}

.map-marker.is-selected {
  background: rgba(10, 20, 38, 0.55);
  box-shadow: 0 0 0 0.18cqw var(--gold-soft), 0 0 1cqw rgba(255, 225, 154, 0.6);
}

.map-marker.is-assigned:not(.is-selected) {
  box-shadow: 0 0 0 0.14cqw rgba(255, 225, 154, 0.7);
  animation: marker-pulse 1.6s ease-in-out infinite;
}

@keyframes marker-pulse {
  50% { box-shadow: 0 0 0 0.14cqw rgba(255, 225, 154, 0.15); }
}

.family-stage {
  width: min(1200px, 100%);
  margin: 0 auto;
}

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

.family-head p {
  color: var(--muted);
  font-size: 13px;
}

.family-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.family-card {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 14px;
  padding: 18px;
  border-radius: 8px;
  text-align: left;
  align-content: start;
}

.family-card > img {
  width: 64px;
  height: 84px;
  object-fit: contain;
  align-self: center;
}

.family-card > span:not(.family-holdings) {
  display: grid;
  grid-template-columns: 128px minmax(0, 1fr);
  gap: 5px 14px;
  align-content: start;
}

.family-leader {
  grid-column: 1;
  grid-row: 1 / span 6;
  width: 128px;
  height: 152px;
  object-fit: contain;
  align-self: center;
}

.family-card .family-title,
.family-card .family-sub {
  grid-column: 2;
}

.family-title {
  display: block;
  font-weight: 900;
  font-size: 17px;
  color: var(--gold-soft);
}

.family-sub {
  display: block;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
}

.family-holdings {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
}

/* ---------------------------------------------------------------------------
   Main screen: the Genesis arrangement with modern panels.

     +-------------+------------------------------+
     | crest, name |  Year 1 Jan                  |
     | portrait    |                              |
     | 6 stats     |  map                         |
     | 4 commands  |                              |
     +-------------+------------------------------+
     | message box                                |
     +--------------------------------------------+

   Only the crests, portraits, stat icons and command icons are image assets;
   frames, headers and text are CSS so the remaster reads as modern.
   --------------------------------------------------------------------------- */
.screen-game {
  min-height: 100vh;
  display: none;
  padding: clamp(8px, 1.2vh, 20px);
}

.screen-game.is-active {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: clamp(8px, 1.2vh, 20px);
  height: 100vh;
}

.remaster-bar {
  position: relative;
  z-index: 12;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto auto;
  align-items: center;
  gap: 0.8em;
  padding: 0.6em 1em;
  border: 1px solid var(--line);
  border-radius: var(--panel-radius);
  background: rgba(12, 18, 30, 0.86);
  font-size: calc(var(--game-text) * 0.8);
}

.remaster-bar .toolbar-button {
  padding: 0.35em 0.9em;
}

.remaster-logo {
  display: block;
  width: clamp(85px, 9vw, 200px);
  height: auto;
  object-fit: contain;
}
.remaster-title { min-width: 0; }
#endMonth { white-space: nowrap; }
.campaign-settings { position: relative; justify-self: end; }
.remaster-bar .settings-gear {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 9px;
}
.settings-gear svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; }
.settings-dropdown {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: max-content;
  min-width: 210px;
  max-width: calc(100vw - 32px);
  padding: 8px;
  display: grid;
  gap: 4px;
  border: 1px solid var(--gold-soft);
  border-radius: 8px;
  background: rgba(8, 21, 38, .98);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
}
.settings-dropdown[hidden] { display: none; }
.remaster-bar .settings-dropdown .toolbar-button { min-height: 44px; text-align: left; }
.audio-toggle { display: flex; align-items: center; justify-content: space-between; gap: 1em; }
.audio-toggle .mute-check { visibility: hidden; color: var(--gold-soft); }
.audio-toggle[aria-pressed="true"] .mute-check { visibility: visible; }

.remaster-title {
  color: var(--muted);
}

.remaster-crest {
  height: 1.8em;
  aspect-ratio: 3 / 4;
  object-fit: contain;
}

.remaster-spacer {
  flex: 1;
}

.game-layout {
  display: grid;
  grid-template-columns: clamp(300px, 26vw, 700px) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) var(--message-bar-height);
  gap: clamp(8px, 1.2vh, 20px);
  min-height: 0;
}

.game-panel {
  position: relative;
  min-height: 0;
  border: 1px solid var(--panel-edge);
  border-radius: var(--panel-radius);
  background: var(--panel-bg);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 225, 154, 0.12);
  backdrop-filter: blur(6px);
  color: var(--text);
}

/* Left status panel. */
.status-panel {
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 1.4vh, 26px);
  padding: clamp(12px, 1.8vh, 34px);
  overflow: hidden;
}

.status-head {
  display: flex;
  align-items: center;
  gap: clamp(10px, 1.2vh, 22px);
}

.faction-crest {
  height: clamp(56px, 8vh, 150px);
  aspect-ratio: 3 / 4;
  flex: none;
  object-fit: contain;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.5));
}

.status-titles {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.faction-name {
  font-family: var(--display-font);
  font-size: calc(var(--game-text) * 1.45);
  font-weight: 700;
  line-height: 1.1;
  color: var(--gold-soft);
}

.province-line {
  display: flex;
  gap: 0.3em;
  font-size: var(--game-text);
  color: var(--text);
}

.panel-rule {
  height: 1px;
  flex: none;
  background: linear-gradient(90deg, transparent, var(--gold) 20%, var(--gold) 80%, transparent);
  opacity: 0.7;
}

.lord-block {
  display: flex;
  align-items: center;
  gap: clamp(12px, 1.6vh, 30px);
}

/* Portrait assets remain unchanged; the campaign frame is CSS, not baked-in art. */
.lord-portrait {
  height: clamp(96px, 16vh, 300px);
  aspect-ratio: 40 / 48;
  flex: none;
  object-fit: contain;
  image-rendering: pixelated;
}

#lordPortrait:not(.creature-picture),
.intro-dialogue-card img {
  aspect-ratio: 1;
  object-fit: cover;
  image-rendering: auto;
  border: 2px solid #ba9750;
  border-color: #efd58b #957033 #80602c #dbc078;
  border-radius: 7px;
  background: #142334;
  box-shadow: 0 0 0 1px #493a22;
}

.player-setup { display: grid; gap: 10px; margin: 0 0 18px; }
.setup-stage { width: min(620px, 100%); }
.setup-heading { display: flex; align-items: center; gap: clamp(12px, 3vw, 24px); margin-bottom: 20px; }
.setup-stage .menu-logo { width: clamp(88px, 30vw, 180px); flex: none; }
.setup-heading-text { min-width: 0; display: grid; gap: 6px; }
.setup-heading h1 { font-size: clamp(20px, 3vw, 26px); overflow-wrap: anywhere; }
.setup-scenario { color: var(--gold); overflow-wrap: anywhere; }
.setup-stage > p { line-height: 1.5; }
.setup-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 24px 0; }
.setup-choices[data-stage="count"] { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.setup-choices .scenario-button:only-child { grid-column: 1 / -1; }
.setup-choices .scenario-button { width: 100%; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; text-align: left; overflow-wrap: anywhere; }
#playerModeSummary { color: var(--gold); }
.player-setup p { margin: 0; }
.family-card:disabled { opacity: .55; cursor: default; }

/* Genesis event pictures replace the lord portrait/name, above the six stats.
   Preserve the complete 4:3 composition: no crops, modal, or map replacement. */
.creature-scene {
  justify-content: center;
  min-height: 0;
}
.creature-scene .creature-picture {
  display: block;
  width: min(100%, calc(clamp(96px, 16vh, 300px) * 4 / 3));
  height: auto;
  max-height: 25vh;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  image-rendering: auto;
}
.creature-scene .creature-picture[data-source="original"] { image-rendering: pixelated; }
.creature-scene .lord-text[hidden], .command-row[hidden] { display: none; }
.creature-continue { margin-left: auto; flex: none; }

.lord-text {
  display: grid;
  gap: 0.4em;
  min-width: 0;
}

.lord-name {
  font-family: var(--display-font);
  font-size: calc(var(--game-text) * 1.25);
  font-weight: 700;
  line-height: 1.15;
}

.lord-rank {
  justify-self: start;
  padding: 0.15em 0.6em;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: calc(var(--game-text) * 0.72);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.lord-rank:empty {
  display: none;
}

/* Six stats, two columns of three (gold/food/soldiers left, loyalty/cultivation/protection right). */
.stat-block {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-auto-rows: auto;
  gap: clamp(6px, 1vh, 18px) clamp(10px, 1.4vw, 30px);
}

.stat-row {
  display: flex;
  align-items: center;
  gap: 0.6em;
  min-width: 0;
}

/* Catie's 768x512 stat tiles carry their own frame, so they are shown whole and
   large enough to read; they shrink with the column on narrow windows. */
.stat-icon {
  width: calc(var(--game-text) * 3.9);
  max-width: 62%;
  height: auto;
  aspect-ratio: 3 / 2;
  flex: 0 1 auto;
  min-width: 0;
  object-fit: contain;
}

.stat-value {
  font-size: calc(var(--game-text) * 1.35);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Command icons: the four main commands, or a menu's four sub-commands. */
.command-row {
  display: flex;
  gap: clamp(8px, 1vh, 18px);
  margin-top: auto;
}

.command-icon {
  position: relative;
  flex: 1 1 0;
  max-width: clamp(64px, 13vh, 280px);
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease;
}

.command-icon img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 6px;
  object-fit: contain;
}

.command-icon:hover:not(:disabled),
.command-icon:focus-visible {
  outline: none;
  transform: translateY(-2px);
  filter: brightness(1.12);
}

.command-icon.is-selected {
  box-shadow: 0 0 0 3px var(--gold-soft), 0 0 16px rgba(255, 225, 154, 0.55);
}

.command-icon:disabled {
  cursor: default;
  filter: grayscale(0.7) brightness(0.55);
}

/* Map panel: date header, then the map filling the rest. The panel is see-through
   so the animated sea is the map's water. */
.map-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: rgba(10, 20, 38, 0.18);
  backdrop-filter: none;
  overflow: hidden;
}

.date-header {
  justify-self: start;
  margin: clamp(10px, 1.4vh, 26px) 0 0 clamp(10px, 1.4vh, 26px);
  padding: 0.3em 1.1em;
  border: 1px solid rgba(255, 225, 154, 0.55);
  border-radius: 6px;
  background: linear-gradient(180deg, #b8452f, #7e2a1d);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
  font-family: var(--display-font);
  font-size: calc(var(--game-text) * 1.2);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #fff4dc;
  position: relative;
  z-index: 1;
}

.map-area {
  container-type: size;
  display: grid;
  place-items: center;
  min-height: 0;
  padding: clamp(6px, 1vh, 18px);
}

.map-area .world-map {
  width: min(100cqw, calc(100cqh * 512 / 346));
}
.map-birds {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 5;
  pointer-events: none;
}

.turn-banner {
  position: absolute;
  left: 12px;
  bottom: 12px;
  font-size: var(--game-text);
  color: var(--gold-soft);
}

/* Start menu occupies the map slot; it uses our panels and modern type. */
.options-panel {
  grid-area: 1 / 1;
  align-self: stretch;
  justify-self: stretch;
  z-index: 3;
  padding: clamp(14px, 2.5vh, 48px);
  overflow: auto;
  background: rgba(10, 20, 38, .94);
  border: 1px solid var(--panel-edge);
  border-radius: var(--panel-radius);
}
.options-list { display: grid; gap: .25em; margin-bottom: 1em; }
.options-row {
  padding: .35em .7em;
  text-align: left;
  font-family: var(--display-font);
  font-size: calc(var(--game-text) * 1.15);
  color: var(--text);
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
}
.options-row:hover:not(:disabled), .options-row:focus-visible, .options-row.is-current {
  border-color: var(--gold-soft);
  background: rgba(216, 169, 61, .12);
  outline: none;
}
.options-row:disabled { opacity: .5; cursor: default; }
.saved-game-button { grid-template-columns: 1fr; }
.saved-game-button .scenario-era { margin: 0; }

/* A narrow campaign needs real space for both panels, not a collapsed second
   desktop column. Keep it scrollable without changing tactical battle layout. */
@media (max-width: 760px) {
  .screen-game.is-active {
    height: 100dvh;
    min-height: 100dvh;
    grid-template-rows: auto minmax(0, 1fr);
    /* Keep the fixed help badge out of scrolling map/command hit targets. */
    padding-bottom: 64px;
  }
  .game-layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: max-content max-content max-content;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .game-layout > .map-panel {
    min-height: 300px;
  }
  .game-layout .map-area {
    min-height: 240px;
  }
  .game-layout > .message-panel {
    height: auto;
    min-height: var(--message-bar-height);
  }
}

/* Message box across the bottom: the prompt and a second line, as in the original. */
.message-panel {
  grid-column: 1 / -1;
  display: grid;
  align-content: start;
  gap: 0.35em;
  height: var(--message-bar-height);
  min-height: 0;
  overflow-y: auto;
  padding: clamp(10px, 1.6vh, 30px) clamp(16px, 2vw, 48px);
  font-size: calc(var(--game-text) * 1.15);
  line-height: 1.3;
}

.message-text,
.sub-message {
  font-family: var(--display-font);
}

.sub-message {
  color: var(--gold-soft);
}

.sub-message:empty {
  display: none;
}

/* A step's options ("▸Yea Nay"): the ▸ marks the cursor, as in the original. */
.sub-message:has(.message-option) {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2em 1.4em;
}

.message-option {
  padding: 0 0 0 1em;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  position: relative;
}

.message-option.is-current {
  color: var(--gold-soft);
}

.message-option.is-current::before {
  content: "▸";
  position: absolute;
  left: 0;
  animation: cursor-blink 133.33ms linear infinite;
}

/* The rest of a broken prompt ("your command?", "cultivation? ▸Yea Nay") reads
   as one sentence with line 1; the highlighted "<Attack>" label keeps the accent. */
.sub-message:has(.message-tail, .message-label) {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.2em 1.4em;
}

.message-tail,
.message-after {
  color: var(--text);
}

.message-label {
  color: var(--gold-soft);
}

/* Input digit entry: the edited digit is boxed, as on Genesis. */
.quantity-digits {
  display: inline-flex;
  gap: 0.08em;
  font-variant-numeric: tabular-nums;
}

.quantity-digit {
  display: inline-block;
  min-width: 0.7em;
  text-align: center;
}

.quantity-digit.is-current {
  outline: 2px solid var(--gold-soft);
  outline-offset: 1px;
  animation: box-blink 133.33ms linear infinite;
}

/* Genesis blinks the cursor 4 frames on, 4 off (8 frames = 133 ms at 60 Hz),
   measured in research/captures/genesis/typing/recruit/. */
@keyframes cursor-blink {
  0%, 49.9% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

/* Only the box blinks; the digit stays readable. */
@keyframes box-blink {
  0%, 49.9% { outline-color: var(--gold-soft); }
  50%, 100% { outline-color: transparent; }
}

@media (prefers-reduced-motion: reduce) {
  .message-option.is-current::before,
  .quantity-digit.is-current {
    animation: none;
  }
}

.message-option:hover,
.message-option:focus-visible {
  outline: none;
  color: var(--gold-soft);
}

/* Hosts kept for the attack flow and the headless tests; never shown. */
.hidden-host {
  display: none;
}

/* ---------------------------------------------------------------------------
   Territory pointer, 5th-unit list and unit card (attack setup, ACT-0033/0049)
   --------------------------------------------------------------------------- */
.map-area {
  position: relative;
}

.map-pointer {
  position: absolute;
  z-index: 3;
  width: 0;
  height: 0;
  pointer-events: none;
}

/* The arrow's tip sits on the pointer position, like the Genesis map arrow. */
.map-pointer::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  width: calc(var(--game-text) * 1.5);
  height: calc(var(--game-text) * 2);
  background: #fffbe8;
  clip-path: polygon(0 0, 0 78%, 26% 60%, 44% 100%, 60% 92%, 42% 54%, 76% 54%);
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.7));
}

.map-pointer-label {
  position: absolute;
  left: calc(var(--game-text) * 1.4);
  top: calc(var(--game-text) * 1.2);
  padding: 0.1em 0.5em;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: rgba(10, 20, 38, 0.86);
  font-family: var(--display-font);
  font-size: calc(var(--game-text) * 0.8);
  white-space: nowrap;
  color: var(--gold-soft);
}

.map-pointer-label:empty {
  display: none;
}

.map-marker.is-pointed {
  z-index: 2;
  filter: drop-shadow(0 0 0.35em var(--gold-soft)) brightness(1.15);
}

/* After a target is chosen, the attacker's and target's flags blink (Genesis a02). */
.map-marker.is-blinking {
  animation: flag-blink 266.67ms steps(1) infinite;
}

@keyframes flag-blink {
  0%, 49.9% { opacity: 1; }
  50%, 100% { opacity: 0.25; }
}

/* "Choose the 5th unit": the list takes the map's place. */
.map-list {
  position: absolute;
  inset: clamp(6px, 1vh, 18px);
  z-index: 4;
  display: flex;
  flex-direction: column;
  gap: 0.4em;
  padding: 1em 1.4em;
  border: 1px solid var(--panel-edge);
  border-radius: var(--panel-radius);
  background: rgba(10, 20, 38, 0.94);
}

.map-list-row {
  display: flex;
  align-items: center;
  gap: 0.8em;
  padding: 0.2em 0.2em 0.2em 1.2em;
  border: 0;
  background: none;
  color: var(--text);
  font-family: var(--display-font);
  font-size: calc(var(--game-text) * 1.2);
  text-align: left;
  cursor: pointer;
  position: relative;
}

.map-list-row img {
  height: 2.2em;
  aspect-ratio: 40 / 48;
  object-fit: contain;
}

.map-list-row.is-current {
  color: var(--gold-soft);
}

.map-list-row.is-current::before {
  content: "▸";
  position: absolute;
  left: 0;
  animation: cursor-blink 133.33ms linear infinite;
}

/* The unit card replaces the left panel while "Is this OK?" is asked (Genesis a05). */
.unit-card {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  gap: clamp(10px, 1.6vh, 30px);
  padding: clamp(12px, 1.8vh, 34px);
  border-radius: var(--panel-radius);
  background: rgba(10, 20, 38, 0.97);
  font-family: var(--display-font);
}

.unit-card-head {
  display: flex;
  gap: clamp(12px, 1.6vh, 30px);
  align-items: center;
}

.unit-card-face {
  height: clamp(96px, 16vh, 300px);
  aspect-ratio: 40 / 48;
  object-fit: contain;
}

.unit-card-stats {
  display: grid;
  gap: 0.4em;
  font-size: calc(var(--game-text) * 1.2);
}

.unit-card-name {
  font-size: 1.2em;
  font-weight: 700;
  color: var(--gold-soft);
}

.unit-card-stat {
  display: flex;
  justify-content: space-between;
  gap: 1.2em;
}

.unit-card-stat span {
  color: var(--muted);
}

.unit-card-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(10px, 1.6vh, 30px);
  align-items: center;
}

.range-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  aspect-ratio: 1;
  padding: 4px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.35);
}

.range-cell {
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.06);
}

.range-cell.is-hit {
  background: #c9443a;
}

.range-cell.is-self {
  background: var(--gold-soft);
}

.unit-card-figure {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.35);
}

.unit-card-text {
  font-size: calc(var(--game-text) * 1.25);
  line-height: 1.3;
}

/* ---------------------------------------------------------------------------
   Battle screen: stacked lord supplies and province/day in modern panels.
   Numbered units flank the raised 10 × 8 field (above/below on phones);
   messages and combat/settlement overlays remain flat.
   --------------------------------------------------------------------------- */
.battle-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) var(--message-bar-height);
  gap: clamp(8px, 1.2vh, 20px);
  padding: clamp(8px, 1.2vh, 20px);
  isolation: isolate;
  background: #326e9c;
}

/* Decorative sky stays behind every panel and hit target, outside the board's
   perspective. Three seamless cloud banks drift at different depths; only
   transforms animate, so the sky needs no canvas, images or per-frame JS. */
.battle-sky {
  --sky-top: #326e9c;
  --sky-middle: #7bb4cd;
  --sky-bottom: #dbe7df;
  --sky-glow: #fff4d3;
  --sky-cloud: 246 249 239;
  --sky-stars: 0;
  position: absolute;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 76% 16%, var(--sky-glow), transparent 42%),
    linear-gradient(var(--sky-top), var(--sky-middle) 58%, var(--sky-bottom));
}

.battle-screen[data-sky-phase="dawn"] .battle-sky {
  --sky-top: #465a91;
  --sky-middle: #b698b2;
  --sky-bottom: #eed8bc;
  --sky-glow: #f6d1a7;
  --sky-cloud: 249 225 213;
}
.battle-screen[data-sky-phase="sunset"] .battle-sky {
  --sky-top: #404f7d;
  --sky-middle: #be827f;
  --sky-bottom: #e6b383;
  --sky-glow: #f8c982;
  --sky-cloud: 245 200 180;
}
.battle-screen[data-sky-phase="night"] .battle-sky {
  --sky-top: #0b1735;
  --sky-middle: #253c63;
  --sky-bottom: #586781;
  --sky-glow: #52688d;
  --sky-cloud: 127 152 184;
  --sky-stars: .65;
}
.battle-sky::before {
  content: "";
  position: absolute;
  inset: 0 0 30%;
  opacity: var(--sky-stars);
  background:
    radial-gradient(circle at 18% 28%, #e9efff 0 1px, transparent 1.6px) 0 0 / 173px 137px,
    radial-gradient(circle at 73% 65%, #e9efff 0 .7px, transparent 1.4px) 0 0 / 257px 191px;
}
.battle-sky::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 48%, transparent 35%, rgb(8 22 47 / .23));
}

.sky-clouds {
  position: absolute;
  left: 0;
  width: 200%;
  height: 42%;
  background-image:
    radial-gradient(ellipse 16% 26% at 0% 62%, rgb(var(--sky-cloud) / .82) 0 40%, transparent 100%),
    radial-gradient(ellipse 12% 30% at 23% 54%, rgb(var(--sky-cloud) / .9) 0 40%, transparent 100%),
    radial-gradient(ellipse 18% 24% at 38% 66%, rgb(var(--sky-cloud) / .86) 0 40%, transparent 100%),
    radial-gradient(ellipse 11% 28% at 60% 40%, rgb(var(--sky-cloud) / .86) 0 40%, transparent 100%),
    radial-gradient(ellipse 14% 30% at 76% 52%, rgb(var(--sky-cloud) / .94) 0 40%, transparent 100%),
    radial-gradient(ellipse 16% 26% at 100% 62%, rgb(var(--sky-cloud) / .82) 0 40%, transparent 100%);
  background-size: 50% 100%;
  background-repeat: repeat-x;
  animation: battle-cloud-drift 150s linear infinite;
}
.sky-clouds-far {
  top: -5%;
  height: 38%;
  opacity: .32;
  animation-duration: 210s;
  animation-delay: -78s;
}
.sky-clouds-middle {
  top: 27%;
  opacity: .48;
  animation-duration: 150s;
  animation-delay: -48s;
}
.sky-clouds-near {
  bottom: -10%;
  height: 49%;
  opacity: .85;
  animation-duration: 100s;
  animation-delay: -63s;
}
@keyframes battle-cloud-drift {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}
@media (prefers-reduced-motion: reduce) {
  .sky-clouds { animation: none; }
}

.battle-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1em;
  padding: 0.5em 1.4em;
  font-family: var(--display-font);
  font-size: calc(var(--game-text) * 1.3);
}

.battle-side-head,
.battle-day-head {
  display: grid;
  line-height: 1.15;
  min-width: 0;
}

.battle-side-head.side-defender {
  text-align: right;
}

.battle-lord {
  font-weight: 700;
  color: var(--gold-soft);
}

.battle-lord-line {
  display: flex;
  align-items: center;
  gap: 0.45em;
  min-width: 0;
}
.side-defender .battle-lord-line { justify-content: flex-end; }
.battle-lord-stack {
  display: grid;
  gap: .12em;
  min-width: 0;
}
.battle-lord-portrait {
  width: clamp(64px, 9vh, 144px);
  height: clamp(64px, 9vh, 144px);
  max-width: 100%;
  object-fit: contain;
  flex: none;
}
.battle-resources {
  display: grid;
  gap: 0.15em;
  font-family: Inter, ui-sans-serif, sans-serif;
  font-size: 0.55em;
  font-variant-numeric: tabular-nums;
  line-height: 1.35;
  margin: 0;
}
.battle-resources span { white-space: nowrap; }
.battle-resource-side {
  display: grid;
  grid-template-columns: 1.6em auto 1.6em auto;
  align-items: center;
  column-gap: .5em;
}
.battle-resource-side img { width: 1.6em; height: 1.2em; object-fit: contain; flex: none; }
.battle-resource-side strong { font-weight: 600; text-align: right; }
/* Screen-specific keyboard instructions, tucked behind a bottom-right badge. */
.keyboard-help {
  position: fixed;
  right: max(10px, env(safe-area-inset-right));
  bottom: max(10px, env(safe-area-inset-bottom));
  z-index: 60;
}
#gameScreen:has(#battleScreen:not([hidden])) > .keyboard-help { display: none; }
.keyboard-help-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid #a89970;
  border-radius: 50%;
  color: #f4e7c3;
  background: #172536;
  box-shadow: 0 3px 12px #0007, inset 0 1px 0 #ffffff15;
  cursor: pointer;
}
.keyboard-help-button span {
  font: italic bold 23px / 1 Georgia, serif;
}
.keyboard-help-button:hover,
.keyboard-help-button[aria-expanded="true"] { background: #29435b; }
.keyboard-help-button:focus-visible {
  outline: 3px solid #a8d8ff;
  outline-offset: 3px;
}
.keyboard-help-tooltip {
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px);
  width: max-content;
  max-width: min(360px, calc(100vw - 32px));
  padding: 12px 16px;
  border: 1px solid #a89970;
  border-radius: 10px;
  color: #edf3fa;
  background: #172536;
  box-shadow: 0 6px 24px #0007;
  font: 14px / 1.65 Inter, ui-sans-serif, sans-serif;
}
.keyboard-help-tooltip[hidden] { display: none; }
/* Keep the tooltip hoverable when crossing the small gap above its badge. */
.keyboard-help-tooltip::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: -9px;
  width: 44px;
  height: 9px;
}
.scenario-button:focus-visible,
.family-card:focus-visible,
.primary-button:focus-visible,
.ghost-button:focus-visible {
  outline: 3px solid #a8d8ff;
  outline-offset: 3px;
  box-shadow: 0 0 0 6px rgba(68, 146, 220, .18);
}
@media (max-width: 900px) {
  .battle-header { gap: 0.4em; padding: 0.4em 0.6em; font-size: calc(var(--game-text) * .85); }
  .battle-lord-portrait { width: 52px; height: 52px; }
  .battle-resources { font-size: 0.6em; }
}

/* "14( 2)": food, then days left, padded as on Genesis. */
.battle-food {
  white-space: pre;
  font-variant-numeric: tabular-nums;
}

.battle-day-head {
  justify-items: center;
  gap: .25em;
  padding: 0 .4em;
}

.battle-day-line {
  display: flex;
  align-items: center;
  gap: 0.5em;
}

/* Time of day: dawn, day, sunset, night (the Genesis sky icon). */
.phase-icon {
  position: relative;
  width: 2em;
  height: 1.25em;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 3px;
}

.phase-icon::after {
  content: "";
  position: absolute;
  width: 0.6em;
  height: 0.6em;
  border-radius: 50%;
}

.phase-icon.phase-dawn { background: linear-gradient(#5b4b9a, #e98fb0 70%, #3f8a3a 70%); }
.phase-icon.phase-dawn::after { left: 0.3em; bottom: 0.2em; background: #ffd36b; }
.phase-icon.phase-day { background: linear-gradient(#7fa7ff, #d3e2ff 70%, #3f8a3a 70%); }
.phase-icon.phase-day::after { right: 0.35em; top: 0.15em; background: #fff6c9; }
.phase-icon.phase-sunset { background: linear-gradient(#b3261a, #f39a2d 70%, #5a3a12 70%); }
.phase-icon.phase-sunset::after { right: 0.3em; bottom: 0.2em; background: #ffcf4a; }
.phase-icon.phase-night { background: linear-gradient(#060b2c, #1b2b6a 70%, #102410 70%); }
.phase-icon.phase-night::after { right: 0.4em; top: 0.15em; background: #e8ecff; box-shadow: -0.12em -0.05em 0 0 #1b2b6a inset; }

.battle-province {
  color: var(--gold-soft);
  font-weight: 700;
}
.battle-day-line { font-size: .8em; }

.battle-body {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: clamp(8px, 1.2vh, 20px);
  min-height: 0;
}

/* Units 1-5 down each edge: number, figure, strength (survivors only). */
.battle-roster {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: clamp(6px, 1.2vh, 22px);
  margin: 0;
  padding: 0.6em 0.8em;
  list-style: none;
  border: 1px solid var(--panel-edge);
  border-radius: var(--panel-radius);
  background: var(--panel-bg);
}

.roster-unit {
  display: grid;
  grid-template-columns: auto auto;
  grid-template-rows: auto auto;
  align-items: center;
  column-gap: 0.3em;
  font-family: var(--display-font);
}

.roster-number {
  grid-row: 1 / 3;
  font-size: calc(var(--game-text) * 1.5);
  font-weight: 700;
}

.roster-figure {
  width: calc(var(--game-text) * 2.6);
  height: calc(var(--game-text) * 2.6);
}

.roster-count {
  justify-self: center;
  padding: 0 5px;
  border: 1px solid #8b8171;
  border-radius: 999px;
  background: #252b2f;
  color: #fff4de;
  line-height: 1.15;
  font-size: calc(var(--game-text) * 0.95);
  font-variant-numeric: tabular-nums;
}
.side-attacker .roster-count { border-color: #bb796e; }
.side-defender .roster-count { border-color: #728fb8; }

/* Desktop frames keep shared top/bottom edges and five stable unit slots. */
@media (min-width: 761px) {
  .battle-roster {
    display: grid;
    grid-template-rows: repeat(5, minmax(0, 1fr));
    align-self: stretch;
    min-height: 0;
    gap: 0;
  }
  .battle-roster .roster-unit { align-content: center; }
}

.roster-unit.side-attacker .roster-number { color: #ff9a8a; }
.roster-unit.side-defender .roster-number { color: #9cc4ff; }

/* Fit the narrow board and both rosters as one centred group, not three
   viewport-height rows. Container height also keeps short landscape views usable. */
@media (max-width: 760px) {
  .battle-header {
    font-size: clamp(12px, 3.2vw, 22px);
    gap: .25em;
    padding: .6em .45em;
  }
  .battle-lord-line { gap: .3em; }
  .battle-lord-portrait { width: clamp(36px, 9vw, 56px); height: clamp(36px, 9vw, 56px); }
  .battle-lord { overflow-wrap: anywhere; }
  .battle-food { font-size: .9em; }
  .battle-resources { font-size: max(9px, .65em); }
  .battle-resource-side { column-gap: .25em; }
  .battle-day-head { padding: 0 .2em; }
  .battle-day-line { gap: .3em; }
  .battle-body {
    --roster-height: 96px;
    --defender-gap: 22px;
    --field-width: min(100cqw, calc((100cqh - 2 * var(--roster-height) - 12px - var(--defender-gap)) * 10 / 7.5));
    container-type: size;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: repeat(3, max-content);
    align-content: center;
    gap: 6px;
  }
  .battle-roster {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 10px;
    min-width: 0;
    width: 100cqw;
    height: var(--roster-height);
    justify-self: center;
    padding: 10px 4px;
  }
  .battle-roster.side-attacker { grid-row: 1; }
  .battle-body .battle-field-area {
    grid-row: 2;
    min-width: 0;
    width: var(--field-width);
    aspect-ratio: 10 / 7.5;
    justify-self: center;
  }
  .battle-field-area .battle-board {
    width: calc(100cqw - 36px);
    transform: translateY(-3cqw) rotateX(var(--board-tilt));
  }
  .battle-roster.side-defender {
    grid-row: 3;
    margin-top: var(--defender-gap);
  }
  .roster-unit {
    grid-template-columns: auto auto;
    grid-template-rows: auto auto;
    justify-content: center;
    column-gap: 1px;
    row-gap: 1px;
    min-width: 0;
  }
  .roster-number { grid-row: 1; font-size: clamp(11px, 2.8vw, 16px); }
  .roster-figure {
    width: clamp(36px, 7.5vw, 48px);
    height: clamp(36px, 7.5vw, 48px);
    max-width: 100%;
    justify-self: start;
  }
  .roster-count {
    grid-column: 1 / 3;
    font-size: clamp(11px, 2.8vw, 14px);
  }
}

/* Reclaim spare message-panel height on small phones before shrinking the board. */
@media (max-width: 760px) and (max-height: 650px) {
  .battle-screen { --message-bar-height: 100px; }
}

/* Short phones in landscape still reserve a usable field between the rosters. */
@media (max-width: 760px) and (max-height: 500px) {
  .battle-screen { --message-bar-height: 60px; }
  .battle-header { font-size: 14px; padding: .4em .6em; }
  .battle-lord-portrait { width: 36px; height: 36px; }
  .battle-body { --roster-height: 60px; }
  .battle-roster .roster-unit {
    grid-template-columns: auto auto auto;
    grid-template-rows: auto;
  }
  .battle-roster .roster-count { grid-column: 3; grid-row: 1; }
  .battle-roster .roster-number,
  .battle-roster .roster-count { font-size: 12px; }
  .battle-roster .roster-figure { width: 32px; height: 32px; }
  .battle-message { padding: 4px .8em; gap: 4px; font-size: 16px; }
}

/* X68000 Side A pieces, 12 frames x 3 rows of 40px cells. */
.piece {
  display: block;
  background-image: var(--piece-sheet);
  background-repeat: no-repeat;
  background-size: 1200% 300%;
  background-position: calc(var(--frame) * 100% / 11) calc(var(--row) * 50%);
  image-rendering: pixelated;
}

.battle-field-area {
  --board-tilt: 30deg;
  position: relative;
  container-type: size;
  display: grid;
  place-items: center;
  min-height: 0;
  perspective: clamp(800px, 160vw, 4800px);
}

/* Only the board tilts. Cut-ins and settlement cards remain flat and readable.
   Preserve the 3D chain so pieces can face the viewer above the terrain plane. */
.battle-board {
  --marble:
    repeating-linear-gradient(163deg, transparent 0 17px, #b5bcb533 18px, #e6e4cc80 19px, transparent 21px 43px),
    repeating-conic-gradient(from 27deg at 36% 64%, #14252d 0deg 9deg, #354b50 11deg 16deg, #1c3239 19deg 32deg);
  position: relative;
  /* Mobile overrides this width; desktop leaves another 2% beside the board. */
  width: calc(min(calc(100cqw - 36px), calc((100cqh - 32px) * 10 / 8)) * .98);
  aspect-ratio: 10 / 8;
  padding: 8px;
  border: 1px solid #c1a664;
  border-radius: 8px;
  background: var(--marble);
  pointer-events: none;
  transform: rotateX(var(--board-tilt));
  transform-style: preserve-3d;
}
.battle-board::before,
.battle-board::after,
.battle-board-edge {
  content: "";
  position: absolute;
  pointer-events: none;
  background: var(--marble);
  border: 1px solid #b49d65;
}
.battle-board::before {
  inset: -1px;
  border-radius: 8px;
  transform: translateZ(-28px);
  box-shadow: 0 22px 32px #0009, 0 40px 65px #0006;
}
.battle-board::after {
  top: 100%;
  left: -1px;
  right: -1px;
  height: 28px;
  transform-origin: center top;
  transform: rotateX(-90deg);
  box-shadow: inset 0 4px 3px #ffffff12, inset 0 -5px 5px #0008;
}
.battle-board-edge {
  top: -1px;
  height: calc(100% + 2px);
  width: 28px;
  transform-origin: left center;
  transform: rotateY(90deg);
}
.battle-board-edge.edge-left { left: -1px; }
.battle-board-edge.edge-right { left: 100%; }

/* The 10 × 8 tactical field: painted terrain, tinted by time of day. */
.battle-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  height: 100%;
  border: 2px solid var(--gold);
  border-radius: 6px;
  box-shadow: 0 0 0 1px #0a1824;
  position: relative;
  pointer-events: none;
  transform-style: preserve-3d;
  --tod: none;
}

/* Terrain is drawn procedurally by battle-terrain.js. Pieces stay untinted. */
.battle-grid.phase-dawn { --tod: brightness(0.72) saturate(0.85) hue-rotate(-8deg); }
.battle-grid.phase-sunset { --tod: sepia(0.28) saturate(1.1) brightness(0.9); }
.battle-grid.phase-night { --tod: brightness(0.5) saturate(0.7) hue-rotate(18deg); }
.battle-terrain-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  border-radius: inherit;
  pointer-events: none;
  filter: var(--tod);
  transition: filter 0.6s ease;
}
.battle-cell {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  cursor: pointer;
  pointer-events: auto;
  /* Separate the hit plane from the coplanar terrain/board surfaces. */
  transform: translateZ(1px);
  transform-style: preserve-3d;
}

/* A separate child keeps the flag visible beneath cursor corners and occupied pieces. */
.battle-flag {
  position: absolute;
  inset: 6% 10% 8% 22%;
  pointer-events: none;
  z-index: 1;
  --flag-light: #9bcdff;
  --flag-mid: #3487e4;
  --flag-dark: #10427e;
  filter: drop-shadow(0 1px 1px #091526);
}
.battle-cell.flag-attacker .battle-flag {
  --flag-light: #ffc0a4;
  --flag-mid: #e55539;
  --flag-dark: #8b261e;
}
.battle-flag::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  width: 7%;
  height: 100%;
  border: 1px solid #172139;
  border-radius: 2px;
  background: linear-gradient(90deg, #866943, #f9df8b 48%, #ac884d);
  box-shadow: 0 1px 0 #fff0bb;
}
.battle-flag::after {
  content: "";
  position: absolute;
  left: 8%;
  top: 5%;
  width: 84%;
  height: 49%;
  border: 1px solid #e9e4c2;
  border-radius: 1px 4px 3px 1px;
  background:
    linear-gradient(100deg, transparent 15%, rgba(255,255,255,.24) 34%, rgba(8,20,35,.22) 49%, transparent 68%),
    linear-gradient(90deg, transparent 22%, #fff0ad 22% 29%, transparent 29%),
    linear-gradient(180deg, transparent 39%, #fff0ad 39% 51%, transparent 51%),
    linear-gradient(115deg, var(--flag-light), var(--flag-mid) 45%, var(--flag-dark));
  box-shadow: 0 0 0 1px #12233f, inset 0 1px 0 #e7f1ff;
  background-size: 220% 100%, 100% 100%, 100% 100%, 100% 100%;
  transform-origin: left center;
  animation: battle-flag-flow 2.8s ease-in-out infinite;
}
/* The hoist stays fixed; a travelling fold lifts and dips the free edge. */
@keyframes battle-flag-flow {
  0%, 100% {
    clip-path: polygon(0 0, 25% 3%, 50% 0, 75% 5%, 100% 10%, 100% 96%, 75% 91%, 50% 94%, 25% 97%, 0 100%);
    transform: skewY(-3deg) scaleX(1);
    background-position: 100% 0, 0 0, 0 0, 0 0;
  }
  33% {
    clip-path: polygon(0 0, 25% 0, 50% 6%, 75% 10%, 100% 3%, 100% 89%, 75% 98%, 50% 100%, 25% 94%, 0 100%);
    transform: skewY(1deg) scaleX(.96);
    background-position: 50% 0, 0 0, 0 0, 0 0;
  }
  66% {
    clip-path: polygon(0 0, 25% 5%, 50% 9%, 75% 2%, 100% 0, 100% 91%, 75% 94%, 50% 99%, 25% 100%, 0 100%);
    transform: skewY(-5deg) scaleX(.98);
    background-position: 0 0, 0 0, 0 0, 0 0;
  }
}
.battle-cell.flag-attacker .battle-flag::after { animation-delay: -.9s; }
@media (prefers-reduced-motion: reduce) {
  .battle-flag::after {
    animation: none;
    transform: skewY(-3deg);
    clip-path: polygon(0 0, 50% 2%, 100% 8%, 100% 96%, 50% 94%, 0 100%);
  }
}

.battle-cell.is-pick {
  box-shadow: inset 0 0 0 2px rgba(255, 225, 154, 0.55);
}

/* The Genesis cursor: four white corners around the cell, blinking. */
.battle-cell.is-cursor::after {
  content: "";
  position: absolute;
  inset: 4%;
  z-index: 2;
  background:
    linear-gradient(#fff, #fff) top left / 30% 3px no-repeat,
    linear-gradient(#fff, #fff) top left / 3px 30% no-repeat,
    linear-gradient(#fff, #fff) top right / 30% 3px no-repeat,
    linear-gradient(#fff, #fff) top right / 3px 30% no-repeat,
    linear-gradient(#fff, #fff) bottom left / 30% 3px no-repeat,
    linear-gradient(#fff, #fff) bottom left / 3px 30% no-repeat,
    linear-gradient(#fff, #fff) bottom right / 30% 3px no-repeat,
    linear-gradient(#fff, #fff) bottom right / 3px 30% no-repeat;
  animation: cursor-blink 266.67ms linear infinite;
  pointer-events: none;
}

.unit-token {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 92%;
  height: 92%;
  transform-style: preserve-3d;
  pointer-events: none;
}
/* A ground-plane contact shadow travels with the unit, including each walk step. */
.unit-token::before {
  content: "";
  position: absolute;
  left: 19%;
  bottom: 8%;
  width: 64%;
  height: 19%;
  border-radius: 50%;
  background: radial-gradient(ellipse, #041009a6, #04100955 45%, transparent 72%);
  pointer-events: none;
}
/* Counter-tilt around the feet rather than flattening the pieces onto the board.
   The token itself remains free to run the existing cell-by-cell walk animation. */
.unit-token .piece {
  width: 100%;
  height: 100%;
  transform-origin: 50% 85%;
  transform: translateZ(3px) rotateX(calc(-1 * var(--board-tilt)));
  filter: drop-shadow(1px 2px 1px #02090870);
}

.unit-token.is-departing { animation: piece-depart 300ms linear both; }
@keyframes piece-depart { from { opacity: 1; } to { opacity: 0; } }

.unit-token.is-moving {
  animation: cursor-blink 266.67ms linear infinite;
}

/* Genesis walk (research/captures/genesis/battle/walk/): one cell in 24 frames, the
   piece alternating its stride pose (frame + 4) and facing pose every 6 frames.
   The token is 92% of its cell, so one cell is 100% / 0.92 of the token. */
.unit-token.is-walking {
  z-index: 3;
  animation: piece-slide 400ms linear both;
  animation-delay: var(--walk-delay, 0ms);
}

.unit-token.is-walking .piece {
  animation: piece-stride 200ms steps(1, end) infinite;
  animation-delay: var(--walk-delay, 0ms);
}

@keyframes piece-slide {
  from { transform: translate(calc(var(--walk-x) * 108.7%), calc(var(--walk-y) * 108.7%)); }
  to { transform: translate(0, 0); }
}

@keyframes piece-stride {
  0% { background-position-x: calc((var(--frame) + 4) * 100% / 11); }
  50% { background-position-x: calc(var(--frame) * 100% / 11); }
}

.battle-message {
  height: var(--message-bar-height);
  min-height: 0;
}

.sub-message.options-grid {
  display: grid;
  grid-template-columns: repeat(2, max-content);
  gap: 0.2em 4em;
}

/* ---------------------------------------------------------------------------
   Combat cut-in (ACT-0040): covers the field. The unit being hit is on the
   left, the one acting on the right; the sky follows the time of day.
   --------------------------------------------------------------------------- */
.cutin {
  position: absolute;
  inset: 0;
  z-index: 5;
  overflow: hidden;
  /* The Genesis layer inside sizes itself from this box (see .cutin-actors). */
  container-type: size;
  border: 2px solid var(--gold);
  border-radius: 6px;
  background: #050505;
  animation: cutin-in 250ms ease-out;
}

@keyframes cutin-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Genesis bands: sky y 0-95, stage 96-191, ground 192-223 of the 256 x 224 layer
   (.cutin-actors). In a tall window the layer is shorter than the box, so the sky
   grows to meet the layer's stage and the ground takes the rest. */
.cutin-bands {
  --scene-h: min(100cqh, 100cqw * 224 / 256);
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows:
    calc((100cqh - var(--scene-h)) / 2 + var(--scene-h) * 96 / 224)
    calc(var(--scene-h) * 96 / 224)
    1fr;
}

/* One complete landscape behind both animation and fallback unit layers.
   Stretch to the stage so the castle stays visible at every window ratio. */
.cutin-bands {
  background-image: var(--battle-background, url("assets/battle-bgs/noon.webp"));
  background-size: 100% 100%;
  background-position: center;
  background-repeat: no-repeat;
}

.cutin.phase-dawn {
  --battle-background: url("assets/battle-bgs/sunrise.webp");
}

.cutin.phase-day {
  --battle-background: url("assets/battle-bgs/noon.webp");
}

.cutin.phase-sunset {
  --battle-background: url("assets/battle-bgs/sunset.webp");
}

.cutin.phase-night {
  --battle-background: url("assets/battle-bgs/night.webp");
}

.cutin-field {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  align-items: center;
  padding: 0 6%;
}

.cutin-rank {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 2%;
  height: 80%;
  align-content: center;
}

.cutin-rank.left {
  grid-column: 1;
}

.cutin-rank.right {
  grid-column: 3;
}

.cutin-rank img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  animation: cutin-step 0.6s ease-in-out infinite alternate;
  animation-delay: calc(var(--i) * -0.12s);
}

.cutin-rank.single {
  grid-template-columns: 1fr;
}

.cutin-rank.single .cutin-piece {
  width: 70%;
  justify-self: center;
}

/* Each side faces the other. */
.cutin-rank.right img {
  transform: scaleX(-1);
}

@keyframes cutin-step {
  from { translate: 0 0; }
  to { translate: 0 -4%; }
}

.cutin-effect {
  grid-column: 2;
  grid-row: 1;
  justify-self: center;
  width: 100%;
  aspect-ratio: 128 / 72;
  background-image: var(--effect-sheet);
  background-size: 800% 100%;
  background-repeat: no-repeat;
  animation: effect-frames 0.7s steps(7, jump-none) infinite;
  transform: scaleX(-1);
}

@keyframes effect-frames {
  from { background-position: 0% 0; }
  to { background-position: 100% 0; }
}

/* The Genesis sheets (assets/battle-anims/) on a 256 x 224 layer: every size and
   position is in Genesis pixels, 1 px = 100cqw / 256, so the recorded feet and effect
   coordinates line up at any display size. */
/* Fits inside the cut-in either way round: a portrait window would otherwise make it
   wider than the box and clip the actor on the right. */
.cutin-actors {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(100cqw, 100cqh * 256 / 224);
  aspect-ratio: 256 / 224;
  translate: -50% -50%;
  container-type: size;
  pointer-events: none;
}

.anim-shadow,
.anim-shield,
.anim-figure,
.anim-effect {
  --gp: calc(100cqw / 256);
  position: absolute;
  left: calc(var(--x) * var(--gp));
  top: calc(var(--y) * var(--gp));
  width: calc(var(--w) * var(--gp));
  height: calc(var(--h) * var(--gp));
  image-rendering: pixelated;
}

.anim-shadow {
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(0, 0, 0, .55), rgba(0, 0, 0, .2) 55%, transparent 75%);
  pointer-events: none;
}
.anim-figure.is-hit i {
  filter: brightness(.65) sepia(1) saturate(12) hue-rotate(325deg);
}
.anim-shield {
  border-radius: 50%;
  border: max(1px, calc(0.8 * var(--gp))) solid rgba(var(--shield-color), .9);
  background: radial-gradient(ellipse at 35% 25%, rgba(255,255,255,.25), rgba(var(--shield-color),.07) 45%, rgba(var(--shield-color),.35) 90%);
  box-shadow: inset 0 0 calc(5 * var(--gp)) rgba(var(--shield-color), .6), 0 0 calc(4 * var(--gp)) rgba(var(--shield-color), .6);
  pointer-events: none;
}

/* A formation is drawn as slices of its frame: top, the middle rank repeated, bottom. */
.anim-figure {
  display: flex;
  flex-direction: column;
}

.anim-column {
  position: absolute;
  display: flex;
  flex-direction: column;
  left: calc(var(--col-x) * var(--gp));
  top: calc(var(--col-y) * var(--gp));
  width: calc(var(--col-w) * var(--gp));
}

.anim-figure i,
.anim-effect {
  background-image: var(--sheet);
  background-repeat: no-repeat;
  background-size: calc(var(--sw) * var(--gp)) calc(var(--sh) * var(--gp));
  background-position: calc(var(--bx) * var(--gp) * -1) calc(var(--by) * var(--gp) * -1);
}

.anim-figure i {
  display: block;
  flex: none;
  width: 100%;
  height: calc(var(--h) * var(--gp));
}

/* A wizard's cast glyph (Catie's painted sheets): one cell of the grid, scaled down to a
   hand-sized circle beside the caster, glowing over the stage. */
.anim-glyph {
  --gp: calc(100cqw / 256);
  position: absolute;
  left: calc(var(--x) * var(--gp));
  top: calc(var(--y) * var(--gp));
  width: calc(var(--g) * var(--gp));
  height: calc(var(--g) * var(--gp));
  background-image: var(--sheet);
  background-repeat: no-repeat;
  background-size: calc(var(--cols) * var(--g) * var(--gp)) calc(var(--rows) * var(--g) * var(--gp));
  background-position: calc(var(--col) * var(--g) * var(--gp) * -1) calc(var(--row) * var(--g) * var(--gp) * -1);
  mix-blend-mode: screen;
  filter: drop-shadow(0 0 calc(2 * var(--gp)) rgba(255, 255, 255, 0.35));
}

/* Hit from the flank or the rear: the target faces away from the actor. */
.anim-figure.is-flipped {
  transform: scaleX(-1);
}

/* "Knights 33 VS Zendor 150", in a framed box across the top. */
.cutin-header {
  position: absolute;
  top: 4%;
  left: 50%;
  translate: -50% 0;
  display: flex;
  align-items: center;
  gap: 1.2em;
  padding: 0.35em 1.2em;
  border: 2px solid var(--gold-soft);
  border-radius: 8px;
  background: rgba(22, 30, 90, 0.92);
  font-family: var(--display-font);
  font-size: calc(var(--game-text) * 1.25);
  white-space: nowrap;
}

/* One side of the header: Catie's unit portrait outside the name and count. */
.cutin-side {
  display: flex;
  align-items: center;
  gap: 0.55em;
}

.cutin-face {
  width: 2.6em;
  height: 2.6em;
  object-fit: cover;
  border: 1px solid var(--gold-soft);
  border-radius: 4px;
}

.cutin-name {
  display: grid;
  justify-items: center;
  line-height: 1.1;
}

.cutin-name strong {
  font-variant-numeric: tabular-nums;
}

.cutin-name.side-attacker strong { color: #ffb0a0; }
.cutin-name.side-defender strong { color: #a8ccff; }

.cutin-vs {
  font-weight: 700;
  color: var(--gold-soft);
}

.cutin-box {
  position: absolute;
  padding: 0.5em 1em;
  border: 2px solid var(--gold-soft);
  border-radius: 8px;
  background: rgba(22, 30, 90, 0.94);
  font-family: var(--display-font);
  font-size: calc(var(--game-text) * 1.1);
  line-height: 1.25;
  text-align: center;
}

/* Centered assault notice before the fight. */
.cutin-label {
  left: 50%;
  top: 50%;
  translate: -50% -50%;
}

/* "The defender's 4th unit / was wiped out" over the field. */
.cutin-result {
  left: 50%;
  top: 60%;
  translate: -50% 0;
}

/* The ransom panel: the captured lord's face and stats above the demand. */
.aftermath {
  position: absolute;
  inset: 12% 22%;
  z-index: 6;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 0.6em;
  padding: 1.4em;
  border: 2px solid var(--gold);
  border-radius: 10px;
  background: rgba(10, 20, 60, 0.96);
  font-family: var(--display-font);
  font-size: calc(var(--game-text) * 1.2);
}

.aftermath-face {
  height: clamp(96px, 20vh, 360px);
  aspect-ratio: 40 / 48;
  object-fit: contain;
  image-rendering: pixelated;
}

.aftermath-name {
  font-weight: 700;
  color: var(--gold-soft);
}

.aftermath-stats {
  display: flex;
  gap: 1.6em;
  margin: 0;
}

.aftermath-stats div {
  display: grid;
  justify-items: center;
}

.aftermath-stats dt {
  font-size: 0.7em;
  color: var(--muted);
}

.aftermath-stats dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
}
/* The compact phone field cannot host the old viewport-sized captive portrait.
   This card stays flat and sizes to the field, independent of the board tilt. */
@media (max-width: 760px) {
  .aftermath {
    inset: max(6px, 2cqh) max(6px, 2cqw);
    padding: clamp(8px, 2cqh, 16px);
    gap: .4em;
    font-size: clamp(12px, 3.8cqw, 22px);
  }
  .aftermath-face { height: min(18vh, 27cqh); }
  .aftermath-stats { gap: 1em; }
}

@media (prefers-reduced-motion: reduce) {
  .map-marker.is-blinking,
  .map-list-row.is-current::before,
  .battle-cell.is-cursor::after,
  .unit-token.is-moving,
  .unit-token.is-walking,
  .unit-token.is-walking .piece,
  .cutin,
  .cutin-rank img,
  .cutin-effect {
    animation: none;
  }
}

/* ---------------------------------------------------------------------------
   Dialogs
   --------------------------------------------------------------------------- */
.dialog-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.land-icon img {
  width: 48px;
  height: 64px;
  object-fit: contain;
}

.intel-dialog {
  width: min(900px, 94vw);
  padding: 16px;
  border: 1px solid var(--line);
  color: var(--text);
  background: #1a1610;
}

.intel-table {
  width: 100%;
  margin-top: 12px;
  border-collapse: collapse;
  font-size: 13px;
}

.intel-table th,
.intel-table td {
  padding: 6px 8px;
  border-bottom: 1px solid rgba(255, 225, 154, 0.16);
  text-align: left;
}

.intel-subhead {
  margin-top: 16px;
  font-size: 14px;
  color: var(--gold-soft);
}

.event-log {
  max-height: 240px;
  margin: 8px 0 0;
  padding: 0;
  overflow: auto;
  list-style: none;
  font-size: 13px;
  color: var(--muted);
}

.event-log li {
  padding: 3px 0;
  border-bottom: 1px solid rgba(255, 225, 154, 0.08);
}

@media (max-width: 760px) {
  .menu-stage {
    grid-template-columns: 1fr;
  }

  .remaster-bar {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas: "logo title title" "crest done settings";
    gap: 8px;
    padding: 8px;
  }
  .remaster-logo { grid-area: logo; width: 85px; }
  .remaster-crest { grid-area: crest; justify-self: center; }
  .remaster-title { grid-area: title; }
  #endMonth { grid-area: done; justify-self: end; }
  .campaign-settings { grid-area: settings; }
}

/* Unrecorded sheets use the same grounded presentation during the short fallback. */
.cutin-piece { position: relative; display: block; }
.cutin-piece::before {
  content: "";
  position: absolute;
  left: 8%; right: 8%; bottom: 0;
  height: 12%;
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(0,0,0,.55), rgba(0,0,0,.2) 55%, transparent 75%);
}
.cutin-piece img { position: relative; }
.cutin-rank.takes-hit img {
  animation: cutin-step .6s ease-in-out infinite alternate, cutin-hit .25s .45s 2;
}
@keyframes cutin-hit {
  0%, 65% { filter: brightness(.65) sepia(1) saturate(12) hue-rotate(325deg); }
  66%, 100% { filter: none; }
}

/* Launch cards keep their natural height; smaller displays scroll the page. */
.screen-menu button:focus-visible,
.screen-boot button:focus-visible {
  outline: 2px solid var(--gold-soft);
  outline-offset: 4px;
}

@media (max-width: 1000px) {
  .family-card { grid-template-columns: 44px minmax(0, 1fr); padding: 14px; gap: 10px; }
  .family-card > img { width: 44px; height: 64px; }
  .family-card > span:not(.family-holdings) { grid-template-columns: 100px minmax(0, 1fr); gap: 5px 10px; }
  .family-leader { width: 100px; height: 128px; }
}

@media (max-width: 760px) {
  .menu-stage { width: min(520px, 100%); gap: 20px; }
  .menu-left, .family-stage { padding: 18px; }
  .menu-map-wrap { width: min(420px, 100%); justify-self: center; }
  .family-grid { grid-template-columns: 1fr; }
  .family-stage { width: min(580px, 100%); }
  .family-head { align-items: flex-start; }
  .family-head h1 { font-size: 22px; }
  .family-card > span:not(.family-holdings) { grid-template-columns: 112px minmax(0, 1fr); }
  .family-leader { width: 112px; height: 136px; }
  .boot-layout { padding: 24px; }
}

@media (max-width: 380px) {
  .scenario-button { grid-template-columns: 30px minmax(0, 1fr); gap: 8px; }
  .scenario-number { width: 28px; height: 32px; }
  .scenario-count { grid-column: 2; }
  .family-card { grid-template-columns: 32px minmax(0, 1fr); gap: 8px; padding: 10px; }
  .family-card > img { width: 32px; height: 48px; }
  .family-card > span:not(.family-holdings) { grid-template-columns: 88px minmax(0, 1fr); }
  .family-leader { width: 88px; height: 112px; }
}

/* Computer provinces act over the campaign map without resizing either panel. */
.map-area { position: relative; }
.campaign-turn-card {
  position: absolute;
  right: clamp(10px, 1.5vw, 24px);
  top: clamp(10px, 1.5vh, 24px);
  width: clamp(180px, 20vw, 320px);
  padding: clamp(10px, 1vw, 18px);
  border: 1px solid var(--gold-soft);
  border-radius: 8px;
  background: rgba(8, 21, 38, .96);
  box-shadow: 0 4px 18px rgba(0,0,0,.45);
  z-index: 8;
  pointer-events: none;
  font-size: clamp(12px, 1vw, 20px);
}
.campaign-turn-heading { display: flex; align-items: center; gap: 10px; }
.campaign-turn-heading > div { min-width: 0; display: grid; gap: 3px; }
.campaign-turn-heading strong { color: var(--gold-soft); }
.campaign-turn-portrait { width: clamp(48px, 5vw, 76px); height: clamp(48px, 5vw, 76px); object-fit: cover; flex: 0 0 auto; border-radius: 3px; }
.campaign-turn-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 16px; margin-top: 12px; }
.campaign-turn-stats > span { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.campaign-turn-stats img { width: 22px; height: 22px; object-fit: contain; }
.campaign-turn-stats b { min-width: 3ch; text-align: right; font-variant-numeric: tabular-nums; }
.map-marker.is-taking-turn { background: rgba(7, 18, 35, .85); box-shadow: 0 0 0 .25cqw #ffe19a, 0 0 1.6cqw #f2c15f; animation: marker-pulse .9s ease-in-out infinite; z-index: 4; }
.campaign-attack-crest { position: absolute; width: 1.875cqw; height: 2.5cqw; object-fit: contain; z-index: 7; pointer-events: none; transform: translate(-50%, -50%); filter: drop-shadow(0 0 .4cqw #ffe19a); animation: campaign-crest-attack 1.1s ease-in-out both; }
@keyframes campaign-crest-attack {
  0%, 45%, 100% { transform: translate(-50%, -50%); }
  22%, 72% { transform: translate(calc(-50% + var(--attack-dx)), calc(-50% + var(--attack-dy))); }
}
@media (max-width: 650px) {
  .campaign-turn-card { width: 165px; padding: 8px; font-size: 11px; }
  .campaign-turn-portrait { width: 40px; height: 40px; }
  .campaign-turn-stats { gap: 3px 10px; margin-top: 6px; }
  .campaign-turn-stats img { width: 17px; height: 17px; }
}
@media (prefers-reduced-motion: reduce) {
  .campaign-attack-crest { animation: none; }
  .map-marker.is-taking-turn { animation: none; }
}

.campaign-turn-card.at-bottom { top: auto; bottom: clamp(10px, 1.5vh, 24px); }

.campaign-attack-crest.defending { animation: none; }

/* Original disaster presentation; art and province-marker positions are unchanged. */
.disaster-map { position: absolute; inset: 0; z-index: 1; pointer-events: none; }
.disaster-map svg { display: block; width: 100%; height: 100%; overflow: hidden; }
.world-map > .map-marker { z-index: 2; }
.map-marker.is-disaster-hit { background: #231f27bb; box-shadow: 0 0 0 .18cqw #f5d799; }
.disaster-map .disaster-flame { transform-box: fill-box; transform-origin: center bottom; animation: disaster-flame 1.1s ease-in-out infinite alternate; }
.disaster-smoke { animation: disaster-smoke 3.4s ease-in-out infinite alternate; }
.disaster-ember { animation: disaster-ember 2.7s linear infinite; }
.disaster-rain { animation: disaster-rain .7s linear infinite; }
.disaster-waves { animation: disaster-waves 2s ease-in-out infinite alternate; }
.disaster-snowflake { animation: disaster-snow 3.8s linear infinite; }
.disaster-tremor { animation: disaster-tremor .8s ease-in-out infinite; }
.disaster-ring { transform-box: fill-box; transform-origin: center; animation: disaster-ring 2.5s ease-out infinite; }
.disaster-mist { animation: disaster-mist 4s ease-in-out infinite alternate; }
.disaster-spore { animation: disaster-spore 4.2s ease-in-out infinite alternate; }
@keyframes disaster-flame { to { transform: scale(.8, 1.2) skewX(6deg); } }
@keyframes disaster-smoke { to { transform: translate(4px, -8px); opacity: .25; } }
@keyframes disaster-ember { to { transform: translate(7px, -20px); opacity: 0; } }
@keyframes disaster-rain { to { transform: translate(-4px, 9px); opacity: .25; } }
@keyframes disaster-waves { to { transform: translate(3px, -2px); opacity: .45; } }
@keyframes disaster-snow { to { transform: translate(7px, 15px); opacity: .2; } }
@keyframes disaster-tremor { 25%, 75% { transform: translate(1px, 0); } 50% { transform: translate(-1px, 1px); } }
@keyframes disaster-ring { from { transform: scale(.65); opacity: .8; } to { transform: scale(1.3); opacity: 0; } }
@keyframes disaster-mist { to { transform: translate(5px, 3px); opacity: .3; } }
@keyframes disaster-spore { to { transform: translate(-3px, -5px); opacity: .3; } }
.disaster-summary { position: relative; font-size: clamp(12px, 1vw, 16px); text-align: left; }
.disaster-summary summary { cursor: pointer; padding: 5px 0; color: var(--gold-soft); }
.disaster-summary ul { position: absolute; bottom: 100%; left: 0; width: min(65vw, 680px); max-height: 35vh; overflow: auto; z-index: 15; margin: 0; padding: 12px 16px 12px 28px; background: #142236; border: 1px solid #b9a574; border-radius: 8px; color: #f4eee2; box-shadow: 0 4px 18px #0009; }
.disaster-summary li { padding: 4px 0; }
#subMessage:has(.disaster-summary) { display: flex; gap: 16px; align-items: center; justify-content: space-between; }
@media (prefers-reduced-motion: reduce) {
  .disaster-map * { animation: none !important; }
}

/* Four difficulty profiles keep the existing setup-card design. */
.setup-choices[data-stage="difficulty"] { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); }
.setup-choices[data-stage="difficulty"] .scenario-button { width:100%; min-width:0; }
@media(max-width:560px) { .setup-choices[data-stage="difficulty"] { grid-template-columns:1fr; } }

.setup-choices[data-stage="difficulty"] .scenario-button[aria-pressed="true"] { border-color:#dbc68b; box-shadow:0 0 0 1px #dbc68b; }
/* Gemfire Online uses the existing navy-and-gold game panels. */
[hidden] { display: none !important; }
.boot-logo { width: min(760px,100%); }
.boot-layout { width: min(940px,95vw); }
.account-summary,.account-hint { margin: 0; color: var(--muted); font-size: .9rem; text-align: center; }
.account-actions,.online-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.online-dialog { width: min(440px,90vw); color: var(--text); background: #121e35; border: 1px solid #ad8950; border-radius: 12px; padding: 28px; }
.online-dialog::backdrop { background: #020811cc; }
.online-dialog form,.lobby-create form { display: grid; gap: 16px; }
.online-dialog label,.lobby-stage label { display: grid; gap: 8px; color: #eedaaa; }
.online-dialog input,.lobby-stage input,.lobby-stage select { min-width: 0; width: 100%; box-sizing: border-box; padding: 10px 12px; border: 1px solid #79664a; border-radius: 7px; background: #091326; color: #f5e5c1; font: inherit; }
.online-dialog button { margin-top: 8px; }
.online-error { color: #ffbaa4; min-height: 1.4em; }
.profile-avatar { width: 96px; height: 96px; object-fit: cover; border-radius: 10px; margin: 0 auto 18px; }
.lobby-stage { width: min(1000px,94vw); margin: 20px auto; padding: 28px; box-sizing: border-box; background: #0d1930ed; border: 1px solid #ad8950; border-radius: 12px; }
.lobby-heading { display: flex; flex-wrap: wrap; align-items: center; gap: 28px; }
.lobby-heading .menu-logo { width: min(400px,100%); margin: 0; }
.pending-lobbies { display: grid; gap: 12px; margin: 20px 0; }
.pending-lobbies .scenario-button { display: grid; gap: 8px; }
.lobby-create { margin: 24px 0; border-top: 1px solid #79664a; padding-top: 20px; }
.lobby-slots { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 14px; margin: 20px 0; }
.lobby-slot { display: flex; align-items: center; gap: 14px; background: #152644; border: 1px solid #79664a; border-radius: 10px; padding: 14px; min-height: 98px; }
.lobby-slot p { margin: 5px 0; color: #d9c69d; }.lobby-slot small { color: #e9bc65; }
.slot-avatar { width: 64px; height: 64px; flex: 0 0 64px; border-radius: 8px; background: #091326; display: grid; place-items: center; font-size: 1.6rem; color: #e9bc65; overflow: hidden; }
.slot-avatar img { width: 100%; height: 100%; object-fit: cover; }.slot-crest { width: 54px; height: 68px; object-fit: contain; margin-left: auto; }
.house-picker { max-width: 380px; margin: 16px 0; }#hostControls { display: flex; gap: 14px; flex-wrap: wrap; align-items: end; }#hostControls label { min-width: 140px; }
.lobby-chat { margin: 24px 0; }.lobby-messages { height: 200px; overflow-y: auto; padding: 12px; border: 1px solid #79664a; border-radius: 8px; background: #091326; overflow-wrap: anywhere; }.lobby-messages p { margin: 8px 0; }.lobby-chat form { display: flex; gap: 12px; margin-top: 12px; }
.online-play-bar { position: fixed; z-index: 1500; bottom: 8px; left: 50%; transform: translateX(-50%); display: flex; gap: 18px; align-items: center; max-width: 96vw; padding: 8px 14px; border: 1px solid #e5b765; border-radius: 9px; color: #ffe4a9; background: #0b182cef; font-size: .85rem; }.online-play-bar.waiting { border-color: #766b57; }.online-play-bar button { padding: 6px 10px; white-space: nowrap; }
@media(max-width:650px) { .lobby-stage { padding: 18px; }.lobby-slots { grid-template-columns: 1fr; }.online-play-bar { gap: 8px; flex-wrap: wrap; width: 94vw; justify-content: center; }.slot-avatar { width: 48px; height: 48px; flex-basis: 48px; }.lobby-chat form { flex-wrap: wrap; } }

.global-mute-music { position: fixed; top: 12px; right: 16px; z-index: 1600; font-size: .85rem; background: #0d1930e8; }
