/*
 * Design system.
 *
 * Shared by every page: the landing picker, the instructor dashboard, the
 * student session and the standalone studio. Page-specific CSS layers on top and
 * never redefines a token.
 *
 * Three decisions worth stating:
 *
 * 1. Light is the default -- unconditionally, not by way of the OS setting. An
 *    instructor authoring a session is doing document work in a lit room, often
 *    projected, and a projector turns a dark UI into a grey smear. Dark is
 *    opt-in via `data-theme` for the student in a dark demo room; the choice
 *    persists to localStorage, and `system` is a third value they can pick
 *    explicitly rather than the default they get by accident.
 * 2. Spacing, radius and type are a fixed scale rather than ad-hoc values. Every
 *    gap in the UI is a multiple of 4px, which is what makes a dense form like
 *    the session editor read as designed rather than assembled.
 * 3. The palette is one hue family, not two: academic navy for everything
 *    interactive, with cyan (`--tech`) as a narrow accent, on warm paper. A
 *    button, a link, a focus ring and the logo all read as the same product.
 *    Neutrals are warm and the ink carries the navy (#10203a, not a neutral
 *    black) so paper surfaces sit under the brand instead of beside it. The
 *    four status hues -- green, amber, red, violet -- stay outside the family
 *    precisely so "live", "over budget" and "failed" can never be mistaken for
 *    chrome. See the colour block below for the numbers.
 */

:root {
  /* -- spacing: 4px base ------------------------------------------------- */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-8: 32px;
  --s-10: 40px;
  --s-12: 48px;
  --s-16: 64px;

  /* -- radius ------------------------------------------------------------ */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 20px;
  --r-full: 999px;

  /* -- type -------------------------------------------------------------- */
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, Consolas, monospace;
  --t-xs: 11.5px;
  --t-sm: 13px;
  --t-md: 14px;
  --t-base: 15px;
  --t-lg: 17px;
  --t-xl: 21px;
  --t-2xl: 27px;
  --t-3xl: 34px;

  /* -- colour ------------------------------------------------------------
   * Academic navy, with cyan as the tech signal, on warm paper.
   *
   * The three decisions behind these numbers:
   *
   * 1. The interactive family is *navy*, not violet. Navy is the colour of
   *    university presses, journals and syllabi, and it is what makes a dense
   *    instructor form read as coursework rather than as a consumer app. It is
   *    also nobody's school colour in particular, which the old NYU violet
   *    could not claim.
   *
   * 2. Cyan (`--tech`) is what keeps it from reading as a library catalogue.
   *    It is deliberately a *narrow* token -- meters, live rails, the logo
   *    gradient, decorative icon chips -- because a whole UI in cyan reads as
   *    a dashboard, while navy with cyan punctuation reads as an instrument.
   *    It is never the primary button; that is always `--accent`.
   *
   * 3. Neutrals are warm (#f7f5f1 paper, #edeae3 sunken), and the ink carries
   *    the navy (#10203a, not a neutral near-black). Warm paper under cool ink
   *    is the pairing that reads as printed rather than as a screen, and it is
   *    the single biggest reason this palette feels academic at a glance.
   *
   * Every value is checked against WCAG AA -- 4.5:1 for text, 3:1 for the
   * boundary of an interactive control -- and two rules follow from that.
   * Breaking either is what made an earlier palette hard to read:
   *
   * a. `--text-faint` is the colour of every hint, field description and
   *    section note -- which is to say, of every sentence that explains what a
   *    control does. It is a real text colour, not a whisper. It clears 4.5:1
   *    on all five surfaces including `--bg-active`, which is the one usually
   *    missed. Nothing below AA goes on text, ever.
   *
   * b. Saturated status colours (`--good`, `--warn`, ...) are for *fills* --
   *    dots, bars, rails, icons -- and clear 3:1 as graphics. Text on a tinted
   *    background uses the matching `--*-text`, which is the same hue darkened
   *    until it passes. White never goes on `--good`: green light enough to
   *    read as green cannot carry white, so the "done" tick has its own
   *    `--check-bg`.
   */

  --bg: #f7f5f1;
  --bg-raised: #ffffff;
  --bg-sunken: #edeae3;
  --bg-input: #ffffff;
  --bg-hover: #f1eee7;
  --bg-active: #e3ded4;

  /* Card boundary, then the boundary of anything you can type in or click.
     The second clears 3:1 because WCAG 1.4.11 counts it as the thing that
     identifies the control. */
  --border: #e2ddd3;
  --border-strong: #8a8478;  /* 3.7:1 on white, 3.1:1 on --bg-sunken */

  --text: #10203a;        /* 16.3:1 -- navy ink, not neutral black */
  --text-dim: #41506a;    /*  8.1:1 */
  --text-faint: #565f73;  /*  6.4:1 on white, 4.8:1 on --bg-active */
  --text-inverse: #ffffff;

  --accent: #14508c;      /* white on it: 8.2:1 */
  --accent-hover: #0f3f70;
  --accent-soft: #e9f0f8;
  --accent-border: #b9d2ea;  /* decorative: the rule of a soft-accent panel.
                                Control boundaries use --border-strong. */
  --accent-text: #124a80; /*  9.1:1 on white, 7.9:1 on --accent-soft */

  /* The tech signal. A fill and an accent, never the primary action. */
  --tech: #0e8f9e;        /*  3.9:1 on white -- fills and graphics */
  --tech-soft: #e2f4f6;
  --tech-text: #0a6b77;   /*  6.2:1 on white, 5.5:1 on --tech-soft */

  --good: #16a34a;        /*  3.3:1 -- fill only, never under white */
  --good-soft: #e6f6ec;
  --good-text: #14713a;   /*  5.4:1 on --good-soft */
  --warn: #c87e00;        /*  3.3:1 -- amber dark enough to be a boundary */
  --warn-soft: #fbf1de;
  --warn-text: #91560a;   /*  5.3:1 on --warn-soft */
  --bad: #dc2626;
  --bad-soft: #fceded;
  --bad-text: #b91c1c;    /*  5.7:1 on --bad-soft */
  /* Informational, and violet on purpose: the four status hues sit *outside*
     the navy/cyan family precisely so "live", "over budget" and "failed" can
     never be mistaken for chrome. A sky-blue --info would collide with the
     accent, which is the one confusion this palette cannot afford. */
  --info: #7c3aed;
  --info-soft: #f1ebfd;
  --info-text: #6b21c8;   /*  6.7:1 on --info-soft */

  /* The wordmark's second half. Brand *ink* -- "Talks", brand text, brand
     links -- which lightens in dark mode. --brand-glow is the cyan end, used
     only in gradients and glows, never under text and never as a boundary. */
  --brand-accent: #12395f;  /* 11.8:1 on white */
  --brand-glow: #22b8cf;
  /* Brand *fill*: the surface of a brand-coloured button, which always carries
     white text and therefore has to stay dark in both themes. Splitting it from
     --brand-accent is what lets the ink lighten for dark mode without turning
     every brand button into white-on-pale-blue. */
  --brand-fill: #14508c;        /* white on it: 8.2:1 */
  --brand-fill-hover: #0f3f70;

  /* The "done" tick. White on --good measures 3.3:1, so the disc uses the
     darkened green and the tick stays white. Inverted in dark, where a light
     disc with dark ink is the legible pairing. */
  --check-bg: #14713a;
  --check-ink: #ffffff;

  --shadow-sm: 0 1px 3px rgba(16, 32, 58, 0.06), 0 1px 2px rgba(16, 32, 58, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(16, 32, 58, 0.08), 0 2px 4px -2px rgba(16, 32, 58, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(16, 32, 58, 0.09), 0 4px 6px -4px rgba(16, 32, 58, 0.05);
  --ring: 0 0 0 3px color-mix(in srgb, var(--accent) 28%, transparent);

  --scrim: rgba(10, 18, 32, 0.55);
  --select-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath fill='%2341506a' d='M6 8.2 2.4 4.6l.9-.9L6 6.4l2.7-2.7.9.9z'/%3E%3C/svg%3E");

  /* The stage is dark in *both* themes, and this is deliberate.
     Everything layered on it -- .stage__note, .captions, .suggests__label --
     is pinned to a light tone with its own scrim, because it has to stay
     readable over an arbitrary avatar photo or video frame and cannot follow a
     theme token. A light placeholder gradient therefore put near-white text on
     near-white ground for as long as the avatar took to load: measured 3.1:1
     for the "Loading avatar…" note and 1.0:1 for "Try saying". The video
     element behind it already paints #0a0f18, so a dark stage also removes the
     light-to-dark flash on load. */
  --stage-bg: radial-gradient(120% 90% at 50% 0%, #1d2b3d 0%, #121b27 62%, #090f18 100%);

  /* The counterpart of `color-scheme: dark` in the dark block below, and it has
     to be stated rather than left to default.

     Every page carries `<meta name="color-scheme" content="light dark">`, which
     tells the UA both themes are supported -- so with no declaration here, a
     visitor whose OS is dark got UA-painted *dark* form controls on our light
     palette however they had set the theme. An unchecked checkbox is the
     visible case: it paints as a filled near-black square, which reads as
     already ticked. `accent-color` does not help, because it only colours the
     checked state. */
  color-scheme: light;
}

/* -- dark ------------------------------------------------------------------
 * Opt-in, keyed on the attribute `initTheme()` in ui.js writes to <html>. It is
 * deliberately *not* also keyed on `prefers-color-scheme`: only pages that call
 * initTheme() participate, so adding dark to the dashboard cannot silently
 * repaint the student session or the studio, whose stage is its own dark
 * surface either way.
 *
 * Same AA rules as above, re-checked against the dark surfaces -- a palette
 * inverted by eye is where dark themes usually fail. Note that `--accent` gets
 * *darker* here rather than lighter: it carries white text, and a blue light
 * enough to look "bright on dark" cannot hold white at 4.5:1.
 */

:root[data-theme='dark'] {
  --bg: #0e1621;
  --bg-raised: #16202e;
  --bg-sunken: #090f18;
  --bg-input: #1b2634;
  --bg-hover: #1e2938;
  --bg-active: #263242;

  --border: #2a3543;
  --border-strong: #6d798a;  /* 3.7:1 on --bg-raised */

  --text: #e8edf4;        /* 13.9:1 */
  --text-dim: #a9b5c6;    /*  7.9:1 */
  --text-faint: #929eb1;  /*  6.1:1 on --bg-raised, 4.8:1 on --bg-active */
  --text-inverse: #0a0f18;

  --accent: #2a72c2;      /* white on it: 4.9:1; 3.4:1 against --bg-raised */
  --accent-hover: #2e77c8; /* white on it: 4.6:1 */
  --accent-soft: #12263e;
  --accent-border: #2d4d78;  /* decorative, as in light */
  --accent-text: #8dc2f2; /*  8.7:1 */

  --tech: #22b8cf;
  --tech-soft: #0a2731;
  --tech-text: #5fd3e3;   /*  8.8:1 on --tech-soft */

  --good: #34d399;
  --good-soft: #0c2a20;
  --good-text: #4ade9f;   /*  9.0:1 on --good-soft */
  --warn: #fbbf24;
  --warn-soft: #2b2010;
  --warn-text: #fcd34d;   /* 11.1:1 on --warn-soft */
  --bad: #f87171;
  --bad-soft: #2d1416;
  --bad-text: #fca5a5;    /*  9.1:1 on --bad-soft */
  --info: #a78bfa;
  --info-soft: #1e1836;
  --info-text: #c4b0fd;   /*  8.9:1 on --info-soft */

  --brand-accent: #9dc9ef;  /* navy does not survive a dark ground; this is the
                               same hue lifted to 9.4:1 */
  --brand-glow: #3fd0e8;
  --brand-fill: #1a5fa8;        /* white on it: 6.5:1 */
  --brand-fill-hover: #2472c4;  /* white on it: 4.9:1 */

  --check-bg: #34d399;
  --check-ink: #0a0f18;

  /* Shadow does almost no work on a dark ground, so the raised surfaces lean
     on their own lightness instead and the shadow only deepens the edge. */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 10px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.55);

  --scrim: rgba(4, 8, 14, 0.7);
  --select-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath fill='%23a9b5c6' d='M6 8.2 2.4 4.6l.9-.9L6 6.4l2.7-2.7.9.9z'/%3E%3C/svg%3E");

  /* --stage-bg is not overridden here: it is dark in both themes. */

  color-scheme: dark;
}

/* -- reset ---------------------------------------------------------------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

/*
 * The `hidden` attribute only sets `display: none` in the UA stylesheet, so any
 * author rule with an explicit `display` silently beats it. Several top-level
 * views here are `display: grid` or `display: flex`, which made `hidden` a no-op
 * and rendered every view at once. This is the standard remedy and has to stay.
 */
[hidden] {
  display: none !important;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--t-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

h1 {
  font-size: var(--t-2xl);
  font-weight: 640;
  letter-spacing: -0.022em;
}
h2 {
  font-size: var(--t-xl);
  font-weight: 620;
  letter-spacing: -0.018em;
}
h3 {
  font-size: var(--t-lg);
  font-weight: 600;
  letter-spacing: -0.012em;
}

a {
  color: var(--accent-text);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

code,
kbd,
pre {
  font-family: var(--mono);
  font-size: 0.92em;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* -- scrollbars ----------------------------------------------------------- */

* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
*::-webkit-scrollbar {
  width: 9px;
  height: 9px;
}
*::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--r-full);
  border: 2px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-track {
  background: transparent;
}

/* -- brand ---------------------------------------------------------------- */

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
  font-weight: 640;
  font-size: var(--t-md);
  letter-spacing: -0.015em;
  color: var(--text);
}

.brand__mark {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  flex: 0 0 auto;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--brand-accent), var(--brand-glow));
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 2px 8px color-mix(in srgb, var(--brand-accent) 35%, transparent);
}

.brand__sub {
  color: var(--text-faint);
  font-weight: 500;
}

.brand__logo {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border-radius: var(--r-md);
  object-fit: contain;
}

.brand__name {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.brand__name-accent {
  color: var(--brand-accent);
}

/* -- page bar --------------------------------------------------------------
 * Shared top bar used by every entry page (landing, join, setup). Fixed
 * height and padding keep the brand mark visually identical as a user moves
 * between pages instead of the header jumping in size.
 */

.page-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
  height: 96px;
  padding: 0 48px;
  flex: 0 0 auto;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  position: sticky;
  top: 0;
  z-index: 100;
}

.page-nav {
  display: flex;
  align-items: center;
  gap: 32px;
}

.page-nav .btn {
  font-size: 16px;
  padding-left: 24px;
  padding-right: 24px;
}

@media (max-width: 640px) {
  .page-bar {
    height: 68px;
    padding: 0 var(--s-5);
  }
}

/* -- buttons -------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  padding: 0 var(--s-4);
  height: 36px;
  border-radius: var(--r-md);
  border: 1px solid var(--border-strong);
  background: var(--bg-raised);
  color: var(--text);
  font: inherit;
  font-size: var(--t-md);
  font-weight: 540;
  white-space: nowrap;
  cursor: pointer;
  transition:
    background 0.14s ease,
    border-color 0.14s ease,
    box-shadow 0.14s ease,
    transform 0.08s ease;
}

.btn:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}
.btn:active:not(:disabled) {
  transform: translateY(0.5px);
  background: var(--bg-active);
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn--primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

/*
 * The AI Session Designer's button, and the confirm button inside it.
 *
 * A gradient rather than another solid accent because it has to sit beside
 * "New session" -- the primary button -- without either one winning. They are
 * two ways into the same place, and two identical primaries would just be a
 * decision the instructor has to make by reading. This one is the brand's own
 * navy-to-cyan sweep (see docs/BRAND.md), which reads as "this one is the
 * clever one" without shouting over the page.
 */
.btn--ai {
  background: linear-gradient(120deg, var(--brand-fill), var(--brand-glow));
  border-color: transparent;
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn--ai:hover:not(:disabled) {
  background: linear-gradient(120deg, var(--brand-fill-hover), var(--brand-glow));
  filter: saturate(1.08);
}

.btn--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-dim);
}
.btn--ghost:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text);
}

.btn--danger {
  color: var(--bad-text);
  border-color: var(--border);
}
.btn--danger:hover:not(:disabled) {
  background: var(--bad-soft);
  border-color: var(--bad);
}

/* A button that reads as a link: needed wherever an inline word acts on the
   page rather than navigating -- "Forgot password?" on the dashboard, "Sign
   out" in the pricing banner -- because a real <a> with no href is unreachable
   by keyboard. Here rather than in one page's stylesheet so both get it. */
.linkbtn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent-text);
  font: inherit;
  font-size: var(--t-sm);
  font-weight: 550;
  cursor: pointer;
  border-radius: var(--r-sm);
}

.linkbtn:hover:not(:disabled) {
  text-decoration: underline;
}

/* Spent, not broken: "Link sent" once a reset mail has gone out. In the link
   colour it still reads as something to press. */
.linkbtn:disabled {
  color: var(--text-faint);
  cursor: default;
}

.linkbtn:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

.btn--sm {
  height: 29px;
  padding: 0 var(--s-3);
  font-size: var(--t-sm);
  border-radius: var(--r-sm);
}

.btn--lg {
  height: 44px;
  padding: 0 var(--s-6);
  font-size: var(--t-lg);
  font-weight: 570;
  border-radius: var(--r-lg);
}

.btn--block {
  width: 100%;
}

.btn__icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  flex: 0 0 auto;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text-dim);
  cursor: pointer;
  transition: color 0.14s, background 0.14s, border-color 0.14s;
}
.btn__icon:hover:not(:disabled) {
  color: var(--text);
  background: var(--bg-hover);
  border-color: var(--border-strong);
}
.btn__icon:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* -- form controls -------------------------------------------------------- */

.field {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  min-width: 0;
}

.field__head {
  display: flex;
  align-items: baseline;
  gap: var(--s-2);
  justify-content: space-between;
}

.label {
  font-size: var(--t-sm);
  font-weight: 580;
  color: var(--text);
  letter-spacing: -0.005em;
}

.hint {
  margin: 0;
  font-size: var(--t-sm);
  line-height: 1.45;
  color: var(--text-faint);
}

.hint code {
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
}

.input,
.select,
.textarea {
  width: 100%;
  padding: 8px 11px;
  border-radius: var(--r-md);
  border: 1px solid var(--border-strong);
  background: var(--bg-input);
  color: var(--text);
  font: inherit;
  font-size: var(--t-md);
  transition: border-color 0.14s, box-shadow 0.14s;
}

.input::placeholder,
.textarea::placeholder {
  color: var(--text-faint);
}

.input:hover:not(:disabled),
.select:hover:not(:disabled),
.textarea:hover:not(:disabled) {
  border-color: var(--text-faint);
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}

.input:disabled,
.select:disabled,
.textarea:disabled {
  background: var(--bg-sunken);
  color: var(--text-faint);
  cursor: not-allowed;
}

.textarea {
  resize: vertical;
  min-height: 76px;
  line-height: 1.55;
}

.select {
  appearance: none;
  padding-right: 30px;
  /*
   * The chevron is a background-image, and a background-image cannot read
   * `currentColor` -- so a single hardcoded grey glyph would stay light-grey on
   * a dark input. It is a token instead, redefined once in the dark block.
   */
  background-image: var(--select-chevron);
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 12px;
}

.check {
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
  cursor: pointer;
  padding: var(--s-1) 0;
}

.check input[type='checkbox'] {
  width: 17px;
  height: 17px;
  margin: 1px 0 0;
  flex: 0 0 auto;
  accent-color: var(--accent);
  cursor: pointer;
}

.check__body {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.check__label {
  font-size: var(--t-md);
  font-weight: 500;
}

/* A setting that does not apply right now. Dimmed rather than removed: the
   hint beside it explains why, and a control that disappears reads as a
   feature we never built. The label keeps full contrast so the sentence
   explaining itself stays readable. */
.check--off {
  cursor: default;
}

.check--off input[type='checkbox'] {
  cursor: default;
  opacity: 0.5;
}

.check--off .check__label {
  color: var(--text-dim, inherit);
}

input[type='range'] {
  width: 100%;
  accent-color: var(--accent);
}

/* -- cards & surfaces ----------------------------------------------------- */

.card {
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  background: var(--bg-raised);
  box-shadow: var(--shadow-sm);
}

.card__head {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-4) var(--s-5);
  border-bottom: 1px solid var(--border);
}

.card__title {
  font-size: var(--t-md);
  font-weight: 600;
  letter-spacing: -0.01em;
}

.card__body {
  padding: var(--s-5);
}

.card__actions {
  margin-left: auto;
  display: flex;
  gap: var(--s-2);
}

/* -- badges --------------------------------------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: var(--r-full);
  border: 1px solid transparent;
  font-size: var(--t-xs);
  font-weight: 600;
  letter-spacing: 0.015em;
  white-space: nowrap;
  text-transform: uppercase;
}

.badge--neutral {
  background: var(--bg-sunken);
  color: var(--text-dim);
  border-color: var(--border);
}
.badge--live {
  background: var(--good-soft);
  color: var(--good-text);
  border-color: color-mix(in srgb, var(--good) 32%, transparent);
}
.badge--draft {
  background: var(--warn-soft);
  color: var(--warn-text);
  border-color: color-mix(in srgb, var(--warn) 32%, transparent);
}
.badge--paused {
  background: var(--info-soft);
  color: var(--info-text);
  border-color: color-mix(in srgb, var(--info) 32%, transparent);
}
.badge--ended {
  background: var(--bg-sunken);
  color: var(--text-dim);
  border-color: var(--border);
}
.badge--accent {
  background: var(--accent-soft);
  color: var(--accent-text);
  border-color: var(--accent-border);
}
.badge--bad {
  background: var(--bad-soft);
  color: var(--bad-text);
  border-color: color-mix(in srgb, var(--bad) 32%, transparent);
}

.badge--dot::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  /* A fill, not text -- it keeps the saturated hue while the label next to it
     uses the darkened `--*-text`, which is why this is not `currentColor`. */
  background: var(--badge-dot, currentColor);
}

.badge--live { --badge-dot: var(--good); }
.badge--draft { --badge-dot: var(--warn); }
.badge--paused { --badge-dot: var(--info); }
.badge--bad { --badge-dot: var(--bad); }

/* -- chips (removable tokens) --------------------------------------------- */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  padding: 4px 6px 4px 10px;
  border-radius: var(--r-full);
  border: 1px solid var(--border-strong);
  background: var(--bg-sunken);
  font-size: var(--t-sm);
  max-width: 100%;
}

.chip__text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip__remove {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-faint);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}
.chip__remove:hover {
  background: var(--bad-soft);
  color: var(--bad-text);
}

/* -- tabs ----------------------------------------------------------------- */

.tabs {
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: var(--r-lg);
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  position: relative;
  padding: 8px var(--s-4);
  border: 0;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: var(--t-sm);
  font-weight: 540;
  white-space: nowrap;
  cursor: pointer;
  transition: color 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
}

.tab:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--bg-raised) 60%, transparent);
}

.tab[aria-selected='true'] {
  color: var(--accent-text);
  background: var(--bg-raised);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.tab__count {
  margin-left: 5px;
  padding: 0 5px;
  border-radius: var(--r-full);
  background: var(--bg-sunken);
  color: var(--text-faint);
  font-size: var(--t-xs);
  font-weight: 600;
}

/* -- tables --------------------------------------------------------------- */

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--t-md);
}

.table th {
  text-align: left;
  padding: var(--s-2) var(--s-3);
  font-size: var(--t-xs);
  font-weight: 640;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-faint);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table td {
  padding: var(--s-3);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.table tbody tr:last-child td {
  border-bottom: 0;
}

.table tbody tr[data-clickable]:hover {
  background: var(--bg-hover);
  cursor: pointer;
}

.table__num {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* -- empty state ---------------------------------------------------------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-12) var(--s-6);
  text-align: center;
  color: var(--text-faint);
}

.empty__title {
  font-size: var(--t-lg);
  font-weight: 600;
  color: var(--text);
}

.empty__body {
  max-width: 44ch;
  font-size: var(--t-md);
  line-height: 1.55;
}

/* -- toasts --------------------------------------------------------------- */

/* Displayed at the bottom right of the screen. */
.toasts {
  position: fixed;
  bottom: var(--s-4);
  right: var(--s-4);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  max-width: min(400px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  border-left: 3px solid var(--info);
  background: var(--bg-raised);
  color: var(--text);
  font-size: var(--t-md);
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.2s cubic-bezier(0.2, 0.9, 0.3, 1);
  transition: opacity 0.28s, transform 0.28s;
}

.toast--warning {
  border-left-color: var(--warn);
}
.toast--error {
  border-left-color: var(--bad);
}
.toast--success {
  border-left-color: var(--good);
}

.toast--out {
  opacity: 0;
  transform: translateX(14px);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(18px);
  }
}

/* -- modal ---------------------------------------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: grid;
  place-items: center;
  padding: var(--s-4);
  background: var(--scrim);
  backdrop-filter: blur(8px) saturate(1.2);
  -webkit-backdrop-filter: blur(8px) saturate(1.2);
  animation: fade-in 0.18s ease;
}

.modal__panel {
  width: min(640px, 100%);
  max-height: min(84vh, 760px);
  display: flex;
  flex-direction: column;
  border-radius: var(--r-xl);
  border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  background: color-mix(in srgb, var(--bg-raised) 96%, transparent);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  box-shadow:
    0 4px 16px rgba(15, 23, 42, 0.08),
    0 16px 48px rgba(15, 23, 42, 0.1);
  animation: modal-in 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
}

.modal__head {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-5) var(--s-6);
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-sunken) 40%, transparent);
}

.modal__body {
  padding: var(--s-6);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--s-5);
}

.modal__foot {
  display: flex;
  justify-content: flex-end;
  gap: var(--s-3);
  padding: var(--s-4) var(--s-6);
  border-top: 1px solid var(--border);
  background: var(--bg-sunken);
}

/* -- avatar picker ---------------------------------------------------------
 * The pop-up gallery for choosing a LiveAvatar (HeyGen) presenter, shared by
 * the studio setup panel and the instructor session editor.
 *
 * Tiles are portrait 3/4 rather than square because these previews are framed
 * head-and-shoulders: a square crop cuts the chin or leaves dead headroom, and
 * the face is the entire reason this screen exists. The caption sits *over* the
 * image on a gradient so the tile reads as one photo rather than a photo with a
 * label bolted underneath, which is what makes a grid of these look composed.
 */

.apick {
  /* Wider than .modal__panel's 640px default: this is a browse-and-compare
     screen, and fewer than four columns makes it feel like a list. */
  width: min(1040px, 100%);
  max-height: min(90vh, 860px);
}

.apick__head {
  display: flex;
  align-items: flex-start;
  gap: var(--s-4);
  padding: var(--s-5) var(--s-5) var(--s-4);
  border-bottom: 1px solid var(--border);
}

.apick__title {
  font-size: var(--t-lg);
  font-weight: 620;
  letter-spacing: -0.014em;
}

.apick__subtitle {
  margin-top: 2px;
  font-size: var(--t-sm);
  color: var(--text-faint);
}

.apick__close {
  margin-left: auto;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  transition: background 0.14s, color 0.14s;
}

.apick__close:hover {
  background: var(--bg-hover);
  color: var(--text);
}

/* Sticky so search and the result count stay reachable 200 avatars down. */
.apick__toolbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-4) var(--s-5);
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
}

.apick__search {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
}

.apick__search svg {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-faint);
  pointer-events: none;
}

.apick__search .input {
  width: 100%;
  padding-left: 34px;
}

.apick__count {
  flex: 0 0 auto;
  font-size: var(--t-sm);
  font-variant-numeric: tabular-nums;
  color: var(--text-faint);
}

.apick__body {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--s-5);
  background: var(--bg);
}

.apick__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: var(--s-4);
}

.apick__foot {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-4) var(--s-5);
  border-top: 1px solid var(--border);
  background: var(--bg-raised);
}

.apick__chosen {
  min-width: 0;
  flex: 1 1 auto;
  font-size: var(--t-sm);
  color: var(--text-dim);
}

.apick__chosen strong {
  font-weight: 620;
  color: var(--text);
}

.apick__actions {
  display: flex;
  gap: var(--s-2);
  flex: 0 0 auto;
}

/* -- tiles ---------------------------------------------------------------- */

.atile {
  position: relative;
  display: block;
  padding: 0;
  border: 0;
  border-radius: var(--r-lg);
  background: var(--bg-active);
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}

.atile::after {
  /* The selection ring lives on a pseudo-element so it draws *over* the image
     without a border changing the tile's box size (which would reflow the
     whole grid by a pixel every time the selection moved). */
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  border: 2px solid transparent;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
  pointer-events: none;
}

.atile:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}

.atile:hover::after {
  border-color: var(--accent-border);
}

.atile:focus-visible {
  outline: none;
}

.atile:focus-visible::after {
  border-color: var(--accent);
  box-shadow: var(--ring);
}

.atile[aria-pressed='true']::after {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.atile[disabled] {
  cursor: not-allowed;
  opacity: 0.55;
  filter: grayscale(1);
}

.atile[disabled]:hover {
  transform: none;
  box-shadow: var(--shadow-sm);
}

.atile__img {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  /*
   * Top-biased, not centred. HeyGen ships previews in two shapes: 16:9 (which
   * this 3:4 box crops on the sides, so the vertical anchor is moot) and 9:16
   * (which it crops top and bottom, losing 25% of the height). Centred, that
   * 25% comes half off the top -- and the top of a 9:16 presenter shot is their
   * head. Anchoring high spends the whole crop on the empty floor instead.
   */
  object-position: 50% 4%;
  background: var(--bg-active);
  /* Faded in on load so a slow roster resolves gracefully instead of
     snapping in tile by tile. */
  opacity: 0;
  transition: opacity 0.25s ease;
}

.atile__img[data-loaded='true'] {
  opacity: 1;
}

.atile__img--empty {
  display: grid;
  place-items: center;
  opacity: 1;
  color: var(--text-faint);
  font-size: var(--t-2xl);
  font-weight: 300;
}

.atile__meta {
  position: absolute;
  inset: auto 0 0 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: var(--s-6) var(--s-3) var(--s-3);
  background: linear-gradient(to top, rgba(8, 11, 18, 0.88) 0%, rgba(8, 11, 18, 0.6) 45%, transparent 100%);
  color: #fff;
  pointer-events: none;
}

.atile__name {
  font-size: var(--t-sm);
  font-weight: 600;
  letter-spacing: -0.005em;
  /* Two lines, because a tile is ~156px wide and most of these names do not fit
     on one. Truncating them made adjacent variants indistinguishable. */
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}

.atile__voice {
  font-size: var(--t-xs);
  color: rgba(255, 255, 255, 0.72);
}

/* Corner flags: the 1080p mark and the "selected" tick. */
.atile__flags {
  position: absolute;
  inset: var(--s-2) var(--s-2) auto var(--s-2);
  display: flex;
  align-items: center;
  gap: var(--s-1);
  pointer-events: none;
}

.atile__flag {
  padding: 2px 6px;
  border-radius: var(--r-sm);
  background: rgba(8, 11, 18, 0.6);
  backdrop-filter: blur(4px);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.atile__tick {
  margin-left: auto;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: var(--r-full);
  background: var(--accent);
  color: #fff;
  box-shadow: 0 1px 4px rgba(8, 11, 18, 0.4);
  transform: scale(0);
  transition: transform 0.18s cubic-bezier(0.2, 1.4, 0.4, 1);
}

.atile[aria-pressed='true'] .atile__tick {
  transform: scale(1);
}

/* -- picker states -------------------------------------------------------- */

.apick__state {
  /* Spans every column: it is a child of the auto-fill grid, so without this it
     is laid out as one ~150px tile and the message wraps one word per line. */
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-12) var(--s-5);
  text-align: center;
  color: var(--text-faint);
}

.apick__state-title {
  font-size: var(--t-md);
  font-weight: 600;
  color: var(--text-dim);
}

.apick__skeleton {
  border-radius: var(--r-lg);
  aspect-ratio: 3 / 4;
  background: linear-gradient(100deg, var(--bg-sunken) 30%, var(--bg-active) 50%, var(--bg-sunken) 70%);
  background-size: 220% 100%;
  animation: apick-shimmer 1.1s linear infinite;
}

@keyframes apick-shimmer {
  from {
    background-position: 130% 0;
  }
  to {
    background-position: -30% 0;
  }
}

@media (max-width: 560px) {
  .apick__grid {
    grid-template-columns: repeat(auto-fill, minmax(122px, 1fr));
    gap: var(--s-3);
  }
  .apick__head,
  .apick__toolbar,
  .apick__body,
  .apick__foot {
    padding-left: var(--s-4);
    padding-right: var(--s-4);
  }
  .apick__foot {
    flex-wrap: wrap;
  }
  .apick__actions {
    width: 100%;
  }
  .apick__actions .btn {
    flex: 1 1 auto;
  }
}

/* -- avatar picker trigger -------------------------------------------------
 * The control that opens the gallery. A framed row rather than a bare button:
 * "which avatar is chosen" is the answer this field exists to show, so the
 * thumbnail is the control's content, not decoration next to it.
 */

.atrigger {
  display: flex;
  align-items: center;
  gap: var(--s-4);
  width: 100%;
  padding: var(--s-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  background: var(--bg-raised);
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.14s, box-shadow 0.14s, background 0.14s;
}

.atrigger:hover {
  border-color: var(--accent-border);
  background: var(--accent-soft);
}

.atrigger:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}

.atrigger__img {
  width: 54px;
  height: 68px;
  flex: 0 0 auto;
  border-radius: var(--r-md);
  object-fit: cover;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
}

.atrigger__img--empty {
  display: grid;
  place-items: center;
  border-style: dashed;
  border-color: var(--border-strong);
  color: var(--text-faint);
}

.atrigger__body {
  min-width: 0;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.atrigger__name {
  font-size: var(--t-md);
  font-weight: 600;
  letter-spacing: -0.008em;
}

.atrigger__meta {
  font-size: var(--t-sm);
  color: var(--text-faint);
}

.atrigger__cta {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  padding: 0 var(--s-3);
  height: 30px;
  border-radius: var(--r-md);
  border: 1px solid var(--accent-border);
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: var(--t-sm);
  font-weight: 600;
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.985);
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

/* -- status dot ----------------------------------------------------------- */

.dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--text-faint);
  transition: background 0.2s, box-shadow 0.2s;
}

.dot[data-phase='idle'] {
  background: var(--good);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 18%, transparent);
}
.dot[data-phase='listening'] {
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  animation: pulse 1.3s ease-in-out infinite;
}
.dot[data-phase='thinking'] {
  background: var(--warn);
  animation: pulse 1s ease-in-out infinite;
}
.dot[data-phase='speaking'] {
  background: var(--brand-glow);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-glow) 22%, transparent);
}
.dot[data-phase='offline'] {
  background: var(--bad);
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

/* -- utility -------------------------------------------------------------- */

.row {
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

/*
 * A voice dropdown and its Test button. Its own class rather than `.row`
 * because the select has to give the button its width instead of the two
 * splitting the line evenly, and the button must not wrap under the select in
 * the studio's narrow drawer.
 */
.voicepick {
  display: flex;
  align-items: center;
  gap: var(--s-2);
}
.voicepick .select {
  flex: 1 1 auto;
  min-width: 0;
}
.voicepick__test {
  flex: none;
  min-width: 72px;
}
.row--wrap {
  flex-wrap: wrap;
}
.spacer {
  margin-left: auto;
}
.stack {
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
}
.stack--tight {
  gap: var(--s-2);
}
.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--s-4);
}
.muted {
  color: var(--text-dim);
}
.faint {
  color: var(--text-faint);
}
.small {
  font-size: var(--t-sm);
}
.tabular {
  font-variant-numeric: tabular-nums;
}
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.code-block {
  margin: 0;
  padding: var(--s-4);
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--bg-sunken);
  font-family: var(--mono);
  font-size: var(--t-sm);
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 60vh;
  overflow-y: auto;
}

.divider {
  height: 1px;
  background: var(--border);
  border: 0;
  margin: 0;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
