/*
 * NeuroSprint brand foundation — "the marked-up page".
 *
 * The product is a page you read and then prove you understood. So the whole
 * identity is a printed page being worked over with two tools:
 *   the HIGHLIGHTER  (--marker)  = reading, the pacer, anything "in progress"
 *   the RED PENCIL   (--pencil)  = review, grading, anything "checked"
 * Everything else is paper and ink. No gradients, no glass, no purple.
 *
 * Shared by the landing page, the legal pages and the free tools. The app and
 * the browser extension reuse the same token values.
 *
 * Requires /dist/fonts.css (self-hosted Fraunces + Atkinson Hyperlegible).
 */

/* Metric-matched fallbacks: while the web fonts load (font-display: swap) the
   text is set in a local face scaled to the same average width, so lines break
   in the same places and nothing jumps when the real fonts arrive. */
@font-face {
    font-family: 'Fraunces Fallback';
    src: local('Georgia'), local('Times New Roman'), local('Noto Serif');
    size-adjust: 96%;
}
@font-face {
    font-family: 'Atkinson Fallback';
    src: local('Arial'), local('Helvetica Neue'), local('Roboto');
    size-adjust: 100%;
}

:root {
    /* Paper */
    --paper: #F6F1E7;
    --paper-deep: #ECE4D3;
    --paper-edge: #D9CFBA;
    --sheet: #FFFDF8;

    /* Ink — --ink-faint is the lightest tone that still passes AA on --paper */
    --ink: #17140F;
    --ink-soft: #4B453B;
    --ink-faint: #6B6356;

    /* The two tools */
    --marker: #FFE14A;
    --marker-deep: #F2C200;
    --pencil: #D23F2C;
    --pencil-deep: #A42C1D; /* use this one for text; --pencil is for strokes */
    --pass: #2C6A4C;

    /* On an ink ground (the inverted "statement" spread) */
    --on-ink: #F6F1E7;
    --on-ink-soft: #C9BFAB;   /* 10:1 on --ink */
    --pencil-on-ink: #EF6A55; /* 6:1 on --ink — red text on the dark spread */

    --font-display: 'Fraunces', 'Fraunces Fallback', 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, serif;
    --font-body: 'Atkinson Hyperlegible Next', 'Atkinson Fallback', 'Atkinson Hyperlegible', 'Segoe UI', system-ui, sans-serif;
    --font-mono: 'Atkinson Hyperlegible Mono', ui-monospace, 'SF Mono', Consolas, monospace;

    --measure: 62ch;
    --radius: 3px;
    --rule: 1px solid var(--paper-edge);
    --rule-ink: 2px solid var(--ink);
    --gutter: clamp(1.25rem, .7rem + 2.2vw, 2.5rem);
    --shadow-sheet: 0 1px 0 rgba(23, 20, 15, .04), 0 18px 40px -18px rgba(23, 20, 15, .28);
    --shadow-hard: 5px 5px 0 rgba(23, 20, 15, .14);

    /* One marker stroke, reused by .mark, the wordmark and the live pacer. */
    --marker-stroke: linear-gradient(100deg,
        rgba(255, 225, 74, 0) .6%,
        rgba(255, 225, 74, .95) 2.4%,
        rgba(255, 225, 74, .8) 96%,
        rgba(255, 225, 74, 0) 99.5%);

    --step--1: clamp(.83rem, .8rem + .15vw, .92rem);
    --step-0: clamp(1.05rem, 1rem + .25vw, 1.2rem);
    --step-1: clamp(1.3rem, 1.2rem + .5vw, 1.6rem);
    --step-2: clamp(1.7rem, 1.45rem + 1.2vw, 2.4rem);
    --step-3: clamp(2.3rem, 1.8rem + 2.6vw, 3.8rem);
    --step-4: clamp(2.9rem, 2rem + 4.8vw, 5.6rem);
}

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

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-behavior: smooth;
    scroll-padding-top: 5.5rem; /* anchors clear the sticky header */
}

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font-body);
    font-size: var(--step-0);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    overflow-wrap: break-word;
}

/* Paper grain. Fixed, inert, and cheap: one inline SVG, no image request. */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    opacity: .5;
    mix-blend-mode: multiply;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .09  0 0 0 0 .08  0 0 0 0 .06  0 0 0 .09 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E");
}

/* Content sits above the grain. <dialog> is excluded: a modal dialog lives in
   the top layer and must keep its own fixed positioning. */
body > :not(dialog) { position: relative; z-index: 1; }

h1, h2, h3, h4 {
    font-family: var(--font-display);
    font-weight: 560;
    font-variation-settings: 'opsz' 144;
    line-height: 1.04;
    letter-spacing: -.022em;
    margin: 0 0 .5em;
    text-wrap: balance;
}

h1 { font-size: var(--step-4); }
h2 { font-size: var(--step-3); }
h3 { font-size: var(--step-1); letter-spacing: -.012em; line-height: 1.15; font-variation-settings: 'opsz' 48; }
h4 { font-size: var(--step-0); letter-spacing: -.005em; line-height: 1.25; font-variation-settings: 'opsz' 24; }

h1 em, h2 em, h3 em { font-style: italic; font-weight: 420; }

p { margin: 0 0 1em; max-width: var(--measure); text-wrap: pretty; }

a { color: inherit; text-decoration-color: var(--pencil); text-decoration-thickness: .09em; text-underline-offset: .18em; }
a:hover { text-decoration-thickness: .16em; }

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

::selection { background: var(--marker); color: var(--ink); }

img, svg { max-width: 100%; }

[hidden] { display: none !important; }

/* ── The highlighter ─────────────────────────────────────────────────────── */
/* A marker stroke, not a background box: slightly short of the cap height,
   uneven at the ends, and it wraps per line. */
.mark {
    background: var(--marker-stroke) no-repeat 0 62% / 100% 58%;
    -webkit-box-decoration-break: clone;
    box-decoration-break: clone;
    padding: 0 .12em;
    margin: 0 -.12em;
    color: inherit;
}

/* ── The red pencil ──────────────────────────────────────────────────────── */
.pencil { color: var(--pencil-deep); }

.pencil-underline {
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 12' preserveAspectRatio='none'%3E%3Cpath d='M2 8c30-5 58 3 92-1s62-5 104 0' fill='none' stroke='%23D23F2C' stroke-width='2.6' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat 0 100% / 100% .38em;
    padding-bottom: .16em;
}

/* Hand-drawn marks: inline <svg class="pm"> whose paths carry pathLength="1",
   so one rule can draw any of them. They are decoration — always aria-hidden.
   Final state is the default; the "undrawn" state only exists where scripting
   is on and motion is welcome, so no-JS and reduced-motion readers simply see
   the finished marks. site.js adds .is-drawn when a [data-draw] block scrolls
   into view. */
.pm {
    position: absolute;
    overflow: visible;
    pointer-events: none;
    fill: none;
    stroke: var(--pencil);
    stroke-width: 2.6;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.pm--inline { position: static; display: inline-block; vertical-align: -.2em; }

/* Text written "in pencil": an editor's note, not body copy. */
.pencil-note {
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 440;
    font-variation-settings: 'opsz' 24;
    color: var(--pencil-deep);
    line-height: 1.25;
}

@media (scripting: enabled) and (prefers-reduced-motion: no-preference) {
    [data-draw] .pm path {
        stroke-dasharray: 1 1;
        stroke-dashoffset: 1;
        opacity: 0;
        transition: stroke-dashoffset .75s cubic-bezier(.55, .1, .25, 1), opacity .01s linear;
    }
    [data-draw] .pm path:nth-child(2) { transition-delay: .4s; }
    [data-draw] .pm path:nth-child(3) { transition-delay: .7s; }
    [data-draw] .pm--late path { transition-delay: .5s; }
    [data-draw] .pm--late path:nth-child(2) { transition-delay: .9s; }
    [data-draw] .pm--later path { transition-delay: 1s; }
    [data-draw] .pm--later path:nth-child(2) { transition-delay: 1.4s; }
    [data-draw].is-drawn .pm path { stroke-dashoffset: 0; opacity: 1; }
}

/* ── Small caps labels, folios, marginalia ───────────────────────────────── */
.folio {
    font-family: var(--font-mono);
    font-size: var(--step--1);
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--ink-faint);
}

.marginalia {
    font-family: var(--font-display);
    font-style: italic;
    font-size: var(--step--1);
    line-height: 1.4;
    color: var(--ink-soft);
    border-left: 2px solid var(--pencil);
    padding-left: .8em;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .55em;
    min-height: 48px;
    padding: .7em 1.35em;
    border: 2px solid var(--ink);
    border-radius: var(--radius);
    background: var(--ink);
    color: var(--paper);
    font: 600 var(--step-0)/1.1 var(--font-body);
    letter-spacing: .005em;
    text-decoration: none;
    cursor: pointer;
    transition: background-color .16s ease, color .16s ease, transform .16s ease, box-shadow .16s ease;
    box-shadow: 4px 4px 0 var(--marker-deep);
}

.btn:hover { background: var(--marker); color: var(--ink); transform: translate(-1px, -1px); box-shadow: 6px 6px 0 var(--ink); }
.btn:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--ink); }

.btn--quiet { background: transparent; color: var(--ink); box-shadow: none; }
.btn--quiet:hover { background: var(--ink); color: var(--paper); box-shadow: none; transform: none; }

.btn--sm { min-height: 44px; padding: .5em 1em; font-size: var(--step--1); box-shadow: 3px 3px 0 var(--marker-deep); }
.btn--block { display: flex; width: 100%; }

.btn[disabled], .btn[aria-disabled='true'] { opacity: .55; cursor: not-allowed; transform: none; }

/* A text link with a drawn arrow — the quiet companion to .btn. */
.link-arrow {
    display: inline-flex;
    align-items: center;
    gap: .5em;
    min-height: 44px;
    font-weight: 600;
}

.arrow {
    width: 1.5em;
    height: .75em;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: transform .16s ease;
}

a:hover > .arrow { transform: translateX(3px); }

/* ── Sheets (cards) ──────────────────────────────────────────────────────── */
.sheet {
    background: var(--sheet);
    border: var(--rule);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sheet);
}

hr, .rule { border: 0; border-top: var(--rule); margin: 0; }

.wrap { width: min(1180px, 100% - 2.5rem); margin-inline: auto; }

.visually-hidden {
    position: absolute !important;
    width: 1px; height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after {
        animation-duration: .001ms !important;
        animation-delay: 0s !important;
        animation-iteration-count: 1 !important;
        transition-duration: .001ms !important;
        transition-delay: 0s !important;
    }
}
