/* ===========================================
   simulai.xyz — Isometric Command Theater
   Forest-Green Palette | Split-Screen Layout
   =========================================== */

/* --- CSS Custom Properties --- */
:root {
    --deep-canopy: #0e1f10;
    --lichen-paper: #eaf0e4;
    --moss-ink: #3a5c3b;
    --fern-glow: #7dba84;
    --amber-lichen: #c4a94d;
    --bark-shadow: #1a2e1c;
    --forest-night: #0b1a0d;
    --sage-mist: #a3c4a6;
    --canopy-edge: #2d4a2e;

    --font-display: 'Chakra Petch', sans-serif;
    --font-body: 'Lora', serif;
    --font-mono: 'Fira Code', monospace;

    --mx: 50%;
    --my: 50%;
}

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

html {
    scroll-behavior: smooth;
    overflow-x: hidden;
}

body {
    background: var(--deep-canopy);
    color: var(--forest-night);
    font-family: var(--font-body);
    font-weight: 400;
    line-height: 1.75;
    overflow-x: hidden;
}

/* --- INTRO SCREEN --- */
#intro-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: var(--deep-canopy);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 1000ms ease-in-out;
}

#intro-screen.exit {
    transform: translateY(-100vh);
}

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

#intro-grid {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    transition: opacity 1200ms ease;
    pointer-events: none;
}

#intro-grid.visible {
    opacity: 0.04;
}

#intro-content {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    z-index: 1;
}

/* --- Intro Cube --- */
#intro-cube {
    width: 80px;
    height: 80px;
    position: relative;
    transform: rotateX(60deg) rotateZ(-45deg);
    transform-style: preserve-3d;
    margin-bottom: 24px;
}

.cube-face {
    position: absolute;
    opacity: 0;
    transition: opacity 800ms cubic-bezier(0.34, 1.56, 0.64, 1),
                transform 800ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.cube-top {
    width: 80px;
    height: 80px;
    background: var(--fern-glow);
    transform: translateY(-40px) rotateX(90deg);
    transform-origin: bottom;
}

.cube-left {
    width: 80px;
    height: 80px;
    background: var(--moss-ink);
    transform: translateX(-40px) rotateY(-90deg);
    transform-origin: right;
}

.cube-right {
    width: 80px;
    height: 80px;
    background: var(--bark-shadow);
    transform: translateX(0) rotateY(0deg);
    top: 0;
    left: 0;
}

.cube-face.assembled {
    opacity: 1;
}

/* --- Intro Title (Typewriter) --- */
#intro-title {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: clamp(2.8rem, 7vw, 6rem);
    color: var(--fern-glow);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    white-space: nowrap;
    overflow: hidden;
    width: 0;
    border-right: 3px solid var(--fern-glow);
}

#intro-title.typing {
    animation: typewriter 1200ms steps(12) forwards,
               blink-caret 600ms step-end 3;
}

#intro-title.typed {
    width: auto;
    border-right-color: transparent;
}

@keyframes typewriter {
    from { width: 0; }
    to { width: 100%; }
}

@keyframes blink-caret {
    50% { border-right-color: transparent; }
}

/* --- Intro Subtitle --- */
#intro-subtitle {
    font-family: var(--font-body);
    font-weight: 400;
    font-style: italic;
    font-size: clamp(0.9rem, 1.3vw, 1.1rem);
    color: var(--sage-mist);
    opacity: 0;
    transition: opacity 600ms ease;
}

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

/* --- MAIN LAYOUT --- */
#main-layout {
    position: relative;
    width: 100%;
}

.isometric-grid-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0.04;
    pointer-events: none;
    z-index: 0;
}

/* --- SPLIT SECTION --- */
.split-section {
    display: grid;
    grid-template-columns: 47% 53%;
    min-height: 100vh;
    position: relative;
}

/* --- Observation Deck (Left) --- */
.observation-deck {
    background: var(--lichen-paper);
    border-right: 6px solid var(--canopy-edge);
    border-right-style: solid;
    position: relative;
    z-index: 1;
}

.observation-deck::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 6px;
    height: 100%;
    background: var(--canopy-edge);
    opacity: 0.4;
}

.deck-inner {
    padding: clamp(2rem, 5vw, 5rem) clamp(1.5rem, 3vw, 3rem) clamp(2rem, 5vw, 5rem) clamp(2rem, 5vw, 5rem);
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 100vh;
    position: relative;
}

.section-heading {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: clamp(1.5rem, 3vw, 2.4rem);
    color: var(--moss-ink);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 0.5rem;
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 600ms ease, transform 600ms ease;
}

.section-rule {
    border: none;
    border-top: 1px dashed rgba(45, 74, 46, 0.3);
    margin-bottom: clamp(1.5rem, 3vh, 2.5rem);
}

.section-body {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(1rem, 1.4vw, 1.15rem);
    color: var(--forest-night);
    line-height: 1.75;
    margin-bottom: clamp(1rem, 2vh, 1.5rem);
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 600ms ease, transform 600ms ease;
}

.section-caption {
    font-family: var(--font-mono);
    font-weight: 400;
    font-size: clamp(0.65rem, 0.9vw, 0.8rem);
    color: var(--canopy-edge);
    letter-spacing: 0.02em;
    margin-top: clamp(1rem, 2vh, 2rem);
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 600ms ease 200ms, transform 600ms ease 200ms;
}

/* Visible state for scroll animations */
.split-section.in-view .section-heading,
.split-section.in-view .section-body,
.split-section.in-view .section-caption {
    opacity: 1;
    transform: translateY(0);
}

.split-section.in-view .section-body:nth-of-type(2) {
    transition-delay: 100ms;
}

.split-section.in-view .section-body:nth-of-type(3) {
    transition-delay: 200ms;
}

/* --- Simulation Chamber (Right) --- */
.simulation-chamber {
    background: var(--deep-canopy);
    position: relative;
    overflow: hidden;
    z-index: 1;
}

.chamber-inner {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Spotlight layer */
.spotlight-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(
        circle 200px at var(--mx) var(--my),
        rgba(125, 186, 132, 0.12) 0%,
        transparent 100%
    );
    pointer-events: none;
    z-index: 3;
}

/* Noise grain layer */
.noise-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2;
    opacity: 0.03;
}

.noise-layer::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence baseFrequency='0.65' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
    background-repeat: repeat;
}

/* --- Vintage Map Overlay --- */
.vintage-map {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

/* --- Scene Container --- */
.scene-container {
    position: relative;
    width: 350px;
    height: 350px;
    z-index: 4;
}

/* --- Isometric Scene --- */
.iso-scene {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotateX(60deg) rotateZ(-45deg);
    transform-style: preserve-3d;
    width: 300px;
    height: 300px;
}

/* --- Isometric Buildings --- */
.iso-building {
    position: absolute;
    width: var(--w);
    height: var(--h);
    left: calc(50% + var(--x));
    top: calc(50% + var(--y));
    transform-style: preserve-3d;
    transform: scaleY(0);
    transform-origin: bottom center;
    transition: transform 600ms cubic-bezier(0.22, 1, 0.36, 1);
    cursor: default;
}

.split-section.in-view .iso-building {
    transform: scaleY(1);
}

.split-section.in-view .iso-building.b1 { transition-delay: 0ms; }
.split-section.in-view .iso-building.b2 { transition-delay: 80ms; }
.split-section.in-view .iso-building.b3 { transition-delay: 160ms; }
.split-section.in-view .iso-building.b4 { transition-delay: 240ms; }
.split-section.in-view .iso-building.b5 { transition-delay: 320ms; }
.split-section.in-view .iso-building.b6 { transition-delay: 400ms; }
.split-section.in-view .iso-building.b7 { transition-delay: 480ms; }
.split-section.in-view .iso-building.b8 { transition-delay: 560ms; }

/* Building faces */
.iso-building::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--moss-ink);
}

.iso-building::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: -50%;
    width: 50%;
    height: 100%;
    background: var(--bark-shadow);
    transform: skewY(-30deg);
    transform-origin: bottom left;
}

/* Top face via nested approach - using box-shadow trick */
.iso-building::before {
    background: linear-gradient(to right, var(--moss-ink) 50%, var(--bark-shadow) 50%);
    box-shadow: 0 -8px 0 0 var(--fern-glow);
}

/* Tooltip label */
.iso-building .building-tooltip {
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%) rotateZ(45deg) rotateX(-60deg);
    background: var(--bark-shadow);
    color: var(--fern-glow);
    font-family: var(--font-mono);
    font-size: clamp(0.65rem, 0.9vw, 0.8rem);
    letter-spacing: 0.02em;
    padding: 4px 8px;
    border-radius: 2px;
    white-space: nowrap;
    opacity: 0;
    transition: opacity 200ms ease;
    pointer-events: none;
    z-index: 10;
}

.iso-building.hovered .building-tooltip {
    opacity: 1;
}

/* Depth shift on hover */
.iso-building.nearby {
    transform: scaleY(1) translateZ(8px);
    transition: transform 200ms ease;
}

/* --- Data Flow Lines --- */
.data-flow-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
    opacity: 0;
    transition: opacity 600ms ease 400ms;
}

.split-section.in-view .data-flow-svg {
    opacity: 1;
}

.flow-line {
    fill: none;
    stroke: var(--fern-glow);
    stroke-width: 1;
    stroke-dasharray: 8 12;
    animation: flowDash 4s linear infinite;
}

.flow-line.flow-delay-1 {
    animation-delay: -1.5s;
    animation-duration: 5s;
}

.flow-line.flow-delay-2 {
    animation-delay: -3s;
    animation-duration: 6s;
}

@keyframes flowDash {
    to {
        stroke-dashoffset: -40;
    }
}

/* --- Section Divider --- */
.section-divider {
    width: 100%;
    height: 60px;
    position: relative;
    z-index: 2;
    overflow: hidden;
}

.contour-line {
    width: 100%;
    height: 100%;
}

.contour-path {
    stroke-dasharray: 1200;
    stroke-dashoffset: 1200;
    opacity: 0.4;
    transition: stroke-dashoffset 2s ease;
}

.section-divider.in-view .contour-path {
    stroke-dashoffset: 0;
}

/* --- Vintage Stamps --- */
.section-stamp {
    position: absolute;
    width: 80px;
    height: 80px;
    border: 2px solid var(--amber-lichen);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: rotate(-7deg);
    clip-path: polygon(3% 0%, 100% 2%, 97% 100%, 0% 98%);
    opacity: 0.6;
}

.stamp-tl {
    top: clamp(1.5rem, 3vw, 3rem);
    right: clamp(1rem, 2vw, 2rem);
}

.stamp-br {
    bottom: clamp(1.5rem, 3vw, 3rem);
    right: clamp(1rem, 2vw, 2rem);
}

.stamp-text {
    font-family: var(--font-mono);
    font-size: clamp(0.55rem, 0.8vw, 0.7rem);
    color: var(--amber-lichen);
    letter-spacing: 0.02em;
    text-align: center;
}

/* --- FOOTER --- */
#site-footer {
    background: var(--deep-canopy);
    border-top: 1px solid var(--canopy-edge);
    padding: clamp(2rem, 4vw, 4rem) clamp(2rem, 5vw, 5rem);
    position: relative;
    z-index: 2;
}

.footer-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1400px;
    margin: 0 auto;
}

.footer-left {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.footer-title {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: clamp(1rem, 1.5vw, 1.2rem);
    color: var(--fern-glow);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.footer-sub {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(0.8rem, 1vw, 0.95rem);
    color: var(--sage-mist);
    line-height: 1.5;
}

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

.footer-coord {
    font-family: var(--font-mono);
    font-size: clamp(0.65rem, 0.9vw, 0.8rem);
    color: var(--fern-glow);
    letter-spacing: 0.02em;
}

/* --- RESPONSIVE (< 768px) --- */
@media (max-width: 768px) {
    .split-section {
        grid-template-columns: 1fr;
        grid-template-rows: 60vh auto;
    }

    .simulation-chamber {
        order: -1;
    }

    .observation-deck {
        border-right: none;
        border-top: 6px solid var(--canopy-edge);
    }

    .observation-deck::after {
        display: none;
    }

    .deck-inner {
        min-height: auto;
        padding: clamp(1.5rem, 4vw, 3rem);
    }

    .chamber-inner {
        min-height: 60vh;
    }

    .scene-container {
        width: 280px;
        height: 280px;
    }

    .footer-inner {
        flex-direction: column;
        gap: 1.5rem;
        align-items: flex-start;
    }

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

    .section-stamp {
        width: 60px;
        height: 60px;
    }

    #intro-cube {
        width: 60px;
        height: 60px;
    }

    .cube-top, .cube-left, .cube-right {
        width: 60px;
        height: 60px;
    }

    .cube-top {
        transform: translateY(-30px) rotateX(90deg);
    }

    .cube-left {
        transform: translateX(-30px) rotateY(-90deg);
    }
}

/* --- SELECTION STYLING --- */
::selection {
    background: var(--fern-glow);
    color: var(--deep-canopy);
}

/* --- SCROLLBAR --- */
::-webkit-scrollbar {
    width: 6px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--moss-ink);
    border-radius: 3px;
}

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