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

:root {
    --abyss-navy: #0b1929;
    --midnight-trench: #0f2238;
    --bio-cyan: #2de2c4;
    --kelp-teal: #1a5c5a;
    --moonlit-foam: #e0e8f0;
    --tideline-gray: #b0c4d8;
    --coral-phosphor: #ff6b6b;
    --hadal-blue: #061220;
}

html {
    scroll-behavior: smooth;
}

body {
    background-color: var(--abyss-navy);
    color: var(--tideline-gray);
    font-family: 'Space Grotesk', sans-serif;
    font-size: clamp(0.95rem, 1.1vw, 1.1rem);
    line-height: 1.72;
    letter-spacing: 0.01em;
    overflow-x: hidden;
}

/* === Masthead === */
#masthead {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 64px;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    background: rgba(11, 25, 41, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.masthead-title {
    font-family: 'Fraunces', serif;
    font-weight: 600;
    font-size: 1.2rem;
    color: var(--moonlit-foam);
    font-variation-settings: 'SOFT' 80, 'opsz' 24;
}

.masthead-nav {
    display: flex;
    align-items: center;
    gap: 8px;
}

.nav-link {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.85rem;
    color: var(--tideline-gray);
    letter-spacing: 0.06em;
    cursor: pointer;
    transition: color 0.3s;
}

.nav-link:hover, .nav-link.active {
    color: var(--bio-cyan);
}

.nav-sep {
    color: var(--kelp-teal);
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.85rem;
}

.menu-toggle {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--midnight-trench);
    border: 1px solid var(--kelp-teal);
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    transition: border-color 0.3s;
}

.menu-toggle:hover {
    border-color: var(--bio-cyan);
}

.menu-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--bio-cyan);
}

/* === Menu Overlay === */
.menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--hadal-blue);
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s;
}

.menu-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.overlay-nav {
    display: flex;
    flex-direction: column;
    gap: 24px;
    text-align: center;
}

.overlay-link {
    font-family: 'Fraunces', serif;
    font-size: 2rem;
    color: var(--moonlit-foam);
    text-decoration: none;
    font-variation-settings: 'SOFT' 80;
    transition: color 0.3s;
}

.overlay-link:hover {
    color: var(--bio-cyan);
}

/* === Hero Bookplate === */
#bookplate {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    background: var(--abyss-navy);
    transition: opacity 0.5s, transform 0.5s;
}

.bookplate-content {
    text-align: center;
    z-index: 1;
}

.bookplate-title {
    font-family: 'Fraunces', serif;
    font-size: clamp(4rem, 12vw, 9rem);
    font-weight: 600;
    color: var(--moonlit-foam);
    font-variation-settings: 'SOFT' 100, 'opsz' 72;
    opacity: 0;
    transform: scale(0.95);
    transition: opacity 0.8s ease, transform 0.8s ease;
}

.bookplate-title.visible {
    opacity: 1;
    transform: scale(1);
}

.bookplate-rule {
    width: 0;
    height: 1px;
    background: var(--kelp-teal);
    margin: 24px auto;
    transition: width 0.6s ease;
}

.bookplate-rule.visible {
    width: 200px;
}

.bookplate-subtitle {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.85rem;
    color: var(--bio-cyan);
    letter-spacing: 0.06em;
    min-height: 1.5em;
}

.cursor {
    animation: blink 1.06s step-end infinite;
    color: var(--bio-cyan);
}

.cursor.fade-out {
    animation: blink 1.06s step-end 3, fadeOut 0.3s 3.18s forwards;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

@keyframes fadeOut {
    to { opacity: 0; }
}

/* === Icon Cluster === */
.icon-cluster {
    position: absolute;
    bottom: 15%;
    right: 15%;
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    max-width: 160px;
}

.iso-icon {
    opacity: 0;
    transition: opacity 0.5s ease, transform 0.4s ease;
}

.iso-icon.visible {
    opacity: 1;
}

.iso-icon:hover {
    transform: scale(1.33) rotate(5deg);
}

.float-icon {
    animation: float 6s ease-in-out infinite;
    will-change: transform;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

/* === Portfolio Grid Section === */
#grid-section {
    padding: 80px 32px;
    max-width: 1200px;
    margin: 0 auto;
}

.portfolio-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 24px;
}

/* === Pull Quotes === */
.pull-quote {
    text-align: center;
    padding: 64px 0;
}

.pq-rule {
    border: none;
    height: 1px;
    background: var(--kelp-teal);
    max-width: 200px;
    margin: 16px auto;
}

.pq-text {
    font-family: 'Fraunces', serif;
    font-size: clamp(1.5rem, 3vw, 2.5rem);
    font-style: italic;
    color: var(--moonlit-foam);
    font-variation-settings: 'SOFT' 60;
    min-height: 1.5em;
}

/* === Cards === */
.card {
    background: var(--abyss-navy);
    border: 1px solid var(--kelp-teal);
    border-radius: 4px;
    padding: 28px 24px;
    position: relative;
    transition: border-color 0.3s, background-color 0.3s;
    contain: layout style;
    opacity: 0;
    transform: translateY(20px);
    overflow: hidden;
}

.card.visible {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.4s ease, transform 0.4s ease, border-color 0.3s, background-color 0.3s;
}

.card:hover {
    border-color: var(--bio-cyan);
    background: var(--midnight-trench);
}

.card::after {
    content: '';
    position: absolute;
    top: var(--click-y, 50%);
    left: var(--click-x, 50%);
    width: 0;
    height: 0;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(45, 226, 196, 0.3), transparent 70%);
    transform: translate(-50%, -50%);
    pointer-events: none;
}

.card.ripple::after {
    animation: ripple 0.6s ease-out forwards;
}

@keyframes ripple {
    to {
        width: 400px;
        height: 400px;
        opacity: 0;
    }
}

.card-wide {
    grid-column: span 2;
}

.card-tall {
    grid-row: span 2;
}

.chapter-num {
    position: absolute;
    top: 12px;
    right: 12px;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.85rem;
    color: var(--bio-cyan);
    letter-spacing: 0.06em;
    opacity: 0.5;
    transition: opacity 0.3s;
}

.card:hover .chapter-num {
    opacity: 1;
}

.card-icon {
    margin-bottom: 16px;
}

.card-icon svg {
    transition: transform 0.4s ease;
}

.card:hover .card-icon svg {
    transform: scale(1.33) rotate(5deg);
}

.card-title {
    font-family: 'Fraunces', serif;
    font-size: clamp(1.2rem, 2.5vw, 1.8rem);
    font-weight: 600;
    color: var(--moonlit-foam);
    font-variation-settings: 'SOFT' 50, 'opsz' 24;
    margin-bottom: 12px;
    line-height: 1.3;
}

.card-excerpt {
    color: var(--tideline-gray);
    line-height: 1.72;
}

.margin-note {
    position: absolute;
    right: -120px;
    top: 50%;
    transform: translateY(-50%);
    writing-mode: vertical-rl;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.75rem;
    color: var(--kelp-teal);
    letter-spacing: 0.06em;
    display: none;
}

/* === Grid Divider === */
.grid-divider {
    grid-column: 1 / -1;
    text-align: center;
    padding: 16px 0;
}

.fleuron {
    font-family: 'Fraunces', serif;
    font-size: 1.5rem;
    color: var(--coral-phosphor);
    opacity: 0.4;
}

/* === Colophon === */
#colophon {
    background: var(--hadal-blue);
    padding: 80px 32px;
    text-align: center;
}

.colophon-content {
    max-width: 400px;
    margin: 0 auto;
}

.colophon-title {
    font-family: 'Fraunces', serif;
    font-size: 1.8rem;
    font-weight: 600;
    color: var(--moonlit-foam);
    font-variation-settings: 'SOFT' 100;
}

.colophon-dots {
    color: var(--kelp-teal);
    margin: 16px 0;
    letter-spacing: 0.2em;
}

.colophon-text {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.85rem;
    color: var(--tideline-gray);
    letter-spacing: 0.04em;
    min-height: 1.5em;
    margin-bottom: 24px;
}

.colophon-icon {
    opacity: 0.6;
    transition: opacity 0.3s;
}

.colophon-icon:hover {
    opacity: 1;
}

/* === Responsive === */
@media (min-width: 1200px) {
    .margin-note {
        display: block;
    }
}

@media (max-width: 768px) {
    .portfolio-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .card-wide {
        grid-column: span 2;
    }

    .masthead-nav {
        display: none;
    }

    .menu-toggle {
        display: flex;
    }

    .icon-cluster {
        right: 8%;
        bottom: 10%;
    }
}

@media (max-width: 480px) {
    .portfolio-grid {
        grid-template-columns: 1fr;
    }

    .card-wide, .card-tall {
        grid-column: span 1;
        grid-row: span 1;
    }

    #grid-section {
        padding: 40px 16px;
    }

    #masthead {
        padding: 0 16px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .float-icon {
        animation: none;
    }

    .bookplate-title {
        opacity: 1;
        transform: none;
    }

    .bookplate-rule {
        width: 200px;
    }

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

    .iso-icon {
        opacity: 1;
    }
}
