:root {
  color-scheme: dark;
  font: 16px/1.45 'PingFang SC', 'Microsoft YaHei', sans-serif;
  --ink: #35261e;
  --muted-ink: #6f5744;
  --paper: #f0ddbc;
  --lacquer: #332722;
  --gold: #dfbd7a;
  --brass: #927954;
  --cinnabar: #913d2e;
  --serif: 'Songti SC', 'STSong', 'SimSun', serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; }
body {
  background: #181514;
  color: var(--paper);
  overflow: hidden;
  font-variant-numeric: tabular-nums;
}
h1, h2, h3, p { margin: 0; }
button, select, input, summary { font: inherit; }
button, summary, select, input[type='checkbox'] { cursor: pointer; }
button, summary { touch-action: manipulation; }
button, select, input[type='number'] {
  border: 1px solid #a78b69;
  border-radius: 2px;
  color: inherit;
  background: transparent;
}
button { padding: 0.3em 0.8em; }
button:disabled { cursor: default; opacity: .6; }
button:focus-visible, select:focus-visible, input:focus-visible, summary:focus-visible, [data-pad-focus] {
  outline: 3px solid #e59b36;
  outline-offset: 2px;
}
[data-pad-edit] { box-shadow: 0 0 0 3px var(--cinnabar); }
[hidden] { display: none !important; }

#nation-screen {
  width: min(100%, 1820px);
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: radial-gradient(ellipse at 25% 32%, #40322a, transparent 72%), #211c19;
}
.hud, .console-foot {
  display: flex;
  align-items: center;
  gap: clamp(8px, 1.8vw, 30px);
  border: 1px solid var(--brass);
  background: linear-gradient(105deg, #352322, #282321 62%, #282220);
}
.hud {
  padding: 9px clamp(12px, 1.9vw, 32px);
  border-top: 3px double var(--gold);
}
.game-title { display: flex; align-items: center; gap: .8rem; margin-right: auto; white-space: nowrap; }
.game-title span {
  color: #fff0cd;
  background: #953e30;
  padding: .15rem .45rem;
  font: 700 .77rem/1.4 var(--serif);
  border: 1px solid #c98258;
  box-shadow: inset 0 0 0 2px #783429;
}
.game-title h1 {
  font: 800 clamp(21px, 2.1vw, 35px)/1.15 var(--serif);
  letter-spacing: .1em;
  color: #f7e4bd;
}
.turn { display: flex; gap: clamp(5px, 1.4vw, 20px); align-items: center; }
#clock { font-size: clamp(13px, 1.2vw, 17px); }
#orders {
  padding: .2rem .7rem;
  border: 1px solid #ae8756;
  color: #ffdaa0;
  background: #503725;
  white-space: nowrap;
}
.audio-switches button, .map-tools button, #news-toggle {
  color: #f5e1b9;
  font-size: .85rem;
  border: 1px solid #8c7658;
  background: #332a25;
}
.audio-switches button[aria-pressed='true'], #map-zoom[aria-pressed='true'], #realm-toggle[aria-expanded='true'], #news-panel[open] > summary {
  color: #2e221c;
  background: var(--gold);
}
.war-table {
  display: grid;
  grid-template-columns: minmax(0, 1.92fr) minmax(310px, 1fr);
  gap: clamp(9px, 1.1vw, 20px);
  min-height: 0;
  padding: clamp(10px, 1.3vw, 22px);
  border-inline: 1px solid var(--brass);
  background: linear-gradient(125deg, #2c2622, #211b19 85%);
}
.atlas, #desk { min-width: 0; min-height: 0; }
.atlas {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  border: 1px solid #827054;
  background: #171a18;
}
.atlas-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-bottom: 1px solid #76674e;
  background: #2a2923;
}
.atlas-head h2 {
  font: 700 1.15rem/1.2 var(--serif);
  color: #edcea0;
  letter-spacing: .12em;
}
.map-tools { display: flex; gap: 6px; }
#realm-panel {
  position: absolute;
  inset: 3.5rem auto auto .8rem;
  width: min(29rem, calc(100% - 1.6rem));
  max-height: calc(100% - 4.4rem);
  padding: 10px 12px;
  overflow: auto;
  scroll-padding-block: .5rem 3.4rem;
  overscroll-behavior: contain;
  z-index: 6;
  color: var(--ink);
  background: var(--paper);
  border: 3px double #72513b;
  box-shadow: 2px 4px 0 #2a211e, 0 6px 16px #19181277;
  font-size: .88rem;
  color-scheme: light;
}
#realm-panel h3 { margin-bottom: 8px; color: var(--cinnabar); font: 700 1.1rem var(--serif); }
.realm-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-top: 5px; padding-top: 5px; border-top: 1px solid #bca07d; }
.realm-row > strong { margin-right: 4px; }
.realm-city, .realm-close { padding: 4px 8px; background: #f8e9cf; color: var(--ink); border-color: #a18465; }
.realm-city[aria-pressed='true'], .realm-close { background: #733b30; color: #f9e7c7; }
.realm-actions {
  position: sticky;
  bottom: -10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
  padding: 6px 0;
  border-top: 1px solid #ac8967;
  background: var(--paper);
}
#desk[inert], #map-scroll[inert] { filter: brightness(.75) saturate(.8); }
#map-scroll {
  container-type: size;
  display: flex;
  overflow: auto;
  overscroll-behavior: contain;
  background: repeating-linear-gradient(135deg, #1b211d 0 3px, #1e241f 3px 5px);
  scrollbar-color: #a68b63 #322a24;
}
#map {
  position: relative;
  flex: none;
  margin: auto;
  width: 100%;
  width: min(100cqw, 160cqh);
  aspect-ratio: 256/160;
  box-shadow: 0 0 0 1px #897654, 0 5px 18px #151711;
}
#map-scroll.is-zoomed #map { width: max(165cqw, 264cqh, 620px); }
#terrain { display: block; width: 100%; height: 100%; image-rendering: pixelated; }
#markers { position: absolute; inset: 0; }
.marker {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: clamp(10px, .94vw, 17px);
  padding: .1em .32em;
  white-space: nowrap;
  color: #fff7eb;
  border: 1px solid #f1dbb2;
  border-radius: 0;
  box-shadow: 1px 1px #292323, -1px 0 #332923;
  font-weight: 650;
  line-height: 1.18;
  text-shadow: 0 1px #1b1b18;
}
.marker.is-target { border: 2px solid #f8d46f; box-shadow: 0 0 0 2px #483621; z-index: 1; }
.marker.is-source, .marker[aria-pressed='true'] {
  outline: 2px solid #fff5b2;
  outline-offset: 1px;
  z-index: 2;
}
.marker.is-objective::after {
  content: '';
  position: absolute;
  top: -11px;
  left: calc(50% - 5px);
  border: 5px solid transparent;
  border-bottom: 0;
  border-top: 7px solid #ffe391;
  filter: drop-shadow(0 1px 0 #362617);
}
.marker[data-pad-focus], .marker:focus-visible {
  outline: 3px solid white;
  outline-offset: 2px;
  box-shadow: 0 0 0 6px #693826;
  z-index: 3;
}
#map-year, #map-month {
  position: absolute;
  top: 15%;
  transform: translateY(-50%);
  color: #211910;
  font: bold clamp(8px, 2.4cqh, 27px)/1 monospace;
  font-size: min(2.7cqw, 4.32cqh);
}
#map-year { left: 10%; }
#map-month { left: 29%; }
.is-zoomed #map-year, .is-zoomed #map-month { font-size: max(4.45cqw, 7.13cqh, 16px); }
#legend {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px clamp(6px, 1.2vw, 20px);
  padding: 8px 10px;
  border-top: 1px solid #72654f;
  color: #e8ddc6;
  background: #2b2923;
  font-size: clamp(11px, .92vw, 15px);
}
#legend > span { white-space: nowrap; }
.swatch {
  display: inline-block;
  width: .78em;
  height: .78em;
  margin-right: .3em;
  border: 1px solid #cbb790;
}
#desk {
  display: flex;
  flex-direction: column;
  color: var(--ink);
  border: 1px solid #a7906c;
  background: linear-gradient(120deg, #f1dfc0 0%, #edd5b2 76%, #e7c9a5 100%);
  box-shadow: inset 0 0 0 3px #ad8f68, inset 0 0 0 4px #e2c69e;
  color-scheme: light;
}
.dispatch {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 3px 12px;
  padding: 9px clamp(12px, 1.3vw, 18px);
  color: #fff1d4;
  background: #773a30;
  border: 2px solid #b37a54;
  box-shadow: inset 0 0 0 1px #683026;
}
#seat-name { font: 700 1.12em/1.3 var(--serif); }
#status { font-size: .87rem; flex: 1 1 auto; }
.desk-scroll { overflow: auto; overscroll-behavior: contain; scrollbar-color: #a48461 #e8d2b1; padding: clamp(12px, 1.45vw, 24px); }
#city-title { font: 800 clamp(20px, 2.2vw, 32px)/1.2 var(--serif); letter-spacing: .05em; }
#garrison { color: #4d3a29; font-weight: 650; margin-top: .35rem; }
#garrison:empty { display: none; }
#city-details { margin-top: 9px; }
#city-toggle, .officer summary { color: #713829; font-weight: 650; }
#city-toggle { width: fit-content; padding: 2px 2px 3px; }
#stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; margin: 8px 0; font-size: .9rem; }
#roster { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 6.7rem), 1fr)); align-items: start; gap: 5px; }
.officer { padding: 5px 8px; color: #f6e5c8; background: #38342d; border-left: 3px solid #a36c46; font-size: .81rem; }
.officer img { display: block; margin-bottom: 2px; height: 14px; image-rendering: pixelated; }
.officer-portrait { display: inline-block; float: left; margin: 0 5px 3px -2px; width: 32px; height: 40px; image-rendering: pixelated; background-repeat: no-repeat; }
.officer > div { clear: both; }
.officer details { clear: both; }
.officer summary { color: #ffda9b; }
.officer details > div { margin-top: 3px; }
#controls:not(:empty) { border-top: 3px double #ac8864; margin-top: .8rem; padding-top: .8rem; }
#controls h3, .command-heading { font: 700 1.18rem/1.35 var(--serif); color: #652d23; margin-bottom: 8px; }
#controls p { margin: 6px 0; }
#controls button, #controls select, #controls input[type='number'] {
  border-color: #9a7c5e;
  color: var(--ink);
  background: #f6e8d0;
  padding: 6px 9px;
}
#controls select { max-width: 65%; }
#controls input[type='number'] { width: 7em; max-width: 50%; }
#controls input[type='checkbox'] { width: 18px; height: 18px; accent-color: #893e2c; }
#controls label { display: flex; justify-content: space-between; align-items: center; gap: 4px 10px; margin: 6px 0; }
#controls fieldset { min-width: 0; border: 1px solid #ae9472; margin: 9px 0; padding: 6px 10px; }
#controls fieldset legend { color: #61442f; padding: 0 5px; }
.command-menu { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 6.3rem), 1fr)); gap: 7px; }
.command-menu:has(.target-option) { grid-template-columns: repeat(auto-fit, minmax(min(100%, 8.45rem), 1fr)); }
#controls .command-menu button, #controls button.target-option {
  position: relative;
  text-align: start;
  padding-left: 16px;
  border-left: 3px solid #96704c;
}
#controls .command-menu button[data-pad-focus]::before, #controls .command-menu button:focus-visible::before {
  content: '';
  position: absolute;
  left: 4px;
  top: calc(50% - 4px);
  border: 4px solid transparent;
  border-left: 5px solid var(--cinnabar);
  border-right: 0;
}
#controls .command-menu button:hover, #controls button:hover:not(:disabled) { background: #ffeecd; border-color: #6b462e; }
#controls .order-summary { padding: 8px; background: #decaab; }
#controls .empty-garrison { color: #872d20; font-weight: 700; }
#controls button.primary, #controls button.primary:hover { background: #7a3428; color: #fff2da; border-color: #5f3025; font-weight: 700; }
#controls .command-back { margin-right: 6px; }
#error:not(:empty) { color: #7e291e; border-left: 3px solid #a84129; padding-left: 8px; margin-top: 10px; }
.console-foot { position: relative; padding: 7px clamp(10px, 1.2vw, 20px); min-height: 44px; gap: 10px; }
#news-panel { flex: none; }
#news-toggle { padding: 3px 8px; }
#news {
  position: absolute;
  bottom: calc(100% + 3px);
  left: 0;
  width: min(400px, 97%);
  max-height: 34vh;
  overflow: auto;
  margin: 0;
  padding: 10px 12px 10px 32px;
  z-index: 5;
  color: var(--paper);
  background: #332a24;
  border: 2px double #c7a57a;
  box-shadow: 4px 4px 0 #1c1915;
}
#news:empty::after { content: '暂无军报'; }
#latest-news, #input-hint { font-size: .82rem; }
#latest-news { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
#input-hint { margin-left: auto; text-align: right; color: #ead2a9; }
#touch-controls { display: none; }
#field { position: fixed; inset: 0; z-index: 10; background: #191a18; }
#field > div { display: flex; align-items: center; justify-content: space-between; height: 46px; padding: 4px 12px; color: var(--paper); }
#battle { width: 100%; height: calc(100% - 46px); display: block; border: 0; }
#field.two-seats { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 46px minmax(0, 1fr); }
#field.two-seats[hidden] { display: none; }
#field.two-seats > div { grid-column: 1 / -1; }
#field.two-seats iframe { width: 100%; height: 100%; border: 0; min-width: 0; }
@media (orientation: portrait) {
  #field.two-seats { grid-template-columns: 1fr; grid-template-rows: 46px 1fr 1fr; }
}

@media (pointer: coarse), (max-width: 760px) {
  #touch-controls, .direction-keys { display: flex; gap: 4px; }
  #touch-controls { margin-left: auto; align-items: center; }
  #touch-controls button, #news-toggle { min-height: 44px; }
  #touch-controls button { min-width: 44px; padding: 2px 5px; touch-action: manipulation; }
  #touch-controls [data-nation-key='confirm'] { color: #ffecc3; background: #853b2d; }
  #input-hint { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  body:has([data-pad-edit]) .console-foot { flex-wrap: wrap; row-gap: 2px; }
  body:has([data-pad-edit]) #latest-news { display: none; }
  body:has([data-pad-edit]) #input-hint {
    position: static;
    flex: 0 0 100%;
    order: -1;
    width: auto;
    height: auto;
    clip-path: none;
    color: #ffdda1;
    text-align: center;
    font-size: .76rem;
  }
  .realm-city, .realm-close, .realm-actions button { min-height: 40px; min-width: 42px; }
  #controls button, #controls select, #controls input[type='number'] { min-height: 38px; }
  .is-zoomed .marker { font-size: 14px; padding: .27em .45em; }
}
@media (max-width: 760px) and (orientation: portrait) {
  #nation-screen {
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  }
  .hud { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: 'title music' 'turn turn'; gap: 3px 9px; padding: 5px 9px; }
  .game-title { grid-area: title; gap: 6px; }
  .game-title span { padding: 0 .2rem; font-size: .61rem; }
  .game-title h1 { font-size: 19px; }
  .audio-switches { grid-area: music; }
  .audio-switches button { min-height: 26px; }
  .turn { grid-area: turn; justify-content: space-between; }
  #clock, #orders, .audio-switches button { font-size: 12px; }
  #orders, .audio-switches button { padding: .15rem .3rem; }
  .war-table { grid-template-columns: 1fr; grid-template-rows: minmax(0, min(43dvh, calc(62.5vw + 55px))) minmax(0, 1fr); gap: 5px; padding: 5px; }
  .atlas-head { padding: 2px 6px; }
  .atlas-head h2 { font-size: .78rem; }
  .map-tools button { font-size: 12px; padding: 2px 8px; min-height: 30px; }
  #realm-panel { inset: 38px auto auto 4px; width: calc(100% - 8px); max-height: calc(100% - 44px); }
  #legend { gap: 1px 7px; padding: 2px 6px; font-size: 10px; }
  .marker { font-size: clamp(9px, 2.6vw, 13px); }
  .dispatch { padding: 4px 10px; }
  #seat-name, #status { font-size: .84rem; }
  .desk-scroll { padding: 9px 12px 14px; }
  #city-title { font-size: 1.13rem; display: inline; }
  #garrison { font-size: .83rem; }
  #city-details { margin-top: 3px; }
  #controls:not(:empty) { margin-top: .4rem; padding-top: .45rem; }
  .console-foot { padding: 4px 6px; gap: 4px; min-height: 48px; }
  #latest-news { display: none; }
  #news-toggle { display: flex; align-items: center; }
}
@media (orientation: landscape) and (max-height: 560px) {
  #nation-screen { padding: env(safe-area-inset-top) max(3px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(3px, env(safe-area-inset-left)); }
  .hud { padding: 3px 9px; }
  .game-title h1 { font-size: 18px; }
  .war-table { grid-template-columns: minmax(0, 1.45fr) minmax(240px, 1fr); padding: 4px; gap: 5px; }
  .atlas-head { padding: 2px 7px; }
  .atlas-head h2 { font-size: .89rem; }
  .map-tools button, #legend { font-size: 10px; padding: 2px 5px; }
  #realm-panel { top: 30px; max-height: calc(100% - 35px); }
  .dispatch { padding: 3px 8px; }
  #seat-name, #status, #garrison { font-size: .82rem; }
  .desk-scroll { padding: 6px 10px; }
  #city-title { font-size: 19px; }
  #controls:not(:empty), #city-details { margin-top: 4px; padding-top: 2px; }
  .console-foot { min-height: 36px; padding: 1px 7px; }
}
@media (max-width: 359px) {
  .game-title span { display: none; }
  #touch-controls, .direction-keys { gap: 2px; }
  #touch-controls button { min-width: 36px; }
}

.audio-switches { display: flex; gap: 4px; }
#order-scene {
  color: var(--ink); background: var(--paper); border: 3px double var(--brass);
  margin: 0; width: min(68vw, 270px); max-height: 88dvh; padding: .6rem;
  box-shadow: 0 5px 20px #18100eca;
}
#order-scene::backdrop { background: #21180f35; }
#order-scene canvas {
  display: block; margin: 0 auto .4rem; max-height: 47dvh; max-width: 100%;
  width: auto; height: 224px; object-fit: contain; image-rendering: pixelated;
}
#order-scene strong { font: bold 1.12rem var(--serif); color: var(--cinnabar); }
#order-scene p { margin: .25rem 0 .4rem; }
#scene-speaker { float: left; margin: .15rem .7rem 0 0; text-align: center; }
#scene-speaker .officer-portrait { display: block; float: none; margin: 0 auto; }
#scene-speaker figcaption { font-size: .85rem; }
#order-scene button { background: var(--lacquer); color: var(--paper); }
#order-scene.calendar-picture { width: min(42vw, 240px); }
#order-scene.calendar-picture canvas { width: min(224px, 100%); height: auto; }
#order-scene.calendar-ending { width: min(84vw, 480px); }
#order-scene.calendar-ending canvas { width: 100%; height: auto; }
@keyframes calendar-city-blink { 50% { opacity: .15; } }
.marker.calendar-city { animation: calendar-city-blink 266.22ms steps(1, end) infinite; }
