:root {
  color-scheme: dark;
  --bg: #101312;
  --surface: #171b19;
  --surface-strong: #1d221f;
  --line: #343a36;
  --line-soft: #272c29;
  --text: #f1f0ea;
  --muted: #a9ada7;
  --faint: #747a75;
  --red: #e85a50;
  --teal: #36b7a7;
  --gold: #e2b94b;
  --danger: #ff776e;
  --focus: #f1f0ea;
  font-family: Inter, "SF Pro Display", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-synthesis: none;
  letter-spacing: 0;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
}

body {
  min-width: 320px;
  overflow-x: hidden;
}

button,
select,
input {
  font: inherit;
  letter-spacing: 0;
}

button,
select {
  color: var(--text);
}

button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.topbar {
  min-height: 68px;
  display: grid;
  grid-template-columns: minmax(250px, 1fr) minmax(260px, 420px) minmax(210px, 1fr);
  align-items: center;
  gap: 24px;
  padding: 10px 22px;
  border-bottom: 1px solid var(--line);
  background: #131614;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid #59605b;
  border-radius: 6px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  font-weight: 850;
}

.brand-kicker,
.panel-kicker,
.match-meta {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
  font-weight: 700;
  letter-spacing: 0;
}

.brand-block h1 {
  margin: 2px 0 0;
  font-size: 18px;
  line-height: 1.2;
  font-weight: 720;
  white-space: nowrap;
}

.match-picker {
  min-width: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.match-picker label,
.speed-control span {
  color: var(--muted);
  font-size: 12px;
}

select {
  min-height: 36px;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0 34px 0 11px;
  background: var(--surface-strong);
}

.broadcast-state {
  justify-self: end;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
  font-size: 12px;
  font-weight: 700;
}

.status-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--faint);
}

.status-dot.live {
  background: var(--red);
  box-shadow: 0 0 0 4px rgb(232 90 80 / 16%);
  animation: broadcast-pulse 1.7s ease-out infinite;
}

.status-dot.replay {
  background: var(--gold);
}

.status-dot.verified {
  background: var(--teal);
}

.integrity-text {
  color: var(--muted);
  font-weight: 500;
}

.workspace {
  height: calc(100vh - 68px);
  min-height: calc(100vh - 68px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
}

.arena-stage {
  height: 100%;
  min-height: 0;
  min-width: 0;
  display: grid;
  grid-template-rows: auto auto minmax(390px, 1fr) auto;
  border-right: 1px solid var(--line);
  background: var(--bg);
  overflow: hidden;
}

.stage-heading {
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px 10px;
}

.stage-heading h2,
.panel-heading h2 {
  margin: 4px 0 0;
  font-size: 20px;
  line-height: 1.15;
  font-weight: 720;
}

.live-return {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--red);
  border-radius: 5px;
  background: transparent;
  color: #ffaca6;
  cursor: pointer;
}

.faction-strip {
  min-height: 76px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-top: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line);
}

.faction-summary {
  min-width: 0;
  padding: 10px 15px 9px;
  border-top: 3px solid var(--faction-color);
}

.faction-summary + .faction-summary {
  border-left: 1px solid var(--line-soft);
}

.faction-name-row,
.resource-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.faction-name {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 13px;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.territory-count {
  flex: 0 0 auto;
  color: var(--faction-color);
  font-size: 12px;
  font-weight: 750;
}

.resource-row {
  justify-content: flex-start;
  gap: 12px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 11px;
}

.resource-row strong {
  margin-left: 3px;
  color: var(--text);
  font-weight: 650;
}

.map-viewport {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background-color: #121614;
  background-image:
    linear-gradient(#242a26 1px, transparent 1px),
    linear-gradient(90deg, #242a26 1px, transparent 1px);
  background-size: 42px 42px;
}

#arenaMap {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
}

.connection-line {
  stroke: #515853;
  stroke-width: 3;
  stroke-linecap: round;
}

.connection-line.frontline {
  stroke: #747c76;
  stroke-dasharray: 8 10;
}

.territory-shape {
  fill: color-mix(in srgb, var(--owner-color) 22%, #171d19);
  stroke: color-mix(in srgb, var(--owner-color) 72%, #dce2dd);
  stroke-width: 1.6;
  stroke-linejoin: round;
  transition: fill 220ms ease, stroke 220ms ease;
}

.territory-shape.active {
  fill: color-mix(in srgb, var(--owner-color) 40%, #171d19);
  stroke: #f4ead9;
  stroke-width: 3;
}

.frontline-edge {
  stroke: #f0d5aa;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 10 7;
  filter: drop-shadow(0 0 4px rgb(240 213 170 / 55%));
  animation: frontline-flow 1.6s linear infinite;
}

.activity-line {
  stroke: var(--event-color, var(--text));
  stroke-width: 7;
  stroke-linecap: round;
  opacity: 0.8;
  animation: activity-flow 1.2s ease-in-out infinite alternate;
}

.attack-line {
  stroke: var(--event-color, var(--text));
  stroke-width: 5;
  stroke-linecap: round;
  stroke-dasharray: 11 7;
  opacity: 0.95;
  filter: drop-shadow(0 0 5px color-mix(in srgb, var(--event-color) 65%, transparent));
}

.transfer-line {
  stroke: var(--event-color, var(--text));
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 3 7;
  opacity: 0.9;
}

.campaign-route {
  stroke: var(--event-color, var(--text));
  stroke-width: 2;
  stroke-linecap: round;
  stroke-dasharray: 5 5;
  opacity: 0.6;
}

.region-node {
  cursor: default;
}

.region-hex {
  fill: #1c211e;
  stroke: var(--owner-color);
  stroke-width: 4;
  transition: fill 220ms ease, stroke 220ms ease, transform 220ms ease;
}

.region-node.active .region-hex {
  fill: color-mix(in srgb, var(--owner-color) 20%, #1c211e);
  stroke-width: 7;
  filter: drop-shadow(0 0 12px color-mix(in srgb, var(--owner-color) 55%, transparent));
}

.region-post {
  fill: var(--owner-color);
  stroke: #f4f1e8;
  stroke-width: 1.5;
}

.region-node.historical .region-name,
.region-node.historical .region-type {
  paint-order: stroke;
  stroke: #111512;
  stroke-linejoin: round;
}

.garrison-label {
  fill: #e4dfd3;
  font-size: 8px;
  font-weight: 750;
  text-anchor: middle;
  paint-order: stroke;
  stroke: #111512;
  stroke-width: 3px;
}

.region-node.historical .region-name {
  font-size: 13px;
  stroke-width: 4px;
}

.region-node.historical .region-type {
  fill: #d3d8d1;
  font-size: 8px;
  font-weight: 650;
  stroke-width: 3px;
}

.region-name {
  fill: var(--text);
  font-size: 17px;
  font-weight: 760;
  text-anchor: middle;
  pointer-events: none;
}

.region-type {
  fill: var(--owner-color);
  font-size: 10px;
  font-weight: 800;
  text-anchor: middle;
  pointer-events: none;
}

.owner-name {
  fill: var(--muted);
  font-size: 11px;
  text-anchor: middle;
  pointer-events: none;
}

.army-marker circle {
  fill: var(--owner-color);
  stroke: #101312;
  stroke-width: 3;
}

.army-marker.engaged circle {
  stroke: #ffd18b;
  stroke-width: 5;
  filter: drop-shadow(0 0 6px rgb(255 209 139 / 58%));
}

.army-marker text {
  fill: #0d100f;
  font-size: 11px;
  font-weight: 850;
  text-anchor: middle;
  dominant-baseline: central;
}

.battle-marker circle {
  fill: #221a16;
  stroke: #ffd18b;
  stroke-width: 3;
  filter: drop-shadow(0 0 8px rgb(255 209 139 / 72%));
}

.battle-icon,
.battle-label,
.battle-duration {
  fill: #ffe0aa;
  text-anchor: middle;
  paint-order: stroke;
  stroke: #16110e;
  stroke-width: 4px;
  stroke-linejoin: round;
}

.battle-icon {
  font-size: 20px;
  dominant-baseline: central;
}

.battle-label {
  font-size: 13px;
  font-weight: 850;
}

.battle-duration {
  fill: #f5d6a4;
  font-size: 9px;
  font-weight: 750;
}

.map-legend {
  position: absolute;
  top: 14px;
  left: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: rgb(16 19 18 / 88%);
  backdrop-filter: blur(8px);
  font-size: 11px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.legend-swatch {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--faction-color);
}

.legend-frontline {
  width: 18px;
  border-top: 2px dashed #f0d5aa;
}

.map-callout {
  position: absolute;
  right: 16px;
  bottom: 14px;
  max-width: min(420px, calc(100% - 32px));
  padding: 9px 11px;
  border-left: 3px solid var(--gold);
  background: rgb(16 19 18 / 88%);
  color: var(--text);
  font-size: 12px;
  line-height: 1.45;
}

.timeline-dock {
  min-height: 104px;
  display: grid;
  grid-template-columns: auto minmax(180px, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: 14px 20px;
  border-top: 1px solid var(--line);
  background: #151917;
}

.playback-controls {
  display: grid;
  grid-template-columns: repeat(3, 38px);
  gap: 6px;
}

.icon-button {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface-strong);
  color: var(--text);
  cursor: pointer;
  font-size: 17px;
}

.icon-button:hover:not(:disabled),
.segment:hover,
.live-return:hover {
  border-color: #68706a;
  background: #252b27;
}

.icon-button:disabled {
  color: #555b57;
  cursor: default;
}

.play-button {
  border-color: var(--teal);
  color: #8ce4d9;
}

.timeline-track {
  min-width: 0;
}

.timeline-labels {
  display: flex;
  justify-content: space-between;
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 11px;
}

#timeline {
  --progress: 0%;
  width: 100%;
  height: 22px;
  margin: 0;
  appearance: none;
  background: transparent;
  cursor: pointer;
}

#timeline::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--teal) var(--progress), #39403b var(--progress));
}

#timeline::-webkit-slider-thumb {
  width: 18px;
  height: 18px;
  margin-top: -7px;
  appearance: none;
  border: 3px solid var(--text);
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 0 3px #101312;
}

#timeline::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: #39403b;
}

#timeline::-moz-range-progress {
  height: 4px;
  background: var(--teal);
}

#timeline::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 3px solid var(--text);
  border-radius: 50%;
  background: var(--teal);
}

.timeline-ticks {
  display: flex;
  justify-content: space-between;
  height: 7px;
  margin-top: 2px;
}

.timeline-tick {
  width: 1px;
  height: 5px;
  background: #4a514c;
}

.speed-control {
  display: grid;
  grid-template-columns: auto 78px;
  align-items: center;
  gap: 8px;
}

.speed-control select {
  min-height: 36px;
}

.intel-panel {
  min-width: 0;
  max-height: calc(100vh - 68px);
  display: grid;
  grid-template-rows: minmax(260px, 44%) minmax(300px, 56%);
  background: var(--surface);
  overflow: hidden;
}

.decision-section,
.event-section {
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.decision-section {
  border-bottom: 1px solid var(--line);
}

.panel-heading {
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 16px 11px;
  border-bottom: 1px solid var(--line-soft);
}

.panel-heading h2 {
  font-size: 16px;
}

.panel-count {
  color: var(--muted);
  font-size: 12px;
}

.decision-list,
.event-list {
  min-height: 0;
  margin: 0;
  overflow-y: auto;
  scrollbar-color: #4d554f transparent;
  scrollbar-width: thin;
}

.decision-row {
  position: relative;
  padding: 13px 15px 13px 18px;
  border-bottom: 1px solid var(--line-soft);
}

.decision-row::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 3px;
  background: var(--faction-color);
}

.decision-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.decision-faction {
  color: var(--faction-color);
  font-size: 13px;
  font-weight: 800;
}

.model-latency {
  color: var(--muted);
  font-size: 10px;
  white-space: nowrap;
}

.assessment {
  margin: 7px 0 9px;
  color: #d4d6d1;
  font-size: 12px;
  line-height: 1.55;
}

.order-line {
  display: grid;
  grid-template-columns: 7px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.order-status {
  width: 7px;
  height: 7px;
  border-radius: 2px;
  background: var(--teal);
}

.order-line.rejected .order-status {
  background: var(--danger);
}

.empty-panel {
  display: grid;
  place-items: center;
  min-height: 120px;
  padding: 24px;
  color: var(--faint);
  font-size: 12px;
  text-align: center;
}

.segments {
  display: grid;
  grid-template-columns: repeat(2, 48px);
  border: 1px solid var(--line);
  border-radius: 5px;
  overflow: hidden;
}

.segment {
  min-height: 30px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
}

.segment + .segment {
  border-left: 1px solid var(--line);
}

.segment.active {
  background: var(--text);
  color: var(--bg);
  font-weight: 750;
}

.event-list {
  padding: 0;
  list-style: none;
}

.event-item {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 10px;
  padding: 11px 15px;
  border-bottom: 1px solid var(--line-soft);
}

.event-seq {
  color: var(--faint);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.event-copy {
  color: #d6d8d3;
  font-size: 12px;
  line-height: 1.45;
}

.event-item.battle .event-copy {
  color: #ffd18b;
}

.event-item.capture .event-copy {
  color: #89e0d5;
  font-weight: 700;
}

.loading-state {
  position: fixed;
  inset: 68px 0 0;
  z-index: 20;
  display: grid;
  place-content: center;
  gap: 14px;
  background: #101312;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.loading-state.hidden {
  display: none;
}

.loading-line {
  width: 160px;
  height: 3px;
  overflow: hidden;
  background: #313733;
}

.loading-line::after {
  content: "";
  display: block;
  width: 48px;
  height: 100%;
  background: var(--teal);
  animation: loading-scan 1.1s ease-in-out infinite;
}

.toast {
  position: fixed;
  z-index: 30;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  padding: 11px 13px;
  border: 1px solid var(--danger);
  border-radius: 5px;
  background: #241918;
  color: #ffd2cf;
  font-size: 12px;
}

@keyframes broadcast-pulse {
  0% { box-shadow: 0 0 0 0 rgb(232 90 80 / 35%); }
  70% { box-shadow: 0 0 0 7px rgb(232 90 80 / 0%); }
  100% { box-shadow: 0 0 0 0 rgb(232 90 80 / 0%); }
}

@keyframes activity-flow {
  from { opacity: 0.45; }
  to { opacity: 0.95; }
}

@keyframes frontline-flow {
  to { stroke-dashoffset: -17; }
}

@keyframes loading-scan {
  from { transform: translateX(-48px); }
  to { transform: translateX(160px); }
}

@media (max-width: 1050px) {
  .topbar {
    grid-template-columns: minmax(220px, 1fr) minmax(230px, 320px) auto;
    gap: 14px;
  }

  .workspace {
    grid-template-columns: minmax(0, 1fr) 340px;
  }

  .resource-row {
    gap: 7px;
  }
}

@media (max-width: 820px) {
  .topbar {
    grid-template-columns: 1fr auto;
    min-height: 116px;
    padding: 10px 14px;
  }

  .match-picker {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .broadcast-state {
    grid-column: 2;
    grid-row: 1;
  }

  .integrity-text {
    display: none;
  }

  .workspace {
    height: auto;
    min-height: calc(100vh - 116px);
    display: block;
  }

  .arena-stage {
    height: auto;
    min-height: calc(100vh - 116px);
    border-right: 0;
    overflow: visible;
  }

  .intel-panel {
    max-height: none;
    grid-template-rows: auto auto;
    border-top: 1px solid var(--line);
  }

  .decision-list,
  .event-list {
    max-height: 460px;
  }

  .loading-state {
    inset: 116px 0 0;
  }
}

@media (max-width: 560px) {
  .brand-block h1 {
    max-width: 190px;
    overflow: hidden;
    font-size: 16px;
    text-overflow: ellipsis;
  }

  .broadcast-state {
    font-size: 11px;
  }

  .stage-heading {
    min-height: 64px;
    padding: 12px 14px 9px;
  }

  .stage-heading h2 {
    font-size: 18px;
  }

  .faction-strip {
    min-height: 68px;
  }

  .faction-summary {
    padding: 8px 7px 7px;
  }

  .faction-name {
    font-size: 11px;
  }

  .territory-count {
    font-size: 10px;
  }

  .resource-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2px;
    margin-top: 6px;
    font-size: 9px;
  }

  .resource-row span {
    display: grid;
  }

  .resource-row strong {
    margin: 0;
    font-size: 10px;
  }

  .map-viewport,
  #arenaMap {
    min-height: 360px;
  }

  .map-legend {
    right: 10px;
    left: 10px;
    justify-content: center;
  }

  .map-callout {
    right: 10px;
    bottom: 10px;
    left: 10px;
    max-width: none;
  }

  .timeline-dock {
    grid-template-columns: auto minmax(0, 1fr);
    gap: 12px;
    padding: 12px 14px;
  }

  .playback-controls {
    grid-template-columns: repeat(3, 34px);
  }

  .icon-button {
    width: 34px;
    height: 34px;
  }

  .speed-control {
    grid-column: 1 / -1;
    justify-self: end;
  }
}

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