/* lk — minimal default look for the runtime's injected UI.
   Everything reads CSS custom properties; a site restyles lk by redefining the --lk-* tokens
   (or any .lk-* rule). lk never styles the page itself (body, headings, layout). */

:root {
  --lk-font: inherit;
  --lk-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --lk-bg: #faf9f6;
  --lk-surface: #ffffff;
  --lk-fg: #1c1c1a;
  --lk-muted: #5c5a54;
  --lk-line: #dcd8cf;
  --lk-accent: #2b5bc8;
  --lk-accent-fg: #ffffff;
  --lk-accent-soft: #e8eefb;
  --lk-ok: #1d6f46;
  --lk-ok-soft: #e4f3ea;
  --lk-bad: #b0271f;
  --lk-bad-soft: #fbe9e7;
  --lk-warn: #7d5200;
  --lk-warn-soft: #fcf1d8;
  --lk-mark-q: #ffd7cd;
  --lk-mark-k: #fdeea0;
  --lk-mark-d: #d7e4fd;
  --lk-mark-x: #d9f0cf;
  --lk-radius: 10px;
  --lk-radius-sm: 6px;
  --lk-hit: 44px;
  --lk-gap: 12px;
  --lk-shadow: 0 8px 28px rgb(0 0 0 / 0.14);
  --lk-top-offset: 0px;   /* measured and updated by lk: the band a sticky / fixed header covers at the top */
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --lk-bg: #151618; --lk-surface: #1d1f23; --lk-fg: #ebe9e4; --lk-muted: #a8a59d; --lk-line: #393c43;
    --lk-accent: #8eaefc; --lk-accent-fg: #0d1830; --lk-accent-soft: #1d2945;
    --lk-ok: #74d19f; --lk-ok-soft: #15301f; --lk-bad: #ff8f85; --lk-bad-soft: #3b1b18; --lk-warn: #f0c35e; --lk-warn-soft: #382c10;
    --lk-mark-q: #5d2f27; --lk-mark-k: #56491a; --lk-mark-d: #243a5e; --lk-mark-x: #294826;
    --lk-shadow: 0 8px 28px rgb(0 0 0 / 0.5);
  }
}
:root[data-theme="dark"] {
  --lk-bg: #151618; --lk-surface: #1d1f23; --lk-fg: #ebe9e4; --lk-muted: #a8a59d; --lk-line: #393c43;
  --lk-accent: #8eaefc; --lk-accent-fg: #0d1830; --lk-accent-soft: #1d2945;
  --lk-ok: #74d19f; --lk-ok-soft: #15301f; --lk-bad: #ff8f85; --lk-bad-soft: #3b1b18; --lk-warn: #f0c35e; --lk-warn-soft: #382c10;
  --lk-mark-q: #5d2f27; --lk-mark-k: #56491a; --lk-mark-d: #243a5e; --lk-mark-x: #294826;
  --lk-shadow: 0 8px 28px rgb(0 0 0 / 0.5);
}

/* ---------- landing below a sticky header: the browser's own jumps (#id, scrollIntoView) keep clear of the
   covered band too. Zero specificity: a site rule wins. Do not also set scroll-padding-top on html (they add up). */
:where([data-lk], h2, h3, :target) { scroll-margin-top: calc(var(--lk-top-offset, 0px) + 12px); }

/* ---------- basics */
[data-lk-ui][hidden], [data-lk] > [data-part][hidden] { display: none !important; }
[data-lk-ui] { box-sizing: border-box; font-family: var(--lk-font); }
.lk-sr { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
:where([data-lk-ui], .lk-mark):focus-visible { outline: 3px solid var(--lk-accent); outline-offset: 2px; }
.lk-card { background: var(--lk-surface); color: var(--lk-fg); border: 1px solid var(--lk-line); border-radius: var(--lk-radius); padding: 16px 18px; margin: 16px 0; }
.lk-help { color: var(--lk-muted); font-size: 0.88em; margin: 6px 0; }
.lk-help[data-tone="bad"], p[data-tone="bad"] { color: var(--lk-bad); }
.lk-label { display: block; font-size: 0.9em; font-weight: 600; margin: 12px 0 6px; }
.lk-h { font-size: 1.1em; margin: 28px 0 10px; }
.lk-empty { padding: 16px; border: 1px dashed var(--lk-line); border-radius: var(--lk-radius); color: var(--lk-muted); background: var(--lk-surface); }
.lk-error { border: 1px dashed var(--lk-bad); color: var(--lk-bad); background: var(--lk-bad-soft); padding: 8px 12px; border-radius: var(--lk-radius-sm); font-size: 0.9em; margin: 8px 0; white-space: pre-wrap; }
.lk-fatal { margin: 12px; }
html[data-lk-debug] [data-lk] { outline: 1px dashed var(--lk-accent); outline-offset: 4px; }

/* ---------- buttons and fields */
.lk-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: var(--lk-hit); padding: 0 16px;
  border: 1px solid var(--lk-line); border-radius: var(--lk-radius-sm); background: var(--lk-surface); color: var(--lk-fg);
  font: inherit; font-size: 0.95em; line-height: 1.2; cursor: pointer; text-decoration: none; text-align: center;
}
.lk-btn:hover:not(:disabled) { border-color: var(--lk-accent); }
.lk-btn[data-variant="primary"] { background: var(--lk-accent); border-color: var(--lk-accent); color: var(--lk-accent-fg); font-weight: 600; }
.lk-btn[data-variant="primary"]:hover:not(:disabled) { filter: brightness(1.08); }
.lk-btn[data-variant="ghost"] { background: transparent; border-color: transparent; color: var(--lk-accent); }
.lk-btn[data-variant="ghost"]:hover:not(:disabled) { background: var(--lk-accent-soft); }
.lk-btn[data-variant="danger"] { color: var(--lk-bad); border-color: var(--lk-bad); background: transparent; }
.lk-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.lk-icon-btn { display: inline-grid; place-items: center; min-width: var(--lk-hit); min-height: var(--lk-hit); border: 1px solid var(--lk-line); border-radius: var(--lk-radius-sm); background: var(--lk-surface); color: var(--lk-fg); font: inherit; font-size: 1.1em; cursor: pointer; }
.lk-icon-btn:disabled { opacity: 0.35; cursor: default; }
.lk-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
.lk-input, .lk-ta, [data-lk-ui] select {
  min-height: var(--lk-hit); padding: 8px 12px; border: 1px solid var(--lk-line); border-radius: var(--lk-radius-sm);
  background: var(--lk-surface); color: var(--lk-fg); font: inherit;
}
.lk-input { width: min(14em, 100%); font-variant-numeric: tabular-nums; }
.lk-ta { display: block; width: 100%; min-height: 4.5em; resize: vertical; line-height: 1.5; }
.lk-input:disabled, .lk-ta:disabled { opacity: 1; background: var(--lk-bg); color: var(--lk-fg); }
.lk-badge { display: inline-block; padding: 2px 9px; border: 1px solid var(--lk-line); border-radius: 999px; font-size: 0.8em; line-height: 1.6; color: var(--lk-muted); }
.lk-badge[data-level="shaky"] { border-color: var(--lk-warn); color: var(--lk-warn); }
.lk-badge[data-tone="bad"], .lk-badge[data-level="new"] { border-color: var(--lk-bad); color: var(--lk-bad); }
.lk-badge[data-level="known"] { border-color: var(--lk-ok); color: var(--lk-ok); }

/* ---------- questions */
.lk-mq-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; font-size: 0.85em; color: var(--lk-muted); }
.lk-topic { color: var(--lk-muted); }
.lk-mq-state { margin-left: auto; font-weight: 600; }
.lk-mq[data-state="right"] .lk-mq-state { color: var(--lk-ok); }
.lk-mq[data-state="wrong"] .lk-mq-state { color: var(--lk-bad); }
.lk-mq-stem { margin: 10px 0 14px; font-size: 1.02em; line-height: 1.6; }
.lk-mq-stem > :first-child { margin-top: 0; }
.lk-mq-stem > :last-child { margin-bottom: 0; }
.lk-opts { border: 0; padding: 0; margin: 0; display: grid; gap: 8px; min-width: 0; }
.lk-opt {
  display: flex; align-items: flex-start; gap: 10px; min-height: var(--lk-hit); padding: 10px 12px;
  border: 1px solid var(--lk-line); border-radius: var(--lk-radius-sm); background: var(--lk-surface); cursor: pointer; line-height: 1.5;
}
.lk-opt input { flex: none; width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--lk-accent); }
.lk-opt-key { flex: none; min-width: 1.1em; font-weight: 600; color: var(--lk-muted); }
.lk-opt-text > :first-child { margin-top: 0; }
.lk-opt-text > :last-child { margin-bottom: 0; }
.lk-opt:hover { border-color: var(--lk-accent); }
.lk-opt:has(input:checked) { border-color: var(--lk-accent); background: var(--lk-accent-soft); }
.lk-opt:has(input:disabled) { cursor: default; }
.lk-opt-row[data-correct="true"] .lk-opt { border-color: var(--lk-ok); background: var(--lk-ok-soft); }
.lk-opt-row[data-picked="true"][data-correct="false"] .lk-opt { border-color: var(--lk-bad); background: var(--lk-bad-soft); }
.lk-why { margin: 6px 4px 2px 42px; font-size: 0.92em; line-height: 1.55; }
.lk-why-tag { font-weight: 600; }
.lk-opt-row[data-correct="true"] .lk-why-tag { color: var(--lk-ok); }
.lk-opt-row[data-picked="true"][data-correct="false"] .lk-why-tag { color: var(--lk-bad); }
.lk-num-row { display: flex; align-items: center; gap: 8px; }
.lk-unit { color: var(--lk-muted); }
.lk-order { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; counter-reset: lk-o; }
.lk-order-item { display: flex; align-items: center; gap: 10px; padding: 4px 4px 4px 12px; border: 1px solid var(--lk-line); border-radius: var(--lk-radius-sm); background: var(--lk-surface); }
.lk-order-item::before { counter-increment: lk-o; content: counter(lk-o); flex: none; min-width: 1.2em; font-weight: 600; color: var(--lk-muted); }
.lk-order-text { flex: 1; min-width: 0; }
.lk-order-btns { display: flex; gap: 4px; }
.lk-order-item[data-ok="true"] { border-color: var(--lk-ok); background: var(--lk-ok-soft); }
.lk-order-item[data-ok="false"] { border-color: var(--lk-bad); background: var(--lk-bad-soft); }
.lk-hints { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; }
.lk-hint { padding: 8px 12px; border-left: 3px solid var(--lk-accent); background: var(--lk-accent-soft); border-radius: 0 var(--lk-radius-sm) var(--lk-radius-sm) 0; line-height: 1.55; }
.lk-hint-n { font-weight: 600; margin-right: 8px; }
.lk-submit { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.lk-submit-label { color: var(--lk-muted); font-size: 0.9em; }
.lk-conf-btns { display: flex; flex-wrap: wrap; gap: 6px; }
.lk-conf-btn { border-color: var(--lk-accent); color: var(--lk-accent); font-weight: 600; }
.lk-conf-btn:hover:not(:disabled) { background: var(--lk-accent-soft); }
.lk-conf-btn[aria-pressed="true"] { background: var(--lk-accent); color: var(--lk-accent-fg); opacity: 1; }
.lk-help-wrap { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.lk-help-toggle::after { content: ""; width: 0.4em; height: 0.4em; margin: 0 0 0.2em 2px; border-right: 2px solid; border-bottom: 2px solid; transform: rotate(45deg); }
.lk-help-toggle[aria-expanded="true"]::after { margin: 0.25em 0 0 2px; transform: rotate(-135deg); }
.lk-help-menu { display: flex; flex-wrap: wrap; gap: 6px; }
.lk-fb { margin-top: 12px; line-height: 1.6; }
.lk-fb:empty { display: none; }
.lk-fb[data-tone="nudge"] { color: var(--lk-warn); font-weight: 600; }
.lk-verdict { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin: 0 0 8px; }
.lk-verdict-icon { display: inline-grid; place-items: center; width: 1.5em; height: 1.5em; border-radius: 50%; font-weight: 700; font-size: 0.9em; color: var(--lk-surface); background: var(--lk-muted); }
.lk-verdict[data-ok="true"] .lk-verdict-icon { background: var(--lk-ok); }
.lk-verdict[data-ok="false"] .lk-verdict-icon { background: var(--lk-bad); }
.lk-verdict[data-ok="true"] strong { color: var(--lk-ok); }
.lk-verdict[data-ok="false"] strong { color: var(--lk-bad); }
.lk-solution, .lk-ref { margin-top: 10px; padding: 10px 14px; border-radius: var(--lk-radius-sm); background: var(--lk-bg); border: 1px solid var(--lk-line); }
.lk-solution > :first-child, .lk-ref > :first-child { margin-top: 0; }
.lk-solution > :last-child, .lk-ref > :last-child { margin-bottom: 0; }
.lk-ref-h { font-weight: 600; margin: 0 0 6px; }
.lk-sched { color: var(--lk-muted); font-size: 0.85em; margin: 10px 0 0; }
.lk-selfgrade { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
.lk-after { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.lk-after:empty { display: none; }
.lk-retry-slot > .lk-mq { border-style: dashed; }

/* ---------- predict / checkpoint */
.lk-predict { margin: 12px 0; }
.lk-predict-opts { display: grid; gap: 8px; }
.lk-predict-opt {
  display: block; width: 100%; min-height: var(--lk-hit); padding: 10px 14px; text-align: left; line-height: 1.5;
  border: 1px solid var(--lk-line); border-radius: var(--lk-radius-sm); background: var(--lk-surface); color: var(--lk-fg); font: inherit; cursor: pointer;
  transition: background-color 0.2s, border-color 0.2s;
}
.lk-predict-opt:hover:not(:disabled) { border-color: var(--lk-accent); background: var(--lk-accent-soft); }
.lk-predict-opt:disabled { cursor: default; }
.lk-predict-opt[data-picked="true"] { border-width: 2px; border-color: var(--lk-accent); background: var(--lk-accent-soft); }
.lk-predict-opt[data-correct="true"] { border-color: var(--lk-ok); background: var(--lk-ok-soft); }
.lk-predict-opt[data-picked="true"][data-correct="false"] { border-color: var(--lk-bad); background: var(--lk-bad-soft); }
.lk-predict-opt[data-picked="true"]::after { content: " ←"; font-weight: 700; }
.lk-predict-msg { font-weight: 600; margin: 10px 0 0; }
.lk-predict-msg:empty { display: none; }
[data-lk="predict"][data-state="right"] .lk-predict-msg { color: var(--lk-ok); }
[data-lk="predict"][data-state="wrong"] .lk-predict-msg { color: var(--lk-bad); }
.lk-cp { margin-top: 8px; }
.lk-cp-note { margin: 6px 0; padding-left: 12px; border-left: 3px solid var(--lk-line); }
[data-lk-flash] { animation: lk-flash 1.8s ease-out; }
@keyframes lk-flash { from { background-color: var(--lk-accent-soft); } to { background-color: transparent; } }

/* ---------- highlights */
.lk-mark { color: inherit; border-radius: 2px; padding: 0 1px; cursor: pointer; background: var(--lk-mark-k); }
.lk-mark[data-color="q"] { background: var(--lk-mark-q); }
.lk-mark[data-color="d"] { background: var(--lk-mark-d); }
.lk-mark[data-color="x"] { background: var(--lk-mark-x); }
.lk-mark[data-note] { text-decoration: underline dotted; text-underline-offset: 3px; }
.lk-hl-bar { position: absolute; z-index: 1000; display: flex; flex-wrap: wrap; gap: 4px; padding: 4px; max-width: calc(100vw - 16px); background: var(--lk-surface); border: 1px solid var(--lk-line); border-radius: var(--lk-radius); box-shadow: var(--lk-shadow); }
.lk-hl-bar button { min-height: var(--lk-hit); min-width: var(--lk-hit); padding: 0 10px; border: 0; border-radius: var(--lk-radius-sm); background: transparent; color: var(--lk-fg); font: inherit; font-size: 0.9em; cursor: pointer; }
.lk-hl-bar button:hover { background: var(--lk-accent-soft); }
.lk-hl-color { box-shadow: inset 0 -5px 0 var(--lk-mark-k); }
.lk-hl-color[data-color="q"], .lk-chip[data-color="q"] { box-shadow: inset 0 -5px 0 var(--lk-mark-q); }
.lk-hl-color[data-color="d"], .lk-chip[data-color="d"] { box-shadow: inset 0 -5px 0 var(--lk-mark-d); }
.lk-hl-color[data-color="x"], .lk-chip[data-color="x"] { box-shadow: inset 0 -5px 0 var(--lk-mark-x); }
.lk-chip[data-color="k"] { box-shadow: inset 0 -5px 0 var(--lk-mark-k); }
.lk-hl-card { position: absolute; z-index: 1000; width: min(380px, calc(100vw - 16px)); margin: 0; box-shadow: var(--lk-shadow); }
.lk-hl-quote { margin: 0 0 8px; padding-left: 12px; border-left: 3px solid var(--lk-line); color: var(--lk-muted); line-height: 1.55; }

/* ---------- chips, dialogs */
.lk-chips { border: 0; padding: 0; margin: 10px 0; display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
.lk-chips > legend { font-size: 0.9em; font-weight: 600; margin-bottom: 6px; padding: 0; }
.lk-chip { display: inline-flex; align-items: center; gap: 6px; min-height: var(--lk-hit); padding: 4px 12px; border: 1px solid var(--lk-line); border-radius: 999px; cursor: pointer; line-height: 1.25; }
.lk-chip input { accent-color: var(--lk-accent); margin: 0; }
.lk-chip small { display: block; color: var(--lk-muted); font-size: 0.78em; }
.lk-chip:has(input:checked) { border-color: var(--lk-accent); background: var(--lk-accent-soft); }
.lk-chip:has(input:focus-visible) { outline: 3px solid var(--lk-accent); outline-offset: 2px; }
dialog.lk-ask { width: min(720px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 0; border: 1px solid var(--lk-line); border-radius: var(--lk-radius); background: var(--lk-surface); color: var(--lk-fg); box-shadow: var(--lk-shadow); }
dialog.lk-ask::backdrop, dialog.lk-lightbox::backdrop { background: rgb(0 0 0 / 0.45); }
.lk-ask-inner { padding: 14px 20px 18px; }
.lk-ask-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.lk-ask-head h2 { font-size: 1.15em; margin: 0; }
.lk-ask-text { font-family: var(--lk-mono); font-size: 0.85em; min-height: 12em; }
.lk-ask-links { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 6px; }
.lk-ask-grade { margin-top: 12px; padding-top: 8px; border-top: 1px solid var(--lk-line); }
dialog.lk-lightbox { max-width: 96vw; max-height: 96dvh; padding: 8px; border: 0; border-radius: var(--lk-radius); background: var(--lk-surface); color: var(--lk-fg); }
dialog.lk-lightbox img { display: block; max-width: 100%; max-height: 84dvh; object-fit: contain; margin: 0 auto; }
dialog.lk-lightbox .lk-icon-btn { float: right; }
/* A figure reserves its box before its image arrives. One image with a width attribute: the figure is that wide (never
   wider than the column; lk sets --lk-fig-w from the attribute); otherwise it takes the column. The image scales inside it
   with the aspect ratio of its width / height attributes. Not width: fit-content — that is measured from the loaded image,
   so a lazy image that arrives later moves everything below it. All zero-specificity defaults a site rule overrides. */
.lk-fig { position: relative; max-width: 100%; }
:where(.lk-fig) { width: var(--lk-fig-w, auto); }
:where(.lk-fig img) { max-width: 100%; height: auto; }
.lk-fig-zoom { position: absolute; top: 8px; right: 8px; min-width: var(--lk-hit); min-height: var(--lk-hit); border: 1px solid var(--lk-line); border-radius: 50%; background: color-mix(in srgb, var(--lk-surface) 88%, transparent); color: var(--lk-fg); font-size: 1.1em; cursor: pointer; }
.lk-status { position: fixed; left: 12px; bottom: 12px; z-index: 999; max-width: min(440px, calc(100vw - 24px)); padding: 10px 14px; border: 1px solid var(--lk-warn); border-radius: var(--lk-radius-sm); background: var(--lk-warn-soft); color: var(--lk-warn); font-size: 0.9em; line-height: 1.45; }

/* ---------- labs */
.lk-canvas { display: block; width: 100%; height: auto; max-width: 100%; border-radius: var(--lk-radius-sm); touch-action: pan-y; }
.lk-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; margin-top: 10px; }
.lk-ctl { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 8px; min-height: var(--lk-hit); max-width: 100%; }
.lk-ctl-label { font-size: 0.92em; }
.lk-ctl input[type="range"] { width: min(220px, 48vw); min-width: 0; flex: 1 1 120px; accent-color: var(--lk-accent); min-height: var(--lk-hit); }
.lk-ctl input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--lk-accent); }
.lk-ctl-out { min-width: 3.5em; font-variant-numeric: tabular-nums; color: var(--lk-muted); }
/* api.canvas(w, h, {fit: 'box'}): the site's CSS decides width and height; without a height the w:h aspect (zero specificity) */
:where(.lk-canvas[data-fit="box"]) { aspect-ratio: var(--lk-canvas-aspect, auto); }
/* handle.enable(false): still visible, not usable by the reader (tours still drive it) */
.lk-ctl[data-disabled] { opacity: 0.5; }
.lk-ctl[data-disabled] :is(input, select), button.lk-ctl[data-disabled] { cursor: not-allowed; }
/* data-gate: the note inside a lab whose prediction gate has not been answered yet */
.lk-gate-note { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin-top: 10px; padding: 6px 12px; border: 1px dashed var(--lk-line); border-radius: var(--lk-radius-sm); color: var(--lk-muted); font-size: 0.92em; }
.lk-gate-text { flex: 1 1 14em; min-width: 0; }

/* ---------- lab panel (dom/panel.js). lk's own frame: section.lk-panel > .lk-panel-head + the mount. A site frame (the
   mount's parent, labelled by a title in a strip before the mount) keeps its look; lk adds .lk-panel-tools to its strip.
   Both carry [data-lk-panel] and [data-lk-panel-head]. The frame line is a ring (box-shadow), so wrapping a mount does not
   change its width. */
.lk-panel { margin: 20px 0; background: var(--lk-surface); color: var(--lk-fg); border-radius: var(--lk-radius); box-shadow: 0 0 0 1px var(--lk-line); }
.lk-panel-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; min-height: 48px; padding: 7px 12px 7px 16px; border-bottom: 1px solid var(--lk-line); }
.lk-panel-tag { font-family: var(--lk-mono); font-size: 0.8em; letter-spacing: 0.06em; color: var(--lk-muted); }
.lk-panel-sep { color: var(--lk-muted); }
.lk-panel-title { font-weight: 600; }
:where(.lk-panel > [data-lk="lab"]) { padding: 14px 16px 16px; }
.lk-panel-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-left: auto; align-self: center; }
.lk-panel-tools:not(:has(> :not([hidden]))) { display: none; }
.lk-tool {
  position: relative; display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 11px 0 9px;
  border: 1px solid var(--lk-line); border-radius: var(--lk-radius-sm); background: var(--lk-surface); color: var(--lk-fg);
  font: inherit; font-size: 13px; line-height: 1; white-space: nowrap; cursor: pointer;
}
.lk-tool:hover:not(:disabled) { border-color: var(--lk-accent); color: var(--lk-accent); }
.lk-tool:disabled { opacity: 0.55; cursor: progress; }
.lk-tool svg { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.lk-tool svg .lk-fill { fill: currentColor; stroke: none; }
.lk-tool[data-on] { border-color: var(--lk-accent); background: var(--lk-accent-soft); color: var(--lk-accent); }
/* how far the demo has run: a hairline along the bottom of its button */
.lk-tool[data-tool="demo"]::after {
  content: ""; position: absolute; left: 7px; right: 7px; bottom: 3px; height: 2px; border-radius: 1px; background: currentColor;
  transform-origin: left center; transform: scaleX(var(--lk-demo-p, 0)); opacity: 0.75;
}
@media (pointer: coarse) { .lk-tool { min-height: var(--lk-hit); } }
@media (max-width: 600px) {
  .lk-panel-tools { flex: 1 1 100%; margin-left: 0; }
  .lk-panel-head { padding-left: 12px; }
  :where(.lk-panel > [data-lk="lab"]) { padding: 12px; }
}
/* 展开: the frame covers the window (the real full screen where the browser allows it); the strip stays at the top */
[data-lk-panel][data-lk-expanded] {
  position: fixed; inset: 0; z-index: 2147483000; display: flex; flex-direction: column; margin: 0; width: auto; max-width: none;
  height: auto; max-height: none; overflow: auto; overscroll-behavior: contain; border-radius: 0; background: var(--lk-surface); box-shadow: none;
}
[data-lk-panel][data-lk-expanded] > [data-lk-panel-head] { position: sticky; top: 0; z-index: 2; flex: none; background: var(--lk-surface); }
/* the stage in the middle of what is left (a lab taller than the window starts at the top and scrolls) */
[data-lk-panel][data-lk-expanded] > [data-lk="lab"] { box-sizing: border-box; width: 100%; max-width: var(--lk-panel-max, 1280px); margin: auto; flex: none; }
html[data-lk-expanded] { overflow: hidden; }

/* ---------- review, progress, notes, unit nav */
.lk-review-count { font-weight: 600; }
.lk-review-top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.lk-review-top progress { flex: 1 1 120px; height: 8px; accent-color: var(--lk-accent); }
.lk-review-pos { font-variant-numeric: tabular-nums; color: var(--lk-muted); }
.lk-review-filter { display: inline-flex; align-items: center; gap: 8px; }
.lk-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.lk-stat { padding: 14px 16px; border: 1px solid var(--lk-line); border-radius: var(--lk-radius); background: var(--lk-surface); }
.lk-stat-v { font-size: 2em; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.lk-stat-l { font-weight: 600; margin-top: 4px; }
.lk-stat-n, .lk-stat-cmp { color: var(--lk-muted); font-size: 0.85em; margin-top: 4px; }
.lk-stat-warn { color: var(--lk-bad); font-weight: 600; }
.lk-rows { list-style: none; margin: 0; padding: 0; }
.lk-row { padding: 10px 0; border-bottom: 1px solid var(--lk-line); }
.lk-row-inline { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.lk-row-inline > .lk-badge { flex: none; white-space: nowrap; }   /* a long name wraps, the badge stays one pill */
.lk-row-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.lk-bar { display: flex; height: 10px; margin: 8px 0 6px; border-radius: 999px; overflow: hidden; background: var(--lk-line); }
.lk-bar-seg[data-level="mastered"] { background: var(--lk-ok); }
.lk-bar-seg[data-level="learning"] { background: var(--lk-accent); }
.lk-bar-seg[data-level="weak"] { background: var(--lk-bad); }
.lk-bar-seg[data-level="new"] { background: transparent; }
.lk-row-counts { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 0.82em; color: var(--lk-muted); }
.lk-row-counts span::before { content: ""; display: inline-block; width: 0.7em; height: 0.7em; margin-right: 5px; border-radius: 2px; vertical-align: -0.05em; border: 1px solid var(--lk-line); }
.lk-row-counts [data-level="mastered"]::before { background: var(--lk-ok); }
.lk-row-counts [data-level="learning"]::before { background: var(--lk-accent); }
.lk-row-counts [data-level="weak"]::before { background: var(--lk-bad); }
.lk-note { padding: 12px 0; border-bottom: 1px solid var(--lk-line); }
.lk-note .lk-mq-head a { margin-left: auto; }
.lk-note-text { margin: 6px 0 0; }
.lk-diag-start { font-weight: 600; margin-top: 14px; }
.lk-unitnav { margin: 32px 0; }
.lk-unitnav-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.lk-unitnav-link { display: flex; flex-direction: column; justify-content: center; gap: 2px; min-height: var(--lk-hit); padding: 10px 14px; border: 1px solid var(--lk-line); border-radius: var(--lk-radius); background: var(--lk-surface); color: var(--lk-fg); text-decoration: none; }
.lk-unitnav-link:hover { border-color: var(--lk-accent); }
.lk-unitnav-link small { color: var(--lk-muted); }
.lk-unitnav-link[data-rel="next"] { text-align: right; grid-column: 2; }
.lk-unitnav-map { margin-top: 12px; }
.lk-unitnav-map summary { display: flex; align-items: center; min-height: var(--lk-hit); cursor: pointer; color: var(--lk-accent); }
.lk-unitnav-map ol { margin: 4px 0 0; padding-left: 1.6em; }
.lk-unitnav-map li > a, .lk-unitnav-map li > span { display: inline-flex; align-items: center; min-height: var(--lk-hit); }
.lk-unitnav-map li[data-state="current"] { font-weight: 600; }
.lk-unitnav-map small { color: var(--lk-muted); font-weight: 400; }

/* ---------- page layout (opt-in, the one place lk.css lays out a page): put .lk-layout on the element that holds the
   lesson (usually <main>). Its children sit in a text column at a readable measure; children with .lk-wide or data-wide
   (labs, figures, tables, media) break out to --lk-wide, and .lk-full / data-full to the whole width. Every column shrinks
   to the window, never overflowing it. The text track is sized first (min(measure, what fits)), so on a narrow window the
   text keeps its measure and the wide margins give way — a grid of three flexible tracks would starve the text instead. */
:root {
  --lk-measure: 42em;     /* the text column: ~42 CJK characters (1em each), ~85 Latin */
  --lk-wide: 1280px;      /* labs, figures, tables, media marked wide */
  --lk-gutter: 16px;      /* the least space on each side */
}
.lk-layout {
  display: grid;
  grid-template-columns:
    [full-start] minmax(var(--lk-gutter), 1fr)
    [wide-start] minmax(0, calc((var(--lk-wide) - var(--lk-measure)) / 2))
    [text-start] min(var(--lk-measure), 100% - 2 * var(--lk-gutter)) [text-end]
    minmax(0, calc((var(--lk-wide) - var(--lk-measure)) / 2)) [wide-end]
    minmax(var(--lk-gutter), 1fr) [full-end];
}
.lk-layout > * { grid-column: text; min-width: 0; }
.lk-layout > :is(.lk-wide, [data-wide]) { grid-column: wide; }
.lk-layout > :is(.lk-full, [data-full]) { grid-column: full; }

/* ---------- sidebar contents (ui/toc.js) — site chrome. Dark by default (--lk-toc-*). Docked from 900 px: while it is
   open, <body> is padded on the left by --lk-toc-w; below 900 px and in e-ink mode it is a drawer over the page, under the
   sticky header (--lk-top-offset). */
:root {
  --lk-toc-w: clamp(256px, 19vw, 312px);
  --lk-toc-top: 0px;      /* docked: where it starts (under a position: fixed full-width header: var(--lk-top-offset)) */
  --lk-toc-z: 880;        /* above the page and its sticky header, below the tour player (900) and dialogs */
  --lk-toc-bg: #15181c; --lk-toc-fg: #e9e6e0; --lk-toc-muted: #a5a29b; --lk-toc-line: #2d3137;
  --lk-toc-accent: #9dbbf7; --lk-toc-ok: #86d3a6; --lk-toc-hover: rgb(255 255 255 / 0.06); --lk-toc-current: rgb(255 255 255 / 0.09);
  --lk-toc-field: rgb(255 255 255 / 0.06);
}
:where([data-lk="toc"], [data-lk="eink"]) { display: contents; }
.lk-toc {
  position: fixed; z-index: var(--lk-toc-z); left: 0; top: var(--lk-toc-top); bottom: 0; width: var(--lk-toc-w);
  display: flex; flex-direction: column; background: var(--lk-toc-bg); color: var(--lk-toc-fg); color-scheme: dark;
  border-right: 1px solid var(--lk-toc-line); font-family: var(--lk-font); font-size: 14px; line-height: 1.45;
  visibility: hidden; transform: translateX(-100%);
}
html[data-lk-toc="open"] .lk-toc { visibility: visible; transform: none; }
.lk-toc-scrim { position: fixed; z-index: calc(var(--lk-toc-z) - 1); inset: var(--lk-top-offset, 0px) 0 0 0; background: rgb(0 0 0 / 0.36); }
html:not([data-lk-toc="open"]) .lk-toc-scrim { display: none; }
@media (min-width: 900px) {
  html[data-lk-toc="open"]:not([data-lk-eink]) body { padding-left: var(--lk-toc-w); }
  html[data-lk-toc="open"]:not([data-lk-eink]) .lk-status { left: calc(var(--lk-toc-w) + 12px); }
  html[data-lk-toc="open"]:not([data-lk-eink]) .lk-tour { left: calc(50% + var(--lk-toc-w) / 2); width: min(var(--lk-tour-max, 760px), calc(100vw - var(--lk-toc-w) - 24px)); }
  html:not([data-lk-eink]) :is(.lk-toc-scrim, .lk-toc-x) { display: none; }
}
@media (max-width: 899.98px) {
  .lk-toc { top: var(--lk-top-offset, 0px); width: min(88vw, 360px); box-shadow: var(--lk-shadow); transition: transform 0.2s ease, visibility 0s linear 0.2s; }
  html[data-lk-toc="open"] .lk-toc { transition: transform 0.2s ease; }
}
html[data-lk-eink] .lk-toc { top: 0; bottom: var(--lk-ek-bar-h); width: min(88vw, 360px); }
html[data-lk-eink] .lk-toc-scrim { inset: 0 0 var(--lk-ek-bar-h) 0; background: rgb(0 0 0 / 0.16); }
.lk-toc-head { position: relative; padding: 18px 16px 12px; border-bottom: 1px solid var(--lk-toc-line); }
.lk-toc-title { display: block; padding-right: 40px; color: var(--lk-toc-fg); font-size: 16px; font-weight: 700; line-height: 1.4; text-decoration: none; }
.lk-toc-title:hover { text-decoration: underline; text-underline-offset: 3px; }
.lk-toc-meta { margin: 4px 0 0; color: var(--lk-toc-muted); font-size: 12.5px; }
.lk-toc-x { position: absolute; top: 6px; right: 6px; min-width: var(--lk-hit); min-height: var(--lk-hit); border: 0; border-radius: var(--lk-radius-sm); background: transparent; color: var(--lk-toc-fg); font: inherit; font-size: 22px; line-height: 1; cursor: pointer; }
.lk-toc-x:hover { background: var(--lk-toc-hover); }
.lk-toc-search { padding: 10px 12px 6px; }
.lk-toc-q { width: 100%; min-height: 40px; padding: 8px 12px; border: 1px solid var(--lk-toc-line); border-radius: var(--lk-radius-sm); background: var(--lk-toc-field); color: var(--lk-toc-fg); font: inherit; font-size: 14px; }
.lk-toc-q::placeholder { color: var(--lk-toc-muted); opacity: 1; }
.lk-toc-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 4px 8px calc(20px + var(--lk-tour-bar-h, 0px)); scrollbar-width: thin; }
.lk-toc :focus-visible { outline: 2px solid var(--lk-toc-accent); outline-offset: -2px; }
.lk-toc ol { list-style: none; margin: 0; padding: 0; }
.lk-toc-part { margin: 14px 10px 4px; color: var(--lk-toc-muted); font-size: 12px; letter-spacing: 0.06em; }
.lk-toc-unit { display: grid; grid-template-columns: 1.1em minmax(0, 1fr) auto; align-items: baseline; gap: 1px 8px; min-height: var(--lk-hit); padding: 8px 10px 8px 7px; border-left: 3px solid transparent; border-radius: var(--lk-radius-sm); color: var(--lk-toc-fg); text-decoration: none; }
a.lk-toc-unit:hover { background: var(--lk-toc-hover); }
.lk-toc-mark { color: var(--lk-toc-muted); font-size: 12px; text-align: center; }
.lk-toc-mark::before { content: "○"; }
[data-state="done"] > .lk-toc-unit .lk-toc-mark::before { content: "✓"; color: var(--lk-toc-ok); }
[data-state="started"] > .lk-toc-unit .lk-toc-mark::before { content: "◐"; }
[data-state="planned"] > .lk-toc-unit .lk-toc-mark::before { content: "·"; }
[data-state="planned"] > .lk-toc-unit { color: var(--lk-toc-muted); }
.lk-toc-t { min-width: 0; overflow-wrap: anywhere; }
.lk-toc-n { margin-right: 2px; color: var(--lk-toc-muted); font-family: var(--lk-mono); font-size: 0.86em; }
.lk-toc-side { grid-column: 3; grid-row: 1 / span 2; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.lk-toc-min { color: var(--lk-toc-muted); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.lk-toc-sub { grid-column: 2; color: var(--lk-toc-muted); font-size: 12px; }
.lk-toc-core { padding: 0 4px; border: 1px solid var(--lk-toc-line); border-radius: 3px; color: var(--lk-toc-muted); font-size: 11px; line-height: 1.5; white-space: nowrap; }
.lk-toc-unit[aria-current="page"] { background: var(--lk-toc-current); border-left-color: var(--lk-toc-accent); }
.lk-toc-unit[aria-current="page"] .lk-toc-t { color: var(--lk-toc-accent); font-weight: 600; }
.lk-toc ol.lk-toc-secs { margin: 2px 0 8px calc(10px + 1.1em + 8px); border-left: 1px solid var(--lk-toc-line); }
.lk-toc-secs a { display: block; min-height: 36px; margin-left: -1px; padding: 9px 10px 9px 11px; border-left: 2px solid transparent; color: var(--lk-toc-muted); font-size: 13px; line-height: 1.4; text-decoration: none; }
.lk-toc-secs a:hover { background: var(--lk-toc-hover); color: var(--lk-toc-fg); }
.lk-toc-secs a[aria-current="location"] { border-left-color: var(--lk-toc-accent); color: var(--lk-toc-fg); font-weight: 600; }
.lk-toc-tools { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin: 12px 2px 0; padding-top: 12px; border-top: 1px solid var(--lk-toc-line); }
.lk-toc-tool { display: flex; align-items: center; justify-content: space-between; gap: 6px; min-height: var(--lk-hit); padding: 6px 10px 6px 7px; border-left: 3px solid transparent; border-radius: var(--lk-radius-sm); color: var(--lk-toc-fg); text-decoration: none; }
.lk-toc-tool:hover { background: var(--lk-toc-hover); }
.lk-toc-tool[aria-current="page"] { background: var(--lk-toc-current); border-left-color: var(--lk-toc-accent); }
.lk-toc-due { color: var(--lk-toc-accent); font-size: 11.5px; white-space: nowrap; }
.lk-toc-count { margin: 6px 10px; color: var(--lk-toc-muted); font-size: 12.5px; }
.lk-toc-hit { display: flex; flex-direction: column; justify-content: center; min-height: var(--lk-hit); padding: 7px 10px; border-radius: var(--lk-radius-sm); color: var(--lk-toc-fg); text-decoration: none; }
.lk-toc-hit small { color: var(--lk-toc-muted); font-size: 11.5px; }
.lk-toc-hit:hover { background: var(--lk-toc-hover); }
/* the toggle and the e-ink switch, wherever the site's header puts them */
.lk-toc-btn, .lk-eink-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-width: var(--lk-hit); min-height: var(--lk-hit); padding: 0 10px;
  border: 0; border-radius: var(--lk-radius-sm); background: transparent; color: inherit; font: inherit; font-size: 0.92em; white-space: nowrap; cursor: pointer;
}
.lk-toc-btn:hover, .lk-eink-btn:hover { background: color-mix(in srgb, currentColor 9%, transparent); }
.lk-btn-ico { display: inline-grid; }
.lk-btn-ico svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.5; }
.lk-toc-btn[aria-expanded="true"], .lk-eink-btn[aria-pressed="true"] { outline: 1.5px solid currentColor; outline-offset: -4px; }
.lk-toc-fab { position: fixed; z-index: calc(var(--lk-toc-z) + 1); top: calc(var(--lk-top-offset, 0px) + 8px); left: 8px; border: 1px solid var(--lk-line); background: var(--lk-surface); color: var(--lk-fg); }
@media (max-width: 560px) {
  .lk-toc-btn, .lk-eink-btn { padding: 0; }
  :is(.lk-toc-btn, .lk-eink-btn) .lk-btn-t { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}

/* ---------- e-ink reading mode (ui/einkswitch.js, eink/eink.js): html[data-lk-eink="mono|color|lcd"]. Page turns
   instead of scrolling, nothing moves, and on ink screens the colours are remapped for the panel. */
:root { --lk-ek-bar-h: 44px; }
/* every frame of a transition or an animation is a repaint (a flash on e-ink); shadows and blur are grey smears */
html[data-lk-eink], html[data-lk-eink] *, html[data-lk-eink] *::before, html[data-lk-eink] *::after {
  transition: none !important; animation: none !important; scroll-behavior: auto !important;
  box-shadow: none !important; text-shadow: none !important; backdrop-filter: none !important; -webkit-backdrop-filter: none !important;
}
html[data-lk-eink] { overflow-anchor: none; }
/* content-visibility makes scrollHeight an estimate: page ends and page numbers would drift */
html[data-lk-eink] * { content-visibility: visible !important; }
html[data-lk-eink] :is(button, a, [role="button"], .lk-opt, .lk-predict-opt):active { transform: none !important; }
/* only the hover effects that brighten; never *:hover { filter: none } — that would also strip the grey filter off the
   canvas or figure under a finger (and on a touch screen the hover sticks) */
html[data-lk-eink] :is(.lk-btn, .lk-toc-btn, .lk-eink-btn, .lk-opt, .lk-predict-opt, button):hover { filter: none !important; }
/* a sticky header is repainted on every turn and costs its height: the pager marks sticky elements static */
html[data-lk-eink] [data-lk-eink-static] { position: static !important; }
html[data-lk-eink] body { padding-bottom: calc(var(--lk-ek-bar-h) + var(--lk-tour-bar-h, 0px) + env(safe-area-inset-bottom, 0px)); }
html[data-lk-eink][data-lk-ek-fs] body { font-size: var(--lk-ek-fs); }
html[data-lk-eink][data-lk-ek-lh] body { line-height: var(--lk-ek-lh); }
html[data-lk-eink][data-lk-ek-meas] { --lk-measure: var(--lk-ek-measure); }
html[data-lk-eink][data-lk-ek-bold] body { font-weight: 600; }
html[data-lk-eink] .lk-tour { bottom: calc(var(--lk-ek-bar-h) + 8px); }
/* ink screens: a hard white page, black text (small coloured type blurs under a colour filter), light scrims (a large
   dark overlay is a full refresh with heavy ghosting), a light sidebar */
html:is([data-lk-eink="mono"], [data-lk-eink="color"]) {
  color-scheme: light;
  --lk-bg: #fff; --lk-surface: #fff; --lk-fg: #000; --lk-muted: #3a3a3a; --lk-line: #8c8c8c; --lk-accent-fg: #fff; --lk-shadow: none;
  --lk-toc-bg: #fff; --lk-toc-fg: #000; --lk-toc-muted: #3a3a3a; --lk-toc-line: #8c8c8c; --lk-toc-hover: transparent;
  --lk-toc-current: #ececec; --lk-toc-field: #fff; --lk-toc-ok: #000;
}
/* mono: the semantic colours on a grey ramp far enough apart to stay apart on a 16-level panel, every step dark enough to be text */
html[data-lk-eink="mono"] {
  --lk-accent: #000; --lk-accent-soft: #ebebeb; --lk-bad: #1f1f1f; --lk-bad-soft: #e4e4e4; --lk-ok: #3d3d3d; --lk-ok-soft: #f2f2f2;
  --lk-warn: #5c5c5c; --lk-warn-soft: #f3f3f3; --lk-mark-q: #d2d2d2; --lk-mark-k: #e0e0e0; --lk-mark-d: #ececec; --lk-mark-x: #f4f4f4;
  --lk-toc-accent: #000;
}
/* colour e-ink washes colours out by about a step and halves their resolution: only deep saturated hues, spread apart
   (danger pulled toward magenta, warning pressed to olive — red, orange and yellow crowd together on a faded panel),
   each ≥ 5.5:1 on white; colour only marks things (borders, tags, chart lines, highlights), text stays black */
html[data-lk-eink="color"] {
  --lk-accent: #0a3fa8; --lk-accent-soft: #cfdff8; --lk-ok: #0a6b2a; --lk-ok-soft: #c9e8d2; --lk-warn: #6b6100; --lk-warn-soft: #f0e6b8;
  --lk-bad: #b3001b; --lk-bad-soft: #f7cccc; --lk-mark-q: #ff9a93; --lk-mark-k: #ffd45c; --lk-mark-d: #8fbdff; --lk-mark-x: #7fdca6;
  --lk-toc-accent: #0a3fa8;
}
html:is([data-lk-eink="mono"], [data-lk-eink="color"]) body { background: #fff; color: #000; }
html:is([data-lk-eink="mono"], [data-lk-eink="color"]) :is(h1, h2, h3, h4, p, li, td, th, dt, dd, figcaption, blockquote) { color: #000; }
html:is([data-lk-eink="mono"], [data-lk-eink="color"]) :focus-visible { outline: 2px solid #000 !important; outline-offset: 2px; }
html:is([data-lk-eink="mono"], [data-lk-eink="color"]) .lk-toc { border-right: 2px solid #000; }
html:is([data-lk-eink="mono"], [data-lk-eink="color"]) dialog { border: 2px solid #000; }
html:is([data-lk-eink="mono"], [data-lk-eink="color"]) dialog::backdrop { background: rgb(0 0 0 / 0.16); }
/* a second code that survives a grey panel: right / wrong / picked by border style, highlights by underline style */
html:is([data-lk-eink="mono"], [data-lk-eink="color"]) :is(.lk-opt:has(input:checked), .lk-predict-opt[data-picked="true"]) { border: 2px solid #000; }
html:is([data-lk-eink="mono"], [data-lk-eink="color"]) :is(.lk-opt-row[data-correct="true"] .lk-opt, .lk-predict-opt[data-correct="true"]) { border: 4px double #000; }
html:is([data-lk-eink="mono"], [data-lk-eink="color"]) :is(.lk-opt-row[data-picked="true"][data-correct="false"] .lk-opt, .lk-predict-opt[data-picked="true"][data-correct="false"]) { border: 2px dashed #000; }
html:is([data-lk-eink="mono"], [data-lk-eink="color"]) .lk-mark { border-radius: 0; border-bottom: 4px double #000; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
html:is([data-lk-eink="mono"], [data-lk-eink="color"]) .lk-mark[data-color="q"] { border-bottom: 3px solid #000; }
html:is([data-lk-eink="mono"], [data-lk-eink="color"]) .lk-mark[data-color="d"] { border-bottom: 2px dashed #000; }
html:is([data-lk-eink="mono"], [data-lk-eink="color"]) .lk-mark[data-color="x"] { border-bottom: 3px dotted #000; }
html[data-lk-eink="mono"] .lk-mark { background: transparent; padding: 0; }
html:is([data-lk-eink="mono"], [data-lk-eink="color"]) :is(.lk-hl-color, .lk-chip[data-color]) { border-bottom: 4px double #000; }
html:is([data-lk-eink="mono"], [data-lk-eink="color"]) :is(.lk-hl-color, .lk-chip)[data-color="q"] { border-bottom: 3px solid #000; }
html:is([data-lk-eink="mono"], [data-lk-eink="color"]) :is(.lk-hl-color, .lk-chip)[data-color="d"] { border-bottom: 2px dashed #000; }
html:is([data-lk-eink="mono"], [data-lk-eink="color"]) :is(.lk-hl-color, .lk-chip)[data-color="x"] { border-bottom: 3px dotted #000; }
/* mastery bars: hatching instead of three greys that look alike */
html[data-lk-eink="mono"] :is(.lk-bar-seg, .lk-row-counts span)[data-level="mastered"] { --lk-ek-fill: #000; }
html[data-lk-eink="mono"] :is(.lk-bar-seg, .lk-row-counts span)[data-level="learning"] { --lk-ek-fill: repeating-linear-gradient(45deg, #000 0 2px, #fff 2px 6px); }
html[data-lk-eink="mono"] :is(.lk-bar-seg, .lk-row-counts span)[data-level="weak"] { --lk-ek-fill: repeating-linear-gradient(90deg, #000 0 1px, #fff 1px 5px); }
html[data-lk-eink="mono"] .lk-bar-seg[data-level] { background: var(--lk-ek-fill, transparent); }
html[data-lk-eink="mono"] .lk-row-counts span[data-level]::before { background: var(--lk-ek-fill, transparent); }
/* form controls draw in the browser's own colour unless told: a meaningless grey on mono, an off-key blue on colour */
html[data-lk-eink="mono"] :is(input, select, textarea, progress, meter) { accent-color: #000; color-scheme: light; }
html[data-lk-eink="color"] :is(input, select, textarea, progress, meter) { accent-color: var(--lk-accent); color-scheme: light; }
html[data-lk-eink="mono"] input[type="range"] { filter: grayscale(1); }
/* labs and pictures: a still, high-contrast picture (labs are told to stop animating through lk.mode.shot) */
html[data-lk-eink="mono"] canvas { filter: grayscale(1) contrast(1.25); }
html[data-lk-eink="color"] canvas { filter: saturate(1.55) contrast(1.12); }
html[data-lk-eink="mono"] [data-lk="lab"] svg { filter: grayscale(1) contrast(1.3); }
html[data-lk-eink="color"] [data-lk="lab"] svg { filter: saturate(1.5); }
/* the lab panel: no demo and no full-window view on a paged, still screen; on ink the frame is plain black on white */
html[data-lk-eink] .lk-tool:is([data-tool="demo"], [data-tool="expand"]) { display: none; }
html:is([data-lk-eink="mono"], [data-lk-eink="color"]) [data-lk-panel] { background: #fff; color: #000; border-color: #000; box-shadow: none; }
html:is([data-lk-eink="mono"], [data-lk-eink="color"]) .lk-panel { border: 2px solid #000; border-radius: 0; }
html:is([data-lk-eink="mono"], [data-lk-eink="color"]) [data-lk-panel-head] { background: #fff; border-bottom-color: #000; }
html:is([data-lk-eink="mono"], [data-lk-eink="color"]) :is(.lk-panel-tag, .lk-panel-sep, .lk-panel-title) { color: #000; }
html:is([data-lk-eink="mono"], [data-lk-eink="color"]) .lk-tool { border: 1.5px solid #000; background: #fff; color: #000; }
html[data-lk-eink="mono"][data-lk-ek-fig] :is(figure, .lk-fig) img { filter: grayscale(1) contrast(1.35) brightness(1.04); }
html[data-lk-eink="color"][data-lk-ek-fig] :is(figure, .lk-fig) img { filter: saturate(1.45) contrast(1.18); }
/* force grey (mono): putting the content on its own compositing layer is the only thing that stops LCD subpixel
   antialiasing from fringing glyphs with colour. On the content only — a filter on html or body turns position: fixed
   into absolute, and the bar and the mask would scroll away. */
html[data-lk-eink="mono"][data-lk-ek-gray] :is([data-lk-content], main) { filter: grayscale(1); }
/* the bar, the mask over the cut half-line, the settings, the first-visit note */
.lk-ek-bar {
  position: fixed; z-index: 870; left: 0; right: 0; bottom: 0; height: calc(var(--lk-ek-bar-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px); display: flex; align-items: stretch;
  background: var(--lk-surface); color: var(--lk-fg); border-top: 1px solid var(--lk-fg); font-family: var(--lk-font); font-size: 13px;
}
.lk-ek-bar button { flex: none; min-width: var(--lk-hit); min-height: var(--lk-ek-bar-h); padding: 0 14px; border: 0; border-right: 1px solid var(--lk-line); background: var(--lk-surface); color: inherit; font: inherit; white-space: nowrap; cursor: pointer; }
.lk-ek-bar button:last-child { border-right: 0; }
.lk-ek-bar button:disabled { opacity: 0.35; cursor: default; }
.lk-ek-bar .lk-ek-nav { min-width: 56px; font-size: 17px; font-weight: 700; }
.lk-ek-mid { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 0 8px; border-right: 1px solid var(--lk-line); line-height: 1.3; }
.lk-ek-mid b { font-variant-numeric: tabular-nums; }
.lk-ek-mid span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--lk-muted); font-size: 11px; }
.lk-ek-clock { display: flex; flex-direction: column; align-items: flex-end; justify-content: center; padding: 0 12px; border-right: 1px solid var(--lk-line); color: var(--lk-muted); font-size: 11px; line-height: 1.3; white-space: nowrap; }
.lk-ek-clock b { color: var(--lk-fg); font-size: 12px; font-variant-numeric: tabular-nums; }
.lk-ek-clock[hidden] { display: none; }
@media (max-width: 520px) { .lk-ek-clock { display: none; } .lk-ek-bar button { padding: 0 10px; } }
.lk-ek-mask { position: fixed; z-index: 869; left: 0; right: 0; bottom: calc(var(--lk-ek-bar-h) + env(safe-area-inset-bottom, 0px)); height: 0; background: var(--lk-bg); pointer-events: none; }
.lk-ek-flash { position: fixed; inset: 0; z-index: 2147483000; background: #000; pointer-events: none; }
.lk-ek-range { display: inline-flex; align-items: center; gap: 4px; min-width: 0; flex: 1 1 auto; max-width: 100%; }
html[data-lk-eink] .lk-ek-range > input[type="range"] { flex: 1 1 auto; width: auto; min-width: 0; }
/* a slider with step buttons gets a row of its own under its label and value (a site's narrow control grid would squeeze it to nothing) */
html[data-lk-eink] .lk-ctl:has(> .lk-ek-range) { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
html[data-lk-eink] .lk-ctl > .lk-ek-range { order: 1; flex: 1 1 100%; }
.lk-ek-step { flex: none; min-width: var(--lk-hit); min-height: var(--lk-hit); border: 1px solid var(--lk-fg); border-radius: var(--lk-radius-sm); background: var(--lk-surface); color: var(--lk-fg); font: inherit; font-size: 16px; line-height: 1; cursor: pointer; }
dialog.lk-ek-set { width: min(600px, calc(100vw - 16px)); max-height: calc(100dvh - 16px); padding: 0; border: 2px solid var(--lk-fg); border-radius: var(--lk-radius); background: var(--lk-surface); color: var(--lk-fg); }
.lk-ek-set-in { padding: 12px 16px 16px; font-size: 14px; }
.lk-ek-set-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.lk-ek-set-head h2 { margin: 0; font-size: 16px; }
.lk-ek-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--lk-line); }
.lk-ek-lab { flex: 0 0 4.5em; color: var(--lk-muted); font-size: 13px; }
.lk-ek-opts { flex: 1; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-width: 0; }
.lk-ek-opt { min-height: var(--lk-hit); padding: 6px 12px; border: 1px solid var(--lk-fg); border-radius: var(--lk-radius-sm); background: var(--lk-surface); color: var(--lk-fg); font: inherit; font-size: 13px; cursor: pointer; }
.lk-ek-opt[aria-pressed="true"] { background: var(--lk-fg); color: var(--lk-surface); }
.lk-ek-val { min-width: 3.5em; text-align: center; font-variant-numeric: tabular-nums; }
.lk-ek-hint { flex: 1 1 100%; margin: 2px 0 0; color: var(--lk-muted); font-size: 12px; line-height: 1.6; }
.lk-ek-actions { border-bottom: 0; }
.lk-ek-note { margin: 8px 0 0; color: var(--lk-muted); font-size: 12px; line-height: 1.7; }
.lk-ek-tip { position: fixed; z-index: 871; left: 10px; right: 10px; bottom: calc(var(--lk-ek-bar-h) + 10px); display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; padding: 10px 12px; border: 2px solid var(--lk-fg); background: var(--lk-surface); color: var(--lk-fg); font-size: 13px; line-height: 1.6; }
.lk-ek-tip-t { flex: 1 1 260px; }

/* ---------- modes */
@media (prefers-reduced-motion: reduce) {
  [data-lk-ui], [data-lk-flash] { transition: none !important; animation: none !important; }
}
html[data-lk-shot] [data-lk-ui], html[data-lk-shot] [data-lk-flash] { transition: none !important; animation: none !important; }
html[data-lk-film] :is(.lk-hl-bar, .lk-hl-card, .lk-status, .lk-help-wrap, .lk-fig-zoom, .lk-toc, .lk-toc-scrim, .lk-toc-btn, .lk-eink-btn, .lk-panel-tools) { display: none !important; }

/* D13: printing never shows hints, answers or explanations of unanswered questions, nor any controls. */
@media print {
  :is(.lk-hl-bar, .lk-hl-card, .lk-status, .lk-actions, .lk-after, .lk-help-wrap, .lk-fig-zoom, .lk-controls, .lk-unitnav-map, .lk-panel-tools, dialog) { display: none !important; }
  :is(.lk-toc, .lk-toc-scrim, .lk-toc-btn, .lk-eink-btn, .lk-ek-bar, .lk-ek-mask, .lk-ek-tip, .lk-ek-step) { display: none !important; }
  html[data-lk-toc] body { padding-left: 0 !important; }
  html[data-lk-eink] body { padding-bottom: 0 !important; }
  .lk-mq[data-state="open"] :is(.lk-hints, .lk-fb, .lk-why, .lk-solution, .lk-ref) { display: none !important; }
  [data-lk="predict"]:not([data-state]) > [data-part="reveal"] { display: none !important; }
  /* only what still fits when moved whole: a question with its hints and feedback is often taller than a page, and keeping
     it whole would push out a page of blank paper and clip its end (learned with the old shell's PDF export) */
  .lk-card { box-shadow: none; }
  :is(.lk-card:not(.lk-mq), .lk-stat, .lk-opt-row, .lk-hint, figure, tr) { break-inside: avoid; }
}
