:root {
  --bg: #04080f;
  --panel: #080f1a;
  --border: #0f3460;
  --accent: #00d4ff;
  --accent2: #ff3c3c;
  --gold: #f5c518;
  --green: #00ff88;
  --text: #b8d4e8;
  --dim: #3a5a78;
  --glow: rgba(0,212,255,0.25);
}

* { margin:0; padding:0; box-sizing:border-box; }

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: 'Tajawal', sans-serif;
  color: var(--text);
}

/* ── MAP ── */
#map {
  position: absolute;
  inset: 0;
  z-index: 1;
  filter: brightness(0.95) contrast(1.02);
}

/* Dark tile overlay */
.leaflet-tile {
  filter: invert(1) hue-rotate(180deg) brightness(1.05) saturate(0.55) contrast(1.0);
}

/* Scanlines */
body::after {
  content:'';
  position:fixed;
  inset:0;
  background: repeating-linear-gradient(0deg, transparent, transparent 3px, rgba(0,212,255,0.018) 3px, rgba(0,212,255,0.018) 4px);
  pointer-events:none;
  z-index:999;
}

/* Radar sweep on map */
#radar-sweep {
  position:fixed;
  inset:0;
  pointer-events:none;
  z-index:5;
  animation: radarSweep 8s linear infinite;
  opacity:0.06;
  background: conic-gradient(from 0deg, transparent 300deg, rgba(0,212,255,0.6) 355deg, transparent 360deg);
  border-radius:50%;
  width:200vw;
  height:200vw;
  top:50%;
  left:50%;
  transform:translate(-50%,-50%);
}

@keyframes radarSweep {
  from { transform: translate(-50%,-50%) rotate(0deg); }
  to   { transform: translate(-50%,-50%) rotate(360deg); }
}

/* ── HEADER ── */
#header {
  position:fixed;
  top:0; left:0; right:0;
  z-index:500;
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:10px 20px;
  background: linear-gradient(180deg, rgba(4,8,15,0.96) 0%, rgba(4,8,15,0.3) 100%);
  border-bottom: 1px solid rgba(0,212,255,0.15);
}

.h-logo {
  display:flex;
  align-items:center;
  gap:12px;
  flex-shrink:0;
}

.h-emblem-img {
  height: 70px;
  max-height: 70px;
  width: auto;
  flex-shrink: 0;
  filter: drop-shadow(0 0 10px rgba(0,212,255,0.35));
}

.h-emblem {
  width:44px; height:44px;
  border:2px solid var(--accent);
  border-radius:50%;
  display:flex; align-items:center; justify-content:center;
  font-size:20px;
  position:relative;
  box-shadow: 0 0 20px rgba(0,212,255,0.4), inset 0 0 12px rgba(0,212,255,0.1);
  animation: emblemPulse 3s infinite;
}

@keyframes emblemPulse {
  0%,100%{box-shadow:0 0 20px rgba(0,212,255,0.4),inset 0 0 12px rgba(0,212,255,0.1);}
  50%{box-shadow:0 0 35px rgba(0,212,255,0.7),inset 0 0 20px rgba(0,212,255,0.2);}
}

.h-emblem::before {
  content:'';
  position:absolute;
  inset:-6px;
  border:1px solid rgba(0,212,255,0.2);
  border-radius:50%;
  animation: spin 12s linear infinite;
}

@keyframes spin { to { transform:rotate(360deg);} }

.h-title h1 {
  font-size:22px;
  font-weight:900;
  color:#fff;
  letter-spacing:0.03em;
  font-family:'Tajawal',sans-serif;
  white-space:nowrap;
}

.h-title p {
  font-family:'Orbitron',monospace;
  font-size:9px;
  color:var(--dim);
  letter-spacing:0.18em;
  margin-top:2px;
}

.h-stats {
  display:flex;
  gap:16px;
}

.stat-box {
  text-align:center;
  padding:8px 18px;
  border:1px solid rgba(0,212,255,0.2);
  border-radius:3px;
  background:rgba(0,212,255,0.04);
}

.stat-n {
  font-family:'Orbitron',monospace;
  font-size:26px;
  font-weight:900;
  color:var(--accent);
  line-height:1;
}

.stat-l {
  font-size:12px;
  font-weight:600;
  color:var(--text);
  margin-top:5px;
  letter-spacing:0.03em;
}

/* ── SIDE PANEL ── */
#panel {
  position:fixed;
  top:192px;
  right:16px;
  width:310px;
  z-index:500;
  transform:translateX(340px);
  transition:transform 0.45s cubic-bezier(0.16,1,0.3,1);
}

#panel.open {
  transform:translateX(0);
}

.panel-inner {
  background:rgba(4,8,15,0.97);
  border:1px solid var(--accent);
  border-radius:6px;
  overflow:hidden;
  box-shadow:0 0 50px rgba(0,212,255,0.15), -4px 0 30px rgba(0,212,255,0.05);
}

/* Corner clips */
.panel-inner::before, .panel-inner::after {
  content:'';
  position:absolute;
  width:12px; height:12px;
  border-color:var(--accent);
  border-style:solid;
}
.panel-inner::before { top:-1px; left:-1px; border-width:2px 0 0 2px; }
.panel-inner::after  { bottom:-1px; right:-1px; border-width:0 2px 2px 0; }

.p-head {
  padding:14px 16px;
  background:linear-gradient(135deg,rgba(0,212,255,0.12),rgba(0,212,255,0.03));
  border-bottom:1px solid var(--border);
  display:flex;
  align-items:center;
  gap:12px;
}

.p-flag { font-size:28px; line-height:1; }

.p-name {
  font-size:20px;
  font-weight:900;
  color:#fff;
}

.p-subtitle {
  font-family:'Tajawal',sans-serif;
  font-size:13px;
  font-weight:600;
  color:var(--accent);
  letter-spacing:0.05em;
  margin-top:4px;
}

.p-body { padding:14px 16px; }

/* Troops counter */
.troops-row {
  display:flex;
  align-items:flex-end;
  gap:10px;
  margin-bottom:14px;
  padding-bottom:12px;
  border-bottom:1px solid rgba(15,52,96,0.8);
}

.troops-num {
  font-family:'Orbitron',monospace;
  font-size:32px;
  font-weight:900;
  color:var(--gold);
  line-height:1;
  text-shadow:0 0 20px rgba(245,197,24,0.5);
}

.troops-label {
  font-size:15px;
  font-weight:700;
  color:#8ab0cc;
  line-height:1.5;
  margin-bottom:4px;
}

/* Bases count badge */
.bases-badge {
  display:inline-flex;
  align-items:center;
  gap:6px;
  background:rgba(255,60,60,0.1);
  border:1px solid rgba(255,60,60,0.35);
  color:var(--accent2);
  font-size:10px;
  font-weight:700;
  padding:3px 10px;
  border-radius:2px;
  letter-spacing:0.08em;
  margin-bottom:12px;
}

.bases-badge::before {
  content:'▣';
  font-size:9px;
}

/* Info list */
.info-list {
  list-style:none;
}

.info-list li {
  position:relative;
  padding:5px 16px 5px 0;
  font-size:12.5px;
  color:var(--text);
  line-height:1.5;
  border-bottom:1px solid rgba(15,52,96,0.4);
}

.info-list li:last-child { border-bottom:none; }

.info-list li::before {
  content:'';
  position:absolute;
  right:0;
  top:50%;
  transform:translateY(-50%);
  width:5px; height:5px;
  border-radius:50%;
  background:var(--accent2);
  box-shadow:0 0 6px var(--accent2);
}

/* Warning note */
.p-note {
  margin-top:12px;
  padding:8px 12px;
  background:rgba(245,197,24,0.06);
  border-right:2px solid var(--gold);
  border-radius:2px;
  font-size:11px;
  color:#9aaebc;
  line-height:1.6;
}

/* Close btn */
#close-btn {
  position:absolute;
  top:10px;
  left:10px;
  width:24px; height:24px;
  background:rgba(255,60,60,0.15);
  border:1px solid rgba(255,60,60,0.4);
  color:var(--accent2);
  border-radius:3px;
  cursor:pointer;
  font-size:12px;
  display:flex;
  align-items:center;
  justify-content:center;
  z-index:10;
  transition:all 0.2s;
}
#close-btn:hover { background:rgba(255,60,60,0.3); }

/* ── LEGEND ── */
#legend {
  position:fixed;
  bottom:20px;
  left:50%;
  transform:translateX(-50%);
  z-index:500;
  display:flex;
  gap:0;
  background:rgba(4,8,15,0.93);
  border:1px solid var(--border);
  border-radius:4px;
  overflow:hidden;
}

.leg-item {
  display:flex;
  align-items:center;
  gap:8px;
  padding:8px 18px;
  font-size:13px;
  font-weight:600;
  color:#ffffff;
  border-right:1px solid var(--border);
}
.leg-item:last-child { border-right:none; }

.leg-dot {
  width:10px; height:10px;
  border-radius:50%;
  flex-shrink:0;
}

/* ── FOOTER CORNERS ── */
.corner-text {
  position:fixed;
  z-index:500;
  font-family:'Orbitron',monospace;
  font-size:8px;
  color:rgba(58,90,120,0.7);
  letter-spacing:0.1em;
  line-height:1.7;
}
.corner-text.bl { bottom:12px; right:16px; text-align:right; }
.corner-text.br { bottom:12px; left:16px; text-align:left; }

/* ── LEAFLET CUSTOM MARKER ── */
.mil-marker svg {
  overflow: visible !important;
  cursor: pointer;
}

/* Hover label on marker */
.leaflet-tooltip {
  background:rgba(4,8,15,0.9) !important;
  border:1px solid var(--accent) !important;
  color:#fff !important;
  font-family:'Tajawal',sans-serif !important;
  font-size:12px !important;
  font-weight:700 !important;
  border-radius:3px !important;
  padding:4px 10px !important;
  box-shadow:0 0 12px rgba(0,212,255,0.3) !important;
  white-space:nowrap !important;
}

.leaflet-tooltip::before { display:none !important; }

/* ── HINT ── */
#hint {
  position:fixed;
  top:50%;
  left:50%;
  transform:translate(-50%,-50%);
  z-index:400;
  text-align:center;
  pointer-events:none;
  animation:fadeHint 1s ease 3s forwards;
  opacity:1;
}

@keyframes fadeHint {
  to { opacity:0; }
}

.hint-text {
  font-size:13px;
  color:rgba(0,212,255,0.5);
  letter-spacing:0.1em;
}

/* ── MOBILE ── */
@media(max-width:600px) {
  #panel { width:calc(100vw - 20px); right:10px; }
  .h-stats { display:none; }
}

/* Radar Canvas */
#radar-canvas { position:fixed; inset:0; pointer-events:none; z-index:6; }

/* ── CASUALTIES SIDEBAR ── */
#casualties {
  position: fixed;
  top: 50%;
  left: 16px;
  transform: translateY(-50%);
  z-index: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  background: rgba(4,8,15,0.93);
  border: 1px solid rgba(0,212,255,0.2);
  border-radius: 6px;
  overflow: hidden;
  padding: 10px 0 6px;
  min-width: 110px;
  box-shadow: 0 0 30px rgba(0,212,255,0.08);
}

.cas-title {
  font-family: 'Tajawal', sans-serif;
  font-size: 11px;
  font-weight: 700;
  color: rgba(0,212,255,0.7);
  letter-spacing: 0.08em;
  margin-bottom: 8px;
  padding: 0 12px;
  text-align: center;
}

.cas-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 16px;
  width: 100%;
  text-align: center;
}

.cas-num {
  font-family: 'Orbitron', monospace;
  font-size: 30px;
  font-weight: 900;
  line-height: 1;
}

.cas-flag {
  font-size: 18px;
  margin: 4px 0 2px;
  line-height: 1;
}

.cas-label {
  font-family: 'Tajawal', sans-serif;
  font-size: 11px;
  font-weight: 600;
  color: #b8d4e8;
  line-height: 1.4;
  margin-top: 2px;
}

.cas-divider {
  width: 80%;
  height: 1px;
  background: rgba(0,212,255,0.12);
  margin: 0 auto;
}

@media(max-width:600px) {
  #casualties { display: none; }
}

/* ═══════════════════════════════════════════
   MOBILE RESPONSIVE (≤ 768px)
   ═══════════════════════════════════════════ */
@media (max-width: 768px) {

  /* ── Header: compact single row ── */
  #header {
    padding: 6px 10px;
    flex-wrap: nowrap;
    gap: 8px;
    background: linear-gradient(180deg, rgba(4,8,15,0.96) 0%, rgba(4,8,15,0.85) 100%);
  }

  .h-emblem { width:28px; height:28px; font-size:13px; flex-shrink:0; }
  .h-emblem-img { height: 28px; }
  .h-title h1 { font-size: 13px; }

  /* Show only war days + 2 key stats */
  #clock-box { display: none; }
  .h-stats { gap: 5px; }
  .stat-box { padding: 4px 8px; }
  .stat-n { font-size: 15px; }
  .stat-l { font-size: 9px; margin-top:2px; }

  /* ── Casualties bar: horizontal strip above legend ── */
  #casualties {
    display: flex !important;
    flex-direction: row;
    position: fixed;
    top: auto;
    bottom: 52px;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: calc(100vw - 16px);
    max-width: 400px;
    padding: 5px 0;
    border-radius: 8px;
    min-width: auto;
    z-index: 501;
  }
  .cas-title { display: none; }
  .cas-box { flex:1; padding: 4px 6px; }
  .cas-box:not(:last-child) { border-left: 1px solid rgba(0,212,255,0.15); }
  .cas-divider { display: none; }
  .cas-num { font-size: 20px; }
  .cas-flag { font-size: 14px; margin: 2px 0 1px; }
  .cas-label { font-size: 9px; }

  /* ── Panel: bottom sheet ── */
  #panel {
    top: auto !important;
    bottom: 0;
    right: 0;
    left: 0;
    width: 100% !important;
    transform: translateY(105%) !important;
    transition: transform 0.38s cubic-bezier(0.16,1,0.3,1);
    z-index: 700;
  }
  #panel.open { transform: translateY(0) !important; }

  .panel-inner {
    border-radius: 16px 16px 0 0;
    max-height: 60vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* drag handle */
  .panel-inner::before {
    content: '';
    display: block;
    width: 38px; height: 4px;
    background: rgba(0,212,255,0.35);
    border-radius: 2px;
    margin: 10px auto 0;
    position: static;
    border: none;
  }

  /* ── Legend: hidden by default, toggle button shows it ── */
  #legend {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0; right: 0;
    width: 100%;
    max-width: 100%;
    transform: none;
    border-radius: 14px 14px 0 0;
    flex-direction: column;
    overflow-y: auto;
    max-height: 60vh;
    z-index: 650;
    padding: 8px 0 16px;
  }

  #legend.mob-open { display: flex; }

  .leg-item {
    padding: 10px 20px;
    font-size: 13px;
    border-right: none;
    border-bottom: 1px solid rgba(15,52,96,0.5);
    width: 100%;
    gap: 12px;
  }
  .leg-item:last-child { border-bottom: none; }

  /* legend drag handle */
  #legend::before {
    content: '';
    display: block;
    width: 38px; height: 4px;
    background: rgba(0,212,255,0.35);
    border-radius: 2px;
    margin: 6px auto 8px;
    flex-shrink: 0;
  }

  /* ── Legend toggle FAB ── */
  #legend-toggle {
    display: flex !important;
    position: fixed;
    bottom: 16px;
    right: 16px;
    z-index: 660;
    width: 44px; height: 44px;
    background: rgba(4,8,15,0.95);
    border: 1px solid rgba(0,212,255,0.4);
    border-radius: 50%;
    color: #00d4ff;
    font-size: 20px;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 0 20px rgba(0,212,255,0.25);
  }

  /* ── Legend overlay background ── */
  #legend-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 640;
  }
  #legend-overlay.mob-open { display: block; }

  /* ── Zoom controls: hide ── */
  .leaflet-control-zoom { display: none !important; }

  /* ── Corner texts: hide ── */
  .corner-text { display: none; }
}

/* FAB hidden on desktop */
#legend-toggle { display: none; }
#legend-overlay { display: none; }
