/* ============================================
   simidiot.net — Palazzo of Procedural Grandeur
   ============================================ */

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

html {
    scroll-behavior: smooth;
    background: #0f0b18;
}

body {
    font-family: 'Nunito Sans', sans-serif;
    font-weight: 400;
    color: #d9ceb8;
    background: #0f0b18;
    overflow-x: hidden;
    line-height: 1.7;
    font-size: clamp(1rem, 1.2vw, 1.15rem);
}

/* --- Noise Overlay --- */
#noise-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 9999;
    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.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 256px 256px;
}

/* --- Fixed Sigil --- */
#sigil {
    position: fixed;
    top: 24px;
    right: 28px;
    z-index: 1000;
    cursor: pointer;
    filter: drop-shadow(0 0 8px rgba(201,168,76,0.3));
    animation: sigil-glow 4s ease-in-out infinite;
    transition: transform 0.3s ease;
}
#sigil:hover { transform: scale(1.15); filter: drop-shadow(0 0 12px #d4883a); }

@keyframes sigil-glow {
    0%, 100% { filter: drop-shadow(0 0 8px rgba(201,168,76,0.2)); }
    50% { filter: drop-shadow(0 0 12px rgba(201,168,76,0.4)); }
}

/* --- Typewriter Thread (fixed left) --- */
#typewriter-thread {
    position: fixed;
    left: 40px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 900;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    font-family: 'Courier Prime', monospace;
    font-size: 0.85rem;
    color: #a89060;
    letter-spacing: 0.06em;
    opacity: 0.7;
    max-height: 60vh;
    overflow: hidden;
}
#typewriter-cursor {
    animation: blink 1s step-end infinite;
}
@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* --- Particle Canvas --- */
#particles-canvas {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 800;
}

/* --- Chamber Base --- */
.chamber {
    position: relative;
    min-height: 100vh;
    overflow: hidden;
    background: #0f0b18;
}

.rd-canvas {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    opacity: 0.35;
    z-index: 1;
    pointer-events: none;
}

.chamber-content {
    position: relative;
    z-index: 10;
    padding: 80px 100px;
}

.chamber-title {
    font-family: 'Nunito Sans', sans-serif;
    font-weight: 600;
    font-size: clamp(1.4rem, 3vw, 2.8rem);
    color: #f2e8d0;
    letter-spacing: 0.02em;
    line-height: 1.15;
    margin-bottom: 40px;
}

/* --- Chamber Dividers --- */
.chamber-divider, .lissajous-divider {
    position: absolute;
    bottom: 0; left: 0;
    width: 100%;
    height: 120px;
    z-index: 20;
}
.lissajous-divider {
    height: 100px;
}

/* --- Chamber I: Foyer --- */
#chamber-1 {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    background: #0f0b18;
}
#chamber-1 .rd-canvas { opacity: 0.45; }

.foyer-content {
    padding-left: 20%;
    padding-top: 10vh;
}

#title-container {
    position: relative;
    min-height: clamp(6rem, 15vw, 14rem);
}

.typewriter-title {
    font-family: 'Courier Prime', monospace;
    font-size: 1.2rem;
    color: #a89060;
    letter-spacing: 0.06em;
    display: inline-block;
}

#title-main {
    font-family: 'Nunito', sans-serif;
    font-weight: 900;
    font-size: clamp(6rem, 15vw, 14rem);
    color: #c9a84c;
    text-transform: lowercase;
    letter-spacing: 0.04em;
    text-shadow: 0 2px 0 #8b6914, 0 4px 8px rgba(0,0,0,0.3), 0 0 60px rgba(201,168,76,0.15);
    line-height: 1;
    transition: opacity 0.2s ease-out;
}

#title-main.hidden {
    opacity: 0;
    position: absolute;
    top: 0; left: 0;
}
#title-main.visible {
    opacity: 1;
    position: relative;
}

#subtitle {
    font-family: 'Nunito Sans', sans-serif;
    font-weight: 600;
    font-size: clamp(1.2rem, 2.5vw, 2rem);
    color: #f2e8d0;
    margin-top: 20px;
    letter-spacing: 0.02em;
    transition: opacity 0.8s ease;
}
#subtitle.hidden { opacity: 0; }
#subtitle.visible { opacity: 1; }

/* --- Chamber II: Gallery --- */
#chamber-2 {
    background: #2a1f3d;
    min-height: 120vh;
}

.gallery-scatter {
    position: relative;
    width: 100%;
    height: 80vh;
}

.gallery-panel {
    position: absolute;
    border: 2px solid rgba(201,168,76,0.3);
    box-shadow: 0 4px 20px rgba(0,0,0,0.4), 0 2px 8px rgba(201,168,76,0.1);
    overflow: hidden;
    transition: transform 0.6s ease-in-out, box-shadow 0.6s ease-in-out;
}
.gallery-panel:hover {
    box-shadow: 0 8px 40px rgba(0,0,0,0.5), 0 4px 16px rgba(201,168,76,0.2);
}

.panel-inner {
    width: 100%;
    height: 100%;
    filter: grayscale(100%) contrast(1.1);
    transition: filter 0.6s ease-in-out;
}
.gallery-panel:hover .panel-inner {
    filter: grayscale(60%) contrast(1.05);
}

.panel-duotone {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 2;
    pointer-events: none;
}
.panel-duotone::before {
    content: '';
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: #7b3f6e;
    mix-blend-mode: multiply;
    opacity: 0.6;
}
.panel-duotone::after {
    content: '';
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: #c9a84c;
    mix-blend-mode: screen;
    opacity: 0.3;
}

.panel-label {
    position: absolute;
    bottom: 8px; left: 10px;
    font-family: 'Courier Prime', monospace;
    font-size: 0.75rem;
    color: #a89060;
    letter-spacing: 0.06em;
    z-index: 5;
}

.panel-large { width: 520px; height: 380px; }
.panel-medium { width: 320px; height: 240px; }
.panel-small { width: 180px; height: 180px; }

/* --- Chamber III: Throne Room --- */
#chamber-3 {
    background: #2a1f3d;
    display: flex;
    align-items: center;
}

.throne-content {
    width: 100%;
}

.throne-text-wrapper {
    max-width: 900px;
    margin: 0 auto;
}

.throne-text-flow p {
    max-width: 55ch;
    margin-bottom: 2em;
    font-size: clamp(1rem, 1.2vw, 1.15rem);
    line-height: 1.7;
    color: #d9ceb8;
}
.throne-text-flow p:nth-child(odd) {
    margin-left: auto;
    text-align: right;
}
.throne-text-flow p:nth-child(even) {
    margin-right: auto;
    text-align: left;
}

/* --- Chamber IV: Cabinet --- */
#chamber-4 {
    background: #0f0b18;
    min-height: 120vh;
}

.cabinet-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: auto auto;
    gap: 30px;
    max-width: 1200px;
    margin: 0 auto;
}

.cabinet-item {
    background: rgba(123, 63, 110, 0.15);
    border: 1px solid rgba(201, 168, 76, 0.2);
    padding: 30px;
    position: relative;
    box-shadow: 
        3px 3px 10px rgba(0,0,0,0.3),
        6px 6px 20px rgba(0,0,0,0.2),
        10px 10px 40px rgba(0,0,0,0.1);
    transition: transform 0.4s ease, box-shadow 0.4s ease;
}
.cabinet-item:hover {
    box-shadow: 
        3px 3px 10px rgba(201,168,76,0.15),
        6px 6px 20px rgba(0,0,0,0.3),
        10px 10px 40px rgba(0,0,0,0.15);
}

.cabinet-item h3 {
    font-family: 'Nunito Sans', sans-serif;
    font-weight: 600;
    font-size: 1.2rem;
    color: #c9a84c;
    margin-bottom: 12px;
}
.cabinet-item p {
    color: #d9ceb8;
    font-size: 0.95rem;
    line-height: 1.65;
}

.item-a { grid-column: 1 / 2; margin-top: 20px; margin-right: -10px; }
.item-b { grid-column: 2 / 3; margin-top: -10px; margin-left: -10px; }
.item-c { grid-column: 3 / 4; margin-top: 40px; margin-left: -15px; }
.item-d { grid-column: 1 / 2; margin-right: -20px; }
.item-e { grid-column: 2 / 4; margin-left: -10px; }
.item-f { grid-column: 1 / 3; margin-top: -15px; }

.ornamental-frame {
    position: absolute;
    top: -4px; left: -4px; right: -4px; bottom: -4px;
    border: 1px solid rgba(201, 168, 76, 0.15);
    pointer-events: none;
}

/* --- Chamber V: Exit --- */
#chamber-5 {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: #0f0b18;
}

.exit-content {
    text-align: center;
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.exit-text {
    font-family: 'Courier Prime', monospace;
    font-size: 1.1rem;
    color: #a89060;
    letter-spacing: 0.06em;
    min-height: 2em;
}

.exit-flourish {
    width: 300px;
    height: 300px;
    opacity: 0;
    transition: opacity 2s ease;
    margin-top: 40px;
}
.exit-flourish.visible { opacity: 1; }

/* --- Chamber enter animations --- */
.chamber-content > *:not(#title-container):not(#subtitle) {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.8s ease, transform 0.8s ease;
}
.chamber.in-view .chamber-content > * {
    opacity: 1;
    transform: translateY(0);
}

/* Stagger children */
.chamber.in-view .chamber-content > *:nth-child(1) { transition-delay: 0.1s; }
.chamber.in-view .chamber-content > *:nth-child(2) { transition-delay: 0.3s; }
.chamber.in-view .chamber-content > *:nth-child(3) { transition-delay: 0.5s; }

/* --- Responsive --- */
@media (max-width: 900px) {
    .chamber-content { padding: 60px 30px; }
    .foyer-content { padding-left: 10%; }
    #typewriter-thread { display: none; }
    .cabinet-grid { grid-template-columns: 1fr; }
    .item-a, .item-b, .item-c, .item-d, .item-e, .item-f {
        grid-column: auto;
        margin: 0;
    }
    .gallery-panel { position: relative !important; width: 80% !important; height: 200px !important; margin: 20px auto; transform: none !important; }
    .gallery-scatter { height: auto; }
}
