/* ==========================================================================
   0. DESIGN TOKENS
   ========================================================================== */
:root {
    --void: #050506;
    --obsidian: #0d0d13;
    --obsidian-2: #14141c;
    --hairline: #232330;
    --ink: #7a7786;
    --ink-dim: #4c4a56;
    --bone: #efece6;
    --frost: #2fb0ff;
    --frost-dim: rgba(47, 176, 255, 0.35);
    --ember: #c9a227;
    --ember-dim: rgba(201, 162, 39, 0.35);
    --font-display: 'Cinzel', serif;
    --font-body: 'JetBrains Mono', monospace;
    --header-size: clamp(76px, 22vw, 128px);
    --tilt-x: 50%;
    --tilt-y: 18%;
    /* Time-of-day reactive glow color (r, g, b triplet, no alpha).
       JS overrides this on load: cool arcane blue by day, warm ember gold by night.
       Default here matches the daytime frost tone. */
    --time-rgb: 47, 176, 255;
}

/* ==========================================================================
   1. CORE RESET
   ========================================================================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
}

body {
    background-color: var(--void);
    color: var(--ink);
    font-family: var(--font-body);
    min-height: 100vh;
    padding: clamp(14px, 4vw, 20px);
    overflow-x: hidden;
    position: relative;
}

a {
    color: inherit;
}

:focus-visible {
    outline: 2px solid var(--frost);
    outline-offset: 3px;
    border-radius: 2px;
}

/* ==========================================================================
   2. AMBIENT ATMOSPHERE (vignette + drifting embers)
   The first radial gradient's focal point reads from --tilt-x / --tilt-y,
   which JS updates from the device's gyroscope once ambient lighting is
   enabled. Defaults to a static top-center glow if never enabled.
   ========================================================================== */
.vignette-layer {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    transition: background 1.2s ease;
    background:
        radial-gradient(circle at var(--tilt-x) var(--tilt-y), rgba(var(--time-rgb), 0.4), transparent 16%),
        radial-gradient(ellipse at var(--tilt-x) var(--tilt-y), rgba(var(--time-rgb), 0.2), transparent 62%),
        radial-gradient(ellipse at 50% 100%, rgba(0, 0, 0, 0.8), transparent 60%),
        radial-gradient(ellipse at 50% 50%, transparent 40%, rgba(0, 0, 0, 0.5) 100%);
}

.ember-field {
    position: fixed;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    pointer-events: none;
}

.ember {
    position: absolute;
    bottom: -10px;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(var(--time-rgb), 1), rgba(var(--time-rgb), 0) 70%);
    box-shadow: 0 0 8px rgba(var(--time-rgb), 0.9), 0 0 18px rgba(var(--time-rgb), 0.5);
    animation: emberRise 9s linear infinite;
    opacity: 0;
}

.ember:nth-child(1) { left: 8%;  animation-delay: 0s;   }
.ember:nth-child(2) { left: 20%; animation-delay: 1.4s; }
.ember:nth-child(3) { left: 34%; animation-delay: 2.8s; }
.ember:nth-child(4) { left: 48%; animation-delay: 0.6s; }
.ember:nth-child(5) { left: 61%; animation-delay: 3.6s; }
.ember:nth-child(6) { left: 74%; animation-delay: 2s;   }
.ember:nth-child(7) { left: 86%; animation-delay: 4.4s; }
.ember:nth-child(8) { left: 93%; animation-delay: 1s;   }

@keyframes emberRise {
    0%   { transform: translateY(0) translateX(0); opacity: 0; }
    10%  { opacity: 1; }
    100% { transform: translateY(-100vh) translateX(12px); opacity: 0; }
}

/* ==========================================================================
   2b. ENTRANCE SEAL
   An irregular wax blob covers the page on first load each session. Tapping
   it presses it flatter and rounder like a stamp coming down, embossing the
   logo into the wax as it flattens. After a beat showing the finished seal,
   it glows and dissolves, revealing the site. Skipped entirely for repeat
   visits in the same tab session and for prefers-reduced-motion (handled
   in JS + section 14).
   ========================================================================== */
.entrance-seal-overlay {
    position: fixed;
    inset: 0;
    z-index: 3000;
    background: var(--void);
    overflow: hidden;
    transition: opacity 0.6s ease 0.15s, visibility 0.6s ease 0.15s;
}

.entrance-seal-overlay.opening {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.seal-blob {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: clamp(120px, 32vw, 170px);
    height: clamp(120px, 32vw, 170px);
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    transition: transform 0.6s ease, opacity 0.6s ease, filter 0.6s ease;
}

.entrance-seal-overlay.opening .seal-blob {
    transform: translate(-50%, -50%) scale(1.15);
    opacity: 0;
    filter: brightness(1.6);
}

.wax-base {
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 35% 30%, #e2bd6c, #b3823a 55%, #6b4a1c 100%);
    border-radius: 42% 58% 63% 37% / 41% 49% 51% 59%;
    box-shadow: inset 0 0 24px rgba(0, 0, 0, 0.5), 0 0 18px rgba(201, 162, 39, 0.2), 0 6px 18px rgba(0, 0, 0, 0.6);
    animation: blobPulse 2.6s ease-in-out infinite;
}

@keyframes blobPulse {
    0%, 100% { box-shadow: inset 0 0 24px rgba(0, 0, 0, 0.5), 0 0 18px rgba(201, 162, 39, 0.2), 0 6px 18px rgba(0, 0, 0, 0.6); }
    50%      { box-shadow: inset 0 0 24px rgba(0, 0, 0, 0.5), 0 0 34px rgba(201, 162, 39, 0.45), 0 6px 18px rgba(0, 0, 0, 0.6); }
}

.entrance-seal-overlay.stamped .wax-base {
    animation: waxPress 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes waxPress {
    0%   { border-radius: 42% 58% 63% 37% / 41% 49% 51% 59%; transform: scaleY(1);    filter: brightness(1); }
    40%  { border-radius: 48% 52% 55% 45% / 45% 45% 55% 55%; transform: scaleY(0.82); filter: brightness(1.8); }
    100% { border-radius: 50% 50% 50% 50% / 47% 47% 53% 53%; transform: scaleY(1);    filter: brightness(1); }
}

.wax-logo-impress {
    position: absolute;
    width: 62%;
    height: 62%;
    object-fit: contain;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    filter: grayscale(1) contrast(1.6) brightness(0.55);
    mix-blend-mode: overlay;
    opacity: 0;
    transition: opacity 0.35s ease 0.25s;
    pointer-events: none;
}

.entrance-seal-overlay.stamped .wax-logo-impress {
    opacity: 1;
}

.seal-hint {
    position: absolute;
    top: calc(50% + clamp(75px, 20vw, 100px));
    left: 50%;
    transform: translateX(-50%);
    font-family: var(--font-body);
    font-size: 0.62rem;
    letter-spacing: 1px;
    color: var(--ink-dim);
    text-align: center;
    white-space: nowrap;
    z-index: 1;
    transition: opacity 0.35s ease;
}

.entrance-seal-overlay.stamped .seal-hint,
.entrance-seal-overlay.opening .seal-hint {
    opacity: 0;
}

/* ==========================================================================
   3. SITE HEADER & BRAND LOGO
   ========================================================================== */
.site-header {
    position: fixed;
    top: clamp(14px, 4vw, 20px);
    left: clamp(14px, 4vw, 20px);
    z-index: 1000;
    width: var(--header-size);
    height: var(--header-size);
    display: flex;
    align-items: center;
    justify-content: center;
}

.pulsing-logo {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
    mix-blend-mode: screen;
    animation: blueFlameBreathing 3.5s infinite ease-in-out;
}

@keyframes blueFlameBreathing {
    0%   { transform: scale(1);    filter: drop-shadow(0 0 4px rgba(47, 176, 255, 0.4)) contrast(1);    opacity: 0.85; }
    50%  { transform: scale(1.04); filter: drop-shadow(0 0 22px rgba(47, 176, 255, 0.8)) contrast(1.15); opacity: 1; }
    100% { transform: scale(1);    filter: drop-shadow(0 0 4px rgba(47, 176, 255, 0.4)) contrast(1);    opacity: 0.85; }
}

/* ==========================================================================
   4. WORKSPACE CONTAINER
   ========================================================================== */
.workspace-container {
    position: relative;
    z-index: 1;
    margin-top: calc(var(--header-size) + clamp(28px, 8vw, 46px));
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    gap: clamp(20px, 5vw, 34px);
}

.vault-intro {
    font-family: var(--font-body);
    font-size: clamp(0.68rem, 2.4vw, 0.78rem);
    color: var(--ink-dim);
    text-align: center;
    letter-spacing: 0.4px;
    max-width: 320px;
    line-height: 1.6;
}

/* ==========================================================================
   5. BOOKCASE ARCHITECTURE
   ========================================================================== */
.bookcase-vault {
    width: 100%;
    max-width: 560px;
    display: flex;
    flex-direction: column;
}

.shelf-tier {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    gap: clamp(4px, 1.6vw, 8px);
    padding: 0 clamp(4px, 2vw, 10px);
    perspective: 900px;
}

.book-spine {
    flex-grow: 1;
    min-width: 38px;
    max-width: 84px;
    height: clamp(200px, 52vw, 236px);
    background: linear-gradient(180deg, #131319 0%, #0d0d13 60%, #0a0a0f 100%);
    border: 1px solid var(--hairline);
    border-radius: 3px 3px 0 0;
    position: relative;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: 14px 4px 12px;
    transition: transform 0.4s cubic-bezier(0.25, 0.8, 0.25, 1),
                background 0.4s ease, border-color 0.4s ease, box-shadow 0.4s ease;
    box-shadow: inset -6px 0 12px rgba(0, 0, 0, 0.6);
    transform-style: preserve-3d;
}

.spine-binding {
    position: absolute;
    left: 0;
    top: 0;
    width: 6px;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.02);
    border-right: 1px solid rgba(0, 0, 0, 0.4);
}

.spine-sigil {
    width: clamp(14px, 4vw, 18px);
    height: clamp(14px, 4vw, 18px);
    color: var(--ink-dim);
    transition: color 0.4s ease, filter 0.4s ease;
    flex-shrink: 0;
}

.spine-numeral {
    font-family: var(--font-display);
    font-size: clamp(0.65rem, 2vw, 0.75rem);
    color: var(--ember);
    opacity: 0.75;
    letter-spacing: 1px;
    transition: opacity 0.4s ease, text-shadow 0.4s ease;
    flex-shrink: 0;
}

.spine-text {
    writing-mode: vertical-rl;
    text-transform: uppercase;
    font-family: var(--font-body);
    font-size: clamp(0.55rem, 1.8vw, 0.63rem);
    font-weight: 500;
    letter-spacing: 1px;
    color: var(--ink-dim);
    transform: rotate(180deg);
    transition: color 0.4s ease, text-shadow 0.4s ease;
    white-space: nowrap;
    flex-shrink: 1;
    overflow: hidden;
}

.shelf-base {
    width: 100%;
    height: 10px;
    background-color: var(--obsidian-2);
    border-bottom: 4px solid #252530;
    border-top: 1px solid var(--ember-dim);
    border-radius: 2px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.65);
}

/* ==========================================================================
   6. SPINE INTERACTION STATES (hover, focus, selected)
   ========================================================================== */
.book-spine:hover,
.book-spine:focus-visible {
    transform: translateY(-12px) rotateX(4deg);
    background: linear-gradient(180deg, #181022 0%, #120c1a 60%, #0d0a12 100%);
    border-color: var(--frost);
    box-shadow: 0 12px 26px rgba(0, 0, 0, 0.55), 0 0 20px var(--frost-dim), inset -6px 0 12px rgba(0, 0, 0, 0.3);
}

.book-spine:active {
    transform: translateY(-6px) scale(0.99);
}

.book-spine:hover .spine-text,
.book-spine:focus-visible .spine-text,
.book-spine.is-selected .spine-text {
    color: var(--bone);
    text-shadow: 0 0 8px var(--frost), 0 0 16px var(--frost-dim);
}

.book-spine:hover .spine-sigil,
.book-spine:focus-visible .spine-sigil,
.book-spine.is-selected .spine-sigil {
    color: var(--frost);
    filter: drop-shadow(0 0 6px var(--frost-dim));
}

.book-spine.is-selected {
    border-color: var(--ember);
    box-shadow: 0 12px 26px rgba(0, 0, 0, 0.55), 0 0 16px var(--ember-dim), inset -6px 0 12px rgba(0, 0, 0, 0.3);
}

.book-spine.is-selected .spine-numeral {
    opacity: 1;
    text-shadow: 0 0 10px var(--ember-dim);
}

/* ==========================================================================
   7. CONTENT DRAWER (smooth grid-based unfurl)
   ========================================================================== */
.panels-display-deck {
    position: relative;
    width: 100%;
    max-width: 480px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
}

.vault-content-panel {
    width: 100%;
    flex-shrink: 0;
    display: grid;
    grid-template-rows: 0fr;
    position: relative;
    border-radius: 4px;
    opacity: 0;
    border: 1px solid transparent;
    overflow: hidden;
    /* Aged vellum page: gutter shadow, warm stains, candlelit vignette, base tone */
    background-image:
        linear-gradient(90deg, rgba(0, 0, 0, 0.4) 0%, rgba(0, 0, 0, 0) 6%),
        radial-gradient(ellipse at 15% 8%, rgba(160, 128, 84, 0.1), transparent 50%),
        radial-gradient(ellipse at 85% 95%, rgba(110, 88, 60, 0.12), transparent 55%),
        radial-gradient(ellipse at 50% 45%, transparent 55%, rgba(0, 0, 0, 0.4) 100%),
        linear-gradient(180deg, #1d1811 0%, #17130d 55%, #120f0a 100%);
    transition: grid-template-rows 0.55s cubic-bezier(0.25, 0.8, 0.25, 1),
                opacity 0.4s ease, border-color 0.4s ease;
}

/* Subtle paper grain, generated — no image asset needed */
.vault-content-panel::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
    opacity: 0.05;
    mix-blend-mode: overlay;
    pointer-events: none;
}

/* Curled corner, bottom-right — fades in only once the page is open */
.vault-content-panel::after {
    content: '';
    position: absolute;
    right: 0;
    bottom: 0;
    width: 26px;
    height: 26px;
    background: linear-gradient(135deg, rgba(30, 24, 18, 0) 45%, rgba(8, 6, 5, 0.55) 46%, rgba(70, 56, 40, 0.85) 60%, rgba(8, 6, 5, 0.35) 100%);
    clip-path: polygon(100% 100%, 0 100%, 100% 0);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.5s ease 0.15s;
}

.vault-content-panel.open::after {
    opacity: 1;
}

.vault-content-panel.open {
    opacity: 1;
    grid-template-rows: 1fr;
    border: 1px solid var(--hairline);
    border-top: 2px solid var(--ember);
    box-shadow: 0 18px 34px rgba(0, 0, 0, 0.5);
}

/* Warmer, candlelit ink tones for text specifically on the open page —
   the rest of the site stays cool/arcane, only the page itself goes warm */
.vault-content-panel .panel-title {
    color: #f1e6d2;
}

.vault-content-panel .panel-description {
    color: #a89a86;
}

.panel-interior {
    overflow: hidden;
    min-height: 0;
    padding: 0 22px;
    transition: padding 0.5s ease;
}

.vault-content-panel.open .panel-interior {
    padding: 24px 22px 26px;
}

.panel-eyebrow {
    display: block;
    font-family: var(--font-body);
    font-size: 0.62rem;
    letter-spacing: 2px;
    color: var(--ember);
    text-transform: uppercase;
    margin-bottom: 6px;
}

/* ==========================================================================
   7b. INK-DRAW TITLE REVEAL
   Titles start clipped to zero width; the .ink-draw class (re-applied by
   JS every time a panel opens) animates them open left-to-right, with a
   thin glowing "nib" leading the reveal, as if freshly inked.
   ========================================================================== */
.panel-title {
    font-family: var(--font-display);
    font-size: clamp(1.15rem, 5vw, 1.4rem);
    font-weight: 600;
    color: var(--bone);
    letter-spacing: 1px;
    margin-bottom: 14px;
    position: relative;
    display: inline-block;
    clip-path: inset(0 100% 0 0);
}

.panel-title.ink-draw {
    animation: inkReveal 0.9s cubic-bezier(0.65, 0, 0.35, 1) forwards;
}

.panel-title.ink-draw::after {
    content: '';
    position: absolute;
    top: 2px;
    bottom: 2px;
    left: 0;
    width: 2px;
    background: linear-gradient(180deg, var(--frost), var(--ember));
    box-shadow: 0 0 8px var(--frost-dim), 0 0 14px var(--ember-dim);
    animation: inkCursor 0.9s cubic-bezier(0.65, 0, 0.35, 1) forwards;
}

@keyframes inkReveal {
    to { clip-path: inset(0 0 0 0); }
}

@keyframes inkCursor {
    to { left: 100%; opacity: 0; }
}

.panel-description {
    font-family: var(--font-body);
    font-size: 0.78rem;
    line-height: 1.7;
    color: var(--ink);
    margin-bottom: 20px;
    max-width: 60ch;
}

/* ==========================================================================
   8. MOVIE POSTER MEDIA FRAME
   ========================================================================== */
.media-frame {
    width: 100%;
    max-width: 280px;
    margin: 6px auto 0 auto;
    border-radius: 4px;
    overflow: hidden;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.75);
    border: 1px solid var(--hairline);
    position: relative;
}

.media-frame::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 8px;
    width: 16px;
    height: 16px;
    border-top: 1px solid var(--ember-dim);
    border-left: 1px solid var(--ember-dim);
    z-index: 2;
    pointer-events: none;
}

.media-frame::after {
    content: '';
    position: absolute;
    bottom: 8px;
    right: 8px;
    width: 16px;
    height: 16px;
    border-bottom: 1px solid var(--ember-dim);
    border-right: 1px solid var(--ember-dim);
    z-index: 2;
    pointer-events: none;
}

.poster-link {
    display: block;
    cursor: zoom-in;
    transition: transform 0.4s ease, filter 0.4s ease;
}

.poster-link:hover,
.poster-link:focus-visible {
    transform: scale(1.02);
    filter: brightness(1.08);
}

.panel-poster {
    width: 100%;
    height: auto;
    display: block;
    object-fit: contain;
}

.poster-caption {
    text-align: center;
    font-family: var(--font-body);
    font-size: 0.66rem;
    letter-spacing: 0.5px;
    color: var(--ink-dim);
    margin: 10px 0 20px;
}

/* ==========================================================================
   9. ABOUT / EMAIL BLOCK
   ========================================================================== */
.email-block {
    margin-top: 4px;
    border-top: 1px solid var(--hairline);
    padding-top: 15px;
}

.site-email-link {
    color: var(--frost);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.85rem;
    transition: text-shadow 0.3s ease, color 0.3s ease;
}

.site-email-link:hover,
.site-email-link:focus-visible {
    text-shadow: 0 0 8px var(--frost), 0 0 16px var(--frost-dim);
    color: var(--bone);
}

/* ==========================================================================
   10. FOOTER & TILT-LIGHTING TOGGLE
   ========================================================================== */
.site-footer {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin-top: clamp(30px, 8vw, 50px);
    padding-bottom: 10px;
}

.site-footer-copy {
    font-family: var(--font-body);
    font-size: 0.62rem;
    letter-spacing: 1px;
    color: var(--ink-dim);
}

.tilt-toggle {
    background: none;
    border: 1px solid var(--hairline);
    color: var(--ink-dim);
    font-family: var(--font-body);
    font-size: 0.62rem;
    letter-spacing: 0.5px;
    padding: 7px 14px;
    border-radius: 20px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    transition: color 0.3s ease, border-color 0.3s ease, opacity 0.4s ease;
}

.tilt-toggle svg {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
}

.tilt-toggle:hover,
.tilt-toggle:focus-visible {
    color: var(--frost);
    border-color: var(--frost-dim);
}

.tilt-toggle.is-active {
    color: var(--ember);
    border-color: var(--ember-dim);
}

.tilt-toggle[hidden] {
    display: none;
}

/* ==========================================================================
   11. SMALL-SCREEN SAFETY NET
   ========================================================================== */
@media (max-width: 360px) {
    :root {
        --header-size: clamp(64px, 20vw, 96px);
    }
    .shelf-tier {
        gap: 3px;
        padding: 0 3px;
    }
    .book-spine {
        min-width: 34px;
        padding: 10px 2px 8px;
    }
    .spine-text {
        font-size: 0.5rem;
    }
    .spine-sigil {
        width: 13px;
        height: 13px;
    }
}

/* ==========================================================================
   12. LARGER VIEWPORTS (tablet / desktop enhancement)
   ========================================================================== */
@media (min-width: 700px) {
    .bookcase-vault {
        max-width: 620px;
    }
    .book-spine {
        max-width: 96px;
        height: 260px;
    }
    .panels-display-deck {
        max-width: 540px;
    }
    .panel-title {
        font-size: 1.6rem;
    }
}

/* ==========================================================================
   13. REDUCED MOTION
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
    .pulsing-logo,
    .ember {
        animation: none !important;
    }
    .book-spine,
    .vault-content-panel,
    .poster-link,
    .panel-interior {
        transition-duration: 0.01ms !important;
    }
    .panel-title {
        clip-path: none !important;
    }
    .panel-title.ink-draw::after {
        display: none !important;
    }
    .entrance-seal-overlay {
        display: none !important;
    }
}
