:root {
  color-scheme: light;
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", system-ui, sans-serif;
  color: var(--ink);
  background: #dde6e8;
  --ink: #202e30;
  --paper: #f6f9f9;
  --line: #c0ced0;
  --ink-light: #46595d;
  --green: #244f4c;
  --map-dark: #2c3c40;
}
* { box-sizing: border-box; }
html { overflow: hidden; overscroll-behavior: none; }
body {
  margin: 0; height: 100dvh; overflow: hidden;
  display: flex; flex-direction: column;
}
button, select, input { font: inherit; }
button, select {
  color: var(--ink); background: #fbfdfd; border: 1px solid #92a6aa;
  border-radius: 5px; padding: .42rem .65rem;
}
button { cursor: pointer; }
button:hover:not(:disabled) { background: #e6eff0; }
button:disabled { cursor: default; opacity: .5; }
button[aria-pressed="true"] { background: #d9eae8; border-color: #416d69; box-shadow: inset 0 0 0 1px #416d69; }
button:focus-visible, select:focus-visible, input:focus-visible, summary:focus-visible { outline: 3px solid #bb7909; outline-offset: 2px; }
h1, h2, h3, p { margin: 0; }
h3 { font-size: .92rem; margin: 1rem 0 .4rem; }
ul, ol { padding-left: 1.35rem; }
[hidden] { display: none !important; }
.masthead {
  flex: none;
  background: #203b3d; color: #f1f7f7; padding: 5px 12px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 5px 12px;
}
.masthead .map-controls { font-size: .82rem; }
.masthead h1 { font-size: clamp(1rem, 2.5vw, 1.45rem); letter-spacing: .035em; }
.game-version { margin-inline-start: .35em; color: #ffe592; font-size: .75em; white-space: nowrap; }
.header-actions { margin-inline-start: auto; display: flex; justify-content: end; flex-wrap: wrap; gap: .45rem; font-size: .82rem; }
.masthead button { color: #f1f7f7; background: #304f51; border-color: #80999a; }
.masthead button:hover:not(:disabled) { background: #426568; }
.game {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 355px);
  grid-template-rows: auto minmax(0, 1fr);
  column-gap: 12px; padding: 12px;
}
.game.command-hidden { grid-template-columns: minmax(0, 1fr); }
.map-panel, .command {
  background: var(--paper); border: 1px solid #9eb2b6; border-radius: 8px;
  display: flex; flex-direction: column; overflow: hidden; min-height: 0; min-width: 0;
}
.map-panel { grid-area: 2 / 1; position: relative; }
.command { grid-area: 2 / 2; overflow: auto; overscroll-behavior: contain; }
.command-toggle {
  position: absolute; z-index: 3; top: 50%; right: 16px; transform: translateY(-50%);
  width: 25px; height: 36px; padding: 0; color: #25464a; font-size: .75rem;
  box-shadow: 0 1px 4px #243c4355;
}
.phase-announcement {
  position: absolute; z-index: 2; top: 20%; left: 50%; transform: translateX(-50%);
  width: max-content; max-width: calc(100% - 24px); padding: .65rem 1.35rem;
  color: #f5faf9; background: #203b3df2; border: 1px solid #afc4c6;
  border-radius: 6px; box-shadow: 0 4px 18px #172e3578; text-align: center; pointer-events: none;
}
.phase-announcement span { display: block; font-size: clamp(.95rem, 2.1vw, 1.45rem); }
.phase-announcement strong { display: block; font-size: clamp(1.3rem, 3.3vw, 2.3rem); line-height: 1.25; }
.phase-announcement.ai-overview {
  top: 50%; transform: translate(-50%, -50%); padding: 1rem 1.4rem;
  background: #203b3d; pointer-events: auto;
}
.phase-announcement.ai-overview strong { font-size: clamp(1.65rem, 4.5vw, 3rem); }
#phase-overview-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: .6rem; margin-top: .8rem; }
#phase-overview-actions button {
  min-height: 44px; padding: .5rem .9rem;
  color: #f5faf9; background: #304f51; border-color: #93afb0;
  font-size: clamp(1rem, 2vw, 1.25rem); font-weight: 700;
}
#phase-overview-actions button:hover:not(:disabled) { background: #426568; }
#phase-overview-actions button.primary { color: #203b3d; background: #ffe592; border-color: #ffe592; }
#phase-overview-actions button.primary:hover:not(:disabled) { background: #fff0b8; }
#phase-overview-actions button:focus-visible { outline-color: #f5faf9; }
.map-toolbar, .map-legend {
  flex: none;
  display: flex; align-items: center; flex-wrap: wrap; justify-content: space-between; gap: .45rem .8rem;
  padding: 8px 10px; color: var(--ink-light); font-size: .76rem;
}
.map-controls { display: flex; align-items: center; flex-wrap: wrap; gap: .5rem; }
input[type="range"] { width: 85px; accent-color: var(--green); }
#zoom-value { min-width: 2.6em; }
#map-scroll { overflow: auto; overscroll-behavior: contain; flex: 1 1 0; min-height: 0; background: var(--map-dark); }
#board { display: block; width: 1604.8px; height: auto; }
#road-data { fill: none; stroke: #f51a25; stroke-width: 4; stroke-linecap: round; pointer-events: none; }
:is(.roads-visible, .rivers-visible, .terrains-visible, .cities-visible) :is(#routes, #marks, #counters) { visibility: hidden; }
:is(.roads-visible, .rivers-visible, .terrains-visible, .cities-visible) #hexes .hex { fill: transparent; stroke: none; filter: none; cursor: crosshair; }
.rivers-visible #hexes .hex[data-river] { fill: #4aabeb66; stroke: #1670ad; stroke-width: 2.5; }
.rivers-visible #hexes .hex[data-river="city"] { stroke-dasharray: 6 4; }
.cities-visible #hexes .hex[data-city] { fill: #e6192955; stroke: #be1528; stroke-width: 3; }
.cities-visible #hexes .hex[data-city="sudden"] { fill: #9a002ca8; stroke: #700020; stroke-width: 4; }
.cities-visible #hexes .hex[data-city="final"] { fill: #f7a02488; stroke: #a65000; stroke-width: 4; }
.terrains-visible #hexes .hex[data-relief="ridge"] { fill: #b2744166; stroke: #7b401c; stroke-width: 2.5; }
.terrains-visible #hexes .hex[data-relief="forest"] { fill: #50b95d66; stroke: #1f692b; stroke-width: 2.5; }
#map-coordinate {
  position: fixed; z-index: 3; padding: 3px 7px; border-radius: 4px;
  background: #203b3d; color: #fff; font: 700 .85rem system-ui, sans-serif; pointer-events: none;
}
.map-legend { justify-content: start; }
.chit-tray {
  --chit-size: 64px;
  --chit-gap: .35rem;
  grid-area: 1 / 1 / 2 / -1; display: flex; align-items: stretch; gap: var(--chit-gap); min-width: 0;
  overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain; margin-bottom: .35rem;
  padding: .45rem; border: 1px solid var(--line); border-radius: 8px; background: var(--paper);
}
.chit-tray:empty { display: none; }
#support-chits { --chit-size: 84px; }
.chit-tray .tile {
  flex: 0 0 calc((100% - 11 * var(--chit-gap)) / 12); min-width: 56px;
  justify-content: center; margin: 0; padding: 3px;
}
.chit-tray button[draggable="true"] { cursor: grab; }
.chit-tray .tile img { display: block; width: min(100%, var(--chit-size)); height: auto; aspect-ratio: 1; }
#support-chits figure { border: 1px solid var(--line); border-radius: 5px; }
.chit-held { position: relative; }
.chit-held::after {
  content: "保留"; position: absolute; inset: auto 3px 3px; padding: 0 .12rem;
  background: #203b3d; color: #fff; font-size: .66rem; line-height: 1.4;
}
.chit-detail {
  position: fixed; z-index: 5; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: min(560px, calc(100vw - 1.6rem)); max-height: calc(100dvh - 1.6rem);
  overflow: auto; padding: .75rem; background: var(--paper); color: #202e30;
  border: 1px solid #869fa3; border-radius: 8px; box-shadow: 0 8px 26px #1d281a55;
  font-size: 1.25rem; line-height: 1.55;
}
.chit-detail-heading { display: grid; grid-template-columns: 80px minmax(0, 1fr) auto; gap: .65rem; align-items: start; }
.chit-detail-heading img { width: 80px; height: 80px; object-fit: contain; }
.chit-detail-heading h2 { font-size: 1.45rem; line-height: 1.35; }
.chit-detail-heading p { margin: .25rem 0 0; font-size: 1.125rem; }
.chit-detail-heading button { font-size: .88rem; }
.chit-detail ul { margin: .55rem 0 0; }
.chit-detail li + li { margin-top: .25rem; }
#chit-detail-note { margin: .55rem 0 0; font-size: 1.125rem; }
.key::before {
  display: inline-block; width: .75em; height: .75em; margin-right: .35em;
  border-radius: 2px; border: 1px solid currentColor; content: "";
}
.key.legal::before { color: #247253; background: #9ed5b4; }
.key.stop::before { color: #975e00; background: #ffdd83; }
.key.support-movement::before { color: #a0001b; background: #ee3347; }
.key.planned::before { color: #c21c29; background: #c21c29; }
.key.reserved::before { color: #6a3194; border: 2px dashed currentColor; }
.key.target::before { color: #453f34; border-width: 2px; }
.hex { fill: transparent; stroke: transparent; cursor: crosshair; }
.hex.legal { fill: #72e09e82; stroke: #155f40; stroke-width: 2; }
.hex.stop { fill: #ffe26999; stroke: #795807; stroke-width: 2.2; }
.hex.target { fill: #ffc25099; stroke: #875100; stroke-width: 3; }
.hex.attacker { fill: #78bde49e; stroke: #1f597c; stroke-width: 3; }
.hex.off-road-forest { fill: #ed263394; stroke: #a50d1d; stroke-width: 3; }
.hex.support-movement { fill: #e5233bbd; stroke: #8c001b; stroke-width: 4; }
.hex.origin { stroke: #136683; stroke-width: 3; stroke-dasharray: 5 3; }
.hex.chosen, .hex:focus-visible, .hex:hover { stroke: #fffdf0; stroke-width: 3; outline: none; }
.hex.battle-group { fill: hsl(var(--battle-hue) 75% 58% / .66); stroke: hsl(var(--battle-hue) 75% 30%); stroke-width: 3; }
.hex.battle-group.target { stroke-width: 5; }
.hex.active-battle { stroke: #fff6d6; stroke-width: 6; filter: drop-shadow(0 0 3px #2a2821); }
.hex.support-placement { fill: #21b2ac59; stroke: #00635f; stroke-width: 5; }
#routes, #marks { pointer-events: none; }
.route { fill: none; stroke: #c21c29; stroke-width: 3.3; stroke-linejoin: round; marker-end: url(#move-arrow); }
.route.candidate { stroke-width: 5; }
.route.reviewed { stroke-width: 7; }
.route.reserved { stroke: #6a3194; stroke-width: 4; stroke-dasharray: 9 5; marker-end: url(#reservation-arrow); }
.route.order-draft { stroke-width: 6; }
.counter { cursor: pointer; }
.counter:focus-visible { outline: none; }
.counter .rim { fill: #fff5dd; stroke: #433e31; stroke-width: 2; }
.counter-support rect { fill: #fff5dd; stroke: #433e31; stroke-width: 1.3; }
.counter.planned .rim { stroke: #196483; stroke-width: 3.5; stroke-dasharray: 4 2; }
.counter.planned > image { filter: brightness(.58); }
.counter.reinforcement-draft .rim { stroke: #42efc0; stroke-width: 5; filter: drop-shadow(0 0 2px #163c36); }
.counter.selected .rim, .counter:focus-visible .rim { stroke: #ffd451; stroke-width: 4; stroke-dasharray: none; }
.counter.attack-ordered .rim { stroke: #935800; stroke-width: 3; }
.counter.recovery-target .rim { stroke: #ffe23e; stroke-width: 6; filter: drop-shadow(0 0 3px #2e2609); }
.counter.recovery-target.selected .rim { stroke: #fff9c4; stroke-dasharray: 7 3; }
.counter .count { fill: #222d25; stroke: #f6f9f9; stroke-width: 1.4; }
.counter text { fill: #fff; font: 600 11px system-ui, sans-serif; text-anchor: middle; pointer-events: none; }
.stack-overview {
  flex: 0 1 auto; min-height: 0; max-height: 28%; overflow: auto; padding: 9px 14px;
  border-bottom: 1px solid var(--line); font-size: .84rem;
}
.stack-heading { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.stack-heading button { flex: none; padding: .15rem .35rem; font-size: .72rem; }
.stack-pieces { display: flex; flex-wrap: wrap; gap: 8px; margin-top: .45rem; }
.stack-pieces figure { width: 62px; margin: 0; text-align: center; }
.stack-pieces img { display: block; width: 48px; height: 48px; margin: 0 auto .2rem; border: 1px solid #827e6c; }
.stack-pieces figcaption { font-size: .7rem; line-height: 1.3; overflow-wrap: anywhere; }
.phase-status {
  flex: none; display: flex; flex-wrap: wrap; align-items: baseline; gap: .2rem .65rem;
  color: #f5faf9;
  font-size: clamp(1rem, 1.8vw, 1.35rem); line-height: 1.25;
}
#turn { color: #ffe592; font-weight: 700; }
#actor { background: #424e55; padding: .08rem .38rem; border-radius: 4px; }
#actor.allied { background: #345f55; }
#phase-title { font-size: inherit; overflow-wrap: anywhere; }
.phase-guidance { flex: none; background: #e7eff0; padding: .55rem .8rem; border-bottom: 1px solid var(--line); }
.phase-guidance:has(#phase-detail:empty) { display: none; }
#phase-detail, .hint, .muted { font-size: .83rem; color: var(--ink-light); line-height: 1.52; }
.command-scroll { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 12px 14px; font-size: .86rem; }
#message { background: #e0ecea; border-radius: 4px; padding: .55rem .7rem; margin-bottom: .65rem; line-height: 1.5; }
#message.error { background: #fff0cd; color: #684200; }
.recovery-supply {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .4rem;
  margin: 0 0 .3rem;
}
.recovery-supply > div {
  padding: .4rem .25rem; text-align: center; border: 1px solid var(--line);
  border-radius: 5px; background: #edf3f4;
}
.recovery-supply > div:last-child { background: #d7e9e6; border-color: #a1bdb9; color: #244642; }
.recovery-supply dt { font-size: .82rem; font-weight: 700; }
.recovery-supply dd {
  margin: 0; font-size: 2.15rem; font-weight: 750; line-height: 1.08; font-variant-numeric: tabular-nums;
}
.recovery-cost { margin-bottom: .5rem; }
.actions { flex: none; display: grid; gap: .4rem; padding: 11px 14px; border-top: 1px solid var(--line); }
.actions:empty { display: none; }
#return-move { flex: none; margin: .4rem 14px 0; }
.support-warning {
  padding: .45rem .55rem; border-radius: 4px; background: #fff0cd; color: #684200;
  font-size: .85rem; line-height: 1.45;
}
button.primary { background: var(--green); border-color: var(--green); color: white; padding: .57rem .7rem; font-weight: 700; }
button.primary:hover:not(:disabled) { background: #356763; }
.controls { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; margin: .5rem 0; }
.controls label { display: flex; align-items: center; gap: .35rem; }
.counter .order-label { stroke: #482064; stroke-width: 3.5; paint-order: stroke; }
.orders { list-style: none; padding: 0; margin: .5rem 0; display: grid; gap: .36rem; }
.order { display: flex; gap: .35rem; align-items: stretch; }
.order button:first-child { flex: 1; text-align: start; }
.order small { display: block; color: var(--ink-light); margin-top: .12rem; }
.order button:not(:first-child) { padding-inline: .4rem; flex: none; }
.order button:first-child { min-width: 0; overflow-wrap: anywhere; }
.tile { display: inline-flex; align-items: center; gap: .35rem; }
.tile img { width: 28px; height: 28px; object-fit: contain; }
.compact { margin: .45rem 0; }
details { margin-top: .75rem; }
summary { cursor: pointer; font-weight: 650; }
#history { border-top: 1px solid var(--line); padding-top: .7rem; }
#log { font-size: .78rem; color: var(--ink-light); line-height: 1.55; margin-bottom: 0; }
#unit-info {
  flex: 0 1 auto; min-height: 0; max-height: 38%; overflow: auto; padding: 9px 14px;
  border-top: 1px solid var(--line); font-size: .86rem;
}
#unit-info .stack-pieces figure { width: 96px; max-width: 100%; }
#unit-info .stack-pieces img { width: 100%; height: auto; aspect-ratio: 1; object-fit: contain; }
#unit-info button { margin-top: .45rem; }
.result { padding: .55rem .65rem; margin-bottom: .65rem; border: 1px solid #a2b9ba; border-radius: 5px; background: #e6efed; line-height: 1.48; }
.result strong { color: #244642; }
.combat-overview { padding: .55rem .65rem; margin: .45rem 0; border: 1px solid var(--line); border-radius: 5px; background: #edf3f4; }
.combat-overview p, .result p { margin-top: .24rem; }
.combat-effects { margin: .4rem 0 0; }
.battle-result-armies { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; margin-top: .6rem; }
.battle-result-armies > section { min-width: 0; padding: .4rem; border: 1px solid var(--line); border-radius: 5px; }
.battle-result-armies h3 { margin: 0 0 .35rem; }
.battle-result-counters { display: flex; flex-wrap: wrap; gap: .45rem; }
.battle-result-counters figure { --counter-size: 56px; position: relative; width: var(--counter-size); margin: 0; text-align: center; }
#battle-overview .battle-result-counters figure { --counter-size: 80px; }
.battle-result-counters img { display: block; width: var(--counter-size); height: var(--counter-size); object-fit: contain; }
.battle-result-counters figcaption { font-size: .7rem; overflow-wrap: anywhere; }
.battle-result-cross { position: absolute; inset: 0 0 auto; height: var(--counter-size); display: grid; place-items: center; color: #cf1425; font: 800 var(--counter-size)/1 system-ui; text-shadow: 1px 1px #fff, -1px -1px #fff; pointer-events: none; }
.battle-result-unit { max-width: 100%; }
.battle-result-chits { display: flex; flex-wrap: wrap; gap: .25rem; margin-top: .25rem; }
#battle-overview .battle-result-chits figure, .battle-result-chits figure { --counter-size: 40px; }
.battle-result-chits .spent-chit img { opacity: .5; }
dialog {
  width: min(530px, calc(100vw - 25px)); max-height: 88dvh; padding: 20px;
  border: 1px solid #869fa3; border-radius: 8px; background: var(--paper); color: inherit;
  box-shadow: 0 10px 40px #1d281a55;
}
dialog::backdrop { background: #172c3696; }
dialog h2 { font-size: 1.12rem; }
#turn-start-dialog {
  width: min(680px, calc(100vw - 24px)); padding: 1.5rem; text-align: center;
  background: #203b3d; color: #f5faf9; border-color: #afc4c6;
}
#turn-start-title { font-size: clamp(2rem, 7vw, 4.75rem); line-height: 1.18; }
#begin-turn { margin-top: 1rem; min-height: 44px; padding-inline: 1.15rem; background: #ffe592; color: #203b3d; border-color: #ffe592; }
#begin-turn:hover:not(:disabled) { background: #fff0b8; }
#begin-turn:focus-visible { outline-color: #f5faf9; }

dialog p { margin: .65rem 0; }
dialog dl { font-size: .9rem; line-height: 1.55; }
dialog dt { font-weight: 700; margin-top: .55rem; }
dialog dd { margin-left: 0; }
.dialog-title { display: flex; align-items: center; justify-content: space-between; }
.game-mode-options { display: grid; gap: .5rem; margin-block: .9rem; }
.game-mode-options button { min-height: 44px; text-align: start; }
#battle-overview { width: min(890px, calc(100vw - 24px)); }
#battle-overview .dialog-title { gap: .65rem; }
#battle-overview .dialog-title button { white-space: nowrap; }
.battle-stage { margin-top: .65rem; }
.battle-armies { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .8rem; }
.battle-armies > section { padding: .6rem; border: 1px solid var(--line); border-radius: 5px; }
.battle-attack { background: #e9f3f8; }
.battle-defense { background: #fbefdb; }
.battle-armies h3 { margin-top: 0; }
.battle-unit { display: grid; grid-template-columns: minmax(0, 10rem) minmax(0, 1fr); align-items: start; gap: .5rem; }
.battle-unit + .battle-unit { margin-top: .7rem; padding-top: .7rem; border-top: 1px solid var(--line); }
.battle-unit-title { display: flex; align-items: center; gap: .5rem; }
.battle-unit-title > div { min-width: 0; overflow-wrap: anywhere; }
.battle-unit-title img { flex: none; width: 54px; height: 54px; object-fit: contain; }
.battle-unit-title p { margin: .12rem 0 0; }
.battle-chips { display: flex; align-items: flex-start; gap: .4rem; min-width: 0; overflow-x: auto; }
.battle-chips figure, .battle-chips .tile { flex: 0 0 84px; margin: 0; padding: .2rem; text-align: center; font-size: .72rem; overflow-wrap: anywhere; }
.battle-chips .tile { flex-direction: column; }
.battle-chips img { display: block; width: 56px; height: 56px; object-fit: contain; margin-inline: auto; }
.battle-chips .inactive-chit img { opacity: .45; }
.battle-overview-actions { display: flex; justify-content: end; margin-top: .75rem; }
.battle-error { color: #872331; }
.battle-die { text-align: center; font-size: 3rem; line-height: 1.5; }
.battle-die.rolling { animation: dice-rock .19s ease-in-out infinite alternate; }
@keyframes dice-rock { from { transform: rotate(-14deg); } to { transform: rotate(14deg); } }
@media (max-width: 740px) { .battle-armies { grid-template-columns: 1fr; } }
.crt { display: block; width: 100%; margin-top: .5rem; }
@media (max-width: 800px) {
  .game { padding: 8px; }
}
@media (max-width: 800px) and (orientation: portrait) {
  .game { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1.15fr) minmax(0, 1fr); }
  .command { grid-area: 3 / 1; margin-top: 8px; }
  .game.command-hidden { grid-template-rows: auto minmax(0, 1fr); }
}
#artillery-die { margin: .4rem; max-width: 100%; }
.battle-overview-actions { flex-wrap: wrap; gap: .4rem; }

#transport-warning { white-space: pre-line; }
