/* ============================================
   musical.quest — Anti-Design / Zen Stillness
   Split-screen chaos vs void
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Josefin+Sans:wght@300;700&family=Libre+Baskerville:ital,wght@0,400;0,700;1,400&family=IBM+Plex+Mono:wght@300;400&display=swap');

/* --- CSS Custom Properties for Counter Animation --- */
@property --counter-val {
    syntax: '<integer>';
    inherits: false;
    initial-value: 0;
}

/* --- Root Variables --- */
:root {
    --color-deep-void: #0B1929;
    --color-ethereal: #E8F0F8;
    --color-accent: #3A5F7A;
    --color-highlight: #7BB8D4;
    --color-whisper: #2A3F52;
    --color-breath: #D0E3EF;
    --color-signal: #4FC3F7;
    --color-mono-accent: #5B8FA8;

    --font-display: 'Josefin Sans', sans-serif;
    --font-body: 'Libre Baskerville', serif;
    --font-mono: 'IBM Plex Mono', monospace;

    --split-left: 58%;
    --split-right: 42%;
}

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

html {
    scroll-behavior: smooth;
}

html, body {
    width: 100%;
    overflow-x: hidden;
    background: var(--color-deep-void);
}

body {
    font-family: var(--font-body);
    color: var(--color-ethereal);
    line-height: 1.6;
}

/* --- Particle Canvas (full viewport, behind everything) --- */
#particleCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
}

/* --- Dividing Line --- */
.dividing-line {
    position: fixed;
    left: var(--split-left);
    top: 0;
    width: 1px;
    height: 100vh;
    background: var(--color-accent);
    z-index: 100;
    opacity: 0;
    animation: divideFadeIn 3s ease-out forwards, pulseBreath 4s cubic-bezier(0.4, 0, 0.2, 1) infinite 3s;
}

@keyframes divideFadeIn {
    from { opacity: 0; }
    to { opacity: 0.5; }
}

@keyframes pulseBreath {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 0.7; }
}

/* --- Split Screen Container --- */
.split-screen {
    position: relative;
    z-index: 10;
}

/* --- Movement (each section = 100vh per panel) --- */
.movement {
    display: flex;
    width: 100%;
    min-height: 100vh;
    position: relative;
}

/* --- Panels --- */
.panel {
    position: relative;
    min-height: 100vh;
    overflow: hidden;
}

.chaos-panel {
    width: var(--split-left);
    background: var(--color-deep-void);
    color: var(--color-ethereal);
    padding: 4rem;
}

.void-panel {
    width: var(--split-right);
    background: var(--color-ethereal);
    color: var(--color-deep-void);
    padding: 4rem;
}

.chaos-content {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.void-content {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.void-centered {
    display: flex;
    justify-content: center;
    align-items: center;
}

/* ============================================
   MOVEMENT 1: OVERTURE
   ============================================ */

.overture-title {
    justify-content: center;
    align-items: flex-start;
}

.title-broken {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(3rem, 10vw, 8rem);
    text-transform: uppercase;
    line-height: 0.9;
    color: var(--color-ethereal);
}

.title-line {
    display: block;
    transform: translateX(var(--offset, 0)) rotate(var(--rotation, 0));
    letter-spacing: var(--spacing, 0);
    opacity: 0;
    animation: titleReveal 0.8s ease-out forwards;
}

.title-line:nth-child(1) { animation-delay: 0.3s; }
.title-line:nth-child(2) { animation-delay: 0.6s; }
.title-line:nth-child(3) { animation-delay: 0.9s; }
.title-line:nth-child(4) { animation-delay: 1.2s; }

.title-line-quest {
    color: var(--color-highlight);
}

@keyframes titleReveal {
    from {
        opacity: 0;
        transform: translateX(calc(var(--offset, 0) - 40px)) rotate(var(--rotation, 0));
    }
    to {
        opacity: 1;
        transform: translateX(var(--offset, 0)) rotate(var(--rotation, 0));
    }
}

.void-period {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 300;
    color: var(--color-deep-void);
    user-select: none;
}

/* ============================================
   MOVEMENT 2: FIRST MOVEMENT
   ============================================ */

.chaos-text-layers {
    position: relative;
    justify-content: center;
    gap: 0;
}

.text-block {
    position: relative;
    transform: translateX(var(--block-offset-x, 0)) translateY(var(--block-offset-y, 0)) rotate(var(--block-rotation, 0));
    max-width: 420px;
    opacity: 0;
    transition: opacity 0.8s ease-out, transform 0.8s ease-out;
}

.text-block.revealed {
    opacity: 1;
}

.text-large {
    font-family: var(--font-body);
    font-size: 22px;
    font-weight: 400;
    line-height: 1.1;
    color: var(--color-ethereal);
    margin-bottom: 4px;
}

.text-medium {
    font-family: var(--font-body);
    font-size: 16px;
    font-weight: 400;
    line-height: 1.1;
    color: var(--color-ethereal);
}

.text-small {
    font-family: var(--font-body);
    font-size: 12px;
    font-weight: 400;
    line-height: 1.6;
    color: var(--color-breath);
}

.text-trailing {
    font-family: var(--font-body);
    font-size: 14px;
    font-style: italic;
    line-height: 1.3;
    color: var(--color-whisper);
}

.text-fragment {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 300;
    letter-spacing: 0.06em;
    color: var(--color-mono-accent);
}

/* Void photo (Movement 2) */
.void-photo {
    width: 140px;
    height: 140px;
    border: 1px solid var(--color-accent);
    overflow: hidden;
    opacity: 0;
    transition: opacity 1s ease-out;
}

.void-photo.revealed {
    opacity: 1;
}

.photo-inner {
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, var(--color-deep-void) 0%, var(--color-highlight) 100%);
    filter: grayscale(100%) brightness(0.7);
    /* Simulated piano felt texture via CSS pattern */
    background-image:
        repeating-linear-gradient(0deg, transparent, transparent 3px, rgba(123, 184, 212, 0.1) 3px, rgba(123, 184, 212, 0.1) 4px),
        repeating-linear-gradient(90deg, transparent, transparent 5px, rgba(11, 25, 41, 0.2) 5px, rgba(11, 25, 41, 0.2) 6px);
    background-color: var(--color-whisper);
}

/* ============================================
   MOVEMENT 3: SCHERZO (maximum chaos)
   ============================================ */

.scherzo-chaos {
    justify-content: flex-start;
    padding-top: 2rem;
    gap: 0;
    overflow: visible;
}

.scherzo-text-block {
    transform: translateX(var(--s-offset, 0)) rotate(var(--s-rotation, 0));
    margin-bottom: 4px;
    opacity: 0;
    transition: opacity 0.5s ease-out;
}

.scherzo-text-block.revealed {
    opacity: 1;
}

.scherzo-fragment {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(2.5rem, 7vw, 5rem);
    text-transform: uppercase;
    letter-spacing: -0.04em;
    line-height: 0.85;
    color: var(--color-ethereal);
}

.scherzo-fragment-small {
    font-family: var(--font-body);
    font-size: 12px;
    line-height: 0.85;
    color: var(--color-whisper);
    font-weight: 400;
}

.scherzo-fragment-overlap {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(2rem, 6vw, 4.5rem);
    text-transform: uppercase;
    letter-spacing: 0.15em;
    line-height: 0.85;
    color: var(--color-highlight);
    opacity: 0.7;
    margin-top: -20px;
}

.scherzo-compressed {
    font-family: var(--font-body);
    font-size: 14px;
    line-height: 0.85;
    letter-spacing: -0.02em;
    color: var(--color-breath);
    font-weight: 400;
}

.counter-container {
    margin: 20px 0;
}

.counter {
    font-family: var(--font-mono);
    font-size: 48px;
    color: var(--color-highlight);
    font-weight: 400;
    letter-spacing: 0.1em;
    line-height: 1;
}

.counter-large {
    font-size: clamp(2.5rem, 8vw, 4rem);
}

/* Scherzo photos */
.scherzo-photos {
    position: relative;
    height: 180px;
    margin: 20px 0;
}

.scherzo-photo {
    position: absolute;
    width: 140px;
    height: 140px;
    overflow: hidden;
    border: none;
}

.scherzo-photo-1 {
    top: 0;
    left: 10%;
    transform: rotate(15deg);
    background: linear-gradient(180deg, var(--color-deep-void) 20%, var(--color-accent) 80%);
    background-image:
        repeating-linear-gradient(45deg, transparent, transparent 2px, rgba(123, 184, 212, 0.15) 2px, rgba(123, 184, 212, 0.15) 3px);
    background-color: var(--color-whisper);
    opacity: 0.8;
}

.scherzo-photo-2 {
    top: 20px;
    left: 25%;
    transform: rotate(-10deg);
    background: linear-gradient(220deg, var(--color-accent) 10%, var(--color-deep-void) 90%);
    background-image:
        repeating-linear-gradient(135deg, transparent, transparent 4px, rgba(79, 195, 247, 0.08) 4px, rgba(79, 195, 247, 0.08) 5px);
    background-color: var(--color-deep-void);
    opacity: 0.65;
}

/* Void panel scherzo elements */
.void-rule {
    position: absolute;
    top: var(--rule-top, 50%);
    left: 15%;
    width: 70%;
    height: 1px;
    background: var(--color-accent);
}

.kanji-watermark {
    position: absolute;
    top: var(--kanji-top, 50%);
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 120px;
    opacity: 0.06;
    color: var(--color-deep-void);
    user-select: none;
    line-height: 1;
}

.kanji-watermark-large {
    font-size: 160px;
}

/* ============================================
   MOVEMENT 4: ADAGIO (quietest section)
   ============================================ */

.chaos-panel-quiet {
    display: flex;
    align-items: center;
    justify-content: center;
}

.adagio-content {
    justify-content: center;
    align-items: center;
    text-align: center;
}

.adagio-line {
    font-family: var(--font-display);
    font-weight: 300;
    font-size: 18px;
    color: var(--color-breath);
    letter-spacing: 0.04em;
    opacity: 0;
    transition: opacity 2s ease-out;
}

.adagio-line.revealed {
    opacity: 1;
}

/* Adagio: dividing line slows down (handled via JS class) */
.dividing-line.adagio-slow {
    animation: divideFadeIn 3s ease-out forwards, pulseBreathSlow 8s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

@keyframes pulseBreathSlow {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 0.7; }
}

/* ============================================
   MOVEMENT 5: CADENZA (climax)
   ============================================ */

.cadenza-content {
    justify-content: center;
    align-items: flex-start;
    gap: 20px;
}

.cadenza-counter-wrap {
    margin-bottom: 10px;
}

.cadenza-text {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(1.5rem, 4vw, 2.5rem);
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--color-signal);
    opacity: 0;
    transition: opacity 1s ease-out;
}

.cadenza-text.revealed {
    opacity: 1;
}

.void-stillness {
    font-family: var(--font-display);
    font-weight: 300;
    font-size: clamp(1.5rem, 4vw, 2.5rem);
    color: var(--color-deep-void);
    text-align: center;
    letter-spacing: 0.1em;
}

/* Cadenza spanning photo */
.cadenza-photo-spanning {
    position: absolute;
    top: 50%;
    left: 15%;
    width: 70%;
    height: 300px;
    transform: translateY(-50%);
    z-index: 50;
    opacity: 0;
    transition: opacity 1.5s ease-out;
    pointer-events: none;
}

.cadenza-photo-spanning.revealed {
    opacity: 0.85;
}

.cadenza-photo-inner {
    width: 100%;
    height: 100%;
    /* Simulated piano interior macro in blue duotone */
    background:
        repeating-linear-gradient(
            87deg,
            transparent,
            transparent 8px,
            rgba(123, 184, 212, 0.12) 8px,
            rgba(123, 184, 212, 0.12) 9px
        ),
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 20px,
            rgba(58, 95, 122, 0.08) 20px,
            rgba(58, 95, 122, 0.08) 21px
        );
    background-color: var(--color-deep-void);
    border: 1px solid var(--color-accent);
    filter: brightness(0.8);
}

/* ============================================
   MOVEMENT 6: CODA (inverted split)
   ============================================ */

/* Swap colors: left becomes void (light), right becomes chaos (dark) */
.coda-void-swap {
    background: var(--color-ethereal) !important;
    color: var(--color-deep-void) !important;
}

.coda-chaos-swap {
    background: var(--color-deep-void) !important;
    color: var(--color-ethereal) !important;
}

.coda-left-content {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
}

.coda-period {
    color: var(--color-deep-void);
}

.coda-right-content {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
    gap: 40px;
}

.coda-vertical-name {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(1.5rem, 3vw, 2.5rem);
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--color-ethereal);
    line-height: 1.1;
}

.coda-vertical-name span {
    display: block;
}

.coda-counter {
    color: var(--color-signal);
    font-size: clamp(1.5rem, 4vw, 2rem);
}

.coda-annotation {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 300;
    letter-spacing: 0.06em;
    color: var(--color-mono-accent);
    text-align: center;
}

/* ============================================
   ELAPSED TIME COUNTER (floating)
   ============================================ */

.elapsed-counter {
    position: fixed;
    bottom: 30px;
    left: 30px;
    z-index: 90;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.elapsed-label {
    font-family: var(--font-mono);
    font-size: 9px;
    font-weight: 300;
    letter-spacing: 0.08em;
    color: var(--color-whisper);
    text-transform: uppercase;
}

.elapsed-value {
    font-family: var(--font-mono);
    font-size: 14px;
    font-weight: 300;
    letter-spacing: 0.06em;
    color: var(--color-highlight);
}

/* ============================================
   HORIZONTAL RULES (decorative, misaligned)
   ============================================ */

.chaos-panel::after {
    content: '';
    position: absolute;
    bottom: 15%;
    left: 0;
    width: 60%;
    height: 1px;
    background: var(--color-accent);
    opacity: 0.4;
}

.movement-1 .chaos-panel::after { bottom: 12%; width: 45%; }
.movement-2 .chaos-panel::after { bottom: 8%; width: 70%; left: 15%; }
.movement-3 .chaos-panel::after { bottom: 20%; width: 55%; }
.movement-5 .chaos-panel::after { bottom: 10%; width: 40%; left: 30%; }
.movement-6 .chaos-panel::after { display: none; }

/* ============================================
   SCROLL REVEAL (via IntersectionObserver)
   ============================================ */

.movement {
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

.movement.in-view {
    opacity: 1;
    transform: translateY(0);
}

/* Movement 1 is always visible on load */
.movement-1 {
    opacity: 1;
    transform: translateY(0);
}

/* ============================================
   RESPONSIVE: Tablet
   ============================================ */

@media (max-width: 1024px) {
    :root {
        --split-left: 62%;
        --split-right: 38%;
    }

    .dividing-line {
        left: 62%;
    }
}

/* ============================================
   RESPONSIVE: Mobile (stacked)
   ============================================ */

@media (max-width: 768px) {
    .movement {
        flex-direction: column;
    }

    .chaos-panel,
    .void-panel {
        width: 100%;
        min-height: 50vh;
        padding: 2rem;
    }

    .dividing-line {
        display: none;
    }

    .cadenza-photo-spanning {
        left: 5%;
        width: 90%;
    }

    .elapsed-counter {
        bottom: 15px;
        left: 15px;
    }

    .scherzo-photos {
        height: 140px;
    }

    .scherzo-photo {
        width: 100px;
        height: 100px;
    }
}

/* ============================================
   REDUCED MOTION
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    .dividing-line {
        animation: none;
        opacity: 0.5;
    }

    .title-line {
        animation: none;
        opacity: 1;
        transform: translateX(var(--offset, 0));
    }

    .movement {
        opacity: 1;
        transform: none;
        transition: none;
    }

    .text-block,
    .scherzo-text-block,
    .adagio-line,
    .cadenza-text,
    .void-photo,
    .cadenza-photo-spanning {
        opacity: 1;
        transition: none;
    }

    #particleCanvas {
        display: none;
    }

    .counter,
    .elapsed-value {
        animation: none;
    }
}
