:root {
  /* Eldritch night: ash-black ground, blood-moon red, torch amber. */
  --bg: #070409;
  --bg-2: #23101a;
  --panel: rgba(16, 9, 14, 0.94);
  --ink: #efe6dd;
  --muted: #9a8c84;
  --accent: #c5402f;     /* blood red */
  --accent-2: #ffae3c;   /* torch amber */
  --line: rgba(255, 230, 210, 0.09);
  --radius: 16px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(1200px 700px at 50% -10%, var(--bg-2), var(--bg));
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}
.layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 14px;
}

/* Ads */
.ad-rail { display: flex; justify-content: center; align-items: center; min-height: 90px; }
.ad-slot { width: 100%; max-width: 728px; }
.ad-placeholder {
  width: 100%; max-width: 728px; min-height: 90px;
  display: flex; align-items: center; justify-content: center;
  border: 1px dashed var(--line); border-radius: 12px;
  color: var(--muted); font-size: 12px; letter-spacing: 0.18em;
  text-transform: uppercase; background: rgba(255, 255, 255, 0.02);
}
.ad-rail.ad-live .ad-placeholder { display: none; }
.ad-rail:not(.ad-live) .ad-slot { display: none !important; }

/* Stage */
.stage { max-width: 1040px; width: 100%; margin: 0 auto; }
.game-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 8 / 5;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
#game {
  display: block;
  width: 100%;
  height: 100%;
  background: radial-gradient(120% 80% at 50% 0%, #2a0e16 0%, #0c0610 55%, #050308 100%);
  cursor: crosshair;
  touch-action: none;
}

/* HUD — kept clear of the top-right controls; shrinks on narrow screens. */
.hud {
  position: absolute;
  top: 14px; left: 16px; right: 110px;
  display: flex; gap: 18px; align-items: center;
  pointer-events: none;
  font-size: 13px; letter-spacing: 0.1em;
  color: var(--muted);
}
.hud b { color: var(--ink); font-size: 18px; margin-left: 5px; font-variant-numeric: tabular-nums; }
.hud-lives b { color: var(--accent-2); letter-spacing: normal; }
@media (max-width: 620px) {
  .hud { gap: 10px; right: 96px; font-size: 11px; letter-spacing: 0.04em; }
  .hud b { font-size: 14px; margin-left: 3px; }
}

/* Soul-shards (XP) meter — a thin bar along the BOTTOM of the arena. */
.overdrive {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
  width: min(560px, 82%); pointer-events: none;
}
.overdrive .od-label {
  font-size: 10px; letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--muted); text-align: center; margin-bottom: 4px;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.8);
}
.overdrive .od-bar {
  height: 7px; border-radius: 5px; overflow: hidden;
  background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line);
}
.overdrive .od-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.1s linear;
}
.overdrive.is-ready .od-fill { animation: odpulse 0.8s ease-in-out infinite; }
@keyframes odpulse { 0%,100% { filter: brightness(1); } 50% { filter: brightness(1.6); } }

.controls {
  position: absolute; top: 12px; right: 12px; z-index: 5;
  display: flex; gap: 8px; align-items: center;
}
.ctrl-btn {
  height: 38px; border-radius: 19px;
  border: 1px solid var(--line); background: rgba(20, 12, 40, 0.7);
  color: var(--ink); font-size: 14px; font-weight: 700; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center; text-decoration: none;
  backdrop-filter: blur(4px);
  transition: filter 0.15s ease, transform 0.06s ease;
}
.ctrl-btn:hover { filter: brightness(1.25); }
.ctrl-btn:active { transform: scale(0.94); }
.back-btn { padding: 0 14px; }
.mute-btn { width: 38px; border-radius: 50%; font-size: 16px; }
.mute-btn.is-muted { opacity: 0.6; }

/* Overlay */
.overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(8, 4, 15, 0.66); backdrop-filter: blur(3px);
  transition: opacity 0.2s ease;
}
.overlay.hidden { opacity: 0; pointer-events: none; }
.panel {
  width: min(460px, 88%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px 26px; text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}
.logo { margin: 0 0 10px; font-size: clamp(30px, 5vw, 44px); font-weight: 800; letter-spacing: 0.06em; }
.logo span { color: var(--accent); }
.msg { color: var(--muted); font-size: 14px; line-height: 1.6; margin: 0 0 20px; }
.msg b { color: var(--ink); }
.result { margin-bottom: 16px; }
.big-score { font-size: 56px; font-weight: 800; color: var(--accent); line-height: 1; }
.result-line { color: var(--muted); font-size: 14px; margin-top: 6px; }
.btn {
  border: none; border-radius: 12px; padding: 13px 18px;
  font-size: 16px; font-weight: 700; cursor: pointer;
  transition: transform 0.06s ease, filter 0.15s ease;
}
.btn:active { transform: translateY(1px); }
.btn--primary {
  width: 100%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #1a0533;
}
.btn--primary:hover { filter: brightness(1.06); }
.hint { margin-top: 12px; color: var(--muted); font-size: 13px; }
.hidden { display: none !important; }

.btn--ghost { background: rgba(255, 255, 255, 0.08); color: var(--ink); white-space: nowrap; }
.name-row { display: flex; gap: 8px; margin-bottom: 16px; }
#name-input {
  flex: 1; background: rgba(0, 0, 0, 0.3); border: 1px solid var(--line);
  border-radius: 10px; color: var(--ink); padding: 10px 12px; font-size: 15px; outline: none;
}
#name-input:focus { border-color: var(--accent); }

/* Leaderboard */
.leaderboard {
  margin-top: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.leaderboard h2 {
  margin: 0 0 12px; font-size: 16px; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--muted);
}
#leaderboard-list { list-style: none; margin: 0; padding: 0; counter-reset: rank; }
#leaderboard-list li {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px;
}
#leaderboard-list li:last-child { border-bottom: none; }
#leaderboard-list li:not(.lb-empty)::before {
  counter-increment: rank; content: counter(rank);
  width: 26px; color: var(--muted); font-variant-numeric: tabular-nums;
}
.lb-name { flex: 1; margin: 0 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.lb-empty { color: var(--muted); justify-content: center !important; }
li.is-you { color: var(--accent); }

/* HUD: HP in torch-amber, turns red when low (toggled by game.js). */
.hud-lives b { color: var(--accent-2); letter-spacing: normal; }
.hud-lives.is-low b { color: #ff5a3c; }

/* Level-up boon picker — pauses the game, dims the arena, offers 3 cards. */
.upgrade-overlay {
  position: absolute; inset: 0; z-index: 6;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(80% 80% at 50% 40%, rgba(40, 8, 12, 0.72), rgba(5, 3, 8, 0.9));
  backdrop-filter: blur(3px);
}
.upgrade-overlay.hidden { display: none !important; }
.upgrade-panel { width: min(640px, 94%); text-align: center; }
.upgrade-title {
  font-size: clamp(16px, 3.4vw, 22px); font-weight: 800; letter-spacing: 0.04em;
  color: var(--ink); margin-bottom: 16px; text-shadow: 0 0 18px rgba(197, 64, 47, 0.6);
}
.upgrade-title span { color: var(--accent-2); }
.upgrade-cards { display: flex; gap: 10px; justify-content: center; align-items: stretch; }
.upgrade-card {
  flex: 1 1 0; min-width: 0; max-width: 200px;
  background: linear-gradient(180deg, rgba(34, 14, 20, 0.95), rgba(12, 7, 12, 0.95));
  border: 1px solid rgba(255, 174, 60, 0.22); border-radius: 14px;
  padding: 14px 11px; cursor: pointer; text-align: center;
  transition: transform 0.08s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
@media (max-width: 560px) {
  .upgrade-card { padding: 11px 8px; border-radius: 11px; }
  .upgrade-card .uc-icon { font-size: 26px; }
  .upgrade-card .uc-name { font-size: 13px; }
  .upgrade-card .uc-desc { font-size: 11px; }
}
.upgrade-card:hover {
  transform: translateY(-3px); border-color: var(--accent-2);
  box-shadow: 0 10px 30px rgba(197, 64, 47, 0.35), 0 0 0 1px rgba(255, 174, 60, 0.3) inset;
}
.upgrade-card:active { transform: translateY(0) scale(0.98); }
.upgrade-card .uc-icon { font-size: 32px; line-height: 1; margin-bottom: 8px; }
.upgrade-card .uc-name { font-size: 15px; font-weight: 800; color: var(--ink); margin-bottom: 4px; }
.upgrade-card .uc-lvl { font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent-2); margin-bottom: 8px; }
.upgrade-card .uc-desc { font-size: 12.5px; line-height: 1.5; color: var(--muted); }
