/* ========================================
   layer-2.wiki — Styles
   Isometric blockchain encyclopedia
   Duotone palette, broken-grid, card-flip
   ======================================== */

/* --- CSS Custom Properties --- */
:root {
    --primary-dark: #2c3e50;
    --primary-light: #e8d5b5;
    --duotone-mid: #5a7a8c;
    --card-surface: #f5ede0;
    --card-back: #34495e;
    --highlight: #c0965a;
    --iso-stroke: rgba(44, 62, 80, 0.4);
}

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

html {
    scroll-behavior: smooth;
    font-size: 16px;
}

body {
    font-family: 'Alegreya', Georgia, serif;
    font-weight: 400;
    color: var(--primary-dark);
    background: var(--card-surface);
    line-height: 1.7;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* --- Typography --- */
h1, h2, h3, h4 {
    font-family: 'Alegreya Sans', 'Helvetica Neue', sans-serif;
    letter-spacing: -0.01em;
}

.code-term {
    font-family: 'Fira Code', monospace;
    font-weight: 400;
    font-size: 14px;
    background: rgba(44, 62, 80, 0.08);
    padding: 2px 6px;
    border-radius: 3px;
}

/* --- Noise Overlay --- */
.noise-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: 0.04;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    background-size: 256px 256px;
    z-index: 1;
}

/* --- Isometric Grid Underlay --- */
.isometric-grid-underlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    pointer-events: none;
    z-index: 0;
    background-image:
        repeating-linear-gradient(
            60deg,
            transparent,
            transparent 39px,
            rgba(232, 213, 181, 0.08) 39px,
            rgba(232, 213, 181, 0.08) 40px
        ),
        repeating-linear-gradient(
            -60deg,
            transparent,
            transparent 39px,
            rgba(232, 213, 181, 0.08) 39px,
            rgba(232, 213, 181, 0.08) 40px
        );
    transition: opacity 1.2s ease;
}

.isometric-grid-underlay.visible {
    opacity: 1;
}

/* ========================================
   HERO SECTION
   ======================================== */
#hero {
    position: relative;
    width: 100%;
    height: 100vh;
    min-height: 600px;
    background: var(--primary-dark);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.hero-content {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    width: 90%;
    max-width: 1200px;
}

.hero-text {
    flex: 0 0 40%;
    padding-right: 40px;
}

.hero-title {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.hero-word {
    display: block;
    font-family: 'Alegreya Sans', sans-serif;
    font-weight: 800;
    font-size: clamp(42px, 8vw, 96px);
    line-height: 0.95;
    color: var(--primary-light);
    letter-spacing: -0.02em;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.hero-word.revealed {
    opacity: 1;
    transform: translateY(0);
}

.hero-subtitle {
    font-family: 'Alegreya', serif;
    font-size: clamp(14px, 1.5vw, 18px);
    color: var(--duotone-mid);
    margin-top: 24px;
    opacity: 0;
    transition: opacity 0.6s ease 0.8s;
}

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

.hero-illustration {
    flex: 0 0 60%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.iso-stack {
    width: 100%;
    max-width: 500px;
    height: auto;
}

/* SVG platform stroke animations */
.platform polygon,
.platform text {
    stroke-dasharray: 600;
    stroke-dashoffset: 600;
    opacity: 0;
    transition: stroke-dashoffset 0.4s ease, opacity 0.4s ease;
}

.platform.drawn polygon,
.platform.drawn text {
    stroke-dashoffset: 0;
    opacity: 1;
}

.pipes line {
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
    transition: stroke-dashoffset 0.2s ease;
}

.pipes line.drawn {
    stroke-dashoffset: 0;
}

/* Scroll hint */
.scroll-hint {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: var(--primary-light);
    font-family: 'Alegreya Sans', sans-serif;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    opacity: 0;
    transition: opacity 0.6s ease 1.6s;
    animation: scrollBounce 2s ease-in-out infinite 2s;
}

.scroll-hint.revealed {
    opacity: 0.6;
}

@keyframes scrollBounce {
    0%, 100% { transform: translateX(-50%) translateY(0); }
    50% { transform: translateX(-50%) translateY(6px); }
}

/* ========================================
   INDEX SECTION — Broken Grid Cards
   ======================================== */
#index {
    position: relative;
    padding: 100px 5% 120px;
    background: var(--card-surface);
}

.section-header {
    text-align: center;
    margin-bottom: 60px;
}

.section-header h2 {
    font-family: 'Alegreya Sans', sans-serif;
    font-weight: 800;
    font-size: clamp(28px, 4vw, 48px);
    color: var(--primary-dark);
    letter-spacing: -0.01em;
}

.section-desc {
    font-family: 'Alegreya', serif;
    font-size: clamp(14px, 1.3vw, 17px);
    color: var(--duotone-mid);
    margin-top: 10px;
}

/* Broken-grid card layout */
.card-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    max-width: 1100px;
    margin: 0 auto;
    position: relative;
}

/* Broken-grid offsets for individual cards */
.wiki-card:nth-child(1) { transform: translateY(0); }
.wiki-card:nth-child(2) { transform: translateY(-15px); }
.wiki-card:nth-child(3) { transform: translateY(10px); }
.wiki-card:nth-child(4) { transform: translateY(20px); }
.wiki-card:nth-child(5) { transform: translateY(-10px); }
.wiki-card:nth-child(6) { transform: translateY(5px); }
.wiki-card:nth-child(7) { transform: translateY(-20px); }
.wiki-card:nth-child(8) { transform: translateY(15px); }
.wiki-card:nth-child(9) { transform: translateY(-5px); }

/* Card base */
.wiki-card {
    perspective: 1000px;
    cursor: pointer;
    min-height: 260px;
    opacity: 0;
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.wiki-card.entered {
    opacity: 1;
}

/* Staggered entry from alternating sides */
.wiki-card.enter-left {
    transform: translateX(-30px);
}

.wiki-card.enter-right {
    transform: translateX(30px);
}

.wiki-card.entered:nth-child(1) { transform: translateY(0); }
.wiki-card.entered:nth-child(2) { transform: translateY(-15px); }
.wiki-card.entered:nth-child(3) { transform: translateY(10px); }
.wiki-card.entered:nth-child(4) { transform: translateY(20px); }
.wiki-card.entered:nth-child(5) { transform: translateY(-10px); }
.wiki-card.entered:nth-child(6) { transform: translateY(5px); }
.wiki-card.entered:nth-child(7) { transform: translateY(-20px); }
.wiki-card.entered:nth-child(8) { transform: translateY(15px); }
.wiki-card.entered:nth-child(9) { transform: translateY(-5px); }

/* Card hover lift */
.wiki-card:hover {
    z-index: 10;
}

.wiki-card:hover .card-inner:not(.flipped) {
    transform: translateY(-4px);
    box-shadow: 0 12px 40px rgba(44, 62, 80, 0.15);
}

/* Card inner — the flipping container */
.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 260px;
    transition: transform 0.6s ease, box-shadow 0.2s ease;
    transform-style: preserve-3d;
    border-radius: 6px;
    box-shadow: 0 4px 20px rgba(44, 62, 80, 0.08);
}

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

/* Card faces */
.card-front,
.card-back {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    border-radius: 6px;
    padding: 24px;
    display: flex;
    flex-direction: column;
}

.card-front {
    background: var(--card-surface);
    border: 1px solid rgba(44, 62, 80, 0.08);
}

.card-back {
    background: var(--card-back);
    transform: rotateY(180deg);
    color: var(--primary-light);
    justify-content: center;
}

/* Card front content */
.card-icon {
    width: 48px;
    height: 48px;
    margin-bottom: 16px;
}

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

.card-title {
    font-family: 'Alegreya Sans', sans-serif;
    font-weight: 700;
    font-size: clamp(18px, 2vw, 22px);
    color: var(--primary-dark);
    margin-bottom: 10px;
    letter-spacing: -0.01em;
}

.card-def {
    font-family: 'Alegreya', serif;
    font-size: clamp(14px, 1.2vw, 16px);
    color: var(--duotone-mid);
    line-height: 1.6;
    flex-grow: 1;
}

.flip-hint {
    font-family: 'Alegreya Sans', sans-serif;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--highlight);
    margin-top: 12px;
    opacity: 0.7;
}

/* Card back content */
.card-title-back {
    font-family: 'Alegreya Sans', sans-serif;
    font-weight: 700;
    font-size: clamp(16px, 1.8vw, 20px);
    color: var(--highlight);
    margin-bottom: 14px;
    letter-spacing: -0.01em;
}

.card-detail {
    font-family: 'Alegreya', serif;
    font-size: clamp(13px, 1.1vw, 15px);
    color: var(--primary-light);
    line-height: 1.65;
}

.card-back .code-term {
    background: rgba(232, 213, 181, 0.12);
    color: var(--highlight);
}

/* ========================================
   DEEP DIVE SECTION
   ======================================== */
#deep-dive {
    position: relative;
    padding: 100px 5% 120px;
    background: linear-gradient(180deg, var(--card-surface) 0%, rgba(232, 213, 181, 0.3) 100%);
}

.deep-dive-article {
    display: flex;
    align-items: flex-start;
    gap: 60px;
    max-width: 1000px;
    margin: 0 auto 80px;
}

.deep-dive-article.reverse {
    flex-direction: row-reverse;
}

.article-illustration {
    flex: 0 0 300px;
    position: relative;
}

.article-illustration svg {
    width: 100%;
    height: auto;
    background: rgba(44, 62, 80, 0.03);
    border-radius: 6px;
    border: 1px solid rgba(44, 62, 80, 0.06);
}

/* Illustration breakout into margin — overlap effect */
.deep-dive-article .article-illustration {
    margin-left: -40px;
}

.deep-dive-article.reverse .article-illustration {
    margin-left: 0;
    margin-right: -40px;
}

.article-content {
    flex: 1;
    max-width: 38em;
}

.article-content h3 {
    font-family: 'Alegreya Sans', sans-serif;
    font-weight: 700;
    font-size: clamp(22px, 3vw, 32px);
    color: var(--primary-dark);
    margin-bottom: 20px;
    letter-spacing: -0.01em;
}

.article-content p {
    font-family: 'Alegreya', serif;
    font-size: clamp(16px, 1.5vw, 18px);
    color: var(--primary-dark);
    line-height: 1.7;
    margin-bottom: 16px;
}

.article-content p:last-child {
    margin-bottom: 0;
}

.article-content em {
    font-style: italic;
    color: var(--highlight);
}

/* ========================================
   PROTOCOL MAP FOOTER
   ======================================== */
#protocol-map {
    position: relative;
    padding: 100px 5% 80px;
    background: var(--primary-dark);
    color: var(--primary-light);
}

#protocol-map .section-header h2 {
    color: var(--primary-light);
}

#protocol-map .section-desc {
    color: var(--duotone-mid);
}

.map-container {
    max-width: 900px;
    margin: 0 auto;
    position: relative;
}

.protocol-map-svg {
    width: 100%;
    height: auto;
}

/* Proto-node hover */
.proto-node {
    cursor: pointer;
    transition: opacity 0.2s ease;
}

.proto-node:hover polygon {
    fill-opacity: 0.4;
    stroke-opacity: 0.8;
}

.proto-node:hover text {
    fill: var(--highlight);
}

/* ========================================
   FOOTER
   ======================================== */
#site-footer {
    background: var(--primary-dark);
    border-top: 1px solid rgba(232, 213, 181, 0.08);
    padding: 30px 5%;
    text-align: center;
}

#site-footer p {
    font-family: 'Alegreya Sans', sans-serif;
    font-size: 13px;
    font-weight: 400;
    color: var(--duotone-mid);
    letter-spacing: 0.02em;
}

/* ========================================
   RESPONSIVE
   ======================================== */
@media (max-width: 900px) {
    .hero-content {
        flex-direction: column;
        text-align: center;
    }

    .hero-text {
        flex: none;
        padding-right: 0;
        margin-bottom: 40px;
    }

    .hero-title {
        align-items: center;
    }

    .hero-illustration {
        flex: none;
        width: 80%;
    }

    .card-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Reset broken-grid offsets on smaller screens */
    .wiki-card:nth-child(n) {
        transform: translateY(0);
    }
    .wiki-card.entered:nth-child(n) {
        transform: translateY(0);
    }

    .deep-dive-article,
    .deep-dive-article.reverse {
        flex-direction: column;
    }

    .article-illustration {
        flex: none;
        width: 100%;
        max-width: 300px;
        margin: 0 auto 30px !important;
    }
}

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

    .wiki-card {
        min-height: 220px;
    }

    .card-inner {
        min-height: 220px;
    }

    .hero-word {
        font-size: clamp(36px, 12vw, 60px);
    }

    #index,
    #deep-dive,
    #protocol-map {
        padding: 60px 5% 80px;
    }
}
