:root {
  --bg-primary: #000000; /* pure black = transparent on additive display */
  --bg-secondary: #0a0a0f;
  --bg-tertiary: #14141f;
  --bg-card: #1a1a2e;
  --text-primary: #ffffff;
  --text-secondary: #a0a0b0;
  --accent-primary: #00d4ff;
  --accent-secondary: #00ff88;
  --danger: #ff4466;
  --focus-ring: #00d4ff;
  --focus-glow: rgba(0, 212, 255, 0.4);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  width: 600px;
  height: 600px;
  overflow: hidden;
}

#app {
  width: 100%;
  height: 100%;
  position: relative;
}

/* --- Screens --- */
.screen {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: absolute;
  top: 0;
  left: 0;
  padding: 8px; /* safe margin */
}
.screen.hidden { display: none; }

/* --- Header --- */
.header {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  gap: 12px;
  flex-shrink: 0;
}
.header h1 { font-size: 22px; font-weight: 600; flex: 1; }
.header-meta { font-size: 14px; color: var(--text-secondary); }

/* --- Home --- */
.home-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 20px;
  padding: 16px 20px;
}
.hero { text-align: center; }
.hero-title {
  font-size: 56px;
  font-weight: 800;
  letter-spacing: 14px;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero-sub {
  font-size: 16px;
  color: var(--text-secondary);
  margin-top: 6px;
}
.card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 16px 20px;
}
.howto { display: flex; flex-direction: column; gap: 10px; }
.howto-row {
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.howto-key {
  min-width: 76px;
  text-align: center;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  color: var(--accent-primary);
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
}

/* --- Focus States (critical for EMG/D-pad) --- */
.focusable {
  transition: all 0.15s ease;
  border: 2px solid transparent;
  cursor: pointer;
  min-height: 44px;
}
.focusable:focus {
  outline: none;
  border-color: var(--focus-ring);
  box-shadow: 0 0 20px var(--focus-glow);
}

/* --- Navigation Bar --- */
.nav-bar {
  display: flex;
  gap: 8px;
  padding: 12px 0 4px;
  flex-shrink: 0;
}
.nav-item {
  flex: 1;
  padding: 16px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 17px;
  font-weight: 600;
  text-align: center;
}
.nav-item:focus { background: var(--bg-card); }
.nav-item.primary { background: var(--accent-primary); color: #0a0a0f; }
.nav-item.primary:focus { background: #33ddff; }

/* --- Game HUD --- */
.game-hud {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  flex-shrink: 0;
  margin-bottom: 8px;
}
.hud-item {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  flex-shrink: 0;
}
#hud-lives { color: var(--danger); letter-spacing: 2px; }
#hud-lives.flash { animation: hudflash 0.6s ease; }
@keyframes hudflash {
  0%, 100% { transform: scale(1); }
  30% { transform: scale(1.5); }
}
.hud-progress {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
}
.hud-pct {
  font-size: 15px;
  font-weight: 600;
  color: var(--accent-primary);
  min-width: 42px;
  text-align: right;
}
.progress-bar {
  flex: 1;
  height: 8px;
  background: var(--bg-tertiary);
  border-radius: 4px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
  border-radius: 4px;
  transition: width 0.3s ease;
}

/* --- Game Canvas --- */
.canvas-wrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
#game-canvas {
  border-radius: var(--radius-sm);
  background: #050508;
}

/* --- Overlay (level clear / game over) --- */
.game-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(5, 5, 10, 0.82);
  border-radius: var(--radius-sm);
}
.game-overlay.hidden { display: none; }
.overlay-title {
  font-size: 34px;
  font-weight: 800;
  color: var(--accent-secondary);
}
.overlay-sub {
  font-size: 16px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.game-overlay .nav-item {
  flex: none;
  min-width: 260px;
}

/* --- Utility --- */
.hidden { display: none !important; }
