/* === CSS Custom Properties === */
:root {
    --primary-dark: #1A0A10;
    --primary-mid: #3A1526;
    --accent-warm: #7A2E45;
    --surface-light: #F5E6D3;
    --surface-warm: #E8D4BF;
    --highlight: #C4A882;
    --interaction: #B85C38;
    --fracture: #2D1219;
    --sidebar-width: 280px;
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Work Sans', sans-serif;
    font-weight: 400;
    font-size: clamp(0.95rem, 1.1vw, 1.15rem);
    line-height: 1.65;
    color: #F5E6D3;
    background-color: #1A0A10;
    overflow-x: hidden;
}

/* === Blueprint Grid Underlay === */
#blueprint-grid {
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    bottom: 0;
    background-image:
        linear-gradient(to right, rgba(196, 168, 130, 0.03) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(196, 168, 130, 0.03) 1px, transparent 1px);
    background-size: 48px 48px;
    pointer-events: none;
    z-index: 0;
}

/* === Sidebar === */
#sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background-color: #3A1526;
    z-index: 100;
    overflow: hidden;
}

.sidebar-texture {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image:
        radial-gradient(ellipse at 20% 30%, rgba(26, 10, 16, 0.15) 0%, transparent 70%),
        radial-gradient(ellipse at 80% 60%, rgba(26, 10, 16, 0.12) 0%, transparent 60%),
        radial-gradient(ellipse at 50% 90%, rgba(26, 10, 16, 0.18) 0%, transparent 50%),
        radial-gradient(circle at 30% 70%, rgba(45, 18, 25, 0.2) 0%, transparent 40%),
        radial-gradient(circle at 70% 20%, rgba(45, 18, 25, 0.15) 0%, transparent 40%);
    pointer-events: none;
}

.sidebar-content {
    position: relative;
    z-index: 1;
    padding: 40px 0;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 24px;
    margin-bottom: 60px;
}

.logo-puzzle {
    flex-shrink: 0;
}

.logo-text {
    font-family: 'Playfair Display', serif;
    font-weight: 900;
    font-size: 1.4rem;
    color: #F5E6D3;
    letter-spacing: -0.02em;
}

.nav-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 24px;
    cursor: pointer;
    transition: transform 300ms cubic-bezier(0.34, 1.56, 0.64, 1), background-color 200ms ease;
    clip-path: polygon(0 0, calc(100% - 12px) 0, 100% 30%, 100% 70%, calc(100% - 12px) 100%, 0 100%);
    background-color: transparent;
    position: relative;
}

.nav-item:hover {
    background-color: rgba(122, 46, 69, 0.3);
}

.nav-item.active {
    background-color: rgba(122, 46, 69, 0.5);
    transform: translateX(40px);
}

.nav-puzzle-icon {
    flex-shrink: 0;
    opacity: 0.7;
}

.nav-item.active .nav-puzzle-icon {
    opacity: 1;
}

.nav-label {
    font-family: 'Space Mono', monospace;
    font-weight: 400;
    font-size: 0.75rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #C4A882;
}

/* === Mobile Header === */
#mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 64px;
    background-color: #3A1526;
    z-index: 200;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
}

.mobile-logo {
    font-family: 'Playfair Display', serif;
    font-weight: 900;
    font-size: 1.2rem;
    color: #F5E6D3;
}

#mobile-menu-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
}

/* === Main Content === */
#content {
    margin-left: var(--sidebar-width);
    position: relative;
    z-index: 1;
    min-height: 100vh;
}

/* === Sections === */
.section {
    padding: 80px 48px;
    position: relative;
}

.section-title {
    font-family: 'Playfair Display', serif;
    font-weight: 900;
    font-size: clamp(1.8rem, 3.5vw, 3.2rem);
    color: #F5E6D3;
    letter-spacing: 0.01em;
    margin-bottom: 48px;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 600ms ease-out, transform 600ms ease-out;
}

.section-title.revealed {
    opacity: 1;
    transform: translateY(0);
}

/* === Hero === */
#hero {
    min-height: 100vh;
    display: flex;
    align-items: flex-start;
    padding-top: 20vh;
    padding-left: 15%;
    position: relative;
    overflow: hidden;
}

.hero-inner {
    position: relative;
    z-index: 2;
}

.hero-puzzle-piece {
    opacity: 0;
    transition: opacity 1.5s ease;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1;
    pointer-events: none;
}

.hero-puzzle-piece.visible {
    opacity: 1;
}

.hero-title {
    font-family: 'Playfair Display', serif;
    font-weight: 900;
    font-size: clamp(2.8rem, 6vw, 5.5rem);
    color: #F5E6D3;
    letter-spacing: -0.03em;
    line-height: 1.05;
    position: relative;
    z-index: 3;
    min-height: 1.2em;
}

.hero-title .char {
    display: inline-block;
    opacity: 0;
    transform: scale(1.4);
    transition: opacity 120ms ease-out, transform 120ms ease-out;
}

.hero-title .char.stamped {
    opacity: 1;
    transform: scale(1);
}

.hero-title .char-space {
    display: inline;
    width: 0.3em;
}

.hero-subtitle {
    font-family: 'Work Sans', sans-serif;
    font-weight: 400;
    font-size: clamp(1rem, 1.5vw, 1.3rem);
    color: #C4A882;
    margin-top: 24px;
    opacity: 0;
    transition: opacity 800ms ease 2s;
}

.hero-subtitle.visible {
    opacity: 1;
}

.hero-fragment {
    position: absolute;
    bottom: 15%;
    left: -40px;
    transform: rotate(-3deg);
    z-index: 1;
    opacity: 0;
    transition: opacity 1.2s ease 0.8s;
}

.hero-fragment.visible {
    opacity: 0.6;
}

/* === Connection Nodes === */
.connection-node {
    filter: drop-shadow(0 0 8px rgba(184, 92, 56, 0.33));
    transition: transform 300ms ease-out;
}

.connection-node:hover {
    transform: scale(1.3);
}

/* === Fracture Lines === */
.fracture-line-container {
    padding: 0 48px;
    overflow: hidden;
}

.fracture-line {
    width: 100%;
    height: 40px;
    display: block;
}

.fracture-path {
    stroke-dasharray: 2000;
    stroke-dashoffset: 2000;
    transition: stroke-dashoffset 800ms ease-out;
}

.fracture-path.drawn {
    stroke-dashoffset: 0;
}

/* === Card Grid === */
.card-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 2px;
    background-color: #1A0A10;
}

.flip-card {
    perspective: 1200px;
    min-height: 320px;
    cursor: pointer;
}

.flip-card.wide {
    grid-column: 1 / -1;
}

.flip-card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 320px;
    transition: transform 600ms cubic-bezier(0.4, 0, 0.2, 1);
    transform-style: preserve-3d;
}

.flip-card.flipped .flip-card-inner {
    transform: rotateY(180deg);
}

.flip-card-front,
.flip-card-back {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 32px;
}

.flip-card-front {
    background-color: #3A1526;
    position: relative;
}

.flip-card-back {
    background-color: #F5E6D3;
    transform: rotateY(180deg);
    align-items: flex-start;
    justify-content: flex-start;
    padding: 40px 32px;
    overflow-y: auto;
}

/* === Card Stamp === */
.card-stamp {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 32px;
    height: 32px;
    border-radius: 0;
    background-color: #3A1526;
    border: 2px solid #C4A882;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 800ms ease-in-out;
    z-index: 5;
    clip-path: polygon(
        50% 0%, 65% 5%, 100% 0%, 95% 35%, 100% 50%,
        95% 65%, 100% 100%, 65% 95%, 50% 100%,
        35% 95%, 0% 100%, 5% 65%, 0% 50%,
        5% 35%, 0% 0%, 35% 5%
    );
}

.card-stamp span {
    font-family: 'Space Mono', monospace;
    font-weight: 400;
    font-size: 0.7rem;
    color: #C4A882;
}

.flip-card.flipped .card-stamp {
    transform: rotate(360deg);
}

/* === Card Art === */
.card-puzzle-art {
    max-width: 200px;
    max-height: 160px;
    margin-bottom: 16px;
}

.flip-card.wide .card-puzzle-art {
    max-width: 360px;
}

.card-title {
    font-family: 'Playfair Display', serif;
    font-weight: 900;
    font-size: 1.4rem;
    color: #F5E6D3;
    letter-spacing: -0.01em;
}

/* === Card Back === */
.card-close {
    position: absolute;
    top: 12px;
    right: 12px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    z-index: 10;
}

.card-back-title {
    font-family: 'Playfair Display', serif;
    font-weight: 900;
    font-size: 1.3rem;
    color: #1A0A10;
    margin-bottom: 16px;
}

.card-back-text {
    font-family: 'Work Sans', sans-serif;
    font-weight: 400;
    font-size: clamp(0.9rem, 1vw, 1.05rem);
    line-height: 1.7;
    color: #1A0A10;
}

/* === Footer === */
#site-footer {
    clip-path: polygon(0 20px, 30px 0, 80px 15px, 150px 5px, 250px 18px, 350px 3px, 500px 15px, 650px 8px, 800px 20px, 100% 0, 100% 100%, 0 100%);
    background-color: #5C1A34;
    padding: 60px 48px 40px;
    margin-top: 40px;
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 24px;
}

.footer-brand {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.footer-domain {
    font-family: 'Playfair Display', serif;
    font-weight: 900;
    font-size: 1.8rem;
    color: #F5E6D3;
    letter-spacing: -0.02em;
}

.footer-tagline {
    font-family: 'Work Sans', sans-serif;
    font-weight: 400;
    font-size: 0.95rem;
    color: #E8D4BF;
    opacity: 0.7;
}

.footer-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.footer-label {
    font-family: 'Space Mono', monospace;
    font-weight: 400;
    font-size: 0.75rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #C4A882;
}

/* === Responsive: Mobile === */
@media (max-width: 768px) {
    :root {
        --sidebar-width: 0px;
    }

    #sidebar {
        display: none;
    }

    #sidebar.mobile-open {
        display: block;
        position: fixed;
        top: 64px;
        left: 0;
        width: 100%;
        height: calc(100vh - 64px);
        z-index: 150;
    }

    #mobile-header {
        display: flex;
    }

    #blueprint-grid {
        left: 0;
    }

    #content {
        margin-left: 0;
        padding-top: 64px;
    }

    #hero {
        padding-left: 24px;
        padding-right: 24px;
        padding-top: 15vh;
    }

    .section {
        padding: 60px 20px;
    }

    .card-grid {
        grid-template-columns: 1fr;
    }

    .flip-card.wide {
        grid-column: 1;
    }

    .fracture-line-container {
        padding: 0 20px;
    }

    .hero-fragment {
        display: none;
    }

    .nav-item {
        clip-path: none;
    }

    .nav-item.active {
        transform: none;
        background-color: rgba(122, 46, 69, 0.6);
    }

    #site-footer {
        padding: 60px 20px 40px;
    }

    .footer-content {
        flex-direction: column;
        align-items: flex-start;
    }

    .footer-meta {
        align-items: flex-start;
    }
}

/* === Animations === */
@keyframes pulse-node {
    0% { transform: scale(1); }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); }
}