/* ========================================
   courts.studio — Coastal Corporate Energy
   ======================================== */

@property --angle {
    syntax: '<angle>';
    initial-value: 0deg;
    inherits: false;
}

:root {
    --deep-tide: #0b3d4a;
    --night-court: #091f28;
    --seafoam: #4ecdc4;
    --sand-warm: #f5deb3;
    --chalk: #f0f5f2;
    --sea-glass: #b8ccc2;
    --dusk-teal: #2a4f5c;
    --coral: #e8735a;
}

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

html {
    scroll-snap-type: y proximity;
    scroll-behavior: smooth;
}

body {
    background: var(--night-court);
    color: var(--chalk);
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-size: clamp(1rem, 1.15vw, 1.2rem);
    line-height: 1.65;
    letter-spacing: 0.01em;
    overflow-x: hidden;
}

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

/* ---- Scroll Progress ---- */
#scroll-progress {
    position: fixed;
    right: 1rem;
    top: 10vh;
    height: 80vh;
    width: 2px;
    border-left: 2px dashed var(--dusk-teal);
    z-index: 100;
}

#scroll-fill {
    position: absolute;
    top: 0;
    left: -2px;
    width: 2px;
    height: 100%;
    background: var(--seafoam);
    transform: scaleY(0);
    transform-origin: top;
    transition: transform 0.1s linear;
}

/* ---- Chapters ---- */
.chapter {
    position: relative;
    min-height: 100vh;
    scroll-snap-align: start;
    z-index: 1;
    overflow: hidden;
}

#chapter-serve { background: var(--night-court); }
#chapter-rally { background: var(--deep-tide); }
#chapter-volley { background: var(--night-court); }
#chapter-matchpoint {
    background: linear-gradient(135deg, var(--deep-tide) 0%, var(--dusk-teal) 40%, var(--sand-warm) 100%);
}
#chapter-handshake { background: var(--night-court); }

/* ---- Court Net Divider ---- */
.court-net {
    position: absolute;
    bottom: 0;
    left: 10%;
    width: 80%;
    height: 1px;
    border-top: 1px dashed rgba(240, 245, 242, 0.12);
}

/* ---- Chapter Grid ---- */
.chapter-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    column-gap: clamp(1rem, 2.5vw, 3rem);
    min-height: 100vh;
    padding: clamp(2rem, 5vw, 6rem);
    align-content: center;
    position: relative;
}

/* ---- Chapter Labels ---- */
.chapter-label {
    font-family: 'Space Mono', monospace;
    font-size: clamp(0.7rem, 0.85vw, 0.85rem);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--seafoam);
    grid-column: 1 / -1;
    margin-bottom: 2rem;
}

/* ---- Z-Block Border Animate ---- */
.z-block {
    position: relative;
    opacity: 0;
    transition: opacity 0.6s ease 1.2s;
}

.z-block::before {
    content: '';
    position: absolute;
    inset: -4px;
    border: 1px solid transparent;
    pointer-events: none;
    opacity: 0;
}

.z-block.visible {
    opacity: 1;
}

.z-block.visible::before {
    border-image: conic-gradient(from var(--angle), var(--seafoam) 0%, transparent 30%) 1;
    animation: trace-border 1.2s ease-out forwards;
}

@keyframes trace-border {
    0% { --angle: 0deg; opacity: 1; }
    80% { opacity: 1; }
    100% { --angle: 360deg; opacity: 0; }
}

/* ---- Hero (Chapter 1) ---- */
.hero-title {
    font-family: 'Archivo Black', sans-serif;
    font-size: clamp(2.8rem, 7vw, 6.5rem);
    line-height: 0.95;
    letter-spacing: -0.03em;
    color: var(--chalk);
    grid-column: 1 / 6;
    align-self: center;
}

.z-corner-tr {
    grid-column: 8 / 12;
    display: flex;
    align-items: center;
    justify-content: center;
}

.flare-accent {
    width: clamp(80px, 12vw, 180px);
    height: clamp(80px, 12vw, 180px);
    border-radius: 50%;
    background: radial-gradient(circle, rgba(78,205,196,0.35) 0%, rgba(245,222,179,0.15) 50%, transparent 70%);
    filter: blur(20px);
    animation: flare-pulse 4s ease-in-out infinite alternate;
}

@keyframes flare-pulse {
    0% { transform: scale(1); opacity: 0.7; }
    100% { transform: scale(1.3); opacity: 1; }
}

.manifesto {
    grid-column: 8 / 13;
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-weight: 600;
    font-size: clamp(1rem, 1.5vw, 1.4rem);
    color: var(--sea-glass);
    align-self: end;
    text-align: right;
}

/* ---- Z Diagonal Lines ---- */
.z-diagonal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

.z-line {
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
    transition: stroke-dashoffset 1.5s ease;
}

.chapter.in-view .z-line {
    stroke-dashoffset: 0;
}

/* ---- Rally (Chapter 2) ---- */
.z-left {
    grid-column: 1 / 6;
}

.z-right {
    grid-column: 8 / 13;
    display: flex;
    align-items: center;
    justify-content: center;
}

.section-title {
    font-family: 'Archivo Black', sans-serif;
    font-size: clamp(1.8rem, 4vw, 3.5rem);
    line-height: 0.95;
    letter-spacing: -0.03em;
    color: var(--chalk);
    margin-bottom: 1.5rem;
}

.body-text {
    color: var(--sea-glass);
    font-weight: 400;
    max-width: 480px;
}

.court-diagram {
    width: 100%;
    max-width: 200px;
    height: auto;
}

.court-line {
    stroke-dasharray: 800;
    stroke-dashoffset: 800;
    transition: stroke-dashoffset 2s ease;
}

.chapter.in-view .court-line {
    stroke-dashoffset: 0;
}

/* ---- Volley (Chapter 3) ---- */
.volley-grid {
    align-content: center;
    row-gap: clamp(2rem, 4vw, 4rem);
}

.volley-pair {
    padding: clamp(1.5rem, 2vw, 2.5rem);
}

.volley-left {
    grid-column: 1 / 6;
    text-align: left;
}

.volley-right {
    grid-column: 8 / 13;
    text-align: right;
}

.volley-title {
    font-family: 'Archivo Black', sans-serif;
    font-size: clamp(1.4rem, 3vw, 2.5rem);
    line-height: 0.95;
    letter-spacing: -0.03em;
    color: var(--chalk);
    margin-bottom: 0.75rem;
}

/* ---- Match Point (Chapter 4) ---- */
.matchpoint-grid {
    align-content: center;
    justify-items: center;
    text-align: center;
}

.matchpoint-statement {
    font-family: 'Archivo Black', sans-serif;
    font-size: clamp(2.4rem, 6vw, 5.5rem);
    line-height: 0.95;
    letter-spacing: -0.03em;
    color: var(--chalk);
    grid-column: 2 / 12;
}

#chapter-matchpoint .body-text {
    color: var(--dusk-teal);
}

/* ---- Handshake (Chapter 5) ---- */
.handshake-grid {
    align-content: center;
    justify-items: center;
    text-align: center;
}

.handshake-contact {
    grid-column: 3 / 11;
}

.contact-line {
    font-family: 'Archivo Black', sans-serif;
    font-size: clamp(1.8rem, 4vw, 3.5rem);
    letter-spacing: -0.02em;
    color: var(--seafoam);
    margin-bottom: 1rem;
}

.contact-sub {
    font-family: 'Space Mono', monospace;
    font-size: clamp(0.7rem, 0.85vw, 0.85rem);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--sea-glass);
}

/* ---- Bubbles ---- */
.bubbles-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
    z-index: 0;
}

.bubble {
    position: absolute;
    border-radius: 50%;
    border: 1.5px solid rgba(78, 205, 196, 0.3);
    background: radial-gradient(circle at 30% 30%, rgba(245,222,179,0.12), transparent);
    animation: bubble-rise var(--duration) ease-in-out var(--delay) infinite;
    bottom: -10%;
}

@keyframes bubble-rise {
    0% { transform: translateY(0) translateX(0) scale(0.3); opacity: 0; }
    10% { opacity: 0.7; }
    90% { opacity: 0.2; }
    100% { transform: translateY(-120vh) translateX(var(--sway)) scale(1); opacity: 0; }
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .chapter-grid {
        grid-template-columns: 1fr;
        padding: 2rem 1.5rem;
    }

    .hero-title,
    .z-left,
    .z-right,
    .volley-left,
    .volley-right,
    .z-corner-tr,
    .manifesto,
    .matchpoint-statement,
    .handshake-contact {
        grid-column: 1 / -1;
    }

    .z-left { text-align: left; }
    .z-right { text-align: right; }
    .volley-left { text-align: left; }
    .volley-right { text-align: right; }
    .manifesto { text-align: right; }

    .z-corner-tr {
        justify-content: flex-end;
        margin-bottom: 2rem;
    }

    .flare-accent {
        width: 80px;
        height: 80px;
    }

    .z-block.visible::before {
        animation-duration: 0.8s;
    }
    .z-block {
        transition-delay: 0.8s;
    }

    #scroll-progress {
        right: 0.5rem;
    }
}
