:root {
  --bg: #0b0908;
  --paper: #14100f;
  --white: #f2f0eb;
  --red: #c81f2a;
  --red-dark: #7a1218;
  --muted: #a39d94;
  --line: #221a18;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  color: var(--white);
  font-family: 'Special Elite', 'Courier New', monospace;
  position: relative;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

#gameCanvas {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
  opacity: 0.1;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='120' height='120'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
}
.vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 49;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0) 45%, rgba(0,0,0,0.65) 100%);
}

.top-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 30;
  padding: 0.9rem 1.25rem;
  background: linear-gradient(to bottom, rgba(0,0,0,0.7), transparent);
  pointer-events: none;
}
.top-bar a.brand {
  font-family: 'Butcherman', cursive;
  color: var(--white);
  text-decoration: none;
  font-size: 1rem;
  pointer-events: auto;
}
.top-bar a.brand span { color: var(--red); }

/* ---- HUD ---- */
.hud {
  position: fixed;
  top: 0.9rem;
  right: 1.25rem;
  z-index: 30;
  text-align: right;
  pointer-events: none;
}
.hud-ability {
  font-size: 0.65rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--red);
  text-shadow: 0 2px 6px rgba(0,0,0,0.8);
  margin-bottom: 0.35rem;
}
.hud-stage {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--white);
  text-shadow: 0 2px 6px rgba(0,0,0,0.8);
  margin-bottom: 0.4rem;
}
.resolve-bar-wrap { display: flex; align-items: center; gap: 0.5rem; justify-content: flex-end; }
.resolve-label {
  font-size: 0.6rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.resolve-bar {
  width: 8rem;
  height: 0.55rem;
  background: rgba(0,0,0,0.5);
  border: 1px solid var(--red-dark);
  border-radius: 2px;
  overflow: hidden;
}
.resolve-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--red-dark), var(--red));
  transition: width 0.2s ease;
}

/* ---- Overlays ---- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.78);
  backdrop-filter: blur(2px);
  padding: 1.5rem;
}
.overlay.hidden { display: none; }
.hidden { display: none !important; }

/* The end sequence renders an actual illustrated scene on the game canvas
   behind this overlay -- style it as a classic JRPG-style dialogue box
   pinned to the bottom, not a full-screen dark backdrop, so the scene
   stays visible while the text plays out. */
#endOverlay {
  align-items: flex-end;
  background: linear-gradient(to top, rgba(0,0,0,0.88) 0%, rgba(0,0,0,0.6) 45%, rgba(0,0,0,0) 100%);
  backdrop-filter: none;
  padding: 0 1.25rem 1.75rem;
}
#endOverlay .panel {
  max-width: 34rem;
  width: 100%;
  background: rgba(11,9,8,0.92);
  border: 2px solid var(--red-dark);
  border-radius: 3px;
  padding: 1.5rem 1.75rem;
  text-align: left;
}
#endOverlay .end-headline,
#endOverlay .twist-gameover,
#endOverlay .end-kicker { text-align: center; }
#endOverlay .actions { justify-content: center; }
#endOverlay #endPeacefulBtn { display: block; margin: 0 auto; }

.panel {
  text-align: center;
  max-width: 27rem;
}

.panel h1 {
  font-family: 'Butcherman', cursive;
  font-weight: 400;
  font-size: clamp(2.6rem, 12vw, 4.2rem);
  color: var(--white);
  text-shadow: 0 0 30px rgba(200,31,42,0.5);
  margin: 0 0 1rem;
  transform: rotate(-1.5deg);
}
.panel h1 span { color: var(--red); }

.rules {
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.6;
  margin: 0 0 1.75rem;
}

.btn-main {
  background: var(--red);
  color: var(--white);
  font-family: 'Special Elite', monospace;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  font-size: 0.9rem;
  padding: 0.9rem 2.2rem;
  border: 2px solid var(--white);
  cursor: pointer;
  box-shadow: 4px 4px 0 #000, 4px 4px 0 1px var(--red-dark);
}
.btn-main:active { transform: translate(2px,2px); box-shadow: 2px 2px 0 #000; }

.controls {
  margin-top: 1.5rem;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0.8;
}

.actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}
.btn-secondary {
  display: inline-block;
  background: transparent;
  color: var(--white);
  border: 1px solid var(--muted);
  font-family: 'Special Elite', monospace;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.8rem;
  padding: 0.75rem 1.5rem;
  cursor: pointer;
  text-decoration: none;
}
.btn-secondary:hover { border-color: var(--white); }

/* ---- Stage intro ---- */
.stage-num {
  font-size: 0.7rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--red);
  margin: 0 0 0.75rem;
}
.stage-name {
  font-family: 'Butcherman', cursive;
  font-weight: 400;
  font-size: clamp(2.2rem, 9vw, 3.4rem);
  color: var(--white);
  margin: 0 0 0.4rem;
  transform: rotate(-1deg);
}
.stage-years {
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 1.25rem;
}
.stage-blurb {
  color: var(--white);
  font-family: 'Source Serif 4', Georgia, serif;
  font-size: 1rem;
  line-height: 1.6;
  margin: 0 0 2rem;
}

/* ---- Stat reveal ---- */
.reveal-kicker {
  font-size: 0.7rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 0.75rem;
}
.reveal-number {
  font-family: 'Butcherman', cursive;
  font-weight: 400;
  font-size: clamp(2.6rem, 12vw, 4rem);
  color: var(--red);
  text-shadow: 0 0 30px rgba(200,31,42,0.5);
  line-height: 1;
  margin-bottom: 1rem;
}
.reveal-label {
  color: var(--white);
  font-family: 'Source Serif 4', Georgia, serif;
  font-size: 1.05rem;
  line-height: 1.55;
  margin: 0 0 0.6rem;
}
.reveal-source {
  color: var(--muted);
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  margin: 0 0 1.75rem;
}
.reveal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
}

/* ---- End ---- */
.end-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 1.25rem;
}
.twist-gameover {
  font-family: 'Special Elite', monospace;
  font-size: 0.85rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 0.5rem;
}
.end-headline {
  font-family: 'Butcherman', cursive;
  font-weight: 400;
  font-size: clamp(2rem, 8vw, 3rem);
  color: var(--red);
  text-shadow: 0 0 30px rgba(200,31,42,0.6);
  margin: 0 0 1.5rem;
  transform: rotate(-1deg);
}
.end-text {
  color: var(--white);
  font-family: 'Source Serif 4', Georgia, serif;
  font-size: 1rem;
  line-height: 1.7;
  margin: 0 0 1.1rem;
}
.end-text.final-line {
  color: var(--muted);
  font-style: italic;
  margin: 0 0 2rem;
}
#endPanelPeaceful .btn-secondary {
  font-size: 1.1rem;
  padding: 0.6rem 1.6rem;
  letter-spacing: 0.3em;
}

.glitch-flash {
  position: fixed;
  inset: 0;
  z-index: 60;
  pointer-events: none;
  background: var(--white);
  opacity: 0;
}
.glitch-flash.firing {
  animation: glitch-seq 0.9s ease-out forwards;
}
/* One bright flash, then a hold and fade -- deliberately not a rapid
   alternation. Full-screen flashing content above ~3 times a second is a
   real photosensitive-seizure risk (WCAG 2.3.1), independent of and in
   addition to the reduced-motion handling below. */
@keyframes glitch-seq {
  0% { opacity: 0; background: var(--white); }
  12% { opacity: 1; background: var(--white); }
  35% { opacity: 1; background: #000; }
  80% { opacity: 1; background: #000; }
  100% { opacity: 0; background: #000; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
