:root {
  --cream: #f4efe4;
  --ink: #1c1812;
  --moss: #3d4a28;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* {
  box-sizing: border-box;
}

html,
body,
#app {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #1a2214;
  overscroll-behavior: none;
}

/* Mobile browser chrome slides away; dvh follows it, vh does not. */
@supports (height: 100dvh) {
  html,
  body,
  #app {
    height: 100dvh;
  }
}

#app {
  position: relative;
}

/* Draws the eye down the path and keeps the poem readable against a bright
   canopy. Sits under the text layer so it never dims the words themselves. */
#app::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  background: radial-gradient(
    ellipse at 50% 46%,
    rgba(18, 14, 6, 0) 46%,
    rgba(18, 14, 6, 0.07) 76%,
    rgba(14, 11, 5, 0.24) 100%
  );
}

body {
  font-family: "Cormorant Garamond", "Palatino Linotype", Palatino, serif;
  color: var(--cream);
  cursor: default;
}

#forest {
  display: block;
  width: 100%;
  height: 100%;
  cursor: default;
  /* Without this the browser takes the drag as a scroll or a pinch and you
     cannot look around on a phone at all. */
  touch-action: none;
}

.poem {
  position: absolute;
  inset: 0;
  z-index: 11;
  display: grid;
  place-items: center;
  /* Shrinking the content box from the bottom lands the centred line at 40%
     of the viewport rather than 50% -- above the horizon, in the canopy. */
  padding-bottom: 20vh;
  overflow: hidden;
  pointer-events: none;
  transition: opacity 0.45s var(--ease);
}

.veil {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background:
    radial-gradient(ellipse at 50% 40%, rgba(20, 24, 14, 0.28), rgba(8, 10, 6, 0.72) 62%),
    rgba(10, 12, 8, 0.35);
  backdrop-filter: blur(2px);
  transition: opacity 1.1s var(--ease), visibility 1.1s;
  z-index: 20;
}

/* The wood goes over to white as the walker keeps going past the last line.
   Sits above the poem and below the closing card. */
.whiteout {
  position: absolute;
  inset: 0;
  z-index: 15;
  pointer-events: none;
  background: #fbfaf6;
  opacity: 0;
}

/* The closing card lands on that white, so it reads dark on light rather than
   the cream-on-shadow of the cover. */
.veil-light {
  background: #fbfaf6;
  backdrop-filter: none;
  color: var(--ink);
}

.veil-light .start-card,
.veil-light h1 {
  color: var(--ink);
}

.veil-light .eyebrow {
  opacity: 0.55;
}

.veil-light .start-cta {
  opacity: 0.5;
}

.veil-light .start-card:focus-visible {
  outline-color: var(--ink);
}

.veil[hidden] {
  display: none;
}

.veil.is-gone {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.start-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2.6rem;
  padding: 2rem;
}

.start-card {
  appearance: none;
  background: none;
  border: 0;
  color: inherit;
  text-align: center;
  cursor: pointer;
  padding: 0.5rem 0;
  max-width: 36rem;
}

.start-card:focus-visible {
  outline: 2px solid var(--cream);
  outline-offset: 8px;
}

.eyebrow {
  margin: 0 0 0.85rem;
  font-size: 1.05rem;
  font-style: italic;
  font-weight: 400;
  letter-spacing: 0.04em;
  opacity: 0.72;
}

h1 {
  margin: 0;
  font-family: "Cormorant Garamond", serif;
  font-weight: 500;
  font-size: clamp(2.6rem, 7vw, 5.2rem);
  line-height: 0.95;
  letter-spacing: -0.02em;
}

.start-cta {
  margin: 1.6rem 0 0;
  font-size: 1.2rem;
  font-style: italic;
  letter-spacing: 0.03em;
  opacity: 0.86;
  animation: pulse 2.4s var(--ease) infinite;
}

.hint {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.8rem;
  /* Secondary to "Click to begin" -- these keys are for after the veil lifts. */
  opacity: 0.7;
}

.hint p {
  margin: 0;
  max-width: 22rem;
  font-size: 1.05rem;
  font-style: italic;
  line-height: 1.45;
  letter-spacing: 0.02em;
  text-align: center;
  text-shadow: 0 2px 16px rgba(0, 0, 0, 0.45);
}

.for-touch {
  display: none;
}

.keys {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.28rem;
}

.key-row {
  display: flex;
  gap: 0.28rem;
}

.key {
  width: 2.2rem;
  height: 2.2rem;
  display: grid;
  place-items: center;
  border: 1px solid rgba(244, 239, 228, 0.45);
  border-radius: 0.4rem;
  background: rgba(20, 22, 16, 0.42);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.25);
  font-size: 1rem;
}

.key-up {
  animation: bounce 1.4s var(--ease) infinite;
}

.audio-dock {
  position: absolute;
  top: 1.25rem;
  right: 1.25rem;
  z-index: 30;
}

/* Collapsed, the panel is padding + button on every side, so it is a true
   circle. The slider's breathing room lives in its own margin, which animates
   open with it -- putting that space in the panel's padding or gap is what
   made the resting state a lopsided oval. */
/* On the closing white the dock has to flip: redefining --cream carries the
   icon and the slider with it. */
.audio-dock.on-light {
  --cream: #1c1812;
}

.audio-dock.on-light .audio-panel {
  background: rgba(28, 24, 18, 0.06);
  border-color: rgba(28, 24, 18, 0.16);
  box-shadow: 0 6px 22px rgba(28, 24, 18, 0.08);
}

.audio-panel {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0.35rem;
  border-radius: 999px;
  background: rgba(18, 16, 12, 0.4);
  border: 1px solid rgba(244, 239, 228, 0.16);
  backdrop-filter: blur(14px);
  box-shadow: 0 6px 22px rgba(12, 14, 8, 0.28);
}

.volume-label {
  display: flex;
  align-items: center;
  flex: none;
  width: 0;
  margin: 0;
  overflow: hidden;
  opacity: 0;
  transition:
    width 0.34s var(--ease),
    margin 0.34s var(--ease),
    opacity 0.24s ease;
}

.audio-dock:hover .volume-label,
.audio-dock:focus-within .volume-label {
  width: 7rem;
  margin: 0 0.6rem 0 0.5rem;
  opacity: 1;
}

#volume {
  -webkit-appearance: none;
  appearance: none;
  flex: none;
  width: 7rem;
  height: 1rem;
  margin: 0;
  background: transparent;
  cursor: pointer;
}

#volume::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 999px;
  background: linear-gradient(
    to right,
    var(--cream) 0 var(--fill, 42%),
    rgba(244, 239, 228, 0.26) var(--fill, 42%) 100%
  );
}

#volume::-moz-range-track {
  height: 3px;
  border-radius: 999px;
  background: linear-gradient(
    to right,
    var(--cream) 0 var(--fill, 42%),
    rgba(244, 239, 228, 0.26) var(--fill, 42%) 100%
  );
}

#volume::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 0.8rem;
  height: 0.8rem;
  margin-top: -0.36rem;
  border: 0;
  border-radius: 50%;
  background: var(--cream);
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.45);
}

#volume::-moz-range-thumb {
  width: 0.8rem;
  height: 0.8rem;
  border: 0;
  border-radius: 50%;
  background: var(--cream);
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.45);
}

#volume:focus-visible {
  outline: 2px solid var(--cream);
  outline-offset: 4px;
  border-radius: 999px;
}

.mute {
  width: 2.75rem;
  height: 2.75rem;
  flex: none;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--cream);
  cursor: pointer;
  display: grid;
  place-items: center;
}

.mute:hover,
.mute:focus-visible {
  background: rgba(244, 239, 228, 0.1);
}

.mute:focus-visible {
  outline: 2px solid var(--cream);
  outline-offset: 2px;
}

.mute svg {
  width: 1.25rem;
  height: 1.25rem;
  fill: currentColor;
}

.mute .icon-off,
.mute.is-muted .icon-on {
  display: none;
}

.mute.is-muted .icon-off {
  display: block;
}

.poem-line {
  /* Every line shares one grid cell, so they are all centred on the same spot
     and only the live one is displayed. */
  grid-area: 1 / 1;
  display: none;
  /* Hug the text so the measured width is the real one; the grid would
     otherwise clamp the box and let the line overflow it. */
  width: max-content;
  max-width: none;
  padding: 1.5rem 2.6rem;
  transform-origin: 50% 50%;
  will-change: transform, filter, opacity;
  font-family: "Cormorant Garamond", "Palatino Linotype", Palatino, serif;
  --base: clamp(1.35rem, 3vw, 2.6rem);
  font-size: calc(var(--base) * var(--fit, 1));
  font-weight: 500;
  line-height: 1.4;
  text-align: center;
  color: #fbf6ea;
  /* The wood behind a line runs from dark trunk to bright snow, so the line
     brings its own ground with it. Everything here is centred rather than cast
     downward: an offset shadow leaves the top of the glyphs unbacked, and the
     scrim then reads as a band sitting above the text. */
  background: radial-gradient(
    ellipse 72% 58% at 50% 50%,
    rgba(16, 12, 5, 0.36),
    rgba(16, 12, 5, 0.22) 48%,
    rgba(16, 12, 5, 0) 74%
  );
  text-shadow:
    0 0 3px rgba(14, 10, 4, 0.9),
    0 0 12px rgba(16, 12, 5, 0.72),
    0 0 30px rgba(8, 10, 4, 0.55);
  /* One line of verse is one line on screen; poem.js scales anything that
     would not otherwise fit the viewport. */
  white-space: nowrap;
  pointer-events: none;
}

.poem-line.is-live {
  display: block;
}


.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.55;
  }
  50% {
    opacity: 1;
  }
}

@keyframes bounce {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-5px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .start-cta,
  .key-up,
  .veil,
  .hint,
  .volume-label {
    animation: none;
    transition: none;
  }
}


/* Roomier on a desktop screen, where there is width to spend. */
@media (min-width: 48rem) {
  .poem-line {
    --base: clamp(1.7rem, 3.75vw, 3.25rem);
  }
}

/* ------------------------------------------------------------------ touch */

@media (hover: none) and (pointer: coarse) {
  .for-keys {
    display: none;
  }

  .for-touch {
    display: block;
  }

  /* Nothing to press on a phone, so the cluster reads as a direction diagram
     rather than as keycaps. */
  .key {
    width: 2rem;
    height: 2rem;
    border: 0;
    background: none;
    box-shadow: none;
    font-size: 1.35rem;
  }

  /* No hover to open it with, so the slider simply stays out. */
  .volume-label {
    width: 6.5rem;
    margin: 0 0.55rem 0 0.5rem;
    opacity: 1;
  }

  #volume {
    width: 6.5rem;
  }

  .audio-dock {
    top: calc(0.9rem + env(safe-area-inset-top, 0px));
    right: calc(0.9rem + env(safe-area-inset-right, 0px));
  }

  .mute {
    width: 2.5rem;
    height: 2.5rem;
  }
}

/* ------------------------------------------------------- narrow and short */

@media (max-width: 34rem) {
  .start-stack {
    gap: 1.9rem;
    padding: 1.25rem;
  }

  h1 {
    font-size: clamp(2.1rem, 12vw, 3.4rem);
  }

  .eyebrow {
    font-size: 0.95rem;
  }

  .start-cta {
    margin-top: 1.1rem;
    font-size: 1.05rem;
  }

  .hint p {
    max-width: 17rem;
    font-size: 0.95rem;
  }

  .poem-line {
    padding: 0.5rem 0.6rem;
  }
}

@media (max-height: 34rem) {
  .start-stack {
    gap: 1.2rem;
  }

  h1 {
    font-size: clamp(1.9rem, 8vh, 3rem);
  }

  .keys {
    display: none;
  }
}


/* -------------------------------------------------------------------- rail */

.rail {
  position: absolute;
  top: 50%;
  right: clamp(0.75rem, 2.2vw, 2rem);
  transform: translateY(-50%);
  z-index: 16;
  color: var(--cream);
}

.rail[hidden] {
  display: none;
}

.rail-list {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  /* The wood behind the rail runs from dark trunk to bright snow, so the marks
     carry their own edge the way the poem does. */
  filter: drop-shadow(0 0 3px rgba(10, 8, 3, 0.85));
}

.rail.on-light .rail-list {
  filter: none;
}

.rail-tick {
  position: relative;
  appearance: none;
  margin: 0;
  padding: 0.2rem 0;
  border: 0;
  background: none;
  color: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.rail-mark {
  display: block;
  width: 0.9rem;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  opacity: 0.46;
  transition:
    width 0.32s var(--ease),
    opacity 0.26s ease;
}

.rail-tick:hover .rail-mark,
.rail-tick:focus-visible .rail-mark {
  width: 1.6rem;
  opacity: 0.85;
}

.rail-tick.is-here .rail-mark {
  width: 2.1rem;
  opacity: 1;
}

.rail-label {
  position: absolute;
  right: 2.6rem;
  white-space: nowrap;
  font-size: 0.92rem;
  font-style: italic;
  opacity: 0;
  transform: translateX(0.45rem);
  transition:
    opacity 0.22s ease,
    transform 0.3s var(--ease);
  pointer-events: none;
  text-shadow:
    0 0 3px rgba(14, 10, 4, 0.9),
    0 0 12px rgba(14, 10, 4, 0.7);
}

.rail-tick:hover .rail-label,
.rail-tick:focus-visible .rail-label {
  opacity: 0.95;
  transform: none;
}

.rail-tick:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 3px;
  border-radius: 2px;
}

/* Slides continuously, so the rail shows the walk rather than just the line. */
.rail-cursor {
  position: absolute;
  right: 0;
  top: 0;
  width: 2.6rem;
  height: 1px;
  margin-top: -0.5px;
  background: currentColor;
  opacity: 0.62;
  pointer-events: none;
}

.rail.on-light {
  --cream: #1c1812;
}

.rail.on-light .rail-label {
  text-shadow: none;
}

@media (hover: none) and (pointer: coarse) {
  .rail-tick {
    padding: 0.34rem 0;
  }

  .rail-label {
    display: none;
  }
}

@media (max-height: 34rem) {
  .rail {
    display: none;
  }
}
