/* The site's shared look (2026-11-21): design tokens, type, focus, loading
   outlines, in-page dialogs and toasts, empty states and field messages.
   Every page loads it (with shared/ui.js); pages keep their own layouts.

   Tokens - a small fixed set, so everything feels of a piece:
     radius   --r-sm 8px (controls) · --r 12px (cards) · --r-lg 16px (panels) · --r-pill
     shadow   --sh-1 (resting) · --sh-2 (raised: menus, cards on hover) · --sh-3 (windows)
     type     --fs-xs .75 · --fs-sm .8125 · --fs-md .875 · --fs-body .9375 · --fs-base 1 ·
              --fs-lg 1.125 · --fs-xl 1.25 · --fs-2xl 1.5 · --fs-3xl 1.875 · --fs-4xl 2.25 (rem) */
:root {
  --r-sm: 8px; --r: 12px; --r-lg: 16px; --r-pill: 999px;
  --sh-1: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 1px rgba(15, 23, 42, .04);
  --sh-2: 0 4px 12px rgba(15, 23, 42, .08), 0 1px 3px rgba(15, 23, 42, .06);
  --sh-3: 0 18px 48px rgba(15, 23, 42, .18), 0 4px 12px rgba(15, 23, 42, .08);
  --fs-xs: .75rem; --fs-sm: .8125rem; --fs-md: .875rem; --fs-body: .9375rem; --fs-base: 1rem; --fs-lg: 1.125rem; --fs-xl: 1.25rem; --fs-2xl: 1.5rem; --fs-3xl: 1.875rem; --fs-4xl: 2.25rem;
  --focus: #6A2C7E;
}
[data-theme="dark"] { --sh-1: 0 1px 2px rgba(0, 0, 0, .4); --sh-2: 0 6px 16px rgba(0, 0, 0, .45); --sh-3: 0 20px 52px rgba(0, 0, 0, .6); --focus: #D6B0EA; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --sh-1: 0 1px 2px rgba(0, 0, 0, .4); --sh-2: 0 6px 16px rgba(0, 0, 0, .45); --sh-3: 0 20px 52px rgba(0, 0, 0, .6); --focus: #D6B0EA; } }

/* ── Type: even heading lines, no lone last word, digits that line up ── */
/* Inter draws "x" between digits as "×" (its contextual alternates): "7x1" became "7×1"
   and plain-text maths like "3x2 + 4x" read as times - so that's off everywhere (2026-11-22). */
html { font-feature-settings: "calt" 0; }
html { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-rendering: optimizeLegibility; font-kerning: normal; }
h1, h2, h3, h4, legend, figcaption, .lead { text-wrap: balance; }
p, li, dd, blockquote, .sub, .hint, .field-help, td { text-wrap: pretty; }
table, time, .timer, .score, .grade, .stat-value, .report-stat-value, .progress-grid .big, .tally, .countdown, .tab-count, .tnav-count, .check-result, .ra-rate,
[class*="score"], [class*="grade-"], [class*="-grade"], [class*="marks"], input[type="number"] { font-variant-numeric: tabular-nums; }

/* ── One focus ring: soft brand colour, for the keyboard only ───────── */
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--focus) !important; outline-offset: 2px !important; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline-offset: 0 !important; box-shadow: 0 0 0 4px color-mix(in srgb, var(--focus) 18%, transparent); }
header :focus-visible, nav.portal-nav :focus-visible, .bar :focus-visible, .tnav-header :focus-visible { outline-color: #F0B93B !important; }

/* ── Loading: an outline of what's coming, not the word "Loading" ──── */
@keyframes ui-shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }
.ui-skeleton { display: grid; gap: 10px; padding: 4px 0; }
.ui-skel { display: block; height: 12px; border-radius: var(--r-sm, 8px); background: linear-gradient(90deg, rgba(120,120,140,.12) 25%, rgba(120,120,140,.22) 37%, rgba(120,120,140,.12) 63%); background-size: 400% 100%; animation: ui-shimmer 1.4s ease infinite; }
.ui-skel:nth-child(1) { width: 62%; height: 14px; } .ui-skel:nth-child(2) { width: 92%; } .ui-skel:nth-child(3) { width: 78%; } .ui-skel:nth-child(4) { width: 85%; }
@media (prefers-reduced-motion: reduce) { .ui-skel { animation: none; } }

/* ── In-page dialogs (UI.ask / UI.tell) ─────────────────────────────── */
.ui-dialog { position: fixed; inset: 0; z-index: 2000; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(15, 23, 42, .38); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.ui-dialog-box { width: min(420px, 100%); background: var(--white, #fff); color: var(--grey-800, #1F2937); border-radius: var(--r-lg); box-shadow: var(--sh-3); padding: 20px 20px 16px; border: .5px solid rgba(0,0,0,.08); }
.ui-dialog-box p { margin: 0 0 14px; font-size: var(--fs-base); line-height: 1.45; white-space: pre-line; }
.ui-dialog-box input { width: 100%; box-sizing: border-box; font: inherit; padding: 9px 11px; border-radius: var(--r-sm); border: 1px solid var(--grey-200, #E5E7EB); margin: 0 0 14px; background: var(--white, #fff); color: inherit; }
.ui-dialog-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.ui-dialog-actions button { font: inherit; font-size: var(--fs-md); font-weight: 600; min-height: 36px; padding: 7px 16px; border-radius: var(--r-sm); cursor: pointer; border: 1px solid var(--grey-200, #E5E7EB); background: var(--white, #fff); color: var(--grey-800, #1F2937); }
.ui-dialog-actions .ui-ok { background: var(--teal, #6A2C7E); border-color: var(--teal, #6A2C7E); color: #fff; }
.ui-dialog-actions .ui-ok.ui-danger { background: #B91C1C; border-color: #B91C1C; }
[data-theme="dark"] .ui-dialog-box { border-color: rgba(255,255,255,.1); }

/* ── Toasts (UI.toast): a quiet note at the bottom, with Undo where it helps ── */
.ui-toasts { position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 2100; display: grid; gap: 8px; width: max-content; max-width: calc(100vw - 24px); pointer-events: none; }
.ui-toast { pointer-events: auto; display: flex; align-items: center; gap: 14px; padding: 10px 12px 10px 16px; border-radius: var(--r); background: rgba(28, 28, 32, .94); color: #fff; font-size: var(--fs-md); box-shadow: var(--sh-3); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); animation: ui-toast-in 260ms cubic-bezier(.32,.72,0,1); }
.ui-toast.leaving { opacity: 0; transform: translateY(6px); transition: opacity 180ms ease, transform 180ms ease; }
.ui-toast button { font: inherit; font-weight: 700; color: #F0B93B; background: none; border: 0; padding: 4px 6px; border-radius: var(--r-sm, 8px); cursor: pointer; }
@keyframes ui-toast-in { from { opacity: 0; transform: translateY(10px) scale(.98); } }

/* ── Empty states: what will appear here, and the one thing to do ───── */
.ui-empty { text-align: center; padding: 22px 16px; color: var(--grey-600, #4B5563); border: 1px dashed var(--grey-200, #E5E7EB); border-radius: var(--r); background: color-mix(in srgb, var(--grey-50, #F9FAFB) 60%, transparent); }
.ui-empty strong { display: block; color: var(--grey-800, #1F2937); font-size: var(--fs-base); margin-bottom: 4px; }
.ui-empty p { margin: 0 auto 10px; max-width: 42ch; font-size: var(--fs-md); }
.ui-empty a, .ui-empty button { font-weight: 600; }

/* ── Field messages (inline checks as you go) ───────────────────────── */
.ui-field-msg { display: block; font-size: var(--fs-sm); font-weight: 500; color: #B91C1C; margin: 4px 0 2px; }
[data-theme="dark"] .ui-field-msg { color: #F49B93; }
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: #DA2323 !important; }

/* ── ⌘K hint ─────────────────────────────────────────────────────────── */
.ui-kbd { font: 600 .7rem/1 -apple-system, 'Inter', system-ui, sans-serif; padding: 3px 5px; border-radius: var(--r-sm, 8px); border: .5px solid currentColor; opacity: .6; margin-left: 6px; }

/* ── A small "nothing here yet" note inside a card, cell or list ───────── */
.ui-none { margin: 4px 0; font-size: var(--fs-sm); color: var(--grey-600, #4B5563); }

/* ── Links: the brand's link colour wherever a page doesn't set one (never the browser's blue) ── */
:where(a:not([class])) { color: #5E2670; text-underline-offset: 2px; }
:where(a:not([class])):hover { color: #6A2C7E; }
[data-theme="dark"] :where(a:not([class])) { color: #D6B0EA; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) :where(a:not([class])) { color: #D6B0EA; } }

/* ── Light / dark: the browser's own controls follow the choice too ────── */
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

/* ── The theme switch (UI.themeSwitch): a button and a three-way menu ──── */
.ui-theme { position: relative; display: inline-flex; }
.ui-theme-btn { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; padding: 0; border-radius: var(--r-sm); border: .5px solid rgba(255,255,255,.28); background: rgba(255,255,255,.1); color: #fff; cursor: pointer; }
.ui-theme-btn:hover { background: rgba(255,255,255,.18); }
.ui-theme-btn svg { width: 18px; height: 18px; }
.ui-theme-menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 1200; min-width: 176px; padding: 5px; border-radius: var(--r); background: var(--white, #fff); color: var(--grey-800, #1F2937); border: .5px solid rgba(0,0,0,.1); box-shadow: var(--sh-3); animation: mo-pop 180ms cubic-bezier(.32,.72,0,1); transform-origin: top right; }
.ui-theme-menu[hidden] { display: none; }
.ui-theme-menu button { display: flex; align-items: center; gap: 9px; width: 100%; padding: 8px 10px; border: 0; border-radius: 7px; background: none; color: inherit; font: inherit; font-size: var(--fs-md); text-align: left; cursor: pointer; }
.ui-theme-menu button:hover, .ui-theme-menu button:focus-visible { background: color-mix(in srgb, var(--teal, #6A2C7E) 12%, transparent); }
.ui-theme-menu button svg { width: 16px; height: 16px; opacity: .8; }
.ui-theme-menu button .tick { margin-left: auto; visibility: hidden; color: var(--teal, #6A2C7E); }
.ui-theme-menu button[aria-checked="true"] { font-weight: 600; } .ui-theme-menu button[aria-checked="true"] .tick { visibility: visible; }
[data-theme="dark"] .ui-theme-menu { border-color: rgba(255,255,255,.12); } [data-theme="dark"] .ui-theme-menu button .tick { color: #D6B0EA; }
header .ui-theme { order: 5; margin-left: 6px; }
header .site-nav .ui-theme, header .header-links .ui-theme { order: 0; margin-left: 4px; vertical-align: middle; }
@media (max-width: 760px) { header .tnav-menu-btn ~ .ui-theme, header .ui-theme:has(+ .tnav-menu-btn) { order: 0; margin-left: auto; } header .ui-theme + .tnav-menu-btn { margin-left: 6px; } }
@media (max-width: 640px) { header.site-header .ui-theme { order: 1; margin-left: auto; } header.site-header .hd-btns { margin-left: 6px; } }
