/* ==========================================================================
   JJUGGL.dev — A Specimen Book of Imagined Developer-Creatures
   pixel-art INSIDE frost glass OVER watercolor washes
   Layout cues honored: marginalia/IntersectionObserver. eviction, sticky pins.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Tokens
   -------------------------------------------------------------------------- */
:root {
    /* Palette (translucent-frost over watercolor base) */
    --vellum-cream: #f3ede0;
    --frost-white: rgba(248, 246, 240, 0.42);
    --frost-edge: rgba(255, 255, 255, 0.18);
    --frost-highlight: rgba(255, 255, 255, 0.5);
    --pure-white: #ffffff;
    --ink-cobalt: #1a1f2e;
    --watercolor-cobalt: #3b5a8a;
    --watercolor-rust: #b85c3a;
    --watercolor-moss: #5a7a52;
    --marginalia-bronze: #b8a888;
    --pixel-highlight: #f7e6c4;
    --caption-slate: #4a5a7a;

    /* Type */
    --font-display: 'Cormorant Garamond', 'Cormorant', Georgia, 'Inter', serif;
    --font-body: 'EB Garamond', 'Cormorant Garamond', Georgia, 'Inter', serif;
    --font-korean: 'Nanum Myeongjo', 'Cormorant Garamond', Georgia, 'Inter', serif;
    --font-pixel: 'Press Start 2P', 'Inter', monospace;

    /* Layout */
    --marginalia-w: 240px;
    --plate-vpad: 8vh;
    --plate-h: 110vh;

    /* Motion */
    --ease-paper: cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* --------------------------------------------------------------------------
   Reset / base
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
    background: var(--vellum-cream);
}

body.vellum {
    font-family: var(--font-body);
    color: var(--ink-cobalt);
    background-color: var(--vellum-cream);
    background-image:
        radial-gradient(circle at 20% 12%, rgba(184, 168, 136, 0.06), transparent 55%),
        radial-gradient(circle at 80% 70%, rgba(74, 90, 122, 0.05), transparent 55%),
        repeating-linear-gradient(
            0deg,
            transparent 0px,
            transparent 2px,
            rgba(184, 168, 136, 0.018) 2px,
            rgba(184, 168, 136, 0.018) 3px
        );
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.7;
    cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' shape-rendering='crispEdges'><rect x='2' y='2' width='1' height='1' fill='%231a1f2e'/><rect x='3' y='3' width='1' height='1' fill='%231a1f2e'/><rect x='4' y='4' width='1' height='1' fill='%231a1f2e'/><rect x='5' y='5' width='1' height='1' fill='%231a1f2e'/><rect x='6' y='6' width='1' height='1' fill='%231a1f2e'/><rect x='7' y='7' width='1' height='1' fill='%23b8a888'/><rect x='8' y='8' width='1' height='1' fill='%23b8a888'/><rect x='9' y='9' width='1' height='1' fill='%231a1f2e'/><rect x='10' y='10' width='1' height='1' fill='%231a1f2e'/><rect x='11' y='11' width='1' height='1' fill='%231a1f2e'/><rect x='12' y='12' width='1' height='1' fill='%231a1f2e'/></svg>") 2 2, default;
}

a, button, summary, details, [role="button"] {
    cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' shape-rendering='crispEdges'><rect x='5' y='3' width='6' height='1' fill='%231a1f2e'/><rect x='4' y='4' width='1' height='5' fill='%231a1f2e'/><rect x='11' y='4' width='1' height='5' fill='%231a1f2e'/><rect x='5' y='9' width='6' height='1' fill='%231a1f2e'/><rect x='6' y='5' width='4' height='3' fill='%23b85c3a'/><rect x='6' y='10' width='4' height='3' fill='%231a1f2e'/></svg>") 8 8, pointer;
}

img, svg.wash {
    display: block;
    max-width: 100%;
}

.svg-defs {
    position: absolute;
    width: 0;
    height: 0;
    pointer-events: none;
}

/* --------------------------------------------------------------------------
   Plate skeleton (editorial-flow, asymmetric two-column grid)
   -------------------------------------------------------------------------- */
.plate {
    position: relative;
    display: grid;
    grid-template-columns: var(--marginalia-w) 1fr;
    gap: 4vw;
    min-height: var(--plate-h);
    padding: var(--plate-vpad) clamp(24px, 6vw, 96px);
    /* no overflow:hidden -- allows position:sticky to work */
}

.plate--hero {
    min-height: 100vh;
    align-items: center;
}

.plate--colophon {
    min-height: 90vh;
    align-items: center;
    padding-bottom: 18vh;
}

/* --------------------------------------------------------------------------
   Marginalia (left column: Roman numeral, Korean subtitle, hairline rule)
   -------------------------------------------------------------------------- */
.plate__marginalia {
    position: sticky;
    top: 12vh;
    align-self: start;
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding-right: 26px;
    border-right: 1px solid rgba(184, 168, 136, 0.3);
    min-height: 60vh;
    transition: opacity 400ms var(--ease-paper), transform 400ms var(--ease-paper);
    list-style: none;
}

.plate__marginalia::-webkit-details-marker {
    display: none;
}

.plate__marginalia.is-evicting {
    transform: translateY(-20px);
    opacity: 0;
}

.plate__numeral {
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 300;
    font-size: clamp(3rem, 6vw, 5rem);
    color: var(--marginalia-bronze);
    letter-spacing: -0.02em;
    line-height: 1;
}

.plate__korean {
    font-family: var(--font-korean);
    font-weight: 400;
    font-size: 1.05rem;
    color: var(--caption-slate);
    line-height: 1.45;
    letter-spacing: 0;
}

.plate__rule {
    width: 1px;
    height: 28vh;
    background: linear-gradient(
        to bottom,
        rgba(184, 168, 136, 0.3) 0%,
        rgba(184, 168, 136, 0.3) 100%
    );
    background-size: 100% 200%;
    background-position: 0 0;
    transition: background-position 2000ms linear;
    margin-top: 8px;
}

.plate:hover .plate__rule,
.plate-details:hover .plate__rule {
    background-image: linear-gradient(
        to bottom,
        rgba(184, 168, 136, 0.3) 0%,
        rgba(184, 168, 136, 0.3) 35%,
        rgba(184, 168, 136, 0.85) 50%,
        rgba(184, 168, 136, 0.3) 65%,
        rgba(184, 168, 136, 0.3) 100%
    );
    background-size: 100% 220%;
    background-position: 0 100%;
}

.plate__hint {
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 400;
    font-size: 0.95rem;
    color: var(--caption-slate);
    opacity: 0.7;
    margin-top: 14px;
    transition: opacity 300ms ease;
}

details[open] .plate__hint {
    opacity: 0;
    pointer-events: none;
}

/* --------------------------------------------------------------------------
   Plate body (right column: wash + sprite + frost caption)
   -------------------------------------------------------------------------- */
.plate__body {
    position: relative;
    display: grid;
    grid-template-columns: 1fr;
    gap: 32px;
    align-items: start;
}

.plate__wash-stage {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    max-width: 560px;
    margin: 0 auto;
    display: grid;
    place-items: center;
}

.plate--hero .plate__body--hero {
    grid-template-columns: 1fr;
    gap: 48px;
    align-items: center;
}

.plate--hero .plate__wash-stage {
    max-width: 720px;
}

/* Watercolor wash (SVG with filtered circle) */
.wash {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
}

.plate--hero .wash {
    transform: scale(1.05);
}

/* Watermark (Korean syllable behind the panel) */
.watermark {
    position: absolute;
    right: 4%;
    top: 4%;
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 300;
    font-size: 140px;
    color: var(--ink-cobalt);
    opacity: 0.06;
    pointer-events: none;
    z-index: 2;
    line-height: 1;
}

.colophon-watermark {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 300;
    font-size: 200px;
    color: var(--ink-cobalt);
    opacity: 0.06;
    pointer-events: none;
    z-index: 1;
    line-height: 1;
}

/* --------------------------------------------------------------------------
   Pixel sprites (CSS box-shadow, 1px x 1px element scaled with transform)
   -------------------------------------------------------------------------- */
.sprite {
    position: relative;
    width: 1px;
    height: 1px;
    transform: scale(8);
    transform-origin: center center;
    z-index: 3;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    /* The actual box-shadow value is set via JS for each sprite-id */
}

.sprite--xl {
    transform: scale(11);
}

@media (max-width: 720px) {
    .sprite {
        transform: scale(6);
    }
    .sprite--xl {
        transform: scale(8);
    }
}

/* Stamp animation for sprite phase 2 (pixel-discrete, no easing) */
@keyframes sprite-stamp {
    0% {
        transform: scale(7.5);
        opacity: 0;
    }
    50% {
        transform: scale(7.5);
        opacity: 0;
    }
    51% {
        transform: scale(8);
        opacity: 1;
    }
    100% {
        transform: scale(8);
        opacity: 1;
    }
}

@keyframes sprite-stamp-xl {
    0% {
        transform: scale(10.5);
        opacity: 0;
    }
    50% {
        transform: scale(10.5);
        opacity: 0;
    }
    51% {
        transform: scale(11);
        opacity: 1;
    }
    100% {
        transform: scale(11);
        opacity: 1;
    }
}

.plate-details[open] .sprite,
.plate--hero .sprite {
    animation: sprite-stamp 450ms steps(1, end) forwards;
}

.plate--hero .sprite--xl {
    animation: sprite-stamp-xl 600ms steps(1, end) forwards;
}

/* --------------------------------------------------------------------------
   Frost glass panels
   -------------------------------------------------------------------------- */
.frost {
    position: relative;
    background: var(--frost-white);
    backdrop-filter: blur(28px) saturate(140%);
    -webkit-backdrop-filter: blur(28px) saturate(140%);
    border: 1px solid var(--frost-edge);
    border-radius: 4px;
    box-shadow:
        0 1px 0 var(--frost-highlight) inset,
        0 12px 40px rgba(26, 31, 46, 0.08);
    padding: clamp(28px, 4vw, 48px);
    z-index: 4;
}

.frost--hero {
    margin-top: -120px;
    width: min(720px, 92%);
    margin-left: auto;
    margin-right: auto;
    text-align: left;
}

.frost--colophon {
    width: min(640px, 92%);
    margin-left: auto;
    margin-right: auto;
    text-align: center;
    position: relative;
    z-index: 4;
}

.plate__caption {
    width: 100%;
    max-width: 640px;
    margin: -64px auto 0;
}

/* --------------------------------------------------------------------------
   Typography on the plates
   -------------------------------------------------------------------------- */
.hero-title {
    font-family: var(--font-display);
    font-weight: 300;
    font-size: clamp(4rem, 11vw, 9rem);
    letter-spacing: -0.04em;
    color: var(--ink-cobalt);
    line-height: 0.95;
    margin-bottom: 18px;
}

.hero-subtitle {
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 400;
    font-size: 1.25rem;
    color: var(--ink-cobalt);
    opacity: 0.84;
    line-height: 1.55;
    margin-bottom: 18px;
    max-width: 560px;
}

.hero-pixel-caption {
    font-family: var(--font-pixel);
    font-size: 0.6rem;
    letter-spacing: 0.06em;
    color: var(--caption-slate);
    margin-bottom: 16px;
    line-height: 1.6;
}

.hero-scrollhint {
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 400;
    font-size: 1rem;
    color: var(--caption-slate);
    opacity: 0.7;
    margin-top: 24px;
    animation: gentle-bob 3s ease-in-out infinite;
}

@keyframes gentle-bob {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(4px); }
}

.plate__title-row {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 14px;
}

.plate__title-roman {
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 400;
    font-size: 1rem;
    color: var(--marginalia-bronze);
    letter-spacing: 0.02em;
}

.plate__title {
    font-family: var(--font-display);
    font-weight: 300;
    font-size: clamp(2.4rem, 5vw, 4.2rem);
    color: var(--ink-cobalt);
    line-height: 1.05;
    letter-spacing: -0.015em;
}

.plate__cursive {
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 400;
    font-size: 1.15rem;
    color: var(--ink-cobalt);
    opacity: 0.9;
    line-height: 1.5;
    margin-bottom: 18px;
}

.plate__body-text {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: 1.05rem;
    line-height: 1.7;
    color: var(--ink-cobalt);
    opacity: 0.88;
    margin-bottom: 20px;
}

.pixel-caption,
.hero-pixel-caption,
.colophon-pixel {
    font-family: var(--font-pixel);
    font-size: 0.6rem;
    letter-spacing: 0.06em;
    color: var(--caption-slate);
    line-height: 1.7;
    text-transform: lowercase;
}

.colophon-title {
    font-family: var(--font-display);
    font-weight: 400;
    font-style: italic;
    font-size: 2rem;
    color: var(--ink-cobalt);
    margin-bottom: 18px;
}

.colophon-text {
    font-family: var(--font-body);
    font-size: 1.05rem;
    line-height: 1.75;
    color: var(--ink-cobalt);
    opacity: 0.88;
    margin-bottom: 14px;
}

.colophon-text code {
    font-family: var(--font-pixel);
    font-size: 0.6rem;
    background: rgba(74, 90, 122, 0.08);
    padding: 2px 6px;
    border-radius: 2px;
    color: var(--caption-slate);
    letter-spacing: 0.06em;
}

.pixel-text {
    font-family: var(--font-pixel);
    font-size: 0.6rem;
    letter-spacing: 0.06em;
    color: var(--caption-slate);
    text-transform: lowercase;
}

.colophon-place {
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 400;
    font-size: 1.1rem;
    color: var(--marginalia-bronze);
    margin: 22px 0 16px;
}

.colophon-pixel {
    margin-top: 14px;
}

/* --------------------------------------------------------------------------
   Progressive-disclosure plates (<details> styled to suppress triangle)
   -------------------------------------------------------------------------- */
.plate-details {
    display: contents;
}

.plate-details summary {
    list-style: none;
}

.plate-details summary::-webkit-details-marker,
.plate-details summary::marker {
    display: none;
    content: '';
}

/* Unfold animation phases:
   phase 1: wash (0 -> 300ms)
   phase 2: sprite stamp (300 -> 450ms, no easing)
   phase 3: frost-glass caption slide up (450 -> 900ms)
*/
.plate-details .plate__body {
    /* Folded state: only marginalia visible */
    grid-template-rows: 0fr;
    transition: grid-template-rows 0ms;
}

.plate-details:not([open]) .plate__body {
    /* While folded, hide the body content */
    overflow: hidden;
    max-height: 0;
    opacity: 0;
    pointer-events: none;
    transition:
        max-height 400ms ease,
        opacity 300ms ease;
}

.plate-details[open] .plate__body {
    max-height: 2000px;
    opacity: 1;
    pointer-events: auto;
    overflow: visible;
    transition: max-height 600ms var(--ease-paper), opacity 400ms ease;
}

.plate-details[open] .plate__wash-stage .wash {
    animation: wash-fade-in 300ms ease-out forwards;
}

@keyframes wash-fade-in {
    from { opacity: 0; transform: scale(0.92); }
    to { opacity: 1; transform: scale(1); }
}

.plate-details[open] .plate__caption {
    animation: caption-rise 450ms 450ms var(--ease-paper) backwards;
}

@keyframes caption-rise {
    from { transform: translateY(36px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* Click-to-fold cursor on summary */
.plate-details summary {
    cursor: pointer;
}

/* JS fallback class -- mirrors [open] state */
.plate-details.is-open .plate__body {
    max-height: 2000px;
    opacity: 1;
    pointer-events: auto;
    overflow: visible;
}

/* --------------------------------------------------------------------------
   Hero plate (always unfolded)
   -------------------------------------------------------------------------- */
.plate--hero .plate__body--hero {
    overflow: visible;
    max-height: none;
    opacity: 1;
}

/* --------------------------------------------------------------------------
   Footnote reveal (3-second hold easter egg)
   -------------------------------------------------------------------------- */
.footnote-reveal {
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px dashed rgba(184, 168, 136, 0.35);
    font-family: var(--font-display);
    font-style: italic;
    font-size: 0.95rem;
    color: var(--caption-slate);
    opacity: 0;
    max-height: 0;
    overflow: hidden;
    transition:
        opacity 600ms ease,
        max-height 600ms var(--ease-paper),
        padding-top 400ms ease,
        margin-top 400ms ease;
}

.footnote-reveal.is-visible {
    opacity: 1;
    max-height: 200px;
}

/* --------------------------------------------------------------------------
   Ornaments (16x16 pixel dividers between plates)
   -------------------------------------------------------------------------- */
.ornament {
    display: block;
    width: 16px;
    height: 16px;
    margin: 4vh auto;
    transform: scale(2);
    transform-origin: center center;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    opacity: 0.7;
    /* box-shadow set via JS based on data-icon */
    background-color: transparent;
    /* tiny canvas root */
    position: relative;
}

.ornament::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    width: 1px;
    height: 1px;
    background: transparent;
    /* JS sets box-shadow on this pseudo? -- no, we set on the element directly */
}

/* --------------------------------------------------------------------------
   Reading-progress hairline (right edge)
   -------------------------------------------------------------------------- */
.progress-rail {
    position: fixed;
    top: 0;
    right: 6px;
    width: 1px;
    height: 100vh;
    background: rgba(184, 168, 136, 0.18);
    z-index: 40;
    pointer-events: none;
}

.progress-rail__fill {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 0;
    background: rgba(184, 168, 136, 0.7);
    transition: height 200ms linear;
}

/* --------------------------------------------------------------------------
   Ambient toggle (frost-panel toggle in bottom-right, off by default)
   -------------------------------------------------------------------------- */
.ambient-toggle {
    position: fixed;
    right: 22px;
    bottom: 22px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    background: var(--frost-white);
    backdrop-filter: blur(20px) saturate(140%);
    -webkit-backdrop-filter: blur(20px) saturate(140%);
    border: 1px solid var(--frost-edge);
    border-radius: 4px;
    box-shadow:
        0 1px 0 var(--frost-highlight) inset,
        0 6px 18px rgba(26, 31, 46, 0.08);
    font-family: var(--font-pixel);
    font-size: 0.55rem;
    color: var(--caption-slate);
    text-transform: lowercase;
    letter-spacing: 0.06em;
    z-index: 30;
    transition: transform 300ms var(--ease-paper);
}

.ambient-toggle:hover {
    transform: translateY(-2px);
}

.ambient-toggle__dot {
    width: 6px;
    height: 6px;
    background: var(--marginalia-bronze);
    border-radius: 50%;
    box-shadow: 0 0 0 1px rgba(184, 168, 136, 0.3);
    transition: background-color 200ms ease, box-shadow 200ms ease;
}

.ambient-toggle[data-state="on"] .ambient-toggle__dot {
    background: var(--watercolor-moss);
    box-shadow: 0 0 0 1px rgba(90, 122, 82, 0.4), 0 0 8px rgba(90, 122, 82, 0.5);
}

/* --------------------------------------------------------------------------
   Mobile (below 720px): collapse marginalia above content
   -------------------------------------------------------------------------- */
@media (max-width: 720px) {
    .plate {
        grid-template-columns: 1fr;
        gap: 24px;
        min-height: auto;
        padding: 6vh 18px 4vh;
    }

    .plate__marginalia {
        position: static;
        flex-direction: row;
        align-items: baseline;
        gap: 16px;
        padding-right: 0;
        padding-bottom: 14px;
        border-right: none;
        border-bottom: 1px solid rgba(184, 168, 136, 0.3);
        min-height: auto;
        flex-wrap: wrap;
    }

    .plate__rule {
        display: none;
    }

    .plate__numeral {
        font-size: 2.4rem;
    }

    .plate__korean {
        font-size: 0.95rem;
    }

    .plate__hint {
        flex-basis: 100%;
        margin-top: 0;
    }

    .plate__wash-stage {
        max-width: 320px;
    }

    .frost {
        padding: 22px;
        backdrop-filter: blur(14px) saturate(130%);
        -webkit-backdrop-filter: blur(14px) saturate(130%);
    }

    .frost--hero {
        margin-top: -50px;
    }

    .plate__caption {
        margin-top: -32px;
    }

    .hero-title {
        font-size: clamp(2.8rem, 14vw, 5rem);
        letter-spacing: -0.03em;
    }

    .progress-rail {
        right: 2px;
    }

    .watermark {
        font-size: 80px;
    }

    .colophon-watermark {
        font-size: 120px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }

    .plate-details[open] .sprite {
        opacity: 1;
        transform: scale(8);
    }

    .plate-details[open] .plate--hero .sprite--xl {
        transform: scale(11);
    }
}
