:root {
  --bg: #05070a;
  --panel: rgba(4, 8, 12, .78);
  --border: rgba(125, 249, 255, .18);
  --text: #d9fff8;
  --muted: rgba(217, 255, 248, .64);
  --cyan: #00ffd5;
  --gold: #f5c76b;
  --danger: #ff6b6b;
  --good: #55d187;
  --grid-color: rgba(125, 249, 255, .035);
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  min-height: 100vh;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(0, 255, 213, .08), transparent 32%),
    linear-gradient(315deg, rgba(245, 199, 107, .08), transparent 34%),
    var(--bg);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background-image:
    linear-gradient(var(--grid-color) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-color) 1px, transparent 1px);
  background-size: 42px 42px;
}

button,
input,
select,
textarea {
  font: inherit;
}

.battle-shell {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-rows: 64px 1fr;
  min-height: 100vh;
}

.battle-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 64px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background:
    linear-gradient(90deg, rgba(2, 6, 10, .96), rgba(5, 13, 18, .86) 45%, rgba(2, 6, 10, .96)),
    rgba(2, 6, 10, .94);
  backdrop-filter: blur(16px);
}

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

.battle-kicker {
  color: var(--gold);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .18em;
  text-transform: uppercase;
}

h1 {
  margin: 4px 0 0;
  font-size: clamp(22px, 3vw, 34px);
  line-height: 1;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.battle-header-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.battle-header-meta span {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border: 1px solid rgba(125, 249, 255, .18);
  border-radius: 999px;
  padding: 0 9px;
  background: rgba(0, 255, 213, .07);
  color: rgba(236, 255, 251, .76);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .1em;
  text-transform: uppercase;
  white-space: nowrap;
}

.battle-header-meta span:last-child {
  border-color: rgba(245, 199, 107, .36);
  background: rgba(245, 199, 107, .1);
  color: #ffe0a0;
}

.home-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  border: 1px solid rgba(125, 249, 255, .24);
  border-radius: 8px;
  padding: 0 13px;
  background: rgba(125, 249, 255, .06);
  color: var(--text);
  text-decoration: none;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .12em;
  text-transform: uppercase;
  white-space: nowrap;
}

.battle-layout {
  position: relative;
  min-height: calc(100vh - 64px);
  overflow: hidden;
}

.map-wrap {
  position: absolute;
  inset: 0;
}

#map {
  width: 100%;
  height: calc(100vh - 64px);
  background: #0b0f14;
}

.map-wrap::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 500;
  pointer-events: none;
  border: 1px solid rgba(125, 249, 255, .08);
  box-shadow: inset 0 0 90px rgba(0, 0, 0, .28);
}

.control-stack {
  position: absolute;
  z-index: 920;
  top: 16px;
  width: min(318px, calc(100vw - 32px));
  max-height: calc(100vh - 92px);
  overflow: auto;
  scrollbar-width: thin;
}

.left-stack { left: 16px; }
.right-stack { right: 16px; }

.control-group,
.intel-card {
  margin-bottom: 12px;
  border: 1px solid rgba(125, 249, 255, .22);
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(12, 23, 31, .88), rgba(3, 8, 13, .74)),
    var(--panel);
  box-shadow: 0 18px 55px rgba(0, 0, 0, .34), inset 0 1px 0 rgba(255, 255, 255, .055);
  backdrop-filter: blur(18px) saturate(1.08);
}

details.control-group {
  overflow: hidden;
}

details.control-group > summary,
.intel-card-title {
  display: flex;
  align-items: center;
  min-height: 40px;
  border-bottom: 1px solid rgba(125, 249, 255, .1);
  padding: 0 12px;
  background: linear-gradient(90deg, rgba(56, 248, 255, .07), transparent 68%);
  color: var(--gold);
  cursor: pointer;
  font-size: 11px;
  font-weight: 950;
  letter-spacing: .16em;
  list-style: none;
  text-transform: uppercase;
}

details.control-group > summary::-webkit-details-marker {
  display: none;
}

.control-inner,
.intel-card {
  padding: 12px;
}

.intel-card-title {
  margin: -12px -12px 12px;
}

label {
  display: block;
  margin-bottom: 10px;
  color: rgba(236, 255, 251, .68);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: .08em;
  text-transform: uppercase;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  margin-top: 6px;
  border: 1px solid rgba(125, 249, 255, .18);
  border-radius: 7px;
  padding: 8px 9px;
  background: #04080c;
  color: var(--text);
  outline: none;
  font-size: 12px;
  letter-spacing: 0;
  text-transform: none;
}

textarea {
  min-height: 78px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(56, 248, 255, .68);
  box-shadow: 0 0 0 2px rgba(56, 248, 255, .11), 0 0 24px rgba(56, 248, 255, .06);
}

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

button {
  min-height: 40px;
  border: 1px solid rgba(125, 249, 255, .22);
  border-radius: 8px;
  padding: 8px 10px;
  background: linear-gradient(180deg, rgba(255, 255, 255, .04), transparent), rgba(125, 249, 255, .075);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .04);
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
}

button:hover {
  border-color: rgba(245, 199, 107, .45);
  background: rgba(245, 199, 107, .08);
}

button.active {
  border-color: rgba(245, 199, 107, .62);
  background: rgba(245, 199, 107, .16);
  color: #ffe0a0;
  box-shadow: 0 0 24px rgba(245, 199, 107, .12);
}

button.primary {
  width: 100%;
  border-color: rgba(245, 199, 107, .55);
  background: linear-gradient(180deg, rgba(245, 199, 107, .18), rgba(245, 199, 107, .08)), rgba(245, 199, 107, .08);
  color: #ffe0a0;
}

button.danger {
  border-color: rgba(255, 107, 107, .4);
  background: rgba(255, 107, 107, .1);
  color: #ffb0b8;
}

button:disabled {
  cursor: not-allowed;
  opacity: .45;
}

.freehand-zone-active #map {
  cursor: crosshair;
}

.freehand-zone-erase #map {
  cursor: not-allowed;
}

.status {
  min-height: 64px;
  max-height: 116px;
  margin-top: 12px;
  overflow: auto;
  border: 1px solid rgba(125, 249, 255, .14);
  border-radius: 8px;
  padding: 10px;
  background: rgba(2, 6, 10, .74);
  color: rgba(236, 255, 251, .58);
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 11px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.status.good {
  color: var(--good);
  border-color: rgba(85, 209, 135, .36);
}

.status.bad {
  color: var(--danger);
  border-color: rgba(255, 107, 107, .44);
}

.small-note {
  margin: 10px 0 0;
  border-left: 2px solid rgba(245, 199, 107, .36);
  padding-left: 8px;
  color: rgba(236, 255, 251, .5);
  font-size: 11px;
  line-height: 1.4;
}

input[type="range"] {
  padding: 0;
  accent-color: var(--gold);
}

.playback-ribbon {
  position: absolute;
  left: 50%;
  bottom: 16px;
  z-index: 860;
  display: grid;
  grid-template-columns: repeat(3, minmax(90px, auto)) minmax(150px, auto);
  gap: 8px;
  align-items: center;
  width: min(560px, calc(100vw - 720px));
  min-width: 430px;
  border: 1px solid rgba(125, 249, 255, .18);
  border-radius: 8px;
  padding: 8px;
  background: rgba(3, 8, 13, .82);
  box-shadow: 0 16px 40px rgba(0, 0, 0, .32);
  backdrop-filter: blur(14px);
  transform: translateX(-50%);
}

.playback-ribbon button {
  min-height: 34px;
}

.playback-status {
  display: flex;
  align-items: center;
  min-height: 34px;
  border-left: 1px solid rgba(125, 249, 255, .14);
  padding-left: 10px;
  color: rgba(236, 255, 251, .5);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.toggle-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.toggle-row label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  margin: 0;
  border: 1px solid rgba(125, 249, 255, .15);
  border-radius: 8px;
  padding: 6px 8px;
  background: rgba(125, 249, 255, .045);
}

.toggle-row input {
  width: 16px;
  min-height: 16px;
  margin: 0;
}

.zone-list {
  display: grid;
  gap: 8px;
  max-height: 260px;
  overflow: auto;
}

.zone-item {
  border: 1px solid rgba(125, 249, 255, .14);
  border-radius: 8px;
  padding: 9px;
  background: rgba(3, 10, 14, .58);
  cursor: pointer;
}

.zone-item.active {
  border-color: rgba(245, 199, 107, .48);
  background: rgba(245, 199, 107, .1);
}

.zone-item strong {
  display: block;
  color: #ffe0a0;
  font-size: 12px;
}

.zone-item span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  color: rgba(236, 255, 251, .72);
  font-size: 12px;
}

.event-dot,
.zone-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .5);
}

.event-dot.battle { background: #e74c3c; }
.event-dot.explosion { background: #f39c12; }
.event-dot.civilian { background: #8e44ad; }
.zone-swatch.contested { background: #f5c76b; }
.zone-swatch.controlled { background: #55d187; }

.legend-source {
  margin-top: 10px;
  border-top: 1px solid rgba(125, 249, 255, .12);
  padding-top: 10px;
  color: rgba(236, 255, 251, .48);
  font-size: 11px;
  line-height: 1.35;
}

.hidden-file {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.battle-marker {
  display: grid;
  place-items: center;
  width: var(--size);
  height: var(--size);
  border: 2px solid rgba(255, 255, 255, .72);
  border-radius: 50%;
  background: var(--color);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, .38), 0 0 18px var(--glow);
  color: #fff;
  font-size: 11px;
  font-weight: 950;
}

.battle-popup {
  min-width: 240px;
  color: #d9fff8;
}

.battle-popup h3 {
  margin: 0 0 8px;
  color: #ffe0a0;
  font-size: 13px;
  text-transform: uppercase;
}

.battle-popup p {
  margin: 5px 0;
  color: rgba(217, 255, 248, .78);
  line-height: 1.35;
}

.leaflet-container {
  font: inherit;
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  border: 1px solid rgba(125, 249, 255, .22);
  background: rgba(4, 8, 12, .94);
  color: var(--text);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .45);
}

.leaflet-control-zoom a {
  background-color: rgba(4, 8, 12, .92) !important;
  color: var(--text) !important;
}

.leaflet-control-zoom {
  margin-left: 348px !important;
  margin-top: 16px !important;
}

@media (max-width: 1180px) {
  .control-stack {
    width: min(300px, calc(100vw - 32px));
  }

  .playback-ribbon {
    width: min(420px, calc(100vw - 640px));
    min-width: 360px;
    grid-template-columns: repeat(3, minmax(72px, auto));
  }

  .playback-status {
    grid-column: 1 / -1;
    border-left: 0;
    border-top: 1px solid rgba(125, 249, 255, .12);
    justify-content: center;
    padding: 7px 0 0;
  }

  .leaflet-control-zoom {
    margin-left: 330px !important;
  }
}

@media (max-width: 920px) {
  body {
    overflow: auto;
  }

  .battle-header {
    align-items: flex-start;
    flex-direction: column;
    min-height: auto;
  }

  .battle-header-meta {
    justify-content: flex-start;
  }

  .home-link {
    width: 100%;
  }

  .battle-layout {
    min-height: auto;
    overflow: visible;
  }

  .map-wrap {
    position: relative;
    height: 70vh;
    min-height: 520px;
  }

  #map {
    height: 70vh;
    min-height: 520px;
  }

  .control-stack {
    position: relative;
    inset: auto;
    width: auto;
    max-height: none;
    margin: 12px;
    overflow: visible;
  }

  .playback-ribbon {
    left: 12px;
    right: 12px;
    bottom: 12px;
    width: auto;
    min-width: 0;
    transform: none;
  }

  .leaflet-control-zoom {
    margin-left: 10px !important;
  }
}

@media (max-width: 640px) {
  .grid-2,
  .button-row,
  .toggle-row {
    grid-template-columns: 1fr;
  }
}
