/* Claim Quest — NES-style RPG layout.
   Mobile-first. Full-bleed scene. NPC stage on top, dialogue box anchored
   to the bottom. Chunky 8-bit borders, pixel sprites, NES palette. */

:root {
  --cq-bg-deep:   #06082a;     /* deepest navy (out-of-frame area) */
  --cq-bg:        #0f1c4a;     /* scene wall */
  --cq-bg-mid:    #1a2b5e;     /* inner */
  --cq-bg-floor:  #2a4070;     /* floor strip */
  --cq-ink:       #f4f4f6;
  --cq-muted:     #b9c4d4;
  --cq-accent:    #ffd400;
  --cq-accent-dk: #b8920a;
  --cq-good:      #34c97a;
  --cq-bad:       #e63946;
  --cq-border:    #ffd400;
  --cq-border-dk: #b8920a;
  --cq-dlg-bg:    #06082a;
  --cq-fail:      #4a1010;
  --cq-win:       #103a1a;
  --cq-tap:       48px;
  --cq-pixel:     4px;     /* CSS-pixel size of one "8-bit pixel" */
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: #000;
  color: var(--cq-ink);
  font-family: "Press Start 2P", monospace;
  font-size: 12px;
  line-height: 1.6;
  min-height: 100vh; min-height: 100dvh;
  overflow-x: hidden;
}
body { display: flex; flex-direction: column; }
img, svg { image-rendering: pixelated; image-rendering: crisp-edges; }

.skip-link {
  position: absolute; left: -9999px; top: 0;
  padding: .5rem 1rem; background: var(--cq-accent); color: #000;
  font-weight: 700; z-index: 200;
}
.skip-link:focus { left: .5rem; top: .5rem; }

/* ─── Game frame: chunky pixel border around the whole stage ───── */
.game-frame {
  flex: 1;
  display: flex; flex-direction: column;
  background: var(--cq-bg);
  border: var(--cq-pixel) solid var(--cq-accent);
  margin: 0; min-height: 100vh; min-height: 100dvh;
  width: 100%;
  position: relative;
  box-shadow:
    inset 0 0 0 var(--cq-pixel) #000,
    inset 0 0 0 calc(var(--cq-pixel) * 2) var(--cq-accent),
    inset 0 0 0 calc(var(--cq-pixel) * 3) #000;
}
@media (min-width: 720px) {
  .game-frame {
    margin: 0 auto;
    max-width: 1100px;
    min-height: 100vh; min-height: 100dvh;
  }
  body { background: #000; padding: 0; }
  /* Bigger NPC + bigger dialogue text on desktop so the screen real
     estate doesn't get wasted with a tiny sprite floating in space. */
  .npc-sprite, .title-shield { width: 192px; height: 192px; }
  .npc-stage { top: 8%; }
  .dialogue-text { font-size: 16px; }
  .dialogue-menu .answer-btn { font-size: 16px; }
  .scene-h2 { font-size: 18px; }
  .title-h1 { font-size: 38px; }
}
@media (min-width: 1100px) {
  .npc-sprite, .title-shield { width: 256px; height: 256px; }
}

/* ─── HUD bar (top status) ─────────────────────────────────────── */
.hud-bar {
  display: flex; align-items: center; gap: .75rem;
  padding: .55rem .75rem;
  background: var(--cq-bg-deep);
  border-bottom: var(--cq-pixel) solid var(--cq-accent);
  flex-shrink: 0;
  font-size: 10px;
  position: relative; z-index: 5;
}
.hud-back {
  color: var(--cq-accent); text-decoration: none;
  min-width: var(--cq-tap); min-height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  border: var(--cq-pixel) solid var(--cq-accent);
  background: var(--cq-bg);
  padding: 0 .5rem;
  font-size: 14px;
}
.hud-back:hover, .hud-back:focus-visible {
  background: var(--cq-accent); color: #000; outline: none;
}
.hud-section { display: inline-flex; align-items: center; gap: .35rem; }
.hud-lives { flex: 1; }
.hud-lives .sprite { width: 24px; height: 24px; }
.hud-coin { display: inline-block; width: 20px; height: 20px; }
.hud-xp-num { color: var(--cq-accent); font-size: 11px; }
.hud-coin-label { color: var(--cq-muted); font-size: 9px; margin-left: .25rem; }

/* Mute toggle in HUD. Same look as hud-back so the bar feels balanced. */
.hud-mute {
  color: var(--cq-accent);
  background: var(--cq-bg);
  border: var(--cq-pixel) solid var(--cq-accent);
  min-width: var(--cq-tap); min-height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0 .5rem;
  font-family: 'Press Start 2P', monospace, system-ui;
  font-size: 14px;
  cursor: pointer;
}
.hud-mute:hover, .hud-mute:focus-visible {
  background: var(--cq-accent); color: #000; outline: none;
}
.hud-mute.is-muted { opacity: .55; }
.hud-mute.is-muted .hud-mute-icon::before { content: ''; }

/* Streak flash — tinted hot, animates with the standard flash-pop. */
.flash-banner.is-streak {
  color: #ffb347;
  text-shadow: 0 0 8px rgba(255, 179, 71, 0.6), 0 2px 0 #000;
  animation: flash-pop .6s ease-out;
}

/* Pause button mirrors the mute button styling */
.hud-pause {
  color: var(--cq-accent);
  background: var(--cq-bg);
  border: var(--cq-pixel) solid var(--cq-accent);
  min-width: var(--cq-tap); min-height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0 .5rem;
  font-family: 'Press Start 2P', monospace, system-ui;
  font-size: 14px;
  cursor: pointer;
}
.hud-pause:hover, .hud-pause:focus-visible {
  background: var(--cq-accent); color: #000; outline: none;
}

/* ─── Pause / settings overlay ─────────────────────────────────── */
.pause-overlay {
  position: fixed; inset: 0;
  background: rgba(6, 8, 42, 0.92);
  display: flex; align-items: center; justify-content: center;
  z-index: 1500;
  padding: 1rem;
}
.pause-overlay[hidden] { display: none; }
.pause-frame {
  background: var(--cq-bg);
  border: var(--cq-pixel) solid var(--cq-accent);
  box-shadow:
    inset 0 0 0 var(--cq-pixel) #000,
    inset 0 0 0 calc(var(--cq-pixel) * 2) var(--cq-accent);
  padding: 1.5rem 1rem;
  max-width: 420px; width: 100%;
  text-align: center;
}
.pause-h2 {
  color: var(--cq-accent);
  font-size: 18px;
  margin: 0 0 1.25rem;
  letter-spacing: 2px;
}
.pause-menu {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: .5rem;
}
.pause-btn {
  width: 100%;
  background: var(--cq-bg-mid);
  color: var(--cq-ink);
  border: var(--cq-pixel) solid var(--cq-accent);
  padding: .8rem 1rem;
  font-family: 'Press Start 2P', monospace, system-ui;
  font-size: 11px;
  cursor: pointer;
  min-height: var(--cq-tap);
  text-align: left;
}
.pause-btn:hover, .pause-btn:focus-visible {
  background: var(--cq-accent); color: #000; outline: none;
}
.pause-hint {
  color: var(--cq-muted);
  font-size: 9px;
  margin: 1rem 0 0;
}
.pause-hint kbd {
  background: var(--cq-bg-mid);
  border: 2px solid var(--cq-accent);
  padding: .15rem .4rem;
  color: var(--cq-accent);
  font-family: inherit;
}

/* ─── Level map screen ─────────────────────────────────────────── */
.screen-map {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 2rem 1rem;
  gap: 1.5rem;
  background: linear-gradient(180deg, var(--cq-bg-deep) 0%, var(--cq-bg) 100%);
}
.level-map {
  list-style: none; margin: 0; padding: 0;
  display: flex; align-items: center; justify-content: center;
  gap: .25rem;
  flex-wrap: wrap;
  max-width: 720px; width: 100%;
}
.level-map li {
  display: inline-flex; flex-direction: column; align-items: center;
  gap: .35rem;
  position: relative;
  flex: 0 0 auto;
}
.level-map li + li::before {
  content: '';
  position: absolute;
  left: -.25rem; top: 22px;
  width: .25rem; height: .35rem;
  background: var(--cq-muted);
}
.map-node {
  width: 44px; height: 44px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--cq-bg-mid);
  border: var(--cq-pixel) solid var(--cq-muted);
  color: var(--cq-muted);
  font-family: 'Press Start 2P', monospace;
  font-size: 16px;
}
.map-node.is-done {
  background: var(--cq-good);
  border-color: var(--cq-good);
  color: #000;
}
.map-node.is-current {
  background: var(--cq-accent);
  border-color: var(--cq-accent);
  color: #000;
  animation: map-pulse 1.2s ease-in-out infinite;
}
.map-label {
  color: var(--cq-muted);
  font-size: 8px;
  max-width: 8rem;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: .5px;
  word-break: break-word;
}
.map-node.is-current + .map-label,
li:has(.map-node.is-current) .map-label {
  color: var(--cq-accent);
}
@keyframes map-pulse {
  0%, 100% { transform: scale(1);   box-shadow: 0 0 0 0    rgba(255,212,0,.7); }
  50%      { transform: scale(1.1); box-shadow: 0 0 0 6px  rgba(255,212,0,0); }
}
.map-hint {
  color: var(--cq-muted);
  font-size: 10px;
  margin: 0;
  animation: map-blink 1.4s ease-in-out infinite;
}
@keyframes map-blink {
  0%, 60%  { opacity: 1; }
  61%, 100% { opacity: .2; }
}
@media (min-width: 720px) {
  .map-node { width: 60px; height: 60px; font-size: 20px; }
  .map-label { font-size: 10px; }
  .level-map li + li::before { top: 30px; }
}

/* ─── Boss question (last question of level) ──────────────────── */
.is-boss .dialogue-inner {
  border-color: var(--cq-bad);
  box-shadow:
    inset 0 0 0 var(--cq-pixel) #000,
    inset 0 0 0 calc(var(--cq-pixel) * 2) var(--cq-bad);
}
.is-boss #dlg-progress {
  color: var(--cq-bad);
  text-shadow: 0 0 6px rgba(230, 57, 70, 0.6);
}
.flash-banner.is-boss {
  color: var(--cq-bad);
  text-shadow: 0 0 8px rgba(230, 57, 70, 0.7), 0 2px 0 #000;
  animation: flash-pop .55s ease-out;
}
.flash-banner.is-makeup {
  color: #6cd3ff;
  text-shadow: 0 0 8px rgba(108, 211, 255, 0.55), 0 2px 0 #000;
  animation: flash-pop .55s ease-out;
}
/* Make-up question dialogue: light blue accent so player knows this is
   a bonus shot at the threshold, not a regular question. */
.is-makeup .dialogue-inner {
  border-color: #6cd3ff;
  box-shadow:
    inset 0 0 0 var(--cq-pixel) #000,
    inset 0 0 0 calc(var(--cq-pixel) * 2) #6cd3ff;
}
.is-makeup #dlg-progress {
  color: #6cd3ff;
}

/* ─── Personal best on win screen ─────────────────────────────── */
.win-best-row {
  margin: .5rem 0;
  font-size: 12px;
  color: var(--cq-muted);
}
.win-best-label { margin-right: .35rem; color: var(--cq-muted); }
#win-best-xp { color: var(--cq-accent); }
.win-best-flag {
  display: inline-block;
  margin-left: .5rem;
  padding: .2rem .5rem;
  background: var(--cq-good);
  color: #000;
  font-size: 9px;
  letter-spacing: 1px;
  animation: best-flash 1.2s ease-in-out infinite alternate;
}
@keyframes best-flash {
  from { opacity: 1; }
  to   { opacity: .55; }
}

/* ─── Scene container ─────────────────────────────────────────── */
.scene {
  flex: 1;
  position: relative;
  overflow: hidden;
  outline: none;
  background:
    repeating-linear-gradient(
      to bottom,
      var(--cq-bg) 0,
      var(--cq-bg) 64px,
      var(--cq-bg-mid) 64px,
      var(--cq-bg-mid) 72px
    );
}

.screen { display: none; height: 100%; position: absolute; inset: 0; }
.screen.is-active { display: flex; flex-direction: column; }

/* ─── Title screen ─────────────────────────────────────────────── */
.screen-title {
  align-items: center; justify-content: center;
  background:
    radial-gradient(ellipse at center, var(--cq-bg-mid), var(--cq-bg-deep));
}
.title-stack {
  display: flex; flex-direction: column; align-items: center; gap: .8rem;
  padding: 1.5rem 1rem;
  text-align: center;
}
.title-shield {
  width: 128px; height: 128px;
  margin-bottom: .5rem;
}
.title-shield svg, .title-shield img { width: 100%; height: 100%; display: block; }
.title-h1 {
  font-size: 22px; line-height: 1.2;
  color: var(--cq-accent); margin: 0;
  letter-spacing: 2px;
  text-shadow: var(--cq-pixel) var(--cq-pixel) 0 #000;
}
@media (min-width: 480px) { .title-h1 { font-size: 30px; letter-spacing: 4px; } }
.title-sub {
  color: var(--cq-ink); font-size: 11px; margin: 0;
}
.title-foot { color: var(--cq-muted); font-size: 8px; margin: 1rem 0 0; }

.press-start {
  font-family: inherit; font-size: 12px;
  color: #000; background: var(--cq-accent);
  border: var(--cq-pixel) solid #000;
  padding: .9rem 1.25rem;
  margin: .75rem 0 0;
  cursor: pointer;
  letter-spacing: 2px;
  min-height: var(--cq-tap);
  box-shadow:
    var(--cq-pixel) var(--cq-pixel) 0 var(--cq-border-dk),
    calc(var(--cq-pixel) * 2) calc(var(--cq-pixel) * 2) 0 #000;
  animation: blink 1.4s steps(1) infinite;
}
.press-start:hover, .press-start:focus-visible {
  background: #fff088; outline: none;
  transform: translate(2px, 2px);
  box-shadow:
    2px 2px 0 var(--cq-border-dk),
    4px 4px 0 #000;
}
@keyframes blink { 50% { opacity: .7; } }
@media (prefers-reduced-motion: reduce) { .press-start { animation: none; } }

/* ─── Select screen (claim type list) ─────────────────────────── */
.screen-select {
  padding: 1.25rem 1rem;
  align-items: stretch; justify-content: flex-start;
  overflow-y: auto;
}
.scene-h2 {
  font-size: 14px; color: var(--cq-accent);
  text-align: center; margin: 0 0 1.25rem;
  letter-spacing: 2px;
  text-shadow: var(--cq-pixel) var(--cq-pixel) 0 #000;
}
.claim-type-list { display: grid; gap: .75rem; }
.claim-type-card {
  background: var(--cq-bg-deep);
  color: var(--cq-ink);
  border: var(--cq-pixel) solid var(--cq-accent);
  padding: .9rem;
  text-align: left;
  font-family: inherit; font-size: 11px;
  cursor: pointer;
  min-height: var(--cq-tap);
  position: relative;
  box-shadow: var(--cq-pixel) var(--cq-pixel) 0 #000;
}
.claim-type-card:hover, .claim-type-card:focus-visible {
  background: var(--cq-bg-mid); outline: none;
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0 #000;
}
.claim-type-card .ct-name {
  color: var(--cq-accent); font-size: 12px; display: block;
  margin-bottom: .5rem; letter-spacing: 1px;
}
.claim-type-card .ct-blurb {
  font-family: system-ui, sans-serif; font-size: 13px;
  color: var(--cq-muted); line-height: 1.5;
}

.btn-link {
  background: transparent; border: none;
  color: var(--cq-muted); font-family: inherit; font-size: 10px;
  cursor: pointer; padding: .75rem .5rem; margin-top: .5rem;
  text-align: center; min-height: var(--cq-tap);
}
.btn-link:hover, .btn-link:focus-visible {
  color: var(--cq-accent); outline: none; text-decoration: underline;
}

/* ─── Level scene (NPC stage + dialogue) ──────────────────────── */
.screen-level {
  align-items: stretch; justify-content: flex-end;
  /* Intentionally no padding — dialogue box hugs the bottom. */
}
.scene-bg {
  position: absolute; inset: 0; pointer-events: none;
  background:
    /* Floor stripe at the bottom */
    linear-gradient(to bottom,
      transparent 0, transparent 60%,
      var(--cq-bg-floor) 60%, var(--cq-bg-floor) 70%,
      var(--cq-bg-mid) 70%, var(--cq-bg-mid) 100%
    ),
    /* Wall pattern */
    repeating-linear-gradient(to bottom,
      var(--cq-bg) 0, var(--cq-bg) 32px,
      var(--cq-bg-mid) 32px, var(--cq-bg-mid) 36px
    );
}
.scene-bg-fail { background: linear-gradient(to bottom, var(--cq-fail), #1a0606); }
.scene-bg-win  { background: linear-gradient(to bottom, var(--cq-win), #061a0c); }

.npc-stage {
  position: absolute; top: 12%; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center;
  pointer-events: none; z-index: 2;
}
.npc-sprite {
  width: 128px; height: 128px;
  filter: drop-shadow(2px 2px 0 #000);
  animation: idle-bob 1.6s steps(2, end) infinite;
}
.npc-sprite svg, .npc-sprite img { width: 100%; height: 100%; display: block; }
@keyframes idle-bob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-4px); }
}
@media (prefers-reduced-motion: reduce) { .npc-sprite { animation: none; } }

.npc-name {
  margin-top: .5rem;
  font-size: 10px; color: var(--cq-accent);
  background: var(--cq-bg-deep);
  border: var(--cq-pixel) solid var(--cq-accent);
  padding: .4rem .7rem;
  letter-spacing: 1px;
  text-align: center;
  line-height: 1.5;
}
.npc-name-role { color: var(--cq-muted); font-size: 8px; }

/* ─── Dialogue box ─────────────────────────────────────────────── */
.dialogue {
  position: relative; z-index: 3;
  background: var(--cq-dlg-bg);
  border-top: var(--cq-pixel) solid var(--cq-accent);
  padding: var(--cq-pixel);
  width: 100%;
  max-height: 65%;
  overflow: hidden;
  flex-shrink: 0;
}
.dialogue-inner {
  background: var(--cq-dlg-bg);
  border: var(--cq-pixel) solid var(--cq-accent);
  padding: .8rem .9rem;
}
.dialogue-header {
  display: flex; justify-content: space-between;
  font-size: 8px; color: var(--cq-muted);
  margin-bottom: .65rem;
  letter-spacing: 1px;
}
.dialogue-text {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 14px; line-height: 1.5;
  color: var(--cq-ink);
  margin: 0 0 .8rem;
  min-height: 3.5em;
}
/* Caret blinks while typing */
.dialogue-text::after {
  content: '';
  display: inline-block;
  width: 8px; height: 1em;
  background: var(--cq-accent);
  margin-left: 2px;
  vertical-align: -2px;
  animation: caret 0.6s steps(2) infinite;
  opacity: 0;
}
.dialogue-text.is-typing::after { opacity: 1; }
@keyframes caret { 50% { opacity: 0; } }

.dialogue-menu {
  list-style: none; padding: 0; margin: 0;
  display: grid; gap: .35rem;
}
.dialogue-menu li {
  display: grid;
  grid-template-columns: 16px 1fr;
  gap: .5rem;
  align-items: start;
}
.dialogue-menu .cursor-cell {
  width: 14px; height: 14px;
  visibility: hidden;
  margin-top: 2px;
}
/* Cursor + yellow highlight ONLY appear on hover or keyboard focus —
   no default focused item, so players don't read the first option as
   pre-selected. */
.dialogue-menu li:hover .cursor-cell,
.dialogue-menu li:focus-within .cursor-cell { visibility: visible; }
.dialogue-menu .answer-btn {
  background: transparent; border: none;
  color: var(--cq-ink); font-family: system-ui, sans-serif;
  font-size: 14px; line-height: 1.4;
  text-align: left; cursor: pointer;
  padding: .35rem 0;
  width: 100%; min-height: 36px;
}
.dialogue-menu .answer-btn:hover,
.dialogue-menu .answer-btn:focus-visible {
  color: var(--cq-accent); outline: none;
}
.dialogue-menu li.is-correct .answer-btn {
  color: var(--cq-good);
  font-weight: 700;
  background: rgba(52, 201, 122, .18);
  padding-left: .5rem; padding-right: .5rem;
  border-left: var(--cq-pixel) solid var(--cq-good);
}
.dialogue-menu li.is-wrong .answer-btn {
  color: var(--cq-bad);
  text-decoration: line-through;
  background: rgba(230, 57, 70, .18);
  padding-left: .5rem; padding-right: .5rem;
  border-left: var(--cq-pixel) solid var(--cq-bad);
}

.dialogue-actions {
  display: flex; justify-content: space-between; align-items: center;
  gap: .5rem; margin-top: .75rem;
  flex-wrap: wrap;
}
.btn-fm, .btn-next {
  font-family: inherit; font-size: 9px;
  background: var(--cq-bg-deep);
  color: var(--cq-accent);
  border: var(--cq-pixel) solid var(--cq-accent);
  padding: .55rem .7rem;
  cursor: pointer;
  min-height: 36px;
  letter-spacing: 1px;
}
.btn-fm:hover, .btn-fm:focus-visible,
.btn-next:hover, .btn-next:focus-visible {
  background: var(--cq-accent); color: #000; outline: none;
}

/* ─── Field Manual dialog ──────────────────────────────────────── */
.fm-dialog {
  border: none; padding: 0; background: transparent;
  max-width: min(36rem, 92vw);
  width: 92vw;
}
.fm-dialog::backdrop { background: rgba(0,0,0,.85); }
.fm-frame {
  background: var(--cq-dlg-bg);
  border: var(--cq-pixel) solid var(--cq-accent);
  padding: 1rem 1.1rem;
  box-shadow: 0 0 0 var(--cq-pixel) #000;
}
.fm-h2 {
  font-size: 12px; color: var(--cq-accent);
  margin: 0 0 .9rem;
  letter-spacing: 2px;
  text-align: center;
}
.fm-excerpt {
  font-family: system-ui, sans-serif;
  font-size: 14px; line-height: 1.55;
  color: var(--cq-ink);
  margin: 0 0 1rem;
}
.fm-link {
  display: inline-block; margin: 0 0 1rem;
  color: var(--cq-accent); text-decoration: underline;
  font-family: inherit; font-size: 9px;
  min-height: var(--cq-tap); line-height: var(--cq-tap);
  letter-spacing: 1px;
}
.fm-close { display: block; margin: 0 auto; }

/* ─── Fail / Win screens ──────────────────────────────────────── */
.centerstack {
  position: relative; z-index: 2;
  margin: auto; padding: 1.5rem 1rem;
  text-align: center;
  display: flex; flex-direction: column;
  align-items: center; gap: 1rem;
}
.centertext {
  font-family: system-ui, sans-serif;
  color: var(--cq-ink); font-size: 14px;
  margin: 0;
}
.fail-h2 { color: var(--cq-bad); }
.win-h2  { color: var(--cq-good); }
.win-xp-row {
  display: inline-flex; align-items: center; gap: .5rem;
  margin: 0;
}
.win-xp-row .hud-coin { width: 28px; height: 28px; }
.win-xp-row strong { color: var(--cq-accent); font-size: 16px; }

.win-cta-row { display: flex; gap: .75rem; flex-wrap: wrap; justify-content: center; }
.btn-cta, .btn-cta-2 {
  font-family: inherit; font-size: 10px;
  padding: .8rem 1.1rem;
  border: var(--cq-pixel) solid var(--cq-accent);
  cursor: pointer; min-height: var(--cq-tap);
  text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center;
  letter-spacing: 1px;
}
.btn-cta { background: var(--cq-accent); color: #000; box-shadow: var(--cq-pixel) var(--cq-pixel) 0 #000; }
.btn-cta-2 { background: var(--cq-bg-deep); color: var(--cq-accent); }
.btn-cta:hover, .btn-cta-2:hover,
.btn-cta:focus-visible, .btn-cta-2:focus-visible { outline: none; transform: translate(1px, 1px); }

/* ─── Opt-in form (win screen) ────────────────────────────────── */
.optin-form {
  background: var(--cq-bg-deep);
  border: var(--cq-pixel) solid var(--cq-accent);
  padding: 1rem;
  width: 100%; max-width: 24rem;
  margin: 0 auto;
}
.optin-label {
  display: block; font-size: 9px; color: var(--cq-accent);
  margin-bottom: .65rem; letter-spacing: 1px;
  text-align: center;
}
.optin-row { display: flex; gap: .5rem; flex-wrap: wrap; }
.optin-row input[type="email"] {
  flex: 1; min-width: 11rem;
  font-family: system-ui, sans-serif; font-size: 14px;
  padding: .55rem .7rem;
  background: #000; color: var(--cq-ink);
  border: var(--cq-pixel) solid var(--cq-accent);
  min-height: var(--cq-tap);
}
.optin-row input[type="email"]:focus-visible {
  outline: var(--cq-pixel) solid #fff;
  outline-offset: 2px;
}
.optin-submit { padding: .5rem .9rem; }
.optin-status {
  font-family: system-ui, sans-serif; font-size: 12px;
  color: var(--cq-muted); min-height: 1.2em;
  margin: .65rem 0 0; text-align: center;
}
.optin-status.is-good { color: var(--cq-good); }
.optin-status.is-bad  { color: var(--cq-bad);  }

/* ─── Flash banner (CORRECT! / MISS!) ─────────────────────────── */
.flash-banner {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
  z-index: 80;
  font-family: "Press Start 2P", monospace;
  font-size: 32px;
  letter-spacing: 4px;
  text-shadow: 4px 4px 0 #000;
  opacity: 0;
}
.flash-banner.is-correct {
  color: var(--cq-good);
  animation: flash-pop .6s ease-out;
}
.flash-banner.is-wrong {
  color: var(--cq-bad);
  animation: flash-pop .6s ease-out;
}
.flash-banner.is-cleared {
  color: var(--cq-accent);
  animation: flash-pop 1.0s ease-out;
}
@keyframes flash-pop {
  0%   { opacity: 0; transform: scale(.5); }
  20%  { opacity: 1; transform: scale(1.2); }
  60%  { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1); }
}
@media (min-width: 720px) { .flash-banner { font-size: 56px; } }
@media (prefers-reduced-motion: reduce) { .flash-banner { animation: none; } }

/* ─── Floating XP gain (+100 above the HUD coin) ───────────────── */
.xp-float {
  position: fixed;
  top: 60px; right: 20px;
  font-family: "Press Start 2P", monospace;
  font-size: 14px;
  color: var(--cq-accent);
  text-shadow: 2px 2px 0 #000;
  pointer-events: none;
  z-index: 90;
  opacity: 0;
}
.xp-float.is-active {
  animation: xp-float-up 1s ease-out;
}
@keyframes xp-float-up {
  0%   { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-40px); }
}
@media (prefers-reduced-motion: reduce) {
  .xp-float.is-active { animation: none; opacity: 1; }
}

/* ─── Pulsing [Next ▶] button ─────────────────────────────────── */
.btn-next.is-pulsing {
  animation: next-pulse 1s ease-in-out infinite;
}
@keyframes next-pulse {
  0%, 100% { transform: scale(1);    box-shadow: var(--cq-pixel) var(--cq-pixel) 0 #000; }
  50%      { transform: scale(1.05); box-shadow: calc(var(--cq-pixel) + 1px) calc(var(--cq-pixel) + 1px) 0 #000, 0 0 12px var(--cq-accent); }
}
@media (prefers-reduced-motion: reduce) { .btn-next.is-pulsing { animation: none; } }

/* ─── Heart-loss pulse on miss ─────────────────────────────────── */
.hud-lives.is-shaking {
  animation: hud-shake .35s steps(4) 1;
}
@keyframes hud-shake {
  0%, 100% { transform: translateX(0); }
  25%      { transform: translateX(-4px); }
  75%      { transform: translateX(4px); }
}

/* ─── Boom overlay (level-clear small, game-clear big) ─────────
   Sprite sheets are 30 frames horizontally, each 100x100 source pixels.
   We scale up the displayed frame size and step through with steps(30). */
.boom {
  position: fixed;
  pointer-events: none;
  background-repeat: no-repeat;
  background-position: 0 0;
  image-rendering: pixelated;
  z-index: 70;
  opacity: 0;
}
.boom.is-active { opacity: 1; }

/* Single fixed display sizes (work on both mobile and desktop).
   Sheet is 3000x100 source; we scale via background-size to make
   each frame exactly the displayed width, so steps(30) lands on
   frame boundaries. */
.boom.boom-small {
  width: 320px; height: 320px;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background-image: url('/game/sprites/explosions/round_explosion.png');
  background-size: 9600px 320px;
  animation: boom-small 0.6s steps(30) 1;
}
@keyframes boom-small {
  from { background-position: 0 0; }
  to   { background-position: -9600px 0; }
}

.boom.boom-big {
  width: 480px; height: 480px;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background-image: url('/game/sprites/explosions/X_plosion.png');
  background-size: 14400px 480px;
  animation: boom-big 1.0s steps(30) 1;
}
@keyframes boom-big {
  from { background-position: 0 0; }
  to   { background-position: -14400px 0; }
}

@media (prefers-reduced-motion: reduce) {
  .boom.boom-small, .boom.boom-big { animation: none; opacity: 0; }
}

/* ─── Fade overlay (between scenes) ───────────────────────────── */
.fade-overlay {
  position: fixed; inset: 0;
  background: #000;
  pointer-events: none;
  opacity: 0;
  transition: opacity .25s ease-out;
  z-index: 100;
}
.fade-overlay.is-active { opacity: 1; pointer-events: auto; }
@media (prefers-reduced-motion: reduce) { .fade-overlay { transition: none; } }

/* ─── Scanline overlay (desktop only, subtle) ────────────────── */
.scanlines {
  position: fixed; inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 2px,
    rgba(0,0,0,.18) 2px,
    rgba(0,0,0,.18) 3px
  );
  z-index: 50;
  display: none;
}
@media (min-width: 720px) { .scanlines { display: block; } }
@media (prefers-reduced-motion: reduce) { .scanlines { display: none; } }

/* ─── Sprite sizing helpers ──────────────────────────────────── */
.sprite { display: inline-block; }
.sprite svg { width: 100%; height: 100%; display: block; }

/* ─── Wrong-answer shake (override idle-bob via specificity) ─── */
.npc-sprite.npc-shake {
  animation: npc-shake 0.4s steps(8) 1;
}
@keyframes npc-shake {
  0%, 100% { transform: translateX(0)    translateY(0); }
  25%      { transform: translateX(-8px) translateY(0); }
  75%      { transform: translateX(8px)  translateY(0); }
}

/* ─── Correct-answer celebration: little jump + scale pulse ──── */
.npc-sprite.npc-celebrate {
  animation: npc-celebrate 0.7s ease-out 1;
}
@keyframes npc-celebrate {
  0%   { transform: translateY(0) scale(1); }
  20%  { transform: translateY(-24px) scale(1.08); }
  40%  { transform: translateY(0) scale(1); }
  55%  { transform: translateY(-12px) scale(1.04); }
  70%  { transform: translateY(0) scale(1); }
  100% { transform: translateY(0) scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .npc-sprite.npc-shake, .npc-sprite.npc-celebrate { animation: none; }
}

/* ─── Tight mobile (< 380px) ──────────────────────────────────── */
@media (max-width: 380px) {
  .title-h1 { font-size: 18px; }
  .scene-h2 { font-size: 12px; }
  .npc-sprite { width: 96px; height: 96px; }
  .title-shield { width: 96px; height: 96px; }
  .dialogue-text { font-size: 13px; }
  .dialogue-menu .answer-btn { font-size: 13px; }
}

/* ─── Desktop sprite sizing (placed last so it overrides the
       smaller defaults defined earlier in source order) ──────────── */
@media (min-width: 720px) {
  .npc-sprite, .title-shield { width: 192px; height: 192px; }
  .npc-stage { top: 8%; }
  .dialogue-text { font-size: 16px; }
  .dialogue-menu .answer-btn { font-size: 16px; }
  .scene-h2 { font-size: 18px; }
  .title-h1 { font-size: 38px; }
}
@media (min-width: 1100px) {
  .npc-sprite, .title-shield { width: 256px; height: 256px; }
}
