* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; background: #1b1230;
  font-family: "Segoe UI", system-ui, sans-serif; color: #e8e2ff; }
#scene-wrap { position: fixed; inset: 0; }
#scene { width: 100%; height: 100%; display: block; touch-action: none; }

#hud-top { position: fixed; top: 8px; left: 10px; display: flex; gap: 10px;
  flex-wrap: wrap; pointer-events: none; z-index: 5; }
.stat { background: rgba(20, 12, 40, 0.72); border: 1px solid rgba(150, 120, 255, 0.35);
  border-radius: 8px; padding: 5px 10px; font-size: 14px; }
.stat.gold b { color: #ffd23f; } .stat.lives b { color: #ff7b9c; }
.stat.wave b { color: #8de8ff; } .stat.score b { color: #62ffa8; }
.stat.timer { color: #b9a8ff; }
.stat.hit { animation: flashHit 0.5s; } .stat.good { animation: flashGood 0.7s; }
@keyframes flashHit { 0% { background: #7a1e3a; } 100% { background: rgba(20,12,40,0.72); } }
@keyframes flashGood { 0% { background: #17604a; } 100% { background: rgba(20,12,40,0.72); } }

#top-btns { position: fixed; top: 8px; right: 10px; display: flex; gap: 6px; z-index: 6; }
#top-btns button, #tower-bar button, #touch-controls button, .big-btn {
  cursor: pointer; border: 1px solid rgba(160, 130, 255, 0.5); border-radius: 9px;
  background: rgba(40, 26, 74, 0.85); color: #e8e2ff; font-size: 14px; padding: 7px 11px; }
#top-btns button:hover, .tower-btn:hover { background: rgba(80, 52, 140, 0.9); }

#tower-bar { position: fixed; bottom: 12px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 8px; z-index: 6; }
.tower-btn { display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: 74px; position: relative; }
.tower-btn .t-key { position: absolute; top: 3px; right: 5px; font-size: 10px; color: #9c8cd6; }
.tower-btn .t-cost { color: #ffd23f; font-weight: 700; }
.tower-btn .t-name { color: #cfe6ff; }
.tower-btn.active { outline: 2px solid #8de8ff; background: rgba(70, 48, 130, 0.95); }
.wave-btn { background: rgba(28, 84, 66, 0.9) !important; border-color: #62ffa8 !important; }

#sel-info { position: fixed; bottom: 92px; left: 50%; transform: translateX(-50%);
  background: rgba(20, 12, 40, 0.82); border: 1px solid rgba(150,120,255,0.3);
  border-radius: 8px; padding: 6px 12px; font-size: 13px; z-index: 5;
  max-width: 92vw; text-align: center; }
#sel-info .ok { color: #62ffa8; } #sel-info .no { color: #ff7b9c; }

#banner { position: fixed; top: 52px; left: 50%; transform: translateX(-50%);
  background: rgba(70, 40, 130, 0.88); padding: 8px 18px; border-radius: 10px;
  font-size: 16px; z-index: 7; border: 1px solid #b9a8ff; }

#touch-controls { position: fixed; bottom: 88px; right: 12px; display: flex;
  flex-direction: column; gap: 10px; z-index: 8; }
#dpad { display: grid; grid-template-columns: repeat(3, 46px); grid-auto-rows: 46px;
  gap: 4px; justify-content: end; }
#dpad button { font-size: 18px; touch-action: none; user-select: none; }
#btn-up { grid-column: 2; grid-row: 1; } #btn-left { grid-column: 1; grid-row: 2; }
#btn-right { grid-column: 3; grid-row: 2; } #btn-down { grid-column: 2; grid-row: 3; }
#touch-actions { display: flex; flex-direction: column; gap: 6px; align-items: end; }

.overlay { position: fixed; inset: 0; display: flex; align-items: center;
  justify-content: center; background: rgba(12, 6, 26, 0.82); z-index: 20; }
.overlay.hidden { display: none; }
.panel { max-width: min(560px, 92vw); max-height: 86vh; overflow-y: auto;
  background: linear-gradient(160deg, #2a1b4e, #1c1132);
  border: 1px solid rgba(160, 130, 255, 0.45); border-radius: 16px;
  padding: 26px 30px; box-shadow: 0 20px 60px rgba(0,0,0,0.6); text-align: center; }
.panel h1 { font-size: clamp(30px, 8vw, 52px); letter-spacing: 4px; color: #8de8ff;
  text-shadow: 0 0 24px rgba(110, 220, 255, 0.45); }
.panel h2 { font-size: 26px; margin-bottom: 10px; }
#end-title.win { color: #62ffa8; } #end-title.lose { color: #ff7b9c; }
.panel .tag { color: #c8b8f8; margin: 10px 0 16px; font-size: 15px; }
.quick { list-style: none; text-align: left; font-size: 14px; line-height: 1.7;
  margin-bottom: 18px; }
.quick b { color: #8de8ff; }
.big-btn { font-size: 18px; padding: 12px 26px; background: rgba(40, 110, 88, 0.9);
  border-color: #62ffa8; }
.big-btn:hover { background: rgba(60, 150, 115, 0.95); }
.big-num { font-size: 22px; color: #ffd23f; margin: 8px 0 16px; }
.hidden { display: none; }

@media (max-width: 640px) {
  #tower-bar { bottom: 8px; gap: 5px; }
  .tower-btn { min-width: 62px; font-size: 12px; padding: 5px 6px; }
  .wave-btn { font-size: 12px; padding: 5px 8px; }
  #sel-info { bottom: 132px; font-size: 12px; }
  #touch-controls { bottom: 76px; }
  .stat { font-size: 12px; padding: 4px 7px; }
}
