/* ── Reset & base ────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: #020208;
  color: #c8d8ff;
  font-family: 'Microsoft YaHei', 'Noto Sans CJK SC', 'PingFang SC', sans-serif;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100vh;
  padding: 8px;
  overflow-x: hidden;
}

/* ── Animations ──────────────────────────────────────────────────────────────── */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(28px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; } to { opacity: 1; }
}
@keyframes slideInRight {
  from { opacity: 0; transform: translateX(18px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes glitch {
  0%,92%,100% { text-shadow: 0 0 18px #88aaff; transform: none; }
  93% { text-shadow: -3px 0 #ff0044, 3px 0 #00e5ff; transform: translate(-2px,0); }
  94% { text-shadow:  3px 0 #ff0044,-3px 0 #00e5ff; transform: translate( 2px,0); }
  95% { text-shadow: -2px 0 #ff0044, 2px 0 #00e5ff; transform: translate(-1px,0); }
  96% { text-shadow: none; transform: none; }
}
@keyframes scanline {
  0%   { transform: translateY(-100%); }
  100% { transform: translateY(400%); }
}
@keyframes pulse-glow {
  0%,100% { box-shadow: 0 0 6px currentColor,  inset 0 0 6px rgba(0,0,0,0.4); }
  50%     { box-shadow: 0 0 18px currentColor, inset 0 0 14px rgba(0,0,0,0.6); }
}
@keyframes border-march {
  to { background-position: 100% 0, 0 100%, 0 0, 100% 100%; }
}
@keyframes hud-blink {
  0%,100% { opacity: 1; } 50% { opacity: 0.6; }
}
@keyframes stagger {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes spin-slow {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
@keyframes flicker {
  0%,89%,91%,100% { opacity: 1; }
  90% { opacity: 0.7; }
}
@keyframes gold-pop {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.5); filter: brightness(1.8); text-shadow: 0 0 20px #ffe066, 0 0 40px rgba(255,220,0,0.8); }
  65%  { transform: scale(0.9); }
  100% { transform: scale(1); filter: none; }
}
@keyframes panel-slide-in {
  from { opacity: 0; transform: translateX(14px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes hud-enter {
  from { opacity: 0; transform: translateY(-10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Layout ──────────────────────────────────────────────────────────────────── */
#game-wrapper {
  display: grid;
  grid-template-columns: 1fr 220px;
  grid-template-rows: 40px 768px auto;
  grid-template-areas:
    "hud   hud"
    "cvs   sidebar"
    "keys  keys";
  gap: 0;
  width: 1372px;
  max-width: 100%;
}

/* ── HUD bar ─────────────────────────────────────────────────────────────────── */
#hud {
  grid-area: hud;
  background: linear-gradient(180deg, #10103a 0%, #08082a 100%);
  border: 1px solid #2a3a7a;
  border-bottom: 1px solid #1a2a5a;
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0;
  position: relative;
  overflow: hidden;
}

#hud-controls { margin-left: auto; display: flex; align-items: center; gap: 6px; padding: 0 8px; }
#hud-controls button {
  background: #0c1635; border: 1px solid #3355aa; color: #a8c4ff;
  padding: 7px 9px; min-height: 32px; cursor: pointer; font: 12px 'Microsoft YaHei', sans-serif;
  white-space: nowrap; touch-action: manipulation;
}
#hud-controls button:disabled { opacity: .45; cursor: default; }

#hud::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(255,255,255,0.015) 2px,
    rgba(255,255,255,0.015) 4px
  );
  pointer-events: none;
}

.hud-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 18px;
  height: 100%;
  border-right: 1px solid #1a2a4a;
  position: relative;
}
.hud-item::after {
  content: '';
  position: absolute;
  bottom: 0; left: 50%;
  transform: translateX(-50%);
  width: 40%;
  height: 1px;
  background: linear-gradient(90deg, transparent, #3355aa, transparent);
}

.hud-label {
  font-family: 'Orbitron', monospace;
  font-size: 8px;
  color: #445577;
  letter-spacing: 2px;
  text-transform: uppercase;
}
.hud-value {
  font-family: 'Orbitron', monospace;
  font-size: 15px;
  font-weight: 700;
  color: #ddeeff;
  text-shadow: 0 0 10px rgba(136,170,255,0.5);
}
.hud-value.lives { color: #ff6688; text-shadow: 0 0 10px rgba(255,80,100,0.6); }
.hud-value.gold  { color: #ffd700; text-shadow: 0 0 10px rgba(255,200,0,0.6); }

#send-early-btn {
  margin-left: auto;
  margin-right: 12px;
  background: linear-gradient(135deg, #1a2a5e, #0e1840);
  border: 1px solid #3355aa;
  border-top: 1px solid #5577cc;
  color: #88aaff;
  padding: 4px 14px;
  cursor: pointer;
  font-family: 'Orbitron', monospace;
  font-size: 10px;
  letter-spacing: 1px;
  transition: all 0.15s;
  text-transform: uppercase;
  clip-path: polygon(8px 0%, 100% 0%, calc(100% - 8px) 100%, 0% 100%);
}
#send-early-btn:hover {
  background: linear-gradient(135deg, #223377, #162255);
  color: #bbccff;
  box-shadow: 0 0 12px rgba(85,136,255,0.4);
}

/* ── Canvas container ────────────────────────────────────────────────────────── */
#canvas-container {
  grid-area: cvs;
  position: relative;
  width: 1152px;
  height: 768px;
  border: 1px solid #1a2a5e;
  border-right: none;
  overflow: hidden;
}

#canvas-bg, #canvas-fg {
  position: absolute;
  top: 0; left: 0;
  display: block;
}

#canvas-fg { cursor: crosshair; }
#map-label {
  position: absolute; top: 10px; left: 12px; z-index: 8; pointer-events: none;
  padding: 5px 10px; border: 1px solid rgba(140,180,255,.55); border-radius: 3px;
  background: rgba(5,12,30,.82); color: #d9e8ff; font-size: 11px;
  letter-spacing: 1px; text-shadow: 0 0 8px currentColor;
}
body.mobile-game #map-label { top: 4px; left: 5px; padding: 2px 5px; font-size: 9px; }

/* ── Sidebar ─────────────────────────────────────────────────────────────────── */
#ui-panel {
  grid-area: sidebar;
  background: linear-gradient(180deg, #08081e 0%, #06060e 100%);
  border: 1px solid #1a2a5e;
  border-left: none;
  padding: 12px 10px;
  overflow-y: auto;
  min-height: 768px;
  user-select: none;
  position: relative;
}

#ui-panel::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, #3355aa, transparent);
}

.panel-anim {
  animation: slideInRight 0.22s ease-out both;
}

.panel-title {
  font-family: 'Orbitron', monospace;
  font-size: 9px;
  letter-spacing: 3px;
  color: #334466;
  margin-bottom: 10px;
  border-bottom: 1px solid #12122e;
  padding-bottom: 5px;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 6px;
}
.panel-title::before {
  content: '';
  display: inline-block;
  width: 3px;
  height: 10px;
  background: #3355aa;
  flex-shrink: 0;
}

.panel-section { margin-bottom: 14px; }

.hint-text {
  font-size: 9px;
  color: #2a3350;
  line-height: 1.6;
  letter-spacing: 0.3px;
}

/* Tower shop buttons */
.tower-btn {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  background: linear-gradient(135deg, #0e0e2e, #0a0a20);
  border: 1px solid #1e2860;
  border-left: 3px solid var(--tower-color, #3344aa);
  color: #ddeeff;
  padding: 8px 10px;
  margin-bottom: 5px;
  cursor: pointer;
  font-family: 'Share Tech Mono', monospace;
  font-size: 11px;
  transition: all 0.15s;
  position: relative;
  overflow: hidden;
}
.tower-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, var(--tower-color, #3344aa), transparent);
  opacity: 0;
  transition: opacity 0.15s;
}
.tower-btn:hover { border-color: var(--tower-color, #5577cc); }
.tower-btn:hover::before { opacity: 0.08; }
.tower-btn.active {
  background: linear-gradient(135deg, #141444, #0e0e30);
  border-color: var(--tower-color, #5599ff);
  box-shadow: 0 0 10px rgba(85,153,255,0.25), inset 0 0 10px rgba(85,153,255,0.05);
}
.tower-btn.active::before { opacity: 0.12; }
.tower-btn.unaffordable  { opacity: 0.35; cursor: not-allowed; }
.tower-btn-name { text-align: left; font-size: 11px; }
.tower-btn-cost { font-weight: bold; font-size: 11px; z-index: 1; }
.tower-btn-key {
  font-size: 9px;
  color: #334466;
  border: 1px solid #223;
  padding: 1px 4px;
  margin-right: 4px;
  border-radius: 2px;
  z-index: 1;
}

/* Tower detail */
.tower-stat {
  font-size: 11px;
  color: #556688;
  margin: 4px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 2px 0;
  border-bottom: 1px solid #0e0e20;
}
.tower-stat b { color: #c8d8ff; font-weight: normal; }

.tower-type-badge {
  display: inline-block;
  font-size: 9px;
  letter-spacing: 1.5px;
  padding: 2px 8px;
  border: 1px solid currentColor;
  margin-bottom: 10px;
  text-transform: uppercase;
  opacity: 0.8;
}

.upgrade-btn, .sell-btn, .cancel-btn {
  display: block;
  width: 100%;
  padding: 8px 10px;
  margin-bottom: 6px;
  font-family: 'Share Tech Mono', monospace;
  font-size: 11px;
  cursor: pointer;
  border: 1px solid;
  letter-spacing: 0.5px;
  transition: all 0.15s;
  position: relative;
  overflow: hidden;
}

.upgrade-btn {
  background: linear-gradient(135deg, #0a1840, #081230);
  border-color: #1e3a8a;
  border-top-color: #2a4aaa;
  color: #88aaff;
  clip-path: polygon(6px 0%, 100% 0%, calc(100% - 6px) 100%, 0% 100%);
}
.upgrade-btn:hover:not([disabled]) {
  background: linear-gradient(135deg, #102060, #0c1840);
  box-shadow: 0 0 12px rgba(85,136,255,0.3);
  color: #aaccff;
}
.upgrade-btn.unaffordable, .upgrade-btn[disabled] { opacity: 0.3; cursor: not-allowed; }

.sell-btn {
  background: linear-gradient(135deg, #1a0808, #120606);
  border-color: #441818;
  border-top-color: #662222;
  color: #ff8888;
  clip-path: polygon(6px 0%, 100% 0%, calc(100% - 6px) 100%, 0% 100%);
}
.sell-btn:hover { background: linear-gradient(135deg, #220e0e, #180a0a); box-shadow: 0 0 10px rgba(255,80,80,0.25); }

.cancel-btn {
  background: transparent;
  border-color: #1e1e30;
  color: #334455;
  font-size: 10px;
}
.cancel-btn:hover { border-color: #2a2a44; color: #556677; }

/* ── Wave banner ────────────────────────────────────────────────────────────── */
.wave-banner {
  position: absolute;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(6, 6, 30, 0.92);
  border: 1px solid #2244aa;
  border-top: 1px solid #4466cc;
  color: #88aaff;
  font-family: 'Orbitron', monospace;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 5px;
  padding: 12px 40px;
  pointer-events: none;
  transition: opacity 0.5s;
  z-index: 10;
  white-space: nowrap;
  clip-path: polygon(16px 0%, 100% 0%, calc(100% - 16px) 100%, 0% 100%);
  text-transform: uppercase;
}
.wave-banner.boss {
  border-color: #aa2200;
  border-top-color: #cc3300;
  color: #ff6633;
  box-shadow: 0 0 30px rgba(255, 80, 0, 0.5);
}

/* ── Overlay ─────────────────────────────────────────────────────────────────── */
#overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,12,0.88);
  z-index: 100;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

/* Animated scanline across overlay */
#overlay::after {
  content: '';
  position: absolute;
  left: 0; right: 0;
  height: 120px;
  background: linear-gradient(180deg,
    transparent 0%,
    rgba(100,160,255,0.04) 40%,
    rgba(100,160,255,0.06) 50%,
    rgba(100,160,255,0.04) 60%,
    transparent 100%);
  animation: scanline 4s linear infinite;
  pointer-events: none;
}

.overlay-box {
  background: linear-gradient(160deg, #0e0e32 0%, #080824 60%, #0a0820 100%);
  border: 1px solid #2a3a7a;
  box-shadow:
    0 0 60px rgba(60,100,255,0.3),
    0 0 120px rgba(40,60,200,0.15),
    inset 0 0 60px rgba(0,0,20,0.5);
  padding: 44px 56px;
  text-align: center;
  max-width: 560px;
  width: 100%;
  position: relative;
  animation: fadeInUp 0.35s cubic-bezier(0.22,1,0.36,1) both;
}

/* Corner decorations */
.overlay-box::before,
.overlay-box::after {
  content: '';
  position: absolute;
  width: 24px;
  height: 24px;
  pointer-events: none;
}
.overlay-box::before {
  top: -1px; left: -1px;
  border-top: 2px solid #6688ff;
  border-left: 2px solid #6688ff;
}
.overlay-box::after {
  bottom: -1px; right: -1px;
  border-bottom: 2px solid #6688ff;
  border-right: 2px solid #6688ff;
}
/* Extra corners via inner span — done in JS with .corner-tr / .corner-bl */
.corner-tr {
  position: absolute; top: -1px; right: -1px;
  width: 24px; height: 24px;
  border-top: 2px solid #6688ff;
  border-right: 2px solid #6688ff;
  pointer-events: none;
}
.corner-bl {
  position: absolute; bottom: -1px; left: -1px;
  width: 24px; height: 24px;
  border-bottom: 2px solid #6688ff;
  border-left: 2px solid #6688ff;
  pointer-events: none;
}

.overlay-box h1 {
  font-family: 'Orbitron', monospace;
  font-size: 20px;
  font-weight: 900;
  letter-spacing: 5px;
  color: #88aaff;
  margin-bottom: 6px;
  animation: glitch 6s ease-in-out infinite;
  text-transform: uppercase;
}
.overlay-box h2 {
  font-family: 'Orbitron', monospace;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 3px;
  color: #c8d8ff;
  margin-bottom: 14px;
}
.overlay-box p {
  color: #778899;
  margin-bottom: 8px;
  font-size: 12px;
  line-height: 1.7;
}
.overlay-box strong { color: #ffd700; }

.overlay-box > button {
  margin-top: 22px;
  background: linear-gradient(135deg, #1e3a8a, #162a6a);
  border: 1px solid #4466cc;
  border-top: 1px solid #6688ff;
  color: #c8d8ff;
  padding: 12px 44px;
  cursor: pointer;
  font-family: 'Orbitron', monospace;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 4px;
  transition: all 0.2s;
  text-transform: uppercase;
  clip-path: polygon(12px 0%, 100% 0%, calc(100% - 12px) 100%, 0% 100%);
}
.overlay-box > button:hover {
  background: linear-gradient(135deg, #2a4aaa, #1e3888);
  box-shadow: 0 0 24px rgba(85,136,255,0.5), 0 0 48px rgba(85,136,255,0.2);
  color: #ffffff;
}

/* Menu subtitle line */
.menu-subtitle {
  font-size: 10px;
  letter-spacing: 3px;
  color: #334466;
  margin-bottom: 28px;
  text-transform: uppercase;
}

/* Separator line */
.menu-sep {
  width: 100%;
  height: 1px;
  background: linear-gradient(90deg, transparent, #2a3a6a, transparent);
  margin: 18px 0;
}

/* Settings button — smaller, secondary style */
.menu-settings-btn {
  background: transparent;
  border: 1px solid #1e2850;
  color: #445577;
  padding: 7px 20px;
  cursor: pointer;
  font-family: 'Share Tech Mono', monospace;
  font-size: 10px;
  letter-spacing: 2px;
  transition: all 0.2s;
  text-transform: uppercase;
  display: inline-block;
  margin-top: 10px;
}
.menu-settings-btn:hover {
  border-color: #3355aa;
  color: #6688bb;
}

/* ── Difficulty selection ────────────────────────────────────────────────────── */
.diff-row {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.diff-btn {
  background: #090922;
  border: 1px solid color-mix(in srgb, var(--diff-color) 30%, #1a1a4a);
  color: color-mix(in srgb, var(--diff-color) 50%, #778899);
  padding: 8px 12px;
  cursor: pointer;
  font-family: 'Orbitron', monospace;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  transition: all 0.15s;
  clip-path: polygon(5px 0%, 100% 0%, calc(100% - 5px) 100%, 0% 100%);
}
.diff-btn:hover {
  background: color-mix(in srgb, var(--diff-color) 12%, #090922);
  border-color: var(--diff-color);
  color: var(--diff-color);
}
.diff-btn.selected {
  background: color-mix(in srgb, var(--diff-color) 18%, #090922);
  border-color: var(--diff-color);
  color: var(--diff-color);
  box-shadow: 0 0 14px color-mix(in srgb, var(--diff-color) 40%, transparent);
}

.diff-info {
  border: 1px solid;
  padding: 12px 16px;
  margin-bottom: 12px;
  text-align: left;
  position: relative;
  animation: fadeIn 0.25s ease both;
}
.diff-info::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  background: inherit;
  opacity: 0.05;
  pointer-events: none;
}
.diff-name   {
  font-family: 'Orbitron', monospace;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 2px;
  margin-bottom: 5px;
}
.diff-desc   { font-size: 11px; color: #889aaa; margin-bottom: 4px; }
.diff-detail { font-size: 10px; color: #556677; }
.diff-special {
  margin-top: 7px;
  font-size: 10px;
  color: #ffaa44;
  letter-spacing: 0.5px;
}

.diff-multipliers {
  display: flex;
  gap: 14px;
  justify-content: center;
  font-size: 10px;
  color: #556677;
  margin-bottom: 10px;
  flex-wrap: wrap;
  letter-spacing: 0.5px;
}

.best-score {
  font-size: 10px;
  color: #445566;
  margin-bottom: 4px;
}
.best-score strong { color: #ffd700; }

/* ── Mid-game difficulty switcher ───────────────────────────────────────────── */
.diff-switcher {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 5px;
}
.diff-switch-btn {
  flex: 1 1 auto;
  background: #080820;
  border: 1px solid color-mix(in srgb, var(--diff-color) 25%, #141430);
  color: color-mix(in srgb, var(--diff-color) 45%, #667788);
  padding: 5px 3px;
  cursor: pointer;
  font-family: 'Orbitron', monospace;
  font-size: 8px;
  letter-spacing: 0.5px;
  font-weight: 700;
  text-transform: uppercase;
  text-align: center;
  transition: all 0.15s;
}
.diff-switch-btn:hover {
  background: color-mix(in srgb, var(--diff-color) 12%, #080820);
  border-color: var(--diff-color);
  color: var(--diff-color);
}
.diff-switch-btn.active {
  background: color-mix(in srgb, var(--diff-color) 18%, #080820);
  border-color: var(--diff-color);
  color: var(--diff-color);
  box-shadow: 0 0 6px color-mix(in srgb, var(--diff-color) 35%, transparent);
}
.diff-switch-note {
  font-size: 8px;
  color: #333444;
  letter-spacing: 0.5px;
  text-align: right;
}

/* ── Settings panel ──────────────────────────────────────────────────────────── */
.settings-box {
  animation: fadeInUp 0.28s ease both;
}
.settings-title {
  font-family: 'Orbitron', monospace;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 4px;
  color: #88aaff;
  margin-bottom: 24px;
  text-transform: uppercase;
}
.settings-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid #0e0e28;
  gap: 12px;
  animation: stagger 0.25s ease both;
}
.settings-row:nth-child(2) { animation-delay: 0.05s; }
.settings-row:nth-child(3) { animation-delay: 0.10s; }
.settings-row:nth-child(4) { animation-delay: 0.15s; }
.settings-label {
  font-size: 11px;
  color: #7788aa;
  letter-spacing: 0.5px;
  text-align: left;
  flex: 1;
}
.settings-sublabel {
  font-size: 9px;
  color: #334455;
  margin-top: 2px;
}
.toggle-btn {
  background: #0a0a22;
  border: 1px solid #1a2a4a;
  color: #334455;
  padding: 5px 14px;
  cursor: pointer;
  font-family: 'Orbitron', monospace;
  font-size: 9px;
  letter-spacing: 1px;
  transition: all 0.15s;
  min-width: 60px;
  text-align: center;
  text-transform: uppercase;
}
.toggle-btn.on {
  border-color: #2255aa;
  color: #5599ff;
  background: #0a1030;
  box-shadow: 0 0 8px rgba(50,120,255,0.3);
}
.toggle-btn:hover { border-color: #2a3a6a; }

.settings-back-btn {
  margin-top: 22px;
  background: transparent;
  border: 1px solid #1e2850;
  color: #445577;
  padding: 9px 28px;
  cursor: pointer;
  font-family: 'Orbitron', monospace;
  font-size: 10px;
  letter-spacing: 2px;
  transition: all 0.2s;
  text-transform: uppercase;
}
.settings-back-btn:hover { border-color: #3355aa; color: #6688bb; }

/* ── Coin animation ──────────────────────────────────────────────────────────── */
.coin-anim {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  color: #ffd700;
  font-family: 'Orbitron', monospace;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-shadow: 0 0 10px rgba(255,200,0,0.95), 0 0 3px rgba(0,0,0,1), 0 1px 0 rgba(0,0,0,0.8);
  will-change: transform, opacity;
  white-space: nowrap;
}
.gold-pop {
  animation: gold-pop 0.38s cubic-bezier(0.36,0.07,0.19,0.97) both;
}

/* ── Hotkey bar ──────────────────────────────────────────────────────────────── */
#hotkeys {
  grid-area: keys;
  font-size: 10px;
  color: #7180a5;
  padding: 5px 8px;
  letter-spacing: 1px;
}

#touch-controls { display: none; }

button { touch-action: manipulation; }

@media (max-width: 900px) {
  body { padding: max(4px, env(safe-area-inset-top)) max(4px, env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom)) max(4px, env(safe-area-inset-left)); }
  #game-wrapper {
    width: 100%; max-width: 100%;
    grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto auto auto auto;
    grid-template-areas: "hud" "cvs" "sidebar" "touch" "keys";
  }
  #hud { min-height: 48px; flex-wrap: wrap; padding: 3px; gap: 2px; }
  .hud-item { padding: 0 6px; gap: 4px; min-height: 30px; border-right: 0; }
  .hud-label { font-size: 9px; letter-spacing: 0; }
  .hud-value { font-size: 12px; }
  #hud-controls { gap: 3px; padding: 0 2px; }
  #hud-controls button { padding: 5px 6px; min-height: 34px; font-size: 11px; }
  #send-early-btn { margin: 0; padding: 5px 7px; font-size: 10px; }
  #canvas-container {
    width: 100%; height: auto; aspect-ratio: 3 / 2; min-width: 0;
    border-right: 1px solid #1a2a5e;
  }
  #canvas-bg, #canvas-fg { width: 100%; height: 100%; max-width: 100%; }
  #overlay { position: fixed; inset: 0; padding: 8px; overflow-y: auto; }
  .overlay-box { width: min(94vw, 520px); max-height: calc(100dvh - 16px); }
  #ui-panel { width: 100%; height: auto; min-height: 150px; max-height: 32vh; overflow-y: auto; }
  #touch-controls { grid-area: touch; display: flex; gap: 6px; overflow-x: auto; padding: 6px 0; }
  #touch-controls button { flex: 1 0 auto; min-height: 42px; padding: 8px 10px; background: #10143a; color: #c8d8ff; border: 1px solid #3355aa; font: 12px 'Microsoft YaHei', sans-serif; }
  #hotkeys { font-size: 10px; line-height: 1.6; padding: 5px 2px; }
  .overlay-box { width: min(94vw, 520px); max-height: 90dvh; overflow-y: auto; padding: 20px 18px; }
  .overlay-box h1 { font-size: clamp(19px, 6vw, 30px); letter-spacing: 2px; }
  .diff-row { flex-wrap: wrap; }
  .diff-btn { flex: 1 1 28%; min-width: 65px; }
  .wide-box { width: 96vw; }
  .enemy-index-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 430px) {
  .hud-item { padding: 0 4px; }
  .hud-label { font-size: 8px; }
  #hud-controls button { font-size: 10px; padding: 4px; }
  #ui-panel { max-height: 28vh; }
}

@media (orientation: landscape) {
  body.mobile-game { overflow: hidden; }
  body.mobile-game #game-wrapper {
    --side-width: clamp(180px, 28vw, 280px);
    width: min(100%, calc((100vh - 48px) * 1.5 + 180px));
    width: min(100%, calc((100dvh - 48px) * 1.5 + var(--side-width)));
    grid-template-columns: minmax(0, 1fr) var(--side-width);
    grid-template-rows: 40px auto;
    grid-template-areas: "hud hud" "cvs sidebar";
  }
  body.mobile-game #hud { flex-wrap: nowrap; overflow-x: auto; min-height: 40px; }
  body.mobile-game .hud-item { flex: 0 0 auto; padding: 0 5px; }
  body.mobile-game #hud-controls { flex: 0 0 auto; }
  body.mobile-game #canvas-container { width: 100%; height: auto; aspect-ratio: 3 / 2; }
  body.mobile-game #ui-panel { width: var(--side-width); min-height: 0; max-height: calc(100vh - 48px); max-height: calc(100dvh - 48px); padding: 6px; }
  body.mobile-game #touch-controls { display: none; }
  body.mobile-game #hotkeys { display: none; }
}

/* Touch devices must be physically rotated before the game can be used. */
#orientation-gate { display: none; }
body.orientation-blocked { overflow: hidden; }
body.orientation-blocked #orientation-gate {
  position: fixed; inset: 0; z-index: 10000;
  display: grid; place-items: center;
  padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right))
           max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  background: radial-gradient(circle at 50% 32%, #192954 0, #0b1430 32%, #050a1a 72%);
  color: #e8efff;
  overflow: hidden;
}
body.orientation-blocked #orientation-gate::before {
  content: ''; position: absolute; inset: 0; opacity: .28; pointer-events: none;
  background-image: linear-gradient(#4b71bc 1px, transparent 1px), linear-gradient(90deg, #4b71bc 1px, transparent 1px);
  background-size: 38px 38px; mask-image: linear-gradient(transparent, #000 25%, #000 75%, transparent);
}
.orientation-card {
  position: relative; z-index: 1;
  width: min(100%, 390px);
  max-height: calc(100dvh - 28px);
  padding: clamp(18px, 5vw, 28px);
  border: 1px solid #456cb7;
  border-radius: 20px;
  background: linear-gradient(155deg, rgba(19,37,82,.96), rgba(8,17,42,.98));
  box-shadow: 0 20px 55px rgba(0,0,0,.45), 0 0 42px rgba(72,116,232,.17), inset 0 1px rgba(180,210,255,.16);
  text-align: left;
  overflow: hidden;
}
.orientation-card::before {
  content: ''; position: absolute; top: 0; left: 28px; right: 28px; height: 2px;
  background: linear-gradient(90deg, transparent, #84adff, transparent);
}
.orientation-eyebrow { color: #93b5ff; font-size: 11px; letter-spacing: 2px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.orientation-status { width: 7px; height: 7px; border-radius: 50%; background: #50edc6; box-shadow: 0 0 10px #50edc6; flex: none; }
.orientation-card h1 { font-size: clamp(25px, 7vw, 32px); color: #f0f5ff; letter-spacing: 1px; line-height: 1.2; margin: 16px 0 9px; }
.orientation-card .orientation-lead { color: #a8b9dc; font-size: 14px; line-height: 1.45; }
.orientation-preview { margin: 22px 0 16px; padding: 17px 16px 12px; border: 1px solid #2c488a; border-radius: 14px; background: radial-gradient(circle at 50% 50%, #1b3470, #0b1839 75%); }
.preview-device { position: relative; width: min(100%, 248px); height: 111px; margin: 0 auto; border: 4px solid #8aafff; border-radius: 14px; background: repeating-linear-gradient(0deg, #0c1a42 0 16px, #14234c 16px 17px); box-shadow: 0 0 22px rgba(96,145,255,.35), inset 0 0 18px rgba(0,0,0,.5); overflow: hidden; }
.preview-device::before { content: ''; position: absolute; left: 8px; top: 50%; width: 4px; height: 18px; margin-top: -9px; border-radius: 4px; background: #a7c3ff; }
.preview-road { position: absolute; left: 24px; right: 29px; top: 53px; height: 5px; border-radius: 5px; background: #4b77e8; box-shadow: 0 0 12px #4b77e8; }
.preview-road::after { content: ''; position: absolute; right: 0; bottom: -25px; width: 5px; height: 30px; border-radius: 5px; background: #4b77e8; box-shadow: 0 0 12px #4b77e8; }
.preview-tower { position: absolute; width: 18px; height: 18px; border: 2px solid #5ce4ee; border-radius: 4px; background: #113a62; box-shadow: 0 0 12px #35dce8; transform: rotate(45deg); }
.tower-one { top: 23px; left: 60px; }
.tower-two { bottom: 14px; left: 128px; }
.preview-enemy { position: absolute; left: 112px; top: 49px; width: 12px; height: 12px; border-radius: 50%; background: #78ff8e; box-shadow: 0 0 11px #78ff8e; }
.preview-panel { position: absolute; right: 9px; top: 11px; width: 21px; height: 34px; border: 1px solid #425d9a; background: repeating-linear-gradient(#6689df 0 3px, transparent 3px 9px); }
.preview-caption { text-align: center; color: #7f9cce; font-size: 11px; letter-spacing: 2px; margin-top: 11px; }
.orientation-instruction { display: flex; justify-content: space-between; align-items: center; color: #d4e2ff; font-size: 14px; margin: 0 0 17px; }
.orientation-instruction span { color: #75a8ff; font-weight: 700; font-size: 17px; }
#request-landscape { width: 100%; min-height: 48px; padding: 10px 18px; border: 1px solid #88aeff; border-radius: 10px; background: linear-gradient(135deg, #3867d6, #254dab); box-shadow: 0 8px 23px rgba(38,86,191,.35), inset 0 1px rgba(255,255,255,.25); color: #fff; font: 700 16px 'Microsoft YaHei', sans-serif; cursor: pointer; display: flex; justify-content: center; align-items: center; gap: 12px; touch-action: manipulation; }
#request-landscape span { font-size: 21px; line-height: 1; }
.orientation-card .orientation-note { color: #8195bb; font-size: 11px; text-align: center; line-height: 1.4; margin: 11px 0 0; }
@media (max-height: 650px) and (orientation: portrait) {
  .orientation-preview { margin: 12px 0; padding: 10px; }
  .preview-device { height: 84px; }
  .preview-road { top: 40px; }
  .preview-enemy { top: 36px; }
  .orientation-card h1 { margin-top: 10px; }
}

/* Fallback for in-app browsers that reject Screen Orientation API. */
body.force-landscape { overflow: hidden; padding: 0; }
body.force-landscape #game-wrapper {
  --side-width: clamp(180px, 28vh, 280px);
  --side-width: clamp(180px, 28dvh, 280px);
  --landscape-width: min(100vh, calc((100vw - 48px) * 1.5 + 180px));
  --landscape-width: min(100dvh, calc((100vw - 48px) * 1.5 + var(--side-width)));
  position: fixed;
  top: calc((100dvh - var(--landscape-width)) / 2);
  left: 100vw;
  width: var(--landscape-width);
  max-width: none;
  height: 100vw;
  transform-origin: top left;
  transform: rotate(90deg);
  grid-template-columns: minmax(0, 1fr) var(--side-width);
  grid-template-rows: 40px auto;
  grid-template-areas: "hud hud" "cvs sidebar";
}
body.force-landscape #hud { min-height: 40px; flex-wrap: nowrap; overflow-x: auto; }
body.force-landscape .hud-item { flex: 0 0 auto; padding: 0 5px; }
body.force-landscape #hud-controls { flex: 0 0 auto; }
body.force-landscape #canvas-container { width: 100%; height: auto; aspect-ratio: 3 / 2; }
body.force-landscape #ui-panel { width: var(--side-width); min-height: 0; max-height: calc(100vw - 48px); padding: 6px; }
body.force-landscape #touch-controls, body.force-landscape #hotkeys { display: none; }
body.force-landscape #overlay { position: fixed; inset: 0; max-height: 100%; }
body.force-landscape .overlay-box { max-height: calc(100vw - 16px); }

/* Keep the complete menu and every battle control on one landscape screen. */
body.mobile-game { --play-height: 100vh; --play-height: 100dvh; }
body.force-landscape { --play-height: 100vw; }
body.mobile-game #overlay { padding: 4px; overflow: hidden; }
body.mobile-game #overlay::after { display: none; }
body.mobile-game .main-menu {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: 25px 34px repeat(4, auto);
  gap: 4px 10px;
  align-content: center;
  align-items: center;
  width: min(96%, 900px);
  max-width: none;
  max-height: calc(var(--play-height) - 8px);
  padding: 8px 12px;
  overflow: hidden;
  animation: none;
  box-shadow: 0 0 22px rgba(60,100,255,.2);
}
body.mobile-game .main-menu h1 { grid-column: 1 / -1; margin: 0; font-size: 20px; letter-spacing: 3px; animation: none; }
body.mobile-game .main-menu .menu-subtitle,
body.mobile-game .main-menu .menu-sep,
body.mobile-game .main-menu .best-score { display: none; }
body.mobile-game .main-menu .diff-row { grid-column: 1 / -1; margin: 0; flex-wrap: nowrap; gap: 4px; }
body.mobile-game .main-menu .diff-btn { flex: 1 1 0; min-width: 0; padding: 7px 2px; font-size: 10px; letter-spacing: 0; }
body.mobile-game .main-menu .diff-info { grid-column: 1; grid-row: 3 / 7; align-self: stretch; margin: 0; padding: 8px; animation: none; display: flex; flex-direction: column; justify-content: center; }
body.mobile-game .main-menu .diff-name { margin-bottom: 4px; }
body.mobile-game .main-menu .diff-desc { font-size: 10px; line-height: 1.3; margin-bottom: 3px; }
body.mobile-game .main-menu .diff-detail,
body.mobile-game .main-menu .diff-special { font-size: 9px; line-height: 1.25; }
body.mobile-game .main-menu .diff-multipliers { grid-column: 2; grid-row: 3; display: grid; grid-template-columns: 1fr 1fr; gap: 2px 5px; margin: 0; font-size: 9px; }
body.mobile-game .main-menu > button:not(.menu-settings-btn) { grid-column: 2; grid-row: 4; width: 100%; min-height: 36px; margin: 0; padding: 7px 4px; font-size: 12px; letter-spacing: 1px; }
body.mobile-game .main-menu .menu-secondary-row { grid-column: 2; grid-row: 5; display: flex; gap: 4px; margin: 0; }
body.mobile-game .main-menu .menu-secondary-btn { flex: 1; justify-content: center; min-width: 0; padding: 5px 3px; font-size: 9px; white-space: nowrap; }
body.mobile-game .main-menu > .menu-settings-btn { grid-column: 2; grid-row: 6; width: 100%; min-height: 26px; margin: 0; padding: 3px; font-size: 10px; }
body.mobile-game #ui-panel { display: flex; flex-direction: column; overflow: hidden; }
body.mobile-game #ui-panel .panel-tabs { flex: 0 0 auto; margin-bottom: 3px; }
body.mobile-game #ui-panel .panel-tab { padding: 4px 2px; font-size: 9px; }
body.mobile-game #ui-panel .panel-section { margin-bottom: 2px; }
body.mobile-game #ui-panel .tower-btn { min-height: 24px; margin-bottom: 2px; padding: 2px 4px; font-size: 9px; }
body.mobile-game #ui-panel .tower-btn-name,
body.mobile-game #ui-panel .tower-btn-cost { font-size: 9px; }
body.mobile-game #ui-panel .hint-text,
body.mobile-game #ui-panel .diff-switch-note { display: none; }
body.mobile-game #ui-panel .panel-title { margin-bottom: 2px; font-size: 9px; }
body.mobile-game #ui-panel .diff-switcher { gap: 2px; margin-bottom: 0; }
body.mobile-game #ui-panel .diff-switch-btn { padding: 3px 1px; font-size: 8px; }
body.mobile-game #hud { overflow: hidden; }
body.mobile-game #hud-controls { gap: 3px; padding: 0 3px; }
body.mobile-game #hud-controls button { min-height: 28px; padding: 3px 5px; font-size: 10px; }
body.mobile-game #fullscreen-btn { display: none; }
@media (orientation: landscape) and (min-width: 750px) {
  body.mobile-game #ui-panel .shop-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 3px; }
  body.mobile-game #ui-panel .shop-list .tower-btn { min-height: 32px; margin: 0; }
}
body.force-landscape #ui-panel .shop-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 3px; }
body.force-landscape #ui-panel .shop-list .tower-btn { min-height: 32px; margin: 0; }

@media (max-width: 900px) and (max-height: 740px) {
  .overlay-box { padding: 14px 18px; }
  .overlay-box h1 { margin-bottom: 2px; }
  .menu-subtitle { margin-bottom: 10px; }
  .diff-info { padding: 10px 12px; }
  .menu-sep { margin: 12px 0; }
  .overlay-box > button { margin-top: 10px; }
  .menu-secondary-row { margin-top: 8px; }
}

/* ── Panel tabs (TOWERS / DEPLOY) ────────────────────────────────────────────── */
.panel-tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 10px;
}
.panel-tab {
  flex: 1;
  background: transparent;
  border: 1px solid #1a2240;
  border-bottom: 1px solid #2a3a6a;
  color: #2a3a55;
  padding: 5px 0;
  cursor: pointer;
  font-family: 'Orbitron', monospace;
  font-size: 7.5px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  transition: all 0.15s;
}
.panel-tab:hover { border-color: #2a3a6a; color: #4a6688; }
.panel-tab.active {
  background: #080820;
  border-color: #3355aa;
  border-bottom-color: #080820;
  color: #88aaff;
  box-shadow: 0 0 6px rgba(50,100,255,0.15);
}

/* ── Deployable HP bar ───────────────────────────────────────────────────────── */
.dep-hp-bar {
  height: 4px;
  background: #0a0a20;
  border: 1px solid #1a1a3a;
  margin: 4px 0 8px;
  border-radius: 2px;
  overflow: hidden;
}
.dep-hp-fill {
  height: 100%;
  transition: width 0.3s;
  border-radius: 2px;
}

/* ── Menu secondary buttons row ──────────────────────────────────────────────── */
.menu-secondary-row {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 12px;
  margin-bottom: 4px;
}
.menu-secondary-btn {
  background: transparent;
  border: 1px solid #1e2a50;
  color: #445577;
  padding: 7px 16px;
  cursor: pointer;
  font-family: 'Share Tech Mono', monospace;
  font-size: 10px;
  letter-spacing: 1px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}
.menu-secondary-btn:hover {
  border-color: #3355aa;
  color: #6688bb;
  background: rgba(50,80,160,0.08);
}

/* Credits badge (inline in button) */
.credits-badge {
  display: inline-block;
  background: rgba(80,120,255,0.15);
  border: 1px solid #2a3a7a;
  color: #88aaff;
  font-size: 9px;
  padding: 1px 6px;
  letter-spacing: 0.5px;
  border-radius: 2px;
}

/* Credits badge large (in armory title) */
.credits-badge-big {
  display: inline-block;
  background: rgba(80,120,255,0.15);
  border: 1px solid #3355aa;
  color: #88aaff;
  font-family: 'Share Tech Mono', monospace;
  font-size: 13px;
  font-weight: normal;
  padding: 2px 12px;
  margin-left: 12px;
  letter-spacing: 1px;
  vertical-align: middle;
}

/* ── Wide overlay box ────────────────────────────────────────────────────────── */
.wide-box {
  max-width: 860px;
  width: 95vw;
  padding: 36px 44px;
  max-height: 88vh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #2a3a6a transparent;
}
.wide-box::-webkit-scrollbar { width: 4px; }
.wide-box::-webkit-scrollbar-track { background: transparent; }
.wide-box::-webkit-scrollbar-thumb { background: #2a3a6a; border-radius: 2px; }

/* ── Enemy Index ─────────────────────────────────────────────────────────────── */
.enemy-index-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
  margin-bottom: 24px;
  text-align: left;
}

.enemy-card {
  background: linear-gradient(160deg, #0a0a22, #080818);
  border: 1px solid #1a2a4a;
  padding: 14px 12px;
  position: relative;
  transition: border-color 0.15s;
  animation: fadeInUp 0.3s ease both;
}
.enemy-card:hover { border-color: #2a3a6a; }

.enemy-card-icon {
  display: block;
  margin: 0 auto 10px;
  border-radius: 50%;
}

.enemy-card-name {
  font-family: 'Orbitron', monospace;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  margin-bottom: 6px;
  text-align: center;
}

.enemy-boss-tag {
  text-align: center;
  font-family: 'Orbitron', monospace;
  font-size: 7px;
  letter-spacing: 2px;
  color: #ff6633;
  border: 1px solid #ff6633;
  padding: 1px 6px;
  display: inline-block;
  margin: 0 auto 8px;
  width: 100%;
  box-sizing: border-box;
}

.enemy-stat-row {
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  color: #445566;
  margin: 2px 0;
  padding: 1px 0;
  border-bottom: 1px solid #0e0e22;
}
.enemy-stat-row span { color: #334455; }
.enemy-stat-row b { color: #889aaa; font-weight: normal; }

.enemy-special-tag {
  margin-top: 7px;
  font-size: 8px;
  color: #ffaa44;
  letter-spacing: 0.3px;
  line-height: 1.5;
  min-height: 12px;
}

.enemy-lore-text {
  margin-top: 5px;
  font-size: 8px;
  color: #334455;
  line-height: 1.6;
  font-style: italic;
}

/* ── Armory ──────────────────────────────────────────────────────────────────── */
.armory-section {
  border: 1px solid #1a2240;
  padding: 16px;
  margin-bottom: 16px;
  text-align: left;
  background: rgba(8,8,24,0.6);
}

.armory-section-title {
  font-family: 'Orbitron', monospace;
  font-size: 9px;
  letter-spacing: 3px;
  color: #334466;
  text-transform: uppercase;
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid #12122e;
}

.armory-hint {
  font-size: 9px;
  color: #2a3a55;
  margin-bottom: 12px;
  letter-spacing: 0.3px;
  line-height: 1.6;
}

.armory-tower-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 12px;
}

.armory-tower-tab {
  background: #06060e;
  border: 1px solid color-mix(in srgb, var(--tc) 20%, #1a1a3a);
  color: color-mix(in srgb, var(--tc) 40%, #556677);
  padding: 4px 10px;
  cursor: pointer;
  font-family: 'Orbitron', monospace;
  font-size: 8px;
  letter-spacing: 0.5px;
  font-weight: 700;
  text-transform: uppercase;
  transition: all 0.15s;
}
.armory-tower-tab:hover {
  border-color: var(--tc);
  color: var(--tc);
  background: color-mix(in srgb, var(--tc) 8%, #06060e);
}
.armory-tower-tab.active {
  border-color: var(--tc);
  color: var(--tc);
  background: color-mix(in srgb, var(--tc) 14%, #06060e);
  box-shadow: 0 0 8px color-mix(in srgb, var(--tc) 30%, transparent);
}

/* ── Skin grid ───────────────────────────────────────────────────────────────── */
.skin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
}

.skin-btn {
  background: #06060e;
  border: 1px solid #1a2240;
  padding: 10px 8px 8px;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.skin-btn:hover:not([disabled]) {
  border-color: var(--skin-color, #3355aa);
  background: color-mix(in srgb, var(--skin-color, #3355aa) 8%, #06060e);
}
.skin-btn.active {
  border-color: var(--skin-color, #3355aa);
  background: color-mix(in srgb, var(--skin-color, #3355aa) 12%, #06060e);
  box-shadow: 0 0 12px color-mix(in srgb, var(--skin-color, #3355aa) 35%, transparent);
}
.skin-btn.locked { opacity: 0.35; cursor: not-allowed; }

.skin-swatch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
}
.skin-name {
  font-family: 'Orbitron', monospace;
  font-size: 8px;
  letter-spacing: 0.5px;
  color: #889aaa;
  text-transform: uppercase;
}
.skin-rarity {
  font-size: 7.5px;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.skin-active-tag {
  font-size: 7px;
  letter-spacing: 1px;
  color: #00ff88;
  border: 1px solid #00ff8840;
  padding: 1px 4px;
  margin-top: 2px;
}
.skin-lock {
  font-size: 14px;
  margin-top: 2px;
}

/* ── Crate items ─────────────────────────────────────────────────────────────── */
.crate-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid #0e0e22;
}
.crate-item:last-child { border-bottom: none; }

.crate-icon {
  font-size: 28px;
  flex-shrink: 0;
  width: 36px;
  text-align: center;
}

.crate-info { flex: 1; text-align: left; }
.crate-name {
  font-family: 'Orbitron', monospace;
  font-size: 10px;
  letter-spacing: 1px;
  color: #889aaa;
  margin-bottom: 3px;
}
.crate-desc { font-size: 9px; color: #334455; }

.crate-buy-btn {
  background: linear-gradient(135deg, #0a1030, #080820);
  border: 1px solid #2244aa;
  border-top-color: #3355cc;
  color: #88aaff;
  padding: 7px 12px;
  cursor: pointer;
  font-family: 'Share Tech Mono', monospace;
  font-size: 10px;
  text-align: center;
  transition: all 0.15s;
  flex-shrink: 0;
  min-width: 70px;
  line-height: 1.4;
}
.crate-buy-btn:hover:not([disabled]) {
  background: linear-gradient(135deg, #102060, #0c1840);
  box-shadow: 0 0 10px rgba(85,136,255,0.3);
}
.crate-buy-btn.unaffordable { opacity: 0.3; cursor: not-allowed; }

/* ── Crate reveal ────────────────────────────────────────────────────────────── */
@keyframes crate-reveal {
  0%   { opacity: 0; transform: scale(0.5) rotate(-8deg); }
  60%  { opacity: 1; transform: scale(1.08) rotate(2deg); }
  80%  { transform: scale(0.96) rotate(-1deg); }
  100% { opacity: 1; transform: scale(1) rotate(0deg); }
}

.crate-reveal-row {
  display: flex;
  gap: 24px;
  justify-content: center;
  margin-bottom: 28px;
  flex-wrap: wrap;
}

.crate-reveal-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 24px 28px;
  background: linear-gradient(160deg, #0a0a22, #06061a);
  border: 2px solid var(--rarity-color, #3355aa);
  box-shadow: 0 0 30px color-mix(in srgb, var(--rarity-color, #3355aa) 30%, transparent);
  animation: crate-reveal 0.55s cubic-bezier(0.22,1,0.36,1) both;
}

.crate-reveal-swatch {
  width: 64px;
  height: 64px;
  border-radius: 50%;
}

.crate-reveal-name {
  font-family: 'Orbitron', monospace;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 2px;
  color: #c8d8ff;
  text-transform: uppercase;
}

.crate-reveal-rarity {
  font-size: 9px;
  letter-spacing: 2px;
  text-transform: uppercase;
}
