:root {
  color-scheme: light;
  --ink: #25333d;
  --edge: #c1baa8;
  --paper: #fff9eb;
  --gold: #ffd483;
  font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  color: var(--ink);
  background: #e8e4d6;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-height: 100vh;
  background-image: radial-gradient(ellipse at 12% 8%, #f9ead0 4%, transparent 64%),
    radial-gradient(ellipse at 94% 0%, #c8c8ce 0%, transparent 65%), repeating-linear-gradient(135deg, #7777860f 0 1px, transparent 1px 9px);
}
button { font: inherit; cursor: pointer; touch-action: manipulation; }
button:focus-visible { outline: 3px solid #0061b6; outline-offset: 2px; }
.masthead { background: linear-gradient(108deg, #373442, #181f2e 73%); color: var(--paper); border-bottom: 2px solid #b9a181; box-shadow: 0 3px 14px #25233632; }
.mast-inner, main { width: min(100% - 64px, 1000px); margin-inline: auto; }
.mast-inner { display: flex; align-items: center; justify-content: space-between; min-height: 64px; }
.brand { display: inline-flex; gap: 12px; align-items: center; font-size: 21px; font-weight: 900; letter-spacing: .035em; }
.brand-icon { width: 34px; height: 34px; display: grid; place-items: center; font: 27px/1 Georgia, serif; background: var(--gold); color: #30283b; border-radius: 4px; box-shadow: inset 0 0 0 2px #f5ba60; }
.help { display: flex; gap: 8px; align-items: center; min-height: 48px; padding: 0 8px; border: 0; background: transparent; color: #f4f4dc; font-size: 14px; font-weight: bold; }
.help span { display: grid; place-items: center; width: 17px; height: 17px; border: 1.5px solid currentColor; border-radius: 50%; font: bold 12px/1 monospace; }
main { padding: 30px 0 max(34px, env(safe-area-inset-bottom)); }
.panel-heading, .map-bar { display: flex; align-items: center; justify-content: space-between; }
.intro { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; grid-template-areas: "title sound turn" "save sound turn"; align-items: center; column-gap: 12px; margin-bottom: 20px; }
#mission-title { grid-area: title; }
.crossing-save-status { grid-area: save; margin-top: 2px; color: #335343; font-size: 12px; font-weight: 750; }
.crossing-save-status[data-error] { color: #803622; }
.sound-controls { display: flex; flex-wrap: wrap; gap: 5px; }
.intro > .sound-controls { grid-area: sound; justify-self: end; }
.sound-toggle { display: inline-grid; place-items: center; min-width: 48px; min-height: 48px; padding: 0 1px; border: 0; border-radius: 6px; background: transparent; color: var(--ink); }
.sound-switch { display: inline-flex; align-items: center; justify-content: center; gap: 4px; min-height: 26px; padding: 2px 6px; border-radius: 14px; border: 1px solid var(--edge); background: var(--paper); font-size: 12px; font-weight: bold; white-space: nowrap; }
.sound-switch b { min-width: 3ch; font: bold 11px Consolas, monospace; color: #53645a; }
.sound-toggle[aria-pressed="true"] .sound-switch { background: #dcece0; border-color: #779e87; }
.sound-toggle[aria-pressed="true"] b { color: #1e6149; }
.sound-toggle:disabled { cursor: default; opacity: .65; }
h1, h2, h3, p, dl, dd { margin: 0; }
h1 { font-size: clamp(28px, 3.6vw, 43px); font-weight: 900; letter-spacing: .025em; line-height: 1.28; }
h2 { font-size: 16px; font-weight: 850; }
.turn { grid-area: turn; background: #dbede5; border: 1px solid #78a298; border-left: 5px solid #28665d; border-radius: 5px; padding: 5px 10px; display: flex; gap: 8px; align-items: center; color: #193f37; box-shadow: 0 2px #b3c5b3; white-space: nowrap; }
.turn[data-side="enemy"] { background: #f8e1d4; border-color: #a06454; border-left-color: #964438; color: #642e25; box-shadow: 0 2px #d4b3a2; }
.turn[data-side="ended"] { background: #eee8d7; border-color: #9d9078; border-left-color: #7e715a; color: #584834; box-shadow: 0 2px #d3c6b1; }
.turn-count { display: inline-flex; align-items: center; gap: 4px; font-weight: 800; font-size: 12px; }
.turn-side { font-weight: 850; font-size: 14px; }
.turn strong, .dimensions, .letters, .numbers, dd { font-family: Consolas, "Courier New", monospace; }
.turn strong { font-size: 30px; line-height: 1.2; }
.layout { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(255px, 1fr); align-items: start; gap: 22px; }
.map-panel, .unit-panel, .orders { border-radius: 10px; overflow: hidden; box-shadow: 0 2px 0 #786c6140, 0 12px 24px #403b3c1c; }
.map-panel { background: #2a3744; border: 1px solid #222838; }
.map-bar { min-height: 44px; padding: 0 12px 0 18px; gap: 8px; background: linear-gradient(90deg,#35394b,#222c3c); color: var(--paper); border-bottom: 1px solid #8e826b; }
.map-bar-actions { display: flex; align-items: center; gap: 12px; }
#desktop-overview { min-width: 48px; min-height: 48px; padding: 4px 10px; border: 0; background: transparent; color: var(--paper); font-size: 13px; font-weight: 800; }
#desktop-overview:hover { color: var(--gold); }
#desktop-overview:focus-visible { outline-color: var(--gold); outline-offset: -4px; }
.map-icon { color: #efce8b; margin-right: 4px; }
.dimensions { font-weight: bold; font-size: 13px; color: #d5dfc3; }
.friendly-roster { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; padding: 6px 9px; background: #eeeadc; max-height: 156px; overflow-y: auto; }
.friendly-roster > .defeated { order: 1; }
.friendly-roster > * { display: flex; flex-wrap: wrap; align-content: center; align-items: baseline; gap: 0 6px; min-height: 48px; padding: 3px 6px; border: 1px solid #9ca99a; border-radius: 4px; background: var(--paper); color: var(--ink); text-align: left; }
.friendly-roster button[aria-pressed="true"] { background: #d5e9e4; border-color: #21565b; box-shadow: inset 0 0 0 1px #21565b; }
.friendly-roster button:disabled { opacity: .7; }
.friendly-roster strong { font-size: 13px; }
.friendly-roster span { font-size: 11px; white-space: nowrap; }
.friendly-roster span:last-child { width: 100%; color: #3f5955; }
.friendly-roster > [data-action="spent"] span:last-child { color: #665442; font-weight: bold; }
.friendly-roster > [data-action="deployed"] span:last-child { color: #424e77; font-weight: bold; }
.friendly-roster > [data-action="attack"] span:last-child { color: #782f28; font-weight: bold; }
.enemy-roster { background: #f0e2d3; border-bottom: 1px solid #c4ad94; }
.enemy-roster > div { border-color: #bc9788; background: #fff1e1; }
.enemy-roster span:last-child { color: #784334; }
.enemy-roster .enemy-acting { border-color: #934533; box-shadow: inset 0 0 0 1px #934533; background: #ffdfc2; }
.enemy-roster .defeated { opacity: .65; }
.map-surround { padding: 0 17px 14px 4px; max-height: clamp(294px, 62dvh, 676px); overflow: auto; scroll-padding: 22px 0 0 24px; }
.map-surround .chart { min-width: calc(var(--columns) * 48px + 24px); }
.map-scroll-note { padding: 6px 12px; color: #e0e8d3; font-size: 12px; }
.enemy-preview { display: grid; gap: 3px; min-height: 58px; padding: 5px 8px; border-bottom: 1px solid #956457; background: #432d35; color: #fff6e6; }
.enemy-preview-heading { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 0 6px; font-size: 13px; }
.enemy-preview-heading span { color: #f3d4be; font-size: 11px; font-weight: bold; }
.enemy-preview-choices { display: flex; flex-wrap: wrap; align-items: stretch; gap: 3px; margin: 0; padding: 0; list-style: none; }
.enemy-preview-choices li { display: flex; align-items: baseline; justify-content: center; flex-wrap: wrap; gap: 0 3px; min-width: 48px; padding: 2px 5px; border: 1px solid #ac7b72; border-radius: 4px; background: #5a4149; color: #fff4e4; font-size: 11px; font-weight: bold; }
.enemy-preview-choices small { color: #ebd7c6; font: bold 10px Consolas, monospace; }
.enemy-preview-choices [aria-current="true"] { border-color: #ffeaad; background: #ffd483; color: #33251c; }
.enemy-preview-choices [aria-current="true"] small { color: #5f4129; }
.enemy-preview[data-menu="production"] .enemy-preview-choices { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.enemy-preview[data-menu="production"] li { display: grid; justify-items: center; min-width: 0; padding-inline: 2px; }
.enemy-preview[data-stage="deploy"] .enemy-preview-heading span { color: #ffe096; }
@media (min-width: 721px) {
  .enemy-preview { position: fixed; z-index: 8; right: max(12px, env(safe-area-inset-right)); bottom: max(12px, env(safe-area-inset-bottom));
    width: min(360px, 32vw); border: 1px solid #956457; border-radius: 7px; box-shadow: 0 3px 16px #16162455; }
}
.chart { display: grid; grid-template-columns: 24px 1fr; grid-template-rows: 22px 1fr; }
.chart::before { content: ""; grid-area: 1 / 1; position: sticky; top: 0; left: 0; z-index: 4; background: #2a3744; }
.letters, .numbers { display: grid; font-size: 11px; color: #d4dfc6; align-items: center; text-align: center; }
.letters { grid-column: 2; grid-template-columns: repeat(var(--columns), 1fr); }
.map-surround .letters { position: sticky; top: 0; z-index: 3; background: #2a3744; }
.numbers { grid-column: 1; grid-row: 2; grid-template-rows: repeat(var(--rows), 1fr); }
.map-surround .numbers { position: sticky; left: 0; z-index: 1; background: #2a3744; }
.board { position: relative; grid-area: 2 / 2; display: grid; grid-template: repeat(var(--rows), 1fr) / repeat(var(--columns), 1fr); aspect-ratio: var(--columns) / var(--rows); isolation: isolate; background: #85a46d; image-rendering: pixelated; box-shadow: 0 0 0 1px #1b242f, 0 0 0 3px #9a9a82; }
.board::after { content: ""; position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 17px #22372a59; }
.tile { position: relative; padding: 0; min-width: 0; min-height: 0; border: 0; border-right: 1px solid #35583755; border-bottom: 1px solid #35583755; background: transparent; color: inherit; border-radius: 0; }
.tile { background-image: linear-gradient(var(--tile-tint, transparent), var(--tile-tint, transparent)), var(--facility-image, none), var(--terrain-image, none); background-size: 100% 100%; }
.tile[data-terrain="forest"], .forest-key { --terrain-image: url("./assets/terrain-forest.png?v=river-motion"); }
.tile[data-terrain="mountain"], .mountain-key { --terrain-image: url("./assets/terrain-mountain.png?v=river-motion"); }
.tile[data-terrain="plains"] { --terrain-image: url("./assets/terrain-crossing-plains.png?v=river-motion"); }
.tile[data-terrain="river"], .river-key { --terrain-image: url("./assets/terrain-river.png"); }
.tile[data-terrain="bridge"], .bridge-key { --terrain-image: url("./assets/terrain-bridge.png?v=river-motion"); }
.tile[data-terrain="marsh"], .marsh-key { --terrain-image: url("./assets/terrain-marsh.png"); }
.tile[data-terrain="sea"], .sea-key { --terrain-image: url("./assets/terrain-sea.png"); }
.tile[data-terrain="shoal"], .shoal-key { --terrain-image: url("./assets/terrain-shoal.png"); }
.tile[data-terrain="road"], .road-key { --terrain-image: url("./assets/terrain-road.png"); }
:is([data-base="friendly"], .friendly-base-key, [data-factory="friendly"], [data-city="friendly"], [data-facility-owner="friendly"]) { --facility-color: #234e60; }
:is([data-base="enemy"], .enemy-base-key, [data-factory="enemy"], [data-city="enemy"], [data-facility-owner="enemy"]) { --facility-color: #723b2a; }
:is([data-factory="neutral"], [data-city="neutral"], [data-facility-owner="neutral"]) { --facility-color: #5b5037; }
:is([data-base="friendly"], .friendly-base-key, [data-facility-kind="headquarters"][data-facility-owner="friendly"]) { --facility-image: url("./assets/headquarters-friendly.png?v=river-motion"); }
:is([data-base="enemy"], .enemy-base-key, [data-facility-kind="headquarters"][data-facility-owner="enemy"]) { --facility-image: url("./assets/headquarters-enemy.png?v=river-motion"); }
:is([data-factory="friendly"], [data-facility-kind="factory"][data-facility-owner="friendly"]) { --facility-image: url("./assets/factory-friendly.png?v=river-motion"); }
:is([data-factory="enemy"], [data-facility-kind="factory"][data-facility-owner="enemy"]) { --facility-image: url("./assets/factory-enemy.png?v=river-motion"); }
:is([data-factory="neutral"], [data-facility-kind="factory"][data-facility-owner="neutral"]) { --facility-image: url("./assets/factory-neutral.png"); }
:is([data-city="friendly"], [data-facility-kind="city"][data-facility-owner="friendly"]) { --facility-image: url("./assets/city-friendly.png?v=river-motion"); }
:is([data-city="enemy"], [data-facility-kind="city"][data-facility-owner="enemy"]) { --facility-image: url("./assets/city-enemy.png?v=river-motion"); }
:is([data-city="neutral"], [data-facility-kind="city"][data-facility-owner="neutral"]) { --facility-image: url("./assets/city-neutral.png?v=river-motion"); }
[data-facility-kind="port"][data-facility-owner="friendly"] { --facility-image: url("./assets/port-friendly.png"); }
[data-facility-kind="port"][data-facility-owner="enemy"] { --facility-image: url("./assets/port-enemy.png"); }
[data-facility-kind="port"][data-facility-owner="neutral"] { --facility-image: url("./assets/port-neutral.png"); }
[data-facility-kind="airfield"][data-facility-owner="friendly"] { --facility-image: url("./assets/airfield-friendly.png"); }
[data-facility-kind="airfield"][data-facility-owner="enemy"] { --facility-image: url("./assets/airfield-enemy.png"); }
[data-facility-kind="airfield"][data-facility-owner="neutral"] { --facility-image: url("./assets/airfield-neutral.png"); }
.tile.last-column { border-right: 0; }
.tile.last-row { border-bottom: 0; }
.tile img { position: absolute; z-index: 1; left: 50%; bottom: 10%; width: 68%; height: 83%; object-fit: contain; transform: translateX(-50%); image-rendering: pixelated; pointer-events: none; filter: drop-shadow(1px 2px 0 #1b282f60); }
.tile.occupied::before { content: ""; position: absolute; bottom: 9%; left: 24%; width: 52%; height: 17%; border: 2px solid #d3faff; border-radius: 50%; background: #22808b; box-shadow: 0 2px #264e38; }
.tile.enemy::before { content: ""; position: absolute; bottom: 9%; left: 21%; width: 58%; height: 16%; background: #994735; border: 2px solid #ffe4c1; transform: skew(-15deg); }
.tile.enemy::after { content: "敵"; position: absolute; top: 3%; right: 3%; z-index: 1; padding: 0 3px; background: #782f28; color: #fff4db; border: 1px solid #ffe4c1; font-size: clamp(10px, 1vw, 13px); font-weight: bold; line-height: 1.35; }
.tile.target { --tile-tint: #f8ab775e; box-shadow: inset 0 0 0 2px #ffeead, inset 0 0 0 4px #893a32; }
.tile.enemy-acting { box-shadow: inset 0 0 0 2px #ffe0a0, inset 0 0 0 4px #934533; }
.tile.enemy-route:not(.enemy-acting) { --tile-tint: #ed956c42; box-shadow: inset 0 0 0 1px #e0a072; }
.tile.enemy-destination:not(.enemy-acting) { --tile-tint: #ffcc774a; box-shadow: inset 0 0 0 2px #ffe3a7, inset 0 0 0 4px #98513c; }
.tile.enemy-spawned { box-shadow: inset 0 0 0 3px #ffe0a0, inset 0 0 0 5px #934533; }
@media (prefers-reduced-motion: no-preference) {
  .tile.enemy-spawned img { animation: enemy-deploy .3s ease-out; }
}
@keyframes enemy-deploy { from { opacity: .25; transform: translateX(-50%) scale(.7); } to { opacity: 1; transform: translateX(-50%); } }
.tile.target::after { content: "攻撃"; }
.tile.spent img { filter: saturate(.45); }
.unit-action { display: inline-grid; place-items: center; min-width: 17px; padding: 1px 3px; border: 1px solid #fbefda; border-radius: 3px; background: #4d4233; color: white; font-size: 11px; font-weight: 850; line-height: 1.2; white-space: nowrap; }
.tile .unit-action { position: absolute; top: 2px; left: 2px; z-index: 2; pointer-events: none; }
.unit-action[data-action="attack"] { background: #95382b; }
.unit-action[data-action="deployed"] { background: #424e77; }
.unit-action[data-action="acting"] { background: #ffe099; border-color: #6d4432; color: #532d22; }
.tile.active-unit:not(.selected) { box-shadow: inset 0 0 0 2px #d0ffff, inset 0 0 0 3px #245466; }
.tile.selected { box-shadow: inset 0 0 0 3px #ffe18a, inset 0 0 0 5px #6e4e2c; --tile-tint: #ffe07c42; }
.tile.reachable { --tile-tint: #b9f0dc65; box-shadow: inset 0 0 0 1px #1e5346, inset 0 0 0 2px #cce5b889; }
.tile.reachable::after, .range-key::after { content: ""; display: block; position: absolute; width: 13%; aspect-ratio: 1; top: 50%; left: 50%; transform: translate(-50%, -50%) rotate(45deg); border: 1px solid #e6ffda; background: #296d50; }
.tile.capture-target, .tile.captured-base { --tile-tint: #f4ce764f; box-shadow: inset 0 0 0 2px #fff0b1, inset 0 0 0 4px #694622; }
.tile.capture-target::after { content: "占領"; top: auto; bottom: 4%; width: auto; aspect-ratio: auto; padding: 1px 4px; transform: translateX(-50%); border-color: #fff0b1; background: #573a1d; color: #fff9dc; font-size: 10px; font-weight: bold; white-space: nowrap; }
.tile:focus-visible { z-index: 2; outline-offset: -4px; }
.tile.action-pending, [data-mobile-field] .tile.action-pending { outline: 3px solid #ffdd79; outline-offset: -4px; z-index: 2; }
.tile-production { position: absolute; right: 2px; bottom: 2px; padding: 0 2px; border: 1px solid #e4fff4;
  border-radius: 3px; background: #184c43; color: #f3fffc; font-size: 10px; font-weight: bold; line-height: 1.3; pointer-events: none; }
@media (hover: hover) { .tile:is(.occupied,.reachable,.target):hover { box-shadow: inset 0 0 0 3px #ffec89; } .help:hover { color: var(--gold); } }
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 5px 16px; background: #f5eedb; border-top: 1px solid #323a37; padding: 10px 18px; }
.legend span { display: inline-flex; gap: 7px; align-items: center; font-size: 12px; font-weight: bold; }
.base-legend { border-color: #a9a596; padding-block: 6px; }
.base-legend i { width: 19px; height: 19px; background: #9ba47c var(--facility-image) center / cover; image-rendering: pixelated; border: 1px solid var(--facility-color); border-radius: 2px; }
.base-legend b { font-family: Consolas, monospace; color: #463b2f; }
.city-economy { background: #ede7d6; border-top: 1px solid #a9a596; padding: 6px 9px; }
.economy-balances { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px; }
.economy-balances > div { padding: 3px 7px; border: 1px solid #93aea7; border-radius: 4px; background: #e1eee6; font-size: 12px; }
.economy-balances > div:last-child { background: #f5e3d3; border-color: #bc9788; }
.economy-balances strong { font: bold 15px Consolas, monospace; }
.economy-balances small { display: block; font-size: 11px; line-height: 1.35; }
.city-list { display: flex; gap: 6px; align-items: baseline; margin-top: 5px; font-size: 11px; }
.city-list > b { white-space: nowrap; }
.city-overview { display: flex; flex-wrap: wrap; gap: 3px; }
.city-overview span { padding: 1px 4px; border: 1px solid #c1bba9; border-radius: 3px; background: #fffaed; color: var(--facility-color); white-space: nowrap; font-weight: bold; }
.facility-healing { margin-top: 5px; color: #244d3a; font-size: 12px; font-weight: bold; }
.facility-healing:empty { margin-top: 0; }
.terrain-legend { background: #e8e4d2; border-top-color: #b0aa96; font-size: 12px; }
.terrain-legend i { width: 16px; height: 16px; background: var(--terrain-image) center / cover; image-rendering: pixelated; border: 1px solid #627459; }
.friendly-key, .enemy-key, .range-key { width: 13px; height: 13px; display: inline-block; }
.enemy-key { background: #994735; border: 2px solid #73372b; box-shadow: inset 0 0 0 1px #ffe4c1; transform: skew(-15deg); }
.friendly-key { background: #32868a; border: 2px solid #24535c; box-shadow: inset 0 0 0 2px #bceada; border-radius: 50%; }
.range-key { position: relative; background: #d4e9b6; border: 1px solid #357356; }
.range-key::after { width: 4px; border: 0; }
.sidebar { display: grid; gap: 16px; }
.unit-panel, .orders { background: var(--paper); border: 1px solid #b4bfa8; }
.panel-heading { padding: 12px 18px; border-bottom: 1px solid var(--edge); }
.state { display: inline-flex; align-items: center; gap: 6px; font-weight: 800; font-size: 12px; color: #295a41; background: #e2ecd5; border: 1px solid #bfceaf; border-radius: 4px; padding: 2px 8px; }
.state::before { content: ""; width: 6px; height: 6px; background: currentColor; }
.state.spent { background: #eee7d6; color: #63563c; }
.state.attack-ready { background: #f9e0cc; color: #782f28; border-color: #cf9a80; }
.portrait { height: clamp(100px, 12vw, 155px); background: #ccddb2 url("./assets/meadow.png?v=highland") center / cover; display: grid; place-items: end center; image-rendering: pixelated; }
.portrait img { height: 83%; margin-bottom: 4%; image-rendering: pixelated; }
.unit-details { padding: 14px 18px 18px; }
.unit-trait { margin-top: 4px; color: #58452e; font-size: 12px; font-weight: bold; }
h3 { font-size: 24px; font-weight: 900; }
dl { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border-top: 1px solid var(--edge); margin-top: 9px; padding-top: 12px; }
dl div + div { border-left: 1px solid var(--edge); padding-left: 7px; }
dt { font-size: 12px; color: #58634f; font-weight: bold; }
dd { font-weight: 850; font-size: 24px; }
dd span { font-family: sans-serif; font-size: 12px; }
#unit-terrain { font-family: inherit; font-size: 18px; line-height: 1.7; }
.orders { padding: 16px 18px 18px; }
.enemy-report { margin-top: 9px; border-left: 3px solid #a9583f; padding: 5px 8px; background: #faebd8; color: #633a2c; font-size: 13px; line-height: 1.5; white-space: pre-line; }
.orders .enemy-report { max-height: 9em; overflow-y: auto; }
.orders-actions button[aria-disabled="true"] { background: #eee4ca; border-color: #b0aa92; color: #5d604f; cursor: wait; }
.production-launch { display: none; }
.orders .replay.primary { background: var(--gold); border-color: #92651d; font-size: 16px; }
.orders p { font-size: 14px; line-height: 1.65; padding: 10px 0 16px; }
.orders .crossing-objective { padding: 7px 0 0; color: #53442b; font-weight: bold; }
.production { margin: 0 0 12px; padding: 9px; border: 1px solid #9ba99a; border-radius: 6px; background: #e7eee3; }
.production h3 { font-size: 14px; }
.production h3 b { margin-inline-start: 4px; font-family: Consolas, monospace; }
.production-heading { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px; }
.production-heading > span { font-size: 12px; white-space: nowrap; }
.factory-picker { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.factory-picker button { min-width: 56px; min-height: 48px; border: 1px solid #9ba99a; border-radius: 4px; background: #f4f2e7; color: #23413a; font: bold 14px Consolas, monospace; }
.factory-picker button[aria-pressed="true"] { background: #2d5a54; color: #fff9eb; border-color: #2d5a54; }
.production #production-status { padding: 4px 0 7px; font-size: 12px; line-height: 1.65; margin: 0; }
.production-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; }
.production-choices button { min-width: 48px; min-height: 48px; padding: 4px 2px; border: 1px solid #2d5a54; border-radius: 4px; background: #cfebe0; color: #203d37; font-size: 12px; font-weight: 800; }
.production-choices small { display: block; margin-top: 2px; font: bold 13px Consolas, monospace; }
.production-choices button[aria-disabled="true"] { background: #eae9e0; color: #5c655e; border-color: #aeb6a8; cursor: default; }
.orders .enemy-range { color: #633a2c; font-size: 12px; font-weight: bold; padding: 7px 0 0; }
.end { display: flex; justify-content: space-between; align-items: center; min-height: 48px; width: 100%; padding: 8px 18px; border: 1px solid #92651d; border-bottom-width: 3px; border-radius: 5px; background: var(--gold); color: #2f361f; font-weight: 850; font-size: 16px; }
.end:hover { background: #ffd578; }
.end:active { background: #efbb50; }
.end span[aria-hidden] { font-size: 23px; line-height: 1; }
#end[aria-disabled="true"] { justify-content: center; }
#end[aria-disabled="true"] span[aria-hidden] { display: none; }
.replay { margin-top: 8px; min-height: 48px; width: 100%; border: 1px solid var(--edge); border-radius: 5px; background: var(--paper); color: var(--ink); font-weight: bold; }
dialog { color: var(--ink); background: var(--paper); border: 2px solid var(--ink); border-radius: 8px; padding: 22px; max-width: min(420px, 90vw); max-height: 85dvh; }
dialog::backdrop { background: #132e24a8; }
dialog h2 { font-size: 22px; }
#guide h3 { margin: 10px 0 4px; font-size: 15px; }
#guide p { margin-bottom: 8px; }
.scenario-switch { display: grid; grid-template-columns: repeat(auto-fit, minmax(115px, 1fr)); gap: 6px; }
.scenario-switch:not(:has(button:not([hidden]))) { display: none; }
.scenario-switch button { margin: 4px 0 8px; padding-inline: 5px; }
dialog ol { padding-left: 1.5em; line-height: 1.7; }
dialog li + li { margin-top: 8px; }
dialog p { font-size: 13px; line-height: 1.65; margin-bottom: 16px; }
dialog .end { justify-content: center; }
.production-dialog, .action-dialog { width: min(420px, 100% - 24px); margin: auto auto max(12px, env(safe-area-inset-bottom)); padding: 14px; }
.action-dialog::backdrop { background: #15233755; }
.action-dialog h2 { font-size: 18px; }
.action-dialog p { margin: 4px 0; }
#action-summary { font-size: 15px; font-weight: bold; }
.order-dialog-buttons { display: flex; gap: 8px; margin-top: 10px; }
.order-dialog-buttons button { flex: 1; margin: 0; min-height: 48px; min-width: 48px; padding-inline: 4px; }
.production-dialog .production { margin: 0; padding: 0; border: 0; background: transparent; }
.turn-change { position: fixed; z-index: 20; top: 50%; left: 50%; translate: -50% -50%;
  width: min(270px, 85vw); display: grid; gap: 4px; padding: 14px 12px; pointer-events: none;
  text-align: center; border: 2px solid #8ad6c6; border-radius: 8px; background: #193d40; color: #f7fffb;
  box-shadow: 0 6px 22px #0d172e65; }
.turn-change[data-side="enemy"] { background: #543039; border-color: #fcc19b; color: #fff6eb; }
.turn-change span { font-size: 13px; font-weight: bold; }
.turn-change strong { font-size: clamp(22px, 7vw, 29px); line-height: 1.2; }
@media (prefers-reduced-motion: no-preference) {
  .turn-change:not([hidden]) { animation: turn-change-in .16s ease-out both; }
  @keyframes turn-change-in { from { opacity: 0; scale: .96; } }
}
.portrait-notice { width: min(370px, 90vw); padding: clamp(14px, 5dvh, 28px); color: #fff9eb; background: #273348; border-color: #aea182; text-align: center; box-shadow: 0 12px 32px #09162480; }
.portrait-notice::backdrop { background: #172234; }
.portrait-notice h2 { font-size: clamp(17px, 4.5dvh, 22px); }
.portrait-notice h2:focus { outline: none; }
.portrait-notice p { margin: 8px 0 0; color: #e3e2d6; }
.portrait-phone { position: relative; display: block; width: 25px; height: 40px; margin: 0 auto 11px; border: 2px solid #ffd483; border-radius: 5px; }
.portrait-phone::after { content: ""; position: absolute; bottom: 3px; left: 8px; width: 5px; height: 2px; border-radius: 2px; background: #ffd483; }
body:has(#portrait-notice[open]) { overflow: hidden; }
body:has(#portrait-notice[open]) > :is(header, main, dialog:not(#portrait-notice)) { visibility: hidden; }
body:has(#portrait-notice[open]) :is(#combat-screen, #combat-screen *, .tile.enemy-spawned img) { animation-play-state: paused; }
@media (min-width: 1100px) and (max-height: 820px) { main { padding-top: 22px; } }
@media (min-width: 1100px) {
  main, .mast-inner { width: min(100% - 64px, 1180px); }
  .layout { grid-template-columns: minmax(0, 1fr) minmax(270px, 29%); }
}
@media (max-width: 720px) {
  html:has(.orders-actions:not([hidden])) { --mobile-actions-height: calc(65px + env(safe-area-inset-bottom)); scroll-padding-block-end: var(--mobile-actions-height); }
  main, .mast-inner { width: min(100% - 24px, 510px); }
  main { padding-top: 16px; }
  main:has(.orders-actions:not([hidden])) { padding-bottom: calc(var(--mobile-actions-height) + 16px); }
  .mast-inner { min-height: 52px; }
  .brand { font-size: 16px; gap: 8px; }
  .brand-icon { width: 29px; height: 29px; font-size: 23px; }
  .intro { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "title turn" "save sound"; column-gap: 5px; margin-bottom: 12px; }
  .turn { padding: 4px 8px; gap: 6px; }
  .turn strong { font-size: 24px; }
  .layout { grid-template-columns: 1fr; gap: 12px; }
  .map-surround { padding: 0 10px 10px 0; }
  .chart { grid-template-columns: 20px 1fr; grid-template-rows: 18px 1fr; }
  .map-bar { min-height: 36px; padding: 0 12px; }
  .legend { padding: 7px 12px; }
  .sidebar { gap: 12px; }
  .orders { grid-row: 1; padding: 12px 14px; }
  .orders p { padding: 4px 0 10px; }
  .orders-actions { position: fixed; z-index: 10; inset-inline: 0; bottom: 0; display: grid; grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr); gap: 8px; padding: 8px max(12px, env(safe-area-inset-right), calc((100% - 510px) / 2))
      calc(8px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left), calc((100% - 510px) / 2));
    border-top: 1px solid #887d69; background: #252d40; box-shadow: 0 -4px 14px #13182532; }
  .orders-actions .end { min-width: 48px; padding-inline: 8px; justify-content: center; gap: 8px; }
  .production-launch { display: block; min-width: 48px; min-height: 48px; padding: 6px; border: 1px solid #2d5a54;
    border-bottom-width: 3px; border-radius: 5px; background: #cfebe0; color: #203d37; font-weight: 850; }
  .production-launch:not([aria-disabled="true"]):active { background: #b4dbce; }
  .portrait { height: 110px; }
}
@media (max-height: 480px) and (min-width: 640px) and (pointer: fine) {
  main, .mast-inner { width: min(100% - 32px, 850px); }
  .layout { grid-template-columns: minmax(0, 1.2fr) minmax(240px, 1fr); }
  main { padding-top: 12px; }
  .intro { margin-bottom: 10px; }
}
@supports (padding: max(0px)) {
  body { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
  .masthead { padding-top: env(safe-area-inset-top); }
}
