/* ── Tower Defense — WildflowerJS Demo ── */

@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700;900&family=Exo+2:wght@400;600;700&display=swap');

:root {
  --bg-void: #0a0a1a;
  --bg-field: #111128;
  --hud-bg: rgba(10, 10, 30, 0.85);
  --hud-border: rgba(100, 120, 255, 0.3);
  --accent: #6c8cff;
  --accent-glow: rgba(108, 140, 255, 0.4);
  --gold: #ffd700;
  --gold-glow: rgba(255, 215, 0, 0.5);
  --hp-green: #00ff88;
  --hp-red: #ff3355;
  --fire: #ff6633;
  --ice: #33ccff;
  --poison: #66ff33;
  --thunder: #ffcc00;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
[data-cloak] { display: none !important; }

body {
  background: var(--bg-void);
  color: #e0e0f0;
  font-family: 'Exo 2', sans-serif;
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  cursor: crosshair;
}

/* ── HUD ── */
.hud {
  position: fixed;
  top: 48px; left: 0; right: 0;
  height: 48px;
  background: var(--hud-bg);
  border-bottom: 1px solid var(--hud-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 100;
  /* backdrop-filter: blur(8px);  PERF: disabled — forces re-composite every frame in Chrome */
  font-family: 'Orbitron', monospace;
}

.hud-left, .hud-right { display: flex; align-items: center; gap: 20px; flex-shrink: 0; }

.hud-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: rgba(200, 210, 255, 0.6);
}

.hud-value {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  font-variant-numeric: tabular-nums;
  min-width: 3ch;
  text-align: right;
}

.hud-value.gold { color: var(--gold); text-shadow: 0 0 8px var(--gold-glow); }
.hud-value.stage { color: var(--accent); }

.hp-bar-container {
  width: 200px;
  height: 12px;
  background: rgba(255,255,255,0.1);
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.15);
}

.hp-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--hp-green), #44ff99);
  transition: width 0.3s ease, background 0.5s;
  border-radius: 6px;
}

.hp-bar-fill.critical {
  background: linear-gradient(90deg, var(--hp-red), #ff6644);
}

.btn-pause {
  background: none;
  border: 1px solid var(--hud-border);
  color: #aab;
  padding: 6px 14px;
  border-radius: 6px;
  font-family: 'Orbitron', monospace;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-pause:hover { border-color: var(--accent); color: #fff; }

/* ── Game Field ── */
.game-field {
  position: fixed;
  top: 48px; left: 0; right: 0; bottom: 0;
  background: var(--bg-field);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

/* Starfield */
.game-field::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(1px 1px at 10% 20%, rgba(255,255,255,0.4) 50%, transparent 100%),
    radial-gradient(1px 1px at 30% 60%, rgba(255,255,255,0.3) 50%, transparent 100%),
    radial-gradient(1px 1px at 50% 10%, rgba(255,255,255,0.5) 50%, transparent 100%),
    radial-gradient(1px 1px at 70% 80%, rgba(255,255,255,0.3) 50%, transparent 100%),
    radial-gradient(1px 1px at 90% 40%, rgba(255,255,255,0.4) 50%, transparent 100%),
    radial-gradient(1px 1px at 15% 85%, rgba(255,255,255,0.2) 50%, transparent 100%),
    radial-gradient(1px 1px at 85% 15%, rgba(255,255,255,0.3) 50%, transparent 100%),
    radial-gradient(2px 2px at 45% 45%, rgba(108,140,255,0.3) 50%, transparent 100%),
    radial-gradient(1px 1px at 60% 30%, rgba(255,255,255,0.25) 50%, transparent 100%),
    radial-gradient(1px 1px at 25% 50%, rgba(255,255,255,0.35) 50%, transparent 100%);
  pointer-events: none;
}

/* Grid lines */
.game-field::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(100,120,255,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(100,120,255,0.03) 1px, transparent 1px);
  background-size: 60px 60px;
  pointer-events: none;
}

/* ── Throne ── */
.throne {
  position: absolute;
  width: 64px;
  height: 64px;
  transform: translate(-50%, -50%);
  z-index: 10;
}

.throne-core {
  width: 100%;
  height: 100%;
  background: radial-gradient(circle, var(--accent) 0%, #3344aa 60%, transparent 100%);
  border-radius: 50%;
  animation: throne-pulse 2s ease-in-out infinite;
  box-shadow: 0 0 30px var(--accent-glow), 0 0 60px rgba(108,140,255,0.15);
}

.throne-ring {
  position: absolute;
  inset: -8px;
  border: 2px solid rgba(108,140,255,0.3);
  border-radius: 50%;
  animation: throne-ring-rotate 8s linear infinite;
}

.throne-ring::before {
  content: '';
  position: absolute;
  top: -3px; left: 50%; transform: translateX(-50%);
  width: 6px; height: 6px;
  background: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 6px var(--accent);
}

@keyframes throne-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.08); opacity: 0.85; }
}

@keyframes throne-ring-rotate {
  to { transform: rotate(360deg); }
}

/* ── Tower ── */
.tower {
  position: absolute;
  width: 52px;
  height: 52px;
  transform: translate(-50%, -50%);
  cursor: pointer;
  z-index: 8;
  transition: transform 0.15s;
}

.tower:hover { transform: translate(-50%, -50%) scale(1.1); }

.tower-body {
  width: 100%;
  height: 100%;
  border-radius: 8px;
  border: 2px solid rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  transition: all 0.3s;
  position: relative;
}

.tower.not-built .tower-body {
  background: rgba(255,255,255,0.05);
  border: 2px dashed rgba(255,255,255,0.2);
  animation: tower-unbuilt-pulse 3s ease-in-out infinite;
}

@keyframes tower-unbuilt-pulse {
  0%, 100% { border-color: rgba(255,255,255,0.15); }
  50% { border-color: rgba(255,255,255,0.35); }
}

.tower.fire .tower-body { background: rgba(255,102,51,0.2); border-color: var(--fire); box-shadow: 0 0 15px rgba(255,102,51,0.3); }
.tower.ice .tower-body { background: rgba(51,204,255,0.2); border-color: var(--ice); box-shadow: 0 0 15px rgba(51,204,255,0.3); }
.tower.poison .tower-body { background: rgba(102,255,51,0.2); border-color: var(--poison); box-shadow: 0 0 15px rgba(102,255,51,0.3); }
.tower.thunder .tower-body { background: rgba(255,204,0,0.2); border-color: var(--thunder); box-shadow: 0 0 15px rgba(255,204,0,0.3); }

.tower-level {
  position: absolute;
  bottom: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Orbitron', monospace;
}

.tower-cost {
  position: absolute;
  top: -20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  font-family: 'Orbitron', monospace;
  color: var(--gold);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.2s;
}

.tower:hover .tower-cost { opacity: 1; }

/* ── Enemy ── */
.enemy {
  position: absolute;
  transform: translate(-50%, -50%);
  z-index: 5;
  cursor: pointer;
  transition: opacity 0.15s;
  pointer-events: auto;
}

.enemy-body {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  position: relative;
  border: 2px solid rgba(255,255,255,0.15);
}

.enemy.common .enemy-body { background: radial-gradient(circle, #9944cc 0%, #663399 100%); }
.enemy.common-yellow .enemy-body { background: radial-gradient(circle, #cc9933 0%, #997722 100%); }
.enemy.common-blue .enemy-body { background: radial-gradient(circle, #3366cc 0%, #224499 100%); }
.enemy.elite .enemy-body { background: radial-gradient(circle, #cc3333 0%, #991111 100%); border-color: rgba(255,100,100,0.4); }
.enemy.elite-green .enemy-body { background: radial-gradient(circle, #33cc44 0%, #229933 100%); border-color: rgba(100,255,100,0.4); }
.enemy.elite-blue .enemy-body { background: radial-gradient(circle, #3388ff 0%, #1155cc 100%); border-color: rgba(100,150,255,0.4); }
.enemy.elite-gold .enemy-body { background: radial-gradient(circle, #cc9900 0%, #886600 100%); border-color: rgba(255,200,50,0.4); }

.enemy-hp {
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 30px;
  height: 3px;
  background: rgba(255,255,255,0.15);
  border-radius: 2px;
  overflow: hidden;
}

.enemy-hp-fill {
  height: 100%;
  background: var(--hp-green);
  transition: width 0.15s;
  border-radius: 2px;
}

.enemy.dying {
  animation: enemy-die 0.3s ease-out forwards;
}

@keyframes enemy-die {
  0% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  50% { transform: translate(-50%, -50%) scale(1.3); opacity: 0.6; }
  100% { transform: translate(-50%, -50%) scale(0); opacity: 0; }
}

/* ── Projectile ── */
.projectile {
  position: absolute;
  width: 10px;
  height: 10px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  z-index: 6;
  pointer-events: none;
}

.projectile.fire { background: var(--fire); box-shadow: 0 0 8px var(--fire), 0 0 16px rgba(255,102,51,0.4); }
.projectile.ice { background: var(--ice); box-shadow: 0 0 8px var(--ice), 0 0 16px rgba(51,204,255,0.4); }
.projectile.poison { background: var(--poison); box-shadow: 0 0 8px var(--poison), 0 0 16px rgba(102,255,51,0.4); }
.projectile.thunder { background: var(--thunder); box-shadow: 0 0 8px var(--thunder), 0 0 16px rgba(255,204,0,0.4); }

.projectile.click-explosion {
  width: 24px;
  height: 24px;
  background: radial-gradient(circle, #fff 0%, var(--accent) 50%, transparent 100%);
  box-shadow: 0 0 20px var(--accent);
  animation: click-explode 0.3s ease-out forwards;
}

@keyframes click-explode {
  0% { transform: translate(-50%, -50%) scale(0.5); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(2.5); opacity: 0; }
}

/* ── Loot ── */
.loot {
  position: absolute;
  width: 14px;
  height: 14px;
  transform: translate(-50%, -50%);
  z-index: 7;
  pointer-events: none;
}

.loot-gem {
  width: 100%;
  height: 100%;
  background: var(--gold);
  border-radius: 2px;
  transform: rotate(45deg);
  box-shadow: 0 0 8px var(--gold-glow);
  animation: loot-spin 1s linear infinite;
}

@keyframes loot-spin {
  to { transform: rotate(405deg); }
}

/* ── Damage flash ── */
.damage-flash {
  position: absolute;
  width: 40px;
  height: 40px;
  transform: translate(-50%, -50%);
  z-index: 20;
  pointer-events: none;
  animation: damage-flash 0.4s ease-out forwards;
}

.damage-number {
  position: absolute;
  font-family: 'Orbitron', monospace;
  font-size: 14px;
  font-weight: 700;
  color: var(--hp-red);
  text-shadow: 0 0 4px rgba(255,50,80,0.6);
  text-align: center;
  pointer-events: none;
  animation: damage-flash 0.8s ease-out forwards;
  transform: translate(-50%, -50%);
}

@keyframes damage-flash {
  0% { transform: translate(-50%, -50%) translateY(0); opacity: 1; }
  100% { transform: translate(-50%, -50%) translateY(-30px); opacity: 0; }
}

/* Tower shoot flash */
.shoot-flash {
  position: absolute;
  width: 20px;
  height: 20px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  z-index: 9;
  pointer-events: none;
  animation: shoot-flash 0.2s ease-out forwards;
}

.shoot-flash.fire { background: radial-gradient(circle, #fff, var(--fire), transparent); }
.shoot-flash.ice { background: radial-gradient(circle, #fff, var(--ice), transparent); }
.shoot-flash.poison { background: radial-gradient(circle, #fff, var(--poison), transparent); }
.shoot-flash.thunder { background: radial-gradient(circle, #fff, var(--thunder), transparent); }

@keyframes shoot-flash {
  0% { transform: translate(-50%, -50%) scale(0.5); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(2); opacity: 0; }
}

/* ── Screens ── */
.screen-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 5, 20, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(12px);
}

.screen-title {
  font-family: 'Orbitron', monospace;
  font-size: 48px;
  font-weight: 900;
  letter-spacing: 4px;
  margin-bottom: 16px;
  background: linear-gradient(135deg, var(--accent), #aa88ff, var(--accent));
  background-size: 200% 200%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: title-shimmer 3s ease-in-out infinite;
}

@keyframes title-shimmer {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

.screen-subtitle {
  font-size: 16px;
  color: rgba(200, 210, 255, 0.6);
  margin-bottom: 40px;
  text-align: center;
  line-height: 1.6;
}

.btn-action {
  font-family: 'Orbitron', monospace;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 2px;
  padding: 14px 40px;
  border: 2px solid var(--accent);
  background: rgba(108, 140, 255, 0.1);
  color: #fff;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s;
  margin: 6px;
}

.btn-action:hover {
  background: rgba(108, 140, 255, 0.25);
  box-shadow: 0 0 20px var(--accent-glow);
  transform: translateY(-2px);
}

.btn-action.gold {
  border-color: var(--gold);
  background: rgba(255, 215, 0, 0.1);
}

.btn-action.gold:hover {
  background: rgba(255, 215, 0, 0.2);
  box-shadow: 0 0 20px var(--gold-glow);
}

.score-display {
  margin-top: 24px;
  font-family: 'Orbitron', monospace;
  font-size: 20px;
  color: var(--gold);
}

.hint-list {
  list-style: none;
  text-align: left;
  margin-bottom: 30px;
}

.hint-list li {
  padding: 6px 0;
  color: rgba(200, 210, 255, 0.5);
  font-size: 13px;
}

.hint-list li span {
  color: rgba(200, 210, 255, 0.8);
}

/* ── Wave announcement ── */
.wave-announce {
  position: fixed;
  top: 120px;
  left: 50%;
  transform: translateX(-50%);
  font-family: 'Orbitron', monospace;
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
  text-shadow: 0 0 20px var(--accent-glow);
  z-index: 50;
  animation: wave-fade 2s ease-out forwards;
  pointer-events: none;
}

@keyframes wave-fade {
  0% { opacity: 0; transform: translateX(-50%) translateY(10px); }
  15% { opacity: 1; transform: translateX(-50%) translateY(0); }
  70% { opacity: 1; }
  100% { opacity: 0; }
}

/* ── Responsive ── */
@media (max-width: 640px) {
  .hud { padding: 0 10px; height: 40px; }
  .hud-label { font-size: 8px; letter-spacing: 0.5px; }
  .hud-value { font-size: 12px; }
  .hud-left, .hud-right { gap: 8px; }
  .hp-bar-container { width: 60px; height: 8px; }
  .btn-pause { padding: 4px 8px; font-size: 10px; }
  .demo-info { display: none; }
  .hp-bar-container { width: 120px; height: 10px; }
  .screen-title { font-size: 32px; }
  .tower { width: 44px; height: 44px; }
  .game-field {
    transform: scale(var(--field-scale, 1));
    transform-origin: top left;
    width: calc(100% / var(--field-scale, 1));
    height: calc((100vh - 48px) / var(--field-scale, 1));
  }
  .demo-toolbar { flex-wrap: wrap; gap: 4px 12px; }
  .demo-toolbar .demo-info { font-size: 9px; }
}

/* ── Demo Toolbar ── */
.demo-toolbar { position: fixed; top: 0; left: 0; right: 0; z-index: 1000; display: flex; justify-content: space-between; align-items: center; padding: 8px 20px; background: rgba(26,26,46,0.95); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; border-bottom: 1px solid rgba(255,255,255,0.1); }
.demo-toolbar a { display: flex; align-items: center; gap: 10px; text-decoration: none; color: #5fa6a6; font-size: 1rem; }
.demo-toolbar .logo { height: 32px; }
.demo-toolbar .brand-wf { font-weight: 520; }
.demo-toolbar .brand-js { font-weight: 700; }
.demo-toolbar .demo-info { font-size: 11px; color: rgba(255,255,255,0.6); text-align: right; }
.demo-toolbar .demo-info strong { color: rgba(255,255,255,0.9); }
