:root {
  color-scheme: dark;
  --ink: #f6f1df;
  --muted: #b9c5bd;
  --panel: #17243b;
  --panel-2: #24344c;
  --line: rgba(246, 241, 223, 0.18);
  --blue: #4ca7d8;
  --blue-deep: #1f5d96;
  --red: #e2594f;
  --red-deep: #983536;
  --gold: #f3c65d;
  --green: #5f8f5c;
  --field: #8aa65d;
  --road: #c6b27a;
  --forest: #3e7144;
  --mountain: #858074;
  --river: #4f9fb8;
  --shadow: 0 18px 36px rgba(4, 8, 16, 0.35);
  font-family: Avenir Next, Pretendard, Apple SD Gothic Neo, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    linear-gradient(180deg, rgba(23, 36, 59, 0.82), rgba(12, 18, 28, 0.96)),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.035) 0 1px, transparent 1px 18px);
  color: var(--ink);
}

button {
  font: inherit;
}

.app-shell {
  width: min(100%, 460px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 12px max(14px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  gap: 10px;
  overflow-x: hidden;
}

.topbar,
.status-strip,
.objective-strip,
.command-panel {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(36, 52, 76, 0.96), rgba(20, 31, 48, 0.96));
  box-shadow: var(--shadow);
}

.topbar {
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
}

.eyebrow,
.status-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 2px 0 0;
  font-size: clamp(1.28rem, 6vw, 1.72rem);
  line-height: 1;
  letter-spacing: 0;
}

.icon-button,
.end-turn-button,
.action-button,
.editor-open-button {
  min-height: 40px;
  border: 1px solid rgba(246, 241, 223, 0.2);
  color: var(--ink);
  background: #2f4160;
  border-radius: 8px;
  font-weight: 800;
  cursor: pointer;
  transition:
    transform 160ms ease,
    background 160ms ease,
    border-color 160ms ease;
}

.icon-button {
  width: 42px;
  padding: 0;
  font-size: 1.2rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 7px;
}

.editor-open-button {
  min-height: 42px;
  display: grid;
  place-items: center;
  padding: 0 11px;
  border-color: rgba(243, 198, 93, 0.42);
  background: #263958;
  color: var(--gold);
  font-size: 0.76rem;
  text-decoration: none;
}

.end-turn-button {
  padding: 0 12px;
  background: var(--gold);
  color: #2b2615;
}

.action-button {
  padding: 0 10px;
}

.icon-button:active,
.end-turn-button:active,
.action-button:active,
.tile:active {
  transform: translateY(1px) scale(0.99);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.status-strip,
.objective-strip {
  display: grid;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border-radius: 8px;
}

.status-strip {
  grid-template-columns: 0.58fr 0.72fr 0.72fr minmax(88px, 1fr);
}

.status-strip strong,
.objective-strip strong {
  display: block;
  margin-top: 2px;
  font-size: 0.92rem;
  line-height: 1.1;
}

.objective-strip {
  grid-template-columns: minmax(0, 1fr) 36%;
}

.stage-select-row,
.scenario-value,
.map-tags,
.scenario-builder-launch {
  grid-column: 1 / -1;
}

.stage-select-row {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}

.stage-select {
  width: 100%;
  min-height: 34px;
  border: 1px solid rgba(246, 241, 223, 0.18);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--ink);
  background: #20304a;
  font: inherit;
  font-weight: 800;
}

.objective-copy {
  min-width: 0;
}

.scenario-value {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.map-tags {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 1px;
  scrollbar-width: none;
}

.map-tags::-webkit-scrollbar {
  display: none;
}

.map-tags span {
  flex: 0 0 auto;
  max-width: 100%;
  border: 1px solid rgba(246, 241, 223, 0.14);
  border-radius: 999px;
  padding: 5px 8px;
  color: #d7decb;
  background: rgba(9, 16, 26, 0.34);
  font-size: 0.68rem;
  font-weight: 800;
  white-space: nowrap;
}

.scenario-builder-launch {
  min-height: 42px;
  border: 1px solid rgba(243, 198, 93, 0.52);
  border-radius: 7px;
  color: #272113;
  background: var(--gold);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 900;
  cursor: pointer;
}

.meter {
  height: 12px;
  border: 1px solid rgba(246, 241, 223, 0.18);
  background: rgba(5, 10, 18, 0.45);
  border-radius: 999px;
  overflow: hidden;
}

.meter span {
  display: block;
  width: 16%;
  height: 100%;
  background: linear-gradient(90deg, var(--blue), var(--gold));
  transition: width 240ms ease;
}

.battlefield-wrap {
  min-height: 0;
  min-width: 0;
  max-height: min(47dvh, 510px);
  overflow: auto;
  display: block;
  padding: 5px;
  border: 1px solid rgba(246, 241, 223, 0.16);
  border-radius: 8px;
  background: rgba(7, 14, 25, 0.58);
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.battlefield {
  --tile-size: 44px;
  width: max-content;
  max-width: none;
  min-width: 100%;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--tile-size));
  grid-template-rows: repeat(var(--rows), var(--tile-size));
  gap: 3px;
  padding: 5px;
  border: 1px solid rgba(246, 241, 223, 0.22);
  border-radius: 8px;
  background: #101c2d;
  box-shadow: var(--shadow);
}

.end-turn-button {
  grid-column: auto;
}

.tile {
  position: relative;
  min-width: 0;
  min-height: 0;
  border: 1px solid rgba(14, 24, 32, 0.38);
  border-radius: 6px;
  overflow: hidden;
  color: var(--ink);
  cursor: pointer;
  isolation: isolate;
  --tile-atlas-position: 0% 0%;
  --tile-fallback: var(--field);
}

.tile::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -2;
  opacity: 0.98;
  background-color: var(--tile-fallback);
  background-image: url("/assets/war_game/terrain-atlas.png");
  background-position: var(--tile-atlas-position);
  background-size: 300% 300%;
  background-repeat: no-repeat;
}

.tile::after {
  content: "";
  position: absolute;
  inset: 3px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 4px;
  z-index: -1;
}

.terrain-plain {
  --tile-atlas-position: 0% 0%;
  --tile-fallback: var(--field);
}

.terrain-road,
.has-road {
  --tile-atlas-position: 50% 0%;
  --tile-fallback: var(--road);
}

.terrain-forest {
  --tile-atlas-position: 100% 0%;
  --tile-fallback: var(--forest);
}

.terrain-mountain {
  --tile-atlas-position: 0% 50%;
  --tile-fallback: var(--mountain);
}

.terrain-city {
  --tile-atlas-position: 50% 50%;
  --tile-fallback: #a99068;
}

.terrain-hq {
  --tile-atlas-position: 100% 50%;
  --tile-fallback: #7f715a;
}

.terrain-river {
  --tile-atlas-position: 0% 100%;
  --tile-fallback: var(--river);
}

.terrain-blockade {
  --tile-atlas-position: 50% 100%;
  --tile-fallback: #524d4b;
}

.terrain-storm {
  --tile-atlas-position: 100% 100%;
  --tile-fallback: #dbe8ed;
}

.terrain-sea,
.terrain-reef {
  --tile-atlas-position: 0% 100%;
  --tile-fallback: #3b89a6;
}

.terrain-shoal {
  --tile-atlas-position: 50% 0%;
  --tile-fallback: #b9a36d;
}

.terrain-port {
  --tile-atlas-position: 50% 50%;
  --tile-fallback: #827d72;
}

.terrain-pipe {
  --tile-atlas-position: 50% 100%;
  --tile-fallback: #667075;
}

.battlefield[data-stage="relay-ridge"] .tile::before {
  filter: saturate(0.92) contrast(1.06);
}

.battlefield[data-stage="whiteout-line"] .tile::before {
  filter: saturate(0.74) brightness(1.12);
}

.terrain-mark {
  display: none;
}

.road-mark {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: block;
  color: transparent;
  font-size: 0;
  pointer-events: none;
}

.road-mark::before,
.road-mark::after {
  content: "";
  position: absolute;
  border-radius: 999px;
  background:
    linear-gradient(180deg, rgba(255, 236, 171, 0.18), transparent 42%),
    rgba(86, 63, 38, 0.44);
  box-shadow: inset 0 0 0 1px rgba(255, 236, 171, 0.12);
}

.road-e .road-mark::before {
  left: 49%;
  right: -1px;
  top: 44%;
  height: 18%;
}

.road-w .road-mark::before {
  left: -1px;
  right: 49%;
  top: 44%;
  height: 18%;
}

.road-ew .road-mark::before {
  left: -1px;
  right: -1px;
  top: 44%;
  height: 18%;
}

.road-n .road-mark::before {
  top: -1px;
  bottom: 49%;
  left: 44%;
  width: 18%;
}

.road-s .road-mark::before {
  top: 49%;
  bottom: -1px;
  left: 44%;
  width: 18%;
}

.road-ns .road-mark::before {
  top: -1px;
  bottom: -1px;
  left: 44%;
  width: 18%;
}

.road-en .road-mark::before,
.road-es .road-mark::before,
.road-nw .road-mark::before,
.road-sw .road-mark::before {
  top: 44%;
  height: 18%;
}

.road-en .road-mark::before,
.road-es .road-mark::before {
  left: 49%;
  right: -1px;
}

.road-nw .road-mark::before,
.road-sw .road-mark::before {
  left: -1px;
  right: 49%;
}

.road-en .road-mark::after,
.road-nw .road-mark::after {
  top: -1px;
  bottom: 49%;
  left: 44%;
  width: 18%;
}

.road-es .road-mark::after,
.road-sw .road-mark::after {
  top: 49%;
  bottom: -1px;
  left: 44%;
  width: 18%;
}

.owner-flag {
  position: absolute;
  right: 4px;
  top: 4px;
  width: 15px;
  height: 15px;
  display: grid;
  place-items: center;
  border-radius: 4px;
  color: #fff;
  font-size: 0.58rem;
  font-weight: 900;
}

.owner-blue .owner-flag {
  background: var(--blue-deep);
}

.owner-red .owner-flag {
  background: var(--red-deep);
}

.owner-neutral .owner-flag {
  background: #6c6f72;
}

.start-blue:not(.owner-blue) {
  box-shadow: inset 0 0 0 2px rgba(76, 167, 216, 0.32);
}

.start-red:not(.owner-red) {
  box-shadow: inset 0 0 0 2px rgba(226, 89, 79, 0.28);
}

.is-blocked {
  cursor: not-allowed;
}

.is-blocked::after {
  inset: 2px;
  border-color: rgba(18, 18, 18, 0.32);
  background: repeating-linear-gradient(135deg, rgba(25, 20, 19, 0.46) 0 5px, transparent 5px 10px);
}

.is-reachable {
  border-color: rgba(243, 198, 93, 0.92);
  box-shadow: inset 0 0 0 2px rgba(243, 198, 93, 0.45);
}

.is-target {
  border-color: rgba(226, 89, 79, 0.96);
  box-shadow: inset 0 0 0 2px rgba(226, 89, 79, 0.52);
}

.is-selected {
  outline: 3px solid rgba(246, 241, 223, 0.76);
  outline-offset: -3px;
}

.is-step-trail {
  border-color: rgba(243, 198, 93, 0.74);
}

.is-step-trail::after {
  inset: 4px;
  border-color: rgba(243, 198, 93, 0.34);
  background: radial-gradient(circle, rgba(243, 198, 93, 0.18), transparent 58%);
}

.unit-token {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(82%, 44px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  transform: translate(-50%, -50%);
  border: 2px solid rgba(255, 255, 255, 0.76);
  border-radius: 50%;
  background:
    radial-gradient(circle at 32% 20%, rgba(255, 255, 255, 0.72), transparent 16%),
    linear-gradient(145deg, var(--unit-token-top), var(--unit-token-bottom));
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.4),
    inset 0 -5px 8px rgba(5, 8, 16, 0.24),
    0 8px 14px rgba(5, 8, 16, 0.34);
}

.is-moving-unit {
  z-index: 5;
  animation: tile-hop 145ms ease both;
}

.unit-blue {
  --unit-token-top: var(--blue);
  --unit-token-bottom: var(--blue-deep);
  --unit-base: #eaf8ff;
  --unit-mid: #83d6ff;
  --unit-accent: #173e70;
  --unit-dark: #10243e;
  --unit-glass: #b9edff;
}

.unit-red {
  --unit-token-top: #fb8c75;
  --unit-token-bottom: var(--red-deep);
  --unit-base: #fff0e8;
  --unit-mid: #ffb29d;
  --unit-accent: #7b201f;
  --unit-dark: #33100f;
  --unit-glass: #ffd8c9;
}

.unit-vector {
  width: 86%;
  height: 86%;
  overflow: visible;
}

.unit-vector path,
.unit-vector circle,
.unit-vector ellipse,
.unit-vector rect {
  vector-effect: non-scaling-stroke;
}

.unit-shadow {
  fill: rgba(5, 8, 16, 0.45);
}

.unit-metal {
  fill: var(--unit-base);
  stroke: var(--unit-dark);
  stroke-width: 2.5;
}

.unit-light {
  fill: var(--unit-mid);
  stroke: var(--unit-dark);
  stroke-width: 2.2;
}

.unit-accent {
  fill: var(--unit-accent);
  stroke: var(--unit-dark);
  stroke-width: 2;
}

.unit-face {
  fill: #f2c694;
  stroke: var(--unit-dark);
  stroke-width: 2;
}

.unit-wheel {
  fill: var(--unit-dark);
  stroke: var(--unit-base);
  stroke-width: 1.8;
}

.model-highlight {
  fill: rgba(255, 255, 255, 0.52);
}

.model-window {
  fill: var(--unit-glass);
  stroke: var(--unit-dark);
  stroke-width: 2;
}

.model-eye {
  fill: var(--unit-dark);
}

.model-tread {
  fill: var(--unit-dark);
  stroke: var(--unit-base);
  stroke-width: 2;
}

.model-rotor {
  fill: var(--unit-accent);
  stroke: var(--unit-dark);
  stroke-width: 1.8;
}

.unit-strength {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 17px;
  height: 17px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.82);
  border-radius: 50%;
  color: #fff;
  background: rgba(8, 14, 24, 0.9);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.45);
  font-size: 0.54rem;
  font-weight: 1000;
  line-height: 1;
}

.is-damage-flash {
  animation: damage-flash 180ms ease both;
}

.is-damage-flash .hp-bar {
  animation: hp-flash 180ms ease both;
}

.is-hp-dropping .hp-bar span {
  animation: hp-drop 460ms cubic-bezier(0.2, 0.78, 0.22, 1) both;
}

.hp-bar {
  position: absolute;
  left: 14%;
  right: 14%;
  bottom: -5px;
  height: 5px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.45);
  overflow: hidden;
}

.hp-bar span {
  display: block;
  height: 100%;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), transparent 48%),
    #c6f26a;
}

.has-acted {
  filter: grayscale(0.55);
  opacity: 0.72;
}

.command-panel {
  border-radius: 8px;
  padding: 10px;
}

.selection-summary {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 10px;
}

.selection-summary > div {
  min-width: 0;
}

.selection-summary strong {
  display: block;
  margin-top: 2px;
  font-size: 1rem;
  word-break: keep-all;
}

.selection-meta {
  color: var(--muted);
  font-size: 0.8rem;
  text-align: right;
  max-width: 46%;
  word-break: keep-all;
}

.action-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
  margin-top: 10px;
}

.action-button.is-active {
  border-color: rgba(243, 198, 93, 0.9);
  background: #5a4a23;
}

.option-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 9px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.option-toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--gold);
}

.battle-log {
  height: 64px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  align-content: start;
  gap: 4px;
  overflow: auto;
  color: var(--muted);
  font-size: 0.77rem;
  line-height: 1.25;
}

.battle-log li {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.content-editor {
  width: 100%;
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  color: var(--ink);
  background: #0d1725;
}

.content-editor::backdrop {
  background: rgba(3, 7, 13, 0.8);
  backdrop-filter: blur(6px);
}

.editor-shell {
  height: 100%;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  background:
    linear-gradient(rgba(255, 255, 255, 0.028) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.028) 1px, transparent 1px),
    #101b2a;
  background-size: 22px 22px;
}

.editor-header,
.editor-control-bar,
.editor-tabs,
.editor-footer {
  border-bottom: 1px solid var(--line);
  background: rgba(16, 27, 42, 0.95);
}

.editor-header {
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 14px 10px;
}

.editor-header h1,
.editor-header h2 {
  margin: 2px 0 0;
  font-size: 1.24rem;
  letter-spacing: 0;
}

.editor-game-link {
  min-height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(243, 198, 93, 0.46);
  border-radius: 7px;
  padding: 0 12px;
  color: var(--gold);
  background: #293a54;
  font-size: 0.76rem;
  font-weight: 900;
  text-decoration: none;
}

.editor-icon-button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #293a54;
  font-size: 1.45rem;
  cursor: pointer;
}

.editor-control-bar {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
  padding: 9px 12px;
}

.editor-stage-picker,
.editor-field {
  min-width: 0;
  display: grid;
  gap: 5px;
}

.editor-stage-picker span,
.editor-field span,
.editor-section-title span {
  color: #8fa1ae;
  font-size: 0.66rem;
  font-weight: 900;
  letter-spacing: 0;
}

.editor-stage-picker select,
.editor-field input,
.editor-field select,
.editor-field textarea,
.terrain-cost-row input[type="number"],
.json-editor {
  width: 100%;
  min-height: 40px;
  border: 1px solid rgba(246, 241, 223, 0.2);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--ink);
  background: #19283b;
  font: inherit;
  outline: none;
}

.editor-stage-picker select:focus,
.editor-field input:focus,
.editor-field select:focus,
.editor-field textarea:focus,
.terrain-cost-row input[type="number"]:focus,
.json-editor:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(243, 198, 93, 0.15);
}

.editor-field textarea {
  resize: vertical;
  line-height: 1.5;
}

.editor-file-actions {
  display: flex;
  gap: 6px;
}

.editor-secondary-button,
.editor-primary-button,
.editor-danger-button,
.editor-apply-button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 11px;
  color: var(--ink);
  background: #293a54;
  font: inherit;
  font-size: 0.76rem;
  font-weight: 900;
  cursor: pointer;
}

.editor-primary-button,
.editor-apply-button {
  color: #211e13;
  background: var(--gold);
}

.editor-danger-button {
  margin-top: 12px;
  color: #ffd8d1;
  border-color: rgba(226, 89, 79, 0.46);
  background: rgba(152, 53, 54, 0.42);
}

.editor-stage-danger-row {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid rgba(246, 241, 223, 0.1);
  color: #8fa1ae;
  font-size: 0.72rem;
  font-weight: 800;
}

.editor-stage-danger-row .editor-danger-button {
  flex: 0 0 auto;
  margin-top: 0;
}

.editor-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  padding: 0 8px;
}

.editor-tabs button {
  min-height: 44px;
  border: 0;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  background: transparent;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 900;
  cursor: pointer;
}

.editor-tabs button.is-active {
  color: var(--gold);
  border-bottom-color: var(--gold);
}

.editor-body {
  min-height: 0;
  overflow: auto;
  padding: 12px;
}

.editor-section {
  width: min(100%, 900px);
  margin: 0 auto;
  padding: 14px 0 18px;
  border-bottom: 1px solid rgba(246, 241, 223, 0.13);
}

.editor-section:first-child {
  padding-top: 2px;
}

.editor-section-title {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.editor-section-title strong {
  max-width: 70%;
  font-size: 0.92rem;
  text-align: right;
}

.editor-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 11px;
}

.editor-field-wide {
  grid-column: 1 / -1;
}

.editor-toolbar-row {
  display: flex;
  align-items: end;
  gap: 9px;
  margin-bottom: 13px;
}

.editor-unit-select {
  flex: 1;
}

.editor-role-chip {
  min-height: 40px;
  display: grid;
  place-items: center;
  padding: 0 10px;
  border: 1px solid rgba(95, 143, 92, 0.54);
  border-radius: 6px;
  color: #d9efc5;
  background: rgba(54, 91, 58, 0.38);
  font-size: 0.72rem;
  font-weight: 900;
}

.editor-stat-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.editor-stat input {
  min-height: 52px;
  font-size: 1.05rem;
  font-weight: 900;
  text-align: center;
}

.editor-unit-meta {
  margin-top: 14px;
}

.editor-check {
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  align-self: end;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
}

.editor-check input,
.terrain-cost-row input[type="checkbox"] {
  width: 19px;
  height: 19px;
  accent-color: var(--gold);
}

.terrain-cost-list {
  display: grid;
  gap: 6px;
}

.terrain-cost-row {
  min-height: 48px;
  display: grid;
  grid-template-columns: minmax(90px, 1fr) 90px 72px;
  gap: 8px;
  align-items: center;
  padding: 5px 7px;
  border-bottom: 1px solid rgba(246, 241, 223, 0.09);
}

.terrain-cost-row label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  font-weight: 900;
}

.terrain-cost-row input[type="number"] {
  min-height: 36px;
  padding: 5px 7px;
  text-align: center;
}

.terrain-cost-row small {
  color: #8fa1ae;
  font-size: 0.66rem;
  text-align: right;
}

.event-editor-layout {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 14px;
}

.event-list {
  display: grid;
  align-content: start;
  gap: 6px;
}

.event-list-item {
  min-height: 58px;
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: 2px 6px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px;
  color: var(--ink);
  background: #19283b;
  text-align: left;
  cursor: pointer;
}

.event-list-item > span {
  grid-row: 1 / span 2;
  color: var(--gold);
  font-weight: 900;
}

.event-list-item strong,
.event-list-item small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.event-list-item small {
  color: #8fa1ae;
}

.event-list-item.is-active {
  border-color: var(--gold);
  background: #2f3c4a;
}

.editor-empty {
  min-height: 180px;
  display: grid;
  place-items: center;
  color: #8fa1ae;
}

.json-section {
  height: 100%;
  display: grid;
  grid-template-rows: minmax(320px, 1fr) auto;
  gap: 10px;
  border: 0;
}

.json-editor {
  min-height: 320px;
  resize: none;
  font-family: SFMono-Regular, Consolas, monospace;
  font-size: 0.72rem;
  line-height: 1.5;
  white-space: pre;
}

.json-action-row {
  display: flex;
  justify-content: flex-end;
  gap: 7px;
}

.editor-footer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 9px 12px max(9px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  border-bottom: 0;
}

.editor-status {
  min-width: 0;
  margin: 0;
  color: #9fb1bd;
  font-size: 0.7rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.editor-status[data-kind="success"] {
  color: #bfe39c;
}

.editor-status[data-kind="error"] {
  color: #ffaea2;
}

.editor-apply-button {
  min-width: 112px;
}

.dialogue-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: end center;
  padding: 18px 12px max(24px, env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(3, 8, 15, 0.2), rgba(3, 8, 15, 0.86));
}

.dialogue-overlay[hidden] {
  display: none;
}

.dialogue-scene {
  width: min(100%, 720px);
  min-height: 190px;
  display: grid;
  grid-template-columns: 124px minmax(0, 1fr);
  align-items: end;
  border: 1px solid rgba(246, 241, 223, 0.3);
  border-radius: 8px;
  overflow: hidden;
  background: rgba(14, 25, 40, 0.98);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.58);
}

.dialogue-portrait {
  align-self: stretch;
  display: grid;
  place-items: end center;
  overflow: hidden;
  background: #244868;
}

.dialogue-portrait[data-portrait="commander-red"] {
  background: #713a3d;
}

.dialogue-portrait[data-portrait="operator"] {
  background: #426253;
}

.portrait-vector {
  width: 138px;
  height: 176px;
  overflow: visible;
  --portrait-uniform: #5ea8d4;
  --portrait-dark: #16395c;
}

[data-portrait="commander-red"] .portrait-vector {
  --portrait-uniform: #d9675f;
  --portrait-dark: #70272d;
}

[data-portrait="operator"] .portrait-vector {
  --portrait-uniform: #75a278;
  --portrait-dark: #315a45;
}

.portrait-shadow { fill: rgba(0, 0, 0, 0.3); }
.portrait-body { fill: var(--portrait-uniform); stroke: #152130; stroke-width: 4; }
.portrait-collar { fill: var(--portrait-dark); stroke: #152130; stroke-width: 3; }
.portrait-neck,
.portrait-face { fill: #efbd8d; stroke: #34251f; stroke-width: 3; }
.portrait-hair { fill: #2c292a; stroke: #191719; stroke-width: 3; }
.portrait-eye { fill: #231e20; }
.portrait-mouth { fill: none; stroke: #8d4f47; stroke-width: 3; stroke-linecap: round; }
.portrait-cap { fill: var(--portrait-uniform); stroke: #152130; stroke-width: 4; }
.portrait-cap-band { fill: var(--portrait-dark); stroke: #152130; stroke-width: 3; }
.portrait-badge { fill: var(--gold); stroke: #6e5725; stroke-width: 3; }
.portrait-headset { fill: none; stroke: #18222d; stroke-width: 7; stroke-linecap: round; }
.portrait-mic { fill: var(--gold); stroke: #18222d; stroke-width: 2; }

.dialogue-copy {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 5px 10px;
  padding: 14px;
}

.dialogue-signal {
  grid-column: 1 / -1;
  color: var(--gold);
  font-size: 0.62rem;
  font-weight: 900;
}

.dialogue-copy strong {
  align-self: center;
  font-size: 1rem;
}

.dialogue-copy p {
  grid-column: 1 / -1;
  min-height: 58px;
  margin: 4px 0 6px;
  color: #e9eadf;
  font-size: 0.87rem;
  line-height: 1.55;
  word-break: keep-all;
}

.dialogue-copy button {
  grid-column: 2;
  min-width: 76px;
  min-height: 38px;
  border: 1px solid rgba(243, 198, 93, 0.55);
  border-radius: 7px;
  color: #241f12;
  background: var(--gold);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 900;
  cursor: pointer;
}

@media (min-width: 820px) {
  .content-editor {
    width: min(94vw, 980px);
    height: min(92dvh, 900px);
    margin: auto;
    border: 1px solid rgba(246, 241, 223, 0.28);
    border-radius: 8px;
  }
}

.editor-page {
  min-height: 100dvh;
  overflow: hidden;
}

.content-editor.content-editor-standalone {
  width: 100%;
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  border: 0;
  border-radius: 0;
}

.combat-effects {
  position: fixed;
  inset: 0;
  z-index: 18;
  overflow: hidden;
  pointer-events: none;
  contain: layout paint;
}

.muzzle-flash,
.projectile,
.impact-effect,
.damage-number {
  position: absolute;
  display: block;
  pointer-events: none;
}

.muzzle-flash {
  width: 34px;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background:
    radial-gradient(circle, #fffbd4 0 14%, #ffd65f 15% 30%, rgba(255, 120, 37, 0.82) 31% 48%, transparent 68%);
  filter: drop-shadow(0 0 10px rgba(255, 192, 65, 0.95));
  animation: muzzle-pop 180ms ease-out both;
}

.muzzle-flash-tank,
.muzzle-flash-artillery {
  width: 48px;
}

.muzzle-flash-gunship {
  width: 40px;
  background:
    radial-gradient(circle, #fff 0 10%, #ffe183 11% 24%, rgba(241, 102, 43, 0.8) 25% 42%, transparent 66%);
}

.projectile {
  z-index: 2;
  left: 0;
  top: 0;
  width: 14px;
  height: 5px;
  border: 1px solid rgba(255, 255, 255, 0.84);
  border-radius: 999px;
  background: #ffe77a;
  box-shadow: 0 0 8px rgba(255, 213, 80, 0.94);
  will-change: transform, opacity;
}

.projectile::before {
  content: "";
  position: absolute;
  right: 70%;
  top: 50%;
  width: 26px;
  height: 3px;
  transform: translateY(-50%);
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, rgba(255, 216, 92, 0.72));
}

.projectile-scout {
  width: 10px;
  height: 4px;
}

.projectile-scout::before {
  width: 18px;
}

.projectile-tank {
  width: 19px;
  height: 8px;
  border-color: #4c351b;
  background: linear-gradient(180deg, #fff4b1, #c88b35);
  box-shadow: 0 0 10px rgba(255, 167, 57, 0.92);
}

.projectile-artillery {
  width: 16px;
  height: 16px;
  border: 2px solid #493018;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, #fff0a8, #c27625 50%, #523019 74%);
  box-shadow: 0 0 12px rgba(255, 139, 45, 0.85);
}

.projectile-artillery::before {
  width: 30px;
  height: 5px;
  background: linear-gradient(90deg, transparent, rgba(104, 96, 83, 0.72));
}

.projectile-gunship {
  width: 22px;
  height: 8px;
  border-color: #55311d;
  background: linear-gradient(180deg, #fff2c1, #e76a34 58%, #853026);
  box-shadow: 0 0 11px rgba(255, 118, 48, 0.86);
}

.projectile-gunship::after {
  content: "";
  position: absolute;
  left: 2px;
  top: -5px;
  border-right: 7px solid #9e3b2a;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
}

.impact-effect {
  z-index: 3;
  width: 70px;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background:
    radial-gradient(circle, #fffce2 0 10%, #ffd85e 11% 24%, #f06b31 25% 43%, rgba(153, 45, 39, 0.72) 44% 54%, transparent 70%);
  filter: drop-shadow(0 0 14px rgba(255, 145, 54, 0.92));
  animation: impact-bloom 300ms cubic-bezier(0.16, 0.78, 0.23, 1) both;
}

.impact-effect::before,
.impact-effect::after {
  content: "";
  position: absolute;
  inset: 12%;
  border: 3px solid rgba(255, 232, 148, 0.82);
  border-radius: 50%;
  animation: impact-ring 320ms ease-out both;
}

.impact-effect::after {
  inset: 26%;
  border-color: rgba(255, 103, 54, 0.82);
  animation-delay: 55ms;
}

.impact-effect-spark {
  width: 45px;
  background:
    radial-gradient(circle, #fff 0 12%, #ffe56e 13% 30%, rgba(255, 123, 40, 0.74) 31% 42%, transparent 66%);
  filter: drop-shadow(0 0 8px rgba(255, 217, 89, 0.84));
}

.impact-effect-heavy {
  width: 92px;
  filter: drop-shadow(0 0 20px rgba(255, 99, 43, 0.94));
}

.impact-effect-rocket {
  width: 78px;
}

.damage-number {
  z-index: 5;
  min-width: 58px;
  display: grid;
  place-items: center;
  gap: 0;
  transform: translate(-50%, -50%);
  color: #fff7d3;
  text-align: center;
  text-shadow:
    0 2px 0 #4a1e18,
    0 0 7px rgba(255, 83, 47, 0.92),
    0 3px 8px rgba(0, 0, 0, 0.72);
  animation: damage-number-rise 780ms cubic-bezier(0.16, 0.74, 0.22, 1) both;
}

.damage-number small,
.damage-number strong {
  display: block;
  letter-spacing: 0;
  line-height: 1;
  white-space: nowrap;
}

.damage-number small {
  color: #ffd991;
  font-size: 0.56rem;
  font-weight: 900;
}

.damage-number strong {
  font-size: 1.46rem;
  font-weight: 1000;
}

.damage-number-critical {
  min-width: 94px;
  color: #fff4a7;
  text-shadow:
    0 3px 0 #7f1f1f,
    0 0 10px rgba(255, 220, 70, 1),
    0 4px 12px rgba(0, 0, 0, 0.82);
  animation: critical-number-rise 1020ms cubic-bezier(0.16, 0.78, 0.2, 1) both;
}

.damage-number-critical small {
  color: #ffdb4d;
  font-size: 0.76rem;
}

.damage-number-critical strong {
  font-size: 2.18rem;
}

.unit-token.is-firing {
  z-index: 7;
  animation: firing-recoil 260ms cubic-bezier(0.2, 0.8, 0.22, 1) both;
}

.unit-token.is-firing-artillery {
  animation-duration: 420ms;
}

.unit-token.is-hit-reacting {
  z-index: 6;
  animation: hit-reaction 260ms ease-out both;
}

.battlefield-wrap.is-impact-shaking {
  animation: impact-shake 280ms ease-out both;
}

@media (max-width: 520px) {
  .editor-control-bar {
    grid-template-columns: 1fr;
  }

  .editor-file-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .editor-stat-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .event-editor-layout {
    grid-template-columns: 1fr;
  }

  .event-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dialogue-scene {
    grid-template-columns: 104px minmax(0, 1fr);
    min-height: 178px;
  }

  .portrait-vector {
    width: 120px;
    height: 160px;
  }

  .dialogue-copy {
    padding: 12px 11px;
  }
}

@media (min-width: 720px) {
  .app-shell {
    width: min(100%, 900px);
    grid-template-columns: minmax(0, 1fr) 320px;
    grid-template-rows: auto auto minmax(0, 1fr);
    align-content: center;
  }

  .topbar {
    grid-column: 1 / -1;
  }

  .status-strip,
  .objective-strip,
  .command-panel {
    grid-column: 2;
  }

  .battlefield-wrap {
    grid-column: 1;
    grid-row: 2 / span 3;
  }

  .battlefield {
    --tile-size: 52px;
  }
}

@media (max-height: 720px) {
  .app-shell {
    gap: 7px;
  }

  .topbar {
    min-height: 54px;
    padding: 8px 10px;
  }

  .objective-strip {
    display: none;
  }

  .battlefield {
    --tile-size: 40px;
  }

  .battle-log {
    height: 44px;
  }
}

@keyframes tile-hop {
  0% {
    transform: translate(-50%, -50%) scale(0.96);
  }

  45% {
    transform: translate(-50%, -58%) scale(1.04);
  }

  100% {
    transform: translate(-50%, -50%) scale(1);
  }
}

@keyframes damage-flash {
  0% {
    filter: brightness(1.55) saturate(1.25);
    transform: translate(-50%, -50%) scale(1.08);
  }

  100% {
    filter: brightness(1);
    transform: translate(-50%, -50%) scale(1);
  }
}

@keyframes hp-flash {
  0%,
  100% {
    box-shadow: 0 0 0 rgba(255, 245, 174, 0);
  }

  45% {
    box-shadow: 0 0 10px rgba(255, 245, 174, 0.95);
  }
}

@keyframes hp-drop {
  0% {
    width: var(--hp-from);
    background-color: #fff48f;
  }

  100% {
    width: var(--hp-to);
    background-color: #c6f26a;
  }
}

@keyframes muzzle-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.28) rotate(0deg);
  }

  38% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.18) rotate(18deg);
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.58) rotate(36deg);
  }
}

@keyframes impact-bloom {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.18) rotate(-18deg);
  }

  38% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.12) rotate(7deg);
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1.42) rotate(18deg);
  }
}

@keyframes impact-ring {
  0% {
    opacity: 0.92;
    transform: scale(0.24);
  }

  100% {
    opacity: 0;
    transform: scale(1.8);
  }
}

@keyframes damage-number-rise {
  0% {
    opacity: 0;
    transform: translate(-50%, -34%) scale(0.56);
  }

  24% {
    opacity: 1;
    transform: translate(-50%, -74%) scale(1.16);
  }

  62% {
    opacity: 1;
    transform: translate(-50%, -112%) scale(1);
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -158%) scale(0.92);
  }
}

@keyframes critical-number-rise {
  0% {
    opacity: 0;
    transform: translate(-50%, -20%) scale(0.38) rotate(-7deg);
  }

  22% {
    opacity: 1;
    transform: translate(-50%, -78%) scale(1.34) rotate(3deg);
  }

  48% {
    opacity: 1;
    transform: translate(-50%, -118%) scale(1.08) rotate(-2deg);
  }

  76% {
    opacity: 1;
    transform: translate(-50%, -146%) scale(1) rotate(0deg);
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -190%) scale(1.08);
  }
}

@keyframes firing-recoil {
  0%,
  100% {
    transform: translate(-50%, -50%) scale(1);
  }

  38% {
    transform: translate(-50%, -50%) scale(0.9) rotate(-4deg);
  }

  62% {
    transform: translate(-50%, -54%) scale(1.06) rotate(2deg);
  }
}

@keyframes hit-reaction {
  0%,
  100% {
    transform: translate(-50%, -50%);
    filter: brightness(1);
  }

  28% {
    transform: translate(-56%, -50%) rotate(-7deg);
    filter: brightness(1.8) saturate(1.4);
  }

  58% {
    transform: translate(-45%, -52%) rotate(5deg);
  }
}

@keyframes impact-shake {
  0%,
  100% {
    transform: translate(0, 0);
  }

  24% {
    transform: translate(-3px, 2px);
  }

  48% {
    transform: translate(3px, -2px);
  }

  72% {
    transform: translate(-2px, -1px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
