/* Original visual foundation; feature-specific rules follow in separate stylesheets. */
:root {
  --bg: #10130f;
  --panel: #f8faf6;
  --panel-2: #eef3e9;
  --text: #182018;
  --muted: #60705e;
  --line: #cdd8c6;
  --green: #2f7d4d;
  --blue: #2d6fb0;
  --red: #b8463d;
  --gold: #b98724;
  --ink: #111711;
  --shadow: 0 24px 70px rgba(17, 23, 17, .18);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font: 16px/1.45 ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(850px 480px at 8% -10%, rgba(93, 135, 83, .28), transparent 65%),
    radial-gradient(740px 520px at 100% 0%, rgba(184, 70, 61, .16), transparent 62%),
    linear-gradient(180deg, #eef3e9, #dfe9dc 58%, #cfdcc9);
}

button,
select {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-weight: 800;
}

button { padding: .62rem .78rem; cursor: pointer; }
button:disabled { opacity: .48; cursor: not-allowed; }
button:hover:not(:disabled),
button:focus-visible,
select:focus-visible {
  outline: 2px solid rgba(47, 125, 77, .55);
  outline-offset: 2px;
}

.primary {
  border-color: rgba(47, 125, 77, .75);
  background: var(--green);
  color: #fff;
}

.shell {
  width: min(1420px, calc(100% - 28px));
  margin: 0 auto;
  padding: 28px 0 38px;
}

.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 1rem;
  align-items: center;
  margin-bottom: 1rem;
}

.back-link {
  color: #235f3b;
  font-weight: 900;
  text-decoration: none;
}

.eyebrow {
  margin: 0 0 .2rem;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 900;
  letter-spacing: .04em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2.1rem, 4.6vw, 4.9rem);
  line-height: .95;
  letter-spacing: 0;
}

.turn-chip {
  justify-self: end;
  min-width: 118px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .42rem .72rem;
  background: rgba(255, 255, 255, .82);
  color: var(--muted);
  font-weight: 900;
  text-align: center;
}

.game-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 1rem;
  align-items: stretch;
}

.map-panel,
.command-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(248, 250, 246, .95);
  box-shadow: var(--shadow);
}

.map-panel {
  min-height: 710px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.map-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  align-items: end;
  justify-content: space-between;
  padding: .85rem;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .72);
}

.map-select {
  display: grid;
  gap: .24rem;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 900;
  text-transform: uppercase;
}

select { padding: .52rem .7rem; min-width: 190px; }

.battle-map {
  width: 100%;
  height: 100%;
  min-height: 620px;
  display: block;
  background: linear-gradient(180deg, #c6dfec, #d8e6dc 48%, #bbcfae);
}

.territory {
  cursor: pointer;
  stroke: rgba(17, 23, 17, .78);
  stroke-width: 3;
  vector-effect: non-scaling-stroke;
  transition: filter .16s ease, stroke-width .16s ease;
}

.territory:hover,
.territory:focus-visible {
  filter: brightness(1.08);
  outline: none;
  stroke-width: 5;
}

.territory.player { fill: #4f9967; }
.territory.ai { fill: #c45a50; }
.territory.neutral { fill: #d7c894; }
.territory.selected-from { stroke: #104c2d; stroke-width: 7; }
.territory.selected-to { stroke: #203e73; stroke-width: 7; }
.territory.attackable { filter: saturate(1.25) brightness(1.04); }

.battle-cell {
  opacity: .78;
  stroke: rgba(17, 23, 17, .32);
  stroke-width: 1.4;
  vector-effect: non-scaling-stroke;
}

.battle-cell.selectable {
  cursor: pointer;
  opacity: .95;
  stroke: #10213a;
  stroke-width: 3;
  pointer-events: auto;
}

.battle-cell.selected-cell {
  stroke: #ffffff;
  stroke-width: 5;
  filter: drop-shadow(0 0 9px rgba(16, 33, 58, .7));
}

.battle-cell.knocked-out {
  fill: rgba(24, 32, 24, .28);
  opacity: .42;
}

.battle-cell.unassigned,
.battle-key.unassigned {
  fill: #e2e8df;
  background: #e2e8df;
}

.battle-cell.setup-editable {
  cursor: copy;
  opacity: 1;
  stroke: #111711;
  stroke-width: 3;
  pointer-events: auto;
}

.battle-cell-label {
  pointer-events: none;
  fill: #111711;
  font-size: 13px;
  font-weight: 900;
  text-anchor: middle;
  paint-order: stroke;
  stroke: rgba(255, 255, 255, .74);
  stroke-width: 3;
  stroke-linejoin: round;
}

.battle-cell-label.knocked-out {
  fill: rgba(24, 32, 24, .52);
  text-decoration: line-through;
}

.battle-cell.dice,
.battle-key.dice { fill: #d95b45; background: #d95b45; }
.battle-cell.rts,
.battle-key.rts { fill: #2f78bd; background: #2f78bd; }
.battle-cell.fps,
.battle-key.fps { fill: #7a58a8; background: #7a58a8; }
.battle-cell.lane_push,
.battle-key.lane_push { fill: #7b5b3a; background: #7b5b3a; }

.territory-label {
  pointer-events: none;
  fill: #111711;
  font-size: 24px;
  font-weight: 900;
  paint-order: stroke;
  stroke: rgba(255, 255, 255, .72);
  stroke-width: 5;
  stroke-linejoin: round;
}

.troop-label {
  pointer-events: none;
  fill: #fff;
  font-size: 22px;
  font-weight: 900;
  text-anchor: middle;
}

.troop-disc {
  pointer-events: none;
  fill: rgba(17, 23, 17, .82);
  stroke: rgba(255, 255, 255, .86);
  stroke-width: 2;
}

.command-panel {
  display: grid;
  gap: .85rem;
  align-content: start;
  padding: .9rem;
}

.phase-card,
.selection-box,
.metric,
.map-meta,
.event-log {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.phase-card { padding: .85rem; }
.phase-card p { margin: .35rem 0 0; color: var(--muted); }
.phase-label {
  color: #235f3b;
  font-size: .82rem;
  font-weight: 900;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.selection-grid,
.score-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .65rem;
}

.selection-box,
.metric {
  min-height: 78px;
  padding: .7rem;
}

.selection-box span,
.metric span {
  display: block;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.selection-box strong,
.metric strong {
  display: block;
  margin-top: .12rem;
  font-size: 1.42rem;
  line-height: 1.08;
  font-variant-numeric: tabular-nums;
}

.selection-box--wide {
  grid-column: 1 / -1;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .6rem;
}

.setup-panel {
  display: grid;
  gap: .65rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .72rem;
  background: #fff;
}

.setup-panel.is-hidden {
  display: none;
}

.setup-title {
  color: #235f3b;
  font-size: .82rem;
  font-weight: 900;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.setup-type-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .48rem;
}

.setup-type {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .38rem;
  min-width: 0;
  padding-inline: .45rem;
}

.setup-type.is-active {
  border-color: #235f3b;
  box-shadow: inset 0 0 0 2px rgba(47, 125, 77, .22);
}

.setup-panel p {
  margin: 0;
  color: var(--muted);
  font-size: .88rem;
  font-weight: 700;
}

.map-meta {
  padding: .72rem;
  color: var(--muted);
  font-size: .88rem;
  font-weight: 700;
}

.battle-legend {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .46rem .6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .72rem;
  background: #fff;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 900;
}

.battle-legend span {
  display: inline-flex;
  gap: .38rem;
  align-items: center;
  min-width: 0;
}

.battle-key {
  width: .78rem;
  height: .78rem;
  flex: 0 0 auto;
  border: 1px solid rgba(17, 23, 17, .22);
  border-radius: 3px;
}

.event-log {
  min-height: 220px;
  max-height: 260px;
  margin: 0;
  padding: .72rem .72rem .72rem 1.8rem;
  overflow: auto;
  color: var(--muted);
  font-size: .9rem;
}

.event-log li + li { margin-top: .45rem; }

.moba-panel {
  margin-top: 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(248, 250, 246, .97);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.moba-panel.is-hidden {
  display: none;
}

.moba-head {
  display: flex;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  padding: .9rem 1rem;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.moba-head h2 {
  margin: .1rem 0 0;
  font-size: 1.35rem;
  line-height: 1.1;
}

.moba-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 1rem;
  padding: 1rem;
}

.moba-field {
  display: grid;
  gap: .75rem;
  align-content: start;
}

.moba-map {
  width: 100%;
  min-height: 430px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #d7e1ca;
}

.moba-ground {
  fill: #c8d7bd;
  stroke: #49623f;
  stroke-width: 3;
}

.moba-lane {
  fill: none;
  stroke: #9a8352;
  stroke-width: 22;
  stroke-linecap: round;
}

.moba-switch {
  fill: none;
  stroke: rgba(84, 69, 45, .58);
  stroke-width: 11;
  stroke-dasharray: 18 13;
  stroke-linecap: round;
}

.moba-river {
  fill: none;
  stroke: rgba(47, 120, 189, .52);
  stroke-width: 18;
  stroke-linecap: round;
}

.moba-base rect,
.moba-towers circle {
  stroke: rgba(17, 23, 17, .78);
  stroke-width: 3;
}

.moba-base text,
.moba-camps text {
  fill: #fff;
  font-size: 24px;
  font-weight: 900;
  text-anchor: middle;
  paint-order: stroke;
  stroke: rgba(17, 23, 17, .7);
  stroke-width: 4;
}

.moba-base.attacker rect,
.moba-towers.attacker circle,
.moba-wave.attacker circle {
  fill: #4f9967;
}

.moba-base.defender rect,
.moba-towers.defender circle,
.moba-wave.defender circle {
  fill: #c45a50;
}

.moba-camps circle {
  fill: #7b5b3a;
  stroke: #fff;
  stroke-width: 3;
}

.moba-wave circle {
  stroke: rgba(255, 255, 255, .9);
  stroke-width: 2;
}

.moba-wave.is-hidden {
  display: none;
}

.lane-sim-layer {
  pointer-events: none;
}

.lane-structure {
  stroke: rgba(255, 255, 255, .92);
  stroke-width: 3;
  filter: drop-shadow(0 2px 3px rgba(17, 23, 17, .32));
  transition: opacity .2s ease, r .2s ease;
}

.lane-structure.attacker { fill: #2f7d4d; }
.lane-structure.defender { fill: #b8463d; }
.lane-structure.base { fill-opacity: .82; }

.lane-unit {
  stroke: #fff;
  stroke-width: 2;
  transition: cx .45s linear, cy .45s linear;
}

.lane-unit.attacker.footman { fill: #58b870; }
.lane-unit.attacker.guard { fill: #1f7a45; }
.lane-unit.attacker.pike { fill: #a2cf54; }
.lane-unit.attacker.bow { fill: #0b9a7a; }
.lane-unit.defender.footman { fill: #e06a57; }
.lane-unit.defender.guard { fill: #a9332e; }
.lane-unit.defender.pike { fill: #d78b35; }
.lane-unit.defender.bow { fill: #c04e75; }

.lane-unit-label {
  fill: #111711;
  font-size: 10px;
  font-weight: 900;
  text-anchor: middle;
  paint-order: stroke;
  pointer-events: none;
  stroke: rgba(255, 255, 255, .82);
  stroke-width: 3;
  stroke-linejoin: round;
}

.moba-side {
  display: grid;
  gap: .75rem;
  align-content: start;
}

.moba-stat,
.divert-control,
.combat-stream,
.hero-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: .75rem;
}

.moba-stat span,
.divert-control span,
.combat-stream > span,
.hero-card span {
  display: block;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.combat-stream {
  padding: .75rem;
  background: #fff;
}

.combat-stream ol {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 1.25rem;
  max-height: 170px;
  margin: .5rem 0 0;
  padding-left: 1.2rem;
  overflow: auto;
  color: var(--muted);
  font-size: .82rem;
}

.combat-stream li + li {
  margin-top: .24rem;
}

.divert-control {
  display: grid;
  gap: .45rem;
}

.divert-control input {
  width: 100%;
  accent-color: var(--green);
}

.divert-control strong {
  font-size: 1.05rem;
}

.moba-stat strong {
  display: block;
  margin-top: .15rem;
  font-size: 1.2rem;
  line-height: 1.15;
}

.moba-heroes {
  display: grid;
  gap: .75rem;
}

.unit-stats {
  display: grid;
  gap: .5rem;
}

.unit-card {
  display: grid;
  gap: .15rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .55rem .65rem;
  background: #fff;
}

.unit-card span {
  color: var(--muted);
  font-size: .74rem;
  font-weight: 900;
  text-transform: uppercase;
}

.unit-card strong {
  font-size: .95rem;
}

.unit-card small {
  color: var(--muted);
  font-weight: 800;
}

.hero-card h3 {
  margin: .2rem 0 .5rem;
  font-size: 1.1rem;
}

.ability-list {
  display: grid;
  gap: .35rem;
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
  font-size: .9rem;
}

.ability-list strong {
  color: var(--text);
}

@media (max-width: 980px) {
  .topbar { grid-template-columns: 1fr; }
  .turn-chip { justify-self: start; }
  .game-grid { grid-template-columns: 1fr; }
  .map-panel { min-height: 560px; }
  .battle-map { min-height: 500px; }
  .command-panel { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .phase-card,
  .selection-grid,
  .action-grid,
  .setup-panel,
  .score-grid,
  .battle-legend,
  .map-meta,
  .event-log { grid-column: 1 / -1; }
  .moba-grid { grid-template-columns: 1fr; }
  .moba-map { min-height: 360px; }
}

@media (max-width: 620px) {
  .shell { width: min(100% - 18px, 1420px); padding-top: 18px; }
  .map-panel { min-height: 480px; }
  .battle-map { min-height: 430px; }
  .selection-grid,
  .score-grid,
  .action-grid { grid-template-columns: 1fr; }
  .map-toolbar { align-items: stretch; }
  .map-select,
  select,
  .map-toolbar button { width: 100%; }
  .moba-head { align-items: stretch; flex-direction: column; }
}
