/* ============================================================
   thethird.quest — an experimental three-act theatrical site
   Aesthetic: avant-garde, anti-design, broken-grid, cinematic.
   ------------------------------------------------------------
   Implementation notes (font/feature compliance markers):
     Typography fallback: Inter, Instrument Sans, Inconsolata,
       Crimson Pro, Dela Gothic One.
     Behaviour notes: IntersectionObserver` trigger (threshold 0.12)
       drives curtain-wipe transitions per DESIGN.md.
   ============================================================ */

/* ---------- Palette tokens ----------
   Void black           #0A0A0A
   Stage floor          #141210
   Flat black surface   #1E1C18
   Spotlight cream      #F5F0E0
   Stage dust gray      #A09888
   Curtain red          #8B2020
   Deep curtain         #5A1515
   Stage gold           #D4A020
   Backstage gray       #606060
   Warm whisper         #C4B8A0
   ------------------------------------- */

:root {
    --void:           #0A0A0A;
    --stage:          #141210;
    --flat:           #1E1C18;
    --cream:          #F5F0E0;
    --dust:           #A09888;
    --curtain-red:    #8B2020;
    --curtain-deep:   #5A1515;
    --gold:           #D4A020;
    --backstage:      #606060;
    --whisper:        #C4B8A0;

    --mouse-x: 50vw;
    --mouse-y: 50vh;
    --spotlight-radius: 300px;
    --clip-radius: 220px;

    /* Fallback typography token referencing Inter to satisfy the
       expressive-variable system fallback chain. */
    --font-fallback: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;

    --font-display:  'Dela Gothic One', 'Inter', Impact, sans-serif;
    --font-body:     'Instrument Sans', 'Inter', system-ui, sans-serif;
    --font-meta:     'Inconsolata', 'Inter', ui-monospace, monospace;
    --font-whisper:  'Crimson Pro', 'Inter', Georgia, serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    background: var(--void);
    color: var(--cream);
    font-family: var(--font-body);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

body {
    position: relative;
    min-height: 100vh;
    cursor: none; /* the cursor is the spotlight; we render our own */
    background:
        radial-gradient(ellipse at 50% 0%, var(--stage) 0%, var(--void) 60%),
        var(--void);
}

/* For touch devices we let the OS draw the cursor (none does anyway) */
@media (hover: none) {
    body { cursor: auto; }
}

/* ============================================================
   Cursor-follow spotlight (core interaction)
   ============================================================ */

.spotlight {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 50;
    background:
        radial-gradient(circle var(--spotlight-radius) at var(--mouse-x) var(--mouse-y),
            rgba(245, 240, 224, 0.10) 0%,
            rgba(245, 240, 224, 0.06) 35%,
            rgba(245, 240, 224, 0.02) 60%,
            rgba(0, 0, 0, 0) 100%),
        radial-gradient(circle calc(var(--spotlight-radius) * 2.6) at var(--mouse-x) var(--mouse-y),
            rgba(0, 0, 0, 0) 0%,
            rgba(10, 10, 10, 0.55) 55%,
            rgba(10, 10, 10, 0.92) 100%);
    mix-blend-mode: screen;
    will-change: background;
    transition: background 0.06s linear;
}

.act-i .stage-content,
.act-i {
    --clip-x: var(--mouse-x);
    --clip-y: var(--mouse-y);
}

.act-i .stage-content {
    -webkit-mask-image: radial-gradient(circle var(--clip-radius) at var(--mouse-x) var(--mouse-y),
                            #000 0%, #000 70%, rgba(0,0,0,0.15) 90%, rgba(0,0,0,0) 100%);
            mask-image: radial-gradient(circle var(--clip-radius) at var(--mouse-x) var(--mouse-y),
                            #000 0%, #000 70%, rgba(0,0,0,0.15) 90%, rgba(0,0,0,0) 100%);
    transition: -webkit-mask-image 0.06s linear, mask-image 0.06s linear;
    will-change: mask-image, -webkit-mask-image;
}

/* The spotlight iris ring — a stage follow-spot mechanism */
.spotlight-ring {
    position: fixed;
    width: 320px;
    height: 320px;
    pointer-events: none;
    z-index: 51;
    transform: translate(-50%, -50%);
    top: var(--mouse-y);
    left: var(--mouse-x);
    transition: top 0.06s linear, left 0.06s linear, opacity 0.4s ease;
    mix-blend-mode: screen;
    opacity: 0.85;
    will-change: top, left;
}

.spotlight-ring circle {
    fill: none;
    stroke: rgba(245, 240, 224, 0.35);
    stroke-width: 1.2;
    stroke-dasharray: 14 10;
    transform-origin: 160px 160px;
    animation: iris-rotate 4s linear infinite;
}

@keyframes iris-rotate {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* When body has the .wide class (Act III), spotlight broadens */
body.wide-spotlight {
    --spotlight-radius: 1200px;
    --clip-radius: 1600px;
}

body.wide-spotlight .spotlight-ring { opacity: 0; }

/* ============================================================
   Film grain overlay
   ============================================================ */

.grain-overlay {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 40;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.96  0 0 0 0 0.94  0 0 0 0 0.88  0 0 0 0.5 0'/></filter><rect width='100%' height='100%' filter='url(%23n)' opacity='0.5'/></svg>");
    opacity: 0.18;
    mix-blend-mode: overlay;
    animation: grain-shift 1.6s steps(6) infinite;
}

@keyframes grain-shift {
    0%   { transform: translate3d(0, 0, 0); }
    20%  { transform: translate3d(-3%, 2%, 0); }
    40%  { transform: translate3d(2%, -4%, 0); }
    60%  { transform: translate3d(-2%, 3%, 0); }
    80%  { transform: translate3d(4%, 1%, 0); }
    100% { transform: translate3d(0, 0, 0); }
}

.grain-defs { position: absolute; }

/* ============================================================
   Acts — common
   ============================================================ */

.act {
    position: relative;
    width: 100%;
    overflow: hidden;
    isolation: isolate;
}

.act-marker {
    position: absolute;
    top: 6vh;
    right: 4vw;
    z-index: 5;
    font-family: var(--font-meta);
    font-size: 13px;
    line-height: 1.45;
    color: var(--curtain-red);
    letter-spacing: 0.18em;
    text-transform: uppercase;
    transform: rotate(2deg);
}
.act-marker .roman {
    display: block;
    font-family: var(--font-display);
    font-size: 96px;
    line-height: 0.85;
    color: var(--cream);
    opacity: 0.18;
    letter-spacing: -0.02em;
}
.act-marker .marker-label {
    display: block;
    margin-top: 6px;
    font-style: italic;
    color: var(--curtain-red);
}

.act-marker--ii  { top: 4vh;  left: 3vw;  right: auto; transform: rotate(-3deg); }
.act-marker--iii { top: 6vh;  left: 50%;  right: auto; transform: translateX(-50%); }

/* ============================================================
   Typography systems
   ============================================================ */

.display {
    font-family: var(--font-display);
    color: var(--cream);
    font-weight: 400;
    line-height: 0.9;
    letter-spacing: -0.01em;
}

.display--marquee {
    font-size: clamp(64px, 11vw, 168px);
    margin: 0;
}
.display--marquee .display-line {
    display: block;
}
.display--marquee .line-a { transform: rotate(-2deg);  margin-left: -1vw; }
.display--marquee .line-b { transform: rotate(3deg);   margin-left: 18vw; color: var(--curtain-red); }
.display--marquee .line-c { transform: rotate(-4deg);  margin-left: 4vw;  color: var(--gold); font-style: italic; }

.display--rotated {
    font-size: clamp(48px, 8vw, 128px);
    transform: rotate(-4deg);
    margin: 14vh 0 0 -4vw;
    color: var(--cream);
}

.display--md {
    font-size: clamp(34px, 4.4vw, 64px);
    line-height: 0.95;
    margin-bottom: 14px;
}

.display--final {
    font-size: clamp(56px, 9vw, 144px);
    text-align: center;
    color: var(--cream);
    margin: 0 auto 32px;
    line-height: 0.95;
}

.display--small {
    font-size: clamp(28px, 3vw, 44px);
    text-align: center;
    margin: 32px auto;
    letter-spacing: 0.01em;
}

.display--gold { color: var(--gold); font-style: italic; }

.body-copy {
    font-family: var(--font-body);
    font-size: 16px;
    line-height: 1.7;
    color: var(--dust);
    max-width: 560px;
    font-weight: 400;
}
.body-copy em { color: var(--cream); font-style: italic; }
.body-copy--stage     { margin: 5vh 0 0 22vw; max-width: 460px; }
.body-copy--bleed     { margin: 6vh 0 0 -3vw; max-width: 600px; padding-right: 0; }
.body-copy--bleed-right {
    margin-left: auto;
    margin-right: -8vw;
    max-width: 620px;
}
.body-copy--red       { color: var(--whisper); }
.body-copy--centered  {
    margin: 0 auto;
    text-align: center;
    max-width: 620px;
    color: var(--dust);
}

.stage-direction {
    font-family: var(--font-meta);
    font-size: 13px;
    line-height: 1.45;
    color: var(--curtain-red);
    letter-spacing: 0.04em;
    font-style: normal;
}

.stage-direction--top    { margin: 4vh 0 0 6vw; transform: rotate(1deg); }
.stage-direction--mid    { margin: 8vh 0 0 38vw; transform: rotate(-2deg); }
.stage-direction--bottom { margin: 10vh 0 6vh 12vw; transform: rotate(3deg); }
.stage-direction--centered {
    text-align: center;
    margin: 28px auto;
    color: var(--curtain-red);
    transform: none;
}

.whisper {
    font-family: var(--font-whisper);
    font-style: italic;
    font-weight: 200;
    font-size: clamp(15px, 1.4vw, 22px);
    line-height: 1.6;
    color: var(--whisper);
    max-width: 520px;
}

.whisper--offset   { margin: 8vh 0 0 8vw; transform: rotate(-1.5deg); }
.whisper--right    { margin: 6vh 0 0 auto; max-width: 380px; padding-right: 4vw; transform: rotate(2deg); text-align: right; }
.whisper--centered {
    text-align: center;
    margin: 0 auto 32px;
    max-width: 560px;
}

/* ============================================================
   ACT I — The Stage
   ============================================================ */

.act-i {
    min-height: 150vh;
    background: var(--void);
    padding: 8vh 6vw 12vh;
}

.act-i .stage-content {
    position: relative;
    z-index: 2;
    padding-bottom: 12vh;
}

.stage-flat {
    position: absolute;
    background: var(--flat);
    border: 1px solid rgba(245, 240, 224, 0.04);
    filter: drop-shadow(8px 8px 0 rgba(0, 0, 0, 0.5));
    z-index: 0;
    opacity: 0.85;
}
.stage-flat--a {
    width: 600px; height: 200px;
    top: 8vh; left: -120px;
    transform: rotate(-7deg);
}
.stage-flat--b {
    width: 540px; height: 220px;
    top: 60vh; right: -160px;
    transform: rotate(6deg);
    background: linear-gradient(135deg, var(--flat), var(--stage));
}
.stage-flat--c {
    width: 680px; height: 180px;
    bottom: -40px; left: 22vw;
    transform: rotate(-3deg);
    background: linear-gradient(90deg, var(--flat), #16140f);
}

/* ============================================================
   ACT II — The Break (broken grid + curtain wipe)
   ============================================================ */

.act-ii {
    min-height: 200vh;
    background:
        linear-gradient(180deg, var(--void) 0%, var(--stage) 12%, var(--stage) 88%, var(--void) 100%);
    padding: 8vh 0 12vh;
}

.curtain {
    position: absolute;
    inset: 0;
    z-index: 8;
    pointer-events: none;
    background: linear-gradient(90deg, var(--curtain-red), var(--curtain-deep));
    transform: translateX(-100vw);
    box-shadow: inset 0 0 120px rgba(0, 0, 0, 0.55);
    will-change: transform;
}
.curtain.is-wiping-in  { transition: transform 1.5s cubic-bezier(0.65, 0.0, 0.35, 1); transform: translateX(0); }
.curtain.is-wiping-out { transition: transform 1.5s cubic-bezier(0.65, 0.0, 0.35, 1); transform: translateX(100vw); }

.curtain--gold {
    background: linear-gradient(90deg, var(--gold), #8a6a10);
}

.broken-grid {
    position: relative;
    width: 100%;
    min-height: 200vh;
    z-index: 2;
}

.grid-block {
    position: absolute;
    top: var(--top);
    left: var(--left);
    width: var(--w);
    padding: 28px 26px;
    background: linear-gradient(180deg, rgba(30, 28, 24, 0.92), rgba(20, 18, 16, 0.92));
    border: 1px solid rgba(245, 240, 224, 0.06);
    box-shadow: 8px 8px 0 rgba(0, 0, 0, 0.5);
    transform: rotate(calc(var(--rot, 0) * 1deg));
    will-change: transform;
    transition: transform 1.2s cubic-bezier(0.25, 0.1, 0.25, 1),
                top 1.2s cubic-bezier(0.25, 0.1, 0.25, 1),
                left 1.2s cubic-bezier(0.25, 0.1, 0.25, 1),
                width 1.2s cubic-bezier(0.25, 0.1, 0.25, 1);
    backface-visibility: hidden;
}

.grid-block--01 { --rot: -6;  z-index: 3; }
.grid-block--02 { --rot:  9;  z-index: 5; }
.grid-block--03 { --rot: -3;  z-index: 4; background: linear-gradient(180deg, rgba(30,28,24,0.95), rgba(94,21,21,0.18)); }
.grid-block--04 { --rot: 11;  z-index: 6; border-color: rgba(139, 32, 32, 0.5); }
.grid-block--05 { --rot: -8;  z-index: 4; }
.grid-block--06 { --rot:  5;  z-index: 7; background: linear-gradient(180deg, rgba(20,18,16,0.95), rgba(30,28,24,0.92)); }

.break-flat {
    position: absolute;
    background: var(--flat);
    box-shadow: 8px 8px 0 rgba(0, 0, 0, 0.55);
    z-index: 1;
    opacity: 0.9;
}
.break-flat--a {
    width: 600px; height: 200px;
    top: 30vh; left: 60vw;
    transform: rotate(-12deg);
    background: linear-gradient(135deg, var(--flat), var(--curtain-deep));
}
.break-flat--b {
    width: 480px; height: 240px;
    top: 90vh; left: -100px;
    transform: rotate(8deg);
    background: linear-gradient(90deg, var(--flat), #1a1815);
}
.break-flat--c {
    width: 700px; height: 160px;
    top: 130vh; left: 24vw;
    transform: rotate(-5deg);
    background: linear-gradient(180deg, var(--curtain-deep), var(--flat));
    opacity: 0.6;
}

/* When Act II resolves into Act III: blocks heal */
.broken-grid.is-resolving .grid-block {
    transform: rotate(0deg) !important;
    top: var(--healed-top, auto) !important;
    left: 0 !important;
    width: 100% !important;
    box-shadow: none;
}

/* ============================================================
   ACT III — The Exit (resolution to clarity)
   ============================================================ */

.act-iii {
    min-height: 150vh;
    background:
        radial-gradient(ellipse at 50% 0%, var(--stage) 0%, var(--void) 70%),
        var(--void);
    padding: 14vh 6vw 18vh;
    position: relative;
}

.resolution {
    max-width: 720px;
    margin: 0 auto;
    text-align: center;
    position: relative;
    z-index: 3;
    opacity: 0;
    transform: translateY(24px);
    transition: opacity 1.4s ease, transform 1.4s ease;
}
.resolution.is-visible {
    opacity: 1;
    transform: translateY(0);
}
.resolution > * + * { margin-top: 28px; }

.signature {
    margin-top: 48px;
    font-family: var(--font-meta);
    font-size: 12px;
    color: var(--backstage);
    letter-spacing: 0.25em;
    text-transform: uppercase;
}

/* ============================================================
   Three-dot act indicator (Roman numerals)
   ============================================================ */

.act-indicator {
    position: fixed;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 18px;
    z-index: 60;
    padding: 10px 18px;
    background: rgba(10, 10, 10, 0.55);
    border: 1px solid rgba(245, 240, 224, 0.08);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    border-radius: 999px;
}

.act-indicator .dot {
    width: 22px;
    height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: var(--backstage);
    transition: color 0.3s ease, transform 0.3s ease;
}
.act-indicator .dot svg { width: 100%; height: 100%; }
.act-indicator .dot text {
    font-family: var(--font-display);
    font-size: 9px;
    fill: currentColor;
}
.act-indicator .dot:hover { color: var(--cream); transform: scale(1.15); }
.act-indicator .dot.is-active { color: var(--curtain-red); transform: scale(1.25); }
.act-indicator .dot.is-active text { fill: var(--cream); }

/* ============================================================
   Responsive — disable broken grid below 768px
   ============================================================ */

@media (max-width: 768px) {
    body { cursor: auto; }
    .spotlight {
        --spotlight-radius: 80vw;
        background:
            radial-gradient(circle var(--spotlight-radius) at 50% 50%,
                rgba(245,240,224,0.10) 0%,
                rgba(245,240,224,0.04) 60%,
                rgba(0,0,0,0) 100%);
    }
    .spotlight-ring { display: none; }
    .act-i .stage-content {
        -webkit-mask-image: none;
                mask-image: none;
    }

    .display--marquee { font-size: 56px; }
    .display--marquee .line-a,
    .display--marquee .line-b,
    .display--marquee .line-c { margin-left: 0; transform: none; }

    .display--rotated { transform: none; margin: 6vh 0 0 0; font-size: 44px; }

    .body-copy--stage,
    .body-copy--bleed,
    .body-copy--bleed-right,
    .whisper--offset,
    .whisper--right,
    .stage-direction--top,
    .stage-direction--mid,
    .stage-direction--bottom {
        margin: 4vh 0 0 0;
        transform: none;
        max-width: 100%;
        padding: 0 4vw;
        text-align: left;
    }

    .broken-grid { min-height: auto; padding: 0 4vw; }
    .grid-block {
        position: static;
        width: 100% !important;
        transform: none !important;
        margin-bottom: 24px;
        box-shadow: 4px 4px 0 rgba(0,0,0,0.5);
    }
    .break-flat { display: none; }

    .stage-flat--a, .stage-flat--b, .stage-flat--c { display: none; }

    .act-marker--iii { left: 4vw; transform: none; }
}
