:root {
  --bg-primary: #1C1E21;
  --bg-secondary: #16181b;
  --bg-tertiary: #24272b;
  --bg-card: #2a2d31;
  --text-primary: #FFFFFF;
  --text-secondary: #E4E6EB;
  --text-muted: #B0B3B8;
  --accent-primary: #00d4ff;
  --accent-gold: #ffcb3d;
  --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;
}
.screen.hidden { display: none; }

/* --- Header --- */
.header {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  background: var(--bg-secondary);
  gap: 12px;
  flex-shrink: 0;
}
.header h1 {
  font-size: 22px;
  font-weight: 600;
  flex: 1;
}
.header-meta {
  font-size: 16px;
  font-weight: 600;
  color: var(--accent-primary);
  font-variant-numeric: tabular-nums;
}
.back-btn {
  background: transparent;
  color: var(--text-primary);
  font-size: 22px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
}

/* --- Content Area --- */
.content {
  flex: 1;
  padding: 16px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* --- 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 / buttons --- */
.nav-item {
  padding: 14px 16px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 500;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.nav-item:focus { background: var(--bg-card); }
.nav-item.primary {
  background: var(--accent-primary);
  color: var(--bg-primary);
}
.nav-item.primary:focus { background: #33ddff; }
.nav-item.danger {
  background: var(--danger);
  color: white;
}

/* --- Menu --- */
.menu-content {
  align-items: center;
  justify-content: center;
  gap: 22px;
}
.menu-tagline {
  font-size: 16px;
  color: var(--text-secondary);
  text-align: center;
  max-width: 380px;
  line-height: 1.4;
}
.menu-nav {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 280px;
}

/* --- Game Canvas --- */
.game-content {
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 8px 20px;
}
#game-canvas {
  /* near-black floor: reads transparent on the additive display so the maze floats */
  background: #050607;
  border-radius: var(--radius-md);
  border: 2px solid var(--bg-tertiary);
}
.game-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 560px;
  gap: 12px;
}
.hud-best {
  font-size: 14px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.hud-mode {
  background: rgba(255, 203, 61, 0.18);
  color: var(--accent-gold);
}

/* --- Overlays --- */
.overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(20, 21, 24, 0.93);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.overlay.hidden { display: none; }
.overlay-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 36px;
}
.overlay-title {
  font-size: 36px;
  font-weight: 700;
  color: var(--accent-gold);
  text-transform: uppercase;
  letter-spacing: 4px;
}
.pause-title {
  color: var(--accent-primary);
  margin-bottom: 8px;
}
.overlay-time {
  font-size: 60px;
  font-weight: 800;
  color: var(--accent-primary);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.overlay-label {
  font-size: 16px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.overlay-best {
  font-size: 15px;
  color: var(--accent-gold);
  margin-bottom: 14px;
  min-height: 18px;
}
.overlay-btn { width: 240px; }

/* --- Level list --- */
.list-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  max-height: 460px;
}
.list-item {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 15px;
  text-align: left;
  gap: 12px;
  width: 100%;
}
.list-item:focus { background: var(--bg-card); }
.list-item-rank {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent-primary);
  width: 36px;
  text-align: center;
  flex-shrink: 0;
}
.list-item-content { flex: 1; min-width: 0; }
.list-item-title { font-weight: 600; }
.list-item-meta {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}
.list-item-badge {
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 15px;
  font-weight: 700;
  background: rgba(255, 203, 61, 0.15);
  color: var(--accent-gold);
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}
.list-item-badge.none {
  background: var(--bg-card);
  color: var(--text-muted);
}

/* --- Help cards --- */
.help-content { gap: 10px; }
.help-card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 14px 16px;
}
.help-card-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--accent-primary);
  margin-bottom: 4px;
}
.help-card-body {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.4;
}
.help-card-body b { color: var(--text-primary); }

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