/* ============================================================
   ASYNC GUIDES — HAND-DRAWN / SKETCHBOOK DESIGN SYSTEM
   Centralized tokens + shared components for every guide page.
   Aesthetic: notebook paper, pencil ink, correction-marker red,
   post-it yellow, ballpoint blue. No straight lines, no blur —
   wobbly borders + hard offset shadows + a little rotation.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Kalam:wght@300;400;700&family=Patrick+Hand&display=swap');

/* ---------- DESIGN TOKENS (The DNA) ---------- */
:root {
    /* Paper & ink */
    --paper:        #fdfbf7;   /* warm notebook paper */
    --ink:          #2d2d2d;   /* soft pencil black — never pure black */
    --muted:        #e5e0d8;   /* erased pencil / old paper */

    /* Limited accent palette */
    --red:          #ff4d4d;   /* correction marker */
    --blue:         #2d5da1;   /* ballpoint pen */
    --postit:       #fff9c4;   /* sticky-note yellow (fills) */
    --yellow:       #f2c14e;   /* marker yellow (accents) */

    /* Base aliases */
    --bg:           var(--paper);
    --fg:           var(--ink);
    --bg-code:      #2b2735;   /* code "sticker" charcoal */

    /* Neon-name aliases kept ONLY so per-page inline overrides that
       reference them (index hero, Prism tokens) resolve to palette
       colors instead of breaking. Structure never reads --accent*. */
    --magenta:      var(--red);
    --purple:       var(--blue);
    --cyan:         var(--blue);
    --orange:       #e0592c;

    /* Wobbly organic radii (CRITICAL — reused everywhere) */
    --wobbly:       255px 15px 225px 15px / 15px 225px 15px 255px;
    --wobbly-md:    18px 40px 22px 36px / 34px 20px 40px 18px;
    --wobbly-sm:    12px 22px 14px 20px / 20px 14px 22px 12px;
    --wobbly-pill:  120px 60px 120px 60px / 60px 120px 60px 120px;

    /* Hard offset shadows (no blur, ever) */
    --shadow:       4px 4px 0 0 var(--ink);
    --shadow-lg:    8px 8px 0 0 var(--ink);

    --font-heading: 'Kalam', 'Comic Sans MS', cursive;
    --font-body:    'Patrick Hand', 'Comic Sans MS', cursive;
    --font-display: 'Kalam', cursive;
}

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

/* ---------- NOTEBOOK-PAPER BASE ---------- */
body {
    font-family: var(--font-body);
    background-color: var(--bg);
    color: var(--fg);
    line-height: 1.75;
    font-size: 1.05rem;
    min-height: 100vh;
    position: relative;
    overflow-x: hidden;
}

/* Dot-grid paper grain */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background-image: radial-gradient(var(--muted) 1.5px, transparent 1.5px);
    background-size: 24px 24px;
}

/* Faint ballpoint margin rule down the left edge */
body::after {
    content: "";
    position: fixed;
    top: 0;
    bottom: 0;
    left: 56px;
    width: 2px;
    z-index: 0;
    pointer-events: none;
    background: rgba(255, 77, 77, 0.18);
}

.container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 48px 24px 80px;
    position: relative;
    z-index: 10;
}

/* ---------- HEADER (page banner) ---------- */
header {
    position: relative;
    background: #ffffff;
    color: var(--ink);
    border: 4px solid var(--ink);
    border-radius: var(--wobbly-md);
    margin: 18px 0 48px;
    padding: 48px 44px;
    box-shadow: var(--shadow-lg);
    transform: rotate(-1deg);
    overflow: visible;
}

/* Strip of "tape" across the top */
header::before {
    content: "";
    position: absolute;
    top: -16px;
    left: 50%;
    width: 150px;
    height: 34px;
    transform: translateX(-50%) rotate(-3deg);
    background: rgba(242, 193, 78, 0.55);
    border: 1px dashed rgba(45, 45, 45, 0.35);
    z-index: 2;
}

header h1 {
    position: relative;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: clamp(2.2rem, 6vw, 4rem);
    line-height: 1.05;
    letter-spacing: -0.01em;
    color: var(--ink);
    text-shadow: 3px 3px 0 var(--red);
}

header p, .tagline {
    position: relative;
    margin-top: 16px;
    font-size: clamp(1.1rem, 2vw, 1.4rem);
    font-weight: 400;
    color: var(--blue);
}

/* ---------- CONTENT SECTIONS (cards) ---------- */
.content-section {
    position: relative;
    background: #ffffff;
    border: 3px solid var(--ink);
    border-radius: var(--wobbly-md);
    padding: 38px 40px;
    margin-bottom: 40px;
    box-shadow: var(--shadow);
    z-index: 10;
}
.content-section:nth-of-type(even) { transform: rotate(0.4deg); }
.content-section:nth-of-type(odd)  { transform: rotate(-0.4deg); }

/* ---------- HEADINGS ---------- */
h2 {
    font-family: var(--font-heading);
    font-weight: 700;
    letter-spacing: -0.01em;
    font-size: clamp(1.7rem, 4vw, 2.5rem);
    line-height: 1.1;
    margin-bottom: 22px;
    padding-bottom: 12px;
    color: var(--ink);
    border-bottom: 3px dashed var(--red);
}

h3 {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: clamp(1.2rem, 2.2vw, 1.55rem);
    margin: 30px 0 14px;
    color: var(--blue);
}

p { font-size: 1.05rem; }
p + p { margin-top: 14px; }

ul, ol { margin-left: 1.2em; }
li { margin: 6px 0; }

/* Ballpoint links with a wavy underline */
a {
    color: var(--blue);
    text-decoration: underline;
    text-decoration-style: wavy;
    text-decoration-thickness: 1.5px;
    text-underline-offset: 3px;
}
a:hover { color: var(--red); }

/* Correction-marker emphasis */
strong { color: var(--red); font-weight: 700; }

/* inline code — a little pencil chip */
:not(pre) > code {
    font-family: 'Fira Code', 'Courier New', monospace;
    background: var(--postit);
    color: var(--ink) !important;
    padding: 1px 8px;
    border-radius: var(--wobbly-sm);
    border: 2px solid var(--ink);
    font-size: 0.9em;
    font-weight: 500;
}

/* ---------- CODE BLOCKS (dark "sticker" taped to the page) ---------- */
pre {
    position: relative;
    background: var(--bg-code) !important;
    border: 3px solid var(--ink);
    border-radius: var(--wobbly-sm);
    padding: 26px !important;
    margin: 26px 0 !important;
    overflow-x: auto;
    font-size: 15px !important;
    line-height: 1.85 !important;
    box-shadow: var(--shadow);
    transform: rotate(-0.4deg);
}

code {
    font-family: 'Fira Code', 'Courier New', monospace !important;
    font-size: 15px !important;
    line-height: 1.85 !important;
}

pre code {
    background: transparent !important;
    padding: 0 !important;
    border: none !important;
    color: #eae6df !important;
    font-weight: 400;
}

/* Prism token palette — legible on charcoal, drawn from the palette */
.token.keyword   { color: var(--red) !important;    font-weight: 700; }
.token.string    { color: var(--yellow) !important; }
.token.function  { color: #7fb2ff !important;        font-weight: 700; }
.token.number    { color: var(--orange) !important; }
.token.operator  { color: #eae6df !important; }
.token.comment   { color: #9a93b5 !important;        font-style: italic; }
.token.class-name{ color: var(--yellow) !important; }
.token.builtin   { color: #7fb2ff !important; }
.token.decorator { color: var(--orange) !important; }

/* ---------- MERMAID DIAGRAMS (pinned sketch) ---------- */
.mermaid {
    background: #ffffff !important;
    padding: 26px !important;
    border: 3px solid var(--ink) !important;
    border-radius: var(--wobbly-md) !important;
    margin: 26px 0 !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    box-shadow: var(--shadow);
    transform: rotate(-0.5deg);
}
/* keep diagrams from eating the whole viewport — scale to fit */
.mermaid svg {
    max-width: 100% !important;
    max-height: 55vh !important;
    width: auto !important;
    height: auto !important;
}

/* index hero has no card frame — drop the tape pseudo there */
.home-header::before { content: none; }

/* ---------- INFO BOXES (post-it notes) ---------- */
.key-insight,
.problem-box,
.solution-box,
.real-world {
    position: relative;
    padding: 22px 26px;
    border: 3px solid var(--ink);
    border-radius: var(--wobbly-sm);
    margin: 26px 0;
    font-size: 1.02rem;
    line-height: 1.7;
    color: var(--ink);
    box-shadow: var(--shadow);
}
/* tape strip on every note */
.key-insight::before,
.problem-box::before,
.solution-box::before,
.real-world::before {
    content: "";
    position: absolute;
    top: -12px;
    left: 24px;
    width: 68px;
    height: 22px;
    transform: rotate(-4deg);
    background: rgba(45, 45, 45, 0.12);
    border: 1px dashed rgba(45, 45, 45, 0.3);
}
.key-insight strong,
.problem-box strong,
.solution-box strong,
.real-world strong { color: var(--ink); }

.key-insight  { background: var(--postit);            transform: rotate(-1deg); }
.problem-box  { background: #ffe3e3;                  transform: rotate(0.8deg);  border-style: dashed; }
.solution-box { background: #e3edf9;                  transform: rotate(-0.6deg); }
.real-world   { background: #fff4d6;                  transform: rotate(0.6deg); }

/* ---------- TABLES ---------- */
table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin: 26px 0;
    background: #ffffff;
    border: 3px solid var(--ink);
    border-radius: var(--wobbly-sm);
    overflow: hidden;
    font-size: 0.98rem;
    box-shadow: var(--shadow);
}
th, td {
    padding: 14px 18px;
    border-bottom: 2px dashed var(--muted);
    text-align: left;
    color: var(--ink);
}
th {
    background: var(--ink);
    font-family: var(--font-heading);
    font-weight: 700;
    color: var(--paper);
    letter-spacing: 0.02em;
}
tr:nth-child(even) td { background: rgba(242, 193, 78, 0.14); }
tr:last-child td { border-bottom: none; }

/* ---------- BUTTONS / NAV ---------- */
.nav-buttons {
    display: flex;
    justify-content: space-between;
    gap: 24px;
    margin-top: 48px;
}

.btn {
    flex: 1;
    padding: 16px 30px;
    border-radius: var(--wobbly-pill);
    text-decoration: none;
    text-align: center;
    font-family: var(--font-body);
    font-weight: 400;
    font-size: 1.25rem;
    color: var(--ink);
    background: #ffffff;
    border: 3px solid var(--ink);
    box-shadow: var(--shadow);
    transition: transform 0.1s ease, box-shadow 0.1s ease, background 0.1s ease, color 0.1s ease;
    will-change: transform;
}

/* Hover: fill accent, shadow shrinks + element nudges down-right ("lift") */
.btn-back:hover,
.btn-next:hover {
    color: #fff;
    box-shadow: 2px 2px 0 0 var(--ink);
    transform: translate(2px, 2px) rotate(-1deg);
}
.btn-back:hover { background: var(--blue); }
.btn-next:hover { background: var(--red); transform: translate(2px, 2px) rotate(1deg); }

.btn-back { border-style: dashed; }

/* Active: presses flat */
.btn:active {
    box-shadow: 0 0 0 0 var(--ink);
    transform: translate(4px, 4px);
}

.btn:focus-visible {
    outline: 3px dashed var(--blue);
    outline-offset: 4px;
}

/* ============================================================
   INDEX PAGE COMPONENTS
   ============================================================ */
.section-title {
    position: relative;
    font-family: var(--font-heading);
    font-weight: 700;
    color: var(--ink);
    font-size: clamp(1.7rem, 4vw, 2.4rem);
    margin: 64px 0 32px;
    text-align: center;
}
/* hand-drawn underline swipe under the label */
.section-title::after {
    content: "";
    display: block;
    width: 160px;
    height: 8px;
    margin: 10px auto 0;
    background: var(--red);
    border-radius: var(--wobbly-pill);
}

.guides-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 34px;
    margin-bottom: 40px;
}

/* Post-it wall: white cards, black wobble border, hard shadow, tilted */
.guide-card {
    position: relative;
    background: #ffffff;
    border: 3px solid var(--ink);
    border-radius: var(--wobbly-md);
    overflow: visible;
    box-shadow: var(--shadow-lg);
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}
/* red thumbtack pinning each card */
.guide-card::before {
    content: "";
    position: absolute;
    top: -12px;
    left: 50%;
    width: 20px;
    height: 20px;
    transform: translateX(-50%);
    background: var(--red);
    border: 2px solid var(--ink);
    border-radius: 50%;
    box-shadow: inset -2px -2px 0 rgba(0, 0, 0, 0.2);
    z-index: 3;
}
/* alternating tilt for a scattered-notes feel */
.guide-card:nth-child(3n+1) { transform: rotate(-1.5deg); }
.guide-card:nth-child(3n+2) { transform: rotate(1deg) translateY(12px); }
.guide-card:nth-child(3n)   { transform: rotate(-0.5deg); }
.guide-card:hover {
    transform: rotate(1deg) translateY(-4px);
    box-shadow: 12px 12px 0 0 var(--ink);
}

/* per-card accent colour, cycled (limited palette) */
.guide-card:nth-child(3n+1) { --card: var(--red); }
.guide-card:nth-child(3n+2) { --card: var(--blue); }
.guide-card:nth-child(3n)   { --card: var(--yellow); }

.guide-header {
    padding: 26px 26px;
    font-family: var(--font-heading);
    font-size: 1.5em;
    font-weight: 700;
    color: var(--ink);
    min-height: 96px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 3px dashed var(--ink);
}

.guide-emoji { font-size: 2.2em; }

.guide-content { padding: 26px; }

.guide-title {
    font-family: var(--font-heading);
    font-size: 1.35em;
    font-weight: 700;
    color: var(--card, var(--red));
    margin-bottom: 12px;
}

.guide-description {
    color: var(--ink);
    line-height: 1.6;
    margin-bottom: 18px;
    font-size: 1.05em;
}

.guide-topics {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 8px;
}

/* sticky-note tags */
.topic-badge {
    background: var(--postit);
    color: var(--ink);
    padding: 5px 14px;
    border-radius: var(--wobbly-sm);
    border: 2px solid var(--ink);
    font-size: 0.9em;
    font-weight: 400;
}
.topic-badge:nth-child(even) { transform: rotate(-2deg); }
.topic-badge:nth-child(odd)  { transform: rotate(1.5deg); }

/* card CTA = button */
.guide-link {
    display: inline-block;
    margin-top: 16px;
    padding: 12px 26px;
    background: #ffffff;
    color: var(--ink);
    text-decoration: none;
    border-radius: var(--wobbly-pill);
    border: 3px solid var(--ink);
    font-family: var(--font-body);
    font-size: 1.15em;
    box-shadow: var(--shadow);
    transition: transform 0.1s ease, box-shadow 0.1s ease, background 0.1s ease, color 0.1s ease;
}
.guide-link:hover {
    background: var(--red);
    color: #fff;
    box-shadow: 2px 2px 0 0 var(--ink);
    transform: translate(2px, 2px) rotate(-1deg);
}
.guide-link:active {
    box-shadow: 0 0 0 0 var(--ink);
    transform: translate(4px, 4px);
}

/* ---------- FOOTER (torn note) ---------- */
.footer {
    position: relative;
    background: var(--postit);
    border: 3px dashed var(--ink);
    border-radius: var(--wobbly-md);
    padding: 44px 48px;
    text-align: center;
    box-shadow: var(--shadow-lg);
    margin-top: 56px;
    transform: rotate(-0.6deg);
}
.footer h2 {
    color: var(--ink);
    margin-bottom: 18px;
    border-bottom: none;
    display: inline-block;
    text-shadow: 2px 2px 0 var(--red);
}
.footer p {
    color: var(--ink);
    line-height: 1.7;
    margin-bottom: 14px;
    font-size: 1.05rem;
}
.footer strong { color: var(--blue); }

/* ============================================================
   ANIMATIONS — gentle, playful
   ============================================================ */
@keyframes float {
    0%, 100% { transform: translateY(0) rotate(-4deg); }
    50%      { transform: translateY(-16px) rotate(4deg); }
}
@keyframes float-reverse {
    0%, 100% { transform: translateY(0) rotate(4deg); }
    50%      { transform: translateY(16px) rotate(-4deg); }
}
@keyframes wiggle {
    0%, 100% { transform: rotate(-6deg); }
    50%      { transform: rotate(6deg); }
}
@keyframes bounce-soft {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-10px); }
}

.animate-float         { animation: float 6s ease-in-out infinite; }
.animate-float-reverse { animation: float-reverse 5s ease-in-out infinite; }
.animate-wiggle        { animation: wiggle 1.4s ease-in-out infinite; }
.animate-pulse-glow    { animation: bounce-soft 3s ease-in-out infinite; }
.animate-spin-slow     { animation: bounce-soft 3s ease-in-out infinite; }

/* Floating doodle emoji */
.deco {
    position: absolute;
    z-index: 1;
    pointer-events: none;
    user-select: none;
    font-size: 2.6rem;
    opacity: 0.95;
    filter: drop-shadow(2px 2px 0 rgba(45, 45, 45, 0.25));
}

/* Massive faint pencil word in the background */
.bg-word {
    position: absolute;
    z-index: 0;
    pointer-events: none;
    font-family: var(--font-heading);
    font-weight: 700;
    text-transform: uppercase;
    font-size: clamp(7rem, 22vw, 16rem);
    line-height: 0.8;
    color: transparent;
    -webkit-text-stroke: 2px rgba(45, 45, 45, 0.08);
    letter-spacing: -0.03em;
    white-space: nowrap;
    transform: rotate(-4deg);
}

/* ============================================================
   RESPONSIVE — keep the sketchy feel, just stack it
   ============================================================ */
@media (max-width: 768px) {
    /* Handwritten fonts (Patrick Hand / Kalam) have a small x-height and thin
       strokes, so 16px reads much smaller than a system font on a phone.
       Scale the whole rem system up so body copy, headings, tables, badges,
       and nav all grow together — then bump the px-locked code blocks. */
    html { font-size: 19px; }

    body { line-height: 1.8; }
    body::after { left: 20px; }
    .container { padding: 28px 16px 60px; }
    header { padding: 34px 24px; transform: rotate(-0.6deg); }
    .content-section { padding: 24px 22px; }

    /* code is px-locked; pre scrolls horizontally so a larger size is safe */
    pre { padding: 18px !important; font-size: 14.5px !important; line-height: 1.7 !important; }
    code { font-size: 14.5px !important; }
    :not(pre) > code { font-size: 0.95em; }

    table { font-size: 1rem; }
    th, td { padding: 12px 14px; }

    .nav-buttons { flex-direction: column; }
    .guide-card:nth-child(3n+2) { transform: rotate(0.5deg); }
    .bg-word { display: none; }
}

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


/* ============================================================
   SITE NAV — cross-collection navigation bar (all pages)
   ============================================================ */
.site-nav {
    position: sticky;
    top: 12px;
    z-index: 100;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px 16px;
    margin-bottom: 36px;
    padding: 12px 20px;
    background: var(--paper);
    border: 3px solid var(--ink);
    border-radius: var(--wobbly-pill);
    box-shadow: var(--shadow);
}
.site-nav a { text-decoration: none; font-family: var(--font-heading); }
.site-nav-home {
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--ink);
    padding: 4px 8px;
    white-space: nowrap;
}
.site-nav-home:hover { color: var(--red); }
.site-nav-links { display: flex; flex-wrap: wrap; gap: 8px; }
.site-nav-links a {
    padding: 6px 15px;
    border: 2px solid var(--ink);
    border-radius: var(--wobbly-sm);
    color: var(--ink);
    background: #fff;
    font-size: 0.98rem;
    white-space: nowrap;
    transition: transform 0.1s ease, background 0.1s ease, color 0.1s ease;
}
.site-nav-links a:hover { background: var(--blue); color: #fff; transform: rotate(-1.5deg); }
.site-nav-links a.active { background: var(--red); color: #fff; }
@media (max-width: 768px) {
    .site-nav { position: static; flex-direction: column; align-items: flex-start; gap: 10px; }
}
