:root {
  --ink: #13251a;
  --cream: #fff5d6;
  --paper: rgba(255, 249, 228, 0.94);
  --lime: #d8f04d;
  --leaf: #3f913e;
  --orange: #ff8b35;
  --red: #e94b35;
  --purple: #67365e;
  --shadow: 0 24px 70px rgba(9, 25, 14, 0.28);
  --display: Impact, Haettenschweiler, 'Arial Narrow Bold', sans-serif;
  --body: Inter, ui-rounded, 'Trebuchet MS', system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #16271d;
  color: var(--ink);
  font-family: var(--body);
}

button { font: inherit; }

button:focus-visible {
  outline: 4px solid #fff;
  outline-offset: 4px;
  box-shadow: 0 0 0 7px var(--ink);
}

#app { position: relative; width: 100%; height: 100%; min-height: 100dvh; isolation: isolate; }

#game-canvas, #trail-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

#game-canvas { z-index: -3; background: #203627; touch-action: none; user-select: none; }
#trail-canvas { z-index: 20; pointer-events: none; }

.vignette {
  position: absolute;
  z-index: -2;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 50% 43%, transparent 30%, rgba(9, 19, 12, 0.23) 100%);
}

.screen {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  padding: clamp(20px, 4vw, 64px);
}

.screen[hidden], .hud[hidden], .loading[hidden], .fatal-error[hidden] { display: none !important; }

.home-screen {
  place-items: center start;
  background: linear-gradient(90deg, rgba(10, 28, 16, 0.9) 0%, rgba(10, 28, 16, 0.53) 46%, transparent 78%);
}

.home-copy { width: min(660px, 80vw); margin-left: clamp(1vw, 7vw, 120px); color: var(--cream); }

.eyebrow {
  margin: 0 0 10px;
  color: var(--lime);
  font-weight: 900;
  font-size: clamp(0.72rem, 1.2vw, 0.9rem);
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

h1, h2, p { margin-top: 0; }

h1 {
  margin-bottom: 12px;
  font-family: var(--display);
  font-size: clamp(5.2rem, 13vw, 10.8rem);
  font-weight: 900;
  line-height: 0.72;
  letter-spacing: -0.055em;
  text-transform: uppercase;
  filter: drop-shadow(0 8px 0 rgba(9, 25, 14, 0.35));
  transform: rotate(-2deg);
}

h1 span, h1 strong { display: block; }
h1 span { color: var(--cream); font-size: 0.62em; letter-spacing: 0.02em; }
h1 strong { color: var(--lime); font-weight: 900; }

.tagline { max-width: 440px; margin: 25px 0; font-size: clamp(1rem, 1.8vw, 1.25rem); line-height: 1.5; color: rgba(255, 245, 214, 0.86); }

.primary-button, .secondary-button, .text-button, .back-button, .icon-button, .map-card {
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 160ms ease, filter 160ms ease, background-color 160ms ease;
}

.primary-button, .secondary-button {
  min-height: 54px;
  padding: 14px 24px;
  border-radius: 14px;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.primary-button {
  background: var(--lime);
  color: var(--ink);
  box-shadow: 0 7px 0 #789c26, 0 14px 30px rgba(0, 0, 0, 0.24);
}

.primary-button:hover, .secondary-button:hover, .map-card:not(:disabled):hover { transform: translateY(-3px); filter: brightness(1.06); }
.primary-button:active, .secondary-button:active, .map-card:not(:disabled):active { transform: translateY(2px); }

.secondary-button { background: #f3e6bd; color: var(--ink); box-shadow: 0 5px 0 #b8a97c; }
.slash-button { min-width: 190px; display: inline-flex; justify-content: space-between; align-items: center; font-size: 1.1rem; }
.slash-button i { font-size: 1.65rem; font-style: normal; line-height: 0; }
.gesture-hint { margin: 25px 0 0; font-size: 0.78rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; opacity: 0.7; }
.gesture-hint span { display: inline-block; margin-right: 8px; font-size: 1.3rem; transform: rotate(-20deg); }

.home-stamp {
  position: absolute;
  right: 5vw;
  bottom: 8vh;
  width: 108px;
  aspect-ratio: 1;
  display: grid;
  place-content: center;
  border: 3px solid rgba(255,255,255,.38);
  border-radius: 50%;
  color: rgba(255,255,255,.7);
  text-align: center;
  transform: rotate(9deg);
}

.home-stamp::before { content: ''; position: absolute; inset: 7px; border: 1px dashed currentColor; border-radius: 50%; }
.home-stamp span, .home-stamp b { display: block; position: relative; }
.home-stamp span { font-family: var(--display); font-size: 1.75rem; }
.home-stamp b { font-size: .65rem; letter-spacing: .25em; }

.sound-button, .pause-button, .back-button {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(19, 37, 26, 0.78);
  color: #fff;
  box-shadow: 0 5px 18px rgba(0,0,0,.2);
}

.sound-button { position: absolute; z-index: 30; top: max(18px, env(safe-area-inset-top)); right: max(18px, env(safe-area-inset-right)); font-size: 1.2rem; }
.sound-button .sound-off { display: none; }
.sound-button[aria-pressed="true"] .sound-on { display: none; }
.sound-button[aria-pressed="true"] .sound-off { display: inline; }

.panel-screen { background: rgba(10, 28, 16, 0.66); backdrop-filter: blur(8px); }
.panel-shell { width: min(1100px, 100%); max-height: 92vh; overflow: auto; padding: clamp(20px, 3vw, 42px); border: 1px solid rgba(255,255,255,.55); border-radius: 28px; background: var(--paper); box-shadow: var(--shadow); }

.panel-heading { display: grid; grid-template-columns: 56px 1fr auto; gap: 18px; align-items: center; margin-bottom: 28px; }
.panel-heading .eyebrow { color: var(--leaf); margin-bottom: 4px; }
.panel-heading h2, .modal-card h2 { margin: 0; font-family: var(--display); font-size: clamp(2.25rem, 5vw, 4.4rem); line-height: .95; text-transform: uppercase; letter-spacing: .01em; }
.back-button { background: var(--ink); }
.total-stars { display: flex; align-items: baseline; gap: 4px; padding: 10px 16px; border-radius: 999px; background: var(--ink); color: white; }
.total-stars span { color: #ffc63c; }
.total-stars strong { font-size: 1.3rem; }
.total-stars small { opacity: .65; }

.map-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 15px; }
.map-card {
  position: relative;
  min-height: 340px;
  overflow: hidden;
  padding: 0;
  border-radius: 20px;
  background: var(--map-color, #5b9c4c);
  color: #fff;
  text-align: left;
  box-shadow: 0 9px 24px rgba(20, 30, 23, .16);
}

.map-card::before, .map-card::after { content: ''; position: absolute; pointer-events: none; }
.map-card::before { inset: 0; background: linear-gradient(180deg, transparent 5%, rgba(5,17,9,.1) 40%, rgba(5,17,9,.93) 100%); }
.map-card::after { width: 160px; height: 160px; top: -55px; right: -35px; border: 18px solid rgba(255,255,255,.11); border-radius: 50%; }
.map-card-art { position: absolute; inset: 0; overflow: hidden; }
.map-card-art i { position: absolute; display: block; border-radius: 50%; background: var(--accent); box-shadow: inset -12px -14px 0 rgba(0,0,0,.13); }
.map-card-art i:nth-child(1) { width: 94px; height: 94px; left: 14%; top: 15%; }
.map-card-art i:nth-child(2) { width: 58px; height: 110px; right: 13%; top: 9%; border-radius: 45% 45% 55% 55%; transform: rotate(25deg); background: var(--accent2); }
.map-card-art i:nth-child(3) { width: 70px; height: 70px; right: 28%; top: 39%; background: var(--accent3); }
.map-card-copy { position: absolute; z-index: 2; left: 20px; right: 20px; bottom: 20px; }
.map-number { display: inline-block; margin-bottom: 8px; opacity: .65; font-size: .7rem; font-weight: 900; letter-spacing: .18em; text-transform: uppercase; }
.map-card h3 { margin: 0 0 6px; font-family: var(--display); font-size: 1.7rem; line-height: .95; text-transform: uppercase; }
.map-card p { margin: 0 0 14px; color: rgba(255,255,255,.72); font-size: .78rem; }
.map-meta { display: flex; justify-content: space-between; align-items: center; }
.map-stars { color: rgba(255,255,255,.3); letter-spacing: .08em; }
.map-stars .earned { color: #ffd145; filter: drop-shadow(0 2px 2px rgba(0,0,0,.3)); }
.map-best { font-size: .7rem; font-weight: 800; text-transform: uppercase; }
.map-card:disabled { cursor: not-allowed; filter: grayscale(.55) brightness(.55); }
.lock-chip { position: absolute; z-index: 3; top: 14px; left: 14px; padding: 8px 10px; border-radius: 999px; background: rgba(12,20,15,.82); font-size: .68rem; font-weight: 900; letter-spacing: .09em; text-transform: uppercase; }
.panel-footer { display: flex; justify-content: space-between; gap: 20px; align-items: center; margin-top: 22px; font-size: .78rem; color: #5b695f; }
.panel-footer p { margin: 0; }
.text-button { padding: 8px; background: transparent; color: #9b3b31; font-size: .76rem; font-weight: 900; text-decoration: underline; text-underline-offset: 3px; }

.hud { position: absolute; z-index: 9; inset: max(16px, env(safe-area-inset-top)) max(74px, calc(env(safe-area-inset-right) + 58px)) auto max(16px, env(safe-area-inset-left)); display: grid; grid-template-columns: 1fr minmax(180px, 340px) 1fr; align-items: start; pointer-events: none; color: #fff; text-shadow: 0 2px 6px rgba(0,0,0,.55); }
.hud-stat span { display: block; margin-bottom: 2px; font-size: .68rem; font-weight: 900; letter-spacing: .18em; text-transform: uppercase; opacity: .7; }
.hud-stat strong { font-family: var(--display); font-size: clamp(1.8rem, 4vw, 3.3rem); letter-spacing: .04em; }
.score-stat { justify-self: start; }
.lives-stat { justify-self: end; text-align: right; }
.lives-stat strong { color: #ff6451; font-family: var(--body); font-size: clamp(1.3rem, 2.6vw, 2.2rem); letter-spacing: .1em; }
.hud-center { display: grid; grid-template-columns: 1fr auto; gap: 3px 10px; align-items: center; text-align: center; }
.hud-center p { grid-column: 1 / -1; margin: 0; font-size: .68rem; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; }
.hud-center strong { min-width: 25px; font-family: var(--display); font-size: 1.4rem; }
.timer-track { height: 9px; overflow: hidden; border: 2px solid rgba(255,255,255,.8); border-radius: 99px; background: rgba(0,0,0,.25); }
.timer-track i { display: block; width: 100%; height: 100%; border-radius: inherit; background: var(--lime); transform-origin: left; }
.pause-button { position: fixed; top: max(18px, env(safe-area-inset-top)); right: max(18px, env(safe-area-inset-right)); pointer-events: auto; font-weight: 900; }
.hud ~ .sound-button { display: none; }
.combo-badge { position: absolute; top: 82px; left: 50%; padding: 7px 14px; border-radius: 9px; background: var(--orange); color: #fff; font-family: var(--display); font-size: 1.5rem; letter-spacing: .04em; opacity: 0; transform: translate(-50%, 15px) rotate(-4deg) scale(.7); transition: opacity 160ms ease, transform 160ms cubic-bezier(.2,.9,.2,1.3); }
.combo-badge.is-visible { opacity: 1; transform: translate(-50%, 0) rotate(-4deg) scale(1); }

.modal-screen { z-index: 24; background: rgba(7, 20, 11, .72); backdrop-filter: blur(10px); }
.modal-card { width: min(470px, 94vw); padding: clamp(26px, 5vw, 46px); border: 1px solid rgba(255,255,255,.7); border-radius: 28px; background: var(--paper); text-align: center; box-shadow: var(--shadow); }
.modal-card .eyebrow { color: var(--leaf); }
.modal-card > .primary-button, .modal-card > .secondary-button { display: block; width: 100%; margin-top: 17px; }
.knife-mark { font-size: 3rem; line-height: .7; color: var(--orange); }
.results-card { width: min(610px, 95vw); }
.result-stars { display: flex; justify-content: center; gap: 12px; margin: 18px 0 10px; }
.result-stars span { color: #b8b29b; font-size: clamp(2.5rem, 8vw, 4.6rem); line-height: 1; transform: scale(.2) rotate(-35deg); opacity: .25; }
.result-stars span.earned { color: #ffc52f; opacity: 1; animation: star-in 580ms cubic-bezier(.17,.89,.2,1.4) forwards; animation-delay: var(--delay); filter: drop-shadow(0 5px 0 #d88721); }
@keyframes star-in { to { transform: scale(1) rotate(0); } }
.result-score { display: grid; place-items: center; margin: 8px auto 18px; }
.result-score > span { color: #657067; font-size: .68rem; font-weight: 900; letter-spacing: .2em; text-transform: uppercase; }
.result-score > strong { font-family: var(--display); font-size: 4.5rem; line-height: .95; color: var(--leaf); }
.result-score small { color: #657067; }
.result-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0 0 24px; }
.result-grid div { padding: 12px 6px; border-radius: 12px; background: rgba(42,78,49,.08); }
.result-grid dt { color: #657067; font-size: .66rem; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; }
.result-grid dd { margin: 3px 0 0; font-family: var(--display); font-size: 1.7rem; }
.result-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.result-actions button { padding-inline: 12px; font-size: .74rem; }

.final-screen { z-index: 23; overflow: hidden; color: var(--cream); text-align: center; background: radial-gradient(circle, rgba(74,123,51,.15), rgba(5,17,9,.7)); }
.final-copy { position: relative; z-index: 2; }
.final-copy h2 { margin: 0; font-family: var(--display); font-size: clamp(4.5rem, 14vw, 10rem); line-height: .82; color: var(--lime); letter-spacing: -.03em; text-shadow: 0 9px 0 #254e2b, 0 18px 60px #000; }
.final-message { margin: 22px 0; font-size: clamp(1.15rem, 2.3vw, 1.7rem); }
.final-message strong { color: var(--lime); }
.final-totals { display: flex; justify-content: center; gap: 50px; margin: 30px auto; }
.final-totals div { min-width: 145px; }
.final-totals span { display: block; margin-bottom: 5px; font-size: .7rem; font-weight: 900; letter-spacing: .13em; text-transform: uppercase; opacity: .6; }
.final-totals strong { font-family: var(--display); font-size: 2.5rem; }
.final-totals i { color: #ffc52f; font-style: normal; }
.final-actions { display: flex; justify-content: center; gap: 14px; }
.final-rays { position: absolute; width: 90vmax; aspect-ratio: 1; background: repeating-conic-gradient(from 0deg, rgba(216,240,77,.08) 0 8deg, transparent 8deg 18deg); animation: rotate-rays 45s linear infinite; }
@keyframes rotate-rays { to { transform: rotate(360deg); } }

.toast { position: absolute; z-index: 35; left: 50%; bottom: 17%; max-width: 80vw; padding: 10px 18px; border-radius: 999px; background: rgba(19,37,26,.9); color: #fff; font-weight: 900; letter-spacing: .05em; text-transform: uppercase; opacity: 0; pointer-events: none; transform: translate(-50%, 18px) scale(.85); transition: 180ms ease; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0) scale(1); }
.loading { position: absolute; z-index: 50; inset: 0; display: flex; gap: 12px; align-items: center; justify-content: center; background: #13251a; color: var(--cream); font-weight: 800; letter-spacing: .08em; }
.loading span { width: 22px; height: 22px; border: 3px solid rgba(255,255,255,.2); border-top-color: var(--lime); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.fatal-error { position: absolute; z-index: 60; inset: 20px; place-content: center; text-align: center; background: #3b1515; color: #fff; }
.fatal-error strong, .fatal-error span { display: block; margin: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }

@media (max-width: 850px) {
  .map-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .map-card { min-height: 250px; }
  .panel-shell { max-height: 94dvh; }
  .home-screen { background: linear-gradient(90deg, rgba(10,28,16,.86), rgba(10,28,16,.3)); }
  .home-copy { margin-left: 3vw; }
}

@media (max-width: 560px) {
  .screen { padding: 14px; }
  .home-screen { align-items: end; padding-bottom: max(48px, env(safe-area-inset-bottom)); background: linear-gradient(0deg, rgba(10,28,16,.92) 0%, rgba(10,28,16,.2) 80%); }
  .home-copy { width: 92vw; margin: 0 auto; }
  h1 { font-size: clamp(4.5rem, 25vw, 7rem); }
  .tagline { margin: 18px 0; font-size: .95rem; }
  .gesture-hint { margin-top: 21px; }
  .home-stamp { display: none; }
  .panel-shell { padding: 18px; border-radius: 20px; }
  .panel-heading { grid-template-columns: 45px 1fr; gap: 12px; }
  .panel-heading h2 { font-size: 2rem; }
  .total-stars { grid-column: 2; justify-self: start; padding: 6px 11px; }
  .map-grid { gap: 10px; }
  .map-card { min-height: 218px; }
  .map-card-copy { left: 14px; right: 14px; bottom: 14px; }
  .map-card h3 { font-size: 1.28rem; }
  .map-card p { display: none; }
  .map-meta { display: block; }
  .map-best { display: block; margin-top: 4px; }
  .panel-footer { display: block; text-align: center; }
  .panel-footer p { margin-bottom: 8px; }
  .hud { inset-inline: 12px 62px; grid-template-columns: 1fr 105px 1fr; }
  .hud-center { order: 2; }
  .hud-center p { display: none; }
  .hud-stat strong { font-size: 1.75rem; }
  .hud-stat span { font-size: .55rem; }
  .lives-stat strong { font-size: 1.15rem; }
  .result-actions { grid-template-columns: 1fr 1fr; }
  .result-actions .primary-button { grid-column: 1 / -1; grid-row: 1; }
  .final-totals { gap: 20px; }
  .final-actions { flex-direction: column; width: min(280px, 80vw); margin: auto; }
}

@media (max-height: 560px) and (orientation: landscape) {
  .home-copy { transform: scale(.82); transform-origin: left center; }
  .panel-shell { padding: 16px 24px; }
  .panel-heading { margin-bottom: 12px; }
  .map-card { min-height: 190px; }
  .modal-card { padding: 18px 28px; }
  .result-stars { margin: 8px 0; }
  .result-score > strong { font-size: 3rem; }
  .result-grid { margin-bottom: 12px; }
}

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