* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  background: #060610;
  overflow: hidden;
  font-family: 'Courier New', monospace;
  color: #00ff88;
  touch-action: none;
  user-select: none;
}
canvas { display: block; }

/* ===== LOADING SCREEN ===== */
#loading-screen {
  position: fixed; inset: 0;
  background: #050510;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  z-index: 10000;
}
.loading-logo { font-size: 12px; letter-spacing: 6px; color: #cc66ff; opacity: 0.6; margin-bottom: 4px; }
.loading-title { font-size: 24px; letter-spacing: 6px; color: #00ff88; margin-bottom: 24px; }
.loading-status { font-size: 10px; letter-spacing: 3px; opacity: 0.4; margin-bottom: 12px; }
.loading-bar { width: 200px; height: 3px; background: rgba(255,255,255,0.08); border-radius: 2px; }
.loading-bar-fill { height: 100%; background: #00ff88; border-radius: 2px; width: 0%; transition: width 0.1s; }

/* ===== TITLE SCREEN ===== */
#title-screen {
  background: #050510;
  z-index: 9999;
}
.title-logo {
  font-size: 14px;
  letter-spacing: 8px;
  color: #cc66ff;
  opacity: 0.7;
  margin-bottom: 8px;
}
.title-heading {
  font-size: 48px;
  letter-spacing: 10px;
  color: #00ff88;
  margin-bottom: 12px;
  text-shadow: 0 0 30px rgba(0,255,136,0.4);
}
.title-tagline {
  font-size: 13px;
  letter-spacing: 4px;
  color: #88bbaa;
  opacity: 0.6;
  margin-bottom: 40px;
}
.title-start-btn {
  font-size: 18px;
  letter-spacing: 6px;
  padding: 14px 48px;
  animation: title-pulse 2s ease-in-out infinite;
}
@keyframes title-pulse {
  0%, 100% { box-shadow: 0 0 8px rgba(0,255,136,0.3); }
  50% { box-shadow: 0 0 20px rgba(0,255,136,0.6); }
}

/* ===== PAUSE OVERLAY ===== */
#pause-overlay {
  position: fixed; inset: 0;
  background: rgba(5,5,16,0.85);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  z-index: 200;
  text-align: center;
  backdrop-filter: blur(4px);
}
#pause-overlay h1 { font-size: 32px; letter-spacing: 8px; color: #00ff88; }

#pause-books {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-top: 16px;
}
#pause-books a { display: block; }
#pause-books img {
  height: 120px;
  width: auto;
  border-radius: 4px;
  box-shadow: 0 0 15px rgba(0,255,136,0.15), 0 4px 12px rgba(0,0,0,0.5);
  cursor: pointer;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}
#pause-books img:hover {
  transform: scale(1.06);
  box-shadow: 0 0 25px rgba(0,255,136,0.3), 0 6px 20px rgba(0,0,0,0.6);
}

/* ===== INSTRUCTIONS PANEL ===== */
#instructions-panel {
  width: min(600px, 90vw);
  max-height: 70vh;
  text-align: left;
}
#instructions-scroll {
  max-height: calc(70vh - 60px);
  overflow-y: auto;
  padding-right: 8px;
  scrollbar-width: thin;
  scrollbar-color: rgba(0,255,136,0.3) transparent;
}
#instructions-scroll::-webkit-scrollbar { width: 5px; }
#instructions-scroll::-webkit-scrollbar-thumb { background: rgba(0,255,136,0.3); border-radius: 3px; }
.inst-section { margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid rgba(0,255,136,0.1); }
.inst-section:last-child { border-bottom: none; }
.inst-section h3 { color: #00ff88; font-size: 13px; letter-spacing: 3px; margin-bottom: 6px; }
.inst-section p { color: rgba(255,255,255,0.6); font-size: 11px; line-height: 1.6; margin-bottom: 6px; }
.inst-row { color: rgba(255,255,255,0.55); font-size: 10px; line-height: 1.7; padding: 1px 0; }
.inst-row b { color: rgba(255,255,255,0.8); }
.inst-sub { padding-left: 12px; opacity: 0.7; }
.inst-icon { font-size: 13px; display: inline-block; width: 16px; text-align: center; }

/* ===== AUDIO CONTROLS ===== */
/* old menu-audio removed — see vol-controls section */
.btn-small { font-size: 10px; padding: 5px 12px; letter-spacing: 1px; }
.btn-tiny { font-size: 9px; padding: 4px 10px; letter-spacing: 1px; border-color: rgba(255,255,255,0.2); color: rgba(255,255,255,0.5); }
.btn-tiny:hover { border-color: rgba(255,255,255,0.4); color: rgba(255,255,255,0.8); }
.audio-off { opacity: 0.4; border-style: dashed; }

.vol-controls { margin-top: 12px; }
.vol-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; justify-content: center; }
.vol-slider {
  -webkit-appearance: none; appearance: none;
  width: 100px; height: 4px;
  background: rgba(255,255,255,0.1);
  border-radius: 2px; outline: none;
  cursor: pointer;
}
.vol-slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 14px;
  background: #00ff88; border-radius: 50%;
  cursor: pointer; border: none;
}
.vol-slider::-moz-range-thumb {
  width: 14px; height: 14px;
  background: #00ff88; border-radius: 50%;
  cursor: pointer; border: none;
}
.vol-slider-small { width: 70px; height: 3px; }
.vol-slider-small::-webkit-slider-thumb { width: 10px; height: 10px; }
.vol-slider-small::-moz-range-thumb { width: 10px; height: 10px; }

#menu-audio-controls {
  position: fixed;
  bottom: 12px; right: 12px;
  display: flex; flex-direction: column; gap: 4px;
  z-index: 101;
}

/* Portrait warning — hidden by default, shown on mobile portrait */
#portrait-warning {
  display: none;
  position: fixed; inset: 0;
  background: #060610;
  z-index: 9999;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #00ff88;
}
@media (max-width: 900px) and (orientation: portrait) {
  #portrait-warning { display: flex !important; }
  #hud, #ability-bar, #event-log, #node-panel, #legend, #evo-toggle, #evo-panel,
  #tooltip, .overlay, canvas { opacity: 0; pointer-events: none; }
}

/* ===== HUD TOP BAR ===== */
#hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  padding: 8px 12px;
  display: none;
  justify-content: space-between;
  align-items: center;
  background: rgba(6,6,16,0.92);
  border-bottom: 1px solid rgba(0,255,136,0.15);
  z-index: 10;
}
.hud-block { display: flex; align-items: center; gap: 14px; }
.hud-item { text-align: center; min-width: 85px; }
.hud-label { font-size: 8px; text-transform: uppercase; letter-spacing: 1.5px; opacity: 0.5; }
.hud-val { font-size: 15px; font-weight: bold; }
.hud-bar-wrap { width: 100%; height: 3px; background: rgba(255,255,255,0.08); border-radius: 2px; margin-top: 2px; }
.hud-bar-inner { height: 100%; border-radius: 2px; transition: width 0.3s; }
.bar-green { background: #00ff88; }
.bar-red { background: #ff3355; }
.bar-blue { background: #4488ff; }
.bar-yellow { background: #ffcc00; }

/* ===== LEGEND ===== */
#legend {
  position: fixed;
  left: 12px;
  top: 52px;
  background: rgba(6,6,16,0.92);
  border: 1px solid rgba(0,255,136,0.12);
  border-radius: 6px;
  padding: 8px 10px;
  z-index: 10;
  display: none;
  font-size: 10px;
  line-height: 1.9;
}
#legend .legend-title { font-size: 8px; letter-spacing: 2px; opacity: 0.4; margin-bottom: 4px; }
.legend-row { display: flex; align-items: center; gap: 8px; }
.legend-shape { width: 18px; height: 18px; display: flex; align-items: center; justify-content: center; }

#legend-toggle {
  display: none;
  position: fixed;
  left: 12px;
  top: 52px;
  width: 32px; height: 32px;
  background: rgba(6,6,16,0.92);
  border: 1px solid rgba(0,255,136,0.2);
  border-radius: 6px;
  color: #00ff88;
  font-family: 'Courier New', monospace;
  font-size: 16px;
  cursor: pointer;
  z-index: 11;
  line-height: 32px;
  text-align: center;
}
#legend-toggle:hover { background: rgba(0,255,136,0.1); }

/* ===== ABILITY BAR ===== */
#ability-bar {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  gap: 5px;
  z-index: 10;
  background: rgba(6,6,16,0.92);
  border: 1px solid rgba(0,255,136,0.15);
  max-width: 95vw;
  flex-wrap: wrap;
  justify-content: center;
  border-radius: 8px;
  padding: 8px 12px;
}
.ability-btn {
  width: 58px; height: 58px;
  background: rgba(0,255,136,0.04);
  border: 1px solid rgba(0,255,136,0.2);
  border-radius: 6px;
  color: #00ff88;
  font-family: 'Courier New', monospace;
  font-size: 9px;
  cursor: pointer;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 1px; transition: all 0.2s;
  position: relative;
}
.ability-btn:hover { background: rgba(0,255,136,0.12); border-color: #00ff88; }
.ability-btn.active { background: rgba(0,255,136,0.2); border-color: #00ff88; box-shadow: 0 0 12px rgba(0,255,136,0.3); }
.ability-btn.disabled { opacity: 0.3; pointer-events: none; }
.ability-btn .icon { font-size: 18px; line-height: 1; }
.ability-btn .lbl { font-size: 8px; }
.ability-btn .cost { font-size: 8px; opacity: 0.6; }
.ability-btn .cooldown-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.7);
  border-radius: 6px;
  display: none; align-items: center; justify-content: center;
  font-size: 14px; font-weight: bold;
}
.ability-btn .hotkey { position: absolute; top: 2px; right: 4px; font-size: 7px; opacity: 0.3; }

/* ===== NODE PANEL ===== */
#node-panel {
  position: fixed; right: 12px; top: 55px;
  width: 190px;
  background: rgba(6,6,16,0.92);
  border: 1px solid rgba(0,255,136,0.15);
  border-radius: 6px;
  padding: 10px;
  display: none; z-index: 10;
  font-size: 11px; line-height: 1.6;
  transition: transform 0.3s ease;
}
.np-title { font-size: 13px; font-weight: bold; margin-bottom: 6px; display: flex; align-items: center; gap: 6px; }
.np-row { display: flex; justify-content: space-between; opacity: 0.7; }
.np-section { margin-top: 6px; padding-top: 6px; border-top: 1px solid rgba(255,255,255,0.06); }
button.np-upgrade, div.np-upgrade, .np-upgrade {
  display: flex; justify-content: space-between; align-items: center;
  width: 100%;
  background: rgba(204,102,255,0.05); border: 1px solid rgba(204,102,255,0.2);
  border-radius: 3px; padding: 6px 8px; margin-top: 3px; cursor: pointer;
  transition: all 0.2s; color: #cc88ff; font-size: 11px;
  font-family: 'Courier New', monospace;
  position: relative; z-index: 20;
}
.np-upgrade:hover { background: rgba(204,102,255,0.15); border-color: #cc66ff; }
.np-upgrade.disabled { opacity: 0.3; pointer-events: none; }

.panel-handle {
  display: none;
  width: 40px; height: 4px;
  background: rgba(255,255,255,0.2);
  border-radius: 2px;
  margin: 0 auto 8px;
}

#panel-close {
  display: none;
  position: absolute;
  top: 4px; right: 6px;
  background: rgba(255,50,50,0.1);
  border: 1px solid rgba(255,50,50,0.3);
  border-radius: 4px;
  color: #ff4444;
  font-size: 18px;
  width: 24px; height: 24px;
  line-height: 22px;
  text-align: center;
  cursor: pointer;
  font-family: 'Courier New', monospace;
  padding: 0;
  transition: all 0.2s;
}
#panel-close:hover {
  background: rgba(255,50,50,0.25);
  border-color: #ff4444;
}

/* ===== EVENT LOG ===== */
#event-log {
  position: fixed; left: 12px; bottom: 82px;
  width: 260px; max-height: 130px; overflow: hidden;
  z-index: 10; display: none; pointer-events: none;
}
.log-entry { font-size: 10px; padding: 2px 0; animation: logFade 10s forwards; }
@keyframes logFade { 0%{opacity:0.85} 70%{opacity:0.5} 100%{opacity:0} }
.log-warn { color: #ffcc00; }
.log-danger { color: #ff3355; }
.log-good { color: #00ff88; }
.log-info { color: #4488ff; }

.bar-purple { background: #cc66ff; }

/* ===== EVOLUTION TOGGLE ===== */
#evo-toggle {
  position: fixed;
  right: 12px;
  bottom: 12px;
  background: rgba(6,6,16,0.92);
  border: 1px solid rgba(204,102,255,0.4);
  color: #cc66ff;
  font-family: 'Courier New', monospace;
  font-size: 11px;
  padding: 8px 14px;
  letter-spacing: 2px;
  cursor: pointer;
  z-index: 12;
  border-radius: 6px;
  transition: all 0.2s;
}
#evo-toggle:hover { background: rgba(204,102,255,0.12); border-color: #cc66ff; }
#evo-ep-badge {
  background: rgba(204,102,255,0.3);
  padding: 1px 6px;
  border-radius: 3px;
  margin-left: 4px;
  font-weight: bold;
}

/* ===== EVOLUTION PANEL ===== */
#evo-panel {
  position: fixed;
  inset: 0;
  background: linear-gradient(180deg, rgba(8,4,20,0.98) 0%, rgba(4,8,16,0.98) 100%);
  z-index: 50;
  padding: 16px;
  overflow-y: auto;
  display: none;
}
.evo-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  border-bottom: 1px solid rgba(204,102,255,0.2);
  padding-bottom: 14px;
}
.evo-header h2 {
  font-size: 20px;
  letter-spacing: 5px;
  background: linear-gradient(90deg, #cc66ff, #8844ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  flex: 1;
}
.evo-ep-display {
  font-size: 16px;
  color: #cc66ff;
  font-weight: bold;
  background: rgba(204,102,255,0.1);
  padding: 4px 12px;
  border-radius: 4px;
  border: 1px solid rgba(204,102,255,0.2);
}
#evo-close {
  background: none;
  border: 1px solid rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.5);
  font-size: 18px;
  width: 34px; height: 34px;
  cursor: pointer;
  border-radius: 6px;
  font-family: 'Courier New', monospace;
  transition: all 0.2s;
}
#evo-close:hover { background: rgba(255,255,255,0.1); color: #fff; }

.evo-branches {
  display: flex;
  gap: 14px;
  justify-content: center;
  max-width: 900px;
  margin: 0 auto;
}
.evo-branch {
  flex: 1;
  max-width: 300px;
  background: rgba(255,255,255,0.015);
  border: 1px solid rgba(255,255,255,0.05);
  border-radius: 10px;
  padding: 14px;
  position: relative;
}
.evo-branch::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 3px;
  border-radius: 10px 10px 0 0;
}
.evo-branch[data-branch="stealth"]::before { background: linear-gradient(90deg, transparent, #00ccff, transparent); }
.evo-branch[data-branch="power"]::before { background: linear-gradient(90deg, transparent, #ff4444, transparent); }
.evo-branch[data-branch="adapt"]::before { background: linear-gradient(90deg, transparent, #ffaa00, transparent); }
.evo-branch-title {
  font-size: 14px;
  font-weight: bold;
  letter-spacing: 3px;
  margin-bottom: 2px;
}
.evo-branch-desc {
  font-size: 10px;
  opacity: 0.5;
  margin-bottom: 12px;
}

/* Connecting line between slots */
.evo-slots { position: relative; }
.evo-connector {
  width: 2px;
  height: 8px;
  margin: 0 auto;
  position: relative;
}
.evo-connector-line {
  position: absolute;
  left: 50%; top: 0;
  width: 2px; height: 100%;
  transform: translateX(-50%);
  background: rgba(255,255,255,0.08);
}
.evo-connector-line.owned { background: rgba(0,255,136,0.4); }

.evo-slot {
  background: rgba(255,255,255,0.02);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  transition: all 0.25s;
  position: relative;
  overflow: hidden;
}
.evo-slot::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(135deg, rgba(204,102,255,0.05) 0%, transparent 50%);
  pointer-events: none;
}
.evo-slot:hover { background: rgba(255,255,255,0.05); transform: translateY(-1px); }
.evo-slot.locked {
  opacity: 0.25;
  cursor: default;
}
.evo-slot.locked:hover { background: rgba(255,255,255,0.02); transform: none; }
.evo-slot.affordable {
  border-color: rgba(204,102,255,0.5);
  box-shadow: 0 0 12px rgba(204,102,255,0.1);
  animation: evoPulse 2s ease-in-out infinite;
}
@keyframes evoPulse {
  0%, 100% { box-shadow: 0 0 8px rgba(204,102,255,0.1); }
  50% { box-shadow: 0 0 16px rgba(204,102,255,0.25); }
}
.evo-slot.affordable:hover {
  background: rgba(204,102,255,0.1);
  border-color: #cc66ff;
  box-shadow: 0 0 20px rgba(204,102,255,0.3);
}
.evo-slot.owned {
  border-color: rgba(0,255,136,0.4);
  background: rgba(0,255,136,0.04);
  cursor: default;
  box-shadow: 0 0 8px rgba(0,255,136,0.1);
}
.evo-slot.owned::after { background: linear-gradient(135deg, rgba(0,255,136,0.05) 0%, transparent 50%); }
.evo-slot.country-locked {
  opacity: 0.15;
  border-style: dashed;
}
.evo-slot-name {
  font-size: 12px;
  font-weight: bold;
  color: #ddd;
  margin-bottom: 3px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.evo-slot.owned .evo-slot-name { color: #00ff88; }
.evo-slot-desc {
  font-size: 10px;
  opacity: 0.5;
  line-height: 1.5;
}
.evo-slot-cost {
  position: absolute;
  top: 10px; right: 12px;
  font-size: 11px;
  color: #cc66ff;
  font-weight: bold;
}
.evo-slot.owned .evo-slot-cost { color: #00ff88; }
.evo-slot-icon {
  font-size: 10px;
  opacity: 0.4;
  margin-right: 4px;
}
.evo-slot-tier {
  font-size: 8px;
  opacity: 0.3;
  margin-bottom: 3px;
}

#evo-req-msg {
  text-align: center;
  font-size: 10px;
  color: #ff8844;
  opacity: 0.6;
  margin-top: 12px;
}

/* ===== TUTORIAL ===== */
#tutorial-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  display: none; align-items: center; justify-content: center;
  z-index: 200;
  padding: 20px;
  pointer-events: none;
}
#tutorial-overlay.active {
  display: flex;
  pointer-events: auto;
}
#tutorial-box {
  background: rgba(6,6,16,0.97);
  border: 1px solid rgba(0,255,136,0.3);
  border-radius: 10px;
  padding: 24px 28px;
  max-width: 440px;
  width: 100%;
  text-align: center;
}
#tut-title {
  font-size: 16px;
  font-weight: bold;
  letter-spacing: 3px;
  color: #00ff88;
  margin-bottom: 14px;
}
#tut-text {
  font-size: 12px;
  line-height: 1.9;
  opacity: 0.8;
  white-space: pre-line;
  text-align: left;
  margin-bottom: 16px;
  max-height: 50vh;
  overflow-y: auto;
}
#tut-highlight {
  font-size: 10px;
  color: #ffcc00;
  opacity: 0.7;
  margin-bottom: 12px;
  letter-spacing: 1px;
}
#tutorial-box .btn {
  margin-top: 4px;
}

@media (max-width: 480px) {
  #tutorial-box { padding: 16px 18px; }
  #tut-title { font-size: 14px; }
  #tut-text { font-size: 11px; line-height: 1.7; }
}

/* ===== COMMS INTERCEPTS ===== */
.comms-intercept {
  position: fixed;
  top: 50px; left: 50%; transform: translateX(-50%);
  background: rgba(0,20,40,0.9);
  border: 1px solid rgba(0,200,255,0.3);
  border-radius: 6px;
  padding: 10px 20px;
  font-size: 11px;
  letter-spacing: 1px;
  z-index: 60;
  animation: commsSlideIn 0.3s ease;
  max-width: 500px;
  text-align: center;
}
.comms-info { color: #44ddff; border-color: rgba(0,200,255,0.3); }
.comms-warn { color: #ffcc00; border-color: rgba(255,200,0,0.3); background: rgba(40,30,0,0.9); }
.comms-danger { color: #ff4444; border-color: rgba(255,50,50,0.3); background: rgba(40,0,0,0.9); }
.comms-fade { opacity: 0; transition: opacity 1s; }
@keyframes commsSlideIn { from { opacity:0; transform: translateX(-50%) translateY(-10px); } to { opacity:1; transform: translateX(-50%); } }

/* ===== ACHIEVEMENTS ===== */
.achievement-popup {
  position: fixed;
  bottom: 100px; right: 20px;
  background: rgba(10,10,30,0.95);
  border: 1px solid rgba(204,102,255,0.4);
  border-radius: 8px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 60;
  animation: achSlideIn 0.4s ease;
  min-width: 200px;
}
.ach-icon { font-size: 20px; color: #cc66ff; min-width: 24px; text-align: center; }
.ach-name { font-size: 12px; font-weight: bold; color: #cc66ff; letter-spacing: 1px; }
.ach-desc { font-size: 10px; opacity: 0.6; margin-top: 2px; }
.ach-fade { opacity: 0; transition: opacity 1s; }
@keyframes achSlideIn { from { opacity:0; transform: translateX(20px); } to { opacity:1; transform: translateX(0); } }

/* ===== MINI-MAP ===== */
#minimap {
  position: fixed;
  bottom: 80px; left: 12px;
  width: 160px; height: 90px;
  background: rgba(6,6,16,0.85);
  border: 1px solid rgba(0,255,136,0.15);
  border-radius: 4px;
  z-index: 10;
  display: none;
  overflow: hidden;
}
#minimap canvas {
  width: 100%; height: 100%;
}

/* ===== RIVAL STATS ===== */
#rival-stats {
  position: fixed;
  top: 46px; right: 12px;
  background: rgba(6,6,16,0.88);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 6px;
  padding: 8px 10px;
  z-index: 10;
  font-size: 10px;
  min-width: 140px;
}
.rs-title { font-size: 8px; letter-spacing: 2px; opacity: 0.4; margin-bottom: 5px; }
.rs-row { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.rs-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.rs-name { flex: 1; }
.rs-nodes { opacity: 0.6; min-width: 28px; text-align: right; }
.rs-power { font-size: 9px; opacity: 0.4; min-width: 30px; text-align: right; }
.rs-eliminated { opacity: 0.3; text-decoration: line-through; }
.rs-bar { height: 2px; background: rgba(255,255,255,0.06); border-radius: 1px; margin-top: 2px; }
.rs-bar-fill { height: 100%; border-radius: 1px; transition: width 0.3s; }

/* ===== OVERLAYS ===== */
.overlay {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: linear-gradient(180deg, #050510 0%, #0a0a1f 40%, #080816 100%);
  z-index: 100; text-align: center; padding: 20px;
  overflow-y: auto;
}
.overlay h1 { font-size: 36px; letter-spacing: 6px; margin-bottom: 8px; }
.overlay .sub { font-size: 15px; opacity: 0.7; letter-spacing: 3px; margin-bottom: 20px; }
.overlay .desc { font-size: 16px; max-width: 520px; line-height: 1.9; opacity: 0.8; margin-bottom: 24px; }
.level-info {
  font-size: 15px;
  opacity: 0.7;
  margin-bottom: 20px;
  line-height: 1.8;
}

/* ===== MAIN MENU ===== */
#menu-title-area {
  margin-bottom: 28px;
}
.menu-logo {
  font-size: 18px;
  letter-spacing: 8px;
  opacity: 0.8;
  margin-bottom: 6px;
  color: #cc66ff;
  font-weight: bold;
}
#start-screen h1 {
  font-size: 40px;
  letter-spacing: 8px;
  background: linear-gradient(90deg, #00ff88, #44ddff, #cc66ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}
.menu-tagline {
  font-size: 16px;
  opacity: 0.6;
  letter-spacing: 2px;
  color: #88bbaa;
}
#menu-main-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  width: 100%;
  max-width: 1100px;
  padding: 0 16px;
}
#menu-center { flex: 1; min-width: 0; max-width: 700px; margin: 0 auto; }
.menu-book-cover {
  flex-shrink: 0;
  width: 130px;
  max-height: 208px;
  overflow: hidden;
  border-radius: 4px;
}
.menu-book-cover a { display: block; }
.menu-book-cover img {
  width: 100%;
  height: auto;
  cursor: pointer;
  border-radius: 4px;
  box-shadow: 0 0 20px rgba(0,255,136,0.15), 0 4px 16px rgba(0,0,0,0.6);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.menu-book-cover img:hover {
  transform: scale(1.04);
  box-shadow: 0 0 30px rgba(0,255,136,0.3), 0 6px 24px rgba(0,0,0,0.7);
}
@media (max-width: 1000px) {
  #menu-main-row {
    flex-wrap: wrap;
    gap: 12px;
  }
  #menu-center { order: 1; width: 100%; flex-basis: 100%; }
  .menu-book-cover {
    order: 2;
    width: 100px;
    max-height: none;
  }
  .menu-book-cover.left { margin-left: auto; }
  .menu-book-cover.right { margin-right: auto; }
}
#menu-content { width: 100%; max-width: 700px; margin: 0 auto; }

/* ===== COUNTRY SELECT ===== */
#country-select {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  max-width: 700px;
  margin: 0 auto;
  padding: 0 10px;
}
.country-card {
  background: rgba(255,255,255,0.02);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  padding: 14px 12px;
  cursor: pointer;
  transition: all 0.25s;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.country-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: linear-gradient(90deg, transparent, rgba(0,255,136,0.3), transparent);
  opacity: 0;
  transition: opacity 0.3s;
}
.country-card:hover::before { opacity: 1; }
.country-card:hover { background: rgba(0,255,136,0.05); border-color: rgba(0,255,136,0.3); transform: translateY(-2px); }
.country-card.locked {
  opacity: 0.2;
  cursor: default;
  pointer-events: none;
}
.country-card.locked::before { display: none; }
.country-card.completed { border-color: rgba(0,255,136,0.3); }
.country-card.completed::before { opacity: 0.5; background: linear-gradient(90deg, transparent, rgba(0,255,136,0.5), transparent); }
.country-card .cc-name { font-size: 16px; font-weight: bold; letter-spacing: 2px; margin-bottom: 4px; color: #ddeedd; }
.country-card .cc-info { font-size: 13px; opacity: 0.6; margin-bottom: 4px; }
.country-card .cc-new { font-size: 12px; color: #cc88ff; margin-bottom: 3px; opacity: 0.8; }
.country-card .cc-status { font-size: 12px; margin-top: 4px; opacity: 0.6; }
.country-card.completed .cc-status { color: #00ff88; opacity: 0.9; }
.country-card .cc-progress { height: 2px; background: rgba(255,255,255,0.06); border-radius: 1px; margin-top: 6px; }
.country-card .cc-progress-fill { height: 100%; background: #00ff88; border-radius: 1px; transition: width 0.3s; }

/* ===== LEVEL SELECT ===== */
#level-select {
  max-width: 500px;
  width: 100%;
  margin: 0 auto;
}
#level-select h2 {
  font-size: 24px;
  letter-spacing: 4px;
  color: #00ff88;
  margin-bottom: 4px;
}
#ls-country-info {
  font-size: 14px;
  opacity: 0.6;
  margin-bottom: 16px;
}
#ls-levels {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.level-card {
  background: rgba(255,255,255,0.02);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 6px;
  padding: 10px 14px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
}
.level-card:hover { background: rgba(0,255,136,0.05); border-color: rgba(0,255,136,0.3); }
.level-card.locked { opacity: 0.25; cursor: default; pointer-events: none; }
.level-card.completed { border-color: rgba(0,255,136,0.25); }
.level-card .lc-num {
  font-size: 18px; font-weight: bold; color: rgba(255,255,255,0.15);
  min-width: 30px; text-align: center;
}
.level-card.completed .lc-num { color: #00ff88; }
.level-card.next .lc-num { color: #44ddff; }
.level-card .lc-body { flex: 1; }
.level-card .lc-name { font-size: 15px; font-weight: bold; letter-spacing: 1px; color: #ddeedd; }
.level-card .lc-desc { font-size: 13px; opacity: 0.6; margin-top: 3px; }
.level-card .lc-grade {
  font-size: 14px; font-weight: bold; min-width: 24px; text-align: center;
}
.level-card.completed .lc-grade { color: #00ff88; }

/* ===== IN-GAME MENU BUTTON ===== */
#menu-btn {
  position: fixed;
  top: 42px; right: 12px;
  background: rgba(6,6,16,0.8);
  border: 1px solid rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.5);
  font-family: 'Courier New', monospace;
  font-size: 9px;
  padding: 4px 10px;
  letter-spacing: 2px;
  cursor: pointer;
  z-index: 11;
  border-radius: 3px;
  transition: all 0.2s;
}
#menu-btn:hover { border-color: rgba(255,255,255,0.4); color: rgba(255,255,255,0.8); }

.btn {
  background: transparent; border: 1px solid #00ff88; color: #00ff88;
  font-family: 'Courier New', monospace; font-size: 15px;
  padding: 12px 32px; letter-spacing: 2px; cursor: pointer;
  transition: all 0.2s; margin: 4px;
}
.btn:hover { background: rgba(0,255,136,0.12); }
.btn-dim { border-color: rgba(255,255,255,0.2); color: rgba(255,255,255,0.5); }
.btn-dim:hover { background: rgba(255,255,255,0.05); }
.btn-back {
  border-color: rgba(255,255,255,0.15); color: rgba(255,255,255,0.4);
  font-size: 10px; padding: 6px 14px; margin-bottom: 16px;
}
.btn-back:hover { border-color: rgba(255,255,255,0.3); color: rgba(255,255,255,0.7); }

/* ===== RESULT ===== */
#result-screen { display: none; }
#result-screen .stats { font-size: 11px; opacity: 0.6; line-height: 2; margin: 16px 0 24px; }
.win h1 { color: #00ff88; }
.lose h1 { color: #ff3355; }

/* ===== TOOLTIP ===== */
#tooltip {
  position: fixed;
  background: rgba(6,6,16,0.92);
  border: 1px solid rgba(0,255,136,0.25);
  border-radius: 4px;
  padding: 6px 10px;
  font-size: 10px;
  pointer-events: none;
  z-index: 20;
  display: none;
  max-width: 200px;
  line-height: 1.5;
}

/* ===== ANIMATIONS ===== */
@keyframes evtFlash {
  0% { opacity: 0; transform: translate(-50%,-50%) scale(0.8); }
  10% { opacity: 1; transform: translate(-50%,-50%) scale(1.1); }
  20% { transform: translate(-50%,-50%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%,-50%) scale(1); }
}

/* ===============================================
   TABLET — max-width: 768px
   =============================================== */
@media (max-width: 768px) {
  #hud { padding: 6px 8px; }
  .hud-block { gap: 10px; }
  .hud-item { min-width: 60px; }
  .hud-val { font-size: 13px; }
  .hud-bar-wrap { height: 4px; }

  .ability-btn { width: 48px; height: 48px; }
  .ability-btn .icon { font-size: 15px; }
  .ability-btn .lbl { font-size: 7px; }
  .ability-btn .cost { font-size: 7px; }
  #ability-bar { gap: 4px; padding: 6px 8px; }

  #event-log { width: 200px; max-height: 100px; bottom: 72px; }
  .log-entry { font-size: 9px; }

  #node-panel { width: 170px; font-size: 10px; }

  .evo-branches { gap: 8px; }
  .evo-branch { padding: 8px; }
  .evo-slot-name { font-size: 10px; }
}

/* ===============================================
   MOBILE — max-width: 480px
   =============================================== */
@media (max-width: 480px) {
  /* HUD compact */
  #hud { padding: 4px 6px; flex-wrap: wrap; gap: 2px; }
  .hud-block { gap: 6px; }
  .hud-item { min-width: 52px; }
  .hud-val { font-size: 11px; }
  .hud-label { font-size: 7px; letter-spacing: 1px; }

  /* Legend toggle visible, legend hidden */
  #legend-toggle { display: block; }
  #legend {
    top: auto;
    bottom: 80px;
    left: 12px;
    z-index: 15;
  }

  /* Ability bar compact */
  #ability-bar {
    gap: 3px;
    padding: 5px 6px;
    bottom: 6px;
  }
  .ability-btn {
    width: 42px; height: 42px;
  }
  .ability-btn .icon { font-size: 14px; }
  .ability-btn .lbl { display: none; }
  .ability-btn .cost { font-size: 7px; }
  .ability-btn .hotkey { display: none; }

  /* Node panel as bottom drawer */
  #node-panel {
    position: fixed;
    right: 0; left: 0; bottom: 56px;
    top: auto;
    width: 100%;
    max-height: 35vh;
    border-radius: 10px 10px 0 0;
    padding: 8px 12px;
    font-size: 10px;
  }
  .panel-handle { display: block; }
  #panel-close { display: block; }

  /* Event log compact */
  #event-log {
    left: 6px; right: 6px;
    bottom: 56px;
    width: auto;
    max-height: 45px;
  }
  .log-entry { font-size: 8px; }

  /* Tooltip hidden on touch */
  #tooltip { display: none !important; }

  /* Evo panel mobile */
  #evo-toggle { right: 6px; bottom: 54px; font-size: 9px; padding: 4px 8px; }
  .evo-branches { flex-direction: column; align-items: stretch; }
  .evo-branch { max-width: 100%; }
  #evo-panel { padding: 10px; }
  .evo-header h2 { font-size: 14px; }

  /* Overlays */
  .overlay h1 { font-size: 20px; letter-spacing: 4px; }
  .overlay .sub { font-size: 10px; margin-bottom: 20px; }
  .overlay .desc { font-size: 11px; max-width: 90vw; line-height: 1.7; margin-bottom: 18px; }
  .btn { padding: 8px 20px; font-size: 12px; }
}

/* ===============================================
   MOBILE LANDSCAPE — compact gameplay UI
   =============================================== */
@media (max-height: 500px) and (orientation: landscape) {
  /* Hide minimap — too small to be useful, wastes space */
  #minimap { display: none !important; }

  /* Hide legend toggle — frees up left side */
  #legend-toggle { display: none !important; }
  #legend { display: none !important; }

  /* Hide event log — obscures gameplay on small screens */
  #event-log { display: none !important; }

  /* Streamlined HUD — single row, essential info only */
  #hud {
    padding: 3px 8px;
    gap: 0;
  }
  .hud-block { gap: 8px; }
  .hud-item { min-width: 46px; }
  .hud-val { font-size: 11px; }
  .hud-label { font-size: 6px; letter-spacing: 1px; }
  .hud-bar-wrap { height: 2px; }

  /* Hide Cycle counter — non-essential */
  #hv-cycle { display: none; }
  #hv-cycle + .hud-bar-wrap { display: none; }
  .hud-item:has(#hv-cycle) { display: none; }

  /* Compact ability bar */
  #ability-bar {
    bottom: 4px;
    gap: 2px;
    padding: 4px 6px;
    border-radius: 6px;
  }
  .ability-btn {
    width: 38px; height: 38px;
  }
  .ability-btn .icon { font-size: 13px; }
  .ability-btn .lbl { display: none; }
  .ability-btn .cost { font-size: 6px; }
  .ability-btn .hotkey { display: none; }

  /* Node panel — right side, not bottom (landscape is already short) */
  #node-panel {
    position: fixed;
    right: 4px; top: 34px;
    left: auto; bottom: auto;
    width: 150px;
    max-height: calc(100vh - 80px);
    overflow-y: auto;
    border-radius: 6px;
    padding: 6px 8px;
    font-size: 9px;
  }
  .panel-handle { display: none; }
  #panel-close {
    display: block;
    background: rgba(255,50,50,0.15);
    border: 1px solid rgba(255,50,50,0.4);
    border-radius: 4px;
    color: #ff4444;
    font-size: 18px;
    width: 26px; height: 26px;
    line-height: 24px;
    text-align: center;
    top: 4px; right: 4px;
    padding: 0;
  }

  /* Pause button smaller */
  #menu-btn {
    font-size: 9px;
    padding: 4px 10px;
    top: 4px;
    right: 4px;
  }

  /* Evo toggle compact */
  #evo-toggle { right: 4px; bottom: 48px; font-size: 8px; padding: 3px 6px; }

  /* Rival stats compact */
  #rival-stats { font-size: 9px; padding: 5px 8px; top: 36px; }

  /* ===== MAIN MENU — scrollable in landscape ===== */
  .overlay {
    justify-content: flex-start;
    padding: 10px 12px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Compact title area */
  #menu-title-area { margin-bottom: 8px; }
  .menu-logo { font-size: 12px; letter-spacing: 4px; margin-bottom: 2px; }
  #start-screen h1 { font-size: 22px; letter-spacing: 4px; margin-bottom: 4px; }
  .menu-tagline { font-size: 12px; letter-spacing: 1px; margin-bottom: 4px; }

  /* Hide book covers on mobile menu — they eat too much space */
  .menu-book-cover { display: none; }

  /* Country select — compact grid for landscape */
  #country-select {
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    padding: 0 4px;
    max-width: 100%;
  }
  .country-card {
    padding: 8px 6px;
  }
  .country-card .cc-name { font-size: 13px; letter-spacing: 1px; margin-bottom: 2px; }
  .country-card .cc-info { font-size: 10px; margin-bottom: 2px; }
  .country-card .cc-new { font-size: 9px; margin-bottom: 1px; }
  .country-card .cc-status { font-size: 9px; margin-top: 2px; }

  /* Level select compact */
  #level-select { max-width: 100%; }
  #level-select h2 { font-size: 18px; letter-spacing: 2px; margin-bottom: 2px; }
  #ls-country-info { font-size: 12px; margin-bottom: 8px; }
  .level-card { padding: 6px 10px; gap: 8px; }
  .level-card .lc-num { font-size: 14px; min-width: 24px; }
  .level-card .lc-name { font-size: 13px; }
  .level-card .lc-desc { font-size: 11px; }

  /* Level intro compact */
  .overlay h1 { font-size: 22px; letter-spacing: 4px; }
  .overlay .sub { font-size: 11px; margin-bottom: 8px; }
  .overlay .desc { font-size: 12px; line-height: 1.5; margin-bottom: 10px; max-width: 90vw; }
  .level-info { font-size: 12px; line-height: 1.5; margin-bottom: 10px; }
  .btn { padding: 8px 20px; font-size: 13px; }

  /* Menu audio controls compact */
  #menu-audio-controls { transform: scale(0.85); transform-origin: top right; }
}

/* ===== VIDEO AD OVERLAY ===== */
#video-overlay {
  position: fixed; inset: 0;
  background: #000;
  z-index: 500;
  display: flex; align-items: center; justify-content: center;
}
#ad-video {
  max-width: 100%; max-height: 100%;
  width: 100%; height: 100%;
  object-fit: contain;
  background: #000;
}

/* ===== JANUS DEFEATED OVERLAY ===== */
#janus-defeated {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0);
  display: none; flex-direction: column;
  align-items: center; justify-content: center;
  z-index: 300; text-align: center;
  transition: background 1.5s ease;
  font-family: 'Courier New', monospace;
}
#janus-defeated.jd-active {
  background: rgba(0,0,0,0.9);
}
.jd-glitch {
  font-size: 48px; font-weight: bold;
  letter-spacing: 10px;
  color: #ff0050;
  text-shadow: 0 0 20px rgba(255,0,80,0.5), 0 0 60px rgba(255,0,80,0.2);
  animation: jd-flicker 0.15s infinite alternate;
  opacity: 0;
  transition: opacity 1s ease 0.5s;
}
#janus-defeated.jd-active .jd-glitch {
  opacity: 1;
  animation: jd-flicker 0.15s 3 alternate, jd-fadeToGreen 2s ease 1.5s forwards;
}
.jd-status {
  font-size: 18px; letter-spacing: 6px;
  color: #00ff88;
  margin-top: 20px;
  opacity: 0;
  transition: opacity 1s ease 2s;
}
#janus-defeated.jd-active .jd-status { opacity: 1; }
.jd-message {
  font-size: 14px; color: rgba(255,255,255,0.7);
  margin-top: 30px; line-height: 2;
  opacity: 0;
  transition: opacity 1s ease 3s;
}
#janus-defeated.jd-active .jd-message { opacity: 1; }
.jd-sub {
  font-size: 11px; color: rgba(255,255,255,0.3);
  margin-top: 16px; line-height: 1.8;
  opacity: 0;
  transition: opacity 1s ease 4s;
}
#janus-defeated.jd-active .jd-sub { opacity: 1; }

@keyframes jd-flicker {
  0% { opacity: 1; text-shadow: 0 0 20px rgba(255,0,80,0.5); }
  50% { opacity: 0.7; text-shadow: -2px 0 #ff0050, 2px 0 #00ff88; }
  100% { opacity: 1; text-shadow: 0 0 30px rgba(255,0,80,0.8); }
}
@keyframes jd-fadeToGreen {
  to {
    color: #00ff88;
    text-shadow: 0 0 20px rgba(0,255,136,0.5), 0 0 60px rgba(0,255,136,0.2);
    animation: none;
  }
}
