/* ============================================================
   scriptgrapher.com — hand-drawn aesthetic
   Palette: high-contrast ink-on-paper
   Type: Caveat (kinetic) + Inter (body) + Fira Code (snippets)
   ============================================================ */

:root {
    --pure-white: #FAFAFA;
    --ink-black: #1A1A1A;
    --pencil-gray: #6B7280;
    --highlight-yellow: #FEF08A;
    --sketch-red: #EF4444;
    --paper-warm: #F5F0E8;
    --eraser-pink: #FECDD3;

    --font-headline: 'Caveat', 'Comic Sans MS', cursive;
    --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-code: 'Fira Code', 'Menlo', 'Monaco', monospace;

    --max-w: 1100px;
}

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

html, body {
    height: 100%;
    width: 100%;
}

body {
    font-family: var(--font-body);
    color: var(--ink-black);
    background: var(--pure-white);
    font-size: clamp(16px, 1.5vw, 18px);
    line-height: 1.75;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ============================================================
   Paper texture (workspace)
   ============================================================ */
.paper-texture {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-image:
        radial-gradient(circle at 20% 35%, rgba(26,26,26,0.025) 0, transparent 60%),
        radial-gradient(circle at 80% 65%, rgba(26,26,26,0.025) 0, transparent 60%);
    mix-blend-mode: multiply;
    opacity: 0.9;
}

.paper-texture::after {
    content: "";
    position: absolute;
    inset: 0;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' seed='3'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.06 0'/></filter><rect width='240' height='240' filter='url(%23n)'/></svg>");
    opacity: 0.45;
    mix-blend-mode: multiply;
}

/* ============================================================
   The Workspace (Hero) — 100vh
   ============================================================ */
.workspace {
    position: relative;
    min-height: 100vh;
    width: 100%;
    background: var(--pure-white);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.wordmark-container {
    position: relative;
    z-index: 5;
    width: min(94vw, 1200px);
    text-align: center;
    padding: 4vh 2vw;
}

.wordmark {
    width: 100%;
    height: auto;
    display: block;
    overflow: visible;
}

.wm-text {
    font-family: var(--font-headline);
    font-weight: 700;
    font-size: 130px;
    fill: none;
    stroke: var(--ink-black);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    /* dasharray + dashoffset set by JS for stroke-draw effect */
    stroke-dasharray: 4000;
    stroke-dashoffset: 4000;
}

.wm-text-fill {
    font-family: var(--font-headline);
    font-weight: 700;
    font-size: 130px;
    fill: var(--ink-black);
    opacity: 0;
    transition: opacity 600ms ease 200ms;
}

.wm-text-fill.is-filled {
    opacity: 1;
}

.wm-text.is-glitching,
.wm-text-fill.is-glitching {
    animation: glitch 0.18s steps(2, end) 1;
}

.wm-cursor {
    opacity: 0;
    transition: opacity 200ms ease;
}

.wm-cursor.is-visible {
    opacity: 1;
}

.tagline {
    font-family: var(--font-headline);
    font-size: clamp(22px, 2.4vw, 32px);
    color: var(--pencil-gray);
    margin-top: 8px;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 800ms ease 1.4s, transform 800ms ease 1.4s;
    letter-spacing: 0.4px;
}

.tagline.is-visible {
    opacity: 1;
    transform: translateY(0);
}

/* Squiggle decorations frame the wordmark */
.squiggle {
    position: absolute;
    width: clamp(180px, 22vw, 320px);
    height: auto;
    z-index: 2;
    opacity: 0.7;
}

.squiggle-tl { top: 6vh; left: 4vw; }
.squiggle-tr { top: 6vh; right: 4vw; }
.squiggle-bl { bottom: 12vh; left: 4vw; }
.squiggle-br { bottom: 12vh; right: 4vw; }

.draw-path {
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
}

.draw-path.is-drawn {
    animation: draw 1.5s ease-out forwards;
}

.draw-path-slow {
    stroke-dasharray: 2400;
    stroke-dashoffset: 2400;
}

.draw-path-slow.is-drawn {
    animation: draw-slow 2.4s ease-out forwards;
}

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

@keyframes draw-slow {
    to { stroke-dashoffset: 0; }
}

.hero-flow {
    position: absolute;
    bottom: 14vh;
    left: 50%;
    transform: translateX(-50%);
    width: clamp(380px, 60vw, 800px);
    height: auto;
    z-index: 1;
    pointer-events: none;
}

.scroll-hint {
    position: absolute;
    bottom: 4vh;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    z-index: 4;
    opacity: 0;
    animation: fade-in 1s ease-out 2.4s forwards;
}

.scroll-hint-label {
    display: block;
    font-family: var(--font-headline);
    font-size: 22px;
    color: var(--pencil-gray);
    margin-bottom: 4px;
}

.scroll-arrow {
    width: 18px;
    height: 30px;
    animation: bob 1.6s ease-in-out infinite;
}

@keyframes bob {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(6px); }
}

@keyframes fade-in {
    to { opacity: 1; }
}

/* ============================================================
   Section Dividers
   ============================================================ */
.divider {
    width: 100%;
    padding: 30px 0;
    overflow: hidden;
}

.divider svg {
    display: block;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    height: 40px;
}

/* ============================================================
   Section Headers
   ============================================================ */
.section-header {
    text-align: center;
    margin: 0 auto 40px;
    max-width: var(--max-w);
    padding: 0 24px;
}

.section-title {
    font-family: var(--font-headline);
    font-weight: 700;
    font-size: clamp(36px, 5vw, 64px);
    color: var(--ink-black);
    line-height: 1.1;
    letter-spacing: 0.5px;
    position: relative;
    display: inline-block;
}

.kinetic-headline {
    position: relative;
    transition: opacity 0s;
}

.kinetic-headline.is-revealed {
    /* Each character revealed by JS */
}

.kinetic-headline .ch {
    display: inline-block;
    opacity: 0;
    transform: translateY(6px) rotate(-2deg);
    transition: opacity 0.18s ease, transform 0.28s ease;
}

.kinetic-headline .ch.shown {
    opacity: 1;
    transform: translateY(0) rotate(0);
}

.kinetic-headline .ch-space {
    display: inline-block;
    width: 0.3em;
}

.section-sub {
    font-family: var(--font-headline);
    font-size: clamp(20px, 2vw, 26px);
    color: var(--pencil-gray);
    margin-top: 6px;
}

/* ============================================================
   Script Cards (3-col grid)
   ============================================================ */
.cards-section {
    padding: 60px 24px 80px;
    position: relative;
}

.cards-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 24px;
    max-width: var(--max-w);
    margin: 0 auto;
}

.script-card {
    position: relative;
    background: var(--paper-warm);
    padding: 32px 26px 26px;
    min-height: 240px;
    transform: rotate(var(--rot, 0deg));
    opacity: 0;
    translate: 0 24px;
    transition: opacity 600ms ease, translate 600ms ease;
}

.script-card.is-visible {
    opacity: 1;
    translate: 0 0;
}

.script-card.is-glitching {
    animation: glitch 0.18s steps(2, end) 1;
}

.card-border {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.card-pin {
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 16px;
    height: 16px;
    background: var(--sketch-red);
    border-radius: 50%;
    box-shadow: 0 2px 6px rgba(0,0,0,0.18);
}

.card-pin::after {
    content: "";
    position: absolute;
    top: 4px;
    left: 4px;
    width: 4px;
    height: 4px;
    background: rgba(255,255,255,0.6);
    border-radius: 50%;
}

.card-title {
    font-family: var(--font-headline);
    font-weight: 700;
    font-size: 36px;
    color: var(--ink-black);
    margin-bottom: 14px;
    line-height: 1;
    text-transform: lowercase;
    position: relative;
    z-index: 1;
}

.strike {
    position: relative;
    display: inline-block;
}

.strike::after {
    content: "";
    position: absolute;
    left: -4px;
    right: -4px;
    top: 56%;
    height: 3px;
    background: var(--sketch-red);
    transform: rotate(-2deg);
    border-radius: 2px;
}

.card-icon {
    width: 88px;
    height: 70px;
    display: block;
    margin-bottom: 12px;
    position: relative;
    z-index: 1;
}

.card-body {
    font-family: var(--font-body);
    font-size: 15.5px;
    color: var(--ink-black);
    line-height: 1.7;
    margin-bottom: 14px;
    position: relative;
    z-index: 1;
}

.card-code {
    display: inline-block;
    font-family: var(--font-code);
    font-size: 13px;
    color: var(--ink-black);
    background: var(--highlight-yellow);
    padding: 3px 8px;
    border-radius: 2px;
    position: relative;
    z-index: 1;
}

.error-code {
    color: var(--sketch-red);
    background: transparent;
    border-bottom: 2px wavy var(--sketch-red);
}

/* ============================================================
   The Flow (flowchart)
   ============================================================ */
.flow-section {
    padding: 60px 24px 100px;
    background: var(--pure-white);
}

.flow-canvas {
    position: relative;
    max-width: 1100px;
    margin: 0 auto;
    height: 460px;
}

.flow-diagram {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.flow-curve {
    stroke-dasharray: 600;
    stroke-dashoffset: 600;
}

.flow-canvas.is-active .flow-curve {
    animation: draw-flow 1.4s ease-out forwards;
}

.flow-canvas.is-active .flow-curve:nth-child(1) { animation-delay: 0.1s; }
.flow-canvas.is-active .flow-curve:nth-child(2) { animation-delay: 0.4s; }
.flow-canvas.is-active .flow-curve:nth-child(3) { animation-delay: 0.7s; }
.flow-canvas.is-active .flow-curve:nth-child(4) { animation-delay: 1.0s; }
.flow-canvas.is-active .flow-curve:nth-child(n+5) { animation-delay: 1.3s; }

@keyframes draw-flow {
    to { stroke-dashoffset: 0; }
}

.flow-node {
    position: absolute;
    left: var(--nx);
    top: var(--ny);
    width: 160px;
    padding: 14px 18px;
    background: var(--paper-warm);
    border: 2px solid var(--ink-black);
    text-align: center;
    transform: rotate(-1deg);
    opacity: 0;
    translate: 0 8px;
    transition: opacity 500ms ease, translate 500ms ease;
}

.flow-canvas.is-active .flow-node { opacity: 1; translate: 0 0; }
.flow-canvas.is-active .node-1 { transition-delay: 0.2s; }
.flow-canvas.is-active .node-2 { transition-delay: 0.5s; transform: rotate(0.6deg); }
.flow-canvas.is-active .node-3 { transition-delay: 0.8s; transform: rotate(-0.6deg); }
.flow-canvas.is-active .node-4 { transition-delay: 1.1s; transform: rotate(0.8deg); }
.flow-canvas.is-active .node-5 { transition-delay: 1.4s; transform: rotate(-0.4deg); }
.flow-canvas.is-active .node-6 { transition-delay: 1.7s; transform: rotate(0.5deg); }

.flow-node-num {
    display: block;
    font-family: var(--font-code);
    font-size: 11px;
    color: var(--pencil-gray);
    margin-bottom: 2px;
    letter-spacing: 1px;
}

.flow-node-text {
    font-family: var(--font-headline);
    font-weight: 700;
    font-size: 30px;
    color: var(--ink-black);
    line-height: 1;
    text-transform: lowercase;
    display: inline-block;
}

.flow-node:hover {
    background: var(--highlight-yellow);
    cursor: default;
}

.flow-node.is-glitching {
    animation: glitch 0.18s steps(2, end) 1;
}

.flow-caption {
    text-align: center;
    margin-top: 50px;
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
    padding: 0 24px;
}

.flow-caption p {
    font-family: var(--font-headline);
    font-size: clamp(22px, 2.4vw, 30px);
    color: var(--ink-black);
    line-height: 1.4;
}

.hl {
    background: var(--highlight-yellow);
    padding: 1px 8px;
    border-radius: 2px;
    display: inline-block;
    transform: rotate(-1deg);
}

/* ============================================================
   Signed Footer
   ============================================================ */
.signed-footer {
    background: var(--pure-white);
    padding: 60px 24px 80px;
    text-align: center;
    position: relative;
}

.footer-flourish {
    width: clamp(280px, 50vw, 600px);
    height: 60px;
    margin: 0 auto 30px;
    display: block;
}

.signature {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.sig-svg {
    width: clamp(220px, 30vw, 360px);
    height: auto;
    display: block;
}

.sig-path {
    stroke-dasharray: 1200;
    stroke-dashoffset: 1200;
}

.signed-footer.is-active .sig-path {
    animation: draw-sig 2.2s ease-out forwards;
}

.signed-footer.is-active .sig-path:nth-child(2) {
    animation-delay: 1.6s;
    animation-duration: 0.5s;
}

@keyframes draw-sig {
    to { stroke-dashoffset: 0; }
}

.sig-label {
    font-family: var(--font-headline);
    font-size: 18px;
    color: var(--pencil-gray);
    letter-spacing: 0.4px;
}

/* ============================================================
   Glitch effect (color-channel offset, brief)
   ============================================================ */
@keyframes glitch {
    0% {
        transform: translate(0, 0);
        text-shadow: 0 0 0 transparent;
    }
    25% {
        transform: translate(-1px, 1px);
        text-shadow: 2px 0 var(--sketch-red), -2px 0 #00b4d8;
        filter: drop-shadow(2px 0 var(--sketch-red)) drop-shadow(-2px 0 #00b4d8);
    }
    50% {
        transform: translate(1px, -1px);
        text-shadow: -2px 0 var(--sketch-red), 2px 0 #00b4d8;
        filter: drop-shadow(-2px 0 var(--sketch-red)) drop-shadow(2px 0 #00b4d8);
    }
    75% {
        transform: translate(-1px, -1px);
        text-shadow: 1px 0 var(--sketch-red), -1px 0 #00b4d8;
        filter: drop-shadow(1px 0 var(--sketch-red)) drop-shadow(-1px 0 #00b4d8);
    }
    100% {
        transform: translate(0, 0);
        text-shadow: 0 0 0 transparent;
        filter: none;
    }
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 900px) {
    .cards-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .squiggle {
        width: 140px;
        opacity: 0.5;
    }

    .squiggle-tl { top: 3vh; left: 2vw; }
    .squiggle-tr { top: 3vh; right: 2vw; }
    .squiggle-bl { bottom: 14vh; left: 2vw; }
    .squiggle-br { bottom: 14vh; right: 2vw; }

    .wm-text, .wm-text-fill {
        font-size: 80px;
    }

    .flow-canvas {
        height: 920px;
    }

    .flow-node {
        width: 140px;
    }

    /* Stack flow nodes vertically on smaller screens */
    .node-1 { left: calc(50% - 70px) !important; top: 20px !important; }
    .node-2 { left: calc(50% - 70px) !important; top: 170px !important; }
    .node-3 { left: calc(50% - 70px) !important; top: 320px !important; }
    .node-4 { left: calc(50% - 70px) !important; top: 470px !important; }
    .node-5 { left: calc(50% - 70px) !important; top: 620px !important; }
    .node-6 { left: calc(50% - 70px) !important; top: 770px !important; }

    .flow-diagram { display: none; }
}

@media (max-width: 600px) {
    .cards-grid {
        grid-template-columns: 1fr;
    }

    .wm-text, .wm-text-fill {
        font-size: 56px;
    }

    .squiggle {
        width: 100px;
        opacity: 0.4;
    }

    .section-title {
        font-size: 36px;
    }
}
