/* ============================================================================
   widgets/kit.css  --  what the two teaching-widget families have in common.

   Two families of interactive widgets are built by static/js:
     .a86  the x86-64 assembly widgets  (js/asm86, css/widgets/asm86.css)
     .pl   the pseudocode lab           (js/pseudo, css/widgets/pseudo-lab.css)
   They were written as twins and shared a design system by copy and paste.
   This file holds the shared half, written once, so a change to a color
   role or a button reaches both. The two family stylesheets keep only what
   is specific to them and must be loaded AFTER this one.

   Color roles carry meaning, so they are worth learning once:
     amber   the step about to run, and anything the last step changed
     blue    a value that was read
     purple  a value that was written
     green   a match, a pass, a proof
     red     a mismatch, an error, a claim a run broke
   The roles are stated once per theme below. Everything neutral is mixed
   from the page colors (--bs-body-bg / --bs-body-color), so a widget sits
   on whatever background the page gives it.

   Dark mode keys off `body.quarto-dark`, which is what Quarto actually sets.
   `[data-bs-theme="dark"]` is grouped in only as a fallback. Reading the OS
   preference (prefers-color-scheme) on a Quarto page is the bug that once
   made a light page render a dark widget, so nothing here does.

   Tokens (--w-*)
     --w-page --w-ink --w-dim --w-rule --w-surface --w-surface-2
     --w-change --w-read --w-write --w-match --w-miss   and their  -bg  washes
     --w-mono --w-sans --w-fs
   --w-fs is the one size that drives every piece of text in a widget. Each
   rule states its size as a multiple of it, so fullscreen raises them all at
   once. At 0.95rem a widget reads a step below the page's body text.
   ==========================================================================*/


/* ------------------------------------------------------------------ tokens */

:is(.a86, .pl) {
    --w-page: var(--bs-body-bg, #ffffff);
    --w-ink: var(--bs-body-color, #1b1f24);

    /* 70%, matching the muted gray in base/site.css and bio.css: at 60% the
       result fails WCAG AA for normal-size text on a white background. */
    --w-dim: color-mix(in srgb, var(--w-ink) 70%, transparent);
    --w-rule: color-mix(in srgb, var(--w-ink) 20%, transparent);
    --w-surface: var(--w-page);
    --w-surface-2: color-mix(in srgb, var(--w-ink) 6%, var(--w-page));

    --w-change: #8a5c05;
    --w-read: #17618f;
    --w-write: #6a4299;
    --w-match: #266a41;
    --w-miss: #93291f;

    --w-change-bg: color-mix(in srgb, var(--w-change) 13%, var(--w-page));
    --w-read-bg: color-mix(in srgb, var(--w-read) 13%, var(--w-page));
    --w-write-bg: color-mix(in srgb, var(--w-write) 13%, var(--w-page));
    --w-match-bg: color-mix(in srgb, var(--w-match) 15%, var(--w-page));
    --w-miss-bg: color-mix(in srgb, var(--w-miss) 13%, var(--w-page));

    --w-mono: var(--bs-font-monospace, ui-monospace, "SF Mono", Menlo, Consolas, monospace);
    --w-sans: var(--bs-font-sans-serif, system-ui, sans-serif);
    --w-fs: 0.95rem;

    color: var(--w-ink);
    font-size: var(--w-fs);
    line-height: 1.45;
    margin: 1.4rem 0;
    outline: none;
}

/* A tinted panel needs a stronger wash to read against a dark page, and the
   accents have to lighten to stay legible on it. */
body.quarto-dark :is(.a86, .pl),
[data-bs-theme="dark"] :is(.a86, .pl) {
    --w-change: #e0a93a;
    --w-read: #6fb4e3;
    --w-write: #c0a0e0;
    --w-match: #74c391;
    --w-miss: #e08a80;

    --w-rule: color-mix(in srgb, var(--w-ink) 28%, transparent);
    --w-surface-2: color-mix(in srgb, var(--w-ink) 9%, var(--w-page));

    --w-change-bg: color-mix(in srgb, var(--w-change) 22%, var(--w-page));
    --w-read-bg: color-mix(in srgb, var(--w-read) 22%, var(--w-page));
    --w-write-bg: color-mix(in srgb, var(--w-write) 22%, var(--w-page));
    --w-match-bg: color-mix(in srgb, var(--w-match) 22%, var(--w-page));
    --w-miss-bg: color-mix(in srgb, var(--w-miss) 22%, var(--w-page));
}

/* Fallback for browsers without color-mix(). */
@supports not (background: color-mix(in srgb, white 50%, black)) {
    :is(.a86, .pl) {
        --w-dim: #666f78;
        --w-rule: #d5dae0;
        --w-surface-2: #f4f6f8;
        --w-change-bg: #fdf1d8;
        --w-read-bg: #e1eef9;
        --w-write-bg: #efe6f7;
        --w-match-bg: #dcefe2;
        --w-miss-bg: #f8e3e1;
    }

    body.quarto-dark :is(.a86, .pl) {
        --w-dim: #98a2ab;
        --w-rule: #3a424b;
        --w-surface-2: #21262c;
        --w-change-bg: #453518;
        --w-read-bg: #1b3348;
        --w-write-bg: #33254a;
        --w-match-bg: #1d3a28;
        --w-miss-bg: #3f2320;
    }
}


/* ------------------------------------------------------------- shared rules
   Each rule below was identical in both stylesheets. Rules that differ
   between the families (panels, code rows, cells, legends...) stay in the
   family file that owns them. */

/* --- Widget shell ------------------------------------------------------ */

.a86:focus-visible,
.pl:focus-visible {
    box-shadow: 0 0 0 3px var(--w-change-bg);
    border-radius: 4px;
}

.a86 code,
.a86 code:not(.sourceCode),
.pl code,
.pl code:not(.sourceCode) {
    background: none;
    border: 0;
    padding: 0;
    border-radius: 0;
    font-size: inherit;
    color: inherit;
    font-family: var(--w-mono);
}

/* --- Text -------------------------------------------------------------- */

.a86-title,
.pl-title {
    font-size: calc(var(--w-fs) * 1.13);
    margin: 0 0 0.2rem;
}

.a86-blurb,
.pl-blurb {
    color: var(--w-dim);
    margin: 0 0 0.7rem;
    max-width: 62ch;
}

.a86-muted,
.pl-muted {
    color: var(--w-dim);
}

.a86-error,
.pl-error {
    color: var(--w-miss);
    background: var(--w-miss-bg);
    border-left: 3px solid var(--w-miss);
    padding: 0.4rem 0.6rem;
    margin: 0.5rem 0;
}

/* --- Controls ---------------------------------------------------------- */

.a86-controls,
.pl-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.5rem;
    margin-bottom: 0.7rem;
    background: var(--w-surface-2);
    border: 1px solid var(--w-rule);
    border-radius: 4px;
}

.a86-btn,
.pl-btn {
    font: inherit;
    font-size: calc(var(--w-fs) * 0.96);
    padding: 0.22rem 0.62rem;
    color: var(--w-ink);
    background: var(--w-surface-2);
    border: 1px solid var(--w-rule);
    border-radius: 3px;
    cursor: pointer;
}

.a86-btn:hover,
.pl-btn:hover {
    border-color: var(--w-change);
}

.a86-btn-primary,
.pl-btn-primary {
    border-color: var(--w-change);
    font-weight: 600;
}

.a86-slider,
.pl-slider {
    flex: 1 1 140px;
    min-width: 110px;
    accent-color: var(--w-change);
}

.a86-readout,
.pl-readout {
    font-family: var(--w-mono);
    font-size: calc(var(--w-fs) * 0.93);
    color: var(--w-dim);
    white-space: nowrap;
}

.a86-btn-full,
.pl-btn-full {
    margin-left: auto;
}

/* --- Layout ------------------------------------------------------------ */

.a86-grid,
.pl-grid {
    display: grid;
    gap: 0.7rem;
    grid-template-columns: 1fr;
}

.a86-panel-title,
.pl-panel-title {
    font-family: var(--w-sans);
    font-size: calc(var(--w-fs) * 0.89);
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--w-dim);
    margin: 0 0 0.45rem;
}

/* --- Fullscreen -------------------------------------------------------- */

.a86.is-fullscreen,
.pl.is-fullscreen {
    --w-fs: clamp(1rem, 0.35rem + 0.62vw, 1.3rem);
    position: fixed;
    inset: 0;
    z-index: 1090;
    margin: 0;
    padding: 0.9rem 1.1rem 2rem;
    background: var(--w-page);
    overflow: auto;
    overscroll-behavior: contain;
}

.a86.is-fullscreen .a86-controls,
.pl.is-fullscreen .pl-controls {
    position: sticky;
    top: 0;
    z-index: 2;
}

.a86.is-fullscreen .a86-grid,
.pl.is-fullscreen .pl-grid {
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
}

.a86.is-fullscreen .a86-trace-wrap,
.pl.is-fullscreen .pl-trace-wrap {
    max-height: 28rem;
}

/* --- Code listing ------------------------------------------------------ */

.a86-code-marker,
.pl-code-marker {
    color: var(--w-change);
    font-weight: 700;
}

.a86-code-row.is-last,
.pl-code-row.is-last {
    background: var(--w-surface-2);
}

.a86-code-row.is-error,
.pl-code-row.is-error {
    background: var(--w-miss-bg);
    border-left-color: var(--w-miss);
}
