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

:root {
    --ash-void: #f4f4f6;
    --slate-abyss: #1c1c22;
    --graphite: #2d2d35;
    --fog: #8b8b96;
    --mist: #d4d4db;
    --wire: #c8c8d0;
    --fracture-cyan: #00e5ff;
    --fracture-magenta: #e040fb;
    --fracture-lime: #76ff03;
    --deep-bg: #16161b;
    --mid-bg: #ededf1;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 300;
    font-size: clamp(1rem, 1.2vw, 1.15rem);
    line-height: 1.75;
    letter-spacing: 0.01em;
    color: var(--graphite);
    background: var(--ash-void);
    overflow-x: hidden;
}

/* === SCROLL INDICATOR === */
#scroll-indicator {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 100;
    opacity: 0.6;
    transition: opacity 0.3s;
}

#scroll-indicator:hover {
    opacity: 1;
}

/* === CHAMBERS === */
.chamber {
    position: relative;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* === CHAMBER I — THE PORTAL === */
#chamber-1 {
    background: var(--ash-void);
}

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

.portal-hexagon {
    width: 65vmin;
    height: 65vmin;
    position: absolute;
}

.hex-draw {
    stroke-dasharray: 1560;
    stroke-dashoffset: 1560;
    animation: drawHex 1.8s cubic-bezier(0.65, 0, 0.35, 1) forwards;
}

@keyframes drawHex {
    to { stroke-dashoffset: 0; }
}

.portal-text {
    position: relative;
    text-align: center;
    z-index: 2;
    opacity: 0;
    animation: fadeIn 1s 1.4s ease forwards;
}

@keyframes fadeIn {
    to { opacity: 1; }
}

.portal-title {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: clamp(3rem, 6vw, 5rem);
    color: var(--graphite);
    letter-spacing: 0.08em;
    line-height: 1.1;
}

.portal-subtitle {
    font-weight: 300;
    font-size: 0.9rem;
    color: var(--fog);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    margin-top: 1rem;
}

/* === CHAMBER II — THE LATTICE === */
#chamber-2 {
    background: var(--mid-bg);
}

.lattice-container {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 2rem;
}

.hex-grid {
    display: grid;
    grid-template-columns: repeat(3, 180px);
    gap: 14px;
    justify-content: center;
}

.hex-grid .hex-cell:nth-child(1),
.hex-grid .hex-cell:nth-child(2),
.hex-grid .hex-cell:nth-child(3) {
    transform: translateX(0);
}

.hex-grid .hex-cell:nth-child(4),
.hex-grid .hex-cell:nth-child(5),
.hex-grid .hex-cell:nth-child(6) {
    transform: translateX(calc(90px + 7px));
    margin-left: calc(-90px - 7px);
}

.hex-grid .hex-cell:nth-child(7),
.hex-grid .hex-cell:nth-child(8),
.hex-grid .hex-cell:nth-child(9) {
    transform: translateX(0);
}

.hex-cell {
    width: 180px;
    height: 200px;
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
    background: var(--ash-void);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: scale(0.92);
    transition: opacity 0.5s ease, transform 0.5s ease, background 0.15s ease;
    position: relative;
    cursor: default;
}

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

.hex-cell.center-cell.visible {
    transform: scale(1.15);
}

.hex-cell::before {
    content: '';
    position: absolute;
    inset: 0;
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
    border: 1px solid var(--wire);
    pointer-events: none;
    transition: border-color 0.15s;
}

.hex-cell:hover::before {
    border-color: var(--fracture-cyan);
}

.hex-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    text-align: center;
}

.kanji {
    font-family: 'Noto Sans JP', sans-serif;
    font-weight: 300;
    font-size: 1.8rem;
    color: var(--graphite);
}

.romaji {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 300;
    font-size: 0.65rem;
    color: var(--fog);
    letter-spacing: 0.08em;
    text-transform: lowercase;
}

/* === CHAMBER III — THE FRACTURE === */
#chamber-3 {
    background: linear-gradient(to bottom, var(--mid-bg), var(--slate-abyss));
    flex-direction: column;
    padding: 4rem 2rem;
}

.fracture-container {
    position: relative;
    width: 100%;
    max-width: 800px;
    min-height: 80vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.fracture-grid {
    display: grid;
    grid-template-columns: repeat(3, 150px);
    gap: 20px;
    justify-content: center;
    position: relative;
    z-index: 2;
}

.fracture-cell {
    width: 150px;
    height: 170px;
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
    background: rgba(44, 44, 53, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}

.fracture-cell .kanji {
    color: var(--mist);
    font-size: 1.4rem;
}

.fracture-cell .romaji {
    color: var(--fog);
}

.fracture-cell:nth-child(1) { transform: rotate(-2deg) translate(-4px, 3px); }
.fracture-cell:nth-child(2) { transform: rotate(3deg) translate(6px, -2px); }
.fracture-cell:nth-child(3) { transform: rotate(-1deg) translate(-3px, 5px); }
.fracture-cell:nth-child(4) { transform: rotate(2deg) translate(8px, -4px); }
.fracture-cell:nth-child(5) { transform: rotate(-3deg) translate(-5px, 6px); }
.fracture-cell:nth-child(6) { transform: rotate(1deg) translate(4px, -8px); }

.fracture-lines {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
}

.scanline-overlay {
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        to bottom,
        transparent,
        transparent 3px,
        rgba(0, 229, 255, 0.02) 3px,
        rgba(0, 229, 255, 0.02) 4px
    );
    pointer-events: none;
    z-index: 3;
    animation: scanlineDrift 15s linear infinite;
}

@keyframes scanlineDrift {
    0% { transform: translateY(0); }
    100% { transform: translateY(80px); }
}

.flowing-curves {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
}

.curve-draw {
    stroke-dasharray: 1200;
    stroke-dashoffset: 1200;
    transition: stroke-dashoffset 1.5s ease;
}

.curve-draw.drawn {
    stroke-dashoffset: 0;
}

.fracture-text {
    position: relative;
    z-index: 4;
    max-width: 38ch;
    text-align: center;
    margin-top: 3rem;
    font-weight: 300;
    font-size: 1rem;
    color: var(--mist);
    line-height: 1.85;
}

/* === CHAMBER IV — THE CURRENT === */
#chamber-4 {
    background: var(--slate-abyss);
    min-height: 100vh;
    padding: 6rem 2rem;
}

.current-curves {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: 0.5;
}

.current-text {
    position: relative;
    z-index: 2;
    max-width: 38ch;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.current-text p {
    font-weight: 300;
    font-size: 1.05rem;
    color: var(--mist);
    line-height: 1.85;
}

.current-text p.glitch-flash {
    animation: chromaticSplit 120ms ease;
}

@keyframes chromaticSplit {
    0% { text-shadow: -2px 0 var(--fracture-cyan), 2px 0 var(--fracture-magenta); }
    50% { text-shadow: 2px 0 var(--fracture-cyan), -2px 0 var(--fracture-magenta); }
    100% { text-shadow: none; }
}

/* === CHAMBER V — THE SEAL === */
#chamber-5 {
    background: var(--deep-bg);
    flex-direction: column;
    gap: 2rem;
}

.seal-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
}

.seal-sigil {
    width: min(60vmin, 400px);
    height: min(60vmin, 400px);
    animation: sealBreathe 6s ease-in-out infinite;
}

@keyframes sealBreathe {
    0%, 100% { transform: scale(0.98); }
    50% { transform: scale(1.02); }
}

.sigil-layer[data-layer="4"] {
    animation: rotateCW 720s linear infinite;
}
.sigil-layer[data-layer="3"] {
    animation: rotateCCW 1200s linear infinite;
}
.sigil-layer[data-layer="2"] {
    animation: rotateCW 1800s linear infinite;
}
.sigil-layer[data-layer="1"] {
    /* static */
}

@keyframes rotateCW {
    to { transform: rotate(360deg); }
}
@keyframes rotateCCW {
    to { transform: rotate(-360deg); }
}

.seal-kanji {
    font-family: 'Noto Sans JP', sans-serif;
    font-weight: 300;
    font-size: 2rem;
    fill: var(--mist);
}

.seal-url {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 500;
    font-size: 0.8rem;
    letter-spacing: 0.2em;
    color: var(--fog);
}

/* === REDUCED MOTION === */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
    .hex-draw {
        stroke-dashoffset: 0;
    }
    .portal-text {
        opacity: 1;
    }
    .hex-cell {
        opacity: 1;
        transform: scale(1);
    }
    .curve-draw {
        stroke-dashoffset: 0;
    }
}
