/* =============================================================
   theme.css — design tokens + switchable themes
   Loaded FIRST on every page (before every other stylesheet).

   The token set is `design/design_v2/handoff/01-design-system.md` §1: fifteen
   semantic slots, filled per theme. Nothing outside this file may name a
   colour — that rule was already true before the redesign (every hex in the
   stylesheets lived here) and is what let the whole app be restyled by
   editing one file.

   Reading the names
   -----------------
   Grounds      --bg          page ground, editor surface
                --panel       cards, rail, side panels
                --panel-2     inputs, inset blocks, code samples
                --row-hover   hover and selected row
   Rules        --line        every 1px rule
                --line-strong emphasised frame, dialog edge
   Text         --fg          primary text, primary button ground
                --fg-2        body prose, table cells
                --fg-dim      labels, meta, hints — the floor for real text
                --fg-mute     DISABLED ONLY, never for information
   Meaning      --accent      identity, links, unread, current location
                --pass        solved, passed, saved
                --warn        partial, read-only, arming a submit
                --pending     waiting on a human (awaiting grading, review)
                --fail        errors, failed tests, overdue

   Rules that come with them: at most two grounds per screen; `--accent` is
   never a verdict; numbers are uncoloured unless they carry a verdict; and
   `--fg-mute` is for disabled controls only — using it for real text is how
   an interface becomes unreadable one commit at a time.

   Beyond the fifteen
   ------------------
   Three groups the design pack does not cover, kept deliberately small and
   labelled so they are not mistaken for slots anyone may reach for:
     * SOFT/INK derivations — tinted grounds and readable ink for badges and
       banners, derived with color-mix() so a new theme never hand-lists them;
     * EDITOR SYNTAX — the code editor needs more hues than an interface does;
     * CHROME — the overlay shadow and the read-only tint.
   ============================================================= */

/* ---- Mocha (default, dark) — the design's reference palette ---- */
:root,
:root[data-theme="mocha"] {
    --bg:           #0E1116;
    --panel:        #12161C;
    --panel-2:      #161A21;
    --row-hover:    #1A1F27;
    --line:         #2A313C;
    --line-strong:  #39424F;
    --fg:           #E6EAF0;
    --fg-2:         #C9D2DC;
    --fg-dim:       #8A97A6;
    --fg-mute:      #4C5765;
    --accent:       #5BC8F5;
    --pass:         #3DDC84;
    --warn:         #F2A93B;
    --pending:      #9B8BF5;
    --fail:         #F2495C;

    /* EDITOR SYNTAX — the code editor only. */
    --syn-keyword:  #9B8BF5;
    --syn-string:   #3DDC84;
    --syn-number:   #F2A93B;
    --syn-builtin:  #5BC8F5;
    --syn-comment:  #5C6875;

    /* CHROME */
    --shadow:        rgba(0, 0, 0, 0.5);
    --readonly-bg:      #1B1710;
    --readonly-chrome:  #16130D;
}

/* ---- Latte (light) ---- */
:root[data-theme="latte"] {
    --bg:           #FAF7F2;
    --panel:        #FFFFFF;
    --panel-2:      #F2EEE7;
    --row-hover:    #EAE4DA;
    --line:         #DED6C9;
    --line-strong:  #C2B7A5;
    --fg:           #23201C;
    --fg-2:         #4A443C;
    --fg-dim:       #776E62;
    --fg-mute:      #A79C8C;
    --accent:       #1E6E96;
    --pass:         #1C7A46;
    --warn:         #9A6410;
    --pending:      #5A46B4;
    --fail:         #B4212F;

    --syn-keyword:  #5A46B4;
    --syn-string:   #1C7A46;
    --syn-number:   #9A6410;
    --syn-builtin:  #1E6E96;
    --syn-comment:  #8C8378;

    --shadow:        rgba(0, 0, 0, 0.18);
    --readonly-bg:      #FBF5E6;
    --readonly-chrome:  #F4EBD6;
}

/* ---- SOFT / INK derivations — same for every theme -------------------------
   color-mix() re-resolves against whatever the theme set above, so a new
   theme fills fifteen slots and gets all of these for free. `-soft` is a
   tinted ground; `-ink` is text that stays readable on it. */
:root {
    --accent-soft:  color-mix(in srgb, var(--accent) 14%, transparent);
    --accent-ink:   color-mix(in srgb, var(--accent), var(--fg) 30%);

    --pass-soft:    color-mix(in srgb, var(--pass) 15%, transparent);
    --pass-ink:     color-mix(in srgb, var(--pass), var(--fg) 32%);
    --warn-soft:    color-mix(in srgb, var(--warn) 15%, transparent);
    --warn-ink:     color-mix(in srgb, var(--warn), var(--fg) 32%);
    --fail-soft:    color-mix(in srgb, var(--fail) 15%, transparent);
    --fail-ink:     color-mix(in srgb, var(--fail), var(--fg) 30%);
    --pending-soft: color-mix(in srgb, var(--pending) 15%, transparent);
    --pending-ink:  color-mix(in srgb, var(--pending), var(--fg) 32%);

    /* Text that sits ON a solid accent/pass/fail fill. In every theme the
       page ground is the readable contrast against those. */
    --on-accent: var(--bg);
}

/* ---- Type (design v2 §2) --------------------------------------------------
   Three voices, three faces, no overlap: serif is "this is the exercise",
   mono is "the machine measured this", and sans is the application talking.
   Faces are declared in fonts.css and self-hosted. See the type-roles block
   further down for the mapping and why v1's serif headings were wrong. */
:root {
    --font-serif: 'Bitstream Vera Serif', 'DejaVu Serif', Georgia, 'Times New Roman', serif;
    --font-sans:  'Bitstream Vera Sans', 'DejaVu Sans', Verdana, system-ui, -apple-system, 'Segoe UI', sans-serif;
    --font-mono:  'Bitstream Vera Sans Mono', 'DejaVu Sans Mono', Menlo, ui-monospace, 'SF Mono', monospace;

    /* Spacing scale — 4·6·8·10·14·18·22·26·34·44. Layout uses flex/grid with
       `gap`, never margin chains. */
    --sp-1: 4px;   --sp-2: 6px;   --sp-3: 8px;   --sp-4: 10px;  --sp-5: 14px;
    --sp-6: 18px;  --sp-7: 22px;  --sp-8: 26px;  --sp-9: 34px;  --sp-10: 44px;

    /* Radius: 2 on controls, 3 on cards, 50% on status dots only. */
    --radius-control: 2px;
    --radius-card: 3px;

    /* Shadows appear on overlays and nowhere else. */
    --shadow-overlay: 0 18px 40px var(--shadow);

    /* Transitions: colour and width only, 120–160ms. One 420ms pulse is
       allowed on a judge verdict; nothing else animates. */
    --transition: 140ms;

    /* ── Page transitions — EVERY KNOB IS HERE ─────────────────────────
       (the effect itself: components.css "Page transitions")

       Nothing arrives until it is ready to be looked at. The background
       paints with the HTML, the topbar and rail come into focus the
       moment they are built, and the page's blocks rise from below the
       screen only once their data is in. On a slow connection that reads
       as "it was always there, the lag made it late" instead of a white
       screen, then bare boxes, then text appearing inside them.

       The point is psychological, not a measurement: the wait for a page
       to load is inevitable, and what the movement buys is that the wait
       ends with something arriving AT PACE. Nothing here is ever made
       conditional on connection speed, and nothing adds delay.

       Three different arrivals, each settled by eye (owner, 2026-09-22):
       the **chrome** comes into focus, with a glow sweeping the topbar;
       a page's **blocks** simply brighten into place; and the **IDE
       workspace** still flies, rising from below the screen as one slab.
       Every transition here is LINEAR: an easing curve is more bytes to
       send and more arithmetic per frame on the device, for a difference
       nobody asked for. */
    --motion-in: 200ms;     /* a block brightening into place            */
    --motion-out: 250ms;    /* the page dimming away. NOTE: this is also
                               the hold before the browser navigates, and
                               the ceiling on --motion-sweep-out          */
    --motion-stagger: 30ms; /* between one block and the next            */
    --motion-chrome: 180ms; /* the chrome's blur pulse, out of focus → sharp */
    /* The chrome does not fly (owner, 2026-09-22) — it comes into focus,
       and a thin glow sweeps along it while it does. shell.css, "Arriving". */
    --motion-blur: 5px;     /* how far out of focus the chrome starts    */
    --motion-rise: 100vh;   /* how far below the screen the IDE workspace
                               starts — the one thing that still flies    */
    --motion-dim: 0.55;     /* how dim it starts, 0–1                    */
    --motion-sweep: 250ms;  /* the glow crossing the bar on ARRIVAL      */
    /* And on the way out. It cannot usefully exceed --motion-out: the
       browser navigates when the hold expires and takes the rest of
       the animation with it. */
    --motion-sweep-out: 250ms;
    --motion-sweep-strength: 50%;  /* how much accent is in the glow    */

    /* ONE content ceiling for every page (owner, 2026-09-15: "a common grid
       beneath all pages" — left edges aligned, the same overall width
       everywhere). It used to be two — 1360px for the student screens and
       1680px for the teacher tables — plus private caps on the library
       (1100), the wizard and admin (900) and settings (620), so no two
       screens started at the same x. A ceiling, not a width.
       `--content-max-wide` is kept as an alias so nothing that names it
       drifts. */
    --content-max: 1680px;
    --content-max-wide: var(--content-max);
}

/* =============================================================
   box-sizing, once
   -------------------------------------------------------------
   A control's `width: 100%` has to MEAN 100%. Without this, padding and
   border are added on top, so two fields in the same column come out
   different widths whenever their padding differs — which is exactly what
   happened on the login form: the email input sat 40px wider than the
   password input, because the password's Show/Hide button reserves padding on
   the right and the flex row it lives in absorbed the overflow while the bare
   email input did not (owner, 2026-08-05).

   Three page stylesheets already declared this for themselves. Declaring it
   here instead means a page cannot be the one that forgot.
   ============================================================= */
*, *::before, *::after { box-sizing: border-box; }

/* The design authored motion as optional. Honour the OS switch globally
   rather than per-component, so a new animation cannot forget to. */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

body {
    font-family: var(--font-sans);
    font-size: 13.5px;
    line-height: 1.5;
}

/* =============================================================
   Light/dark toggle (lives in the topbar; see theme.js)
   -------------------------------------------------------------
   One icon button, not a menu: there are two themes, and they are the two
   modes. It shows the mode it would switch to.
   ============================================================= */
.theme-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: 1px solid var(--line);
    border-radius: 4px;
    color: var(--fg-2);
    font-size: 0.95rem;
    line-height: 1;
    width: 32px;
    min-height: 32px;
    cursor: pointer;
    flex-shrink: 0;
    transition: color 0.15s, border-color 0.15s;
}
.theme-toggle-btn:hover { color: var(--fg); border-color: var(--line-strong); }

/* A standalone toggle for pages without a topbar (login / register). */
.theme-switch-floating {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 100;
}

/* =============================================================
   The `hidden` attribute must always win (2026-08-04)
   -------------------------------------------------------------
   The UA stylesheet's `[hidden] { display: none }` has the lowest possible
   precedence, so ANY author rule that sets `display` on the same element
   silently defeats it — `el.hidden = true` then does nothing at all, and the
   JS looks broken while the bug is in the CSS.

   This bit us three times: the editor's read-only badge (patched locally in
   editor.css), and then the authoring screen's editor layout, file toolbar
   and file list — all `display: flex`, all still on screen after being
   hidden. Rather than remember a `[hidden]` guard beside every future
   `display` rule, `hidden` is made authoritative once, here, for every page.

   Anything that needs to be visible while carrying the attribute is by
   definition not hidden — give it a class instead.
   ============================================================= */
[hidden] { display: none !important; }

/* =============================================================
   Type roles (design v2 §2) — three voices, three faces, NO overlap
   -------------------------------------------------------------
   The split is the product's strongest signal, so it only works if it is
   absolute:

     serif  THE EXERCISE        — a task's title wherever it appears, and its
                                  instructions, including rendered Markdown.
                                  Nothing else.
     sans   THE APPLICATION     — page and section headings, greetings,
                                  buttons, body, hints, nav labels, empty
                                  states, dialog copy, comment bodies
     mono   THE MACHINE         — the editor, section labels, data cells,
                                  scores, dates, filenames, emails, ids

   The test (v2 §2): point at any serif glyph and you must be able to answer
   "which exercise is this?" If you cannot, it is the wrong face.

   v1 had serif on every heading, which failed that test on thirteen screens —
   "Login", "Settings", "Classes & Students" and the rest are the application
   talking, not an exercise. Headings are therefore sans by default here, and
   serif is opted into by the two classes below plus `.task-title`-style
   classes in the page stylesheets.
   ============================================================= */

h1, h2, h3 {
    font-family: var(--font-sans);
    font-weight: 700;
}

/* Page heading 26/700, section heading 22/700 (v2 §2). A greeting is 30 and
   says so itself (`.home-greeting`). */
h1 { font-size: 26px; line-height: 1.25; }
h2 { font-size: 22px; line-height: 1.3; }
h3 { font-size: 17px; line-height: 1.35; }

/* --- The only two serif slots the element selectors can reach ----------- */

/* A task title, wherever it appears. Pages set the size the context calls for
   (list row 15.5–17, editor panel 21, reading pane 28) — but never the FACE.
   Every element that holds a task's name carries this class, and no page
   stylesheet declares `font-family` on one again: the rule "a task title is
   serif" has exactly one place it can be changed or broken.

   It was declared here and used nowhere until 2026-09-14 — six screens had
   each reached for `var(--font-serif)` locally instead, and two (the student
   progress table and the Assignments table) had quietly not, so the same task
   read in two faces depending on which screen you were looking at.
   `serif-rule.test.js` now reads the sources to keep that from drifting back. */
.task-title-type {
    font-family: var(--font-serif);
    font-weight: 600;
}

/* The size a task title takes in a LIST ROW. Declared here beside the face
   for the same reason: Home shows two lists side by side, and 16px in one
   next to 13.5px in the other read as two different kinds of thing rather
   than as one kind in two places (owner, 2026-09-14). Screens that are not
   list rows — the editor's panel, the library row — still choose their own. */
:root { --task-title-row: 15px; }

/* Rendered task instructions: serif and generously led. They use the whole
   width of their box (owner, 2026-10-15): the 66-character measure they had
   wrapped them well short of the edge on the Tasks screen and in the editor,
   while the authoring preview, which never had it, looked right. */
.task-description,
.markdown-body {
    font-family: var(--font-serif);
    font-weight: 400;
    font-size: 16px;
    line-height: 1.6;
}

/* Lists in instructions, one rule for every screen (owner, 2026-10-15: the
   bullets and numbers did not line up with the paragraphs). Each page had its
   own — 1.2rem on bullets in the editor, whose reset left numbered lists with
   no indent at all, so their numbers hung out to the left of the text. Now
   the marker starts exactly where a paragraph starts, and the item's text
   hangs at one indent, wrapped lines included. The markers are drawn rather
   than the browser's, because a native marker is right-aligned against the
   text and so starts wherever its width puts it. `markdown.js` carries an
   `<ol start>` into the counter. */
:is(.task-description, .markdown-body, .md-preview) :is(ul, ol) {
    list-style: none;
    margin: 0 0 0.75em;
    padding: 0 0 0 1.8em;
}
:is(.task-description, .markdown-body, .md-preview) li {
    position: relative;
    margin: 0 0 0.2em;
}
:is(.task-description, .markdown-body, .md-preview) li > :is(ul, ol) { margin: 0.2em 0 0; }
:is(.task-description, .markdown-body, .md-preview) ul > li::before {
    content: '•';
    position: absolute;
    left: -1.8em;
}
:is(.task-description, .markdown-body, .md-preview) ol { counter-reset: md-item; }
:is(.task-description, .markdown-body, .md-preview) ol > li { counter-increment: md-item; }
:is(.task-description, .markdown-body, .md-preview) ol > li::before {
    content: counter(md-item) '.';
    position: absolute;
    left: -1.8em;
    font-variant-numeric: tabular-nums;
}
/* The author's own headings are part of the exercise too, so they keep its
   face — the element rule above would otherwise turn them sans, and a task
   would read as two documents (owner, 2026-10-01). */
.task-description :is(h1, h2, h3, h4),
.markdown-body :is(h1, h2, h3, h4) {
    font-family: var(--font-serif);
}

/* Machine values. Anything the system produced rather than a person typed. */
.mono,
code, kbd, samp, pre,
input[type="datetime-local"],
input[type="number"],
.topbar-user,
.breadcrumbs,
.col-score, .col-due, .col-start,
.state-badge {
    font-family: var(--font-mono);
}

/* Section labels: mono, small, uppercase, tracked — the design's card-header
   marker (§6). */
.card-label {
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--fg-dim);
}

/* Controls are always sans, whatever they sit inside. */
button, select, textarea,
input:not([type="datetime-local"]):not([type="number"]) {
    font-family: var(--font-sans);
}
button { font-size: 14px; font-weight: 600; }
