:root {
  --bg: #0a0512;
  --bg2: #12081e;
  --panel: rgba(16, 8, 28, 0.88);
  --panel-strong: rgba(10, 5, 20, 0.94);
  --accent: #c473ff;
  --accent2: #ff6b4a;
  --amber: #ffb347;
  --red: #ff2d55;
  --green: #4affb4;
  --text: #f0e6ff;
  --muted: #9880b4;
  --danger: #ff2d55;
  --warning: #ffb347;
  --line: rgba(196, 115, 255, 0.2);
  --shadow-glow: 0 0 24px rgba(196, 115, 255, 0.35);
  --shadow-danger: 0 0 24px rgba(255, 45, 85, 0.35);
  --shadow-amber: 0 0 24px rgba(255, 179, 71, 0.3);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  width: 100%; height: 100%; margin: 0; padding: 0;
  overflow: hidden; background: var(--bg); color: var(--text);
  touch-action: none; user-select: none; -webkit-user-select: none;
}

.game-shell {
  position: relative; width: 100vw; height: 100dvh; overflow: hidden;
  background: radial-gradient(ellipse at 30% 20%, rgba(100, 40, 160, 0.15), transparent 60%),
              radial-gradient(ellipse at 80% 80%, rgba(255, 45, 85, 0.08), transparent 50%),
              linear-gradient(180deg, #0a0512 0%, #0d041a 100%);
}

.game-bar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 6px max(10px, env(safe-area-inset-left)) 6px max(10px, env(safe-area-inset-right));
  background: rgba(10, 5, 18, 0.85); backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(196, 115, 255, 0.12); height: 42px;
}

.back-link {
  display: flex; align-items: center; gap: 4px;
  color: var(--muted); text-decoration: none; font-size: 0.8rem;
  transition: color 150ms; white-space: nowrap;
}
.back-link:hover { color: var(--accent); }

.game-bar-title {
  font-weight: 700; font-size: 0.9rem; letter-spacing: 0.04em;
  color: var(--accent); flex: 1; text-align: center; white-space: nowrap;
  text-shadow: 0 0 12px rgba(196, 115, 255, 0.3);
}

.player-pill {
  font-size: 0.75rem; color: var(--amber); white-space: nowrap;
  background: rgba(255, 179, 71, 0.08); border: 1px solid rgba(255, 179, 71, 0.15);
  border-radius: 6px; padding: 2px 10px; line-height: 24px;
}

.icon-btn {
  width: 32px; height: 32px; border: 1px solid var(--line);
  border-radius: 6px; background: rgba(10, 5, 18, 0.8);
  color: var(--muted); cursor: pointer; font-size: 0.9rem;
  display: grid; place-items: center; transition: all 150ms;
  flex-shrink: 0;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); box-shadow: var(--shadow-glow); }
.icon-btn:active { transform: scale(0.93); }

.game-wrap {
  position: absolute; inset: 0; margin-top: 42px;
  overflow: hidden;
}

#game-canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  display: block; z-index: 1;
}

.screen {
  position: absolute; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  padding: 60px 16px 16px;
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity 300ms ease, visibility 300ms ease;
}
.screen-active { opacity: 1; visibility: visible; pointer-events: auto; }

.panel {
  width: min(92vw, 600px); max-height: 85vh; overflow-y: auto;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel); backdrop-filter: blur(16px);
  box-shadow: 0 0 40px rgba(196, 115, 255, 0.08);
  padding: 28px 24px; text-align: center;
}
.panel-sm { width: min(92vw, 400px); }
.panel-readable { width: min(92vw, 640px); text-align: left; }

.eyebrow {
  color: var(--accent); font-size: 0.7rem; letter-spacing: 0.15em;
  text-transform: uppercase; margin-bottom: 6px;
}

h1 {
  font-size: clamp(2rem, 8vw, 4.5rem); line-height: 0.95; margin: 0;
  text-shadow: 0 0 30px rgba(196, 115, 255, 0.4), 0 0 60px rgba(255, 45, 85, 0.15);
  letter-spacing: -0.02em;
}
h2 { font-size: clamp(1.4rem, 5vw, 2.2rem); margin: 0; }
h3 { font-size: 1rem; margin: 16px 0 8px; color: var(--muted); }
p { margin: 0; line-height: 1.5; color: var(--muted); }

.subtitle { color: var(--muted); margin: 10px 0 0; font-size: 0.9rem; }

.logo-orb {
  width: 72px; height: 72px; margin: 0 auto 16px;
  border: 2px solid var(--accent); border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(196,115,255,0.3), transparent 60%);
  box-shadow: var(--shadow-glow); animation: orbPulse 2.5s ease-in-out infinite;
}
@keyframes orbPulse {
  0%, 100% { transform: scale(0.95); opacity: 0.7; box-shadow: 0 0 20px rgba(196,115,255,0.2); }
  50% { transform: scale(1.05); opacity: 1; box-shadow: 0 0 40px rgba(196,115,255,0.5); }
}

.stat-strip {
  display: flex; justify-content: center; gap: 16px; flex-wrap: wrap;
  margin: 14px 0; font-size: 0.82rem; color: var(--muted);
}
.stat-strip b { color: var(--amber); }

.menu-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.menu-actions.compact { gap: 6px; }
.menu-actions.row { flex-direction: row; flex-wrap: wrap; justify-content: center; }

button.primary, button.secondary {
  min-height: 44px; border-radius: 8px; cursor: pointer;
  transition: all 150ms; font-weight: 700; font-size: 0.95rem;
  letter-spacing: 0.04em; padding: 0 20px;
}
button.primary {
  border: 1px solid rgba(196, 115, 255, 0.6);
  background: linear-gradient(135deg, rgba(196,115,255,0.2), rgba(255,107,74,0.1));
  color: var(--text); box-shadow: var(--shadow-glow);
}
button.primary:hover { border-color: var(--accent); box-shadow: 0 0 30px rgba(196,115,255,0.4); }
button.primary:active { transform: scale(0.97); }

button.secondary {
  border: 1px solid var(--line); background: rgba(10, 5, 18, 0.7);
  color: var(--muted);
}
button.secondary:hover { border-color: var(--accent); color: var(--text); }
button.secondary:active { transform: scale(0.97); }

.how-grid {
  display: grid; gap: 10px; margin: 16px 0;
}
.how-grid div {
  border: 1px solid var(--line); border-radius: 8px;
  padding: 12px 14px; background: rgba(10,5,18,0.5);
}
.how-grid b {
  display: block; color: var(--accent); margin-bottom: 4px; font-size: 0.9rem;
}
.how-grid span {
  color: var(--muted); font-size: 0.82rem; line-height: 1.4;
}

.hud {
  position: absolute; top: 8px; left: 8px; right: 8px; z-index: 8;
  display: flex; flex-wrap: wrap; gap: 6px; align-items: flex-start;
  pointer-events: none; opacity: 0; transition: opacity 200ms;
}
.hud-visible { opacity: 1; }
.hud > * { pointer-events: auto; }

.hud-chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border: 1px solid var(--line);
  border-radius: 6px; background: rgba(10,5,18,0.78);
  backdrop-filter: blur(8px); font-size: 0.7rem;
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted); white-space: nowrap;
}
.hud-chip b { color: var(--text); font-size: 0.85rem; min-width: 20px; text-align: right; }
.hud-chip .chip-accent { color: var(--accent); }
.hud-chip .chip-amber { color: var(--amber); }
.hud-chip .chip-danger { color: var(--danger); }
.hud-chip .chip-green { color: var(--green); }

.hud-btn {
  width: 34px; height: 34px; border: 1px solid var(--line);
  border-radius: 6px; background: rgba(10,5,18,0.8);
  color: var(--muted); cursor: pointer; font-size: 0.85rem;
  display: grid; place-items: center; pointer-events: auto;
  transition: all 150ms;
}
.hud-btn:hover { border-color: var(--accent); color: var(--accent); }

.battery-bar {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; border: 1px solid var(--line);
  border-radius: 6px; background: rgba(10,5,18,0.78);
  backdrop-filter: blur(8px); font-size: 0.7rem; color: var(--muted);
}
.battery-track {
  width: 48px; height: 8px; background: rgba(255,255,255,0.08);
  border-radius: 4px; overflow: hidden; position: relative;
}
.battery-fill {
  height: 100%; border-radius: 4px; transition: width 120ms, background 200ms;
}
.battery-fill.high { background: var(--green); }
.battery-fill.mid { background: var(--amber); }
.battery-fill.low { background: var(--danger); }

.danger-meter {
  display: inline-flex; align-items: center; gap: 3px;
}
.danger-dot {
  width: 8px; height: 8px; border-radius: 50%;
  border: 1px solid rgba(255,45,85,0.3); transition: all 200ms;
}
.danger-dot.active { background: var(--danger); box-shadow: 0 0 8px rgba(255,45,85,0.6); border-color: var(--danger); }

.inv-items {
  display: inline-flex; gap: 2px; align-items: center;
}
.inv-slot {
  width: 22px; height: 22px; border: 1px solid var(--line);
  border-radius: 4px; display: grid; place-items: center;
  font-size: 0.65rem; background: rgba(10,5,18,0.7);
}

.toast {
  position: absolute; bottom: 80px; left: 50%; transform: translateX(-50%);
  z-index: 15; padding: 10px 20px; border-radius: 8px;
  background: rgba(16,8,28,0.92); backdrop-filter: blur(8px);
  border: 1px solid var(--line); color: var(--text);
  font-size: 0.85rem; text-align: center;
  opacity: 0; visibility: hidden; transition: all 250ms; max-width: 90vw;
  pointer-events: none;
}
.toast-visible { opacity: 1; visibility: visible; }

.jumpscare-flash {
  position: absolute; inset: 0; z-index: 12;
  pointer-events: none; opacity: 0;
  transition: opacity 50ms;
}

.nn-score-nudge {
  margin: 12px 0; padding: 14px; border-radius: 8px;
  border: 1px solid rgba(255, 179, 71, 0.2);
  background: rgba(255, 179, 71, 0.06);
}
.nn-score-nudge p { color: var(--amber); font-size: 0.85rem; margin-bottom: 10px; }
.nn-nudge-btns { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.nn-nudge-signup {
  display: inline-block; padding: 8px 16px; border-radius: 6px;
  background: var(--accent); color: #fff; text-decoration: none;
  font-weight: 700; font-size: 0.8rem; transition: opacity 150ms;
}
.nn-nudge-signup:hover { opacity: 0.85; }
.nn-nudge-later {
  padding: 8px 16px; border-radius: 6px; border: 1px solid var(--line);
  background: transparent; color: var(--muted); cursor: pointer; font-size: 0.8rem;
}

.leaderboard-list { margin: 12px 0; font-size: 0.82rem; }
.lb-entry {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 12px; border-bottom: 1px solid rgba(196,115,255,0.06);
}
.lb-entry:last-child { border-bottom: none; }
.lb-rank { color: var(--muted); min-width: 24px; }
.lb-name { color: var(--text); flex: 1; text-align: left; margin-left: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { color: var(--amber); font-weight: 700; }
.lb-entry.me { background: rgba(196,115,255,0.06); border-color: rgba(196,115,255,0.15); }

.final-score {
  font-size: 3rem; font-weight: 900; margin: 8px 0;
  color: var(--accent); text-shadow: var(--shadow-glow);
}

.summary-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 12px 0;
}
.summary-grid div {
  padding: 8px; border: 1px solid var(--line); border-radius: 6px;
  background: rgba(10,5,18,0.5);
}
.summary-grid span { display: block; color: var(--muted); font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.06em; }
.summary-grid b { color: var(--text); font-size: 1rem; }

.tutorial-overlay {
  position: absolute; inset: 0; z-index: 9;
  background: rgba(0,0,0,0.7); display: flex;
  align-items: center; justify-content: center;
  opacity: 0; visibility: hidden; transition: opacity 250ms;
  pointer-events: none;
}
.tutorial-overlay.active { opacity: 1; visibility: visible; pointer-events: auto; }

.tutorial-card {
  width: min(88vw, 420px); padding: 24px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel);
  backdrop-filter: blur(12px); text-align: center;
}
.tutorial-card h3 { color: var(--accent); margin: 0 0 12px; }
.tutorial-card p { font-size: 0.85rem; margin-bottom: 8px; }
.tutorial-card .keys {
  display: flex; justify-content: center; gap: 8px; flex-wrap: wrap;
  margin: 14px 0;
}
.tutorial-card kbd {
  padding: 6px 12px; border: 1px solid var(--line); border-radius: 6px;
  background: rgba(10,5,18,0.8); font-size: 0.75rem; color: var(--accent);
  font-family: inherit;
}
.tutorial-card button {
  margin-top: 16px;
}

@media (max-width: 720px) {
  .game-bar { height: 38px; padding: 4px 8px; }
  .game-bar-title { font-size: 0.78rem; }
  .game-wrap { margin-top: 38px; }
  .screen { padding-top: 50px; }
  .panel { padding: 20px 16px; }
  .summary-grid { grid-template-columns: 1fr; }
  .hud-chip { font-size: 0.62rem; padding: 3px 7px; }
  .hud-chip b { font-size: 0.75rem; }
  .battery-track { width: 36px; }
}
