/* ============================================================================
   Spirit Runner — style.css (Game 07, plan/games/07-spirit-runner.md §3)
   Forked from Game 05's stylesheet. Mobile-first, one-thumb: the canvas
   contain-fits the 900×500 logical viewport into the space below the
   back-link (no scrolling in any state); main.js sizes it explicitly, so
   the CSS only lays out the chrome. Additions for 07: the character cards
   (menu picker with locked shard costs), the auto-power toggle, and the
   bottom-right power button that lights when the orb meter is full.
   Theme follows the site's `ai-quiz-theme` setting (resolved to
   [data-theme="dark"] / "light" by an inline script in index.html).
   ========================================================================== */

:root,
[data-theme='light'] {
  --bg-a: #e8e4f3;
  --bg-b: #d4c5e8;
  --card: #ffffff;
  --card-border: rgba(148, 163, 184, 0.35);
  --text: #1e293b;
  --muted: #64748b;
  --primary-a: #7c3aed;
  --primary-b: #4f46e5;
  --gold: #b45309;
  --gold-bg: #fef3c7;
  --spirit: #14b8a6;
  --spirit-bg: rgba(20, 184, 166, 0.12);
  --dim: rgba(12, 20, 42, 0.45);
  --shadow: 0 10px 30px rgba(30, 27, 75, 0.18);
}

[data-theme='dark'] {
  --bg-a: #1e1b4a;
  --bg-b: #12102e;
  --card: #272257;
  --card-border: rgba(148, 163, 184, 0.3);
  --text: #e2e8f0;
  --muted: #94a3b8;
  --primary-a: #8b5cf6;
  --primary-b: #6366f1;
  --gold: #fcd34d;
  --gold-bg: rgba(252, 211, 77, 0.14);
  --spirit: #5eead4;
  --spirit-bg: rgba(94, 234, 212, 0.12);
  --dim: rgba(4, 10, 22, 0.55);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family:
    'Segoe UI',
    system-ui,
    -apple-system,
    sans-serif;
  background: linear-gradient(160deg, var(--bg-a), var(--bg-b));
  color: var(--text);
}

.app {
  position: relative; /* anchors the All-games pill */
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* BUG-019/018/020: the All-games exit must stay readable over the full-screen
   canvas — pill offset to the right of the pause chip so both stay tappable. */
.back-link {
  position: absolute;
  top: 12px;
  left: 72px;
  z-index: 30;
  display: inline-block;
  padding: 8px 16px;
  color: #fff;
  background: rgba(15, 24, 45, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  text-decoration: none;
  font-size: 14px;
  font-weight: 700;
  backdrop-filter: blur(6px);
}

.back-link:hover {
  background: rgba(15, 24, 45, 0.78);
  color: #fff;
  text-decoration: none;
}

/* BUG-034: the pill must not sit over live gameplay — main.js's showScreen
   toggles this class: hidden while playing, back on pause/menu/game-over. */
.back-link.hidden {
  display: none;
}

/* ---- stage + canvas ------------------------------------------------------ */

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
  padding: 0; /* BUG-018/020: full-screen game — no page chrome margins */
}

.world-wrap {
  position: relative; /* overlays and the chip buttons align to the canvas box */
}

#world {
  display: block;
  /* Pre-JS guard: fitCanvas() sizes the canvas on the first render frame; until
     then cap it at the container so the page can never scroll sideways. */
  max-width: 100%;
  height: auto;
  border-radius: 0; /* BUG-020: full-bleed background — no card framing */
  box-shadow: none;
  background: #1c2c52; /* painted over every frame — this only covers resize gaps */
  touch-action: none; /* the whole world is a game surface (plan §4) */
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* ---- chip buttons (mute / pause) ------------------------------------------- */

.chip {
  position: absolute;
  top: 14px;
  z-index: 6;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.55);
  background: rgba(15, 24, 45, 0.4);
  color: #fff;
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.chip.mute {
  right: 14px;
}

.chip.pause {
  left: 14px;
}

.chip.hidden {
  display: none;
}

.chip:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}

/* ---- power button (plan §2 Phase B: bottom-right, thumb reach) -------------- */

.power-btn {
  position: absolute;
  right: 16px;
  bottom: 16px;
  z-index: 6;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: rgba(15, 24, 45, 0.45);
  color: rgba(255, 255, 255, 0.55);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  transition:
    transform 0.12s ease,
    box-shadow 0.2s ease,
    background 0.2s ease,
    color 0.2s ease;
}

.power-btn.charged {
  border-color: #ffe9b0;
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  color: #fff;
  box-shadow: 0 0 22px rgba(245, 158, 11, 0.75);
  animation: power-pulse 1.1s ease-in-out infinite;
}

.power-btn.charged:active {
  transform: scale(0.92);
}

.power-btn.charged:focus-visible {
  outline: 3px solid #ffe9b0;
  outline-offset: 2px;
}

@keyframes power-pulse {
  0%,
  100% {
    box-shadow: 0 0 14px rgba(245, 158, 11, 0.55);
  }
  50% {
    box-shadow: 0 0 28px rgba(245, 158, 11, 0.95);
  }
}

.power-btn.hidden {
  display: none;
}

/* ---- overlays --------------------------------------------------------------- */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 18px;
  background: var(--dim);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.overlay.hidden {
  display: none;
}

.card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 9px;
  width: min(340px, 90%);
  max-height: 94%;
  overflow-y: auto;
  padding: 20px 20px;
  border-radius: 22px;
  background: var(--card);
  border: 1px solid var(--card-border);
  box-shadow: var(--shadow);
  text-align: center;
}

.card-emoji {
  font-size: 40px;
  line-height: 1;
}

.card-title {
  margin: 0;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.card-sub {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--muted);
}

.best-line {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}

.shards-line {
  color: var(--spirit);
}

.final-score {
  font-size: 52px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.02em;
}

.badge-new {
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--gold-bg);
  color: var(--gold);
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.badge-new.hidden {
  display: none;
}

.unlock-line {
  margin: 0;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--spirit-bg);
  color: var(--spirit);
  font-size: 12.5px;
  font-weight: 700;
}

.unlock-line.hidden {
  display: none;
}

.tiny-hint {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

/* ---- character cards (plan §2 Phase D picker) -------------------------------- */

.char-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: 100%;
}

.char-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 6px 8px;
  border-radius: 14px;
  border: 2px solid var(--card-border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition:
    border-color 0.12s ease,
    background 0.12s ease,
    transform 0.12s ease;
}

.char-card:hover {
  background: rgba(148, 163, 184, 0.12);
}

.char-card.selected {
  border-color: var(--spirit);
  background: var(--spirit-bg);
}

.char-card.locked {
  opacity: 0.62;
  cursor: not-allowed;
}

.char-card:focus-visible {
  outline: 3px solid var(--primary-a);
  outline-offset: 2px;
}

.char-emoji {
  font-size: 22px;
  line-height: 1;
}

.char-name {
  font-size: 12.5px;
  font-weight: 800;
}

.char-blurb {
  font-size: 10px;
  line-height: 1.3;
  color: var(--muted);
  min-height: 26px;
}

.char-state {
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
}

.char-card.selected .char-state {
  color: var(--spirit);
}

.char-cost {
  color: var(--gold);
}

/* ---- settings row --------------------------------------------------------------- */

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.check-row input {
  width: 17px;
  height: 17px;
  accent-color: var(--primary-a);
  cursor: pointer;
}

/* ---- buttons ------------------------------------------------------------------ */

button {
  font-family: inherit;
}

.primary {
  width: 100%;
  padding: 12px 22px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary-a), var(--primary-b));
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(124, 58, 237, 0.35);
  transition:
    transform 0.12s ease,
    filter 0.12s ease;
}

.primary:hover {
  filter: brightness(1.07);
}

.primary:active {
  transform: scale(0.97);
}

.ghost {
  padding: 9px 16px;
  border: 1.5px solid var(--card-border);
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s ease;
}

.ghost:hover {
  background: rgba(148, 163, 184, 0.14);
}

.primary:focus-visible,
.ghost:focus-visible {
  outline: 3px solid var(--primary-a);
  outline-offset: 2px;
}

.btn-row {
  display: flex;
  gap: 10px;
  width: 100%;
}

.btn-row .ghost {
  flex: 1;
}

/* ---- toast ----------------------------------------------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 16px);
  z-index: 20;
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--text);
  color: var(--card);
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
}

.toast.toast--in {
  opacity: 1;
  transform: translate(-50%, 0);
}
