/* ============================================ */
/* EESUGI.COM - Cryptomeria Research Station    */
/* Sci-Fi Naturalism / Bento-Box Grid           */
/* ============================================ */

/* --- Custom Properties --- */
:root {
    --charred-heartwood: #1A1208;
    --sapwood-dark: #2C2114;
    --bark-medium: #3D3022;
    --aged-parchment: #E8DCC8;
    --lichen-gray: #9B917E;
    --resin-amber: #C4873B;
    --copper-patina: #5B8C6A;
    --scanner-pulse: #D4553A;
    --bento-gap: 2px;
    --morph-ease: cubic-bezier(0.23, 1, 0.32, 1);
}

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

html {
    scroll-behavior: smooth;
    background: var(--charred-heartwood);
}

body {
    font-family: 'Source Sans 3', sans-serif;
    font-weight: 400;
    color: var(--aged-parchment);
    background: var(--charred-heartwood);
    line-height: 1.72;
    font-size: clamp(0.95rem, 1.8vw, 1.15rem);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: var(--resin-amber);
    text-decoration: none;
}

/* --- Bento Grid System --- */
.bento-grid {
    display: grid;
    gap: var(--bento-gap);
    background: var(--charred-heartwood);
}

.bento-cell {
    background: var(--sapwood-dark);
    position: relative;
    overflow: hidden;
    opacity: 0;
    transform: scale(0.92);
    transition: transform 0.8s var(--morph-ease), opacity 0.6s ease-out;
}

.bento-cell.visible {
    opacity: 1;
    transform: scale(1);
}

/* Wood-grain noise overlay */
.bento-cell::before {
    content: '';
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        90deg,
        transparent 0px,
        transparent 3px,
        rgba(26, 18, 8, 0.08) 3px,
        rgba(26, 18, 8, 0.08) 4px
    );
    pointer-events: none;
    z-index: 1;
}

/* --- Grid Notation Labels --- */
.cell-notation {
    position: absolute;
    font-family: 'IBM Plex Mono', monospace;
    font-size: clamp(0.6rem, 1vw, 0.72rem);
    letter-spacing: 0.05em;
    color: var(--lichen-gray);
    opacity: 0.5;
    z-index: 2;
    pointer-events: none;
    font-variant-numeric: tabular-nums;
}

.cell-notation.top-left {
    top: 8px;
    left: 10px;
}

.cell-notation.bottom-right {
    bottom: 8px;
    right: 10px;
}

/* ============================================ */
/* ACT I: SPECIMEN ACQUISITION                  */
/* ============================================ */
.act-1 {
    min-height: 100vh;
    display: flex;
    align-items: stretch;
    padding: var(--bento-gap);
}

.hero-grid {
    width: 100%;
    min-height: 100vh;
    grid-template-columns: 2fr 1fr 1fr;
    grid-template-rows: 2fr 1fr 1fr;
    grid-template-areas:
        "specimen title   readout"
        "specimen contour swatches"
        "specimen contour nav";
    position: relative;
}

.cell-specimen { grid-area: specimen; }
.cell-title    { grid-area: title; }
.cell-readout  { grid-area: readout; }
.cell-contour  { grid-area: contour; }
.cell-swatches { grid-area: swatches; }
.cell-nav      { grid-area: nav; }

/* --- Specimen Cell --- */
.cell-specimen {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--charred-heartwood);
}

.scanner-pulse {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 600px;
    height: 600px;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: radial-gradient(circle, rgba(196, 135, 59, 0.1) 0%, transparent 70%);
    animation: scannerPulse 8s ease-in-out infinite;
    pointer-events: none;
    z-index: 0;
}

@keyframes scannerPulse {
    0%, 100% { opacity: 0.4; transform: translate(-50%, -50%) scale(1); }
    50% { opacity: 0.6; transform: translate(-50%, -50%) scale(1.08); }
}

.specimen-container {
    position: relative;
    width: min(70%, 380px);
    aspect-ratio: 1;
    z-index: 1;
}

.cross-section {
    width: 100%;
    height: 100%;
    animation: specimenRotate 60s linear infinite;
    filter: drop-shadow(0 0 30px rgba(196, 135, 59, 0.15));
}

@keyframes specimenRotate {
    0% { transform: rotateY(0deg); }
    100% { transform: rotateY(360deg); }
}

.cell-specimen {
    perspective: 800px;
}

.hud-reticle {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2;
}

.reticle-line {
    animation: reticleScan 4s linear infinite;
}

@keyframes reticleScan {
    0% { stroke-dashoffset: 0; }
    100% { stroke-dashoffset: -24; }
}

/* --- Title Cell --- */
.cell-title {
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: clamp(16px, 3vw, 40px);
    background: var(--sapwood-dark);
}

.site-title {
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-size: clamp(2.4rem, 5.5vw, 4.8rem);
    letter-spacing: 0.12em;
    color: var(--aged-parchment);
    line-height: 1.1;
    text-transform: uppercase;
}

.title-rule {
    height: 1px;
    background: var(--resin-amber);
    margin: clamp(8px, 1.5vw, 16px) 0;
    width: 0%;
    transition: width 1.2s var(--morph-ease);
}

.title-rule.animate {
    width: 100%;
}

.site-subtitle {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    font-size: clamp(0.7rem, 1.2vw, 0.85rem);
    letter-spacing: 0.05em;
    color: var(--lichen-gray);
    font-variant-numeric: tabular-nums;
}

/* --- Data Readout Cell --- */
.cell-readout {
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: clamp(12px, 2vw, 24px);
    background: var(--charred-heartwood);
}

.data-stream {
    display: flex;
    flex-direction: column;
    gap: clamp(6px, 1vw, 12px);
}

.data-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
    font-family: 'IBM Plex Mono', monospace;
    font-size: clamp(0.7rem, 1.2vw, 0.85rem);
    letter-spacing: 0.05em;
    font-variant-numeric: tabular-nums;
}

.data-label {
    color: var(--lichen-gray);
    min-width: 100px;
    opacity: 0.7;
}

.data-value {
    color: var(--resin-amber);
    font-weight: 400;
    min-width: 60px;
    text-align: right;
}

.data-value.data-text {
    text-align: left;
    min-width: auto;
}

.data-unit {
    color: var(--lichen-gray);
    opacity: 0.5;
    font-size: 0.85em;
}

/* --- Contour Cell --- */
.cell-contour {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: clamp(12px, 2vw, 20px);
    background: var(--charred-heartwood);
}

.contour-svg {
    width: 100%;
    max-height: 80%;
    opacity: 0.8;
}

.contour-label {
    font-family: 'IBM Plex Mono', monospace;
    font-size: clamp(0.6rem, 0.9vw, 0.72rem);
    letter-spacing: 0.08em;
    color: var(--lichen-gray);
    opacity: 0.5;
    margin-top: 8px;
}

/* --- Swatch Strip Cell --- */
.cell-swatches {
    display: flex;
    align-items: center;
    padding: clamp(8px, 1.5vw, 16px);
    background: var(--sapwood-dark);
}

.swatch-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    width: 100%;
}

.swatch {
    flex: 1 1 calc(25% - 3px);
    min-width: 40px;
    aspect-ratio: 1.2;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 4px;
    border: 1px solid rgba(232, 220, 200, 0.08);
}

.swatch span {
    font-family: 'IBM Plex Mono', monospace;
    font-size: clamp(0.45rem, 0.7vw, 0.55rem);
    letter-spacing: 0.04em;
    color: var(--aged-parchment);
    opacity: 0.7;
    text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}

/* --- Nav Cell --- */
.cell-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: clamp(8px, 1.5vw, 16px);
    background: var(--sapwood-dark);
}

.nav-indicator {
    display: flex;
    flex-direction: column;
    gap: clamp(6px, 1vw, 12px);
}

.nav-link {
    font-family: 'IBM Plex Mono', monospace;
    font-size: clamp(0.7rem, 1vw, 0.85rem);
    letter-spacing: 0.08em;
    color: var(--lichen-gray);
    opacity: 0.6;
    transition: color 0.4s ease, opacity 0.4s ease;
    position: relative;
    padding-left: 16px;
}

.nav-link::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    width: 8px;
    height: 1px;
    background: var(--lichen-gray);
    transform: translateY(-50%);
    transition: background 0.4s ease, width 0.4s ease;
}

.nav-link.active {
    color: var(--resin-amber);
    opacity: 1;
}

.nav-link.active::before {
    background: var(--resin-amber);
    width: 12px;
}

/* --- Data Tethers --- */
.data-tethers {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 3;
    opacity: 0.4;
}

.tether-line {
    stroke-dasharray: 300;
    stroke-dashoffset: 300;
    transition: stroke-dashoffset 1.5s var(--morph-ease);
}

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

/* ============================================ */
/* ACT II: THE ARCHIVE                          */
/* ============================================ */
.act-2 {
    min-height: 200vh;
    padding: 0 var(--bento-gap);
}

.archive-row {
    margin-top: var(--bento-gap);
    position: relative;
}

.row-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: clamp(12px, 2vw, 20px) clamp(12px, 2vw, 20px) 0;
    background: transparent;
}

.row-label {
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-size: clamp(1.4rem, 3vw, 2.6rem);
    letter-spacing: -0.02em;
    color: var(--aged-parchment);
}

.row-code {
    font-family: 'IBM Plex Mono', monospace;
    font-size: clamp(0.6rem, 1vw, 0.75rem);
    letter-spacing: 0.05em;
    color: var(--lichen-gray);
    opacity: 0.5;
    font-variant-numeric: tabular-nums;
}

/* Row 1: Ring Chronology (2x2) */
.row-chronology {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto 1fr 1fr;
    grid-template-areas:
        "header header"
        "rings-a rings-b"
        "data-table prose";
}

.row-chronology .row-header { grid-area: header; }
.cell-rings-a    { grid-area: rings-a; }
.cell-rings-b    { grid-area: rings-b; }
.cell-data-table { grid-area: data-table; }
.cell-prose      { grid-area: prose; }

.cell-rings-a,
.cell-rings-b {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: clamp(20px, 3vw, 40px);
    min-height: 360px;
    background: var(--charred-heartwood);
}

.ring-specimen {
    width: min(80%, 260px);
    margin-bottom: 16px;
}

.specimen-label {
    font-family: 'Playfair Display', serif;
    font-weight: 400;
    font-style: italic;
    font-size: clamp(0.85rem, 1.5vw, 1.1rem);
    color: var(--aged-parchment);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.specimen-age {
    font-family: 'IBM Plex Mono', monospace;
    font-size: clamp(0.65rem, 1vw, 0.78rem);
    color: var(--lichen-gray);
    opacity: 0.6;
    letter-spacing: 0.05em;
    margin-top: 4px;
}

/* Data Table */
.cell-data-table {
    padding: clamp(16px, 2.5vw, 32px);
    display: flex;
    align-items: center;
    background: var(--charred-heartwood);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-family: 'IBM Plex Mono', monospace;
    font-size: clamp(0.7rem, 1.1vw, 0.82rem);
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.05em;
}

.data-table th {
    text-align: left;
    padding: 8px 12px;
    color: var(--lichen-gray);
    opacity: 0.6;
    font-weight: 400;
    border-bottom: 1px solid var(--bark-medium);
}

.data-table td {
    padding: 8px 12px;
    color: var(--aged-parchment);
    border-bottom: 1px solid rgba(61, 48, 34, 0.5);
}

.data-table .status-active {
    color: var(--copper-patina);
}

/* Prose Cell */
.cell-prose {
    display: flex;
    align-items: center;
    padding: clamp(20px, 3vw, 40px);
    background: var(--sapwood-dark);
}

.prose-text {
    font-family: 'Playfair Display', serif;
    font-weight: 400;
    font-style: italic;
    font-size: clamp(0.9rem, 1.5vw, 1.08rem);
    line-height: 1.85;
    color: var(--aged-parchment);
    opacity: 0.9;
}

/* Row 2: Canopy Mapping (1x3 -> wide + narrow) */
.row-canopy {
    grid-template-columns: 2fr 1fr;
    grid-template-rows: auto 1fr;
    grid-template-areas:
        "header header"
        "topo-wide elevation";
}

.row-canopy .row-header { grid-area: header; }
.cell-topo-wide  { grid-area: topo-wide; }
.cell-elevation  { grid-area: elevation; }

.cell-topo-wide {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: clamp(16px, 2.5vw, 32px);
    min-height: 320px;
    background: var(--charred-heartwood);
}

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

.topo-label {
    font-family: 'IBM Plex Mono', monospace;
}

.cell-elevation {
    display: flex;
    align-items: center;
    padding: clamp(16px, 2.5vw, 32px);
    background: var(--sapwood-dark);
}

.elevation-data {
    display: flex;
    flex-direction: column;
    gap: clamp(8px, 1.5vw, 14px);
    width: 100%;
}

.elev-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-family: 'IBM Plex Mono', monospace;
    font-size: clamp(0.7rem, 1.1vw, 0.82rem);
    letter-spacing: 0.05em;
    font-variant-numeric: tabular-nums;
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(61, 48, 34, 0.3);
}

.elev-label {
    color: var(--lichen-gray);
    opacity: 0.7;
}

.elev-value {
    color: var(--aged-parchment);
}

/* Row 3: Preservation Protocol (2x2) */
.row-preservation {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto 1fr 1fr;
    grid-template-areas:
        "header header"
        "protocol-a protocol-b"
        "protocol-c protocol-d";
    margin-bottom: var(--bento-gap);
}

.row-preservation .row-header { grid-area: header; }
.cell-protocol-a { grid-area: protocol-a; }
.cell-protocol-b { grid-area: protocol-b; }
.cell-protocol-c { grid-area: protocol-c; }
.cell-protocol-d { grid-area: protocol-d; }

.cell-protocol-a,
.cell-protocol-b,
.cell-protocol-c {
    padding: clamp(20px, 3vw, 40px);
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
}

.cell-protocol-a { background: var(--sapwood-dark); }
.cell-protocol-b { background: var(--charred-heartwood); }
.cell-protocol-c { background: var(--charred-heartwood); }

.protocol-title {
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-size: clamp(0.9rem, 1.5vw, 1.2rem);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--aged-parchment);
    margin-bottom: clamp(8px, 1.5vw, 16px);
}

.protocol-text {
    font-family: 'Source Sans 3', sans-serif;
    font-weight: 400;
    font-size: clamp(0.85rem, 1.4vw, 1rem);
    line-height: 1.72;
    color: var(--aged-parchment);
    opacity: 0.85;
}

/* Protocol Stats */
.cell-protocol-d {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: clamp(20px, 3vw, 40px);
    background: var(--sapwood-dark);
}

.protocol-stats {
    display: flex;
    flex-direction: column;
    gap: clamp(16px, 2.5vw, 28px);
    width: 100%;
}

.stat-block {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-value {
    font-family: 'IBM Plex Mono', monospace;
    font-size: clamp(1.4rem, 3vw, 2.4rem);
    color: var(--resin-amber);
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.05em;
}

.stat-label {
    font-family: 'IBM Plex Mono', monospace;
    font-size: clamp(0.6rem, 0.9vw, 0.72rem);
    color: var(--lichen-gray);
    opacity: 0.6;
    letter-spacing: 0.08em;
}

/* ============================================ */
/* ACT III: SIGNAL                              */
/* ============================================ */
.act-3 {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    background: var(--charred-heartwood);
    overflow: hidden;
}

.act-3::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 600px;
    height: 600px;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: radial-gradient(circle, rgba(196, 135, 59, 0.05) 0%, transparent 70%);
    animation: signalPulse 8s ease-in-out infinite;
    pointer-events: none;
}

@keyframes signalPulse {
    0%, 100% { opacity: 0.8; transform: translate(-50%, -50%) scale(1); }
    50% { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
}

.signal-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    position: relative;
    z-index: 1;
}

.signal-reticle {
    width: clamp(120px, 20vw, 240px);
    height: auto;
    margin-bottom: clamp(24px, 4vw, 48px);
}

.signal-circle {
    animation: reticleRotate 20s linear infinite;
    transform-origin: center;
}

@keyframes reticleRotate {
    0% { stroke-dashoffset: 0; }
    100% { stroke-dashoffset: -75.4; }
}

.signal-quote {
    font-family: 'Playfair Display', serif;
    font-weight: 400;
    font-style: italic;
    font-size: clamp(1.4rem, 3vw, 2.2rem);
    color: var(--aged-parchment);
    letter-spacing: -0.02em;
    line-height: 1.4;
    max-width: 600px;
    margin-bottom: clamp(12px, 2vw, 24px);
}

.signal-station {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    font-size: clamp(0.7rem, 1.2vw, 0.85rem);
    color: var(--lichen-gray);
    letter-spacing: 0.05em;
    font-variant-numeric: tabular-nums;
}

/* ============================================ */
/* HUD Active State Transitions                 */
/* ============================================ */
.bento-cell .cell-notation {
    transition: color 0.6s ease;
}

.bento-cell.in-view .cell-notation {
    color: var(--resin-amber);
}

/* ============================================ */
/* Archive Row Dissolve (Hero fades on scroll)  */
/* ============================================ */
.act-1.scrolled-past .bento-cell {
    transform: scale(0.95);
    opacity: 0.8;
    transition: transform 0.6s var(--morph-ease), opacity 0.6s ease-out;
}

/* ============================================ */
/* Responsive: Mobile Single Column             */
/* ============================================ */
@media (max-width: 768px) {
    .hero-grid {
        grid-template-columns: 1fr;
        grid-template-rows: 60vh auto auto auto auto auto;
        grid-template-areas:
            "specimen"
            "title"
            "readout"
            "contour"
            "swatches"
            "nav";
        min-height: auto;
    }

    .act-1 {
        min-height: auto;
    }

    .cell-specimen {
        min-height: 60vh;
    }

    .row-chronology {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto auto auto;
        grid-template-areas:
            "header"
            "rings-a"
            "rings-b"
            "data-table"
            "prose";
    }

    .row-canopy {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
        grid-template-areas:
            "header"
            "topo-wide"
            "elevation";
    }

    .row-preservation {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto auto auto;
        grid-template-areas:
            "header"
            "protocol-a"
            "protocol-b"
            "protocol-c"
            "protocol-d";
    }

    .data-tethers {
        display: none;
    }

    .data-label {
        min-width: 80px;
    }
}

@media (max-width: 480px) {
    .site-title {
        font-size: clamp(1.8rem, 10vw, 3rem);
        letter-spacing: 0.08em;
    }

    .swatch {
        flex: 1 1 calc(25% - 3px);
        min-width: 30px;
    }

    .swatch span {
        font-size: 0.4rem;
    }
}

/* ============================================ */
/* Reduced Motion                               */
/* ============================================ */
@media (prefers-reduced-motion: reduce) {
    .cross-section {
        animation: none;
    }

    .scanner-pulse {
        animation: none;
    }

    .reticle-line {
        animation: none;
    }

    .signal-circle {
        animation: none;
    }

    .act-3::before {
        animation: none;
    }

    .bento-cell {
        transition: none;
        opacity: 1;
        transform: none;
    }

    .title-rule {
        transition: none;
        width: 100%;
    }

    .tether-line {
        transition: none;
        stroke-dashoffset: 0;
    }
}
