/* ============================================
   archetype.works - Styles
   ============================================ */

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

:root {
    --void: #09080d;
    --aureate: #d4af37;
    --parchment: #f0ece2;
    --amethyst: #5b2c6f;
    --vermillion: #8b1a1a;
    --verdigris: #2e8b7a;
    --slate-mist: #4a4458;
    --ember: #c4721a;
    --gray: #7a7486;
    --spring-bezier: cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

html {
    scroll-behavior: smooth;
}

body {
    background-color: var(--void);
    color: var(--parchment);
    font-family: 'Commissioner', sans-serif;
    font-weight: 300;
    font-size: 17px;
    line-height: 1.7;
    letter-spacing: 0.01em;
    overflow-x: hidden;
    min-height: 100vh;
}

/* --- Intro Overlay --- */
#intro-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: var(--void);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 1.2s ease;
}

#intro-overlay.fade-out {
    opacity: 0;
    pointer-events: none;
}

#intro-overlay.hidden {
    display: none;
}

#intro-spiral {
    opacity: 0;
    transition: opacity 0.3s ease;
}

#intro-spiral.visible {
    opacity: 1;
}

#intro-spiral.contract {
    transition: transform 0.8s var(--spring-bezier), opacity 0.8s ease;
    transform: scale(0.15) translate(-300px, -300px);
    opacity: 0;
}

#spiral-path {
    stroke-dasharray: 500;
    stroke-dashoffset: 500;
}

#spiral-path.animate {
    animation: drawSpiral 2.5s ease-out forwards;
}

@keyframes drawSpiral {
    to {
        stroke-dashoffset: 0;
    }
}

/* --- Site Title Watermark --- */
#site-title {
    position: fixed;
    top: 32px;
    left: 48px;
    font-family: 'DM Mono', monospace;
    font-size: 11px;
    font-weight: 400;
    text-transform: uppercase;
    letter-spacing: 0.4em;
    color: var(--slate-mist);
    z-index: 100;
    opacity: 0;
    transition: background-color 0.2s ease, color 0.2s ease, opacity 0.8s ease;
    padding: 4px 8px;
    cursor: default;
}

#site-title.visible {
    opacity: 1;
}

#site-title:hover {
    background-color: var(--aureate);
    color: var(--void);
}

/* --- Glyph Navigation (Desktop) --- */
#glyph-nav {
    position: fixed;
    left: 48px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 40px;
    z-index: 100;
    opacity: 0;
    transition: opacity 0.8s ease;
}

#glyph-nav.visible {
    opacity: 1;
}

.glyph-link {
    display: block;
    width: 24px;
    height: 24px;
    color: var(--slate-mist);
    transition: color 0.3s ease, transform 0.3s ease-out;
    text-decoration: none;
}

.glyph-link:hover {
    color: var(--aureate);
    transform: rotate(15deg);
}

.glyph-link.active {
    color: var(--aureate);
}

/* --- Glyph Navigation (Mobile) --- */
#glyph-nav-mobile {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 56px;
    background: rgba(9, 8, 13, 0.95);
    z-index: 100;
    flex-direction: row;
    align-items: center;
    justify-content: space-around;
    padding: 0 16px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.glyph-link-mobile {
    display: block;
    width: 24px;
    height: 24px;
    color: var(--slate-mist);
    transition: color 0.3s ease;
    text-decoration: none;
    flex-shrink: 0;
}

.glyph-link-mobile.active {
    color: var(--aureate);
}

/* --- Noise Overlay --- */
#noise-filter {
    position: absolute;
    width: 0;
    height: 0;
}

#noise-overlay {
    position: fixed;
    top: -10%;
    left: -10%;
    width: 120%;
    height: 120%;
    z-index: 1;
    pointer-events: none;
    filter: url(#noiseFilter);
    background: transparent;
    will-change: transform;
}

/* --- Overlay Veil --- */
#overlay-veil {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(9, 8, 13, 0.85);
    z-index: 50;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

#overlay-veil.active {
    opacity: 1;
    pointer-events: auto;
}

/* --- Masonry Grid --- */
#masonry-grid {
    position: relative;
    z-index: 10;
    padding: 120px 120px 120px 140px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 32px;
    max-width: 1600px;
    margin: 0 auto;
    opacity: 0;
    transition: opacity 1.2s ease;
}

#masonry-grid.visible {
    opacity: 1;
}

/* Varying card proportions for masonry feel */
.archetype-card:nth-child(1) {
    grid-row: span 2;
}

.archetype-card:nth-child(2) {
    grid-column: span 1;
}

.archetype-card:nth-child(3) {
    grid-row: span 2;
}

.archetype-card:nth-child(4) {
    grid-column: span 1;
}

.archetype-card:nth-child(5) {
    grid-column: span 1;
}

/* --- Archetype Card --- */
.archetype-card {
    position: relative;
    background: transparent;
    cursor: pointer;
    overflow: hidden;
    min-height: 300px;
    opacity: 0;
    transform: translateY(40px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.archetype-card.visible {
    opacity: 1;
    transform: translateY(0);
}

.archetype-card.dimmed {
    opacity: 0.15 !important;
    transition: opacity 0.4s ease;
    pointer-events: none;
}

/* Expanded card state */
.archetype-card.expanded {
    position: fixed !important;
    top: 10vh !important;
    left: 15vw !important;
    width: 70vw !important;
    height: 80vh !important;
    z-index: 60 !important;
    overflow-y: auto;
    grid-row: auto !important;
    grid-column: auto !important;
    min-height: auto !important;
    transition: all 0.5s var(--spring-bezier);
}

/* --- Card Watermark --- */
.card-watermark {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--parchment);
    opacity: 0.04;
    pointer-events: none;
    z-index: 0;
}

/* --- Radial Light Pool --- */
.card-radial-light {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    transition: opacity 0.8s ease;
    pointer-events: none;
    z-index: 1;
    --light-x: 50%;
    --light-y: 30%;
}

.archetype-card[data-accent="#8b1a1a"] .card-radial-light {
    background: radial-gradient(ellipse at var(--light-x) var(--light-y), rgba(139, 26, 26, 0.12) 0%, transparent 70%);
}

.archetype-card[data-accent="#5b2c6f"] .card-radial-light {
    background: radial-gradient(ellipse at var(--light-x) var(--light-y), rgba(91, 44, 111, 0.12) 0%, transparent 70%);
}

.archetype-card[data-accent="#d4af37"] .card-radial-light {
    background: radial-gradient(ellipse at var(--light-x) var(--light-y), rgba(212, 175, 55, 0.12) 0%, transparent 70%);
}

.archetype-card[data-accent="#2e8b7a"] .card-radial-light {
    background: radial-gradient(ellipse at var(--light-x) var(--light-y), rgba(46, 139, 122, 0.12) 0%, transparent 70%);
}

.archetype-card[data-accent="#c4721a"] .card-radial-light {
    background: radial-gradient(ellipse at var(--light-x) var(--light-y), rgba(196, 114, 26, 0.12) 0%, transparent 70%);
}

.card-radial-light.warm {
    opacity: 1;
}

.archetype-card:hover .card-radial-light {
    opacity: 1;
}

.archetype-card:hover .card-radial-light,
.archetype-card.expanded .card-radial-light {
    opacity: 1;
}

/* Intensify on hover */
.archetype-card:hover .card-radial-light {
    filter: brightness(2);
}

/* --- Border Animate --- */
.card-border-animate {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2;
    border: 1px solid transparent;
    transition: border-color 0.6s ease;
}

.archetype-card:hover .card-border-animate {
    border-color: rgba(212, 175, 55, 0);
    animation: borderTrace 0.6s ease-out forwards;
}

@keyframes borderTrace {
    0% {
        border-image: conic-gradient(from 0deg, var(--aureate) 0%, transparent 0%) 1;
    }
    25% {
        border-image: conic-gradient(from 0deg, var(--aureate) 25%, transparent 25%) 1;
    }
    50% {
        border-image: conic-gradient(from 0deg, var(--aureate) 50%, transparent 50%) 1;
    }
    75% {
        border-image: conic-gradient(from 0deg, var(--aureate) 75%, transparent 75%) 1;
    }
    100% {
        border-image: conic-gradient(from 0deg, var(--aureate) 100%, transparent 100%) 1;
    }
}

/* --- Card Content --- */
.card-content {
    position: relative;
    z-index: 3;
    padding: 48px 40px;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.card-index {
    font-family: 'DM Mono', monospace;
    font-size: 11px;
    font-weight: 400;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--gray);
    margin-bottom: 24px;
}

.card-title {
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-style: italic;
    font-size: clamp(3.5rem, 8vw, 9rem);
    line-height: 1;
    color: var(--parchment);
    margin-bottom: 24px;
    transition: color 0.3s ease;
}

.first-letter {
    color: var(--aureate);
}

.card-evocation {
    font-family: 'Commissioner', sans-serif;
    font-weight: 300;
    font-size: 17px;
    line-height: 1.7;
    letter-spacing: 0.01em;
    color: var(--parchment);
    max-width: 500px;
    margin-top: auto;
}

/* --- Expanded Content --- */
.card-expanded-content {
    display: none;
    position: relative;
    z-index: 3;
    padding: 0 40px 48px;
    opacity: 0;
}

.archetype-card.expanded .card-expanded-content {
    display: block;
    animation: fadeInContent 0.8s ease 0.3s forwards;
}

@keyframes fadeInContent {
    to {
        opacity: 1;
    }
}

.expanded-watermark-text {
    position: absolute;
    top: -80px;
    left: -20px;
    font-family: 'Playfair Display', serif;
    font-weight: 900;
    font-size: clamp(15rem, 25vw, 40rem);
    color: var(--parchment);
    opacity: 0.02;
    pointer-events: none;
    white-space: nowrap;
    line-height: 1;
    z-index: 0;
}

.expanded-glyph {
    margin-bottom: 24px;
    opacity: 0;
}

.archetype-card.expanded .expanded-glyph {
    animation: fadeUp 0.3s ease 0.5s forwards;
}

.expanded-glyph svg path,
.expanded-glyph svg line,
.expanded-glyph svg polyline,
.expanded-glyph svg circle,
.expanded-glyph svg polygon {
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
}

.archetype-card.expanded .expanded-glyph svg path,
.archetype-card.expanded .expanded-glyph svg line,
.archetype-card.expanded .expanded-glyph svg polyline,
.archetype-card.expanded .expanded-glyph svg circle,
.archetype-card.expanded .expanded-glyph svg polygon {
    animation: drawGlyph 0.8s ease-out 0.5s forwards;
}

@keyframes drawGlyph {
    to {
        stroke-dashoffset: 0;
    }
}

.expanded-title {
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-style: italic;
    font-size: clamp(2rem, 5vw, 5rem);
    line-height: 1.1;
    color: var(--parchment);
    margin-bottom: 32px;
    opacity: 0;
}

.archetype-card.expanded .expanded-title {
    animation: fadeUp 0.3s ease 0.6s forwards;
}

@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- Hairline Dividers --- */
.hairline-divider {
    width: 100%;
    height: 0.5px;
    background: rgba(212, 175, 55, 0.3);
    margin: 24px 0;
    transform: scaleX(0);
    transform-origin: left;
}

.archetype-card.expanded .hairline-divider {
    animation: drawLine 0.6s ease-out 0.8s forwards;
}

@keyframes drawLine {
    to {
        transform: scaleX(1);
    }
}

/* --- Expanded Body Text --- */
.expanded-body {
    font-family: 'Commissioner', sans-serif;
    font-weight: 300;
    font-size: 17px;
    line-height: 1.7;
    letter-spacing: 0.01em;
    color: var(--parchment);
    margin-bottom: 16px;
    max-width: 700px;
    opacity: 0;
}

.archetype-card.expanded .expanded-body:nth-child(4) {
    animation: fadeUp 0.3s ease 0.9s forwards;
}

.archetype-card.expanded .expanded-body:nth-child(5) {
    animation: fadeUp 0.3s ease 0.95s forwards;
}

.archetype-card.expanded .expanded-body:nth-child(7) {
    animation: fadeUp 0.3s ease 1.1s forwards;
}

/* --- Expanded Meta --- */
.expanded-meta {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px 24px;
    margin-top: 32px;
    opacity: 0;
}

.archetype-card.expanded .expanded-meta {
    animation: fadeUp 0.3s ease 1.2s forwards;
}

.meta-label {
    font-family: 'DM Mono', monospace;
    font-size: 11px;
    font-weight: 400;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--gray);
}

.meta-value {
    font-family: 'Commissioner', sans-serif;
    font-weight: 500;
    font-size: 14px;
    color: var(--parchment);
}

/* --- Scroll Snap --- */
@supports (scroll-snap-type: y proximity) {
    #masonry-grid {
        scroll-snap-type: y proximity;
    }

    .archetype-card {
        scroll-snap-align: start;
    }
}

/* --- Mobile Responsive --- */
@media (max-width: 768px) {
    #glyph-nav {
        display: none;
    }

    #glyph-nav-mobile {
        display: flex;
    }

    #site-title {
        left: 16px;
        top: 16px;
    }

    #masonry-grid {
        padding: 80px 16px 80px 16px;
        grid-template-columns: 1fr;
        gap: 24px;
    }

    .archetype-card:nth-child(n) {
        grid-row: auto;
        grid-column: auto;
    }

    .archetype-card {
        min-height: 400px;
    }

    .card-title {
        font-size: clamp(2.5rem, 12vw, 5rem);
    }

    .archetype-card.expanded {
        top: 0 !important;
        left: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
    }

    .card-content {
        padding: 32px 24px;
    }

    .card-expanded-content {
        padding: 0 24px 32px;
    }

    .expanded-watermark-text {
        font-size: clamp(6rem, 20vw, 15rem);
    }
}

@media (max-width: 1024px) and (min-width: 769px) {
    #masonry-grid {
        grid-template-columns: repeat(2, 1fr);
        padding: 120px 80px 120px 120px;
    }

    .archetype-card:nth-child(1) {
        grid-row: span 1;
    }

    .archetype-card:nth-child(3) {
        grid-row: span 1;
    }
}

/* --- Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .archetype-card {
        opacity: 1;
        transform: none;
    }

    .archetype-card.expanded {
        transition: none;
    }

    #intro-overlay {
        display: none;
    }

    #masonry-grid {
        opacity: 1;
    }

    #site-title, #glyph-nav {
        opacity: 1;
    }
}

/* --- Scrollbar styling --- */
::-webkit-scrollbar {
    width: 4px;
}

::-webkit-scrollbar-track {
    background: var(--void);
}

::-webkit-scrollbar-thumb {
    background: var(--slate-mist);
    border-radius: 2px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--aureate);
}

/* Expanded card scrollbar */
.archetype-card.expanded::-webkit-scrollbar {
    width: 3px;
}

.archetype-card.expanded::-webkit-scrollbar-thumb {
    background: rgba(212, 175, 55, 0.3);
}
