/* ============================================
   courthouse.app — Goblincore Jurisprudence
   ============================================ */

/* --- CSS Custom Properties --- */
@property --num {
    syntax: '<integer>';
    initial-value: 0;
    inherits: false;
}

:root {
    --coastal-slate: #2C3E50;
    --moss-verdict: #6B8F71;
    --oxidized-brass: #8B6914;
    --courtroom-parchment: #E8E4DC;
    --tidal-ink: #1E2D2F;
    --sea-glass: #5B7B7A;
    --bracket-fungus: #C4763C;
    --vellum-white: #F4F1EB;
    --charcoal-teal: #3D4F5F;
    --grid-opacity: 0.12;
}

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

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

body {
    font-family: 'Nunito Sans', sans-serif;
    font-weight: 400;
    font-size: clamp(0.95rem, 1.8vw, 1.15rem);
    color: #3D4F5F;
    background-color: var(--courtroom-parchment);
    line-height: 1.72;
    overflow-x: hidden;
    /* Grid-line background pattern */
    background-image:
        repeating-linear-gradient(
            91.2deg,
            transparent,
            transparent 59px,
            rgba(91, 123, 122, var(--grid-opacity)) 59px,
            rgba(91, 123, 122, var(--grid-opacity)) 60px
        ),
        repeating-linear-gradient(
            1.2deg,
            transparent,
            transparent 79px,
            rgba(91, 123, 122, var(--grid-opacity)) 79px,
            rgba(91, 123, 122, var(--grid-opacity)) 80px
        );
}

.svg-filters {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

/* --- Typography --- */
h1 {
    font-family: 'Caveat', cursive;
    font-weight: 700;
    font-size: clamp(2.4rem, 6vw, 5.5rem);
    color: var(--coastal-slate);
    letter-spacing: 0.01em;
    line-height: 1.15;
}

h2 {
    font-family: 'Caveat', cursive;
    font-weight: 600;
    font-size: clamp(1.6rem, 3.5vw, 3rem);
    color: var(--coastal-slate);
    letter-spacing: 0.01em;
    line-height: 1.15;
}

h3, h4 {
    font-family: 'Architects Daughter', cursive;
    font-weight: 400;
    font-size: clamp(1.2rem, 2.5vw, 2rem);
    color: var(--moss-verdict);
    margin-bottom: 0.5em;
}

.mono-accent {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    font-size: 0.85em;
    color: var(--oxidized-brass);
    background: rgba(139, 105, 20, 0.07);
    padding: 0.15em 0.4em;
    border-radius: 2px;
}

p {
    max-width: 38em;
}

/* --- Fracture Line --- */
.fracture-line {
    position: fixed;
    top: 0;
    left: 58%;
    width: 20px;
    height: 100vh;
    z-index: 5;
    pointer-events: none;
    opacity: 0.15;
    animation: fracturePulse 8s ease-in-out infinite;
}

.fracture-line svg {
    width: 100%;
    height: 100%;
}

#fracturePath {
    stroke-dasharray: 2200;
    stroke-dashoffset: 2200;
    animation: drawFracture 2.5s ease-out 0.4s forwards;
}

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

@keyframes fracturePulse {
    0%, 100% { opacity: 0.15; }
    50% { opacity: 0.35; }
}

/* --- Chamber Indicator --- */
.chamber-indicator {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, rgba(244,241,235,0.72) 0%, rgba(232,228,220,0.45) 100%);
    backdrop-filter: blur(16px) saturate(1.2);
    -webkit-backdrop-filter: blur(16px) saturate(1.2);
    border: 1px solid rgba(107,143,113,0.25);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(30,45,47,0.12);
}

.chamber-numeral {
    font-family: 'Architects Daughter', cursive;
    font-size: 1.4rem;
    color: var(--coastal-slate);
}

/* --- Chambers (Sections) --- */
.chamber {
    position: relative;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6vh 5vw;
    overflow: hidden;
}

.chamber-content {
    position: relative;
    z-index: 10;
    width: 100%;
    max-width: 1100px;
}

.chamber-title {
    margin-bottom: 0.3em;
}

.chamber-subtitle {
    font-family: 'Architects Daughter', cursive;
    font-size: clamp(1rem, 2vw, 1.3rem);
    color: var(--sea-glass);
    margin-bottom: 3rem;
    opacity: 0.85;
}

/* --- Tilt Classes --- */
.tilt-pos { transform: rotate(1.2deg); }
.tilt-neg { transform: rotate(-1deg); }
.tilt-pos-sm { transform: rotate(0.7deg); }
.tilt-neg-sm { transform: rotate(-0.5deg); }

/* --- Chamber I: The Antechamber --- */
.chamber-antechamber {
    min-height: 100vh;
    flex-direction: column;
}

.chamber-antechamber .chamber-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.antechamber-heading {
    position: relative;
}

.heading-reveal {
    opacity: 0;
}

.heading-reveal.revealed {
    opacity: 1;
}

.heading-reveal .char {
    display: inline-block;
    opacity: 0;
    animation: charReveal 0.3s ease forwards;
}

@keyframes charReveal {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.subtitle {
    font-family: 'Architects Daughter', cursive;
    font-size: clamp(1.2rem, 2.5vw, 1.8rem);
    color: var(--moss-verdict);
    opacity: 0;
    transition: opacity 0.8s ease;
    margin-top: 1rem;
}

.subtitle.visible {
    opacity: 1;
}

/* --- Gavel Motifs --- */
.gavel-motif {
    display: flex;
    justify-content: center;
    margin: 3rem auto;
    opacity: 0.7;
}

.gavel-svg {
    width: 120px;
    height: auto;
}

.gavel-sprouting .gavel-svg {
    width: 120px;
    height: auto;
}

/* --- Glassmorphic Cards --- */
.glass-card {
    position: relative;
    background: linear-gradient(135deg, rgba(244,241,235,0.72) 0%, rgba(232,228,220,0.45) 100%);
    backdrop-filter: blur(16px) saturate(1.2);
    -webkit-backdrop-filter: blur(16px) saturate(1.2);
    border: 1px solid rgba(107,143,113,0.25);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(30,45,47,0.12);
    padding: 2rem 2.2rem;
    margin-bottom: 1.5rem;
    opacity: 0;
    transition: transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1),
                opacity 0.6s ease,
                backdrop-filter 0.3s ease 0.48s,
                -webkit-backdrop-filter 0.3s ease 0.48s;
}

@supports not (backdrop-filter: blur(16px)) {
    .glass-card {
        background: rgba(244, 241, 235, 0.92);
    }
}

.glass-card.card-left {
    transform: translateX(-40px) rotate(-2deg);
}

.glass-card.card-right {
    transform: translateX(40px) rotate(2deg);
}

.glass-card.card-visible {
    opacity: 1;
    transform: translateX(0) rotate(var(--rest-rotate, 0deg));
}

.glass-card.card-left.card-visible {
    transform: translateX(0) rotate(0deg);
}

.glass-card.card-right.card-visible {
    transform: translateX(0) rotate(0deg);
}

/* Tilt overrides for visible cards */
.glass-card.tilt-pos.card-visible {
    transform: translateX(0) rotate(1.2deg);
}
.glass-card.tilt-neg.card-visible {
    transform: translateX(0) rotate(-1deg);
}
.glass-card.tilt-pos-sm.card-visible {
    transform: translateX(0) rotate(0.7deg);
}

.glass-card p {
    color: var(--coastal-slate);
    font-weight: 300;
    line-height: 1.72;
}

.case-number {
    display: block;
    font-family: 'Architects Daughter', cursive;
    font-size: 0.9rem;
    color: var(--sea-glass);
    margin-bottom: 0.6em;
}

/* --- Dark Glass Cards (Verdict Hall) --- */
.glass-card-dark {
    background: rgba(30, 45, 47, 0.6);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(91, 123, 122, 0.3);
}

.glass-card-dark h3 {
    color: var(--courtroom-parchment);
}

.glass-card-dark p {
    color: var(--courtroom-parchment);
    opacity: 0.9;
}

/* --- Evidence Cards Layout --- */
.evidence-cards {
    display: grid;
    gap: 1.5rem;
    margin: 2rem 0;
}

.docket-cards {
    grid-template-columns: 1fr;
    max-width: 700px;
}

.docket-cards .card-left {
    justify-self: start;
    max-width: 600px;
}

.docket-cards .card-right {
    justify-self: end;
    max-width: 600px;
}

.deliberation-cards {
    grid-template-columns: 1fr;
    max-width: 700px;
}

.verdict-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    margin-top: 3rem;
    max-width: 900px;
    margin-left: auto;
    margin-right: auto;
}

/* --- Evidence Scatter (Chamber III) --- */
.evidence-scatter {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    margin: 2rem 0;
    position: relative;
}

.scatter-card {
    transform: translateX(var(--card-x, 0)) rotate(var(--card-rotate, 0deg));
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
                z-index 0s,
                box-shadow 0.3s ease;
}

.scatter-card:hover {
    transform: scale(1.04) rotate(0deg) !important;
    z-index: 50;
    box-shadow: 0 12px 48px rgba(30,45,47,0.2);
}

.scatter-card.card-visible {
    opacity: 1;
}

/* --- Barnacle Clusters --- */
.barnacle-cluster {
    position: absolute;
    width: 40px;
    height: 20px;
}

.barnacle-cluster::before,
.barnacle-cluster::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    background: rgba(91, 123, 122, 0.2);
    border: 1px solid rgba(91, 123, 122, 0.15);
}

.barnacle-cluster::before {
    width: 6px;
    height: 6px;
    top: 2px;
    left: 4px;
}

.barnacle-cluster::after {
    width: 4px;
    height: 4px;
    top: 8px;
    left: 12px;
}

.barnacle-top-right {
    top: 8px;
    right: 8px;
}

.barnacle-bottom-left {
    bottom: 8px;
    left: 8px;
}

.barnacle-top-left {
    top: 8px;
    left: 8px;
}

/* --- Counter Blocks --- */
.counter-block {
    display: flex;
    gap: 2rem;
    margin-top: 3rem;
    flex-wrap: wrap;
}

.counter-card {
    background: linear-gradient(135deg, rgba(244,241,235,0.72) 0%, rgba(232,228,220,0.45) 100%);
    backdrop-filter: blur(16px) saturate(1.2);
    -webkit-backdrop-filter: blur(16px) saturate(1.2);
    border: 1px solid rgba(107,143,113,0.25);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(30,45,47,0.12);
    padding: 1.5rem 2rem;
    text-align: center;
    min-width: 180px;
}

.counter-value {
    display: block;
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    font-size: clamp(2rem, 4vw, 3.5rem);
    color: var(--oxidized-brass);
    line-height: 1.2;
}

.counter-label {
    display: block;
    font-family: 'Architects Daughter', cursive;
    font-size: 0.9rem;
    color: var(--sea-glass);
    margin-top: 0.5rem;
}

/* --- Verdict Hall (Dark Section) --- */
.chamber-verdict {
    background-color: var(--tidal-ink);
    background-image:
        repeating-linear-gradient(
            91.2deg,
            transparent,
            transparent 59px,
            rgba(91, 123, 122, 0.15) 59px,
            rgba(91, 123, 122, 0.15) 60px
        ),
        repeating-linear-gradient(
            1.2deg,
            transparent,
            transparent 79px,
            rgba(91, 123, 122, 0.15) 79px,
            rgba(91, 123, 122, 0.15) 80px
        );
}

.lichen-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    filter: url(#lichen-noise);
    opacity: 0.07;
    pointer-events: none;
    z-index: 1;
}

.verdict-title {
    color: var(--courtroom-parchment);
}

.verdict-subtitle {
    color: var(--sea-glass);
}

.verdict-center {
    display: flex;
    justify-content: center;
    margin: 3rem 0;
}

.verdict-counter-card {
    background: rgba(30, 45, 47, 0.6);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(91, 123, 122, 0.3);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(30,45,47,0.3);
    padding: 3rem 4rem;
    text-align: center;
}

.verdict-number {
    font-size: clamp(3rem, 8vw, 6rem);
    color: var(--oxidized-brass);
}

.verdict-label {
    color: var(--courtroom-parchment);
    opacity: 0.8;
}

/* --- Clerk's Archive (Chamber VI) --- */
.chamber-archive {
    background-color: var(--courtroom-parchment);
    background-image:
        repeating-linear-gradient(
            91.2deg,
            transparent,
            transparent 59px,
            rgba(91, 123, 122, 0.25) 59px,
            rgba(91, 123, 122, 0.25) 60px
        ),
        repeating-linear-gradient(
            1.2deg,
            transparent,
            transparent 79px,
            rgba(91, 123, 122, 0.25) 79px,
            rgba(91, 123, 122, 0.25) 80px
        );
}

.archive-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.2rem;
    margin: 2rem 0;
}

.archive-card {
    padding: 1.2rem 1.5rem;
    text-align: center;
}

.archive-colophon {
    text-align: center;
    font-family: 'Caveat', cursive;
    font-size: clamp(1.2rem, 2.5vw, 1.8rem);
    color: var(--sea-glass);
    margin-top: 3rem;
    opacity: 0.7;
}

/* --- Root Transitions --- */
.root-transition {
    position: relative;
    width: 100%;
    height: 80px;
    margin: -3vh 0;
    z-index: 15;
    overflow: hidden;
}

.root-transition svg {
    width: 100%;
    height: 100%;
}

.root-path {
    stroke-dasharray: 2000;
    stroke-dashoffset: 2000;
    transition: stroke-dashoffset 3s ease-out;
}

.root-path.drawn {
    stroke-dashoffset: 0;
}

.mushroom-dot {
    transition: opacity 0.3s ease;
}

.mushroom-dot.visible {
    opacity: 0.8;
}

/* --- Overlapping Strata (Negative Margins) --- */
.chamber-docket {
    margin-top: -3vh;
}

.chamber-evidence {
    margin-top: -2vh;
}

.chamber-deliberation {
    margin-top: -4vh;
}

.chamber-verdict {
    margin-top: -3vh;
}

.chamber-archive {
    margin-top: -2vh;
}

/* --- Scroll-linked Grid Intensity (via JS class) --- */
.chamber.grid-intense {
    --grid-opacity: 0.22;
    transition: --grid-opacity 1.5s ease;
}

/* --- Prefers Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .glass-card {
        opacity: 1;
        transform: none;
    }

    .heading-reveal {
        opacity: 1;
    }

    .subtitle {
        opacity: 1;
    }

    .fracture-line {
        opacity: 0.25;
    }

    #fracturePath {
        stroke-dashoffset: 0;
    }

    .root-path {
        stroke-dashoffset: 0;
    }

    .mushroom-dot {
        opacity: 0.8;
    }

    .counter-value {
        /* Show final values immediately */
    }
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .evidence-scatter {
        grid-template-columns: 1fr;
    }

    .verdict-cards {
        grid-template-columns: 1fr;
    }

    .archive-grid {
        grid-template-columns: 1fr;
    }

    .counter-block {
        flex-direction: column;
        align-items: center;
    }

    .fracture-line {
        display: none;
    }

    .chamber {
        padding: 4vh 4vw;
    }

    .scatter-card {
        transform: none !important;
    }

    .scatter-card:hover {
        transform: scale(1.02) !important;
    }
}

@media (max-width: 480px) {
    .evidence-scatter {
        grid-template-columns: 1fr;
    }

    .verdict-counter-card {
        padding: 2rem 2.5rem;
    }

    .glass-card {
        padding: 1.5rem 1.5rem;
    }
}
