:root {
  --panel: rgba(10, 25, 40, 0.9);
  --panel-border: rgba(121, 187, 255, 0.18);
  --text: #edf5ff;
  --muted: #9fbbd2;
  --accent: #5ee7ff;
  --danger: #ff6f61;
  --warning: #ffca63;
  --good: #69f0ae;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top, rgba(94, 231, 255, 0.12), transparent 34%),
    linear-gradient(180deg, #0b1520 0%, #04080d 100%);
}

.app-shell {
  max-width: 1680px;
  margin: 0 auto;
  padding: clamp(10px, 1.8vw, 18px);
}

.topbar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(0, 1.2fr);
  gap: 16px 20px;
  align-items: end;
  margin-bottom: 16px;
}

.topbar-title {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--accent);
  font-size: 0.72rem;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.8rem, 3vw, 2.6rem);
}

h2 {
  font-size: 1rem;
  margin-bottom: 12px;
  letter-spacing: 0.04em;
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
  gap: 10px;
  width: 100%;
}

.stat-card,
.panel,
.viewport-card,
.debug-panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  box-shadow: 0 18px 36px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(10px);
}

.stat-card {
  padding: 12px 14px;
}

.stat-card span,
.intel-grid span,
.message-log,
.panel-note,
.panel-subtitle,
small,
.viewport-card span,
.debug-label,
.timeline-empty {
  color: var(--muted);
}

.stat-card strong,
.intel-grid strong,
.viewport-card strong {
  display: block;
  margin-top: 4px;
  font-size: 1.1rem;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.75fr) minmax(340px, 0.95fr);
  gap: clamp(12px, 1.5vw, 18px);
  align-items: start;
}

.battlefield-panel {
  position: relative;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.battlefield-stage {
  position: relative;
  min-width: 0;
  width: 100%;
  aspect-ratio: 1100 / 680;
  min-height: clamp(280px, 36vh, 420px);
  max-height: min(78vh, 840px);
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 24px;
  background:
    linear-gradient(180deg, rgba(10, 22, 35, 0.78), rgba(8, 14, 22, 0.95)),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.028) 0, rgba(255, 255, 255, 0.028) 1px, transparent 1px, transparent 42px),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.028) 0, rgba(255, 255, 255, 0.028) 1px, transparent 1px, transparent 42px);
  border: 1px solid var(--panel-border);
  box-shadow: 0 26px 46px rgba(0, 0, 0, 0.24);
  cursor: crosshair;
  touch-action: none;
}

#gameCanvas.panning {
  cursor: grabbing;
}

.pause-overlay {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 3;
  min-width: min(320px, calc(100% - 32px));
  max-width: min(420px, calc(100% - 32px));
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  text-align: center;
  pointer-events: none;
  background: rgba(7, 17, 27, 0.88);
  border: 1px solid rgba(121, 187, 255, 0.3);
  border-radius: 18px;
  box-shadow: 0 26px 48px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(12px);
}

.pause-overlay strong {
  font-size: 1.15rem;
  color: var(--text);
}

.pause-overlay span {
  color: var(--muted);
}

.battle-overlay {
  position: absolute;
  inset: 16px 16px auto;
  pointer-events: none;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
}

.alert-banner {
  max-width: min(58%, 560px);
  background: rgba(7, 17, 27, 0.72);
  border: 1px solid rgba(121, 187, 255, 0.24);
  border-radius: 14px;
  padding: 10px 14px;
  font-size: 0.92rem;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
  max-width: min(42%, 420px);
  background: rgba(7, 17, 27, 0.72);
  border: 1px solid rgba(121, 187, 255, 0.24);
  border-radius: 14px;
  padding: 10px 12px;
  font-size: 0.82rem;
}

.legend span {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.viewport-strip {
  position: static;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  pointer-events: none;
}

.viewport-card {
  min-width: 0;
  padding: 12px 14px;
  background: rgba(7, 17, 27, 0.76);
}

.viewport-help {
  text-align: right;
}

.viewport-help-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
  pointer-events: auto;
}

.pause-button {
  min-width: 130px;
  pointer-events: auto;
}

.debug-panel {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 2;
  min-width: 148px;
  max-width: min(210px, calc(100% - 24px));
  padding: 7px 9px;
  background: rgba(7, 17, 27, 0.66);
  font-size: 0.68rem;
  line-height: 1.25;
  pointer-events: none;
  border-radius: 10px;
}

.debug-panel strong {
  color: var(--accent);
  font-size: 0.68rem;
  font-weight: 700;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.debug-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 3px 5px;
  align-items: center;
}

.debug-row + .debug-row {
  margin-top: 3px;
}

.debug-wide {
  grid-template-columns: auto minmax(0, 1fr);
}

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  display: inline-block;
}

.swatch.city {
  background: var(--warning);
}

.swatch.launcher {
  background: var(--accent);
}

.swatch.launcher-mk2 {
  background: #8cff75;
}

.swatch.factory {
  background: #88ffcc;
}

.swatch.treasury {
  background: #ffd76f;
}

.swatch.airport {
  background: #8fb7ff;
}

.swatch.missile {
  background: var(--danger);
}

.swatch.radar {
  background: rgba(94, 231, 255, 0.5);
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel {
  padding: 16px;
}

.panel-header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 10px;
}

.panel-header-row h2 {
  margin-bottom: 4px;
}

.panel-subtitle {
  margin: 0;
  font-size: 0.84rem;
}

.button-grid,
.upgrade-list,
.district-list {
  display: grid;
  gap: 10px;
}

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

button {
  appearance: none;
  border: 1px solid rgba(121, 187, 255, 0.2);
  border-radius: 14px;
  background: rgba(14, 28, 42, 0.95);
  color: var(--text);
  padding: 12px 14px;
  font: inherit;
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

button:hover {
  transform: translateY(-1px);
  border-color: rgba(94, 231, 255, 0.42);
}

button.active,
button:focus-visible {
  outline: none;
  border-color: rgba(94, 231, 255, 0.82);
  background: rgba(18, 45, 60, 0.95);
}

button:disabled {
  opacity: 0.52;
  cursor: not-allowed;
  transform: none;
}

button small {
  display: block;
  margin-top: 4px;
  font-size: 0.78rem;
}

.upgrade-button,
.primary-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
  width: 100%;
}

.upgrade-button strong {
  color: var(--accent);
}

.panel-note {
  margin: 10px 0 0;
  font-size: 0.86rem;
  line-height: 1.4;
}

.strategy-panel {
  gap: 12px;
}

.threat-timeline {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.timeline-row,
.timeline-empty {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) auto;
  gap: 4px 10px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(9, 20, 31, 0.7);
  border: 1px solid rgba(121, 187, 255, 0.12);
}

.timeline-row small {
  grid-column: 1 / -1;
  font-size: 0.78rem;
}

.timeline-row strong {
  color: var(--accent);
}

.timeline-fast strong,
.timeline-hypersonic strong {
  color: #ffd3a1;
}

.timeline-drone strong,
.timeline-cluster strong {
  color: #d8d5c8;
}

.district-list {
  gap: 12px;
}

.district-card {
  padding: 14px;
  border-radius: 16px;
  border: 1px solid rgba(121, 187, 255, 0.16);
  background: rgba(8, 18, 29, 0.82);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.district-card.selected {
  border-color: rgba(94, 231, 255, 0.72);
  box-shadow: 0 0 0 1px rgba(94, 231, 255, 0.15);
}

.district-card.pressure-stable {
  background: linear-gradient(180deg, rgba(8, 20, 29, 0.9), rgba(8, 18, 29, 0.82));
}

.district-card.pressure-strained {
  border-color: rgba(255, 202, 99, 0.34);
}

.district-card.pressure-overloaded {
  border-color: rgba(255, 154, 99, 0.42);
}

.district-card.pressure-critical {
  border-color: rgba(255, 111, 97, 0.5);
  box-shadow: 0 0 0 1px rgba(255, 111, 97, 0.12);
}

.district-card-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.district-card-head strong {
  display: inline-block;
  margin-left: 8px;
}

.district-role-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.role-industrial {
  background: rgba(136, 255, 204, 0.16);
  color: #8bffd0;
}

.role-civil {
  background: rgba(255, 202, 99, 0.16);
  color: #ffd891;
}

.role-air {
  background: rgba(143, 183, 255, 0.18);
  color: #bed2ff;
}

.role-treasury {
  background: rgba(255, 215, 111, 0.16);
  color: #ffe08f;
}

.district-pressure {
  color: var(--muted);
  font-size: 0.82rem;
}

.district-role-name,
.district-assets {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.district-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.district-metrics span {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
}

.district-metrics strong {
  display: inline;
  color: var(--text);
  margin-left: 4px;
}

.district-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.district-tag {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
}

.tag-alert {
  color: #7ff6ff;
  background: rgba(94, 231, 255, 0.12);
}

.tag-penalty {
  color: #ffd18d;
  background: rgba(255, 190, 110, 0.14);
}

.tag-retool {
  color: #c9c7ff;
  background: rgba(168, 164, 255, 0.13);
}

.district-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.district-action {
  padding: 10px 10px;
  border-radius: 12px;
  font-size: 0.8rem;
}

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

.message-log {
  margin-top: 14px;
  min-height: 130px;
  max-height: 220px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 4px;
}

.message {
  border-left: 2px solid rgba(94, 231, 255, 0.4);
  padding-left: 10px;
  font-size: 0.88rem;
  line-height: 1.4;
}

.message.warning {
  border-color: rgba(255, 202, 99, 0.8);
}

.message.danger {
  border-color: rgba(255, 111, 97, 0.8);
}

.hidden {
  display: none;
}

.game-over-panel {
  border-color: rgba(255, 111, 97, 0.3);
}

@media (max-width: 1380px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    align-items: start;
  }

  .build-panel,
  .upgrade-panel,
  .intel-panel {
    grid-column: span 4;
  }

  .strategy-panel,
  .game-over-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 1120px) {
  .topbar {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .battle-overlay {
    inset: 12px 12px auto;
    flex-direction: column;
    align-items: stretch;
  }

  .alert-banner,
  .legend {
    max-width: none;
  }

  .legend {
    justify-content: flex-start;
  }

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

  .build-panel,
  .upgrade-panel {
    grid-column: span 1;
  }

  .strategy-panel,
  .intel-panel,
  .game-over-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 10px;
  }

  .status-strip,
  .button-grid,
  .intel-grid,
  .sidebar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .battlefield-stage {
    min-height: clamp(240px, 42vh, 320px);
  }

  .viewport-strip {
    grid-template-columns: 1fr;
  }

  .viewport-help {
    text-align: left;
  }

  .viewport-help-actions {
    justify-content: flex-start;
  }

  .panel {
    padding: 14px;
  }

  button {
    padding: 11px 12px;
  }

  .debug-panel {
    display: none;
  }

  .district-metrics,
  .district-actions {
    grid-template-columns: 1fr 1fr;
  }

  .build-panel,
  .upgrade-panel,
  .strategy-panel,
  .intel-panel,
  .game-over-panel {
    grid-column: span 2;
  }
}

@media (max-width: 560px) {
  .status-strip,
  .sidebar,
  .intel-grid {
    grid-template-columns: 1fr 1fr;
  }

  .button-grid,
  .district-actions {
    grid-template-columns: 1fr 1fr;
  }

  .legend {
    font-size: 0.76rem;
    gap: 8px;
    padding: 8px 10px;
  }

  .alert-banner {
    font-size: 0.84rem;
    padding: 9px 11px;
  }

  .pause-overlay {
    min-width: min(260px, calc(100% - 24px));
    padding: 14px 16px;
  }

  .district-metrics {
    grid-template-columns: 1fr;
  }

  .panel-header-row {
    flex-direction: column;
  }
}
