/* Shared styles for index.html (report) and app.html (web app).
   Color: ink for actions (--primary), one blue accent for links and highlights (--accent); ok/warn/bad are status only.
   Shape: buttons are pills, containers --radius, inputs --radius-sm, badges 6px. */
:root {
  --bg: #f8fafc;
  --surface: #fdfefe;
  --surface-2: #e8ecf1;
  --text: #0f172a;
  --muted: #475569;
  --border: #e2e8f0;
  --border-strong: #94a3b8;
  --primary: #0f172a;
  --primary-strong: #334155;
  --on-primary: #f8fafc;
  --accent: #0369a1;
  --accent-strong: #075985;
  --info-bg: #e0f2fe;
  --ok: #166534;
  --ok-bg: #dcfce7;
  --warn: #854d0e;
  --warn-bg: #fef3c7;
  --bad: #b91c1c;
  --bad-bg: #fee2e2;
  --radius: 16px;
  --radius-sm: 12px;
  --shadow: 0 8px 24px rgb(15 23 42 / 0.16);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --font: "Be Vietnam Pro", "Noto Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --surface: #111827;
    --surface-2: #1e293b;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --border: #1e293b;
    --border-strong: #475569;
    --primary: #f1f5f9;
    --primary-strong: #cbd5e1;
    --on-primary: #0f172a;
    --accent: #38bdf8;
    --accent-strong: #7dd3fc;
    --info-bg: #0c2a3d;
    --ok: #4ade80;
    --ok-bg: #0f2e1d;
    --warn: #fbbf24;
    --warn-bg: #33270a;
    --bad: #f87171;
    --bad-bg: #3a1414;
    --shadow: 0 8px 24px rgb(0 0 0 / 0.5);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 76px; }
/* Reduced motion: keep end states, drop the movement. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important; animation-delay: 0s !important; animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important; scroll-behavior: auto !important;
  }
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.65 var(--font);
  -webkit-text-size-adjust: 100%;
}
img, svg { max-width: 100%; }
a { color: var(--accent); text-underline-offset: 3px; }
a:hover { color: var(--accent-strong); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
main:focus { outline: none; } /* focused by script on view change, not a control */
/* Line-height stays at 1.15 or above: Vietnamese stacked diacritics clip below that. */
h1, h2, h3, h4 { line-height: 1.2; margin: 0 0 0.5em; letter-spacing: -0.02em; text-wrap: balance; }
h1 { font-size: clamp(1.9rem, 4.2vw, 2.75rem); font-weight: 800; line-height: 1.15; letter-spacing: -0.03em; }
h2 { font-size: clamp(1.4rem, 3.2vw, 1.85rem); font-weight: 800; letter-spacing: -0.025em; }
h3, .h3 { font-size: 1.15rem; font-weight: 600; letter-spacing: -0.01em; }
h4 { font-size: 1rem; font-weight: 600; letter-spacing: 0; }
b, strong { font-weight: 600; }
p { margin: 0 0 1em; text-wrap: pretty; }
code { font-size: 0.9em; background: var(--surface-2); padding: 1px 6px; border-radius: 6px; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: 8px; top: -60px; background: var(--primary); color: var(--on-primary); padding: 8px 14px; border-radius: 999px; z-index: 100; }
.skip-link:focus { top: 8px; color: var(--on-primary); }
.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }

/* Layout */
.container { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.site-header {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.site-header .container { display: flex; align-items: center; gap: 4px 12px; min-height: 60px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 1.05rem; letter-spacing: -0.02em; color: var(--text); text-decoration: none; }
.brand:hover { color: var(--text); }
.brand .icon { color: var(--accent); width: 24px; height: 24px; }
.nav { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; margin-left: auto; }
.nav a { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 999px; text-decoration: none; color: var(--muted); font-weight: 500; font-size: 0.9rem; white-space: nowrap; transition: background-color 0.15s, color 0.15s; }
.nav .icon { width: 16px; height: 16px; }
/* Phones: keep the four links on one row. The GitHub link shows its icon only (it has an aria-label). */
@media (max-width: 520px) {
  .nav { gap: 0; }
  .nav a { padding: 8px 4px; gap: 4px; font-size: 0.8rem; }
  .nav .wide-only { display: none; }
}
.nav a:hover { color: var(--text); background: var(--surface-2); }
.nav a[aria-current="page"] { color: var(--text); font-weight: 600; }
.site-footer { border-top: 1px solid var(--border); padding: 24px 0 48px; margin-top: 64px; }
.site-footer p { max-width: 65ch; }

/* Buttons & forms */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 8px 20px;
  border: 1px solid var(--border-strong); border-radius: 999px;
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; white-space: nowrap; cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, transform 0.1s var(--ease-out);
}
.btn:hover { background: var(--surface-2); color: var(--text); }
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-strong); border-color: var(--primary-strong); color: var(--on-primary); }
.btn-sm { min-height: 36px; padding: 4px 14px; font-size: 0.875rem; }
.btn-danger { color: var(--bad); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
label { display: block; font-weight: 500; font-size: 0.875rem; margin-bottom: 6px; }
input, select {
  width: 100%; min-height: 44px; padding: 8px 12px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit;
  transition: border-color 0.15s;
}
input:hover, select:hover { border-color: var(--muted); }
input::placeholder { color: var(--muted); }
input[type="number"] { width: 5.5rem; font-variant-numeric: tabular-nums; }
.field { margin-bottom: 12px; }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); align-items: end; }
.form-grid .field { margin: 0; }

/* Cards, badges, tables */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; transition: border-color 0.15s; }
.card > :last-child { margin-bottom: 0; }
.card .badge + p { margin-top: 10px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid .card:hover { border-color: var(--border-strong); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 0.8rem; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-bad { background: var(--bad-bg); color: var(--bad); }
.badge-info { background: var(--info-bg); color: var(--accent-strong); }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 0.925rem; }
th, td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 0.8rem; font-weight: 600; color: var(--muted); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td:first-child { min-width: 9rem; }
tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 45%, transparent); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.callout { background: var(--info-bg); padding: 14px 18px; border-radius: var(--radius); margin: 16px 0; }
.callout-warn { background: var(--warn-bg); }
/* Hairline-divided cells: one bordered container, no separate cards. */
.stats { display: grid; gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.stats > * { background: var(--surface); padding: 16px 18px; }

/* ---------- Report page ---------- */
.hero { padding: 40px 0 0; }
.hero-grid { display: grid; gap: 32px; align-items: center; }
@media (min-width: 900px) {
  .hero { padding: 72px 0 0; }
  .hero-grid { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 56px; }
}
.hero .lead { font-size: 1.125rem; color: var(--muted); max-width: 46ch; margin: 0; }
.hero .actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 28px; }
.hero-photo { margin: 0; }
.hero-photo img { display: block; width: 100%; height: auto; aspect-ratio: 960 / 516; object-fit: cover; border-radius: var(--radius); }
.eyebrow { font-size: 0.875rem; font-weight: 600; color: var(--accent); margin-bottom: 12px; }
/* Key figures under the hero: plain numbers on hairlines, not cards. */
.figures { display: grid; margin: 48px 0 0; padding: 0; list-style: none; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.figures li { padding: 20px 0; border-top: 1px solid var(--border); }
.figures li:first-child { border-top: 0; }
.figures b { display: block; font-size: clamp(1.7rem, 3.6vw, 2.4rem); font-weight: 800; line-height: 1.15; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.figures span { color: var(--muted); font-size: 0.925rem; }
@media (min-width: 760px) {
  .figures { grid-template-columns: repeat(3, 1fr); }
  .figures li { border-top: 0; padding: 24px 28px; border-left: 1px solid var(--border); }
  .figures li:first-child { border-left: 0; padding-left: 0; }
}
.report { display: grid; gap: 40px; padding-top: 48px; }
.report > * { min-width: 0; }
@media (min-width: 960px) { .report { grid-template-columns: 230px minmax(0, 1fr); gap: 64px; } }
.toc { font-size: 0.9rem; }
.toc details { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 16px; }
.toc summary { cursor: pointer; font-weight: 600; min-height: 36px; display: flex; align-items: center; }
.toc ol { list-style: none; padding: 0; margin: 8px 0; }
.toc a { display: block; padding: 5px 0 5px 12px; border-left: 2px solid var(--border); color: var(--muted); text-decoration: none; transition: color 0.15s, border-color 0.15s; }
.toc a:hover { color: var(--text); }
.toc a[aria-current] { color: var(--text); font-weight: 600; border-left-color: var(--accent); }
@media (min-width: 960px) {
  .toc > div { position: sticky; top: 84px; }
  .toc details { border: 0; background: none; padding: 0; }
}
.report-body { max-width: 760px; }
.report-body section { padding-bottom: 40px; margin-bottom: 40px; border-bottom: 1px solid var(--border); }
.report-body section:last-child { border-bottom: 0; margin-bottom: 0; }
.report-body h3 { margin-top: 2em; }
.report-body ul, .report-body ol { padding-left: 22px; }
.report-body li { margin-bottom: 8px; }
.report-body li::marker { color: var(--muted); }
.front h2 { font-size: 1.1rem; font-weight: 600; letter-spacing: -0.01em; margin-top: 1.5em; }
.front h2:first-child { margin-top: 0; }
.front ul { list-style: none; padding: 0 !important; font-size: 0.925rem; }
.sec-num { color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; margin-right: 8px; }
.rows > div { display: grid; gap: 4px 24px; padding: 16px 0; border-top: 1px solid var(--border); }
.rows h4, .rows p:last-child { margin: 0; }
.rows p { margin-bottom: 6px; }
@media (min-width: 640px) { .rows > div { grid-template-columns: 200px 1fr; } }
.steps { counter-reset: step; list-style: none; padding: 0 !important; }
.steps li { counter-increment: step; position: relative; padding-left: 44px; margin-bottom: 16px; }
.steps li::before {
  content: counter(step); position: absolute; left: 0; top: 0;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--info-bg); color: var(--accent-strong);
  display: grid; place-items: center; font-weight: 600; font-size: 0.875rem; font-variant-numeric: tabular-nums;
}
figure { margin: 24px 0; }
figcaption { font-size: 0.875rem; color: var(--muted); margin-top: 8px; }
.caption { font-size: 0.875rem; font-weight: 600; margin: 20px 0 8px; }
.chart ul { list-style: none; padding: 0 !important; margin: 12px 0; }
.chart li { display: grid; grid-template-columns: 44px 1fr; align-items: center; gap: 12px; margin-bottom: 8px; font-variant-numeric: tabular-nums; }
.chart li span { color: var(--muted); font-size: 0.875rem; }
.chart li div { display: flex; align-items: center; gap: 8px; }
.chart i { flex: none; width: calc(var(--v) * 0.6%); height: 20px; border-radius: 4px; background: var(--accent); transform-origin: left; print-color-adjust: exact; }
.chart b { font-size: 0.925rem; }
.ref { font-size: 0.8em; text-decoration: none; }
.sources li { overflow-wrap: anywhere; }
.timeline { list-style: none; padding: 0 !important; border-left: 2px solid var(--border); margin-left: 6px; }
.timeline li { position: relative; padding: 0 0 20px 22px; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: 8px; width: 12px; height: 12px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px var(--bg); }
.timeline strong { display: block; }

/* ---------- App page ---------- */
.mode-badge { font-size: 0.75rem; }
.app-main { padding-top: 32px; padding-bottom: 32px; }
.app-main > p { max-width: 65ch; }
.skeleton { display: grid; gap: 12px; }
.skeleton i { height: 88px; border-radius: var(--radius); background: var(--surface-2); animation: pulse 1s ease-in-out infinite alternate; }
.skeleton i:first-child { height: 36px; width: 45%; }
@keyframes pulse { to { opacity: 0.45; } }
.home-section { margin: 32px 0 40px; }
.home-section .rows h3 { font-size: 1rem; margin: 0; }
.home-section .stats { margin-bottom: 16px; }
.home-section .steps { margin: 0; max-width: 70ch; }
.role-cards { margin: 24px 0; border-bottom: 1px solid var(--border); }
.role-card { display: grid; gap: 16px 32px; padding: 24px 0; border-top: 1px solid var(--border); }
.role-card h2 { display: flex; align-items: center; gap: 10px; }
.role-card .icon { width: 24px; height: 24px; color: var(--accent); }
.role-card p { margin: 0; color: var(--muted); max-width: 60ch; }
.role-enter { display: flex; gap: 8px; align-items: end; }
.role-enter .field { flex: 1; margin: 0; min-width: 0; }
@media (min-width: 800px) { .role-card { grid-template-columns: minmax(0, 1fr) 380px; align-items: end; } }
.page-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; justify-content: space-between; margin-bottom: 20px; }
.page-head h1 { font-size: clamp(1.5rem, 3.5vw, 2rem); margin: 0; }
.page-head .eyebrow { margin-bottom: 4px; }
.stats { grid-template-columns: repeat(2, 1fr); margin-bottom: 24px; }
@media (min-width: 640px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat b { display: block; font-size: 1.9rem; font-weight: 800; line-height: 1.2; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 0.875rem; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; overflow-x: auto; }
.tabs button {
  min-height: 44px; padding: 8px 14px; border: 0; background: none; font: inherit; font-weight: 500;
  color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap;
  transition: color 0.15s;
}
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { color: var(--text); font-weight: 600; border-bottom-color: var(--accent); }
.panel { display: grid; gap: 24px; }
.panel > * { min-width: 0; }
.panel h2 { font-size: 1.1rem; font-weight: 600; letter-spacing: -0.01em; margin: 0 0 10px; }
.panel .callout { margin: 0; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.empty { padding: 28px 20px; margin: 0; text-align: center; color: var(--muted); }
/* Toast: enters with movement, leaves with a quicker plain fade. */
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 8px);
  max-width: calc(100% - 32px); padding: 12px 20px; border-radius: 999px;
  background: var(--primary); color: var(--on-primary); font-weight: 500; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity 0.15s, transform 0.15s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); transition: opacity 0.3s var(--ease-out), transform 0.3s var(--ease-out); }
.toast.error { background: var(--bad); color: var(--bg); }

/* ---------- Motion ----------
   Rule of thumb: rare events get an entrance, frequent ones stay instant.
   - Page load and switching school/role (rare): content materializes in reading order.
   - Tabs, saves, table actions (frequent): no animation, only the 150ms hover/press feedback above.
   Only transform, opacity and filter are animated. The reduced-motion block at the top shortens all of it to nothing. */
@keyframes enter { from { opacity: 0; transform: translateY(8px); filter: blur(4px); } }
@keyframes grow { from { transform: scaleX(0); } }
@keyframes progress { from { transform: scaleX(0); } }
.hero-grid > div > *, .hero-photo, .enter > :nth-child(-n+4) { animation: enter 0.45s var(--ease-out) both; }
.hero-grid > div > :nth-child(2), .enter > :nth-child(2) { animation-delay: 0.05s; }
.hero-grid > div > :nth-child(3), .enter > :nth-child(3) { animation-delay: 0.1s; }
.hero-grid > div > :nth-child(4), .enter > :nth-child(4) { animation-delay: 0.15s; }
.hero-photo { animation-delay: 0.15s; }
.chart i { animation: grow 0.7s var(--ease-out) both; }
/* Scroll-driven extras for browsers that support them; others show the static end state. */
@supports (animation-timeline: view()) {
  .chart i { animation: grow linear both; animation-timeline: view(); animation-range: entry 0% cover 30%; }
  /* Reading progress along the bottom edge of the report header. */
  .has-progress::after {
    content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--accent);
    transform-origin: left; animation: progress linear both; animation-timeline: scroll(root);
  }
}
/* Cross-fade between the report and the app (same-origin page navigation). */
@media (prefers-reduced-motion: no-preference) { @view-transition { navigation: auto; } }

@media print {
  .site-header, .toc, .hero .actions, .skip-link { display: none; }
  body { background: #fff; color: #000; }
  .hero { padding: 0 0 16px; }
  .report { display: block; }
  a { color: inherit; }
  * { animation: none !important; }
}
