:root {
  color-scheme: dark;
  --page-bg: #120b18;
  --page-tint: #180e20;
  --surface: #201228;
  --surface-soft: #2d1836;
  --text: #ffe9f6;
  --text-soft: #d8b9d0;
  --accent: #ff4fa3;
  --accent-soft: #ff82c2;
  --wine: #6d35a3;
  --wine-soft: #8649b8;
  --terracotta: #a855f7;
  --sand: #3a1d46;
  --border: rgba(255, 130, 194, 0.22);
  --border-strong: rgba(168, 85, 247, 0.5);
  --focus: #ff82c2;
  --poster-shadow: 12px 14px 0 rgba(109, 53, 163, 0.25), 0 28px 70px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--page-bg);
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 12% 16%, rgba(168, 85, 247, 0.16), transparent 27rem),
    radial-gradient(circle at 88% 82%, rgba(255, 79, 163, 0.11), transparent 30rem),
    repeating-linear-gradient(7deg, rgba(255, 233, 246, 0.018) 0 1px, transparent 1px 5px),
    var(--page-bg);
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image:
    radial-gradient(circle, rgba(255, 130, 194, 0.09) 0 0.7px, transparent 0.9px),
    radial-gradient(circle, rgba(168, 85, 247, 0.07) 0 0.8px, transparent 1px);
  background-position: 0 0, 13px 17px;
  background-size: 19px 23px, 29px 31px;
  content: "";
  opacity: 0.65;
  pointer-events: none;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

button:focus-visible,
a:focus-visible,
canvas:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 20;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0.75rem 1rem;
  color: var(--text);
  background: var(--wine);
  font-weight: 800;
  transform: translateY(-160%);
}

.skip-link:focus {
  transform: translateY(0);
}

.site-header,
.hero,
footer {
  width: min(1380px, calc(100% - 3rem));
  margin-inline: auto;
}

.site-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-height: 84px;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  justify-self: start;
  gap: 0.75rem;
  min-height: 44px;
  color: var(--accent-soft);
  font-size: 0.95rem;
  font-weight: 950;
  letter-spacing: 0.26em;
  text-decoration: none;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 2px solid var(--terracotta);
  color: var(--page-bg);
  background: var(--accent);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1rem;
  letter-spacing: 0;
  box-shadow: 3px 3px 0 var(--terracotta);
  transform: rotate(-3deg);
}

.chapter,
.mini-goal {
  margin: 0;
  color: var(--text-soft);
  font-size: 0.68rem;
  font-weight: 850;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.chapter {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.chapter span {
  width: 20px;
  height: 1px;
  background: var(--terracotta);
}

.mini-goal {
  display: grid;
  justify-self: end;
  gap: 0.15rem;
  text-align: right;
}

.mini-goal strong {
  color: var(--text);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
}

.hero {
  display: grid;
  grid-template-columns: minmax(400px, 0.44fr) minmax(0, 1fr);
  gap: clamp(2rem, 3vw, 3rem);
  align-items: center;
  min-height: calc(100vh - 148px);
  padding-block: clamp(2rem, 4vw, 4rem);
}

.story-panel {
  position: relative;
  min-width: 0;
}

.story-intro,
.mission-details {
  min-width: 0;
}

.story-panel::before {
  position: absolute;
  top: -3.5rem;
  left: -3.5rem;
  z-index: -1;
  width: 17rem;
  height: 17rem;
  border: 1px solid rgba(168, 85, 247, 0.24);
  content: "";
  transform: rotate(7deg);
  box-shadow: 2rem 2rem 0 rgba(255, 79, 163, 0.04), 4rem 4rem 0 rgba(168, 85, 247, 0.035);
}

h1 {
  max-width: 9ch;
  margin: 0;
  color: var(--text);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(3.25rem, 4.8vw, 4rem);
  font-weight: 900;
  letter-spacing: -0.045em;
  line-height: 0.8;
  text-wrap: balance;
  text-shadow: 3px 3px 0 rgba(168, 85, 247, 0.32);
}

h1 span {
  display: block;
  margin-bottom: 0.2rem;
  color: var(--terracotta);
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: 0.3em;
  font-weight: 950;
  letter-spacing: 0.16em;
  line-height: 1.2;
  text-shadow: none;
}

.lead {
  max-width: 34rem;
  margin: 1.5rem 0 0;
  color: var(--text-soft);
  font-size: clamp(0.92rem, 1.15vw, 1.04rem);
  line-height: 1.7;
}

.lead strong {
  color: var(--text);
}

.mission-card {
  position: relative;
  margin-top: 1.75rem;
  padding: 1rem 1.1rem;
  border: 1px solid var(--border-strong);
  background:
    linear-gradient(rgba(32, 18, 40, 0.94), rgba(32, 18, 40, 0.94)),
    repeating-linear-gradient(0deg, transparent 0 5px, rgba(255, 130, 194, 0.06) 5px 6px);
  box-shadow: 5px 5px 0 rgba(109, 53, 163, 0.28);
}

.mission-card::before,
.mission-card::after {
  position: absolute;
  top: -5px;
  width: 27px;
  height: 10px;
  background: rgba(255, 130, 194, 0.6);
  content: "";
  transform: rotate(-5deg);
}

.mission-card::before { left: 14px; }
.mission-card::after { right: 14px; transform: rotate(6deg); }

.mission-heading {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.6rem;
  font-size: 0.66rem;
  font-weight: 950;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.mission-heading > span,
.mission-card p {
  color: var(--text-soft);
}

.mission-heading strong span {
  color: var(--accent);
}

progress {
  display: block;
  width: 100%;
  height: 8px;
  overflow: hidden;
  border: 1px solid rgba(255, 130, 194, 0.22);
  border-radius: 0;
  background: var(--surface-soft);
}

progress::-webkit-progress-bar { background: var(--surface-soft); }
progress::-webkit-progress-value { background: linear-gradient(90deg, var(--terracotta), var(--accent)); }
progress::-moz-progress-bar { background: linear-gradient(90deg, var(--terracotta), var(--accent)); }

.mission-card p {
  margin: 0.65rem 0 0;
  font-size: 0.72rem;
  line-height: 1.5;
}

.key-guide {
  display: grid;
  margin: 1.25rem 0 0;
}

.key-guide div {
  display: flex;
  justify-content: space-between;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.68rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.key-guide dt {
  color: var(--accent-soft);
  font-weight: 900;
}

.key-guide dd {
  margin: 0;
  color: var(--text-soft);
}

.game-frame {
  position: relative;
  min-width: 0;
  padding: 8px;
  border: 2px solid var(--wine);
  overflow: hidden;
  background: var(--sand);
  box-shadow: var(--poster-shadow);
}

.game-frame::before {
  position: absolute;
  inset: 3px;
  z-index: 2;
  border: 1px solid rgba(255, 130, 194, 0.38);
  content: "";
  pointer-events: none;
}

.frame-topbar {
  display: flex;
  justify-content: space-between;
  padding: 0.72rem 0.85rem;
  border-bottom: 1px solid var(--border-strong);
  background: var(--surface);
}

.frame-topbar p {
  margin: 0;
  color: var(--text-soft);
  font-size: 0.6rem;
  font-weight: 900;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.live-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 0.4rem;
  border: 1px solid var(--wine);
  border-radius: 50%;
  background: var(--terracotta);
  animation: pulse 1.6s ease-in-out infinite;
}

.game-play-area {
  display: grid;
}

.stage-wrap,
.game-messages {
  grid-area: 1 / 1;
}

.stage-wrap {
  position: relative;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  background: var(--surface-soft);
}

.game-messages {
  z-index: 3;
  display: grid;
  min-width: 0;
  pointer-events: none;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
}

.hud {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid rgba(168, 85, 247, 0.34);
  background: rgba(18, 11, 24, 0.9);
  pointer-events: none;
}

.hud-cell {
  display: grid;
  gap: 0.12rem;
  padding: 0.65rem 0.85rem;
}

.hud-cell + .hud-cell {
  border-left: 1px solid rgba(168, 85, 247, 0.24);
}

.hud-cell span {
  color: var(--text-soft);
  font-size: 0.52rem;
  font-weight: 950;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.hud-cell strong {
  color: var(--text);
  font-size: 0.74rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hud-courage strong {
  color: var(--accent);
  letter-spacing: 0.2em;
}

.game-overlay {
  grid-area: 1 / 1;
  display: grid;
  place-items: center;
  padding: 1rem;
  overflow-y: auto;
  background:
    linear-gradient(90deg, rgba(18, 11, 24, 0.88), rgba(109, 53, 163, 0.34)),
    repeating-linear-gradient(135deg, transparent 0 7px, rgba(255, 233, 246, 0.04) 7px 8px);
  pointer-events: auto;
}

.is-hidden,
.game-overlay.is-hidden {
  display: none !important;
}

.overlay-card {
  position: relative;
  z-index: 2;
  width: min(410px, 94%);
  padding: clamp(1.2rem, 3vw, 2rem);
  border: 2px solid var(--wine);
  background: var(--surface);
  box-shadow: 7px 7px 0 rgba(109, 53, 163, 0.42);
}

.overlay-card.compact {
  max-width: 320px;
  text-align: center;
}

.overlay-kicker {
  color: var(--accent);
  font-size: 0.6rem;
  font-weight: 950;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.overlay-card h2 {
  margin: 0.45rem 0 0.65rem;
  color: var(--text);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.8rem, 3.5vw, 2.8rem);
  letter-spacing: -0.02em;
  line-height: 0.96;
  text-wrap: balance;
}

.overlay-card p {
  margin: 0 0 1rem;
  color: var(--text-soft);
  font-size: 0.82rem;
  line-height: 1.5;
}

.primary-button,
.jump-button,
.direction-button,
.icon-button {
  min-height: 44px;
  border: 0;
  color: var(--text);
  font-size: 0.68rem;
  font-weight: 950;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}

.primary-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0.72rem 0.9rem;
  border: 2px solid var(--wine);
  transition: filter 160ms ease, transform 160ms ease;
}

.primary-button {
  color: var(--page-bg);
  background: var(--accent);
  box-shadow: 4px 4px 0 var(--sand);
}

.primary-button:hover {
  filter: brightness(1.08);
  transform: translateY(-2px);
}

.celebration-confetti {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  pointer-events: none;
}

.confetti-piece {
  position: absolute;
  top: -18%;
  font-size: 1.15rem;
  animation: confetti-fall 2.7s cubic-bezier(0.2, 0.7, 0.3, 1) forwards;
}

.confetti-piece:nth-child(12n + 1) { left: 3%; animation-delay: 0.04s; }
.confetti-piece:nth-child(12n + 2) { left: 11%; animation-delay: 0.32s; }
.confetti-piece:nth-child(12n + 3) { left: 19%; animation-delay: 0.16s; }
.confetti-piece:nth-child(12n + 4) { left: 28%; animation-delay: 0.46s; }
.confetti-piece:nth-child(12n + 5) { left: 37%; animation-delay: 0.08s; }
.confetti-piece:nth-child(12n + 6) { left: 45%; animation-delay: 0.38s; }
.confetti-piece:nth-child(12n + 7) { left: 54%; animation-delay: 0.22s; }
.confetti-piece:nth-child(12n + 8) { left: 63%; animation-delay: 0.52s; }
.confetti-piece:nth-child(12n + 9) { left: 71%; animation-delay: 0.12s; }
.confetti-piece:nth-child(12n + 10) { left: 79%; animation-delay: 0.42s; }
.confetti-piece:nth-child(12n + 11) { left: 87%; animation-delay: 0.26s; }
.confetti-piece:nth-child(12n) { left: 95%; animation-delay: 0.56s; }
.confetti-piece:nth-child(n + 13) { animation-duration: 3.1s; }
.confetti-piece:nth-child(n + 25) { animation-duration: 3.5s; }

.touch-controls {
  display: grid;
  grid-template-columns: 1fr 58px 58px;
  gap: 1px;
  border-top: 1px solid var(--border-strong);
  background: var(--wine);
}

.jump-button,
.direction-button,
.icon-button {
  min-height: 56px;
  background: var(--surface);
}

.jump-button:hover,
.direction-button:hover,
.icon-button:hover {
  background: var(--surface-soft);
}

.jump-button span {
  display: inline-grid;
  place-items: center;
  width: 27px;
  height: 27px;
  margin-right: 0.5rem;
  border: 1px solid var(--accent);
  border-radius: 50%;
  color: var(--accent);
}

.descent-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  min-width: 0;
  gap: 1px;
  background: var(--wine);
}

.direction-button {
  min-width: 0;
  padding-inline: 0.55rem;
  touch-action: none;
}

.direction-button span {
  color: var(--accent);
  font-size: 1rem;
}

footer {
  display: flex;
  justify-content: space-between;
  padding-block: 1rem 1.75rem;
  border-top: 1px solid var(--border);
}

footer p {
  margin: 0;
  color: var(--text-soft);
  font-size: 0.58rem;
  font-weight: 850;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes pulse {
  50% { opacity: 0.35; }
}

@keyframes confetti-fall {
  0% { transform: translateY(-1rem) rotate(0); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translateY(35rem) rotate(540deg); }
}

@media (min-width: 681px) and (max-width: 1119px) {
  .hero {
    grid-template-columns: 1fr;
    gap: 2.25rem;
    max-width: 980px;
    min-height: auto;
  }

  .story-panel {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 2rem;
    align-items: end;
  }

  .mission-card {
    margin-top: 0;
  }

  h1 { font-size: clamp(3rem, 6.5vw, 4rem); }
}

@media (max-width: 680px) {
  .site-header,
  .hero,
  footer {
    width: min(100% - 1.25rem, 1380px);
  }

  .site-header {
    grid-template-columns: 1fr auto;
    min-height: 70px;
  }

  .chapter { display: none; }
  .mini-goal > span { display: none; }

  .hero {
    grid-template-columns: 1fr;
    min-height: auto;
    gap: 1.75rem;
    padding-block: 1.75rem 2.5rem;
  }

  .story-panel { display: block; }
  .story-panel::before { display: none; }

  h1 {
    max-width: none;
    font-size: clamp(3rem, 15vw, 5rem);
  }

  .lead {
    margin-top: 1.2rem;
    line-height: 1.55;
  }

  .mission-card { margin-top: 1.4rem; }

  .game-frame {
    margin-inline: -0.625rem;
    padding: 5px;
    border-right: 0;
    border-left: 0;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  }

  .frame-topbar {
    gap: 0.75rem;
    padding: 0.55rem 0.65rem;
  }

  .frame-topbar p:last-child {
    text-align: right;
  }

  .hud-cell { padding: 0.48rem 0.5rem; }
  .hud-cell span { font-size: 0.43rem; }
  .hud-cell strong { font-size: 0.59rem; }

  .game-play-area {
    display: block;
  }

  .game-messages {
    display: block;
  }

  .game-overlay {
    padding: 0;
    overflow: visible;
    background: none;
  }

  .overlay-card {
    width: 100%;
    padding: 1rem;
    border: 0;
    border-top: 1px solid var(--border-strong);
    box-shadow: none;
  }

  .overlay-card.compact { max-width: none; }

  .overlay-kicker { font-size: 0.56rem; }

  .overlay-card h2 {
    margin-block: 0.3rem 0.5rem;
    font-size: clamp(1.5rem, 7vw, 2rem);
  }

  .overlay-card p {
    margin-bottom: 0.75rem;
    font-size: 0.76rem;
    line-height: 1.45;
  }

  .primary-button {
    min-height: 44px;
    padding: 0.65rem 0.75rem;
    font-size: 0.62rem;
  }

  footer {
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    text-align: center;
  }
}

@media (max-width: 680px) and (orientation: landscape) {
  .stage-wrap,
  .game-messages {
    width: min(100%, 120svh);
    margin-inline: auto;
  }
}

@media (max-width: 340px) {
  .brand { font-size: 0.82rem; }
  .mini-goal strong { font-size: 0.68rem; }
}

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