/* Reset, typography, layout primitives and the global shell (03-design §2, docs/11-design-language.md). */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding: calc(var(--frame-browse) + var(--sp-2)); }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: var(--lh-body);
  font-weight: var(--fw-normal);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  --frame: var(--frame-browse);
  --page-pad: calc(var(--frame) + var(--gutter));
}

h1, h2, h3, h4 { line-height: var(--lh-heading); font-weight: var(--fw-bold); margin: 0 0 var(--sp-3); }
h1 { font-size: var(--fs-xl); font-weight: var(--fw-heavy); letter-spacing: -0.02em; }
h2 { font-size: var(--fs-lg); }
h3, .h3 { font-size: var(--fs-md); }
p { margin: 0 0 var(--sp-3); }
ul, ol { margin: 0 0 var(--sp-3); padding-left: var(--sp-5); }
img, svg, video, iframe { display: block; max-width: 100%; }
svg.icon { display: inline-block; flex: none; vertical-align: middle; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { padding: 0; }
table { border-collapse: collapse; }
kbd {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  padding: 1px 6px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: var(--r-sm);
  background: var(--surface);
  font-variant-numeric: tabular-nums;
  color: var(--text);
  white-space: nowrap;
}
code, pre, .code { font-family: var(--font-mono); font-size: var(--fs-sm); }
mark { background: var(--mark); color: var(--text); border-radius: 2px; padding: 0 1px; }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--sp-5) 0; }

a { color: var(--link); text-decoration-thickness: 1px; text-decoration-color: var(--border-strong); text-underline-offset: 4px; }
a:hover { text-decoration-thickness: 2px; text-decoration-color: currentColor; }

/* Focus ring for every interactive element (never removed without replacement). */
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }
[tabindex="-1"]:focus { outline: none; }

[hidden] { display: none !important; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%);
  white-space: nowrap; border: 0;
}

.muted { color: var(--text-muted); }
.small { font-size: var(--fs-sm); }
.lead { font-size: var(--fs-lg); line-height: 1.45; }
.tabular, time { font-variant-numeric: tabular-nums; }
/* Timecodes are the headline type of this app: mono, tabular, never wrapped. */
.timecode { font-family: var(--font-time); font-variant-numeric: tabular-nums; white-space: nowrap; letter-spacing: -0.02em; }

/* Skip link: visible on focus only */
.skip-link {
  position: absolute;
  left: var(--sp-3);
  top: -100px;
  z-index: 100;
  padding: var(--sp-2) var(--sp-4);
  background: var(--surface);
  color: var(--text);
  border: 2px solid var(--focus);
  border-radius: var(--r-sm);
  box-shadow: var(--float-frame);
  font-weight: var(--fw-bold);
  text-decoration: none;
}
.skip-link:focus { top: var(--sp-2); }

/* --- Frame (passe-partout) ------------------------------------------------------------------------ */
/* A mat fixed around the viewport: the app reads as one picture in a frame. Its width says how much the page
   wants from you (wide while browsing, thin while watching, none in focus and embed); its tone says the mode
   (student view). Decorative only: no pointer events, no content underneath (page padding clears it). */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: var(--z-frame);
  pointer-events: none;
  border: var(--frame) solid var(--mat);
  box-shadow: inset 0 0 0 1px var(--mat-edge);
  transition: border-width var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
body.has-player { --frame: var(--frame-watch); }
body.viewer-mode::before { border-color: var(--mat-student); }
body.embed-mode::before, body.focus-mode::before { display: none; }
body.embed-mode, body.focus-mode { --frame: 0px; }

/* --- Header ---------------------------------------------------------------------------------- */
.site-header {
  position: relative;
  z-index: var(--z-header);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  margin-top: var(--frame);
}
.header-inner {
  max-width: calc(var(--content-max) + 2 * var(--page-pad));
  margin: 0 auto;
  min-height: var(--header-h);
  padding: 0 var(--page-pad);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: var(--hit);
  padding: 0 var(--sp-1);
  margin-left: calc(-1 * var(--sp-1));
  color: var(--text);
  text-decoration: none;
  font-weight: var(--fw-heavy);
  font-size: 1.0625rem;
  letter-spacing: -0.03em;
  border-radius: var(--r-sm);
  flex: none;
}
.brand-mark { color: var(--text); }
.brand:not([href]) { cursor: default; }
/* R2: a small, quiet marker that this page is a teacher's student-view link. */
.student-badge { display: inline-flex; align-items: center; min-height: 28px; padding: 0 var(--sp-3); border: 1px solid var(--border-strong); border-radius: var(--r-full); color: var(--text); font-size: var(--fs-xs); font-weight: var(--fw-bold); letter-spacing: var(--ls-caps); text-transform: uppercase; white-space: nowrap; flex: none; box-shadow: inset 4px 0 0 var(--mat-student); padding-left: calc(var(--sp-3) + 4px); }
/* F10: "Unlocked until 10:42" while a PIN is set and unlocked; clicking locks. */
.header-lock { display: flex; }
.lock-indicator { position: relative; display: inline-flex; align-items: center; gap: var(--sp-1); min-height: var(--hit); padding: 0 var(--sp-3); border: 1px solid var(--border-strong); border-radius: var(--r-full); background: var(--accent-soft); color: var(--text); font-size: var(--fs-xs); font-weight: var(--fw-bold); font-variant-numeric: tabular-nums; white-space: nowrap; }
.lock-indicator:hover { background: var(--surface-2); }
@media (max-width: 599.98px) {
  .lock-indicator-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .lock-indicator { padding: 0; width: var(--hit); justify-content: center; }
}

.header-search {
  position: relative;
  flex: 1 1 auto;
  max-width: 460px;
  margin-left: var(--sp-4);
  min-width: 0;
}
.header-search .input-search { width: 100%; padding-right: 40px; }
.search-hint {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}
.header-search:focus-within .search-hint { display: none; }

.site-nav {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  flex: none;
}
.header-items { display: flex; align-items: center; gap: var(--sp-2); }
.header-items:empty { display: none; }
.nav-link {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: var(--hit);
  min-width: var(--hit);
  justify-content: center;
  padding: 0 var(--sp-3);
  border-radius: var(--r-sm);
  color: var(--text);
  text-decoration: none;
  font-weight: var(--fw-bold);
  font-size: var(--fs-sm);
}
.nav-link:hover { background: var(--surface-2); }
/* Where you are is the playhead: a bar on the header's bottom rule. */
.nav-link[aria-current="page"]::after { content: ""; position: absolute; left: var(--sp-2); right: var(--sp-2); bottom: calc((var(--header-h) - var(--hit)) / -2 - 1px); height: var(--rule-bold); background: var(--accent); }
.nav-link .icon { width: 20px; height: 20px; }

@media (max-width: 599.98px) {
  .nav-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
  .nav-link { padding: 0; }
  .nav-link[aria-current="page"]::after { left: 6px; right: 6px; }
  .brand-name { display: none; }
  .header-search { margin-left: var(--sp-1); }
  .search-hint { display: none; }
  .header-inner { gap: var(--sp-2); }
}
@media (min-width: 600px) and (max-width: 759.98px) {
  .brand-name { display: none; }
}

/* Home has its own big box. */
body[data-route="home"] .site-header { border-bottom-color: transparent; }

/* --- Banners --------------------------------------------------------------------------------- */
.banners:empty { display: none; }

/* --- Main + footer ----------------------------------------------------------------------------- */
main {
  flex: 1 0 auto;
  width: 100%;
  max-width: calc(var(--content-max) + 2 * var(--page-pad));
  margin: 0 auto;
  padding: var(--sp-6) var(--page-pad) var(--sp-7);
}
main:focus { outline: none; }

.site-footer {
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: var(--fs-sm);
  margin-bottom: var(--frame);
}
.footer-inner {
  max-width: calc(var(--content-max) + 2 * var(--page-pad));
  margin: 0 auto;
  padding: var(--sp-4) var(--page-pad) var(--sp-5);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-1) var(--sp-2);
}
.footer-inner a { color: var(--text-muted); display: inline-flex; align-items: center; min-height: 32px; }
.footer-inner a:hover { color: var(--text); }
.footer-note { flex-basis: 100%; }

.noscript { max-width: var(--prose-max); margin: var(--sp-7) auto; text-align: center; }

/* --- Viewer, embed and focus modes ------------------------------------------------------------- */
body.viewer-mode .header-search,
body.viewer-mode .site-nav,
body.viewer-mode .site-footer { display: none; }

body.embed-mode { background: #000; }
body.embed-mode .site-header,
body.embed-mode .site-footer,
body.embed-mode .banners,
body.embed-mode .skip-link { display: none; }
body.embed-mode main { padding: 0; max-width: none; }

body.focus-mode { background: var(--bg-focus); color: var(--shield-text); }
body.focus-mode .site-header,
body.focus-mode .site-footer,
body.focus-mode .banners { display: none; }
body.focus-mode main { max-width: none; padding: var(--sp-3) var(--page-pad) var(--sp-3); }

/* Forced colours: use system colours for rings and borders. */
@media (forced-colors: active) {
  :focus-visible { outline-color: Highlight; }
  .nav-link[aria-current="page"] { outline: 2px solid CanvasText; }
  body::before { display: none; }
}
