/* paper kit: the site. Components live in paper.css, the phone in phone.css. */
:root {
    --paper: #f4ecde;
    --sheet: 251, 247, 239;
    --ink: #211e19;
    --muted: #6b6256;
    --faint: #9d9386;
    --rule: #d8cebc;
    --accent: #8e7d67;
    --primary: #322d26;
    --on-primary: #f4ecde;
    --red: #b8432f;
    --blue: #3f5d7d;
    --note: #f3e3b5;
    --amber: #b37b26;
    --green: #567849;
    --plum: #7a4b6b;
    --rust: #93522a;
    --teal: #2b6e69;
    --tab-ink: #fff8ee;
    --bar: rgba(232, 220, 199, 0.9);
    --tape: rgba(201, 189, 167, 0.62);
    --shadow: 40, 26, 14;
    --texture: url('assets/handmade-paper.jpg');
    --veil: rgba(244, 236, 222, 0);
    --ruled: rgba(63, 93, 125, 0.12);
    --margin-line: rgba(184, 67, 47, 0.32);
    --code-key: #7a4b6b;
    --code-type: #2b6e69;
    --code-string: #93522a;
    --code-number: #b37b26;
    --code-comment: #9d9386;
    --sans: 'Montserrat', system-ui, sans-serif;
    --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
    color-scheme: light;
}

:root[data-theme='dark'] {
    --paper: #171512;
    --sheet: 33, 31, 27;
    --ink: #f8f3ea;
    --muted: #b9b0a2;
    --faint: #81786c;
    --rule: #4b463e;
    --accent: #c9bda7;
    --primary: #f3eadb;
    --on-primary: #171512;
    --red: #e0715c;
    --blue: #8fb0d6;
    --note: #4a4130;
    --amber: #d9a54b;
    --green: #93b683;
    --plum: #be92b1;
    --rust: #d58d59;
    --teal: #6db5ae;
    --tab-ink: #17140f;
    --bar: rgba(23, 21, 18, 0.9);
    --tape: rgba(201, 189, 167, 0.28);
    --shadow: 0, 0, 0;
    --texture: url('assets/dark-handmade-paper-1040.jpg');
    --veil: rgba(23, 21, 18, 0.38);
    --ruled: rgba(143, 176, 214, 0.1);
    --margin-line: rgba(224, 113, 92, 0.32);
    --code-key: #be92b1;
    --code-type: #6db5ae;
    --code-string: #d58d59;
    --code-number: #d9a54b;
    --code-comment: #81786c;
    color-scheme: dark;
}

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

/* clip, not hidden: nothing that flies off a widget (a torn stub, a paper plane) may
   widen the page, or phones zoom out to fit it. */
html,
body {
    overflow-x: clip;
}

html {
    scroll-behavior: smooth;
    scroll-padding-top: 80px;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    background-color: var(--paper);
    background-image: linear-gradient(var(--veil), var(--veil)), var(--texture);
    background-size: 100% 100%, 520px auto;
    color: var(--ink);
    font-family: var(--sans);
    font-size: 16px;
    line-height: 1.6;
}

a {
    color: inherit;
}

img,
svg {
    display: block;
}

button {
    color: inherit;
    font: inherit;
}

:focus-visible {
    border-radius: 4px;
    outline: 2px solid var(--primary);
    outline-offset: 3px;
}

.visually-hidden {
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    height: 1px;
    overflow: hidden;
    position: absolute;
    white-space: nowrap;
    width: 1px;
}

.defs {
    height: 0;
    position: absolute;
    width: 0;
}

/* Top bar */
.topbar {
    align-items: center;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    background: var(--bar);
    border-bottom: 1px solid var(--rule);
    display: flex;
    gap: 1rem;
    justify-content: space-between;
    padding: 0.65rem max(1.25rem, calc((100vw - 1180px) / 2));
    position: sticky;
    top: 0;
    z-index: 40;
}

.brand {
    align-items: center;
    display: flex;
    gap: 0.5rem;
    text-decoration: none;
}

.brand-mark {
    flex: none;
    height: 40px;
    width: 40px;
}

.brand-mark img {
    height: 100%;
    width: 100%;
}

:root[data-theme='dark'] .brand-mark img {
    filter: invert(1) brightness(1.2);
}

.brand-wordmark {
    color: var(--primary);
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    line-height: 1;
}

.brand-wordmark em {
    color: var(--accent);
    font-style: normal;
    font-weight: 600;
}

.nav {
    align-items: center;
    display: flex;
}

.nav-link {
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    padding: 0.5rem 0.85rem;
    position: relative;
    text-decoration: none;
    transition: color 0.3s ease;
}

.nav-link::after {
    background: var(--primary);
    bottom: 0.2rem;
    content: '';
    height: 2px;
    left: 50%;
    position: absolute;
    transform: translateX(-50%);
    transition: width 0.3s ease;
    width: 0;
}

.nav-link:hover {
    color: var(--primary);
}

.nav-link:hover::after {
    width: 70%;
}

.theme-toggle {
    align-items: center;
    background: transparent;
    border: 0;
    border-left: 1px solid var(--rule);
    color: var(--muted);
    cursor: pointer;
    display: inline-flex;
    font-size: 0.9rem;
    font-weight: 700;
    gap: 0.5rem;
    letter-spacing: 0.5px;
    margin-left: 0.5rem;
    padding: 0.5rem 0 0.5rem 1.1rem;
    transition: color 0.3s ease;
}

.theme-toggle:hover {
    color: var(--primary);
}

.theme-toggle-dot {
    background: linear-gradient(90deg, currentColor 50%, transparent 50%);
    border: 2px solid currentColor;
    border-radius: 50%;
    display: inline-block;
    height: 0.8rem;
    transition: transform 0.4s cubic-bezier(0.645, 0.045, 0.355, 1);
    width: 0.8rem;
}

:root[data-theme='dark'] .theme-toggle-dot {
    transform: rotate(180deg);
}

/* The page turns dark as an ink blot spreading from the toggle (kit.js drives the clip). */
::view-transition-old(root),
::view-transition-new(root) {
    animation: none;
    mix-blend-mode: normal;
}

::view-transition-new(root) {
    z-index: 2;
}

/* Index tabs down the right edge: one per chapter, like the journal's. */
.chapter-tabs {
    display: flex;
    flex-direction: column;
    gap: 6px;
    position: fixed;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    z-index: 30;
}

.chapter-tab {
    align-items: center;
    background: var(--tone);
    border-radius: 8px 0 0 8px;
    box-shadow: -3px 4px 10px -6px rgba(var(--shadow), 0.55);
    color: var(--tab-ink);
    display: flex;
    font-size: 0.68rem;
    font-weight: 700;
    height: 76px;
    justify-content: center;
    letter-spacing: 0.08em;
    opacity: 0.82;
    text-decoration: none;
    transform: translateX(8px);
    transition: transform 0.3s cubic-bezier(0.215, 0.61, 0.355, 1), opacity 0.3s ease;
    width: 30px;
    writing-mode: vertical-rl;
}

.chapter-tab:hover,
.chapter-tab.is-active {
    opacity: 1;
    transform: none;
}

/* Hero */
.hero {
    padding: 4.5rem 1.25rem 3rem;
    position: relative;
}

.hero-sheet {
    background-color: rgb(var(--sheet));
    background-image: linear-gradient(rgba(var(--sheet), 0.84), rgba(var(--sheet), 0.84)), var(--texture);
    background-size: 100% 100%, 520px auto;
    filter: drop-shadow(0 22px 26px rgba(var(--shadow), 0.18)) drop-shadow(0 2px 2px rgba(var(--shadow), 0.08));
    margin: 0 auto;
    max-width: 1180px;
    padding: 4.5rem clamp(1.5rem, 6vw, 5rem) 6rem;
    position: relative;
}

.hero-sheet-paper {
    background: inherit;
    inset: 0;
    position: absolute;
    z-index: -1;
}

.kicker {
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.hero-title {
    display: flex;
    flex-wrap: wrap;
    font-size: clamp(4.2rem, 15vw, 12.5rem);
    font-weight: 800;
    gap: 0 0.02em;
    letter-spacing: -0.04em;
    line-height: 0.92;
    margin: 1.4rem 0 1.8rem -0.04em;
    user-select: none;
}

.hero-word {
    display: flex;
    margin-right: 0.22em;
}

/* Each letter is a paper cut-out lying on the sheet; it lifts when you reach for it. */
.cutout {
    display: inline-block;
    transition: transform 0.25s cubic-bezier(0.215, 0.61, 0.355, 1);
}

.cutout span {
    display: block;
    filter: drop-shadow(0.02em 0.04em 0 rgba(var(--shadow), 0.14));
    transition: filter 0.25s ease;
}

.cutout:hover {
    transform: translateY(-0.04em) rotate(-1.5deg);
}

.cutout:hover span {
    filter: drop-shadow(0.03em 0.08em 0.02em rgba(var(--shadow), 0.2));
}

.hero-lede {
    color: var(--muted);
    font-size: clamp(1.05rem, 2vw, 1.3rem);
    font-weight: 500;
    line-height: 1.55;
    max-width: 34em;
}

.hero-lede strong {
    color: var(--ink);
    font-weight: 700;
}

.hero-actions {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 1rem 1.6rem;
    margin-top: 2.2rem;
}

.install-chip {
    align-items: center;
    background: var(--primary);
    border: 0;
    border-radius: 10px;
    box-shadow: 0 14px 26px -16px rgba(var(--shadow), 0.8);
    color: var(--on-primary);
    cursor: pointer;
    display: inline-flex;
    font-family: var(--mono);
    font-size: 0.95rem;
    gap: 0.75rem;
    padding: 0.85rem 1.1rem 0.85rem 1.25rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.install-chip:hover {
    box-shadow: 0 18px 30px -16px rgba(var(--shadow), 0.9);
    transform: translateY(-2px);
}

.install-chip .prompt {
    opacity: 0.55;
}

.install-chip .copy {
    border-left: 1px solid color-mix(in srgb, var(--on-primary) 30%, transparent);
    font-family: var(--sans);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    padding-left: 0.75rem;
}

.text-link {
    color: var(--ink);
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-decoration: underline;
    text-decoration-color: var(--rule);
    text-decoration-thickness: 2px;
    text-underline-offset: 5px;
}

.text-link:hover {
    text-decoration-color: var(--primary);
}

.hero-notes {
    bottom: 3.25rem;
    display: flex;
    gap: 1.25rem;
    position: absolute;
    right: clamp(1rem, 5vw, 4.5rem);
    transform: rotate(3deg);
}

.hero-stats {
    color: var(--muted);
    display: flex;
    flex-wrap: wrap;
    font-size: 0.8rem;
    font-weight: 600;
    gap: 0.4rem 1.6rem;
    margin-top: 2.6rem;
}

.hero-stats li {
    align-items: center;
    display: flex;
    gap: 0.5rem;
    list-style: none;
}

.hero-stats li::before {
    background: var(--accent);
    border-radius: 50%;
    content: '';
    height: 6px;
    width: 6px;
}

/* Chapters and spreads */
.chapter {
    margin: 0 auto;
    max-width: 1180px;
    padding: 4.5rem 1.25rem 1rem;
}

.chapter-head {
    align-items: end;
    border-bottom: 2px solid var(--ink);
    display: grid;
    gap: 0.25rem 2rem;
    grid-template-columns: auto minmax(0, 1fr);
    margin-bottom: 2.5rem;
    padding-bottom: 1rem;
}

.chapter-no {
    color: var(--tone);
    font-size: 0.85rem;
    font-weight: 800;
    grid-column: 1 / -1;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.chapter-title {
    font-size: clamp(2.6rem, 7vw, 4.6rem);
    font-weight: 800;
    letter-spacing: -0.035em;
    line-height: 0.95;
}

.chapter-blurb {
    color: var(--muted);
    font-size: 1rem;
    font-weight: 500;
    justify-self: end;
    max-width: 30em;
    padding-bottom: 0.3rem;
}

/* A component is an open notebook: the demo on the left page, the Dart on the right. */
.spread {
    border-radius: 6px;
    box-shadow:
        0 1px 1px rgba(var(--shadow), 0.06),
        0 26px 50px -30px rgba(var(--shadow), 0.5),
        0 10px 20px -16px rgba(var(--shadow), 0.3);
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    margin-bottom: 3rem;
    position: relative;
}

.spread-page {
    background-color: rgb(var(--sheet));
    background-image: linear-gradient(rgba(var(--sheet), 0.86), rgba(var(--sheet), 0.86)), var(--texture);
    background-size: 100% 100%, 520px auto;
    min-width: 0;
    position: relative;
}

.spread-demo {
    border-radius: 6px 0 0 6px;
    display: flex;
    flex-direction: column;
    padding: 2rem 2.25rem 2.25rem;
}

/* The gutter: each page darkens toward the binding. */
.spread-demo::after,
.spread-code::before {
    bottom: 0;
    content: '';
    pointer-events: none;
    position: absolute;
    top: 0;
    width: 46px;
}

.spread-demo::after {
    background: linear-gradient(90deg, transparent, rgba(var(--shadow), 0.1) 80%, rgba(var(--shadow), 0.18));
    right: 0;
}

.spread-code::before {
    background: linear-gradient(270deg, transparent, rgba(var(--shadow), 0.08) 80%, rgba(var(--shadow), 0.16));
    left: 0;
    z-index: 1;
}

.spec-top {
    align-items: baseline;
    display: flex;
    gap: 0.75rem;
}

.spec-no {
    color: var(--tone);
    font-family: var(--mono);
    font-size: 0.8rem;
    font-weight: 500;
}

.spec-name {
    font-size: 1.45rem;
    font-weight: 800;
    letter-spacing: -0.01em;
    line-height: 1.2;
}

.spec-desc {
    color: var(--muted);
    font-size: 0.95rem;
    font-weight: 500;
    margin-top: 0.35rem;
    max-width: 32em;
}

.spec-widget {
    color: var(--faint);
    font-family: var(--mono);
    font-size: 0.75rem;
    margin-top: 0.15rem;
}

.stage {
    align-items: center;
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 1.25rem;
    justify-content: center;
    margin-top: 1.75rem;
    min-height: 260px;
    position: relative;
}

.stage-row {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 1.25rem;
    justify-content: center;
}

.stage-hint {
    color: var(--faint);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.04em;
}

.stage-button {
    background: none;
    border: 0;
    color: var(--muted);
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-decoration: underline;
    text-decoration-color: var(--rule);
    text-decoration-thickness: 1.5px;
    text-underline-offset: 4px;
}

.stage-button:hover {
    color: var(--primary);
}

/* The code page: ruled notebook paper with a red margin, the line numbers outside it. */
.spread-code {
    border-radius: 0 6px 6px 0;
    display: flex;
    flex-direction: column;
    min-height: 100%;
}

.code-head {
    align-items: center;
    display: flex;
    gap: 0.5rem;
    justify-content: space-between;
    padding: 1.1rem 1.25rem 0.4rem 3.4rem;
    position: relative;
    z-index: 2;
}

.code-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.code-tab {
    background: transparent;
    border: 1px solid var(--rule);
    border-radius: 999px;
    color: var(--muted);
    cursor: pointer;
    font-family: var(--mono);
    font-size: 0.72rem;
    padding: 0.18rem 0.65rem;
}

.code-tab[aria-selected='true'] {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--on-primary);
}

.code-copy {
    background: transparent;
    border: 0;
    color: var(--muted);
    cursor: pointer;
    flex: none;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    padding: 0.2rem 0.1rem;
}

.code-copy:hover {
    color: var(--primary);
}

.code {
    --line: 1.75em;
    background-image:
        linear-gradient(90deg, transparent 2.75rem, var(--margin-line) 2.75rem, var(--margin-line) calc(2.75rem + 1px), transparent calc(2.75rem + 1px)),
        repeating-linear-gradient(180deg, transparent 0 calc(var(--line) - 1px), var(--ruled) calc(var(--line) - 1px) var(--line));
    background-attachment: local;
    background-position: 0 0, 0 0.55rem;
    counter-reset: line;
    flex: 1;
    font-family: var(--mono);
    font-size: 0.78rem;
    line-height: var(--line);
    overflow-x: auto;
    padding: 0.55rem 1.25rem 1.6rem 0;
    position: relative;
    tab-size: 2;
    white-space: pre;
}

.code-line {
    display: block;
    min-height: var(--line);
    padding-left: 3.4rem;
    position: relative;
}

.code-line::before {
    color: var(--faint);
    content: counter(line);
    counter-increment: line;
    font-size: 0.68rem;
    left: 0;
    position: absolute;
    text-align: right;
    width: 2.15rem;
}

.tok-key {
    color: var(--code-key);
    font-weight: 500;
}

.tok-type {
    color: var(--code-type);
}

.tok-string {
    color: var(--code-string);
}

.tok-number {
    color: var(--code-number);
}

.tok-comment {
    color: var(--code-comment);
    font-style: italic;
}

.tok-param {
    color: var(--muted);
}

/* Phone chapter */
.phone-spread {
    grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
}

.phone-stage {
    min-height: 720px;
}

/* Install chapter */
.install-grid {
    display: grid;
    gap: 1.5rem;
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.install-step {
    background-color: rgb(var(--sheet));
    background-image: linear-gradient(rgba(var(--sheet), 0.86), rgba(var(--sheet), 0.86)), var(--texture);
    background-size: 100% 100%, 520px auto;
    border-radius: 6px;
    box-shadow: 0 18px 36px -26px rgba(var(--shadow), 0.5);
    padding: 1.5rem 1.5rem 1.25rem;
}

.install-step h3 {
    font-size: 1.05rem;
    font-weight: 800;
    margin-top: 0.35rem;
}

.install-step p {
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 500;
    margin-top: 0.35rem;
}

.install-step pre {
    background: rgba(var(--shadow), 0.05);
    border-radius: 6px;
    font-family: var(--mono);
    font-size: 0.78rem;
    margin-top: 0.9rem;
    overflow-x: auto;
    padding: 0.75rem 0.9rem;
}

.swatches {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    margin-top: 2.5rem;
}

.swatch {
    background: transparent;
    border: 0;
    cursor: pointer;
    text-align: left;
}

.swatch-chip {
    aspect-ratio: 4 / 3;
    background: var(--chip);
    border-radius: 4px;
    box-shadow: inset 0 0 0 1px rgba(var(--shadow), 0.12), 0 10px 18px -14px rgba(var(--shadow), 0.7);
    display: block;
    transition: transform 0.25s cubic-bezier(0.215, 0.61, 0.355, 1);
}

.swatch:hover .swatch-chip {
    transform: translateY(-3px) rotate(-1.5deg);
}

.swatch-name {
    display: block;
    font-size: 0.8rem;
    font-weight: 700;
    margin-top: 0.5rem;
}

.swatch-hex {
    color: var(--muted);
    display: block;
    font-family: var(--mono);
    font-size: 0.72rem;
}

.site-foot {
    align-items: center;
    color: var(--muted);
    display: flex;
    flex-direction: column;
    font-size: 0.85rem;
    font-weight: 600;
    gap: 0.9rem;
    padding: 4rem 1.25rem calc(3rem + env(safe-area-inset-bottom));
    text-align: center;
}

.site-foot nav {
    display: flex;
    flex-wrap: wrap;
    font-weight: 700;
    gap: 0.5rem 1.6rem;
    justify-content: center;
    letter-spacing: 0.5px;
}

.site-foot a {
    text-decoration: none;
}

.site-foot a:hover {
    color: var(--primary);
}

.site-foot .brand-mark {
    height: 32px;
    width: 32px;
}

@media (max-width: 1100px) {
    .chapter-tabs {
        display: none;
    }
}

@media (max-width: 900px) {
    .spread,
    .phone-spread {
        grid-template-columns: minmax(0, 1fr);
    }

    .spread-demo {
        border-radius: 6px 6px 0 0;
    }

    .spread-code {
        border-radius: 0 0 6px 6px;
    }

    /* Stacked, the binding runs across the middle. */
    .spread-demo::after {
        background: linear-gradient(180deg, transparent, rgba(var(--shadow), 0.1));
        bottom: 0;
        height: 30px;
        left: 0;
        right: 0;
        top: auto;
        width: auto;
    }

    .spread-code::before {
        background: linear-gradient(0deg, transparent, rgba(var(--shadow), 0.09));
        height: 30px;
        right: 0;
        width: auto;
    }

    .install-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .chapter-head {
        grid-template-columns: minmax(0, 1fr);
    }

    .chapter-blurb {
        justify-self: start;
    }

    .hero-notes {
        display: none;
    }
}

@media (max-width: 640px) {
    .nav-link--wide {
        display: none;
    }

    /* At the top of the page, scrolling away with it, so it never sits over a demo. */
    .topbar {
        padding-bottom: 0.55rem;
        padding-top: 0.55rem;
        position: relative;
    }

    .brand-mark {
        height: 34px;
        width: 34px;
    }

    .brand-wordmark {
        font-size: 1.15rem;
    }

    .hero {
        padding: 1.25rem 0.75rem 1.5rem;
    }

    .hero-sheet {
        padding: 2.5rem 1.35rem 4rem;
    }

    .hero-title {
        font-size: clamp(3.6rem, 22vw, 6rem);
        margin: 1rem 0 1.25rem;
        row-gap: 0.1em;
    }

    .install-chip {
        font-size: 0.78rem;
        gap: 0.6rem;
        padding: 0.8rem 0.9rem 0.8rem 1rem;
        white-space: nowrap;
    }

    .chapter {
        padding: 3rem 0.75rem 0.5rem;
    }

    .spread-demo {
        padding: 1.5rem 1.25rem 1.75rem;
    }

    .stage {
        min-height: 220px;
    }

    .code {
        font-size: 0.72rem;
    }

    .code-head {
        padding-left: 1rem;
    }

    .phone-stage {
        min-height: 640px;
    }
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
