/* Raincrow: The Descent (prototype)
   Tokens first. Two voices: the human serif and the machine mono. */
:root {
  --abyss: #060908;          /* page ground, matches the shader's deep water */
  --bone: #ddd6c6;           /* plaster / human voice */
  --bone-dim: #9b9586;
  --lichen: #8fb9a1;         /* machine voice, borrowed from the phone light */
  --grey-1: #2a2f2d;         /* map ink, faint */
  --grey-2: #4a514e;
  --grey-3: #7d8581;
  --ember: #d9a066;          /* the human light */

  --serif: "IM Fell English", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --gutter: clamp(16px, 4vw, 56px);
  --bar-pad-top: calc(18px + env(safe-area-inset-top, 0px));
}

* { box-sizing: border-box; }
html { background: var(--abyss); color: var(--bone); }
body {
  margin: 0;
  background: var(--abyss);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; touch-action: manipulation; }
button { touch-action: manipulation; }
::selection { background: var(--ember); color: var(--abyss); }

/* ---------- top bar: almost not there ---------- */
.bar {
  position: fixed; inset: 0 0 auto 0; z-index: 20;
  display: flex; justify-content: space-between; align-items: center;
  padding: var(--bar-pad-top) var(--gutter) 18px;
  pointer-events: none;
  mix-blend-mode: difference;
  transition: opacity .5s ease, visibility .5s;
}
.bar.is-away {
  opacity: 0;
  visibility: hidden;
}
.bar a { pointer-events: auto; text-decoration: none; }
.mark {
  display: inline-flex; align-items: center; gap: 0.4em;
  font-size: 22px; letter-spacing: 0.01em; white-space: nowrap;
  line-height: 1;
}
.mark__o {
  display: block; flex: 0 0 auto;
  width: 0.72em; height: 0.72em;
  color: currentColor;
}
.bar nav { display: flex; gap: 22px; font-family: var(--mono); font-size: 12px; color: var(--bone-dim); }
.bar nav a:hover { color: var(--bone); }

/* ---------- 1. surface ---------- */
.surface { position: relative; height: 330vh; }
.surface__stage {
  position: sticky; top: 0; height: 100vh; height: 100svh; overflow: hidden;
  contain: paint;
}
#hero { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: none; }
.surface__fallback {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; object-position: 72% 50%;
  display: none;
}
.veil {
  position: absolute; inset: 0; z-index: 2;
  display: grid; place-items: center;
  background: var(--abyss);
  transition: opacity 1.6s ease, visibility 0s linear 1.6s;
}
.veil__mark { width: 28px; height: 28px; color: var(--bone-dim); opacity: .7; animation: veil-breathe 2.4s ease-in-out infinite; }
@keyframes veil-breathe { 50% { opacity: .25; } }
.hero-ready .veil, .no-webgl .veil { opacity: 0; visibility: hidden; }
.no-webgl #hero { display: none; }
.no-webgl .surface__fallback { display: block; }

.thoughts {
  position: absolute; left: var(--gutter); bottom: 22vh;
  width: min(30ch, 80vw);
  pointer-events: none;
}
.thought {
  position: absolute; left: 0; bottom: 0; margin: 0;
  font-size: clamp(26px, 3.1vw, 46px);
  line-height: 1.12;
  color: var(--bone);
  opacity: 0;
  filter: blur(10px);
  transform: translateY(14px);
  transition: opacity 1.8s ease, filter 2.2s ease, transform 2.4s cubic-bezier(.2,.7,.2,1);
  will-change: opacity, transform, filter;
}
.thought.is-on { opacity: 0.92; filter: blur(0); transform: none; }
.thought.is-gone { opacity: 0; filter: blur(14px); transform: translateY(-10px); transition-duration: 2.6s; }
.thought.is-on, .thought.is-gone { will-change: auto; }

.descend {
  position: absolute; left: 50%; bottom: max(22px, env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  font-family: var(--mono); font-size: 11px; color: var(--bone-dim);
  pointer-events: none; transition: opacity .6s ease;
}
.descend i { display: block; width: 1px; height: 38px; background: linear-gradient(var(--bone-dim), transparent); }

/* ---------- 2. below: the shared world ---------- */
.below { position: relative; height: 560vh; margin-top: -1px; }
.below__stage {
  position: sticky; top: 0; height: 100vh; height: 100svh; overflow: hidden;
  background: var(--abyss); contain: paint;
}
#map, #map-svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#map-svg { pointer-events: none; overflow: visible; }

.map-head {
  position: absolute; left: var(--gutter); top: calc(84px + env(safe-area-inset-top, 0px)); max-width: 34ch;
  pointer-events: none;
  transition: opacity .8s ease;
}
.kicker { margin: 0 0 12px; display: flex; align-items: center; gap: 10px; font-family: var(--mono); font-size: 12px; color: var(--bone); }
.kicker__mark { width: 18px; height: 18px; color: var(--bone); flex: none; }
.map-head h2 { margin: 0; font-weight: 400; font-size: clamp(26px, 3vw, 42px); line-height: 1.1; }
.map-head em { color: var(--bone-dim); }

.realms {
  list-style: none; margin: 0; padding: 0;
  position: absolute; left: var(--gutter); bottom: 64px;
  width: min(340px, calc(100vw - 2 * var(--gutter)));
  display: flex; flex-direction: column; gap: 4px;
  transition: opacity .55s ease;
}
.realm__name {
  all: unset; cursor: pointer; display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  width: 100%; padding: 8px 0; border-top: 1px solid var(--grey-1);
  font-family: var(--serif); font-size: 22px; color: var(--bone-dim);
  transition: color .4s ease;
}
.realm__name span { font-family: var(--mono); font-size: 11px; color: var(--grey-3); text-align: right; }
.realm__name:hover, .realm.is-active .realm__name { color: var(--bone); }
.realm__name:focus-visible { outline: 1px dashed var(--grey-3); outline-offset: 4px; }
/* realm card: a tarot card beside a few words.
   The card's layout never changes open or closed, so nothing reflows mid-transition.
   Desktop: the closing card shrinks at exactly the rate the opening one grows (grid 0fr -> 1fr),
   so the list keeps a steady height. Phone: see the media query, the cards cross-fade in one slot. */
.realm__card {
  display: grid; grid-template-rows: 0fr; opacity: 0; visibility: hidden;
  transition: grid-template-rows .7s cubic-bezier(.45,0,.25,1), opacity .3s ease, visibility 0s linear .7s;
}
.realm.is-active .realm__card {
  grid-template-rows: 1fr; opacity: 1; visibility: visible;
  transition: grid-template-rows .7s cubic-bezier(.45,0,.25,1), opacity .45s ease .25s, visibility 0s;
}
.realm__inner {
  min-height: 0; overflow: hidden;
  display: grid; grid-template-columns: 140px minmax(0, 1fr); column-gap: 18px; align-items: start; align-content: start;
}
.realm__card p { margin: 10px 0 0; font-size: 17px; color: var(--bone); }
.realm__card p:first-of-type { margin-top: 6px; }
.realm__card .meta { margin-top: 6px; font-family: var(--mono); font-size: 11px; color: var(--grey-3); }
.realm__card .card-art {
  grid-row: span 2; display: block; width: 100%; height: auto;
  margin: 6px 0 10px; border-radius: 6px; background: transparent;
}

/* ---------- 3. studio ---------- */
.studio {
  position: relative; z-index: 15;
  min-height: 80vh; display: flex; align-items: center;
  padding: 18vh var(--gutter) calc(18vh + env(safe-area-inset-bottom, 0px));
  background: var(--abyss);
}
.studio__inner { max-width: 36ch; }
.studio p { margin: 0 0 1em; color: var(--bone-dim); }
.studio__mark { display: block; width: 22px; height: 22px; color: var(--bone); margin-bottom: 1.4em; }
.studio__lede { font-size: clamp(24px, 2.6vw, 36px); line-height: 1.15; color: var(--bone) !important; }
.studio__open { font-family: var(--mono); font-size: 13px; color: var(--grey-3) !important; margin-top: 2.2em !important; }
.studio__addr { color: var(--bone); margin-left: .6em; text-decoration: none; border-bottom: 1px solid var(--grey-2); user-select: all; }
.studio__addr:hover, .studio__addr:focus-visible { color: var(--ember); border-color: currentColor; }
.fine { font-family: var(--mono); font-size: 11px; color: var(--grey-2) !important; margin-top: 4em !important; }

@media (max-width: 720px) {
  body { font-size: 17px; }
  .mark { font-size: 16px; gap: 0.35em; }
  .bar {
    /* mix-blend-mode is costly while scrolling on phones; solid mark stays legible on the dark scenes */
    mix-blend-mode: normal;
    color: var(--bone);
  }
  .bar nav { gap: 14px; font-size: 11px; color: var(--bone-dim); }
  .thoughts { bottom: auto; top: calc(18vh + env(safe-area-inset-top, 0px)); }
  /* blur filters during scroll are a common jank source on mobile GPUs */
  .thought {
    filter: none;
    transform: translateY(10px);
    transition: opacity 1.2s ease, transform 1.4s cubic-bezier(.2,.7,.2,1);
    will-change: opacity, transform;
  }
  .thought.is-on { filter: none; }
  .thought.is-gone { filter: none; transform: translateY(-8px); transition-duration: 1.6s; }
  .realms {
    left: 0; right: 0; width: auto; bottom: 0;
    padding: 40px var(--gutter) 40px;
    background: linear-gradient(to bottom, transparent, var(--abyss) 38px);
  }
  .map-head { top: calc(64px + env(safe-area-inset-top, 0px)); max-width: min(34ch, calc(100vw - 2 * var(--gutter))); }
  .map-head h2 { font-size: 22px; }
  .realm__inner { grid-template-columns: 84px minmax(0, 1fr); column-gap: 14px; }
  .realm__card p { font-size: 16px; }
  .realm__name { font-size: 19px; padding: 6px 0; }

  /* phone panel: the three names in one row, the active game's card and line beneath */
  .realms {
    display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); column-gap: 12px;
    padding: 34px var(--gutter) max(18px, env(safe-area-inset-bottom));
  }
  .realm { display: contents; }
  .realm__name {
    grid-row: 1; flex-direction: column; justify-content: flex-start; align-items: flex-start; gap: 2px;
    font-size: 17px; padding: 8px 0 10px;
    min-height: 44px; /* comfortable tap target */
  }
  .realm__name span { font-size: 10px; line-height: 1.3; text-align: left; }
  .realm.is-active .realm__name { border-top-color: var(--bone-dim); }
  /* all three cards share one slot at full height, so the panel never changes size; they only cross-fade */
  .realm__card, .realm.is-active .realm__card { grid-row: 2; grid-column: 1 / -1; grid-template-rows: 1fr; }
  .realm__card { transition: opacity .3s ease, visibility 0s linear .3s; }
  .realm.is-active .realm__card { transition: opacity .45s ease .2s, visibility 0s; }

  .studio { min-height: 72vh; padding: 14vh var(--gutter) calc(14vh + env(safe-area-inset-bottom, 0px)); }
  .studio__lede { font-size: clamp(22px, 7vw, 30px); }
}

@media (prefers-reduced-motion: reduce) {
  .thought, .realm__card { transition-duration: .01s; }
  .veil__mark { animation: none; }
}

/* desktop: a soft dark field behind the realm list so map labels never sit under the copy */
@media (min-width: 721px) {
  .realms { isolation: isolate; }
  .realms::before {
    content: ""; position: absolute; z-index: -1;
    inset: -48px -90px -40px calc(-1 * var(--gutter));
    background: linear-gradient(to right, var(--abyss) 78%, transparent);
    pointer-events: none;
  }
}
