:root {
  --bg: #e9ece6;
  --panel: rgba(251, 249, 241, 0.94);
  --panel-border: #272727;
  --shadow: 0 18px 40px rgba(32, 38, 29, 0.12);
  --text: #182027;
  --muted: #5d6872;
  --grid-line: rgba(33, 39, 35, 0.18);
  --grid-land: linear-gradient(145deg, #ebe4cf, #ded4b6);
  --grid-sea: linear-gradient(145deg, #bfd0dd, #9ab3c5);
  --grid-contested: linear-gradient(145deg, #f0dbc7, #e7c4a8);
  --red: #be1200;
  --red-dark: #840d00;
  --yellow: #efff2b;
  --yellow-dark: #748100;
  --blue: #39207e;
  --blue-dark: #221149;
  --accent: #1b1b1b;
  --success: #0d7a46;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.9), transparent 28%),
    radial-gradient(circle at bottom right, rgba(147, 168, 180, 0.35), transparent 26%),
    linear-gradient(180deg, #f4f3ef 0%, var(--bg) 100%);
  font-family: "Noto Sans TC", sans-serif;
}

.app-shell {
  width: min(1800px, calc(100vw - 24px));
  margin: 0 auto;
  padding: 12px 0 18px;
}

.topbar,
.layout,
.board-toolbar,
.panel-heading,
.legend-row,
.board-main,
.toolbar-group {
  display: flex;
}

.topbar,
.board-toolbar,
.panel-heading,
.legend-row,
.toolbar-group {
  align-items: center;
}

.topbar,
.board-toolbar,
.panel-heading {
  justify-content: space-between;
}

.topbar {
  gap: 24px;
  margin-bottom: 18px;
}

.eyebrow,
.turn-label,
.capture-counter,
.badge,
.turn-counter {
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.eyebrow,
.turn-label,
.capture-counter,
.turn-counter,
.badge,
.rules-list,
.stat-list,
.battle-log,
.selected-unit,
.action-button {
  font-family: "Chakra Petch", sans-serif;
}

h1,
h2,
p,
ul,
ol {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 4vw, 3.2rem);
  line-height: 0.95;
}

h2 {
  font-size: 1rem;
}

.eyebrow,
.turn-label,
.turn-counter,
.capture-counter,
.badge {
  font-size: 0.78rem;
}

.turn-card,
.intel-card,
.theater-frame {
  background: var(--panel);
  border: 2px solid var(--panel-border);
  box-shadow: var(--shadow);
}

.turn-card {
  min-width: 280px;
  padding: 14px 16px;
}

.turn-card strong {
  display: block;
  font-size: 1.4rem;
  margin: 2px 0 6px;
}

.turn-card p {
  color: var(--muted);
  font-size: 0.95rem;
}

.layout {
  gap: 18px;
  align-items: flex-start;
}

.map-only-layout {
  display: block;
}

.map-stage {
  width: 100%;
}

.sidebar {
  width: min(290px, 22vw);
  display: grid;
  gap: 14px;
}

.center-stage {
  flex: 1;
  min-width: 0;
}

.intel-card {
  padding: 14px;
}

.faction-card {
  position: relative;
  overflow: hidden;
}

.faction-card::after {
  content: "";
  position: absolute;
  inset: auto -40px -40px auto;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  opacity: 0.1;
}

.faction-card-red::after {
  background: var(--red);
}

.faction-card-blue::after {
  background: var(--blue);
}

.faction-card-yellow::after {
  background: var(--yellow-dark);
}

.badge {
  border: 1px solid currentColor;
  padding: 2px 8px;
}

.badge.blue {
  color: var(--blue);
}

.badge.yellow {
  color: #6f7300;
}

.badge.muted {
  color: var(--muted);
}

.turn-helper {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.86rem;
}

.stat-list,
.rules-list,
.battle-log {
  padding-left: 18px;
}

.stat-list {
  list-style: none;
  padding-left: 0;
  margin-top: 12px;
}

.stat-list li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 1px dashed rgba(24, 32, 39, 0.16);
}

.stat-list li span:last-child {
  font-weight: 600;
}

.legend-grid {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.legend-row {
  gap: 10px;
}

.selected-unit {
  margin-top: 12px;
  min-height: 112px;
  padding: 12px;
  border: 1px dashed rgba(24, 32, 39, 0.24);
  background: rgba(255, 255, 255, 0.55);
}

.selected-unit.empty {
  color: var(--muted);
}

.battle-log {
  margin-top: 12px;
  display: grid;
  gap: 8px;
  max-height: 244px;
  overflow: auto;
}

.battle-log li {
  font-size: 0.92rem;
  color: var(--muted);
}

.board-toolbar {
  gap: 10px;
  margin-bottom: 10px;
  justify-content: flex-start;
}

.toolbar-group {
  gap: 10px;
  flex-wrap: wrap;
}

.toolbar-group.compact {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.action-button {
  padding: 10px 14px;
  border: 2px solid var(--accent);
  background: #fffae5;
  font-weight: 600;
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease;
}

.action-button:hover {
  transform: translateY(-1px);
  background: #fff5c0;
}

.action-button.secondary {
  background: #e4eef5;
}

.mode-picker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border: 2px solid var(--accent);
  background: #fff7d8;
  font-family: "Chakra Petch", sans-serif;
  font-weight: 600;
}

.mode-picker select {
  border: 0;
  background: transparent;
  font: inherit;
  padding: 10px 0;
  outline: none;
}

.zoom-controls {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.zoom-controls .action-button {
  min-width: 44px;
  padding-inline: 0;
}

.zoom-level {
  min-width: 64px;
  text-align: center;
  padding: 10px 8px;
  border: 2px solid var(--accent);
  background: rgba(255, 255, 255, 0.72);
  font-family: "Chakra Petch", sans-serif;
  font-weight: 600;
}

.theater-frame {
  padding: 12px;
  overflow: auto;
}

.theater-frame-large {
  padding: 8px;
  height: calc(100vh - 110px);
}

.map-hint-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
  color: var(--muted);
  font-family: "Chakra Petch", sans-serif;
  font-size: 0.76rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.map-hint-bar span {
  padding: 6px 10px;
  border: 1px solid rgba(24, 32, 39, 0.14);
  background: rgba(255, 255, 255, 0.74);
}

.theater-map {
  position: relative;
  width: 1200px;
  height: 760px;
  overflow: hidden;
  border: 1px solid rgba(24, 32, 39, 0.18);
  background:
    radial-gradient(circle at 20% 38%, rgba(255, 255, 255, 0.12), transparent 22%),
    linear-gradient(180deg, #b9ccdf 0%, #9fb6ca 100%);
}

.map-svg,
.unit-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.map-svg {
  z-index: 1;
}

.unit-layer {
  z-index: 2;
}

.sea-grid line {
  stroke: rgba(255, 255, 255, 0.08);
  stroke-width: 1;
}

.zone-shape {
  fill: rgba(227, 217, 178, 0.92);
  stroke: rgba(156, 133, 87, 0.72);
  stroke-width: 2;
}

.zone-label {
  font-family: "Chakra Petch", sans-serif;
  font-size: 18px;
  letter-spacing: 0.12em;
  text-anchor: middle;
  dominant-baseline: middle;
  fill: rgba(157, 96, 74, 0.9);
}

.sea-label {
  font-family: "Chakra Petch", sans-serif;
  font-size: 22px;
  letter-spacing: 0.16em;
  text-anchor: middle;
  fill: rgba(56, 74, 92, 0.58);
}

.preview-range,
.attack-range {
  fill: rgba(13, 122, 70, 0.08);
  stroke: rgba(13, 122, 70, 0.74);
  stroke-width: 2;
  stroke-dasharray: 8 8;
}

.attack-range {
  fill: rgba(190, 18, 0, 0.07);
  stroke: rgba(190, 18, 0, 0.68);
}

.move-arrow {
  stroke: rgba(13, 122, 70, 0.9);
  stroke-width: 3;
}

.attack-arrow {
  stroke: rgba(190, 18, 0, 0.9);
  stroke-width: 3;
}

.target-marker {
  fill: rgba(13, 122, 70, 0.88);
  stroke: rgba(255, 255, 255, 0.82);
  stroke-width: 2;
}

.target-marker.attack {
  fill: rgba(190, 18, 0, 0.92);
}

.map-unit {
  position: absolute;
  width: 48px;
  height: 48px;
  border: 0;
  background: transparent;
  transform: translate(-50%, -50%);
  cursor: pointer;
}

.map-unit .piece {
  width: 42px;
  height: 42px;
}

.map-unit.selectable:hover {
  transform: translate(-50%, -50%) scale(1.05);
}

.map-unit.selected {
  filter: drop-shadow(0 0 0.55rem rgba(17, 17, 17, 0.42));
}

.map-unit.spent-unit {
  opacity: 0.68;
}

.map-unit.attackable {
  filter: drop-shadow(0 0 0.5rem rgba(190, 18, 0, 0.42));
}

.map-unit.carried-unit {
  z-index: 3;
}

.map-unit.carried-unit .map-unit-label,
.map-unit.carried-unit .map-unit-health {
  background: rgba(245, 248, 252, 0.92);
}

.map-unit-label,
.map-unit-health {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-family: "Chakra Petch", sans-serif;
  background: rgba(255, 255, 255, 0.86);
  white-space: nowrap;
  border: 1px solid rgba(24, 32, 39, 0.08);
}

.map-unit-label {
  top: -20px;
  font-size: 0.62rem;
  padding: 0 5px;
}

.map-unit-health {
  bottom: -12px;
  font-size: 0.64rem;
  padding: 0 5px;
}

.piece {
  width: 34px;
  height: 34px;
  border: 2px solid rgba(0, 0, 0, 0.7);
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.18));
}

.piece.red {
  background: #ee1a08;
}

.piece.blue {
  background: #4a2ba4;
}

.piece.yellow {
  background: #f7ff2f;
}

.piece-infantry {
  border-radius: 50%;
  position: relative;
}

.piece-infantry::before,
.piece-infantry::after,
.piece-armor::before,
.piece-armor::after,
.piece-hq::before,
.piece-hq::after {
  content: "";
  position: absolute;
  background: rgba(0, 0, 0, 0.55);
}

.piece-infantry::before {
  inset: 15px 4px auto;
  height: 2px;
}

.piece-infantry::after {
  inset: 4px 15px;
  width: 2px;
}

.piece-armor {
  position: relative;
  border-radius: 50%;
}

.piece-armor::before {
  inset: 15px 5px auto;
  height: 2px;
  transform: rotate(45deg);
}

.piece-armor::after {
  inset: 15px 5px auto;
  height: 2px;
  transform: rotate(-45deg);
}

.piece-air {
  clip-path: polygon(8% 50%, 45% 8%, 45% 30%, 92% 30%, 92% 70%, 45% 70%, 45% 92%);
}

.piece-fleet {
  clip-path: polygon(10% 18%, 78% 18%, 95% 50%, 78% 82%, 10% 82%);
}

.piece-missile {
  clip-path: polygon(12% 50%, 55% 12%, 92% 50%, 55% 88%);
}

.piece-hq {
  position: relative;
  clip-path: polygon(16% 20%, 50% 4%, 84% 20%, 84% 92%, 16% 92%);
}

.piece-hq::before {
  inset: 12px 15px 8px;
  width: 2px;
}

.piece-hq::after {
  inset: 18px 9px auto;
  height: 2px;
}

.piece-stack {
  display: none;
}

.piece.spent {
  opacity: 0.52;
}

.selected-unit p + p {
  margin-top: 4px;
}

.briefing-card {
  margin-top: 14px;
}

.rules-list {
  margin-top: 12px;
  display: grid;
  gap: 8px;
}

@media (max-width: 1180px) {
  .layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  .app-shell {
    width: min(100vw, calc(100vw - 12px));
    padding: 10px 0 16px;
  }

  .topbar,
  .board-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .turn-card,
  .sidebar {
    width: 100%;
  }

  .sidebar {
    grid-template-columns: 1fr;
  }

  .board {
    min-width: unset;
  }

  .mode-picker {
    justify-content: space-between;
  }

  .theater-map {
    min-width: 920px;
  }
}