:root {
  --bg: #0b111d;
  --panel: rgba(15, 24, 39, 0.94);
  --panel-2: #172238;
  --line: rgba(255, 255, 255, 0.09);
  --text: #f4f7fb;
  --muted: #93a1b7;
  --accent: #57e3a1;
  --accent-2: #65a9ff;
  --danger: #ff6b6b;
  --warning: #ffc55e;
  --shadow: 0 18px 50px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html, body { width: 100%; min-height: 100%; margin: 0; }
body {
  background: radial-gradient(circle at 50% 10%, #1a2942, var(--bg) 58%);
  color: var(--text);
  font-family: Inter, Arial, system-ui, sans-serif;
  overflow-x: hidden;
}
button { font: inherit; }
button, .tower-card, .level-card { user-select: none; }

#app { min-height: 100vh; }
.screen { display: none; min-height: 100vh; }
.screen.active { display: flex; }

/* HOME */
#homeScreen {
  position: relative;
  flex-direction: column;
  overflow: hidden;
  padding: 50px clamp(22px, 6vw, 90px) 34px;
  background:
    linear-gradient(180deg, rgba(8, 14, 25, .2), rgba(8, 14, 25, .95)),
    radial-gradient(circle at 78% 8%, rgba(101, 169, 255, .17), transparent 28%),
    radial-gradient(circle at 20% 70%, rgba(87, 227, 161, .12), transparent 30%);
}
.home-bg-grid {
  position: absolute;
  inset: -25%;
  transform: rotateX(62deg) rotateZ(45deg) scale(1.15);
  background-image: linear-gradient(rgba(255,255,255,.03) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.03) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: linear-gradient(to bottom, transparent, #000 25%, transparent 76%);
  pointer-events: none;
}
.hero, .level-select, .home-footer { position: relative; z-index: 1; }
.hero { max-width: 870px; }
.eyebrow { color: var(--accent); font-size: 13px; font-weight: 800; letter-spacing: .3em; }
.hero h1 {
  margin: 4px 0 10px;
  font-family: "Arial Narrow", "Roboto Condensed", Arial, sans-serif;
  font-size: clamp(68px, 10vw, 132px);
  line-height: .88;
  letter-spacing: -.035em;
  background: linear-gradient(180deg, #fff, #99aac1);
  -webkit-background-clip: text;
  color: transparent;
  text-shadow: 0 18px 55px rgba(107, 166, 255, .12);
}
.hero p { max-width: 670px; color: #aab6c8; font-size: clamp(15px, 2vw, 19px); line-height: 1.55; }
.level-select { margin-top: auto; }
.section-title { display: flex; align-items: end; justify-content: space-between; margin-bottom: 14px; }
.section-title span { font-family: "Arial Narrow", "Roboto Condensed", Arial, sans-serif; font-weight: 700; font-size: 22px; letter-spacing: .08em; }
.section-title small { color: var(--muted); }
.level-cards { display: grid; grid-template-columns: repeat(3, minmax(220px, 1fr)); gap: 18px; }
.level-card {
  position: relative;
  min-height: 220px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  cursor: pointer;
  background: linear-gradient(160deg, rgba(255,255,255,.08), rgba(255,255,255,.015));
  box-shadow: var(--shadow);
  transition: transform .22s ease, border-color .22s ease, box-shadow .22s ease;
}
.level-card::before { content: ""; position: absolute; inset: 0; background: var(--card-art); opacity: .78; }
.level-card::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, transparent 5%, rgba(7,12,21,.2) 40%, rgba(7,12,21,.95) 100%); }
.level-card > * { position: relative; z-index: 2; }
.level-card:hover { transform: translateY(-7px); border-color: rgba(255,255,255,.28); box-shadow: 0 24px 65px rgba(0,0,0,.48); }
.level-index { color: rgba(255,255,255,.72); font: 700 13px "Arial Narrow", "Roboto Condensed", Arial, sans-serif; letter-spacing: .18em; }
.level-card h3 { margin: 92px 0 5px; font: 800 30px "Arial Narrow", "Roboto Condensed", Arial, sans-serif; letter-spacing: .02em; }
.level-card p { margin: 0 0 12px; color: #b5c1d2; font-size: 13px; }
.level-tags { display: flex; gap: 7px; }
.level-tags span { padding: 5px 8px; border-radius: 7px; background: rgba(0,0,0,.27); color: #d9e2ee; font-size: 10px; font-weight: 700; letter-spacing: .08em; }
.home-footer { display: flex; justify-content: space-between; gap: 24px; margin-top: 20px; color: #6f7d91; font-size: 12px; }

/* GAME */
#gameScreen { flex-direction: column; background: #09101b; }
.topbar {
  height: 72px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  background: rgba(12, 19, 32, .96);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 10px 30px rgba(0,0,0,.18);
  z-index: 5;
}
.icon-btn, .chip-btn, .secondary-btn, .primary-btn {
  border: 1px solid var(--line);
  color: var(--text);
  cursor: pointer;
  transition: .15s ease;
}
.icon-btn { width: 42px; height: 42px; border-radius: 11px; background: #172238; font-size: 23px; }
.icon-btn:hover, .chip-btn:hover, .secondary-btn:hover { background: #22314e; }
.mission-label { min-width: 160px; }
.mission-label small, .status-pill small, .panel-heading small, .wave-block small, .result-stats small { display: block; color: var(--muted); font-size: 9px; font-weight: 800; letter-spacing: .13em; }
.mission-label strong { font-family: "Arial Narrow", "Roboto Condensed", Arial, sans-serif; font-size: 21px; letter-spacing: .04em; }
.status-cluster { display: flex; gap: 8px; margin-left: auto; }
.status-pill { min-width: 108px; height: 48px; display: flex; align-items: center; gap: 10px; padding: 7px 12px; border-radius: 12px; border: 1px solid var(--line); background: #121d31; }
.status-pill strong { font: 700 19px "Arial Narrow", "Roboto Condensed", Arial, sans-serif; }
.status-icon { color: var(--accent-2); }
.status-pill.ore .status-icon { color: var(--warning); }
.status-pill.health .status-icon { color: var(--accent); }
.top-actions { display: flex; gap: 7px; }
.chip-btn { min-width: 68px; height: 38px; padding: 0 11px; border-radius: 10px; background: #172238; font-size: 11px; font-weight: 700; }

.game-layout { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 320px; }
.canvas-shell { position: relative; min-width: 0; overflow: hidden; background: #0c1523; }
#gameCanvas { width: 100%; height: 100%; display: block; cursor: crosshair; }
.canvas-hint { position: absolute; left: 16px; bottom: 13px; color: rgba(255,255,255,.44); font-size: 10px; pointer-events: none; }
.announcement {
  position: absolute;
  left: 50%; top: 46%;
  transform: translate(-50%, -50%);
  min-width: 300px;
  padding: 16px 25px;
  border-radius: 14px;
  text-align: center;
  font: 800 26px "Arial Narrow", "Roboto Condensed", Arial, sans-serif;
  letter-spacing: .08em;
  background: rgba(9, 16, 28, .88);
  border: 1px solid rgba(255,255,255,.17);
  box-shadow: 0 18px 50px rgba(0,0,0,.35);
  pointer-events: none;
  z-index: 2;
}
.hidden { display: none !important; }
.hover-tip { position: absolute; z-index: 3; max-width: 230px; padding: 9px 11px; border-radius: 9px; color: #dfe7f2; background: rgba(7,12,21,.92); border: 1px solid var(--line); font-size: 11px; line-height: 1.45; pointer-events: none; }

.side-panel { min-height: 0; display: flex; flex-direction: column; gap: 10px; padding: 11px; overflow-y: auto; background: #0e1727; border-left: 1px solid var(--line); }
.panel-block { border: 1px solid var(--line); border-radius: 14px; background: linear-gradient(145deg, #162238, #111b2d); overflow: hidden; box-shadow: 0 8px 24px rgba(0,0,0,.13); }
.build-block { flex: 0 0 auto; padding: 14px; }
.panel-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 11px; }
.panel-heading h2 { margin: 1px 0 0; font: 700 22px "Arial Narrow", "Roboto Condensed", Arial, sans-serif; }
.mode-badge { padding: 5px 7px; border-radius: 7px; color: #88ffd0; background: rgba(87,227,161,.1); border: 1px solid rgba(87,227,161,.2); font-size: 9px; font-weight: 800; }
.tower-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tower-card {
  min-height: 81px;
  position: relative;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 11px;
  cursor: grab;
  background: rgba(255,255,255,.035);
  transition: .16s ease;
}
.tower-card:hover { transform: translateY(-2px); border-color: rgba(255,255,255,.22); background: rgba(255,255,255,.065); }
.tower-card.unaffordable { opacity: .48; }
.tower-card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(87,227,161,.12); }
.tower-card .tower-top { display: flex; gap: 7px; align-items: center; }
.tower-card .tower-symbol { width: 29px; height: 29px; display: grid; place-items: center; border-radius: 8px; background: var(--tower-color); color: #071019; font-weight: 900; }
.tower-card strong { font: 700 14px "Arial Narrow", "Roboto Condensed", Arial, sans-serif; line-height: 1; }
.tower-card p { margin: 7px 0 0; color: #8795aa; font-size: 9px; line-height: 1.3; }
.cost { position: absolute; top: 7px; right: 7px; color: #ffd271; font: 700 11px "Arial Narrow", "Roboto Condensed", Arial, sans-serif; }

.inspector { min-height: 164px; flex: 1 1 auto; padding: 14px; }
.empty-inspector { height: 100%; display: grid; place-content: center; justify-items: center; gap: 5px; text-align: center; color: var(--muted); }
.empty-inspector strong { color: #dbe3ef; font-size: 12px; }
.empty-inspector span { max-width: 210px; font-size: 10px; line-height: 1.4; }
.radar-icon { color: var(--accent-2); font-size: 29px; }
.inspector-head { display: flex; align-items: center; gap: 10px; }
.inspector-icon { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 11px; color: #071019; background: var(--tower-color); font-weight: 900; }
.inspector-head h3 { margin: 0; font: 700 20px "Arial Narrow", "Roboto Condensed", Arial, sans-serif; }
.inspector-head span { color: var(--muted); font-size: 10px; }
.hp-row { margin-top: 11px; }
.hp-label { display: flex; justify-content: space-between; font-size: 9px; color: var(--muted); }
.hp-track, .progress-track { height: 6px; border-radius: 20px; overflow: hidden; background: rgba(255,255,255,.07); }
.hp-fill { height: 100%; background: var(--accent); }
.stats-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 6px; margin: 10px 0; }
.stat-box { padding: 7px; border-radius: 8px; background: rgba(255,255,255,.035); }
.stat-box small { display: block; color: var(--muted); font-size: 8px; }
.stat-box strong { font: 700 13px "Arial Narrow", "Roboto Condensed", Arial, sans-serif; }
.inspector-actions { display: grid; grid-template-columns: 1fr auto; gap: 7px; }
.inspector-actions button { height: 35px; border-radius: 9px; }
.sell-btn { width: 58px; background: rgba(255,107,107,.08); border-color: rgba(255,107,107,.18); color: #ff9393; }

.wave-block { flex: 0 0 auto; padding: 13px; }
.wave-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.wave-row strong { display: block; margin-top: 2px; font: 700 17px "Arial Narrow", "Roboto Condensed", Arial, sans-serif; }
.primary-btn { padding: 0 15px; height: 38px; border-radius: 10px; color: #071019; background: linear-gradient(180deg, #79f2ba, #45cd8c); border-color: transparent; font-size: 11px; font-weight: 800; }
.primary-btn:hover { filter: brightness(1.08); transform: translateY(-1px); }
.primary-btn:disabled { opacity: .45; cursor: default; transform: none; }
.progress-track { margin-top: 10px; height: 5px; }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent-2), var(--accent)); }
.enemy-forecast { min-height: 20px; display: flex; gap: 5px; margin-top: 9px; }
.enemy-chip { padding: 4px 7px; border-radius: 6px; background: rgba(255,255,255,.05); color: #bac5d5; font-size: 8px; font-weight: 700; }

.secondary-btn { height: 40px; padding: 0 17px; border-radius: 10px; background: #19263d; }
.modal { position: fixed; inset: 0; display: grid; place-items: center; z-index: 20; background: rgba(3,7,13,.74); backdrop-filter: blur(8px); }
.modal-card { width: min(430px, calc(100vw - 30px)); padding: 30px; border-radius: 20px; text-align: center; border: 1px solid rgba(255,255,255,.13); background: linear-gradient(145deg, #1b2942, #111b2d); box-shadow: 0 30px 80px rgba(0,0,0,.52); }
.result-badge { color: var(--accent); font-size: 10px; font-weight: 800; letter-spacing: .18em; }
.modal-card h2 { margin: 8px 0 5px; font: 800 35px "Arial Narrow", "Roboto Condensed", Arial, sans-serif; }
.modal-card p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.result-stats { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin: 22px 0; }
.result-stats div { padding: 12px 6px; border-radius: 10px; background: rgba(255,255,255,.04); }
.result-stats strong { display: block; margin-top: 3px; font: 700 23px "Arial Narrow", "Roboto Condensed", Arial, sans-serif; }
.modal-actions { display: flex; justify-content: center; gap: 8px; }

@media (max-width: 980px) {
  .game-layout { grid-template-columns: 1fr; grid-template-rows: minmax(520px, 1fr) auto; }
  .side-panel { display: grid; grid-template-columns: 1.25fr 1fr; max-height: 390px; border-left: none; border-top: 1px solid var(--line); }
  .wave-block { grid-column: 1 / -1; }
  .level-cards { grid-template-columns: 1fr; }
  .level-card { min-height: 170px; }
  .level-card h3 { margin-top: 56px; }
  .home-footer { flex-direction: column; gap: 5px; }
  .status-pill { min-width: 82px; }
  .top-actions { display: none; }
}

@media (max-width: 650px) {
  #homeScreen { padding: 30px 16px; }
  .hero h1 { font-size: 74px; }
  .section-title small, .mission-label { display: none; }
  .status-cluster { margin-left: 0; flex: 1; }
  .status-pill { min-width: 0; flex: 1; padding: 6px 8px; }
  .status-icon { display: none; }
  .game-layout { grid-template-rows: 430px auto; }
  .side-panel { display: flex; max-height: none; }
  .tower-list { grid-template-columns: repeat(3,1fr); }
  .tower-card p { display: none; }
}
