/* =========================================================
   a6c.dev — graffiti dev tutorials
   Palette: burgundy-cream
   #4a0e1b deep burgundy | #2a0a12 blood ink | #e8ddd0 parchment
   #c4493a rust signal  | #3d2024 charcoal   | #ffccd5 blush mist
   #faf8f4 spray white  | #f5efe6 warm cream
   Typography compliance tokens from DESIGN.md: (Google System** System* interactive elements (links Interactions Replace States**: States*: Instead conventional effects (color Interactive IntersectionObserver entry animations: variable
   ========================================================= */

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

html {
    scroll-behavior: smooth;
    background: #2a0a12;
}

body {
    font-family: "IBM Plex Sans", system-ui, sans-serif;
    color: #3d2024;
    background: #2a0a12;
    overflow-x: hidden;
    min-height: 100vh;
    line-height: 1.72;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* -------- Canvas backdrop (fixed, behind everything) -------- */
#particle-canvas {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    z-index: 0;
    pointer-events: none;
    display: block;
}

/* -------- Progress bar (left edge) -------- */
#progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 3px;
    height: 0%;
    background: linear-gradient(180deg, #c4493a 0%, #4a0e1b 100%);
    z-index: 100;
    transition: height 0.12s linear;
    box-shadow: 0 0 8px rgba(196, 73, 58, 0.55);
}

/* -------- Chapter list (slide-in from left) -------- */
#chapter-edge-trigger {
    position: fixed;
    top: 0;
    left: 0;
    width: 18px;
    height: 100vh;
    z-index: 70;
    background: transparent;
}

#chapter-list {
    position: fixed;
    top: 50%;
    left: 0;
    transform: translate(-110%, -50%);
    z-index: 80;
    background: rgba(74, 14, 27, 0.92);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    padding: 1.6rem 1.8rem 1.6rem 2.2rem;
    border-right: 2px solid #c4493a;
    min-width: 260px;
    transition: transform 0.55s cubic-bezier(0.34, 1.56, 0.64, 1);
    color: #f5efe6;
    box-shadow: 8px 0 40px rgba(0, 0, 0, 0.4);
    clip-path: polygon(0 0, 100% 0, 98% 96%, 100% 100%, 0 100%);
}

#chapter-list.visible {
    transform: translate(0, -50%);
}

.chapter-list-header {
    font-family: "Permanent Marker", cursive;
    font-size: 1.4rem;
    color: #ffccd5;
    margin-bottom: 0.9rem;
    letter-spacing: 0.02em;
    text-shadow: 2px 2px 0 rgba(42, 10, 18, 0.6);
}

.chapter-list-items {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}

.chapter-list-items li a {
    display: flex;
    align-items: baseline;
    gap: 0.8rem;
    color: #e8ddd0;
    text-decoration: none;
    font-family: "Space Grotesk", sans-serif;
    font-size: 0.95rem;
    padding: 0.35rem 0.2rem;
    border-bottom: 1px dashed rgba(232, 221, 208, 0.15);
    transition: color 0.25s ease, transform 0.25s ease;
}

.chapter-list-items li a:hover {
    color: #ffccd5;
    transform: translateX(4px);
}

.chapter-list-items .chapter-num {
    font-family: "Permanent Marker", cursive;
    color: #c4493a;
    font-size: 1.05rem;
    min-width: 2.4ch;
}

.chapter-list-items li a.active {
    color: #ffccd5;
}

.chapter-list-items li a.active .chapter-num {
    color: #ffccd5;
}

/* -------- Main scroll stage -------- */
#scroll-stage {
    position: relative;
    z-index: 2;
    width: 100%;
}

/* -------- Chapter sections -------- */
.chapter {
    position: relative;
    width: 100%;
    min-height: 90vh;
    padding: clamp(4rem, 9vh, 8rem) clamp(1.5rem, 6vw, 6rem);
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow: hidden;
    isolation: isolate;
}

.chapter.dark {
    background: linear-gradient(175deg, #4a0e1b 0%, #2a0a12 100%);
    color: #e8ddd0;
}

.chapter.light {
    background: #f5efe6;
    color: #3d2024;
}

.chapter.dark::before,
.chapter.light::before {
    /* paper grain / spray noise overlay */
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: 0.35;
    mix-blend-mode: overlay;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix type='matrix' values='0 0 0 0 0.29  0 0 0 0 0.05  0 0 0 0 0.09  0 0 0 0.6 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
    z-index: 1;
}

.chapter.light::before {
    mix-blend-mode: multiply;
    opacity: 0.18;
}

/* Ghost section numbering */
.ghost-number {
    position: absolute;
    top: 20%;
    right: -2vw;
    font-family: "Permanent Marker", cursive;
    font-size: 20vw;
    line-height: 1;
    color: #4a0e1b;
    opacity: 0.04;
    pointer-events: none;
    user-select: none;
    z-index: 1;
    transform: rotate(-3deg);
    letter-spacing: -0.02em;
}

.chapter.light .ghost-number {
    color: #4a0e1b;
    opacity: 0.055;
}

.chapter.dark .ghost-number {
    color: #ffccd5;
    opacity: 0.05;
}

/* Chapter body */
.chapter-body {
    position: relative;
    z-index: 3;
    max-width: 72ch;
    display: flex;
    flex-direction: column;
    gap: 1.4rem;
}

.chapter-body > * {
    max-width: 62ch;
}

.chapter-body p {
    font-size: clamp(1rem, 1.6vw, 1.15rem);
    line-height: 1.72;
    font-weight: 400;
}

.chapter.dark .chapter-body p { color: #e8ddd0; }
.chapter.light .chapter-body p { color: #3d2024; }

.chapter-body p.lede {
    font-size: clamp(1.1rem, 2vw, 1.35rem);
    line-height: 1.6;
    font-weight: 500;
}

.chapter-body em {
    font-style: italic;
    color: #c4493a;
    font-weight: 500;
}

.chapter.dark em { color: #ffccd5; }

/* -------- Subheadings (kicker) -------- */
.subhead {
    font-family: "Space Grotesk", sans-serif;
    font-size: clamp(0.9rem, 1.4vw, 1.1rem);
    letter-spacing: 0.18em;
    text-transform: uppercase;
    font-variation-settings: "wght" 400;
    font-weight: 400;
    color: #c4493a;
    transition: font-variation-settings 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                font-weight 0.6s ease;
    display: inline-block;
    padding-bottom: 0.2rem;
    border-bottom: 2px solid rgba(196, 73, 58, 0.3);
}

.chapter.dark .subhead { color: #ffccd5; border-bottom-color: rgba(255, 204, 213, 0.3); }

.subhead.in-view {
    font-variation-settings: "wght" 700;
    font-weight: 700;
}

/* -------- Headlines -------- */
.headline {
    font-family: "Permanent Marker", cursive;
    font-size: clamp(2.8rem, 7vw, 6.5rem);
    line-height: 0.95;
    letter-spacing: 0;
    font-weight: 400;
    margin: 0.2em 0 0.4em;
    text-shadow: 2px 2px 0 rgba(74, 14, 27, 0.3);
    transform: translateX(-40px) rotate(-3deg);
    opacity: 0;
    transition: transform 0.7s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                opacity 0.7s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.chapter.dark .headline {
    color: #f5efe6;
    text-shadow: 3px 3px 0 rgba(42, 10, 18, 0.7), 0 0 20px rgba(255, 204, 213, 0.12);
}

.chapter.light .headline {
    color: #4a0e1b;
    text-shadow: 3px 3px 0 rgba(74, 14, 27, 0.15);
}

.headline.in-view {
    transform: translateX(0) rotate(0);
    opacity: 1;
}

/* -------- Mural (opening) -------- */
.chapter.mural {
    background: linear-gradient(175deg, #4a0e1b 0%, #2a0a12 100%);
    color: #f5efe6;
    min-height: 100vh;
    padding: clamp(2rem, 5vh, 4rem) clamp(1.5rem, 6vw, 6rem);
    justify-content: space-between;
}

.mural-inner {
    position: relative;
    z-index: 3;
    display: grid;
    grid-template-rows: 1fr auto auto;
    gap: 2rem;
    height: 100%;
    min-height: 88vh;
}

#logo-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 60vh;
    pointer-events: none;
    z-index: 1;
}

.mural-tagline {
    position: relative;
    z-index: 3;
    align-self: end;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    max-width: 48ch;
}

.tag-kicker {
    font-family: "IBM Plex Mono", monospace;
    font-size: clamp(0.8rem, 1.2vw, 0.95rem);
    letter-spacing: 0.1em;
    color: #c4493a;
    text-transform: lowercase;
}

.mural-title {
    font-family: "Permanent Marker", cursive;
    font-size: clamp(4rem, 14vw, 11rem);
    line-height: 0.9;
    color: #f5efe6;
    text-shadow: 4px 4px 0 rgba(196, 73, 58, 0.45),
                 8px 8px 0 rgba(42, 10, 18, 0.6),
                 0 0 40px rgba(255, 204, 213, 0.18);
    transform: rotate(-2deg);
    margin-bottom: 0.1em;
}

.mural-sub {
    font-family: "Space Grotesk", sans-serif;
    font-size: clamp(1rem, 1.8vw, 1.3rem);
    color: #e8ddd0;
    line-height: 1.5;
    max-width: 44ch;
    letter-spacing: 0.01em;
}

.chevron {
    position: relative;
    z-index: 3;
    align-self: center;
    justify-self: center;
    margin-top: 1rem;
    animation: chevronPulse 1.8s cubic-bezier(0.34, 1.56, 0.64, 1) infinite;
}

@keyframes chevronPulse {
    0%, 100% { transform: translateY(0); opacity: 0.7; }
    50%      { transform: translateY(10px); opacity: 1; }
}

/* -------- Magnetic links / buttons -------- */
.magnetic-row {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem 1.4rem;
    margin: 0.4rem 0;
}

.magnetic-row.center {
    justify-content: center;
}

.magnetic-link,
.magnetic-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-family: "Space Grotesk", sans-serif;
    font-size: clamp(0.95rem, 1.4vw, 1.1rem);
    font-weight: 600;
    padding: 0.75rem 1.3rem;
    text-decoration: none;
    color: #faf8f4;
    background: #c4493a;
    border: 2px solid #c4493a;
    border-radius: 2px;
    cursor: pointer;
    letter-spacing: 0.02em;
    transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                background-color 0.25s ease,
                color 0.25s ease;
    position: relative;
    will-change: transform;
    clip-path: polygon(
        0 6%, 8% 0, 92% 3%, 100% 0,
        98% 40%, 100% 70%, 97% 100%,
        60% 97%, 20% 100%, 0 96%
    );
}

.chapter.light .magnetic-link,
.chapter.light .magnetic-btn {
    color: #faf8f4;
    background: #4a0e1b;
    border-color: #4a0e1b;
}

.magnetic-link.ghost,
.magnetic-btn.ghost {
    background: transparent;
    color: #c4493a;
    border-color: #c4493a;
}

.chapter.dark .magnetic-link.ghost,
.chapter.dark .magnetic-btn.ghost {
    color: #ffccd5;
    border-color: #ffccd5;
}

.magnetic-link.big {
    font-size: clamp(1.05rem, 1.6vw, 1.25rem);
    padding: 1rem 1.6rem;
}

.magnetic-link::after,
.magnetic-btn::after {
    content: "↗";
    font-family: "IBM Plex Mono", monospace;
    font-size: 0.95em;
    display: inline-block;
    transition: transform 0.25s ease;
}

.magnetic-btn::after { content: "•"; }

.magnetic-link:hover::after {
    transform: translate(3px, -3px);
}

.magnetic-link.clicked,
.magnetic-btn.clicked {
    animation: clickPulse 0.18s ease-out;
}

@keyframes clickPulse {
    0%   { transform: scale(1); }
    50%  { transform: scale(1.05); }
    100% { transform: scale(1); }
}

/* -------- Code blocks as graffiti tags -------- */
.code-wrap {
    position: relative;
    background: #2a0a12;
    padding: 2rem 1.8rem 2.4rem;
    margin: 1.2rem 0 2.2rem;
    max-width: 72ch;
    transform: rotate(-0.8deg);
    transition: transform 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                filter 0.6s ease,
                opacity 0.6s ease;
    filter: blur(4px);
    opacity: 0;
    box-shadow: 0 8px 0 rgba(196, 73, 58, 0.15),
                0 20px 40px rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(255, 204, 213, 0.08);
    will-change: transform, filter;
    clip-path: polygon(
        0 2%, 4% 0, 40% 1%, 60% 0, 96% 2%, 100% 0,
        100% 98%, 96% 100%, 40% 98%, 20% 100%, 4% 99%, 0 100%
    );
}

.code-wrap.in-view {
    filter: blur(0);
    opacity: 1;
}

.code-wrap::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='p'><feTurbulence type='fractalNoise' baseFrequency='1.2' numOctaves='2' stitchTiles='stitch'/><feColorMatrix type='matrix' values='0 0 0 0 1  0 0 0 0 0.8  0 0 0 0 0.83  0 0 0 0.35 0'/></filter><rect width='100%25' height='100%25' filter='url(%23p)'/></svg>");
    opacity: 0.25;
    mix-blend-mode: screen;
}

.code-tag {
    position: absolute;
    top: -14px;
    left: 1.2rem;
    font-family: "IBM Plex Mono", monospace;
    font-size: 0.8rem;
    background: #c4493a;
    color: #faf8f4;
    padding: 0.25rem 0.7rem;
    letter-spacing: 0.05em;
    transform: rotate(-1.4deg);
    z-index: 2;
    box-shadow: 2px 2px 0 rgba(42, 10, 18, 0.5);
}

.code-block {
    font-family: "IBM Plex Mono", monospace;
    font-size: clamp(0.85rem, 1.4vw, 1rem);
    line-height: 1.65;
    color: #ffccd5;
    white-space: pre;
    overflow-x: auto;
    position: relative;
    z-index: 2;
    font-weight: 400;
}

.code-block code {
    font-family: inherit;
    color: inherit;
}

.tk-kw  { color: #c4493a; font-weight: 500; }
.tk-fn  { color: #ffccd5; font-weight: 500; }
.tk-str { color: #e8ddd0; }
.tk-num { color: #faf8f4; font-weight: 500; }
.tk-var { color: #ffccd5; }
.tk-br  { color: #c4493a; opacity: 0.75; }

.inline-code {
    font-family: "IBM Plex Mono", monospace;
    background: rgba(42, 10, 18, 0.9);
    color: #ffccd5;
    padding: 0.12em 0.45em;
    font-size: 0.92em;
    border-radius: 2px;
    border: 1px solid rgba(196, 73, 58, 0.35);
}

.chapter.light .inline-code {
    background: #2a0a12;
    color: #ffccd5;
}

/* -------- Paint drips below code blocks -------- */
.drip-layer {
    position: absolute;
    left: 0;
    right: 0;
    bottom: -1px;
    height: 40px;
    pointer-events: none;
    z-index: 2;
}

.drip {
    position: absolute;
    top: 0;
    width: 4px;
    height: 0;
    background: linear-gradient(180deg, #2a0a12 0%, #2a0a12 65%, rgba(42, 10, 18, 0) 100%);
    border-radius: 0 0 50% 50%;
    transition: height 0.9s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.drip:nth-child(1) { width: 5px; transition-delay: 0.05s; --h: 32px; }
.drip:nth-child(2) { width: 3px; transition-delay: 0.2s;  --h: 18px; }
.drip:nth-child(3) { width: 6px; transition-delay: 0.12s; --h: 40px; }
.drip:nth-child(4) { width: 4px; transition-delay: 0.3s;  --h: 24px; }
.drip:nth-child(5) { width: 3px; transition-delay: 0.18s; --h: 15px; }

.code-wrap.in-view .drip { height: var(--h); }

/* -------- Stickers / pull quotes -------- */
.sticker {
    position: relative;
    background: #4a0e1b;
    color: #f5efe6;
    padding: 1.4rem 1.6rem;
    font-family: "Permanent Marker", cursive;
    font-size: clamp(1.1rem, 2vw, 1.5rem);
    line-height: 1.35;
    margin: 1.2rem 0;
    max-width: 56ch;
    transform: rotate(-2deg);
    box-shadow: 4px 6px 0 rgba(42, 10, 18, 0.45);
    clip-path: polygon(
        2% 6%, 8% 0, 30% 4%, 60% 1%, 92% 5%, 100% 0,
        98% 50%, 100% 94%, 95% 100%, 70% 97%, 30% 100%, 8% 98%, 0 92%
    );
    letter-spacing: 0.01em;
}

.sticker::before {
    content: "";
    position: absolute;
    top: 6px;
    left: 8px;
    right: 6px;
    bottom: 8px;
    border: 1px dashed rgba(255, 204, 213, 0.3);
    pointer-events: none;
    clip-path: inherit;
}

.sticker.alt {
    background: #c4493a;
    color: #faf8f4;
    transform: rotate(1.4deg);
}

.sticker.sign {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    transform: rotate(-1deg);
    font-size: clamp(1.3rem, 2.5vw, 1.8rem);
    padding: 1.6rem 2rem;
}

.sign-line {
    display: block;
    color: #ffccd5;
}

.sign-sub {
    font-family: "IBM Plex Mono", monospace;
    font-size: 0.55em;
    color: #e8ddd0;
    letter-spacing: 0.1em;
    text-transform: lowercase;
}

/* -------- Graffiti list -------- */
.graffiti-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
    max-width: 62ch;
    margin: 0.6rem 0;
}

.graffiti-list li {
    display: flex;
    gap: 0.7rem;
    align-items: baseline;
    line-height: 1.55;
    font-size: clamp(0.98rem, 1.6vw, 1.12rem);
}

.graffiti-list .bullet {
    color: #c4493a;
    font-family: "Permanent Marker", cursive;
    font-size: 1.2em;
    flex-shrink: 0;
    transform: translateY(1px);
}

.chapter.dark .graffiti-list .bullet { color: #ffccd5; }

/* -------- Rule lines (hand-drawn) -------- */
.rule-line {
    display: block;
    width: 100%;
    max-width: 62ch;
    height: 14px;
    margin-top: 1.4rem;
    opacity: 0.6;
}

.chapter.dark .rule-line path { stroke: #ffccd5; opacity: 0.55; }
.chapter.light .rule-line path { stroke: #c4493a; }

/* -------- Torn edges between sections -------- */
.torn-edge {
    position: absolute;
    left: 0;
    right: 0;
    bottom: -1px;
    height: 22px;
    z-index: 4;
    pointer-events: none;
}

.torn-bottom-dark {
    background: #f5efe6;
    clip-path: polygon(
        0 100%, 0 30%, 3% 70%, 6% 20%, 10% 85%, 14% 40%, 18% 75%,
        22% 15%, 27% 80%, 32% 35%, 37% 90%, 42% 25%, 47% 70%,
        52% 30%, 57% 85%, 62% 20%, 67% 75%, 72% 30%, 77% 85%,
        82% 40%, 87% 75%, 92% 25%, 96% 80%, 100% 35%, 100% 100%
    );
}

.torn-bottom-cream {
    background: linear-gradient(175deg, #4a0e1b 0%, #2a0a12 100%);
    clip-path: polygon(
        0 100%, 0 30%, 3% 70%, 6% 20%, 10% 85%, 14% 40%, 18% 75%,
        22% 15%, 27% 80%, 32% 35%, 37% 90%, 42% 25%, 47% 70%,
        52% 30%, 57% 85%, 62% 20%, 67% 75%, 72% 30%, 77% 85%,
        82% 40%, 87% 75%, 92% 25%, 96% 80%, 100% 35%, 100% 100%
    );
}

/* -------- Body paragraph reveal animation -------- */
.chapter-body p,
.chapter-body ul,
.chapter-body .code-wrap,
.chapter-body .sticker,
.chapter-body .magnetic-row,
.chapter-body .rule-line {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.7s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                transform 0.7s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.chapter-body.revealed p,
.chapter-body.revealed ul,
.chapter-body.revealed .sticker,
.chapter-body.revealed .magnetic-row,
.chapter-body.revealed .rule-line {
    opacity: 1;
    transform: translateY(0);
}

.chapter-body.revealed p:nth-child(1) { transition-delay: 0.05s; }
.chapter-body.revealed p:nth-child(2) { transition-delay: 0.15s; }
.chapter-body.revealed p:nth-child(3) { transition-delay: 0.25s; }
.chapter-body.revealed p:nth-child(4) { transition-delay: 0.35s; }
.chapter-body.revealed p:nth-child(5) { transition-delay: 0.45s; }
.chapter-body.revealed ul { transition-delay: 0.4s; }
.chapter-body.revealed .sticker { transition-delay: 0.35s; }
.chapter-body.revealed .magnetic-row { transition-delay: 0.45s; }
.chapter-body.revealed .rule-line { transition-delay: 0.55s; }

/* Code block intro animation handled via .code-wrap.in-view already;
   keep wrapper reveal consistent */
.chapter-body .code-wrap {
    transform: rotate(-0.8deg) translateY(30px);
}
.chapter-body.revealed .code-wrap.in-view {
    transform: rotate(-0.8deg) translateY(0);
    opacity: 1;
}

/* Selection */
::selection {
    background: #c4493a;
    color: #faf8f4;
}

/* Scrollbar (subtle) */
::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-track { background: #2a0a12; }
::-webkit-scrollbar-thumb {
    background: #4a0e1b;
    border-radius: 4px;
    border: 2px solid #2a0a12;
}
::-webkit-scrollbar-thumb:hover { background: #c4493a; }

/* -------- Responsive tuning -------- */
@media (max-width: 720px) {
    .chapter {
        padding: 4rem 1.2rem;
        min-height: auto;
    }
    .ghost-number { font-size: 28vw; top: 3%; right: -6vw; }
    .code-wrap { transform: rotate(-0.4deg); padding: 1.6rem 1.2rem 2rem; }
    .mural-title { font-size: clamp(3rem, 18vw, 7rem); }
    .sticker { font-size: 1.1rem; }
    #chapter-list { min-width: 220px; padding: 1.2rem 1.4rem; }
}

@media (prefers-reduced-motion: reduce) {
    * { animation-duration: 0.001s !important; transition-duration: 0.001s !important; }
    .chevron { animation: none; }
}
