:root {
  --ink: #1c1812;
  --ink-soft: #3a3428;
  --paper: #e6d7b8;
  --paper-deep: #d4c09a;
  --paper-dark: #c4ae84;
  --vermillion: #c4452c;
  --vermillion-deep: #8f2c18;
  --jade: #3d8f6e;
  --indigo: #4a6fad;
  --gold: #c4923a;
  --plum: #9a4d88;
  --teal: #2a9aaa;
  --ochre: #b87a28;
  --fog: #9a8f78;
  --fog-deep: #6e6554;
  --blood: #5c1818;
  --line: #5a4e3a;
  --ok: #2f5d4a;
  --danger: #b33a22;
  --radius: 4px;
  --font-display: "Songti SC", "STSong", "Noto Serif SC", "SimSun", serif;
  --font-body: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  --font-data: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(ellipse at 20% 0%, #2a2418 0%, transparent 50%),
    radial-gradient(ellipse at 80% 100%, #241c14 0%, transparent 45%),
    var(--ink);
  min-height: 100vh;
}

#app { min-height: 100vh; }
.screen { display: none; min-height: 100vh; }
.screen.active { display: block; }

/* ——— Setup ——— */
#screen-setup.active {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  min-height: 100vh;
}
.setup-hero {
  position: relative;
  overflow: hidden;
  min-height: 320px;
  background: #120f0a;
}
.setup-cover {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  filter: saturate(0.75) contrast(1.05);
}
.setup-hero-fade {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, transparent 35%, rgba(28, 24, 18, 0.55) 100%),
    linear-gradient(0deg, rgba(18, 15, 10, 0.96) 0%, rgba(18, 15, 10, 0.72) 28%, transparent 58%);
}
.setup-hero-copy {
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: 10%;
  color: var(--paper);
}
.setup-hero-copy h1 {
  font-family: var(--font-display);
  font-size: clamp(2rem, 5vw, 3.4rem);
  font-weight: 600;
  letter-spacing: 0.12em;
  margin: 0.2em 0 0.4em;
}
.tagline {
  margin: 0;
  opacity: 0.88;
  line-height: 1.6;
  max-width: 28em;
}
.cover-credits {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(230, 215, 184, 0.28);
  font-size: 0.78rem;
  line-height: 1.55;
  opacity: 0.82;
  max-width: 34em;
}
.cover-credits p {
  margin: 0.2rem 0;
}
.eyebrow {
  font-size: 0.75rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--gold);
  margin: 0 0 0.4em;
}
.setup-panel {
  background: var(--paper);
  padding: clamp(1.5rem, 4vw, 3rem);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1rem;
  box-shadow: inset 0 0 0 1px rgba(28, 24, 18, 0.12);
}
.setup-panel h2 {
  font-family: var(--font-display);
  font-size: 1.6rem;
  letter-spacing: 0.15em;
  margin: 0 0 0.5rem;
  font-weight: 600;
}
.field { display: flex; flex-direction: column; gap: 0.45rem; font-size: 0.95rem; }
.field > span { color: var(--ink-soft); }
.checkbox-field {
  flex-direction: row;
  align-items: flex-start;
  gap: 0.6rem;
  line-height: 1.45;
}
.checkbox-field input { margin-top: 0.2rem; }
.stepper {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.25rem;
  background: rgba(255, 255, 255, 0.25);
  width: fit-content;
}
.stepper input {
  width: 3rem;
  text-align: center;
  border: 0;
  background: transparent;
  font-family: var(--font-data);
  font-size: 1.1rem;
  color: var(--ink);
}
.player-names { display: grid; gap: 0.55rem; }
.player-names label {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.6rem;
  align-items: center;
  font-size: 0.92rem;
}
.player-names .swatch {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  border: 1px solid rgba(0, 0, 0, 0.25);
}
.player-names input {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.55rem 0.7rem;
  font: inherit;
  background: rgba(255, 255, 255, 0.35);
  color: var(--ink);
}
.player-names input:focus {
  outline: 2px solid var(--vermillion);
  outline-offset: 1px;
}
.setup-actions { display: flex; flex-direction: column; gap: 0.5rem; }
.btn-ghost-dark {
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid transparent;
  padding: 0.45rem 0.75rem;
  font-size: 0.85rem;
  width: fit-content;
  cursor: pointer;
  font-family: var(--font-body);
}
.btn-ghost-dark:hover { border-color: var(--line); color: var(--blood); }
.hint {
  font-size: 0.85rem;
  color: var(--ink-soft);
  line-height: 1.55;
  margin: 0;
}

/* ——— Buttons ——— */
.btn-primary,
.btn-secondary,
.btn-danger,
.btn-ghost,
.btn-icon {
  font-family: var(--font-body);
  cursor: pointer;
  border-radius: var(--radius);
  transition: transform 0.12s ease, background 0.12s ease, opacity 0.12s ease;
}
.btn-primary {
  background: var(--vermillion);
  color: #f7efe0;
  border: 1px solid var(--vermillion-deep);
  padding: 0.85rem 1.2rem;
  font-size: 1rem;
  letter-spacing: 0.18em;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2);
}
.btn-primary:hover:not(:disabled) { background: var(--vermillion-deep); }
.btn-primary:active:not(:disabled) { transform: translateY(1px); }
.btn-secondary {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 0.75rem 1rem;
  width: 100%;
}
.btn-secondary:hover:not(:disabled) { background: rgba(28, 24, 18, 0.06); }
.btn-danger {
  background: var(--blood);
  color: #f3e6d6;
  border: 1px solid #3e1010;
  padding: 0.7rem 1rem;
  flex: 1;
  letter-spacing: 0.12em;
}
.btn-danger:hover:not(:disabled) { filter: brightness(1.08); }
.btn-ghost {
  background: transparent;
  color: var(--paper);
  border: 1px solid rgba(230, 215, 184, 0.35);
  padding: 0.45rem 0.75rem;
  font-size: 0.85rem;
}
.btn-ghost:hover { background: rgba(230, 215, 184, 0.1); }
.btn-icon {
  width: 2.2rem;
  height: 2.2rem;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.3);
  font-size: 1.1rem;
  line-height: 1;
}
button:disabled { opacity: 0.4; cursor: not-allowed; }
button:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* ——— Game chrome ——— */
.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.7rem 1rem;
  background: rgba(18, 15, 10, 0.92);
  border-bottom: 1px solid rgba(166, 124, 61, 0.35);
  color: var(--paper);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 0.7rem; }
.brand-seal {
  width: 2.2rem;
  height: 2.2rem;
  display: grid;
  place-items: center;
  background: var(--vermillion);
  color: #f7efe0;
  font-family: var(--font-display);
  font-size: 1.1rem;
  border-radius: 2px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25);
}
.brand strong {
  display: block;
  font-family: var(--font-display);
  letter-spacing: 0.12em;
  font-weight: 600;
}
.brand small { opacity: 0.7; font-size: 0.75rem; }
.turn-chip {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.75rem;
  border: 1px solid rgba(230, 215, 184, 0.25);
  border-radius: 999px;
  font-size: 0.9rem;
  background: rgba(230, 215, 184, 0.06);
}
.turn-chip .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--fog);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.12);
}
.topbar-actions { display: flex; gap: 0.4rem; }

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(280px, 0.9fr);
  min-height: calc(100vh - 58px);
}
.map-wrap {
  position: relative;
  background:
    radial-gradient(ellipse at 40% 30%, #2c2618 0%, #1a1610 70%);
  border-right: 1px solid rgba(166, 124, 61, 0.3);
  min-height: 420px;
}
#map {
  width: 100%;
  height: 100%;
  min-height: calc(100vh - 58px);
  display: block;
  touch-action: manipulation;
}
.map-legend {
  position: absolute;
  left: 12px;
  bottom: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.75rem;
  padding: 0.5rem 0.7rem;
  background: rgba(28, 24, 18, 0.78);
  border: 1px solid rgba(166, 124, 61, 0.35);
  color: var(--paper);
  font-size: 0.75rem;
  max-width: calc(100% - 24px);
}
.map-legend span { display: inline-flex; align-items: center; gap: 0.3rem; }
.map-legend i {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}

/* Province styles inside SVG */
.province {
  cursor: pointer;
  stroke: #2a2418;
  stroke-width: 1.1;
  stroke-linejoin: round;
  transition: filter 0.12s ease, stroke-width 0.12s ease;
}
.province.owned {
  stroke: #f0e2c0;
  stroke-width: 2.2;
}
.province:hover { filter: brightness(1.08); stroke-width: 2; }
.province.selected {
  stroke: #f0e2c0;
  stroke-width: 2.8;
  filter: brightness(1.12);
}
.province-label {
  font-family: var(--font-body);
  font-size: 12px;
  fill: #1c1812;
  pointer-events: none;
  text-anchor: middle;
  dominant-baseline: middle;
  font-weight: 700;
  paint-order: stroke;
  stroke: rgba(230, 215, 184, 0.72);
  stroke-width: 3px;
}
.province-troops {
  font-family: var(--font-data);
  font-size: 11px;
  fill: #1c1812;
  pointer-events: none;
  text-anchor: middle;
  dominant-baseline: middle;
  font-weight: 700;
  paint-order: stroke;
  stroke: rgba(230, 215, 184, 0.78);
  stroke-width: 3px;
}
.province.dark-label .province-label,
.province.dark-label .province-troops {
  fill: #f0e6d2;
  stroke: rgba(28, 24, 18, 0.55);
}

/* Side panel */
.side {
  background: var(--paper);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  overflow: auto;
  max-height: calc(100vh - 58px);
  box-shadow: inset 8px 0 16px -12px rgba(0, 0, 0, 0.35);
}
.side-block h3 {
  margin: 0 0 0.5rem;
  font-family: var(--font-display);
  font-size: 0.95rem;
  letter-spacing: 0.16em;
  font-weight: 600;
  color: var(--ink-soft);
}
.player-card {
  border: 1px solid var(--line);
  border-left: 4px solid var(--fog);
  padding: 0.75rem 0.85rem;
  background: rgba(255, 255, 255, 0.28);
}
.player-card .name {
  font-family: var(--font-display);
  font-size: 1.15rem;
  letter-spacing: 0.08em;
  margin-bottom: 0.35rem;
}
.player-card .stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem 1rem;
  font-family: var(--font-data);
  font-size: 0.88rem;
}
.region-detail {
  border: 1px solid var(--line);
  padding: 0.75rem 0.85rem;
  background: rgba(255, 255, 255, 0.28);
  min-height: 5.5rem;
  line-height: 1.55;
  font-size: 0.92rem;
}
.region-detail.empty { color: var(--ink-soft); font-style: italic; }
.region-detail .rd-title {
  font-family: var(--font-display);
  font-size: 1.05rem;
  letter-spacing: 0.08em;
  margin-bottom: 0.3rem;
}
.region-detail .tag {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  border: 1px solid var(--line);
  font-size: 0.75rem;
  margin-left: 0.35rem;
  vertical-align: middle;
}
.action-row { display: flex; gap: 0.5rem; margin-bottom: 0.55rem; }
.action-row .btn-primary,
.action-row .btn-secondary,
.action-row .btn-danger { flex: 1; letter-spacing: 0.08em; padding: 0.7rem 0.5rem; font-size: 0.9rem; }
.action-flags {
  font-family: var(--font-data);
  font-size: 0.72rem;
  letter-spacing: 0;
  color: var(--ink-soft);
  font-weight: 400;
}
.develop-options { display: flex; flex-direction: column; gap: 0.45rem; margin-bottom: 0.5rem; }
.develop-options button {
  text-align: left;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.3);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.92rem;
  color: var(--ink);
  border-radius: var(--radius);
  line-height: 1.4;
}
.develop-options button:hover:not(:disabled) { background: rgba(179, 58, 34, 0.08); border-color: var(--vermillion); }
.develop-options button:disabled { opacity: 0.45; cursor: not-allowed; }
.develop-options button strong { display: block; margin-bottom: 0.15rem; }
.develop-options button span { color: var(--ink-soft); font-size: 0.82rem; }
.trait-chip {
  display: inline-block;
  font-size: 0.75rem;
  padding: 0.05rem 0.35rem;
  border: 1px solid var(--line);
  margin: 0.1rem 0.2rem 0.1rem 0;
  background: rgba(255, 255, 255, 0.35);
}
.ally-status {
  margin-top: 0.45rem;
  font-size: 0.8rem;
  color: var(--ink-soft);
  line-height: 1.4;
}
.event-banner {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(92, 24, 24, 0.92);
  color: #f3e6d6;
  border: 1px solid #8f2c18;
  padding: 0.45rem 0.9rem;
  font-size: 0.85rem;
  z-index: 4;
  white-space: nowrap;
  max-width: calc(100% - 24px);
  overflow: hidden;
  text-overflow: ellipsis;
}
.event-card { border-top: 4px solid var(--blood); }
.event-desc { line-height: 1.6; }
.event-battle {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.28);
  padding: 0.75rem;
  margin: 0.75rem 0 1rem;
  font-size: 0.9rem;
  line-height: 1.55;
  white-space: pre-wrap;
}
.tutorial-card { max-width: min(520px, 100%); }
.tutorial-body {
  font-size: 0.95rem;
  line-height: 1.65;
  min-height: 8em;
  margin: 0.5rem 0 0.75rem;
}
.tutorial-body ul {
  margin: 0.4rem 0;
  padding-left: 1.1rem;
}
.tutorial-body li { margin: 0.25rem 0; }
.tutorial-body strong { color: var(--vermillion); }
.tutorial-progress {
  font-family: var(--font-data);
  font-size: 0.75rem;
  color: var(--ink-soft);
  margin-bottom: 0.5rem;
}
.creative-opts {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.65rem;
  border: 1px dashed var(--line);
  background: rgba(179, 58, 34, 0.04);
  margin-bottom: 0.25rem;
}
.creative-opts input[type="number"] {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.45rem 0.55rem;
  font: inherit;
  width: 8rem;
  background: rgba(255, 255, 255, 0.35);
  color: var(--ink);
}
#creative-owner {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.5rem;
  font: inherit;
  background: rgba(255, 255, 255, 0.35);
  color: var(--ink);
  width: 100%;
}
.disclaimer-card {
  max-width: min(480px, 100%);
  border-top: 4px solid var(--vermillion);
}
.disclaimer-body {
  font-size: 0.95rem;
  line-height: 1.7;
  margin: 0.75rem 0 1.25rem;
  color: var(--ink);
}
.disclaimer-body p { margin: 0 0 0.75rem; }
.online-box {
  margin-top: 0.75rem;
  padding: 0.75rem;
  border: 1px solid var(--line);
  background: rgba(47, 93, 74, 0.06);
}
.online-box h3 {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
  font-size: 0.95rem;
  letter-spacing: 0.1em;
}
.online-row {
  display: flex;
  gap: 0.45rem;
  margin-top: 0.45rem;
  flex-wrap: wrap;
}
.online-row input {
  flex: 1;
  min-width: 7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.55rem 0.65rem;
  font: inherit;
  background: rgba(255, 255, 255, 0.35);
  color: var(--ink);
}
.online-status {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--ink-soft);
  word-break: break-all;
}
.online-status strong { color: var(--vermillion); }
.battle-log {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 220px;
  overflow: auto;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.28);
  font-size: 0.82rem;
  line-height: 1.45;
}
.battle-log li {
  padding: 0.45rem 0.6rem;
  border-bottom: 1px dotted rgba(90, 78, 58, 0.35);
}
.battle-log li:last-child { border-bottom: 0; }
.battle-log li.combat { color: var(--blood); }
.battle-log li.system { color: var(--ink-soft); }

/* Overlays */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(12, 10, 8, 0.72);
  display: grid;
  place-items: center;
  z-index: 20;
  padding: 1rem;
}
.overlay[hidden] { display: none; }
.overlay-card {
  width: min(420px, 100%);
  max-height: min(90vh, 640px);
  overflow: auto;
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow:
    0 0 0 4px rgba(28, 24, 18, 0.35),
    0 18px 40px rgba(0, 0, 0, 0.45);
  padding: 1.4rem 1.3rem 1.2rem;
}
.overlay-card h2 {
  font-family: var(--font-display);
  letter-spacing: 0.1em;
  margin: 0.15em 0 0.5em;
  font-weight: 600;
}
.overlay-card p { margin: 0 0 0.85rem; line-height: 1.55; }
.overlay-card .muted { color: var(--ink-soft); font-size: 0.9rem; }
.overlay-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 0.75rem;
  position: sticky;
  bottom: 0;
  background: var(--paper);
  padding-top: 0.5rem;
}
.slider-meta {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-data);
  font-size: 0.88rem;
  color: var(--ink-soft);
}
input[type="range"] { width: 100%; accent-color: var(--vermillion); }
.combat-card { text-align: center; }
.combat-numbers {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 0.5rem;
  align-items: center;
  margin: 0.8rem 0;
  padding: 0.8rem;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.28);
}
.combat-numbers strong {
  display: block;
  font-family: var(--font-data);
  font-size: 1.5rem;
  margin-top: 0.2rem;
}
.combat-label { font-size: 0.75rem; color: var(--ink-soft); letter-spacing: 0.12em; }
.combat-vs { font-family: var(--font-display); color: var(--vermillion); }
.combat-detail { text-align: left; min-height: 3em; }
.rules-card ul {
  margin: 0 0 1rem;
  padding-left: 1.1rem;
  line-height: 1.65;
  font-size: 0.92rem;
}
.rules-card li { margin-bottom: 0.35rem; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
  }
}

@media (max-width: 900px) {
  #screen-setup.active { grid-template-columns: 1fr; }
  .setup-hero { min-height: 240px; max-height: 36vh; }
  .game-layout { grid-template-columns: 1fr; }
  #map { min-height: 52vh; }
  .side { max-height: none; }
  .map-wrap { border-right: 0; border-bottom: 1px solid rgba(166, 124, 61, 0.3); }
}
