:root {
  color-scheme: dark;
  --ink: #f8efc6;
  --ink-soft: rgba(248, 239, 198, 0.72);
  --night: #0a2019;
  --leaf: #123126;
  --sun: #ffe989;
  --orange: #f4aa45;
  --line: rgba(255, 241, 179, 0.34);
  --ease: cubic-bezier(.22, .72, .18, 1);
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--night);
}

body {
  color: var(--ink);
  font-family: Georgia, 'Times New Roman', serif;
}

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

button {
  min-height: 48px;
  border: 1px solid rgba(255, 241, 179, 0.62);
  border-radius: 999px;
  padding: 0.8rem 1.2rem;
  color: #11251d;
  background: var(--sun);
  font: 700 0.78rem/1.1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 180ms var(--ease), background 180ms var(--ease), color 180ms var(--ease);
}

button:hover { transform: translateY(-2px); }
button:focus-visible, canvas:focus-visible { outline: 3px solid #fff; outline-offset: 4px; }
button.quiet { color: var(--ink); background: rgba(7, 28, 21, 0.38); backdrop-filter: blur(12px); }

.experience {
  position: relative;
  width: 100vw;
  height: 100svh;
  min-height: 560px;
  isolation: isolate;
  overflow: hidden;
}

#field {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.grain {
  position: absolute;
  inset: -25%;
  z-index: 1;
  pointer-events: none;
  opacity: 0.18;
  mix-blend-mode: soft-light;
  background-image:
    linear-gradient(125deg, rgba(9, 33, 24, 0.15), rgba(255, 228, 128, 0.08)),
    url('canopy-texture.webp');
  background-position: center;
  background-size: cover;
  filter: saturate(.72) contrast(1.12);
}

.mast {
  position: absolute;
  z-index: 4;
  top: max(1rem, env(safe-area-inset-top));
  left: clamp(1rem, 3.2vw, 3rem);
  right: clamp(1rem, 3.2vw, 3rem);
  display: flex;
  justify-content: space-between;
  gap: 2rem;
  color: rgba(255, 244, 202, 0.62);
  font: 600 0.66rem/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  pointer-events: none;
}

.intro, .ending {
  position: absolute;
  z-index: 5;
  left: clamp(1.25rem, 6vw, 6.5rem);
  top: 50%;
  width: min(42rem, calc(100vw - 2.5rem));
  transform: translateY(-48%);
  text-shadow: 0 2px 24px rgba(0, 0, 0, 0.6);
}

.intro[hidden], .ending[hidden], .story[hidden], .field-actions[hidden], .gesture-hint[hidden] { display: none; }

.eyebrow, .chapter {
  margin: 0 0 0.7rem;
  color: var(--sun);
  font: 700 0.7rem/1.25 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

h1, h2, p { text-wrap: balance; }

h1 {
  margin: 0;
  max-width: 11ch;
  font-size: clamp(3.1rem, 8.4vw, 8.5rem);
  line-height: 0.82;
  letter-spacing: -0.065em;
  font-weight: 500;
}

h1 em, .ending h2 em { color: var(--sun); font-weight: 400; }

.lede {
  margin: 1.4rem 0 1.35rem;
  max-width: 34rem;
  color: rgba(255, 247, 218, 0.82);
  font-size: clamp(1rem, 1.8vw, 1.3rem);
  line-height: 1.45;
}

.micro {
  margin: 0.9rem 0 0;
  color: rgba(255, 247, 218, 0.56);
  font: 0.68rem/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.story {
  position: absolute;
  z-index: 4;
  top: clamp(4rem, 12vh, 8rem);
  left: clamp(1.2rem, 5vw, 5rem);
  width: min(34rem, calc(100vw - 2.4rem));
  pointer-events: none;
  text-shadow: 0 2px 24px rgba(0, 0, 0, 0.72);
  transition: opacity 220ms var(--ease), transform 220ms var(--ease);
}

.story h2, .ending h2 {
  margin: 0;
  font-size: clamp(2.2rem, 5.3vw, 5.8rem);
  line-height: 0.94;
  letter-spacing: -0.045em;
  font-weight: 500;
}

.scene-copy, .ending > p:not(.eyebrow) {
  margin: 1rem 0 0;
  max-width: 28rem;
  color: rgba(255, 247, 218, 0.8);
  font-size: clamp(0.95rem, 1.5vw, 1.18rem);
  line-height: 1.45;
}

.depth-marks {
  position: absolute;
  z-index: 5;
  right: clamp(1rem, 3vw, 3rem);
  top: 50%;
  display: grid;
  gap: 1.05rem;
  width: 5rem;
  margin: 0;
  padding: 0;
  transform: translateY(-50%);
  list-style: none;
  pointer-events: none;
}

.depth-marks li {
  position: relative;
  height: 1px;
  background: rgba(255, 244, 202, 0.25);
  transition: background 260ms var(--ease), transform 260ms var(--ease);
}

.depth-marks li::before {
  content: '';
  position: absolute;
  right: 0;
  top: -3px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(255, 244, 202, 0.45);
}

.depth-marks span {
  position: absolute;
  right: 0.85rem;
  top: -0.45rem;
  color: rgba(255, 244, 202, 0.42);
  font: 0.6rem/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.depth-marks li.current { transform: scaleX(1.25); transform-origin: right; background: var(--sun); }
.depth-marks li.current::before { background: var(--sun); box-shadow: 0 0 18px var(--sun); }
.depth-marks li.current span { color: var(--sun); }

.field-actions {
  position: absolute;
  z-index: 6;
  left: clamp(1.2rem, 5vw, 5rem);
  bottom: max(1.1rem, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.gesture-hint {
  position: absolute;
  z-index: 5;
  right: clamp(1rem, 3vw, 3rem);
  bottom: max(1.4rem, env(safe-area-inset-bottom));
  margin: 0;
  color: rgba(255, 244, 202, 0.66);
  font: 0.67rem/1.35 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  pointer-events: none;
}

.inversion-cue {
  position: absolute;
  z-index: 6;
  right: clamp(1rem, 3vw, 3rem);
  bottom: max(1.4rem, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
  width: min(22rem, calc(100vw - 2rem));
  padding: 0.7rem;
  border: 1px solid rgba(255, 239, 167, 0.5);
  border-radius: 0.85rem;
  background: rgba(3, 20, 14, 0.82);
  box-shadow: 0 14px 42px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(14px);
  pointer-events: none;
}

.inversion-cue[hidden] { display: none; }
.inversion-cue span { display: grid; gap: 0.25rem; padding: 0.25rem 0.45rem; }
.inversion-cue span + span { border-left: 1px solid rgba(255, 239, 167, 0.24); }
.inversion-cue small {
  color: rgba(255, 244, 202, 0.58);
  font: 600 0.58rem/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.inversion-cue strong {
  color: var(--sun);
  font: 700 0.76rem/1.15 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.ending { width: min(36rem, calc(100vw - 2.5rem)); }
.ending button { margin-top: 1.25rem; }

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

@media (max-width: 680px) {
  .experience { min-height: 480px; }
  .mast span:last-child { display: none; }
  .intro { top: 47%; }
  h1 { font-size: clamp(3rem, 16vw, 5.2rem); }
  .lede { width: 92%; font-size: 0.98rem; }
  .story { top: max(4.1rem, calc(env(safe-area-inset-top) + 3rem)); width: min(24rem, calc(100vw - 4.5rem)); }
  .story h2, .ending h2 { font-size: clamp(2.25rem, 11vw, 4rem); }
  .depth-marks { right: 0.8rem; width: 2.4rem; }
  .depth-marks span { display: none; }
  .field-actions { right: 1rem; justify-content: flex-start; flex-wrap: wrap; }
  .field-actions button { min-height: 46px; padding-inline: 1rem; }
  .gesture-hint { right: 1rem; bottom: 5.4rem; max-width: 12rem; text-align: right; }
  .inversion-cue {
    top: 52%;
    right: 1rem;
    bottom: auto;
    width: 13.5rem;
    grid-template-columns: 1fr;
  }
  .inversion-cue span + span { border-top: 1px solid rgba(255, 239, 167, 0.24); border-left: 0; }
  .ending { top: 48%; }
}

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