:root {
    --bg-parchment: #F5E6D3;
    --bg-desk: #EDD9C0;
    --ink-coral: #B25032;
    --seal-marigold: #D4963A;
    --blush: #E8A07A;
    --text-ink: #2E1A0E;
    --rule-faded: #E8C9A0;
    --pencil-gray: #8C7B6B;
    --coffee: #C4956A;
    --espresso: #B87D5E;
    --font-main: 'Commissioner', sans-serif;
}

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    background-color: var(--bg-parchment);
    color: var(--text-ink);
    font-family: var(--font-main);
    min-height: 100vh;
    position: relative;
    overflow-x: hidden;
}

/* SVG Filters (hidden) */
.svg-filters {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

/* ==========================================
   GRAIN OVERLAY
   ========================================== */
.grain-overlay {
    position: fixed;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    pointer-events: none;
    z-index: 100;
    opacity: 0.06;
    mix-blend-mode: multiply;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence baseFrequency='0.65' numOctaves='4' type='fractalNoise'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)'/%3E%3C/svg%3E");
    background-size: 300px 300px;
    animation: grain-shift 4s steps(2) infinite;
}

@keyframes grain-shift {
    0% { transform: translate(0, 0); }
    25% { transform: translate(1px, 0); }
    50% { transform: translate(1px, 1px); }
    75% { transform: translate(0, 1px); }
    100% { transform: translate(0, 0); }
}

/* ==========================================
   RULED LINES (hand-drawn grid)
   ========================================== */
.ruled-lines {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 0;
    background-image: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 31px,
        var(--rule-faded) 31px,
        var(--rule-faded) 32px
    );
    opacity: 0.35;
    filter: url(#wobble-filter);
}

/* ==========================================
   LAYOUT
   ========================================== */
.section {
    max-width: 680px;
    margin: 0 auto;
    padding: 120px 2rem;
    position: relative;
    z-index: 1;
}

/* ==========================================
   SECTION 1: PREAMBLE (THE STAMP)
   ========================================== */
.preamble {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* Ripple containers */
.ripple-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 0;
    height: 0;
    pointer-events: none;
    z-index: 0;
}

.ripple-ring {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    width: 120vw;
    height: 120vw;
    border-radius: 50%;
    border: 2px solid rgba(178, 80, 50, 0.08);
    background: radial-gradient(circle at center, transparent 40%, rgba(178, 80, 50, 0.04) 60%, transparent 100%);
    animation: ripple-expand 1.2s ease-out forwards;
    pointer-events: none;
}

@keyframes ripple-expand {
    0% { transform: translate(-50%, -50%) scale(0); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 0; }
}

/* Hero Stamp */
.stamp {
    transform: scale(1.3) rotate(0deg);
    opacity: 0;
    margin-bottom: 2rem;
    position: relative;
    z-index: 2;
}

.stamp.stamp-landed {
    animation: stamp-land 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes stamp-land {
    0% { transform: scale(1.3) rotate(0deg); opacity: 0; }
    60% { transform: scale(0.97) rotate(-2.5deg); opacity: 1; }
    100% { transform: scale(1) rotate(-2.5deg); opacity: 1; }
}

.stamp-border-outer {
    border: 1px solid var(--ink-coral);
    border-radius: 4px;
    padding: 4px;
}

.stamp-border-inner {
    border: 3px solid var(--ink-coral);
    border-radius: 3px;
    padding: 1.5rem 3rem;
    background: radial-gradient(ellipse at center, rgba(178, 80, 50, 0.06) 0%, transparent 70%);
}

.stamp-text {
    font-family: var(--font-main);
    font-weight: 900;
    font-size: clamp(2rem, 5vw, 3.5rem);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--ink-coral);
    text-shadow: 0 0 2px rgba(178, 80, 50, 0.4);
    display: block;
    text-align: center;
}

.preamble-sub {
    font-family: var(--font-main);
    font-weight: 300;
    font-style: italic;
    font-size: 1rem;
    color: var(--pencil-gray);
    letter-spacing: 0.02em;
    text-align: center;
}

/* ==========================================
   PERFORATED LINE
   ========================================== */
.perforated-line {
    border: none;
    border-top: 1px dashed var(--rule-faded);
    max-width: 680px;
    margin: 0 auto;
    position: relative;
    z-index: 1;
}

.perforated-line::before {
    content: '';
    position: absolute;
    top: -1px;
    left: 0;
    right: 0;
    height: 1px;
    background: repeating-linear-gradient(
        90deg,
        var(--rule-faded) 0px,
        var(--rule-faded) 4px,
        transparent 4px,
        transparent 12px
    );
}

/* ==========================================
   SECTION 2: TERMS OF WHIMSY
   ========================================== */
.terms {
    position: relative;
    min-height: 80vh;
}

/* Margin Doodles */
.margin-doodle {
    position: absolute;
    opacity: 0;
    transition: opacity 0.5s ease;
}

.margin-doodle.doodle-visible {
    opacity: 0.55;
}

.doodle-key {
    left: -65px;
    top: 160px;
}

.doodle-check {
    right: -55px;
    top: 320px;
    transform: rotate(8deg);
}

.doodle-quill {
    left: -60px;
    top: 480px;
    transform: rotate(-5deg);
}

.doodle-magnifier {
    right: -55px;
    top: 600px;
    transform: rotate(3deg);
}

.doodle-scroll {
    right: -65px;
    top: 40%;
    transform: rotate(-2deg);
}

/* SVG Path-Draw Animation */
.draw-path {
    stroke-dasharray: var(--path-length, 200);
    stroke-dashoffset: var(--path-length, 200);
    transition: stroke-dashoffset 2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.doodle-visible .draw-path {
    stroke-dashoffset: 0;
}

/* Clauses */
.clause {
    margin-bottom: 2rem;
    position: relative;
}

.clause-number {
    font-family: var(--font-main);
    font-weight: 700;
    font-size: 0.85rem;
    letter-spacing: 0.08em;
    color: var(--ink-coral);
    display: block;
    margin-bottom: 0.5rem;
}

.section-heading {
    font-family: var(--font-main);
    font-weight: 700;
    font-size: clamp(2rem, 5vw, 3.5rem);
    color: var(--text-ink);
    letter-spacing: -0.02em;
    margin-bottom: 2rem;
    transition: font-weight 0.3s ease;
}

.section-heading:hover {
    font-weight: 800;
}

.body-text {
    font-family: var(--font-main);
    font-weight: 400;
    font-size: clamp(1rem, 2.2vw, 1.15rem);
    line-height: 1.75;
    color: var(--text-ink);
    margin-bottom: 1.5rem;
    letter-spacing: 0.01em;
}

.annotation {
    font-family: var(--font-main);
    font-weight: 300;
    font-style: italic;
    font-size: 0.8rem;
    color: var(--espresso);
    margin-bottom: 1.5rem;
    padding-left: 1rem;
}

/* ==========================================
   SECTION 3: THE BROKER'S DESK
   ========================================== */
.desk {
    padding: 80px 2rem;
    max-width: 780px;
    min-height: 100vh;
    transition: background-color 0.8s ease;
}

.desk.desk-active {
    background-color: var(--bg-desk);
    border-radius: 2px;
}

.desk-surface {
    position: relative;
    padding: 3rem 2rem;
}

/* Coffee Ring Stains */
.coffee-ring {
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
}

.coffee-ring-1 {
    top: 8%;
    right: 6%;
    width: 85px;
    height: 85px;
    background: radial-gradient(circle,
        transparent 28px,
        rgba(196, 149, 106, 0.22) 29px,
        rgba(196, 149, 106, 0.15) 34px,
        transparent 35px
    );
}

.coffee-ring-2 {
    bottom: 18%;
    left: 3%;
    width: 65px;
    height: 65px;
    background: radial-gradient(circle,
        transparent 20px,
        rgba(196, 149, 106, 0.18) 21px,
        rgba(196, 149, 106, 0.12) 27px,
        transparent 28px
    );
}

.coffee-ring-3 {
    top: 50%;
    right: 15%;
    width: 50px;
    height: 50px;
    background: radial-gradient(circle,
        transparent 15px,
        rgba(196, 149, 106, 0.15) 16px,
        rgba(196, 149, 106, 0.1) 20px,
        transparent 21px
    );
}

/* Ink Splatter */
.ink-splatter span {
    position: absolute;
    border-radius: 50%;
    background-color: var(--ink-coral);
    opacity: 0.15;
}

/* Desk Lamp */
.desk-lamp {
    position: absolute;
    top: -20px;
    right: -30px;
    opacity: 0;
    transition: opacity 0.6s ease;
}

.desk-active .desk-lamp {
    opacity: 0.5;
}

/* Desk Documents */
.desk-doc {
    background-color: rgba(245, 230, 211, 0.85);
    border: 1px solid var(--rule-faded);
    padding: 2rem;
    margin-bottom: 2rem;
    position: relative;
    box-shadow: 2px 2px 8px rgba(46, 26, 14, 0.04);
}

.desk-doc-1 {
    transform: rotate(0.5deg);
}

.desk-doc-2 {
    transform: rotate(-0.3deg);
    margin-left: 2rem;
}

.desk-doc-3 {
    transform: rotate(0.8deg);
    margin-left: 1rem;
}

.stamp-mini {
    display: inline-block;
    font-family: var(--font-main);
    font-weight: 900;
    font-size: 0.7rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--ink-coral);
    border: 2px solid var(--ink-coral);
    padding: 0.25rem 0.75rem;
    border-radius: 2px;
    transform: rotate(-3deg);
    margin-bottom: 1rem;
    text-shadow: 0 0 2px rgba(178, 80, 50, 0.3);
    background: radial-gradient(ellipse at center, rgba(178, 80, 50, 0.04) 0%, transparent 70%);
}

.stamp-filed {
    color: var(--seal-marigold);
    border-color: var(--seal-marigold);
    transform: rotate(2deg);
    text-shadow: 0 0 2px rgba(212, 150, 58, 0.3);
    background: radial-gradient(ellipse at center, rgba(212, 150, 58, 0.04) 0%, transparent 70%);
}

.stamp-pending {
    color: var(--pencil-gray);
    border-color: var(--pencil-gray);
    transform: rotate(-1.5deg);
    text-shadow: 0 0 2px rgba(140, 123, 107, 0.3);
    background: radial-gradient(ellipse at center, rgba(140, 123, 107, 0.04) 0%, transparent 70%);
}

.stamp-official {
    color: var(--ink-coral);
    transform: rotate(-4deg);
}

.desk-heading {
    font-family: var(--font-main);
    font-weight: 700;
    font-size: clamp(1.3rem, 3vw, 2rem);
    color: var(--text-ink);
    margin-bottom: 1rem;
}

.desk-text {
    font-family: var(--font-main);
    font-weight: 400;
    font-size: clamp(0.95rem, 1.5vw, 1.05rem);
    line-height: 1.75;
    color: var(--text-ink);
}

/* ==========================================
   SECTION 4: OFFICIAL ENDORSEMENT
   ========================================== */
.endorsement {
    max-width: 480px;
    min-height: 60vh;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.endorsement .ripple-container {
    top: 15%;
}

.endorsement-block {
    position: relative;
}

/* Wax Seal */
.wax-seal {
    margin-bottom: 2.5rem;
    position: relative;
}

.seal-outer {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: radial-gradient(circle at 45% 45%,
        #e6ad4b 0%,
        var(--seal-marigold) 40%,
        #c08030 60%,
        var(--ink-coral) 100%
    );
    display: flex;
    align-items: center;
    justify-content: center;
    clip-path: polygon(
        50% 0%, 61% 4%, 71% 2%, 79% 10%, 88% 12%,
        93% 21%, 98% 29%, 100% 40%, 98% 50%, 100% 61%,
        96% 71%, 90% 79%, 84% 88%, 75% 93%, 65% 96%,
        55% 100%, 45% 98%, 36% 96%, 27% 92%, 19% 86%,
        12% 78%, 6% 69%, 2% 60%, 0% 50%, 2% 39%,
        5% 30%, 10% 22%, 17% 14%, 25% 8%, 35% 4%,
        44% 1%
    );
    box-shadow: 0 4px 12px rgba(46, 26, 14, 0.15);
    transform: scale(0);
    transition: transform 0.8s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.8s ease;
}

.seal-outer.seal-revealed {
    transform: scale(1);
    box-shadow: 0 4px 20px rgba(212, 150, 58, 0.2);
}

.seal-inner {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: 2px solid rgba(245, 230, 211, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
}

.seal-monogram {
    font-family: var(--font-main);
    font-weight: 900;
    font-size: 1.6rem;
    letter-spacing: 0.1em;
    color: rgba(245, 230, 211, 0.9);
    text-shadow: 0 1px 3px rgba(46, 26, 14, 0.3);
}

/* Signature Block */
.signature-block {
    margin-top: 3rem;
    text-align: right;
}

.signature-flourish {
    display: block;
    margin-left: auto;
    margin-bottom: 0.5rem;
}

.signature-path {
    stroke-dasharray: 400;
    stroke-dashoffset: 400;
    transition: stroke-dashoffset 2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

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

.signature-label {
    font-family: var(--font-main);
    font-weight: 300;
    font-size: 0.75rem;
    color: var(--pencil-gray);
    letter-spacing: 0.05em;
    display: block;
}

.signature-date {
    font-family: var(--font-main);
    font-weight: 300;
    font-style: italic;
    font-size: 0.65rem;
    color: var(--pencil-gray);
    letter-spacing: 0.03em;
    display: block;
    margin-top: 0.25rem;
}

/* ==========================================
   SECTION 5: FILED UNDER
   ========================================== */
.filed-under {
    padding: 60px 2rem;
    max-width: 680px;
    text-align: center;
    border-top: 1px dashed var(--rule-faded);
    min-height: 40vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.filed-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.filed-label {
    font-family: var(--font-main);
    font-weight: 900;
    font-size: 0.7rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--pencil-gray);
}

.filed-ref {
    font-family: var(--font-main);
    font-weight: 300;
    font-size: 0.7rem;
    color: var(--pencil-gray);
    letter-spacing: 0.1em;
}

.filed-dept {
    font-family: var(--font-main);
    font-weight: 300;
    font-style: italic;
    font-size: 0.65rem;
    color: var(--pencil-gray);
    letter-spacing: 0.05em;
    margin-top: 0.25rem;
}

.footer-stamp {
    margin-top: 1.5rem;
    opacity: 0.3;
    transform: rotate(-5deg);
}

.footer-stamp .draw-path {
    stroke-dasharray: var(--path-length, 250);
    stroke-dashoffset: var(--path-length, 250);
    transition: stroke-dashoffset 2.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.footer-stamp.stamp-drawn .draw-path {
    stroke-dashoffset: 0;
}

/* ==========================================
   REVEAL ANIMATIONS
   ========================================== */
.fade-reveal {
    opacity: 0;
    transform: translateY(24px);
    transition: opacity 0.7s ease-out, transform 0.7s ease-out;
}

.fade-reveal.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Staggered clause reveals */
.clause.fade-reveal:nth-child(2) { transition-delay: 0ms; }
.clause.fade-reveal:nth-child(3) { transition-delay: 200ms; }
.clause.fade-reveal:nth-child(4) { transition-delay: 400ms; }
.clause.fade-reveal:nth-child(5) { transition-delay: 600ms; }
.clause.fade-reveal:nth-child(7) { transition-delay: 800ms; }

/* ==========================================
   RESPONSIVE
   ========================================== */
@media (max-width: 768px) {
    .section {
        padding: 80px 1.5rem;
    }

    .margin-doodle {
        display: none;
    }

    .desk-doc-2 {
        margin-left: 0;
    }

    .desk-doc-3 {
        margin-left: 0;
    }

    .desk-lamp {
        display: none;
    }

    .endorsement {
        max-width: 100%;
    }

    .wax-seal {
        margin-bottom: 2rem;
    }

    .seal-outer {
        width: 100px;
        height: 100px;
    }

    .seal-inner {
        width: 66px;
        height: 66px;
    }

    .seal-monogram {
        font-size: 1.3rem;
    }
}

@media (max-width: 480px) {
    .section {
        padding: 60px 1.2rem;
    }

    .body-text {
        font-size: 1rem;
    }

    .stamp-text {
        font-size: 1.8rem;
    }

    .stamp-border-inner {
        padding: 1rem 1.5rem;
    }

    .desk-doc {
        padding: 1.5rem;
    }

    .signature-flourish {
        width: 160px;
    }
}
