/* ===================================================
   loophole.dev — Deep-Sea Observatory Stylesheet
   =================================================== */

/* --- Color Palette Reference ---
   Abyssal Sapphire:   #1a1a4e
   Reef Emerald:       #00c9a7
   Mandarin Topaz:     #f4a261
   Dragonet Ruby:      #e63946
   Crown Amethyst:     #6a0572
   Lagoon Aquamarine:  #7ecdc0
   Trench Black:       #0a0a12
   Foam White:         #f0f5f3
--- */

:root {
    --abyssal-sapphire: #1a1a4e;
    --reef-emerald: #00c9a7;
    --mandarin-topaz: #f4a261;
    --dragonet-ruby: #e63946;
    --crown-amethyst: #6a0572;
    --lagoon-aquamarine: #7ecdc0;
    --trench-black: #0a0a12;
    --foam-white: #f0f5f3;
}

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

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

body {
    font-family: 'Space Mono', monospace;
    font-weight: 400;
    background: #0a0a12;
    color: #f0f5f3;
    overflow-x: hidden;
    line-height: 1.9;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* --- Porthole Frame --- */
#porthole-frame {
    position: relative;
    width: 100%;
    min-height: 500vh;
    background: linear-gradient(
        to bottom,
        #7ecdc0 0%,
        #1a1a4e 40%,
        #6a0572 65%,
        #0a0a12 85%,
        #f0f5f3 100%
    );
    background-size: 100% 500vh;
}

#porthole-content {
    clip-path: circle(48% at 50% 50%);
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    overflow: hidden;
    z-index: 1;
}

/* Porthole border glow */
#porthole-border {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 96vmin;
    height: 96vmin;
    border-radius: 50%;
    box-shadow: 0 0 0 2px rgba(0, 201, 167, 0.3), 0 0 40px rgba(0, 201, 167, 0.08);
    pointer-events: none;
    z-index: 10;
    transition: opacity 1s ease;
}

/* --- Zones --- */
.zone {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.8s ease;
}

.zone-inner {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

/* Zone backgrounds */
.zone-surface {
    background: linear-gradient(180deg, rgba(126, 205, 192, 0.3) 0%, rgba(26, 26, 78, 0.2) 100%);
}

.zone-twilight {
    background: linear-gradient(180deg, rgba(26, 26, 78, 0.8) 0%, rgba(106, 5, 114, 0.5) 100%);
    opacity: 0;
}

.zone-mesopelagic {
    background: linear-gradient(180deg, rgba(106, 5, 114, 0.4) 0%, rgba(10, 10, 18, 0.9) 100%);
    opacity: 0;
}

.zone-abyssal {
    background: rgba(10, 10, 18, 0.95);
    opacity: 0;
}

.zone-loophole {
    background: transparent;
    opacity: 0;
}

.zone.active {
    opacity: 1;
    z-index: 2;
}

.zone.inactive {
    opacity: 0;
    z-index: 0;
}

/* --- Typography --- */

/* Site Title */
.site-title {
    font-family: 'Space Mono', monospace;
    font-weight: 700;
    font-size: clamp(2rem, 5vw, 4.5rem);
    letter-spacing: 0.12em;
    color: #7ecdc0;
    text-align: center;
    cursor: default;
    transition: transform 400ms ease-out;
    display: inline-block;
}

.site-title:hover {
    transform: scale(1.08);
}

.letter {
    display: inline-block;
    opacity: 0;
    transform: translateY(20px);
    animation: letterReveal 600ms ease-out forwards;
    animation-delay: calc(var(--delay) * 120ms);
}

@keyframes letterReveal {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Aside/secondary text */
.aside-text {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 300;
    font-style: italic;
    font-size: clamp(0.8rem, 1.4vw, 1rem);
    letter-spacing: 0.06em;
    opacity: 0;
    margin-top: 2rem;
    color: rgba(126, 205, 192, 0.5);
}

.zone-twilight .aside-text {
    color: rgba(240, 245, 243, 0.5);
}

/* Code blocks */
.code-block {
    font-family: 'Space Mono', monospace;
    font-weight: 400;
    font-size: clamp(0.9rem, 1.8vw, 1.1rem);
    line-height: 1.9;
    color: rgba(240, 245, 243, 0.7);
    white-space: pre;
    text-align: left;
    max-width: 90%;
    transition: transform 400ms ease-out;
    cursor: default;
}

.code-block:hover {
    transform: scale(1.08);
}

.code-block-meso {
    color: rgba(0, 201, 167, 0.5);
    margin-top: 3rem;
}

/* Bioluminescent text */
.bioluminescent-text {
    font-family: 'Space Mono', monospace;
    font-weight: 700;
    font-size: clamp(1.4rem, 3.5vw, 2.8rem);
    letter-spacing: 0.12em;
    color: #00c9a7;
    text-align: center;
    text-shadow: 0 0 30px rgba(0, 201, 167, 0.4), 0 0 60px rgba(0, 201, 167, 0.2);
    animation: biolumPulse 4s ease-in-out infinite;
    margin-bottom: 1rem;
}

@keyframes biolumPulse {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

/* Exit text */
.exit-text {
    font-family: 'Space Mono', monospace;
    font-weight: 400;
    font-size: 1.2rem;
    color: #0a0a12;
    opacity: 0;
    transition: opacity 600ms ease-out;
    position: relative;
    z-index: 5;
}

.exit-text.visible {
    opacity: 1;
}

/* --- Reveal animation --- */
.reveal-text {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 800ms ease-out, transform 800ms ease-out;
}

.reveal-text.revealed {
    opacity: 1;
    transform: translateY(0);
}

.aside-text.revealed {
    opacity: 0.5;
    transform: translateY(0);
}

/* --- Bubbles --- */
.bubble {
    position: absolute;
    width: var(--size);
    height: var(--size);
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, rgba(240, 245, 243, 0.6), transparent 70%);
    opacity: var(--opacity);
    left: var(--x);
    bottom: -30px;
    animation: rise var(--duration) var(--delay) linear infinite;
    will-change: transform;
    pointer-events: none;
}

@keyframes rise {
    0% {
        transform: translateY(0) translateX(0);
        opacity: var(--opacity);
    }
    25% {
        transform: translateY(-25vh) translateX(8px);
    }
    50% {
        transform: translateY(-50vh) translateX(-5px);
        opacity: var(--opacity);
    }
    75% {
        transform: translateY(-75vh) translateX(6px);
    }
    100% {
        transform: translateY(-110vh) translateX(-3px);
        opacity: 0;
    }
}

/* --- Fish --- */
.fish {
    position: absolute;
    pointer-events: auto;
    cursor: default;
    transition: transform 400ms ease-out;
    will-change: transform;
}

.fish:hover {
    transform: scale(1.08);
}

/* Angelfish */
.fish-angelfish {
    width: 80px;
    height: 120px;
    top: 50%;
    right: -100px;
    animation: angelfishSwim 30s linear infinite, angelfishBob 6s ease-in-out infinite;
}

@keyframes angelfishSwim {
    0% { right: -120px; }
    100% { right: calc(100% + 120px); }
}

@keyframes angelfishBob {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-20px); }
}

/* Mandarin Dragonet */
.fish-dragonet {
    width: 200px;
    height: 125px;
    top: 50%;
    left: 50%;
    margin-left: -100px;
    margin-top: -62px;
    animation: dragonetRotate 20s linear infinite, dragonetPulse 6s ease-in-out infinite;
}

@keyframes dragonetRotate {
    0% { transform: perspective(800px) rotateY(0deg); }
    100% { transform: perspective(800px) rotateY(360deg); }
}

@keyframes dragonetPulse {
    0%, 100% { transform: perspective(800px) rotateY(0deg) scale(0.95); }
    50% { transform: perspective(800px) rotateY(180deg) scale(1.05); }
}

.fish-dragonet:hover {
    animation-play-state: paused;
    transform: perspective(800px) rotateY(0deg) scale(1.08);
}

/* Lanternfish */
.fish-lanternfish {
    width: 60px;
    height: 22px;
    position: absolute;
}

.lanternfish-group {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    pointer-events: none;
}

.lanternfish-1 {
    top: 25%;
    left: 15%;
    animation: lanternDrift1 18s ease-in-out infinite;
}

.lanternfish-2 {
    top: 55%;
    left: 65%;
    animation: lanternDrift2 22s ease-in-out infinite;
    animation-delay: -5s;
}

.lanternfish-3 {
    top: 70%;
    left: 30%;
    animation: lanternDrift3 15s ease-in-out infinite;
    animation-delay: -8s;
}

.lanternfish-4 {
    top: 40%;
    left: 80%;
    animation: lanternDrift1 20s ease-in-out infinite;
    animation-delay: -12s;
}

@keyframes lanternDrift1 {
    0%, 100% { transform: translate(0, 0); }
    25% { transform: translate(20px, -30px); }
    50% { transform: translate(-10px, -60px); }
    75% { transform: translate(15px, -30px); }
}

@keyframes lanternDrift2 {
    0%, 100% { transform: translate(0, 0); }
    25% { transform: translate(-25px, -40px); }
    50% { transform: translate(10px, -70px); }
    75% { transform: translate(-15px, -35px); }
}

@keyframes lanternDrift3 {
    0%, 100% { transform: translate(0, 0); }
    33% { transform: translate(30px, -50px); }
    66% { transform: translate(-20px, -40px); }
}

/* Photophore glow */
.photophore {
    filter: blur(2px);
}

.photophore-glow {
    filter: blur(8px);
    animation: photophoreGlow 3s ease-in-out infinite;
}

@keyframes photophoreGlow {
    0%, 100% { opacity: 0.3; r: 5; }
    50% { opacity: 0.8; r: 8; }
}

/* --- Organism Dots (Abyssal Zone) --- */
/* Uses Dragonet Ruby #e63946 and Mandarin Topaz #f4a261 */
.organism-dot {
    position: absolute;
    width: var(--dot-size);
    height: var(--dot-size);
    border-radius: 50%;
    background: var(--dot-color);
    left: var(--dot-x);
    top: var(--dot-y);
    box-shadow: 0 0 8px var(--dot-color), 0 0 16px var(--dot-color);
    animation: dotPulse 3s ease-in-out infinite;
    animation-delay: var(--dot-delay);
    pointer-events: none;
}

.organism-dot-ruby {
    background: #e63946;
    box-shadow: 0 0 8px #e63946, 0 0 16px #e63946;
}

.organism-dot-topaz {
    background: #f4a261;
    box-shadow: 0 0 8px #f4a261, 0 0 16px #f4a261;
}

@keyframes dotPulse {
    0%, 100% { opacity: 0.4; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.5); }
}

/* --- White Expansion (Zone 5) --- */
.white-expansion {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: #f0f5f3;
    transform: translate(-50%, -50%) scale(1);
    transition: transform 1.2s ease-out, opacity 0.8s ease;
    pointer-events: none;
}

.white-expansion.expanding {
    transform: translate(-50%, -50%) scale(400);
}

/* --- Porthole expansion in zone 5 --- */
#porthole-content.expanded {
    clip-path: circle(100% at 50% 50%);
    transition: clip-path 1.5s ease-out;
}

/* Hide porthole border when expanded */
#porthole-border.hidden {
    opacity: 0;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    #porthole-content {
        clip-path: circle(54% at 50% 50%);
    }

    #porthole-border {
        width: 108vmin;
        height: 108vmin;
    }

    .site-title {
        font-size: clamp(1.6rem, 6vw, 3rem);
    }

    .bioluminescent-text {
        font-size: clamp(1.1rem, 4vw, 2rem);
    }

    .code-block {
        font-size: clamp(0.7rem, 2.5vw, 0.9rem);
    }

    .fish-dragonet {
        width: 140px;
        height: 87px;
        margin-left: -70px;
        margin-top: -43px;
    }

    .fish-angelfish {
        width: 60px;
        height: 90px;
    }
}

@media (max-width: 480px) {
    #porthole-content {
        clip-path: circle(55% at 50% 50%);
    }

    .code-block {
        font-size: 0.7rem;
        max-width: 95%;
    }
}
