/* MYSTIC OBLIVION: THE CRYSTAL AWAKENING */

@font-face { font-family: 'Oswald'; src: url('../../assets/fonts/oswald-500.woff2') format('woff2'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'Oswald'; src: url('../../assets/fonts/oswald-600.woff2') format('woff2'); font-weight: 600; font-display: swap; }
@font-face { font-family: 'Spectral'; src: url('../../assets/fonts/spectral-400.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Spectral'; src: url('../../assets/fonts/spectral-400i.woff2') format('woff2'); font-weight: 400; font-style: italic; font-display: swap; }

:root {
    --void: #06080a;
    --deep: #0a0f12;
    --quartz: #cfe6f2;
    --signal: #9fd8d4;
    --copper: #c07a3e;
    --amber: #d9a441;
    --growth: #6f9868;
    --violet: #8a7fb8;
    --bone: #f2ead8;
    --dim: #7e8a86;

    --font-display: 'Oswald', 'Arial Narrow', sans-serif;
    --font-body: 'Spectral', Georgia, serif;

    --ease-glide: cubic-bezier(0.22, 1, 0.36, 1);
    --stone-hue: var(--signal);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }   /* author display rules must never resurrect hidden UI */

html, body {
    height: 100%;
    overflow: hidden;
    background: var(--void);
    color: var(--bone);
    font-family: var(--font-body);
    overscroll-behavior: none;
}

.sr-only {
    position: absolute; width: 1px; height: 1px;
    overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}

#stage { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

/* fade veil for beat transitions */
#veil {
    position: fixed; inset: 0; background: var(--void);
    opacity: 1; pointer-events: none; z-index: 30;
    transition: opacity 1.2s var(--ease-glide);
}
#veil.open { opacity: 0; }

/* film grain — subtle, static-free */
#grain {
    position: fixed; inset: -50%; z-index: 20; pointer-events: none; opacity: .05;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23n)' opacity='0.6'/%3E%3C/svg%3E");
}

/* ---------- captions ---------- */
#captions {
    position: fixed; left: 50%; bottom: clamp(96px, 16vh, 160px);
    transform: translateX(-50%);
    width: min(88vw, 720px);
    text-align: center; z-index: 40; pointer-events: none;
}
.cap {
    opacity: 0; transform: translateY(10px);
    transition: opacity 1.1s var(--ease-glide), transform 1.1s var(--ease-glide);
    will-change: opacity, transform;
}
.cap.on { opacity: 1; transform: none; }
.cap.line {
    font-family: var(--font-display); font-weight: 500;
    font-size: clamp(1.05rem, 0.9rem + 1.4vw, 1.7rem);
    letter-spacing: .34em; text-indent: .34em; text-transform: uppercase;
    color: var(--quartz);
    text-shadow: 0 0 24px rgba(159, 216, 212, .35);
}
.cap.voice {
    font-family: var(--font-body); font-style: italic;
    font-size: clamp(1.15rem, 1rem + 1.2vw, 1.65rem);
    color: var(--bone);
    text-shadow: 0 2px 18px rgba(0,0,0,.8);
}
.cap.voice .who {
    display: block; font-family: var(--font-display); font-style: normal;
    font-size: .62rem; letter-spacing: .42em; text-indent: .42em;
    color: var(--dim); margin-bottom: .55em; text-transform: uppercase;
}
.cap.voice.ai { color: var(--signal); text-shadow: 0 0 26px rgba(159,216,212,.4); }

/* ---------- shared button voice ---------- */
button, .act {
    font-family: var(--font-display); font-weight: 500;
    letter-spacing: .3em; text-indent: .3em; text-transform: uppercase;
    background: rgba(6, 8, 10, .55); color: var(--bone);
    border: 1px solid rgba(207, 230, 242, .28);
    padding: .85em 1.6em; font-size: .72rem;
    cursor: pointer; text-decoration: none;
    backdrop-filter: blur(6px);
    transition: color .35s, border-color .35s, box-shadow .35s, background .35s, transform .35s var(--ease-glide);
}
button:hover, .act:hover, button:focus-visible, .act:focus-visible {
    color: var(--signal); border-color: var(--signal);
    box-shadow: 0 0 22px rgba(159, 216, 212, .22);
    outline: none;
}
button:focus-visible, .act:focus-visible { outline: 2px solid var(--signal); outline-offset: 3px; }

/* ---------- persistent controls ---------- */
#controls {
    position: fixed; top: max(14px, env(safe-area-inset-top)); right: max(14px, env(safe-area-inset-right));
    display: flex; gap: 10px; z-index: 60;
}
#controls button { padding: .6em 1em; font-size: .62rem; }
#sound { padding: .45em .6em; }
#sound svg { width: 20px; height: 20px; display: block; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
#sound .spk { fill: currentColor; stroke: none; }
#sound .waves { opacity: 0; transition: opacity .3s; }
#sound .mute { transition: opacity .3s; }
#sound[aria-pressed="true"] .waves { opacity: 1; }
#sound[aria-pressed="true"] .mute { opacity: 0; }
#sound.invite { animation: invite 3.2s ease-in-out 2; }
@keyframes invite { 0%,100% { box-shadow: none; } 50% { box-shadow: 0 0 26px rgba(159,216,212,.4); border-color: var(--signal); } }

/* ---------- beat 3 socket ---------- */
#socket {
    position: fixed; left: 50%; bottom: clamp(120px, 22vh, 220px); transform: translateX(-50%);
    z-index: 50; border-color: rgba(217, 164, 65, .5); color: var(--amber);
    animation: socketPulse 2.6s ease-in-out infinite;
}
#socket:hover, #socket:focus-visible { color: var(--amber); border-color: var(--amber); box-shadow: 0 0 26px rgba(217,164,65,.35); }
@keyframes socketPulse { 0%,100% { box-shadow: 0 0 8px rgba(217,164,65,.12); } 50% { box-shadow: 0 0 26px rgba(217,164,65,.4); } }

/* ---------- beat 5 vision (corner post — never over the captions) ---------- */
#vision {
    position: fixed; left: max(14px, env(safe-area-inset-left)); bottom: max(18px, env(safe-area-inset-bottom));
    z-index: 50; font-size: .62rem; padding: .7em 1.1em;
}
#vision[aria-pressed="true"] { color: var(--amber); border-color: var(--amber); box-shadow: 0 0 26px rgba(217,164,65,.3); }

/* ---------- beat 6 stones ---------- */
#stones {
    position: fixed; left: 50%; bottom: clamp(90px, 15vh, 150px); transform: translateX(-50%);
    z-index: 50; text-align: center;
}
.stones-ask {
    font-family: var(--font-display); font-size: .66rem; letter-spacing: .42em; text-indent: .42em;
    color: var(--dim); margin-bottom: 14px; text-transform: uppercase;
}
.stones-row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.stone { display: flex; align-items: center; gap: .7em; padding: .8em 1.3em; }
.stone-gem {
    width: 12px; height: 12px; display: inline-block; transform: rotate(45deg);
    box-shadow: 0 0 14px currentColor;
}
.gem-memory { background: var(--violet); color: var(--violet); }
.gem-courage { background: var(--amber); color: var(--amber); }
.gem-compassion { background: var(--growth); color: var(--growth); }

/* ---------- finale ---------- */
#finale {
    position: fixed; inset: 0; z-index: 45;
    display: flex; flex-direction: column; align-items: center; justify-content: safe center;
    text-align: center; padding: 24px; pointer-events: none;
    overflow-y: auto;                       /* short viewports scroll, never clip */
    background: radial-gradient(ellipse at 50% 42%, rgba(4,6,10,.55), rgba(4,6,10,.1) 65%, rgba(4,6,10,0));
}
#finale > * { pointer-events: auto; opacity: 0; transform: translateY(14px); transition: opacity 1.4s var(--ease-glide), transform 1.4s var(--ease-glide); }
#finale.on > * { opacity: 1; transform: none; }
#finale.on > .finale-title { transition-delay: .5s; }
#finale.on > .finale-law { transition-delay: 1.6s; }
#finale.on > .finale-actions { transition-delay: 2.6s; }
.finale-eyebrow {
    font-family: var(--font-display); font-size: .72rem; letter-spacing: .58em; text-indent: .58em;
    color: var(--dim);
}
.finale-title {
    font-family: var(--font-display); font-weight: 600;
    font-size: min(clamp(2.6rem, 1.4rem + 7vw, 6.4rem), 16vh);
    letter-spacing: .18em; text-indent: .18em; line-height: 1.08;
    color: var(--quartz); margin: 18px 0 10px;
    text-shadow: 0 0 44px rgba(159, 216, 212, .3);
}
@media (max-height: 560px) {
    .finale-law { margin-bottom: 16px; line-height: 1.6; }
    .finale-actions { gap: 8px; }
    #finale .act { padding: .55em 1.1em; }
}
.finale-law {
    font-family: var(--font-display); font-weight: 500;
    font-size: clamp(.8rem, .7rem + .8vw, 1.05rem);
    letter-spacing: .34em; text-indent: .34em; line-height: 2;
    color: var(--amber); margin-bottom: 34px;
}
.finale-actions { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }
.act-primary { color: var(--void); background: var(--signal); border-color: var(--signal); font-weight: 600; }
.act-primary:hover, .act-primary:focus-visible { color: var(--void); background: var(--quartz); box-shadow: 0 0 34px rgba(159,216,212,.5); }

/* ---------- beat 8 material readout ---------- */
#material {
    position: fixed; left: 50%; bottom: clamp(96px, 15vh, 150px); transform: translateX(-50%);
    z-index: 50; text-align: center; pointer-events: none; width: min(88vw, 560px);
}
#material h3 {
    font-family: var(--font-display); font-weight: 500; font-size: .8rem;
    letter-spacing: .42em; text-indent: .42em; color: var(--signal); text-transform: uppercase;
}
#material p { font-style: italic; color: var(--bone); margin-top: .5em; font-size: 1.05rem; text-shadow: 0 2px 14px rgba(0,0,0,.8); }
#back-finale { position: fixed; top: max(14px, env(safe-area-inset-top)); left: max(14px, env(safe-area-inset-left)); z-index: 60; padding: .6em 1em; font-size: .62rem; }

/* ---------- reduced-motion nav ---------- */
#rm-nav {
    position: fixed; bottom: max(18px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
    display: flex; gap: 12px; z-index: 60;
}

.noscript {
    position: fixed; inset: 0; display: grid; place-content: center; text-align: center;
    padding: 24px; font-size: 1.1rem; line-height: 2;
}
.noscript a { color: var(--signal); }

/* ---------- mobile ---------- */
@media (max-width: 640px) {
    #captions { bottom: 132px; }
    .stones-row { flex-direction: column; }
    .stone { justify-content: center; }
    #controls button { padding: .7em 1em; }
    .finale-actions { flex-direction: column; width: min(78vw, 320px); }
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
    #veil { transition-duration: .6s; }
    .cap, #finale > * { transition-duration: .5s; }
    #socket, #sound.invite { animation: none; }
    #grain { display: none; }
}

/* ================= CHAPTER III — THE SLEEPING OCEAN ================= */

:root {
    --sun-zone: #2a7f9e;
    --twilight: #123a52;
    --midnight: #05141f;
    --abyss: #01080f;
    --vent: #ff7a3c;
    --bio: #7fe8d8;
}

/* veils tinted by water */
#veil.shallow { background: linear-gradient(180deg, #2a7f9e, #123a52); }
#veil.deep    { background: linear-gradient(180deg, #05141f, #01080f); }
#veil.dawn    { background: linear-gradient(180deg, #f0c48a, #7fb0c4 60%, #2a4a5a); }

/* ---------- depth HUD: the explorer's instrument ---------- */
#depth {
    /* sits in the upper-left band so its readout never lands in the caption
       zone at the bottom of the frame */
    position: fixed; left: max(16px, env(safe-area-inset-left)); top: 44%;
    transform: translateY(-60%); z-index: 55; pointer-events: none;
    font-family: var(--font-display); color: var(--quartz);
    letter-spacing: .2em;
}
#depth.hidden-hud { opacity: 0; }
#depth { transition: opacity .8s var(--ease-glide); }
.depth-track {
    position: relative; width: 2px; height: min(38vh, 290px);
    background: linear-gradient(180deg, rgba(207,230,242,.35), rgba(207,230,242,.06));
}
.depth-marker {
    position: absolute; left: -5px; width: 12px; height: 2px;
    background: var(--quartz); opacity: .55;
}
.depth-marker span {
    position: absolute; left: 18px; top: -.55em;
    font-size: .5rem; letter-spacing: .26em; white-space: nowrap;
    color: var(--dim);
}
.depth-you {
    position: absolute; left: -7px; width: 16px; height: 16px; margin-top: -8px;
    border: 1px solid var(--signal); border-radius: 50%;
    box-shadow: 0 0 14px rgba(159,216,212,.5);
    transition: top .25s linear;
}
.depth-read {
    margin-top: 12px; font-size: .66rem; color: var(--signal);
    text-shadow: 0 0 16px rgba(159,216,212,.4);
}
.depth-zone { margin-top: 4px; font-size: .5rem; letter-spacing: .3em; color: var(--dim); }

/* ---------- the hold: you cannot rush this ---------- */
#hold-wrap {
    /* clears the caption band beneath it — the note and the dialogue were
       landing on top of each other */
    position: fixed; left: 50%; bottom: clamp(196px, 30vh, 320px); transform: translateX(-50%);
    z-index: 55; text-align: center;
}
#hold {
    position: relative; width: 108px; height: 108px; border-radius: 50%;
    border: 1px solid rgba(127,232,216,.4); background: rgba(1,8,15,.5);
    padding: 0; letter-spacing: .18em; font-size: .55rem; color: var(--bio);
    display: grid; place-content: center; line-height: 1.6;
}
#hold:hover, #hold:focus-visible { border-color: var(--bio); box-shadow: 0 0 30px rgba(127,232,216,.3); }
#hold-ring { position: absolute; inset: -6px; transform: rotate(-90deg); pointer-events: none; }
#hold-ring circle { fill: none; stroke-width: 2; }
#hold-ring .bg { stroke: rgba(127,232,216,.14); }
#hold-ring .fg { stroke: var(--bio); stroke-linecap: round; transition: stroke-dashoffset .12s linear; filter: drop-shadow(0 0 6px var(--bio)); }
.hold-note {
    margin-top: 14px; font-family: var(--font-body); font-style: italic;
    font-size: .95rem; color: var(--dim); max-width: 22ch;
}
#hold.slipped { animation: slip .5s ease; }
@keyframes slip { 0%,100% { transform: none; } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

/* ---------- descent prompt ---------- */
#sink {
    position: fixed; left: 50%; bottom: clamp(90px, 14vh, 150px); transform: translateX(-50%);
    z-index: 50; color: var(--bio); border-color: rgba(127,232,216,.45);
}

@media (max-width: 640px) {
    #depth { left: 10px; }
    .depth-track { height: 32vh; }
    .depth-marker span { font-size: .44rem; }
    #hold { width: 96px; height: 96px; }
}
@media (prefers-reduced-motion: reduce) {
    #hold.slipped { animation: none; }
}
