/* ============================================
   judge.bar — Styles
   Skeuomorphic judicial docket design
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    --judicial-linen: #F5F0E8;
    --judicial-ink: #1B1710;
    --walnut-ink: #3A3228;
    --bench-brass: #C9A96E;
    --tarnished-brass: #8C7853;
    --chamber-wood: #5C5042;
    --seal-red: #7B2D26;
    --parchment-warm: #EDE6D8;
    --seal-red-dark: #5A1F1A;
    --seal-red-light: #943832;
}

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

html {
    scroll-behavior: smooth;
    scroll-snap-type: y proximity;
    font-size: 16px;
}

body {
    font-family: 'Source Serif 4', 'Georgia', serif;
    font-weight: 400;
    color: var(--walnut-ink);
    background-color: var(--judicial-linen);
    line-height: 1.72;
    overflow-x: hidden;
}

/* --- Bond Paper Texture SVG --- */
#paper-texture {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
    opacity: 0.03;
}

/* --- Typography --- */
h1 {
    font-family: 'Libre Baskerville', 'Georgia', serif;
    font-weight: 700;
    font-size: clamp(2.6rem, 5.5vw, 4.8rem);
    color: var(--judicial-ink);
    letter-spacing: 0.03em;
    line-height: 1.12;
    text-transform: uppercase;
}

h2 {
    font-family: 'Libre Baskerville', 'Georgia', serif;
    font-weight: 700;
    font-size: clamp(1.5rem, 3vw, 2.4rem);
    color: var(--judicial-ink);
    letter-spacing: 0.03em;
    line-height: 1.12;
    margin-bottom: 1.5rem;
}

p {
    font-family: 'Source Serif 4', 'Georgia', serif;
    font-weight: 400;
    font-size: clamp(1rem, 1.2vw, 1.15rem);
    color: var(--walnut-ink);
    line-height: 1.72;
    max-width: 62ch;
    margin-bottom: 1.5em;
}

/* --- JB Monogram --- */
#jb-monogram {
    position: fixed;
    top: 24px;
    left: 24px;
    z-index: 100;
    font-family: 'Libre Baskerville', 'Georgia', serif;
    font-weight: 700;
    font-size: 1.1rem;
    font-variant: small-caps;
    color: var(--judicial-ink);
    text-decoration: none;
    opacity: 0;
    transition: opacity 400ms ease;
    letter-spacing: 0.05em;
    pointer-events: none;
}

#jb-monogram.visible {
    opacity: 0.6;
    pointer-events: auto;
}

#jb-monogram:hover {
    opacity: 1;
}

/* --- Docket Rail --- */
#docket-rail {
    position: fixed;
    left: 0;
    top: 0;
    width: 12%;
    height: 100vh;
    z-index: 50;
    pointer-events: none;
    opacity: 0;
    transition: opacity 600ms ease;
}

#docket-rail.visible {
    opacity: 1;
}

.rail-line {
    position: absolute;
    left: 50%;
    top: 0;
    width: 2px;
    height: 100%;
    background-color: var(--tarnished-brass);
    transform: translateX(-50%);
    opacity: 0.4;
}

.rail-node {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: radial-gradient(circle, var(--bench-brass), var(--tarnished-brass));
    opacity: 0.4;
    transition: opacity 400ms ease, box-shadow 400ms ease;
}

.rail-node[data-section="1"] { top: 10%; }
.rail-node[data-section="2"] { top: 30%; }
.rail-node[data-section="3"] { top: 50%; }
.rail-node[data-section="4"] { top: 70%; }
.rail-node[data-section="5"] { top: 90%; }

.rail-node.active {
    opacity: 1;
    box-shadow: 0 0 0 4px rgba(201, 169, 110, 0.3), 0 0 0 8px rgba(201, 169, 110, 0.1);
}

.rail-number {
    position: absolute;
    left: 28px;
    top: 50%;
    transform: translateY(-50%);
    font-family: 'Libre Baskerville', 'Georgia', serif;
    font-style: italic;
    font-size: 0.85rem;
    color: var(--tarnished-brass);
    letter-spacing: 0.06em;
    white-space: nowrap;
    opacity: 0.4;
    transition: opacity 400ms ease;
}

.rail-node.active .rail-number {
    opacity: 1;
}

/* --- Sections --- */
.docket-section {
    position: relative;
    min-height: 100vh;
    width: 100%;
    scroll-snap-align: start;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.docket-section:nth-child(even of .docket-section) {
    background-color: var(--parchment-warm);
}

.section-inner {
    width: 100%;
    max-width: 1200px;
    padding: 4rem 2rem;
    display: flex;
    align-items: flex-start;
}

/* --- Split Layout --- */
.split-left {
    width: 38%;
    padding-right: 2%;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding-left: 14%;
}

.split-gutter {
    width: 4%;
}

.split-right {
    width: 58%;
}

.section-ordinal {
    font-family: 'Libre Baskerville', 'Georgia', serif;
    font-style: italic;
    font-size: clamp(2rem, 4vw, 3.5rem);
    color: var(--bench-brass);
    letter-spacing: 0.06em;
    line-height: 1;
    margin-bottom: 1rem;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 600ms ease, transform 600ms ease;
}

.case-caption {
    font-family: 'Libre Baskerville', 'Georgia', serif;
    font-style: italic;
    font-size: 0.85rem;
    color: var(--tarnished-brass);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    font-variant: small-caps;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 600ms ease 200ms, transform 600ms ease 200ms;
}

.docket-section.in-view .section-ordinal,
.docket-section.in-view .case-caption {
    opacity: 1;
    transform: translateY(0);
}

/* --- Margin Notes --- */
.margin-note {
    margin-top: 2rem;
    width: 180px;
    font-family: 'IBM Plex Mono', monospace;
    font-style: italic;
    font-size: 0.8rem;
    color: var(--chamber-wood);
    line-height: 1.5;
    opacity: 0;
    filter: blur(4px);
    transition: opacity 500ms ease, filter 500ms ease;
}

.docket-section.in-view .margin-note {
    opacity: 1;
    filter: blur(0);
}

.note-ref {
    font-weight: 400;
    color: var(--tarnished-brass);
    margin-right: 0.25rem;
}

/* --- Section 1: Opening / Seal --- */
.section-opening {
    background-color: var(--judicial-linen);
    display: flex;
    align-items: center;
    justify-content: center;
}

.section-opening .section-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.opening-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

/* --- Wax Seal --- */
#wax-seal {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: radial-gradient(circle at 40% 35%, var(--seal-red-light), var(--seal-red) 50%, var(--seal-red-dark) 100%);
    box-shadow:
        0 4px 12px rgba(27, 23, 16, 0.3),
        inset 0 2px 4px rgba(255, 255, 255, 0.1),
        inset 0 -2px 4px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    opacity: 0;
    transition: opacity 600ms ease;
    margin-bottom: 2rem;
}

#wax-seal::before {
    content: '';
    position: absolute;
    top: -6px;
    left: -6px;
    right: -6px;
    bottom: -6px;
    border-radius: 50%;
    background: repeating-conic-gradient(
        var(--seal-red) 0deg 10deg,
        var(--seal-red-dark) 10deg 20deg
    );
    z-index: -1;
    opacity: 0.7;
}

#wax-seal::after {
    content: '';
    position: absolute;
    top: -6px;
    left: -6px;
    right: -6px;
    bottom: -6px;
    border-radius: 50%;
    background: radial-gradient(circle, transparent 55%, rgba(27, 23, 16, 0.15) 100%);
    z-index: 0;
}

#wax-seal.visible {
    opacity: 1;
}

.seal-letter {
    font-family: 'Libre Baskerville', 'Georgia', serif;
    font-weight: 700;
    font-size: 3rem;
    color: var(--judicial-linen);
    position: relative;
    z-index: 1;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

/* --- Domain Typewriter --- */
#domain-typewriter {
    margin-bottom: 2rem;
    overflow: hidden;
}

.typewriter-text {
    font-family: 'Libre Baskerville', 'Georgia', serif;
    font-size: 1.2rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--walnut-ink);
    display: inline-block;
    opacity: 0;
}

.typewriter-text.typing {
    opacity: 1;
}

.typewriter-text .char {
    opacity: 0;
    transition: opacity 50ms ease;
}

.typewriter-text .char.visible {
    opacity: 1;
}

/* --- Ornamental Rules --- */
.ornamental-rule {
    position: relative;
    width: 100%;
    max-width: 400px;
    height: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 1.5rem auto;
    opacity: 0;
    transition: opacity 400ms ease;
}

.ornamental-rule.visible {
    opacity: 1;
}

.ornamental-rule::before,
.ornamental-rule::after {
    content: '';
    position: absolute;
    top: 50%;
    height: 0.5px;
    background-color: var(--tarnished-brass);
    transform: translateY(-50%) scaleX(0);
    transition: transform 800ms cubic-bezier(0.25, 0, 0.15, 1);
}

.ornamental-rule::before {
    right: 50%;
    left: 0;
    transform-origin: right center;
}

.ornamental-rule::after {
    left: 50%;
    right: 0;
    transform-origin: left center;
}

.ornamental-rule.animate::before,
.ornamental-rule.animate::after {
    transform: translateY(-50%) scaleX(1);
}

/* Second line offset */
.ornamental-rule .diamond-glyph {
    position: relative;
    z-index: 2;
    font-size: 0.6rem;
    color: var(--bench-brass);
    line-height: 1;
}

/* --- Scroll Indicator --- */
#scroll-indicator {
    position: absolute;
    bottom: 3rem;
    left: 50%;
    transform: translateX(-50%);
    opacity: 0;
    transition: opacity 600ms ease;
}

#scroll-indicator.visible {
    opacity: 1;
}

.chevron-pulse {
    display: block;
    font-size: 1.4rem;
    color: var(--tarnished-brass);
    animation: pulseDown 2s ease-in-out infinite;
}

@keyframes pulseDown {
    0%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    50% {
        transform: translateY(8px);
        opacity: 1;
    }
}

/* --- Section 2: Nameplate --- */
.section-nameplate {
    background-color: var(--parchment-warm);
}

.section-nameplate .section-inner {
    align-items: center;
}

.section-nameplate .split-right {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* --- Brass Nameplate --- */
#brass-nameplate {
    aspect-ratio: 4 / 1;
    max-width: 360px;
    width: 100%;
    background: linear-gradient(135deg, var(--bench-brass), #DFC690, var(--tarnished-brass));
    box-shadow:
        inset 0 1px 3px rgba(27, 23, 16, 0.4),
        inset 0 -1px 2px rgba(255, 255, 255, 0.15),
        0 2px 8px rgba(27, 23, 16, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 2.5rem;
    border: 1px solid rgba(140, 120, 83, 0.3);
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 700ms ease, transform 700ms ease;
}

.section-nameplate.in-view #brass-nameplate {
    opacity: 1;
    transform: translateY(0);
}

.nameplate-text {
    font-family: 'Libre Baskerville', 'Georgia', serif;
    font-weight: 700;
    font-size: clamp(1.2rem, 2.5vw, 1.8rem);
    letter-spacing: 0.15em;
    color: var(--chamber-wood);
    text-shadow:
        1px 1px 0 rgba(255, 255, 255, 0.3),
        -1px -1px 0 rgba(0, 0, 0, 0.25);
}

.purpose-statement {
    font-family: 'Source Serif 4', 'Georgia', serif;
    font-size: 1.25rem;
    font-weight: 400;
    color: var(--walnut-ink);
    text-align: center;
    max-width: 48ch;
    line-height: 1.72;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 700ms ease 300ms, transform 700ms ease 300ms;
}

.section-nameplate.in-view .purpose-statement {
    opacity: 1;
    transform: translateY(0);
}

/* --- Section 3: Opinion --- */
.section-opinion {
    background-color: var(--judicial-linen);
}

.opinion-text p {
    text-indent: 2em;
    opacity: 0;
    transform: translateY(15px);
    transition: opacity 600ms ease, transform 600ms ease;
}

.section-opinion.in-view .opinion-text p:nth-child(1) {
    opacity: 1;
    transform: translateY(0);
    transition-delay: 200ms;
}

.section-opinion.in-view .opinion-text p:nth-child(2) {
    opacity: 1;
    transform: translateY(0);
    transition-delay: 400ms;
}

.section-opinion.in-view .opinion-text p:nth-child(3) {
    opacity: 1;
    transform: translateY(0);
    transition-delay: 600ms;
}

.section-opinion .split-right h2 {
    opacity: 0;
    transform: translateY(15px);
    transition: opacity 600ms ease, transform 600ms ease;
}

.section-opinion.in-view .split-right h2 {
    opacity: 1;
    transform: translateY(0);
}

/* Horizontal rule beneath opinion sections */
.section-opinion .split-right {
    border-bottom: 1px solid rgba(58, 50, 40, 0.3);
    padding-bottom: 2rem;
}

/* --- Section 4: Gavel Strike --- */
.section-gavel {
    background-color: var(--parchment-warm);
    flex-direction: column;
}

.gavel-strike-line {
    position: absolute;
    top: 50%;
    left: 0;
    width: 100%;
    height: 4px;
    background-color: var(--judicial-ink);
    transform: translateY(-50%);
    clip-path: inset(0 100% 0 0);
    z-index: 5;
    opacity: 0;
}

.gavel-strike-line.strike {
    opacity: 1;
    animation: gavelStrike 400ms ease-out forwards;
}

@keyframes gavelStrike {
    0% {
        clip-path: inset(0 100% 0 0);
    }
    100% {
        clip-path: inset(0 0 0 0);
    }
}

@keyframes bodyShake {
    0% { transform: translateX(0); }
    20% { transform: translateX(-2px); }
    40% { transform: translateX(2px); }
    60% { transform: translateX(-2px); }
    80% { transform: translateX(1px); }
    100% { transform: translateX(0); }
}

body.shaking {
    animation: bodyShake 60ms ease-in-out;
}

.section-gavel-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 4rem 2rem;
    max-width: 900px;
    margin: 0 auto;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 600ms ease, transform 600ms ease;
}

.section-gavel.in-view .section-gavel-content {
    opacity: 1;
    transform: translateY(0);
}

.thesis-statement {
    margin: 2rem 0;
}

.seal-red-word {
    color: var(--seal-red);
}

.gavel-rule-top,
.gavel-rule-bottom {
    max-width: 300px;
}

/* --- Section 5: Closing --- */
.section-closing {
    background-color: var(--judicial-linen);
}

.closing-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 100vh;
    padding: 4rem 2rem;
}

/* --- Court Filing Header --- */
.court-filing-header {
    max-width: 420px;
    width: 100%;
    margin-bottom: 2.5rem;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 700ms ease, transform 700ms ease;
}

.section-closing.in-view .court-filing-header {
    opacity: 1;
    transform: translateY(0);
}

.filing-line {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 0.5rem 0;
    border-bottom: 1px solid rgba(58, 50, 40, 0.15);
}

.filing-line:last-child {
    border-bottom: none;
}

.filing-label {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    font-size: 0.8rem;
    color: var(--chamber-wood);
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.filing-value {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    font-size: 0.8rem;
    color: var(--walnut-ink);
}

/* --- Closing Seal --- */
#closing-seal {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: radial-gradient(circle at 40% 35%, var(--seal-red-light), var(--seal-red) 50%, var(--seal-red-dark) 100%);
    box-shadow:
        0 4px 12px rgba(27, 23, 16, 0.3),
        inset 0 2px 4px rgba(255, 255, 255, 0.1),
        inset 0 -2px 4px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    margin-top: 2rem;
    opacity: 0;
    transform: scale(0.6);
    transition: opacity 800ms ease 300ms, transform 800ms ease 300ms;
}

#closing-seal::before {
    content: '';
    position: absolute;
    top: -6px;
    left: -6px;
    right: -6px;
    bottom: -6px;
    border-radius: 50%;
    background: repeating-conic-gradient(
        var(--seal-red) 0deg 10deg,
        var(--seal-red-dark) 10deg 20deg
    );
    z-index: -1;
    opacity: 0.7;
}

#closing-seal::after {
    content: '';
    position: absolute;
    top: -6px;
    left: -6px;
    right: -6px;
    bottom: -6px;
    border-radius: 50%;
    background: radial-gradient(circle, transparent 55%, rgba(27, 23, 16, 0.15) 100%);
    z-index: 0;
}

.section-closing.in-view #closing-seal {
    opacity: 1;
    transform: scale(1);
}

#closing-seal .seal-letter {
    font-family: 'Libre Baskerville', 'Georgia', serif;
    font-weight: 700;
    font-size: 3rem;
    color: var(--judicial-linen);
    position: relative;
    z-index: 1;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

/* Border trace animation on closing seal */
@keyframes sealBorderTrace {
    0% {
        clip-path: circle(0% at 50% 0%);
    }
    100% {
        clip-path: circle(100% at 50% 50%);
    }
}

.section-closing.in-view #closing-seal::before {
    animation: sealBorderTrace 2s ease-out 600ms forwards;
}

/* --- Closing Rule --- */
.closing-rule {
    max-width: 300px;
    margin: 1.5rem auto;
}

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

    html {
        scroll-behavior: auto;
    }

    .section-ordinal,
    .case-caption,
    .margin-note,
    #brass-nameplate,
    .purpose-statement,
    .opinion-text p,
    .section-opinion .split-right h2,
    .section-gavel-content,
    .court-filing-header,
    #closing-seal,
    #wax-seal,
    .typewriter-text,
    .ornamental-rule,
    #scroll-indicator {
        opacity: 1 !important;
        transform: none !important;
        filter: none !important;
    }

    .gavel-strike-line {
        opacity: 1 !important;
        clip-path: none !important;
    }

    .ornamental-rule::before,
    .ornamental-rule::after {
        transform: translateY(-50%) scaleX(1) !important;
    }
}

/* --- Responsive --- */
@media (max-width: 768px) {
    #docket-rail {
        display: none;
    }

    .section-inner {
        flex-direction: column;
        padding: 3rem 1.5rem;
    }

    .split-left {
        width: 100%;
        padding-left: 0;
        padding-right: 0;
        margin-bottom: 2rem;
    }

    .split-gutter {
        display: none;
    }

    .split-right {
        width: 100%;
    }

    .section-opinion .split-right {
        border-bottom: none;
    }

    #jb-monogram {
        top: 16px;
        left: 16px;
    }

    .margin-note {
        width: 100%;
        max-width: 100%;
    }

    h1 {
        font-size: clamp(2rem, 8vw, 3rem);
    }

    #brass-nameplate {
        max-width: 280px;
    }

    .court-filing-header {
        max-width: 100%;
    }

    .filing-line {
        flex-direction: column;
        gap: 0.25rem;
    }
}
