/* 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 IV — THE SKY SHEPHERDS ================= */

:root {
    --thin: #cfe0ea;
    --altitude: #1b3550;
    --high: #6ea8c8;
    --prayer-blue: #3f7fb8;
    --prayer-white: #e8eef0;
    --prayer-red: #c4402f;
    --prayer-green: #5f9463;
    --prayer-yellow: #d9a441;
    --shepherd: #b9d4e2;
}

#veil.thinair { background: linear-gradient(180deg, #0a1826, #2a4a68 55%, #7fa8c0); }
#veil.strato  { background: linear-gradient(180deg, #02060f, #0a1c30 60%, #24466a); }
#veil.years   { background: linear-gradient(180deg, #d9a441, #8a5f3f 50%, #1b3550); }

/* ---------- the time dial: this chapter's instrument ---------- */
#timepiece {
    position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom));
    transform: translateX(-50%); z-index: 55;
    width: min(84vw, 520px); text-align: center;
    padding: 0 38px;   /* room for the SECOND / DECADE tick captions at the ends */
    font-family: var(--font-display); color: var(--quartz);
    transition: opacity .8s var(--ease-glide);
}
#timepiece[hidden] { display: none !important; }
.tp-read {
    font-size: clamp(1.1rem, .9rem + 1.2vw, 1.7rem);
    letter-spacing: .26em; text-indent: .26em;
    color: var(--shepherd); text-shadow: 0 0 22px rgba(185,212,226,.4);
}
.tp-label {
    font-size: .52rem; letter-spacing: .34em; text-indent: .34em;
    color: var(--dim); margin-top: 6px;
}
.tp-track {
    /* tall enough that the tick captions below the rail never reach the hint */
    position: relative; height: 34px; margin: 22px 0 24px;
    display: flex; align-items: center;
}
.tp-rail {
    position: absolute; left: 0; right: 0; height: 1px;
    background: linear-gradient(90deg, rgba(207,224,234,.5), rgba(207,224,234,.16));
}
.tp-tick {
    position: absolute; width: 1px; height: 9px; top: 50%; margin-top: -4px;
    background: rgba(207,224,234,.4);
}
.tp-tick span {
    position: absolute; left: 50%; transform: translateX(-50%); top: 13px;
    font-size: .44rem; letter-spacing: .2em; color: var(--dim); white-space: nowrap;
}
#tp-input {
    position: relative; width: 100%; margin: 0; background: transparent;
    -webkit-appearance: none; appearance: none; height: 34px; cursor: ew-resize;
}
#tp-input:focus-visible { outline: 2px solid var(--shepherd); outline-offset: 6px; }
#tp-input::-webkit-slider-thumb {
    -webkit-appearance: none; width: 20px; height: 20px; border-radius: 50%;
    background: var(--void); border: 1px solid var(--shepherd);
    box-shadow: 0 0 16px rgba(185,212,226,.55); cursor: ew-resize;
}
#tp-input::-moz-range-thumb {
    width: 20px; height: 20px; border-radius: 50%;
    background: var(--void); border: 1px solid var(--shepherd);
    box-shadow: 0 0 16px rgba(185,212,226,.55); cursor: ew-resize;
}
#tp-input::-webkit-slider-runnable-track { background: transparent; }
#tp-input::-moz-range-track { background: transparent; }
.tp-hint {
    font-family: var(--font-body); font-style: italic; font-size: .92rem;
    color: var(--dim);
}

/* ---------- the flag you tie ---------- */
#tie {
    position: fixed; left: 50%; bottom: clamp(150px, 24vh, 250px); transform: translateX(-50%);
    z-index: 50; color: var(--prayer-yellow); border-color: rgba(217,164,65,.5);
    animation: flagPulse 3.4s ease-in-out infinite;
}
#tie:hover, #tie:focus-visible { color: var(--prayer-yellow); border-color: var(--prayer-yellow); box-shadow: 0 0 28px rgba(217,164,65,.35); }
@keyframes flagPulse { 0%,100% { box-shadow: 0 0 6px rgba(217,164,65,.12); } 50% { box-shadow: 0 0 26px rgba(217,164,65,.4); } }

@media (max-width: 640px) {
    #timepiece { width: 92vw; }
    .tp-tick span { font-size: .4rem; }
}
@media (prefers-reduced-motion: reduce) {
    #tie { animation: none; }
}
