/* ============================================
   XANADU.WIKI - Victorian Mechanical Encyclopedia
   Chrome-Metallic Palette | Diagonal Layout
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    /* Chrome-Metallic Palette */
    --polished-steel: #C0C0C0;
    --brushed-nickel: #A0A0A0;
    --gunmetal: #2C2C2C;
    --white-gold: #E8E0D0;
    --verdigris: #5A7A6A;
    --carbon-steel: #404040;
    --anthracite: #1A1A1A;
    --platinum-mist: #E8E8E8;
    --aged-brass: #B8976A;
    --oxidized-copper: #6B8F71;

    /* Extended palette */
    --chrome-mid: #A8A8A8;
    --chrome-light: #D8D8D8;
    --chrome-highlight: #C8C8C8;
    --chrome-border: #909090;
    --chrome-node: #D4D4D4;
    --chrome-dark: #707070;
    --chrome-surface: #B0B0B0;
    --chrome-bg: #B8B8B8;
    --chrome-deep: #8A8A8A;

    /* Diagonal angle */
    --diagonal-angle: 12deg;
    --diagonal-tan: 0.2126; /* tan(12deg) */

    /* Typography sizes */
    --title-size: clamp(2.8rem, 6vw, 5.2rem);
    --heading-size: clamp(1.8rem, 3.5vw, 3rem);
    --subheading-size: clamp(1.2rem, 2vw, 1.6rem);
    --body-size: clamp(1rem, 1.8vw, 1.15rem);
}

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

html {
    scroll-behavior: smooth;
    overflow-x: hidden;
}

body {
    font-family: 'Lora', Georgia, serif;
    font-size: var(--body-size);
    font-weight: 400;
    line-height: 1.72;
    letter-spacing: 0.015em;
    color: var(--anthracite);
    background: var(--polished-steel);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* --- Brushed Metal Texture Base --- */
.tier {
    position: relative;
    overflow: hidden;
}

.tier::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        repeating-linear-gradient(90deg, transparent, transparent 2px, rgba(255,255,255,0.03) 2px, rgba(255,255,255,0.03) 4px);
    pointer-events: none;
    z-index: 1;
}

/* --- Diagonal Rule (Persistent Spine) --- */
#diagonal-rule {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 100;
}

#diagonal-rule::before {
    content: '';
    position: absolute;
    top: -20%;
    left: 50%;
    width: 1px;
    height: 140%;
    background: var(--chrome-border);
    transform-origin: top center;
    transform: rotate(var(--diagonal-angle));
    opacity: 0.5;
}

.node-marker {
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--chrome-node);
    border: 1px solid var(--chrome-dark);
    left: 50%;
    transform: translateX(-50%);
    transition: background 0.4s ease, transform 0.4s ease;
}

.node-marker[data-tier="1"] { top: 10%; }
.node-marker[data-tier="2"] { top: 28%; }
.node-marker[data-tier="3"] { top: 48%; }
.node-marker[data-tier="4"] { top: 68%; }
.node-marker[data-tier="5"] { top: 88%; }

.node-marker.active {
    background: var(--aged-brass);
    border-color: var(--aged-brass);
    transform: translateX(-50%) scale(1.4);
}

/* Gear pairs on node markers */
.node-marker::before,
.node-marker::after {
    content: '';
    position: absolute;
    width: 12px;
    height: 12px;
    border: 1px solid var(--chrome-dark);
    border-radius: 50%;
    top: -2px;
    opacity: 0.4;
}

.node-marker::before {
    left: -14px;
    border-style: dashed;
    animation: gearCW 8s linear infinite paused;
}

.node-marker::after {
    right: -14px;
    border-style: dashed;
    animation: gearCCW 8s linear infinite paused;
}

.node-marker.active::before {
    animation-play-state: running;
    opacity: 0.7;
}

.node-marker.active::after {
    animation-play-state: running;
    opacity: 0.7;
}

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

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

/* --- Lens Flare Container --- */
#lens-flare-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 999;
}

.lens-flare {
    position: absolute;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.4s ease;
}

.lens-flare.visible {
    opacity: 1;
}

.lens-flare.fading {
    opacity: 0;
    transition: opacity 0.8s ease;
}

/* Core bloom */
.lens-flare .bloom {
    position: absolute;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255,255,240,0.4) 0%, transparent 70%);
    transform: translate(-50%, -50%) scale(0.8);
    transition: transform 0.6s ease;
}

.lens-flare.visible .bloom {
    transform: translate(-50%, -50%) scale(1.2);
}

/* Anamorphic streak */
.lens-flare .streak {
    position: absolute;
    width: 80vw;
    height: 3px;
    background: linear-gradient(90deg, transparent 0%, rgba(200,200,220,0.15) 30%, rgba(200,200,220,0.2) 50%, rgba(200,200,220,0.15) 70%, transparent 100%);
    transform: translate(-50%, -50%);
    top: 0;
    left: 0;
}

/* Ghost rings */
.lens-flare .ghost-ring {
    position: absolute;
    border-radius: 50%;
    background: transparent;
    border: 1px solid rgba(255,255,255,0.06);
    box-shadow: inset 0 0 8px rgba(180,200,210,0.08);
    transform: translate(-50%, -50%);
}

.lens-flare .ghost-ring:nth-child(3) {
    width: 80px;
    height: 80px;
}

.lens-flare .ghost-ring:nth-child(4) {
    width: 160px;
    height: 160px;
}

.lens-flare .ghost-ring:nth-child(5) {
    width: 240px;
    height: 240px;
}

/* --- TIER 1: The Portico --- */
.tier-1 {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--polished-steel) 0%, var(--chrome-light) 25%, var(--chrome-mid) 50%, var(--chrome-deep) 75%, var(--chrome-surface) 100%);
    clip-path: polygon(0 0, 100% 0, calc(100% - 4vw) 100%, 0 100%);
    padding: 4rem 2rem;
}

.tier-1 .tier-inner {
    position: relative;
    z-index: 2;
    text-align: center;
    max-width: 800px;
}

/* Compass Rose */
.compass-rose {
    position: relative;
    width: 160px;
    height: 160px;
    margin: 0 auto 2rem;
}

.compass-rose svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.compass-outer {
    animation: rotateCW 120s linear infinite;
}

.compass-inner {
    animation: rotateCCW 200s linear infinite;
}

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

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

/* Site Title */
.site-title {
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 900;
    font-size: var(--title-size);
    letter-spacing: 0.12em;
    line-height: 1.1;
    color: var(--anthracite);
    text-rendering: optimizeLegibility;
    font-feature-settings: 'liga' 1, 'kern' 1;
    margin-bottom: 0.3rem;
}

.site-subtitle {
    font-family: 'Lora', Georgia, serif;
    font-style: italic;
    font-size: var(--subheading-size);
    color: var(--carbon-steel);
    letter-spacing: 0.08em;
    margin-bottom: 2.5rem;
}

.epigraph {
    font-family: 'Lora', Georgia, serif;
    font-style: italic;
    font-size: var(--body-size);
    color: var(--carbon-steel);
    line-height: 1.72;
    border-left: 2px solid var(--aged-brass);
    padding-left: 1.5rem;
    display: inline-block;
    text-align: left;
}

.epigraph cite {
    display: block;
    margin-top: 0.75rem;
    font-size: 0.85em;
    color: var(--chrome-dark);
    font-style: normal;
    letter-spacing: 0.05em;
}

/* --- TIER 2: The Cabinet of Curiosities --- */
.tier-2 {
    min-height: 100vh;
    background: linear-gradient(135deg, var(--chrome-mid) 0%, var(--polished-steel) 30%, var(--chrome-light) 60%, var(--chrome-mid) 100%);
    clip-path: polygon(4vw 0, 100% 0, calc(100% - 6vw) 100%, 0 100%);
    margin-top: -4vh;
    padding: 8rem 2rem 6rem;
    z-index: 2;
}

.tier-2 .tier-inner {
    position: relative;
    z-index: 2;
    max-width: 1100px;
    margin: 0 auto;
}

/* Tier Headings */
.tier-heading-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 3rem;
}

.tier-label {
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 700;
    font-size: var(--heading-size);
    letter-spacing: 0.12em;
    line-height: 1.1;
    color: var(--anthracite);
    text-rendering: optimizeLegibility;
    font-feature-settings: 'liga' 1, 'kern' 1;
    white-space: nowrap;
}

/* Drop Caps */
.drop-cap {
    font-family: 'IM Fell English', Georgia, serif;
    font-weight: 400;
    font-size: 1.4em;
    line-height: 1;
    color: var(--aged-brass);
    margin-right: 0.02em;
}

/* Scrollwork brackets */
.scrollwork-left,
.scrollwork-right {
    width: 60px;
    height: 40px;
    flex-shrink: 0;
    opacity: 0.8;
}

.scrollwork-left path,
.scrollwork-right path {
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
    transition: stroke-dashoffset 1.2s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.tier-heading-wrap.animated .scrollwork-left path {
    stroke-dashoffset: 0;
}

.tier-heading-wrap.animated .scrollwork-right path {
    stroke-dashoffset: 0;
}

/* Cabinet Cards */
.cabinet-cards {
    display: flex;
    flex-direction: column;
    gap: 2rem;
    position: relative;
    padding-left: 2rem;
}

.cabinet-card {
    position: relative;
    background: linear-gradient(135deg, rgba(192,192,192,0.6) 0%, rgba(216,216,216,0.4) 50%, rgba(192,192,192,0.6) 100%);
    border: 1px solid var(--brushed-nickel);
    box-shadow: inset 0 0 30px rgba(192,192,192,0.15);
    padding: 2.5rem 3rem;
    clip-path: polygon(2% 0, 100% 0, 98% 100%, 0 100%);
    transform: rotate(-2deg);
    transition: transform 0.4s ease, box-shadow 0.4s ease;
}

.cabinet-card:hover {
    transform: rotate(-1deg) translateY(-2px);
    box-shadow: inset 0 0 30px rgba(192,192,192,0.15), 0 8px 32px rgba(0,0,0,0.12);
}

.card-1 {
    margin-left: 0;
}

.card-2 {
    margin-left: 8vw;
}

.card-3 {
    margin-left: 16vw;
}

.cabinet-card h3 {
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 700;
    font-size: var(--subheading-size);
    letter-spacing: 0.1em;
    color: var(--anthracite);
    margin-bottom: 0.75rem;
    text-rendering: optimizeLegibility;
    font-feature-settings: 'liga' 1, 'kern' 1;
}

.cabinet-card p {
    color: var(--carbon-steel);
    max-width: 55ch;
}

/* Card ornaments (corner rosettes) */
.card-ornament {
    position: absolute;
    width: 24px;
    height: 24px;
}

.card-ornament.top-left { top: 8px; left: 12px; }
.card-ornament.top-right { top: 8px; right: 12px; }
.card-ornament.bottom-left { bottom: 8px; left: 12px; }
.card-ornament.bottom-right { bottom: 8px; right: 12px; }

.card-ornament svg {
    width: 100%;
    height: 100%;
}

/* Greek Key Divider */
.greek-key-divider {
    height: 16px;
    margin: 1rem 0;
    background: repeating-linear-gradient(
        90deg,
        transparent 0px,
        transparent 4px,
        var(--brushed-nickel) 4px,
        var(--brushed-nickel) 8px,
        transparent 8px,
        transparent 12px,
        var(--brushed-nickel) 12px,
        var(--brushed-nickel) 16px
    );
    opacity: 0.3;
    background-size: 16px 4px;
    background-repeat: repeat-x;
    background-position: center;
}

/* --- TIER 3: The Observatory --- */
.tier-3 {
    min-height: 90vh;
    background: linear-gradient(135deg, var(--polished-steel) 0%, var(--chrome-light) 25%, var(--chrome-mid) 50%, var(--chrome-highlight) 75%, var(--chrome-surface) 100%);
    clip-path: polygon(6vw 0, 100% 0, calc(100% - 3vw) 100%, 0 100%);
    margin-top: -4vh;
    padding: 8rem 2rem 6rem;
    z-index: 3;
}

.tier-3 .tier-inner {
    position: relative;
    z-index: 2;
    max-width: 1100px;
    width: 85vw;
    margin: 0 auto;
}

/* Observatory Two-Column Layout */
.observatory-columns {
    display: flex;
    gap: 0;
    align-items: stretch;
}

.obs-column {
    flex: 1;
    padding: 0 2rem;
}

.obs-column h3 {
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 700;
    font-size: var(--subheading-size);
    letter-spacing: 0.08em;
    color: var(--anthracite);
    margin-bottom: 1.2rem;
    text-rendering: optimizeLegibility;
    font-feature-settings: 'liga' 1, 'kern' 1;
}

.obs-column p {
    margin-bottom: 1.2rem;
    color: var(--anthracite);
}

/* Column divider with diamond terminals */
.column-divider {
    width: 1px;
    background: var(--chrome-dark);
    position: relative;
    flex-shrink: 0;
    min-height: 300px;
}

.diamond-terminal {
    position: absolute;
    width: 8px;
    height: 8px;
    background: var(--chrome-dark);
    transform: rotate(45deg);
    left: -3.5px;
}

.diamond-terminal.top { top: 0; }
.diamond-terminal.bottom { bottom: 0; }

/* --- TIER 4: The Greenhouse --- */
.tier-4 {
    min-height: 80vh;
    background: linear-gradient(135deg, var(--chrome-bg) 0%, #8aaa9a 30%, var(--verdigris) 60%, #4a6a5a 100%);
    clip-path: polygon(3vw 0, 100% 0, calc(100% - 5vw) 100%, 0 100%);
    margin-top: -4vh;
    padding: 8rem 2rem 6rem;
    z-index: 4;
}

.tier-4 .tier-inner {
    position: relative;
    z-index: 2;
    max-width: 900px;
    margin: 0 auto;
}

/* Botanical illustrations */
.botanical-illustrations {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    overflow: hidden;
}

.botanical {
    position: absolute;
    opacity: 0.5;
}

.botanical-fern {
    left: 2%;
    top: 10%;
    width: 180px;
    height: 270px;
}

.botanical-ivy {
    right: 2%;
    top: 30%;
    width: 160px;
    height: 240px;
}

.botanical-path {
    stroke-dasharray: 500;
    stroke-dashoffset: 500;
    transition: stroke-dashoffset 2s ease;
}

.botanical.animated .botanical-path {
    stroke-dashoffset: 0;
}

.greenhouse-content {
    position: relative;
    z-index: 3;
}

.greenhouse-content h3 {
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 700;
    font-size: var(--subheading-size);
    letter-spacing: 0.08em;
    color: var(--platinum-mist);
    margin-bottom: 1.2rem;
    text-rendering: optimizeLegibility;
    font-feature-settings: 'liga' 1, 'kern' 1;
}

.greenhouse-content p {
    color: var(--platinum-mist);
    margin-bottom: 1.2rem;
    opacity: 0.92;
}

.greenhouse-divider {
    background: repeating-linear-gradient(
        90deg,
        transparent 0px,
        transparent 4px,
        var(--polished-steel) 4px,
        var(--polished-steel) 8px,
        transparent 8px,
        transparent 12px,
        var(--polished-steel) 12px,
        var(--polished-steel) 16px
    );
    background-size: 16px 4px;
    background-repeat: repeat-x;
    background-position: center;
    opacity: 0.25;
    margin: 2rem 0;
}

/* --- TIER 5: The Colophon --- */
.tier-5 {
    min-height: 50vh;
    background: linear-gradient(135deg, var(--carbon-steel) 0%, var(--gunmetal) 40%, #1E1E1E 100%);
    clip-path: polygon(5vw 0, 100% 0, calc(100% - 2vw) 100%, 0 100%);
    margin-top: -4vh;
    padding: 8rem 2rem 6rem;
    z-index: 5;
}

.tier-5 .tier-inner {
    position: relative;
    z-index: 2;
    max-width: 700px;
    width: 60vw;
    margin: 0 auto;
}

.tier-5 .tier-label {
    color: var(--platinum-mist);
}

.tier-5 .drop-cap {
    color: var(--aged-brass);
}

/* Acanthus Frame */
.acanthus-frame {
    position: relative;
    margin: 2rem 0;
}

.acanthus-border {
    width: 100%;
    height: auto;
}

.acanthus-path {
    stroke-dasharray: 600;
    stroke-dashoffset: 600;
    transition: stroke-dashoffset 2.5s ease;
}

.acanthus-frame.animated .acanthus-path {
    stroke-dashoffset: 0;
}

/* Colophon Content */
.colophon-content {
    text-align: center;
    padding: 1rem 0;
}

.colophon-text {
    color: var(--platinum-mist);
    font-size: var(--body-size);
    line-height: 1.72;
    margin-bottom: 1.5rem;
}

.colophon-text strong {
    color: var(--white-gold);
}

.colophon-divider {
    background: repeating-linear-gradient(
        90deg,
        transparent 0px,
        transparent 4px,
        var(--aged-brass) 4px,
        var(--aged-brass) 8px,
        transparent 8px,
        transparent 12px,
        var(--aged-brass) 12px,
        var(--aged-brass) 16px
    );
    background-size: 16px 4px;
    background-repeat: repeat-x;
    background-position: center;
    opacity: 0.35;
    margin: 1.5rem auto;
    max-width: 200px;
}

.colophon-attribution {
    color: var(--brushed-nickel);
    font-size: 0.9em;
    margin-bottom: 0.3rem;
}

.colophon-closing {
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 700;
    font-size: 1.2em;
    letter-spacing: 0.2em;
    color: var(--aged-brass);
    margin-top: 2rem;
}

/* --- Tier Boundaries --- */
.tier-boundary {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 1px;
    z-index: 10;
}

/* --- Responsive: Diagonal Degradation --- */
@media (max-width: 768px) {
    :root {
        --diagonal-angle: 6deg;
        --diagonal-tan: 0.1051;
    }

    .tier-1 {
        clip-path: polygon(0 0, 100% 0, calc(100% - 2vw) 100%, 0 100%);
    }

    .tier-2 {
        clip-path: polygon(2vw 0, 100% 0, calc(100% - 3vw) 100%, 0 100%);
    }

    .tier-3 {
        clip-path: polygon(3vw 0, 100% 0, calc(100% - 1.5vw) 100%, 0 100%);
    }

    .tier-4 {
        clip-path: polygon(1.5vw 0, 100% 0, calc(100% - 2.5vw) 100%, 0 100%);
    }

    .tier-5 {
        clip-path: polygon(2.5vw 0, 100% 0, calc(100% - 1vw) 100%, 0 100%);
    }

    .observatory-columns {
        flex-direction: column;
    }

    .column-divider {
        width: 100%;
        height: 1px;
        min-height: auto;
        margin: 2rem 0;
    }

    .diamond-terminal {
        display: none;
    }

    .cabinet-card {
        transform: rotate(-1deg);
    }

    .card-1,
    .card-2,
    .card-3 {
        margin-left: 0;
    }

    .cabinet-cards {
        padding-left: 0;
    }

    .tier-5 .tier-inner {
        width: 85vw;
    }

    .compass-rose {
        width: 120px;
        height: 120px;
    }
}

@media (max-width: 480px) {
    .tier-1,
    .tier-2,
    .tier-3,
    .tier-4,
    .tier-5 {
        clip-path: none;
    }

    .tier::after {
        content: '';
        position: absolute;
        top: 8px;
        left: 8px;
        right: 8px;
        bottom: 8px;
        border: 1px solid var(--brushed-nickel);
        transform: rotate(-2deg);
        pointer-events: none;
        z-index: 1;
    }

    .tier-5 .tier-inner {
        width: 90vw;
    }

    .scrollwork-left,
    .scrollwork-right {
        display: none;
    }
}

/* Disable lens flare on small viewports */
@media (max-width: 640px) {
    #lens-flare-container {
        display: none;
    }
}
