:root {
  color-scheme: dark;
  --ink: #090a08;
  --charcoal: #151713;
  --moss-dark: #1f291c;
  --moss: #34432a;
  --olive: #5a6240;
  --earth: #342a20;
  --stone: #57574d;
  --bone: #d2c8ae;
  --moon: #bbc4b0;
  --warning: #8a3a32;
  --gold: #b69a4c;
  --focus: #e5d88d;
}

* { box-sizing: border-box; }

html { background: var(--ink); scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--bone);
  background:
    radial-gradient(circle at 50% 0%, rgba(90, 98, 64, .18), transparent 32rem),
    repeating-linear-gradient(0deg, rgba(255,255,255,.012) 0 1px, transparent 1px 4px),
    var(--ink);
  font-family: "Courier New", Courier, monospace;
}

button { font: inherit; }
button:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

.page-shell { width: min(100%, 1120px); margin: 0 auto; padding: 42px 20px 80px; }
.campaign-header { text-align: center; margin: 0 auto 28px; max-width: 760px; }
.eyebrow, .overlay-rule { color: var(--gold); letter-spacing: .22em; font-size: .75rem; font-weight: 700; }
.campaign-header h1 { margin: 8px 0; font-size: clamp(2rem, 7vw, 4.8rem); line-height: .95; letter-spacing: .03em; }
.lede { color: var(--moon); line-height: 1.6; }
.campaign-progress { margin: 8px 0 0; color: var(--gold); font-size: .68rem; letter-spacing: .14em; }
.campaign-progress[hidden] { display: none; }

.game-shell { max-width: 1000px; margin: auto; }
.game-frame {
  position: relative;
  overflow: hidden;
  width: 100%;
  aspect-ratio: 16 / 9;
  min-height: 260px;
  max-height: 76vh;
  background: #10140e;
  border: 2px solid var(--stone);
  box-shadow: 0 24px 70px rgba(0, 0, 0, .55), inset 0 0 0 3px #0c0d0b;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.game-frame * {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.game-frame::after { content: ""; position: absolute; z-index: 18; inset: 0; pointer-events: none; opacity: 0; }
.game-frame.hit-flash::after { background: rgba(197,96,85,.3); animation: frame-flash .18s steps(2); }
.game-frame.reward-flash::after { background: rgba(224,207,125,.25); animation: frame-flash .18s steps(2); }
@keyframes frame-flash { 0%, 55% { opacity: 1; } 100% { opacity: 0; } }

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.hud {
  position: absolute;
  inset: 14px 14px auto;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
  font-size: clamp(.75rem, 2vw, 1rem);
  font-weight: 700;
  text-shadow: 2px 2px #000;
}

.hearts { color: #b44b42; letter-spacing: .15em; }
.relic-count { color: var(--bone); }
.icon-button {
  position: absolute;
  z-index: 8;
  top: 42px;
  padding: 6px 8px;
  color: var(--bone);
  background: rgba(9,10,8,.78);
  border: 1px solid var(--stone);
  font-size: clamp(.56rem, 1.5vw, .72rem);
}
.sound-button { right: 14px; }
.pause-button { left: 14px; }
.options-button { right: 104px; z-index: 24; }
.fullscreen-button { right: 182px; z-index: 24; }
.loading-overlay { z-index: 30; background: var(--ink); }
.orientation-hint { display: none; }

.overlay {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(7, 8, 6, .78);
  backdrop-filter: blur(2px);
}
.overlay[hidden], .hud[hidden], .icon-button[hidden], .message[hidden] { display: none; }
.overlay-card { max-width: 480px; text-align: center; }
.overlay-card h2 { margin: 8px 0 14px; font-size: clamp(1.65rem, 6vw, 3.8rem); line-height: .95; }
.overlay-card p { margin: 0 0 18px; line-height: 1.55; }
.overlay-card.compact h2 { margin-bottom: 22px; }
.pause-rule { max-width: 430px; margin: 18px auto 0; }
.overlay-card .pause-rule .overlay-rule { margin-bottom: 8px; }
.pause-rule-title { color: var(--bone); font-size: clamp(.76rem, 2vw, 1rem); line-height: 1.5; }
.options-overlay { z-index: 25; background: rgba(5,6,5,.94); }
.options-card { width: min(460px, 96%); padding: 22px; border: 1px solid var(--gold); background: rgba(9,10,8,.96); }
.options-card label { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin: 10px 0; padding: 8px 0; border-bottom: 1px solid rgba(210,200,174,.18); color: var(--moon); font-size: .76rem; text-align: left; }
.options-card input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--gold); }
.options-card input[type="range"] { width: 160px; accent-color: var(--gold); }

.primary-button, .secondary-button {
  min-height: 46px;
  padding: 10px 18px;
  border: 2px solid var(--bone);
  font-weight: 700;
  letter-spacing: .06em;
  cursor: pointer;
}
.primary-button { color: var(--ink); background: var(--bone); }
.secondary-button { color: var(--bone); background: transparent; }
.resume-campaign { display: block; margin: 10px auto 0; }
.resume-campaign[hidden] { display: none; }
.control-hint { margin-top: 14px !important; color: var(--moon); font-size: .72rem; letter-spacing: .08em; }
.level-transition { background: radial-gradient(circle at 50% 30%, rgba(107,46,42,.28), transparent 45%), rgba(5,6,5,.9); }
.level3-transition { background: radial-gradient(circle at 50% 24%, rgba(140,122,74,.25), transparent 38%), rgba(5,6,5,.92); }
.level2-controls { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin: 0 0 18px; }
.level2-controls span { padding: 5px 8px; color: var(--gold); background: rgba(9,10,8,.75); border: 1px solid var(--stone); font-size: .7rem; }
.level2-intro-rule, .level3-intro-rule { max-width: 460px; margin: 16px auto 0; }
.overlay-card .level2-intro-rule .overlay-rule,
.overlay-card .level3-intro-rule .overlay-rule { margin-bottom: 7px; }
.overlay-card .level2-intro-rule p:last-child,
.overlay-card .level3-intro-rule p:last-child { margin-bottom: 0; font-size: clamp(.68rem, 1.8vw, .88rem); line-height: 1.45; }

.message {
  position: absolute;
  z-index: 9;
  left: 50%;
  top: 24%;
  min-width: min(86%, 380px);
  transform: translateX(-50%);
  padding: 10px 14px;
  color: var(--bone);
  background: rgba(59, 18, 16, .92);
  border: 1px solid var(--warning);
  text-align: center;
  pointer-events: none;
}
.message strong, .message span { display: block; }
.message strong { color: #e0978d; font-size: 1.15rem; letter-spacing: .12em; }
.message span { margin-top: 4px; font-size: .76rem; }

.results-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px 20px; margin: 16px auto; max-width: 340px; }
.results-grid div { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px solid rgba(210,200,174,.24); }
.results-grid .wide { grid-column: 1 / -1; }
.results-grid dt { color: var(--moon); }
.results-grid dd { margin: 0; color: var(--gold); font-weight: 700; }
.result-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; }

.finale-overlay {
  place-items: end center;
  padding: 14px;
  background: linear-gradient(180deg, transparent 48%, rgba(7, 8, 6, .9) 78%);
  backdrop-filter: none;
  pointer-events: none;
}
.finale-card {
  width: min(680px, 96%);
  padding: 10px 18px 12px;
  background: rgba(9, 10, 8, .86);
  border: 1px solid rgba(224, 207, 125, .6);
  box-shadow: 0 8px 30px rgba(0, 0, 0, .5);
  pointer-events: auto;
}
.finale-card .overlay-rule { margin-bottom: 3px; font-size: clamp(.55rem, 1.4vw, .72rem); }
.finale-card h2 { margin: 2px 0 3px; font-size: clamp(1.4rem, 4vw, 2.4rem); }
.finale-card p { margin-bottom: 9px; line-height: 1.35; }
.finale-card .primary-button, .finale-card .secondary-button { min-height: 38px; padding: 6px 14px; }

.prize-overlay {
  z-index: 14;
  background: #050604;
  backdrop-filter: none;
}
.prize-card {
  width: min(620px, 96%);
  padding: clamp(22px, 5vw, 48px);
  border: 2px solid var(--gold);
  box-shadow: 0 0 0 5px #11140e, 0 0 46px rgba(224, 207, 125, .12);
}
.prize-card h2 {
  color: var(--bone);
  text-shadow: 3px 3px #342a20;
}
.prize-offer { color: var(--moon); font-size: clamp(.85rem, 2.4vw, 1.15rem); }
.prize-offer strong { color: var(--focus); }
.promo-code {
  margin: 0 auto 20px;
  padding: 12px 18px;
  color: var(--ink);
  background: var(--focus);
  border: 3px solid var(--bone);
  outline: 3px solid #342a20;
  font-size: clamp(1.15rem, 4vw, 2rem);
  font-weight: 700;
  letter-spacing: .16em;
}
.prize-status { min-height: 1.4em; color: var(--focus); font-size: .72rem; }
.shop-button { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }

body.high-contrast .legend.danger,
body.high-contrast .message { box-shadow: 0 0 0 3px #fff, 0 0 18px rgba(255,255,255,.45); }
body.high-contrast .game-frame { border-color: var(--focus); }
body.reduce-effects *, body.reduce-effects *::before, body.reduce-effects *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }

.dpad {
  position: absolute;
  z-index: 7;
  left: max(14px, env(safe-area-inset-left));
  bottom: max(14px, env(safe-area-inset-bottom));
  display: none;
  grid-template: repeat(3, 48px) / repeat(3, 48px);
  gap: 4px;
}
.dpad[hidden] { display: none; }
.dpad button {
  border: 1px solid rgba(210,200,174,.55);
  color: var(--bone);
  background: rgba(9,10,8,.72);
  border-radius: 5px;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.dpad button:active { color: var(--ink); background: var(--focus); transform: translateY(1px); }
.dpad button[data-direction="up"] { grid-area: 1 / 2; }
.dpad button[data-direction="left"] { grid-area: 2 / 1; }
.dpad button[data-direction="down"] { grid-area: 2 / 2; }
.dpad button[data-direction="right"] { grid-area: 2 / 3; }

.below-game { display: flex; justify-content: space-between; align-items: center; gap: 16px; color: var(--moon); font-size: .75rem; }
.legend { display: inline-block; position: relative; width: 12px; height: 10px; margin: 0 4px 0 12px; vertical-align: -1px; }
.legend.true { background: var(--gold); border: 2px solid #e0cf7d; clip-path: polygon(25% 0,75% 0,100% 25%,100% 75%,75% 100%,25% 100%,0 75%,0 25%); }
.legend.false { border: 2px solid var(--warning); border-radius: 60% 0 60% 0; transform: rotate(-45deg); }
.legend.false::after { content: ""; position: absolute; inset: 2px 3px; background: var(--bone); }
.legend.danger { height: 5px; background: var(--warning); border-radius: 50% 50% 0 50%; }
.legend.venom { background: #83c94c; border: 2px solid #b6ed68; border-radius: 50% 50% 45% 55%; transform: rotate(35deg); }
.text-button {
  padding: 6px 8px;
  color: var(--bone);
  background: rgba(9,10,8,.78);
  border: 1px solid var(--stone);
  cursor: pointer;
}
.story-anchor { max-width: 720px; min-height: 30vh; margin: 8px auto 0; padding: 10px 0 28px; text-align: center; }
.story-anchor h2 { font-size: clamp(1.5rem, 4vw, 2.5rem); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (pointer: coarse), (max-width: 720px) {
  .page-shell { padding: 22px 10px 50px; }
  .game-frame { min-height: 62vh; aspect-ratio: auto; }
  .dpad { display: grid; grid-template: repeat(3, 58px) / repeat(3, 58px); }
  .icon-button { top: 40px; }
  .fullscreen-button { right: 14px; top: 72px; }
  .options-button { right: 112px; }
  .below-game { align-items: flex-start; flex-direction: column; }
  .results-card { transform: scale(.9); }
}

@media (orientation: portrait) and (pointer: coarse) {
  .orientation-hint {
    position: absolute;
    z-index: 6;
    right: 10px;
    bottom: 10px;
    display: block;
    max-width: 180px;
    padding: 6px 8px;
    color: var(--gold);
    background: rgba(9,10,8,.84);
    border: 1px solid var(--stone);
    font-size: .58rem;
    text-align: center;
  }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .overlay { backdrop-filter: none; }
}
