/* ==========================================================================
   VLN8N — design system

   A production tool, not a marketing site. The palette follows professional
   audio and video editors — deep blue-grey panels with one cyan accent — so
   long editing sessions stay comfortable and the interface reads as an
   instrument rather than a landing page. Small sharp radii, a real
   typographic scale, no gradients and no decorative glow.
   ========================================================================== */

/* --- Tokens ------------------------------------------------------------- */

:root {
  /* Surfaces: deep blue-grey, the tone of an editing suite. */
  --ink-900: #0e1420;
  --ink-850: #141c2b;
  --ink-800: #1a2435;
  --ink-750: #1f2a3d;
  --ink-700: #243146;
  --ink-600: #32415a;
  --ink-500: #46587a;

  /* Text: cool near-white, high contrast against the panels. */
  --paper-100: #e8eef7;
  --paper-200: #d2dced;
  --paper-300: #aebdd4;
  --paper-400: #93a4bd;
  --paper-500: #8496af;

  /* One accent, used sparingly, never as a gradient. */
  --accent-400: #22b8cf;
  --accent-500: #1ba3ba;
  --accent-600: #15869b;
  --accent-tint: rgba(34, 184, 207, 0.15);

  /* Status */
  --ok-400: #3ddc97;
  --ok-tint: rgba(61, 220, 151, 0.14);
  --warn-400: #ffb84d;
  --warn-tint: rgba(255, 184, 77, 0.14);
  --bad-400: #ff6b6b;
  --bad-tint: rgba(255, 107, 107, 0.14);
  --info-400: #5aa9e6;
  --info-tint: rgba(90, 169, 230, 0.14);

  /* Type */
  --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --font-serif: "Iowan Old Style", "Palatino Linotype", Georgia, serif;

  /* A real scale, not arbitrary sizes. Ratio ~1.2, floor 11px. */
  --t-xs: 0.6875rem;   /* 11px — functional floor, labels only */
  --t-sm: 0.8125rem;   /* 13px */
  --t-base: 0.9375rem; /* 15px — body */
  --t-md: 1.0625rem;   /* 17px */
  --t-lg: 1.3125rem;   /* 21px */
  --t-xl: 1.625rem;    /* 26px */
  --t-2xl: 2.125rem;   /* 34px */
  --t-3xl: 2.75rem;    /* 44px */

  /* Spacing: 4px base. */
  --s-1: 0.25rem;
  --s-2: 0.5rem;
  --s-3: 0.75rem;
  --s-4: 1rem;
  --s-5: 1.5rem;
  --s-6: 2rem;
  --s-7: 3rem;
  --s-8: 4rem;

  /* Small, deliberate radii. */
  --r-sm: 3px;
  --r-md: 5px;
  --r-lg: 8px;

  --line: 1px solid var(--ink-700);
  --line-soft: 1px solid var(--ink-750);

  /* Shadows are flat and dark, never coloured glow. */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.42);
  --shadow-lg: 0 18px 44px rgba(0, 0, 0, 0.5);

  --header-h: 56px;
  --rail-h: 44px;
  --max-measure: 74ch;

  color-scheme: dark;
}

/* Light mode: same system, inverted. Respects the OS setting and the toggle. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --ink-900: #f7f9fc;
    --ink-850: #ffffff;
    --ink-800: #eef2f8;
    --ink-750: #e3e9f2;
    --ink-700: #d0d9e6;
    --ink-600: #adbacd;
    --ink-500: #8496af;
    --paper-100: #101722;
    --paper-200: #24303f;
    --paper-300: #41506a;
    --paper-400: #4a5870;
    --paper-500: #5c6b85;
    --accent-400: #0b7286;
    --accent-500: #0d7f95;
    --accent-600: #0a6a7d;
    --accent-tint: rgba(13, 127, 149, 0.10);

    /*
     * The status colours need their own light-mode values, not the dark ones.
     *
     * Measured on the light surfaces, the dark-mode tokens come out at
     * 1.57:1 - 2.78:1 — well under the 4.5:1 body text needs — and they are used
     * for every ok/warn/bad/info badge, every notice icon and all `.error-text` in
     * the app. An error message nobody can read is worse than no error message,
     * because the form then looks as though it did nothing at all.
     *
     * Measured on white / page / tinted panel:
     *   ok 5.37 / 5.09 / 4.78   ·  warn 6.39 / 6.06 / 5.69
     *   bad 6.54 / 6.20 / 5.82  ·  info 6.59 / 6.25 / 5.86
     *
     * The tints are rebuilt from the same hues, so a badge's background still
     * belongs to its text rather than being a pale wash of a different green.
     */
    --ok-400:    #0f7a4d;
    --ok-tint:   rgba(15, 122, 77, 0.12);
    --warn-400:  #8a5200;
    --warn-tint: rgba(138, 82, 0, 0.12);
    --bad-400:   #b3261e;
    --bad-tint:  rgba(179, 38, 30, 0.12);
    --info-400:  #0b5fa4;
    --info-tint: rgba(11, 95, 164, 0.12);
    --shadow-sm: 0 1px 2px rgba(20, 35, 60, 0.08);
    --shadow-md: 0 4px 14px rgba(20, 35, 60, 0.10);
    --shadow-lg: 0 18px 44px rgba(20, 35, 60, 0.14);
    color-scheme: light;
  }
}

:root[data-theme="light"] {
  --ink-900: #f7f9fc;
  --ink-850: #ffffff;
  --ink-800: #eef2f8;
  --ink-750: #e3e9f2;
  --ink-700: #d0d9e6;
  --ink-600: #adbacd;
  --ink-500: #8496af;
  --paper-100: #101722;
  --paper-200: #24303f;
  --paper-300: #41506a;
  --paper-400: #4a5870;
  --paper-500: #5c6b85;
  --accent-400: #0b7286;
  --accent-500: #0d7f95;
  --accent-600: #0a6a7d;
  --accent-tint: rgba(13, 127, 149, 0.10);

  /*
   * The status colours need their own light-mode values, not the dark ones.
   *
   * Measured on the light surfaces, the dark-mode tokens come out at
   * 1.57:1 - 2.78:1 — well under the 4.5:1 body text needs — and they are used
   * for every ok/warn/bad/info badge, every notice icon and all `.error-text` in
   * the app. An error message nobody can read is worse than no error message,
   * because the form then looks as though it did nothing at all.
   *
   * Measured on white / page / tinted panel:
   *   ok 5.37 / 5.09 / 4.78   ·  warn 6.39 / 6.06 / 5.69
   *   bad 6.54 / 6.20 / 5.82  ·  info 6.59 / 6.25 / 5.86
   *
   * The tints are rebuilt from the same hues, so a badge's background still
   * belongs to its text rather than being a pale wash of a different green.
   */
  --ok-400:    #0f7a4d;
  --ok-tint:   rgba(15, 122, 77, 0.12);
  --warn-400:  #8a5200;
  --warn-tint: rgba(138, 82, 0, 0.12);
  --bad-400:   #b3261e;
  --bad-tint:  rgba(179, 38, 30, 0.12);
  --info-400:  #0b5fa4;
  --info-tint: rgba(11, 95, 164, 0.12);
  --shadow-sm: 0 1px 2px rgba(20, 35, 60, 0.08);
  --shadow-md: 0 4px 14px rgba(20, 35, 60, 0.10);
  --shadow-lg: 0 18px 44px rgba(20, 35, 60, 0.14);
  color-scheme: light;
}

/* --- Reset -------------------------------------------------------------- */

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

/* `hidden` must win over the display rules further down. Without this, any
   element that is also a .row/.badge/.tabpanel stays visible when JS sets
   element.hidden = true. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--ink-900);
  color: var(--paper-200);
  font-family: var(--font-sans);
  font-size: var(--t-base);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv05" 1, "ss01" 1;
}

h1, h2, h3, h4 {
  margin: 0;
  color: var(--paper-100);
  font-weight: 600;
  line-height: 1.22;
  letter-spacing: -0.014em;
}

h1 { font-size: var(--t-2xl); }
h2 { font-size: var(--t-xl); }
h3 { font-size: var(--t-lg); }
h4 { font-size: var(--t-md); }

p { margin: 0 0 var(--s-4); max-width: var(--max-measure); }
p:last-child { margin-bottom: 0; }

a { color: var(--accent-400); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--accent-500); }

img, svg, video { max-width: 100%; height: auto; display: block; }

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

hr { border: 0; border-top: var(--line); margin: var(--s-5) 0; }

::selection { background: var(--accent-tint); color: var(--paper-100); }

/* Focus is always visible. Never remove it. */
:focus-visible {
  outline: 2px solid var(--accent-400);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* Scrollbars, matched to the surface. */
* { scrollbar-width: thin; scrollbar-color: var(--ink-600) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--ink-600); border-radius: 99px; border: 3px solid var(--ink-900); }
::-webkit-scrollbar-thumb:hover { background: var(--ink-500); }

/* --- Layout ------------------------------------------------------------- */

.shell { display: flex; flex-direction: column; min-height: 100vh; }

/*
 * The working application uses the whole browser width — a script editor has
 * no reason to leave half the screen empty. Reading pages (marketing, legal,
 * help, sign-in) stay measured, because long lines of prose are hard to read.
 */
.container {
  width: 100%;
  max-width: var(--container-max, 1320px);
  margin: 0 auto;
  padding-inline: var(--s-4);
}
body.is-app .container { --container-max: none; padding-inline: var(--s-5); }
@media (max-width: 720px) {
  body.is-app .container { padding-inline: var(--s-4); }
}
.container--narrow { max-width: 820px; }
.container--mid { max-width: 1080px; }

.page { padding-block: var(--s-6) var(--s-8); flex: 1; }

.page-head {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-4);
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: var(--s-5);
}
.page-head__title { display: flex; flex-direction: column; gap: var(--s-2); }
.page-head__actions { display: flex; flex-wrap: wrap; gap: var(--s-2); }

.eyebrow {
  font-size: var(--t-xs);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--paper-500);
}

.lede { font-size: var(--t-md); color: var(--paper-300); max-width: 60ch; }

.stack > * + * { margin-top: var(--s-4); }
.stack-sm > * + * { margin-top: var(--s-2); }
.stack-lg > * + * { margin-top: var(--s-6); }

.row { display: flex; gap: var(--s-3); align-items: center; flex-wrap: wrap; }
.row--tight { gap: var(--s-2); }
.row--between { justify-content: space-between; }
.row--end { justify-content: flex-end; }
.spacer { flex: 1; }

.grid { display: grid; gap: var(--s-4); }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid--3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid--4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

/* Two-pane tool layout: input on the left, result on the right. */
.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-4);
  align-items: start;
}
@media (max-width: 960px) { .split { grid-template-columns: 1fr; } }

/* --- Header ------------------------------------------------------------- */

.masthead {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--ink-850) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: var(--line);
}

.masthead__inner {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: var(--s-4);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  font-weight: 650;
  font-size: var(--t-md);
  color: var(--paper-100);
  text-decoration: none;
  letter-spacing: -0.02em;
  white-space: nowrap;
}
.brand__mark {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border-radius: var(--r-sm);
  background: var(--accent-500);
  color: var(--ink-900);
  font-weight: 700; font-size: var(--t-sm);
  font-family: var(--font-mono);
}
.brand img { width: auto; height: 26px; }

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

/* On a phone the navigation loses its wording, never its links. The icons
   stay tappable and keep their tooltip, so Library and Admin are always one
   tap away — previously the whole nav was hidden below 720px and there was
   no way to reach either. */
@media (max-width: 720px) {
  .masthead__nav--icons .navlink__label { display: none; }
  .masthead__nav--icons .navlink { padding-inline: var(--s-2); }
  .masthead__nav { gap: 2px; flex-wrap: nowrap; }
  .masthead__nav .navlink { font-size: var(--t-xs); padding-inline: var(--s-2); }
  .masthead--public .masthead__inner { height: auto; min-height: var(--header-h); flex-wrap: wrap; padding-block: var(--s-2); gap: var(--s-2); }
  .masthead--public .spacer { display: none; }
  .masthead--public .masthead__nav { width: 100%; justify-content: space-between; flex-wrap: wrap; }
}

.navlink {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-md);
  font-size: var(--t-sm);
  font-weight: 500;
  color: var(--paper-300);
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s;
}
.navlink:hover { background: var(--ink-800); color: var(--paper-100); }
.navlink[aria-current="page"] { background: var(--ink-800); color: var(--paper-100); }
.navlink[aria-current="page"] .icon { color: var(--accent-400); }

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

.toolbar-tabs {
  position: sticky;
  top: var(--header-h);
  z-index: 30;
  background: var(--ink-900);
  border-bottom: var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}
.toolbar-tabs::-webkit-scrollbar { display: none; }
.toolbar-tabs__inner { display: flex; gap: var(--s-1); min-height: 44px; align-items: stretch; }

.tooltab {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  padding: 0 var(--s-3);
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--paper-400);
  font-size: var(--t-sm);
  font-weight: 500;
  font-family: inherit;
  white-space: nowrap;
  cursor: pointer;
  text-decoration: none;
  transition: color 0.12s, border-color 0.12s;
}
.tooltab:hover { color: var(--paper-100); }
.tooltab[aria-current="page"] { color: var(--paper-100); border-bottom-color: var(--accent-400); }
.tooltab--locked { color: var(--paper-500); }
.tooltab--locked .icon { opacity: 0.6; }

/* --- Cards -------------------------------------------------------------- */

.card {
  background: var(--ink-850);
  border: var(--line);
  border-radius: var(--r-lg);
  padding: var(--s-5);
}
.card--flush { padding: 0; overflow: hidden; }
.card--raised { box-shadow: var(--shadow-md); }

.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  padding-bottom: var(--s-3);
  margin-bottom: var(--s-4);
  border-bottom: var(--line);
}
.card--flush .card__head { padding: var(--s-4) var(--s-5); margin-bottom: 0; }
.card__title { font-size: var(--t-md); font-weight: 600; color: var(--paper-100); }
.card__body { padding: var(--s-5); }
.card__foot {
  padding: var(--s-4) var(--s-5);
  border-top: var(--line);
  background: var(--ink-800);
  display: flex; gap: var(--s-2); justify-content: flex-end; flex-wrap: wrap;
}

/* Stat tile */
.stat {
  background: var(--ink-850);
  border: var(--line);
  border-radius: var(--r-lg);
  padding: var(--s-4);
}
.stat__label {
  font-size: var(--t-xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--paper-500);
  font-weight: 600;
}
.stat__value {
  margin-top: var(--s-2);
  font-size: var(--t-xl);
  font-weight: 650;
  color: var(--paper-100);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.stat__note { margin-top: var(--s-1); font-size: var(--t-sm); color: var(--paper-400); }

/* --- Buttons ------------------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  padding: var(--s-2) var(--s-4);
  min-height: 36px;
  /* Every button is the same height whatever it contains, so a row of them
     reads as one control strip rather than a jumble. */
  flex: none;
  border: var(--line);
  border-radius: var(--r-md);
  background: var(--ink-750);
  color: var(--paper-100);
  font-family: inherit;
  font-size: var(--t-sm);
  font-weight: 550;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, transform 0.06s;
}
.btn:hover { background: var(--ink-700); border-color: var(--ink-600); }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.45; pointer-events: none; }

.btn--primary {
  background: var(--accent-500);
  border-color: var(--accent-500);
  color: #06232b;
  font-weight: 600;
}
.btn--primary:hover { background: var(--accent-400); border-color: var(--accent-400); }

.btn--ghost { background: transparent; border-color: transparent; color: var(--paper-300); }
.btn--ghost:hover { background: var(--ink-800); color: var(--paper-100); }

.btn--danger { background: transparent; border-color: var(--bad-400); color: var(--bad-400); }
.btn--danger:hover { background: var(--bad-tint); }

.btn--sm { min-height: 30px; padding: var(--s-1) var(--s-3); font-size: var(--t-xs); }
.btn--lg { min-height: 44px; padding: var(--s-3) var(--s-5); font-size: var(--t-base); }
.btn--block { width: 100%; }
.btn--icon { padding: var(--s-2); min-width: 36px; }

.btn .icon { width: 16px; height: 16px; flex: none; }

/* Busy state driven by JS */
.btn.is-busy { pointer-events: none; opacity: 0.7; }
.btn.is-busy::after {
  content: "";
  width: 13px; height: 13px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Forms -------------------------------------------------------------- */

.field { display: flex; flex-direction: column; gap: var(--s-2); }
.field + .field { margin-top: var(--s-4); }

.label {
  font-size: var(--t-sm);
  font-weight: 550;
  color: var(--paper-200);
  display: flex; align-items: center; gap: var(--s-2);
}
.label__hint { font-weight: 400; color: var(--paper-500); font-size: var(--t-xs); }

.help { font-size: var(--t-sm); color: var(--paper-400); line-height: 1.5; }
.error-text { font-size: var(--t-sm); color: var(--bad-400); }

.input, .select, .textarea {
  width: 100%;
  padding: var(--s-2) var(--s-3);
  min-height: 38px;
  background: var(--ink-800);
  border: var(--line);
  border-radius: var(--r-md);
  color: var(--paper-100);
  font-family: inherit;
  font-size: var(--t-base);
  line-height: 1.5;
  transition: border-color 0.12s, background 0.12s;
}
.input::placeholder, .textarea::placeholder { color: var(--paper-500); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--ink-600); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent-500);
  background: var(--ink-850);
  box-shadow: 0 0 0 3px var(--accent-tint);
}
.input[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--bad-400); }

.textarea { min-height: 200px; resize: vertical; font-family: var(--font-mono); font-size: var(--t-sm); line-height: 1.65; }
.textarea--tall { min-height: 420px; }
.textarea--prose { font-family: var(--font-sans); font-size: var(--t-base); }

.select {
  appearance: none;
  padding-right: var(--s-6);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath fill='none' stroke='%239a9383' stroke-width='1.6' stroke-linecap='round' d='m3 4.5 3 3 3-3'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--s-3) center;
  background-size: 12px;
}

/* Checkbox and radio */
.check { display: flex; align-items: flex-start; gap: var(--s-2); cursor: pointer; font-size: var(--t-sm); }
.check input { margin: 3px 0 0; width: 15px; height: 15px; accent-color: var(--accent-500); flex: none; cursor: pointer; }
.check__text { color: var(--paper-200); }
.check__note { display: block; color: var(--paper-500); font-size: var(--t-xs); margin-top: 2px; }

/* Switch, for on/off settings */
.switch { display: inline-flex; align-items: center; gap: var(--s-3); cursor: pointer; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch__track {
  width: 38px; height: 21px; flex: none;
  background: var(--ink-700);
  border-radius: 99px;
  position: relative;
  transition: background 0.16s;
}
.switch__track::after {
  content: "";
  position: absolute; top: 3px; left: 3px;
  width: 15px; height: 15px;
  background: var(--paper-300);
  border-radius: 50%;
  transition: transform 0.16s, background 0.16s;
}
.switch input:checked + .switch__track { background: var(--accent-600); }
.switch input:checked + .switch__track::after { transform: translateX(17px); background: var(--paper-100); }
.switch input:focus-visible + .switch__track { outline: 2px solid var(--accent-400); outline-offset: 2px; }

/* Segmented control */
.segmented {
  display: inline-flex;
  padding: 2px;
  background: var(--ink-800);
  border: var(--line);
  border-radius: var(--r-md);
  gap: 2px;
}
.segmented button, .segmented a {
  border: 0; background: transparent;
  padding: var(--s-1) var(--s-3);
  min-height: 28px;
  border-radius: var(--r-sm);
  color: var(--paper-400);
  font-family: inherit; font-size: var(--t-sm); font-weight: 500;
  cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; gap: var(--s-1);
}
.segmented button:hover, .segmented a:hover { color: var(--paper-100); }
.segmented [aria-pressed="true"], .segmented [aria-current="true"] {
  background: var(--ink-700); color: var(--paper-100);
}

/* Inline form row */
/*
 * Fields laid out side by side line up with each other: labels on one line,
 * controls on the next, help text underneath. Without this a field carrying a
 * hint sits lower than its neighbour, which is the ragged look people notice
 * immediately even when they cannot name it.
 */
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--s-3) var(--s-4);
  align-items: start;
}
.form-row > .field {
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: var(--s-2);
  margin-top: 0;
}
.form-row > .field > .label { align-self: end; margin: 0; }
.form-row > .field > .help,
.form-row > .field > .error-text { margin: 0; align-self: start; }

/*
 * Filter bar. Each field is its own three-row grid — label, control, hint —
 * and all of them start at the same top edge, so the labels sit on one line
 * and the controls on the next however many hints there are. The actions sit
 * on their own line beneath, which always aligns and never fights the grid.
 */
.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: var(--s-4);
  align-items: start;
}
.filters--users { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.filters > .field {
  display: grid;
  grid-template-rows: auto auto auto;
  align-content: start;
  gap: var(--s-2);
  margin-top: 0;
}
.filters > .field > .label { margin: 0; }
.filters > .field > .help,
.filters > .field > .error-text { margin: 0; }

.filters__actions {
  grid-column: 1 / -1;
  display: flex;
  gap: var(--s-2);
  align-items: center;
  justify-content: flex-end;
  padding-top: var(--s-3);
  border-top: var(--line-soft);
}
@media (max-width: 720px) {
  .filters, .filters--users { grid-template-columns: 1fr; }
  .filters__actions { flex-wrap: wrap; }
  .filters__actions .btn { flex: 1 1 auto; }
}
@media (min-width: 721px) and (max-width: 980px) {
  .filters--users { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* --- Badges and pills --------------------------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  padding: 2px var(--s-2);
  border-radius: var(--r-sm);
  font-size: var(--t-xs);
  font-weight: 600;
  letter-spacing: 0.02em;
  background: var(--ink-750);
  color: var(--paper-300);
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge--ok { background: var(--ok-tint); color: var(--ok-400); }
.badge--warn { background: var(--warn-tint); color: var(--warn-400); }
.badge--bad { background: var(--bad-tint); color: var(--bad-400); }
.badge--info { background: var(--info-tint); color: var(--info-400); }
.badge--accent { background: var(--accent-tint); color: var(--accent-400); }

.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--paper-500); flex: none; }
.dot--ok { background: var(--ok-400); }
.dot--bad { background: var(--bad-400); }
.dot--live { background: var(--ok-400); box-shadow: 0 0 0 0 var(--ok-tint); animation: pulse 2.4s infinite; }
@keyframes pulse {
  70% { box-shadow: 0 0 0 6px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* --- Tables ------------------------------------------------------------- */

.table-wrap {
  overflow-x: auto;
  border-radius: var(--r-lg);
  border: var(--line);
  /* Positioned, so absolutely-placed children inside the table (the
     screen-reader-only labels) resolve against this scroller rather than
     the page — otherwise a wide table pushes the whole document sideways. */
  position: relative;
}

.table { width: 100%; border-collapse: collapse; font-size: var(--t-sm); }
.table th {
  text-align: left;
  padding: var(--s-3) var(--s-4);
  background: var(--ink-800);
  color: var(--paper-400);
  font-size: var(--t-xs);
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  border-bottom: var(--line);
  position: sticky; top: 0;
}
.table td { padding: var(--s-3) var(--s-4); border-bottom: var(--line-soft); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--ink-800); }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--font-mono); }
.table .cell-actions { display: flex; gap: var(--s-1); justify-content: flex-end; }

/* Card-per-row on small screens, so tables never overflow the viewport. */
@media (max-width: 720px) {
  .table--stack thead { display: none; }
  .table--stack tr {
    display: block;
    padding: var(--s-3) var(--s-4);
    border-bottom: var(--line);
  }
  .table--stack td {
    display: flex; justify-content: space-between; gap: var(--s-4);
    padding: var(--s-1) 0; border: 0;
  }
  .table--stack td::before {
    content: attr(data-label);
    font-size: var(--t-xs); text-transform: uppercase; letter-spacing: 0.06em;
    color: var(--paper-500); font-weight: 650; flex: none;
  }
  .table--stack .cell-actions { justify-content: flex-start; padding-top: var(--s-2); }

  /* A stacked row is a flex container, and a flex item will not shrink below
     a nowrap child — so a long file name pushed the whole page sideways.
     Inside a stacked table, truncation gives way to wrapping. */
  .table--stack .truncate {
    white-space: normal;
    overflow: visible;
    overflow-wrap: anywhere;
  }
  .table--stack td { min-width: 0; }
}

/* --- Empty and loading states ------------------------------------------ */

.empty {
  text-align: center;
  padding: var(--s-7) var(--s-4);
  color: var(--paper-400);
}
.empty__icon { color: var(--ink-600); margin: 0 auto var(--s-3); width: 30px; height: 30px; }
.empty__title { color: var(--paper-200); font-weight: 600; font-size: var(--t-md); margin-bottom: var(--s-2); }
.empty p { margin-inline: auto; max-width: 42ch; font-size: var(--t-sm); }

.skeleton {
  background: linear-gradient(90deg, var(--ink-800) 25%, var(--ink-750) 50%, var(--ink-800) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--r-sm);
  height: 1em;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* --- Notices ------------------------------------------------------------ */

.notice {
  display: flex;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-md);
  border: var(--line);
  background: var(--ink-800);
  font-size: var(--t-sm);
  line-height: 1.55;
}
.notice .icon { flex: none; width: 18px; height: 18px; margin-top: 1px; }
.notice__body { min-width: 0; }
.notice__title { font-weight: 600; color: var(--paper-100); margin-bottom: 2px; }
.notice--ok { border-color: color-mix(in srgb, var(--ok-400) 40%, transparent); background: var(--ok-tint); }
.notice--ok .icon { color: var(--ok-400); }
.notice--warn { border-color: color-mix(in srgb, var(--warn-400) 40%, transparent); background: var(--warn-tint); }
.notice--warn .icon { color: var(--warn-400); }
.notice--bad { border-color: color-mix(in srgb, var(--bad-400) 40%, transparent); background: var(--bad-tint); }
.notice--bad .icon { color: var(--bad-400); }
.notice--info { border-color: color-mix(in srgb, var(--info-400) 40%, transparent); background: var(--info-tint); }
.notice--info .icon { color: var(--info-400); }

/* --- Toasts ------------------------------------------------------------- */

.toasts {
  position: fixed;
  right: var(--s-4); bottom: var(--s-4);
  z-index: 200;
  display: flex; flex-direction: column; gap: var(--s-2);
  max-width: min(380px, calc(100vw - 2 * var(--s-4)));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: flex-start; gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  background: var(--ink-750);
  border: var(--line);
  border-left: 3px solid var(--paper-500);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  font-size: var(--t-sm);
  animation: toast-in 0.18s ease-out;
}
.toast--success { border-left-color: var(--ok-400); }
.toast--error { border-left-color: var(--bad-400); }
.toast--warning { border-left-color: var(--warn-400); }
.toast--info { border-left-color: var(--info-400); }
.toast__close { margin-left: auto; background: none; border: 0; color: var(--paper-500); cursor: pointer; padding: 0; }
.toast__close:hover { color: var(--paper-100); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* --- Meters ------------------------------------------------------------- */

.meter { display: flex; flex-direction: column; gap: var(--s-1); }
.meter__head {
  display: flex; justify-content: space-between; gap: var(--s-2);
  font-size: var(--t-xs); color: var(--paper-400);
}
.meter__value { font-family: var(--font-mono); color: var(--paper-200); font-variant-numeric: tabular-nums; }
.meter__track { height: 4px; background: var(--ink-700); border-radius: 99px; overflow: hidden; }
.meter__fill { height: 100%; background: var(--accent-500); border-radius: 99px; transition: width 0.3s ease; }
.meter__fill--warn { background: var(--warn-400); }
.meter__fill--bad { background: var(--bad-400); }

/* --- Locked features ---------------------------------------------------- */

.locked { position: relative; }
.locked > .locked__veil {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--ink-900) 80%, transparent);
  backdrop-filter: blur(2px);
  border-radius: inherit;
  z-index: 5;
  padding: var(--s-4);
}
.locked__card {
  max-width: 34ch;
  text-align: center;
  background: var(--ink-800);
  border: var(--line);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  box-shadow: var(--shadow-md);
}
.locked__card .icon { color: var(--accent-400); width: 22px; height: 22px; margin: 0 auto var(--s-3); }
.locked__card p { font-size: var(--t-sm); color: var(--paper-300); margin-bottom: var(--s-4); }

/* Inline lock on a single control */
.is-locked { opacity: 0.5; cursor: not-allowed; }

/* --- Modals ------------------------------------------------------------- */

dialog.modal {
  padding: 0;
  border: var(--line);
  border-radius: var(--r-lg);
  background: var(--ink-850);
  color: var(--paper-200);
  max-width: min(680px, calc(100vw - 2 * var(--s-4)));
  width: 100%;
  box-shadow: var(--shadow-lg);
}
dialog.modal--wide { max-width: min(1040px, calc(100vw - 2 * var(--s-4))); }
dialog.modal::backdrop { background: rgba(10, 9, 7, 0.68); backdrop-filter: blur(3px); }
.modal__head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-3);
  padding: var(--s-4) var(--s-5); border-bottom: var(--line);
}
.modal__body { padding: var(--s-5); max-height: min(70vh, 640px); overflow-y: auto; }
.modal__foot {
  padding: var(--s-4) var(--s-5); border-top: var(--line);
  display: flex; gap: var(--s-2); justify-content: flex-end; flex-wrap: wrap;
  background: var(--ink-800);
}

/* --- Tabs (in-page) ----------------------------------------------------- */

/*
 * Tabs wrap; they do not scroll sideways.
 *
 * This was `overflow-x: auto` with the scrollbar hidden, so on any screen with
 * more tabs than fit — /help measured 1389px of tabs in a 358px box on a phone,
 * the plan feature matrix 1501px in 1254px — the rest were simply invisible,
 * with nothing on screen to say they existed. Hiding the scrollbar made that
 * worse, not better. Wrapping shows every tab at every width, which is the
 * entire point of a tab strip.
 */
.tabs {
  border-bottom: var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-1);
  row-gap: 0;
}
.tab {
  padding: var(--s-2) var(--s-3);
  border: 0; border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--paper-400);
  font-family: inherit; font-size: var(--t-sm); font-weight: 500;
  cursor: pointer; white-space: nowrap; text-decoration: none;
  display: inline-flex; align-items: center; gap: var(--s-2);
}
.tab:hover { color: var(--paper-100); }
.tab[aria-selected="true"] { color: var(--paper-100); border-bottom-color: var(--accent-400); }
.tab__count {
  font-size: var(--t-xs); font-family: var(--font-mono);
  background: var(--ink-750); padding: 1px 5px; border-radius: var(--r-sm); color: var(--paper-400);
}
.tabpanel[hidden] { display: none; }

/* --- Utility ------------------------------------------------------------ */

.icon { width: 18px; height: 18px; flex: none; }
.icon--sm { width: 14px; height: 14px; }
.icon--lg { width: 24px; height: 24px; }

.muted { color: var(--paper-400); }
.faint { color: var(--paper-500); }
.strong { color: var(--paper-100); font-weight: 600; }
.nums { font-variant-numeric: tabular-nums; font-family: var(--font-mono); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.text-sm { font-size: var(--t-sm); }
.text-xs { font-size: var(--t-xs); }
.center { text-align: center; }

.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;
}

.skip-link {
  position: absolute; left: var(--s-3); top: -100px;
  z-index: 300; padding: var(--s-2) var(--s-4);
  background: var(--accent-500); color: #06232b;
  border-radius: var(--r-md); font-weight: 600; font-size: var(--t-sm);
  text-decoration: none;
}
.skip-link:focus { top: var(--s-3); }

.hide-sm { }
@media (max-width: 720px) { .hide-sm { display: none !important; } }
@media (min-width: 721px) { .only-sm { display: none !important; } }

/* --- Footer ------------------------------------------------------------- */

.footer {
  border-top: var(--line);
  padding-block: var(--s-5);
  margin-top: var(--s-7);
  font-size: var(--t-sm);
  color: var(--paper-500);
}
.footer a { color: var(--paper-400); text-decoration: none; }
.footer a:hover { color: var(--paper-200); text-decoration: underline; }
.footer__inner { display: flex; flex-wrap: wrap; gap: var(--s-4); justify-content: space-between; align-items: center; }

/* --- Motion preferences ------------------------------------------------- */

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

/* --- Print -------------------------------------------------------------- */

@media print {
  .masthead, .toolbar-tabs, .footer, .toasts, .page-head__actions { display: none !important; }
  body { background: #fff; color: #000; }
  .card { border: 1px solid #ccc; }
}

/* --- Avatar ------------------------------------------------------------- */

.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  object-fit: cover; flex: none;
  background: var(--ink-700);
}
.avatar--sm { width: 24px; height: 24px; }
.avatar--lg { width: 72px; height: 72px; }
.avatar--initial {
  display: grid; place-items: center;
  /* Tinted rather than solid: the initial has to stay legible at 24px,
     and light text on the solid accent does not reach 4.5:1. */
  background: var(--accent-tint);
  color: var(--accent-400);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent-400) 35%, transparent);
  font-weight: 650; font-size: var(--t-sm);
}
.avatar--lg.avatar--initial { font-size: var(--t-xl); }

/* --- Dropdown menu ------------------------------------------------------ */

.menu { position: relative; }
.menu > summary { list-style: none; cursor: pointer; }
.menu > summary::-webkit-details-marker { display: none; }
.menu__panel {
  position: absolute; right: 0; top: calc(100% + 6px);
  min-width: 236px; z-index: 60;
  background: var(--ink-800);
  border: var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--s-1);
  animation: menu-in 0.12s ease-out;
}
@keyframes menu-in { from { opacity: 0; transform: translateY(-4px); } }
.menu__header { padding: var(--s-3); border-bottom: var(--line); margin-bottom: var(--s-1); }
.menu__form { margin: 0; display: block; }
.menu__item {
  display: flex; align-items: center; gap: var(--s-2);
  width: 100%; padding: var(--s-2) var(--s-3);
  background: none; border: 0; border-radius: var(--r-md);
  color: var(--paper-200); font-family: inherit; font-size: var(--t-sm);
  text-align: left; text-decoration: none; cursor: pointer;
}
.menu__item:hover { background: var(--ink-750); color: var(--paper-100); }
.menu__item--danger { color: var(--bad-400); }
.menu__item--danger:hover { background: var(--bad-tint); }

/* --- Header usage meter ------------------------------------------------- */

.usage-mini { display: flex; gap: var(--s-4); align-items: center; }
.usage-mini .meter { min-width: 108px; }
@media (max-width: 1100px) { .usage-mini { display: none; } }

/* --- Impersonation banner ----------------------------------------------- */

.impersonation-bar {
  background: var(--warn-tint);
  border-bottom: 1px solid color-mix(in srgb, var(--warn-400) 40%, transparent);
  color: var(--warn-400);
  font-size: var(--t-sm);
  padding: var(--s-2) 0;
}
.impersonation-bar strong { color: var(--paper-100); }
.impersonation-bar .row { gap: var(--s-3); }

/* --- Signed-out layout -------------------------------------------------- */

.auth-body { background: var(--ink-900); }
.auth-wrap {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}
@media (max-width: 900px) { .auth-wrap { grid-template-columns: 1fr; } }

.auth-panel {
  display: flex; flex-direction: column; justify-content: center;
  gap: var(--s-5);
  padding: var(--s-7) var(--s-5);
  max-width: 460px; width: 100%;
  margin-inline: auto;
}
.auth-brand { font-size: var(--t-lg); margin-bottom: var(--s-2); }

/* The sign-in and sign-up pages have no masthead, so the language switch
   lives here. Someone who cannot read English has to be able to reach it
   BEFORE they have an account. */
.auth-langswitch {
  display: inline-flex;
  align-self: flex-start;
  margin-bottom: var(--s-4);
}

.auth-aside {
  background: var(--ink-850);
  border-left: var(--line);
  padding: var(--s-7) var(--s-6);
  display: flex; flex-direction: column; justify-content: center; gap: var(--s-6);
}
@media (max-width: 900px) { .auth-aside { display: none; } }

.auth-quote p {
  font-family: var(--font-serif);
  font-size: var(--t-2xl);
  line-height: 1.25;
  color: var(--paper-100);
  letter-spacing: -0.015em;
  margin-bottom: var(--s-3);
  max-width: 18ch;
}
.auth-quote cite {
  font-style: normal; font-size: var(--t-base); color: var(--paper-400);
  display: block; max-width: 34ch;
}
.auth-points { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s-3); max-width: 40ch; }
.auth-points li {
  display: flex; gap: var(--s-3); align-items: flex-start;
  font-size: var(--t-sm); color: var(--paper-300); line-height: 1.5;
}
.auth-points .icon { color: var(--accent-400); margin-top: 2px; }

.auth-footer { font-size: var(--t-sm); color: var(--paper-400); }
.auth-footer a { color: var(--paper-200); }

/* Password strength meter */
.pw-strength { display: flex; gap: 3px; margin-top: var(--s-2); }
.pw-strength span {
  height: 3px; flex: 1; border-radius: 99px; background: var(--ink-700);
  transition: background 0.2s;
}
.pw-strength[data-score="1"] span:nth-child(-n+1) { background: var(--bad-400); }
.pw-strength[data-score="2"] span:nth-child(-n+2) { background: var(--warn-400); }
.pw-strength[data-score="3"] span:nth-child(-n+3) { background: var(--accent-400); }
.pw-strength[data-score="4"] span { background: var(--ok-400); }

/* --- Input group (field with a trailing button) ------------------------- */

.input-group { position: relative; display: flex; }
.input-group .input { padding-right: 42px; }
.input-group__btn {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  display: grid; place-items: center;
  width: 30px; height: 30px;
  background: none; border: 0; border-radius: var(--r-sm);
  color: var(--paper-400); cursor: pointer;
}
.input-group__btn:hover { color: var(--paper-100); background: var(--ink-750); }

/* ==========================================================================
   Tool workspace

   Editor on the left, a sticky reference sidebar on the right — statistics,
   search, patterns, dictionary and presets stay in view while you scroll
   through a long script, which is how the original worked and how anyone
   editing a 60,000-character narration needs it to work.
   ========================================================================== */

/*
 * On a tool screen the workspace fills the window, the way an editing
 * application does: the page itself does not scroll, so the toolbar and the
 * reference sidebar are always where you left them, and only the panes and
 * the sidebar scroll internally. Below 1180px it falls back to a normal
 * stacked page that scrolls, which is what a phone needs.
 */
.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--aside-w, 340px);
  gap: var(--s-4);
  align-items: start;
}
@media (max-width: 1180px) {
  .workspace { grid-template-columns: 1fr; }
}

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

.workspace__aside {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}

@media (min-width: 1181px) {
  /*
   * No magic numbers: the page becomes a flex column that is exactly the
   * height left over below the header and rail, and the workspace takes
   * whatever the heading and toolbar do not use.
   */
  /* The document itself must not scroll, or the sticky chrome slides away. */
  html:has(body.is-workspace) { overflow: hidden; height: 100%; }
  body.is-workspace { overflow: hidden; height: 100dvh; }
  body.is-workspace .shell { height: 100dvh; min-height: 0; }
  body.is-workspace .page {
    flex: 1;
    height: auto;
    min-height: 0;
    padding-block: var(--s-3) 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
  }
  body.is-workspace .page > .container {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
  }
  body.is-workspace .page > .container > form { display: flex; flex-direction: column; flex: 1; min-height: 0; }
  /* The toolbar keeps its natural height; only the workspace flexes. Without
     this the flex column shrinks the strip and its buttons spill over the
     editors below. */
  /* In the fixed-height workspace the page itself never scrolls, so `sticky`
     buys nothing — and because `.page` is the scrollport here, the sticky
     offset pushed the strip 31px down onto the pane headers. Static. */
  body.is-workspace .workbar { flex: 0 0 auto; position: static; }
  body.is-workspace .page-head { flex: 0 0 auto; }
  body.is-workspace .footer { display: none; }

  /* A tool screen does not need a large heading eating the workspace. */
  body.is-workspace .page-head { margin-bottom: var(--s-3); }
  body.is-workspace .page-head h1 { font-size: var(--t-xl); }
  body.is-workspace .page-head .lede { display: none; }

  body.is-workspace .workspace {
    flex: 1;
    min-height: 0;
    align-items: stretch;
  }
  body.is-workspace .workspace__main { min-height: 0; }
  body.is-workspace .workspace__aside {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-right: 4px;
  }
  body.is-workspace .panes { min-height: 0; height: 100%; }
  body.is-workspace .pane { min-height: 0; }
  body.is-workspace .pane__text { min-height: 0; height: 100%; }
  body.is-workspace .panes--stacked { grid-template-rows: minmax(8rem, 26%) minmax(0, 1fr); }
  body.is-workspace .panes--stacked.is-resizable { grid-template-rows: minmax(8rem, var(--source-pane-height, 26%)) 12px minmax(0, 1fr); row-gap: 0; }
  body.is-workspace .panes--stacked.is-resizable > .pane:last-child { margin-top: var(--s-2); }
  body.is-workspace .panes--stacked > .pane:first-child .pane__text { min-height: 0; }
}

/* --- Quota warning strip ------------------------------------------------ */

/* Sits under the tool rail. `.shell` is a flex column, so the strip keeps its
   own height and `.page` gives up the difference — the workspace shrinks
   instead of the document growing a scrollbar. Its width comes from the
   `.container` it is wrapped in, so it lines up with the page at every
   breakpoint without repeating the container's maths here. */
.usage-warning-slot { flex: 0 0 auto; margin-bottom: var(--s-2); }
.usage-warning {
  align-items: center;
  gap: var(--s-3);
  margin: 0;
}
.usage-warning .notice__body { flex: 1 1 auto; }
.usage-warning .btn { flex: 0 0 auto; }

@media (max-width: 640px) {
  .usage-warning { flex-wrap: wrap; }
  .usage-warning .notice__body { flex-basis: 100%; }
}

/* --- Action toolbar ----------------------------------------------------- */

/* The verbs sit at the TOP of the workspace, under the tool rail, and stay
   there while you scroll — never buried at the bottom of a long page. */
/*
 * The action toolbar.
 *
 * It scrolls sideways rather than wrapping into a ragged block of buttons —
 * a second and third row of controls is what made this look unfinished, and
 * it pushed the editor down the page. One line, always, at every width.
 */
.workbar {
  position: sticky;
  top: calc(var(--header-h) + var(--rail-h));
  z-index: 25;
  display: flex;
  flex-wrap: nowrap;
  gap: var(--s-2);
  align-items: center;
  padding: var(--s-2) var(--s-3);
  margin-bottom: var(--s-1);
  background: color-mix(in srgb, var(--ink-850) 96%, transparent);
  backdrop-filter: blur(10px);
  border: var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  overscroll-behavior-x: contain;
}
.workbar::-webkit-scrollbar { height: 5px; }
.workbar .menu__panel[popover] {
  position: fixed; inset: auto; right: auto; margin: 0;
  max-height: calc(100dvh - 16px); overflow-y: auto;
}
.workbar > * { flex: none; }
.workbar__group {
  display: flex; gap: var(--s-1); align-items: center;
  flex-wrap: nowrap;          /* a group must not stack inside the strip */
  padding-left: var(--s-3);
  margin-left: var(--s-1);
  border-left: var(--line);
}
.workbar__group > * { flex: none; }
.workbar__group:first-of-type { border-left: 0; padding-left: 0; margin-left: 0; }

/* Every control in the strip is exactly one height. Buttons, icon buttons,
   selects and menu triggers each brought their own (30 / 34 / 36 / 40px),
   which read as a ragged row of mismatched boxes. */
.workbar .btn,
.workbar .select,
.workbar .menu > summary,
.workbar .input {
  height: 34px;
  min-height: 34px;
  padding-top: 0;
  padding-bottom: 0;
  line-height: 32px;
}
.workbar .select { padding-right: var(--s-6); }
/* The spacer only earns its keep when there is room to spare. */
.workbar .spacer { flex: 1 1 auto; min-width: var(--s-2); }

@media (max-width: 760px) {
  .workbar { padding: var(--s-2); gap: var(--s-1); }
  .workbar__group { padding-left: var(--s-2); margin-left: 0; }
  /* On a phone the labels go and the icons stay, so the row still fits. */
  .workbar .btn--sm .btn__label { display: none; }
}

/* --- Editor panes ------------------------------------------------------- */

.panes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-3);
  align-items: stretch;
}
.panes--single { grid-template-columns: 1fr; }
.panes--stacked { grid-template-columns: minmax(0, 1fr); }
.panes--stacked > .pane:first-child .pane__text { min-height: clamp(8rem, 20vh, 15rem); }
@media (max-width: 1180px) {
  body.is-workspace .page-head .lede { display: none; }
  .panes--stacked > .pane:first-child .pane__text { min-height: 7rem; }
}
.pane-divider { display: none; }
@media (min-width: 1181px) {
  .pane-divider { display: block; cursor: row-resize; position: relative; touch-action: none; }
  .pane-divider::before { content: ''; position: absolute; left: 35%; right: 35%; top: 5px; height: 2px; background: var(--paper-500); border-radius: var(--r-sm); }
  .pane-divider:hover::before, .pane-divider:focus-visible::before { background: var(--accent-400); }
}
@media (max-width: 900px) { .panes { grid-template-columns: 1fr; } }

.pane { display: flex; flex-direction: column; min-height: 0; }
/* The card clips its children, so the header and footer have to be told they
   are fixed-size — otherwise a tall editor squeezes them out of view. */
.pane__head, .pane__foot { flex: 0 0 auto; }
.pane__body { min-height: 0; flex: 1 1 auto; }
.pane__head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s-2); flex-wrap: wrap;
  padding: var(--s-2) var(--s-3);
  border-bottom: var(--line);
  background: var(--ink-800);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  min-height: 42px;
}
.pane__title { font-size: var(--t-sm); font-weight: 600; color: var(--paper-100); }
.pane__body { flex: 1; display: flex; min-height: 0; }
.pane__text {
  border: 0; border-radius: 0;
  min-height: var(--editor-h, 48vh);
  background: transparent;
  resize: vertical;
  padding: var(--s-3) var(--s-4);
  width: 100%;
}
.pane__text:focus { box-shadow: none; background: transparent; outline-offset: -2px; }
.pane__body--numbered { position: relative; }
.pane__body--highlights { position: relative; }
.text-highlight-overlay {
  position: absolute; top: 0; left: 0; z-index: 2; box-sizing: border-box;
  overflow: hidden; white-space: pre-wrap; overflow-wrap: anywhere;
  color: transparent; pointer-events: none;
}
.text-highlight-overlay[hidden] { display: none; }
.text-highlight-overlay mark { color: transparent; border-radius: 2px; }
.text-highlight--emerald { background: rgb(16 185 129 / 32%); }
.text-highlight--blue { background: rgb(59 130 246 / 34%); }
.text-highlight--purple { background: rgb(168 85 247 / 34%); }
.text-highlight--orange { background: rgb(249 115 22 / 36%); }
.text-highlight--red { background: rgb(239 68 68 / 34%); }
.text-highlight--yellow { background: rgb(234 179 8 / 38%); }
.text-mark-color { width: 28px; height: 28px; border: 2px solid transparent; border-radius: 50%; cursor: pointer; }
.text-mark-color[aria-pressed="true"] { outline: 2px solid var(--paper-100); outline-offset: 2px; }
.text-mark-color:disabled { cursor: not-allowed; opacity: 0.4; }
.pane__body--numbered.is-numbered .pane__text { padding-left: calc(var(--s-4) + 2.8rem); }
.paragraph-mirror {
  position: absolute; top: 0; left: 0; box-sizing: border-box;
  white-space: pre-wrap; overflow-wrap: anywhere;
  visibility: hidden; pointer-events: none;
}
.paragraph-marker { display: inline-block; width: 0; }
.paragraph-gutter[hidden] { display: none; }
.paragraph-gutter {
  position: absolute; z-index: 1; top: 0; bottom: 0; left: 0;
  width: 2.8rem; overflow: hidden; pointer-events: none;
  background: var(--ink-850); border-right: var(--line);
  color: var(--accent-400); font-size: var(--t-xs);
}
.paragraph-gutter__number { position: absolute; left: var(--s-2); font-variant-numeric: tabular-nums; }
.pane__foot {
  display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap;
  padding: var(--s-2) var(--s-3);
  border-top: var(--line);
  background: var(--ink-800);
  border-radius: 0 0 var(--r-lg) var(--r-lg);
  font-size: var(--t-xs);
  color: var(--paper-400);
  font-variant-numeric: tabular-nums;
  min-height: 32px;
}

/* --- Sidebar sections --------------------------------------------------- */

.side { background: var(--ink-850); border: var(--line); border-radius: var(--r-lg); }
.side > summary {
  display: flex; align-items: center; gap: var(--s-2);
  padding: var(--s-3);
  cursor: pointer;
  list-style: none;
  font-size: var(--t-sm);
  font-weight: 600;
  color: var(--paper-100);
  border-radius: var(--r-lg);
}
.side > summary::-webkit-details-marker { display: none; }
.side > summary::after {
  content: "";
  margin-left: auto;
  width: 7px; height: 7px;
  border-right: 1.5px solid var(--paper-400);
  border-bottom: 1.5px solid var(--paper-400);
  transform: rotate(45deg) translateY(-2px);
  transition: transform 0.15s;
}
.side[open] > summary::after { transform: rotate(-135deg) translateY(-2px); }
.side[open] > summary { border-radius: var(--r-lg) var(--r-lg) 0 0; border-bottom: var(--line); }
.side > summary:hover { background: var(--ink-800); }
.side__body { padding: var(--s-3); display: flex; flex-direction: column; gap: var(--s-3); }
.side__body > .field + .field { margin-top: 0; }
.side .icon { color: var(--accent-400); }

/* Statistics read-out */
/*
 * Statistics read-out: a dense two-column list, not a wall of cards. The
 * numbers are glanced at constantly while editing, so they need to be
 * compact enough to sit beside everything else in the sidebar.
 */
.figures {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1px;
  background: var(--ink-700);
  border: var(--line);
  border-radius: var(--r-md);
  overflow: hidden;
}
.figure {
  display: contents;
}
.figure__label {
  padding: 5px var(--s-3);
  background: var(--ink-850);
  font-size: var(--t-xs);
  color: var(--paper-400);
  display: flex; align-items: center;
}
.figure__value {
  padding: 5px var(--s-3);
  background: var(--ink-850);
  font-size: var(--t-sm);
  font-weight: 650;
  color: var(--paper-100);
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}
.figure__delta {
  padding: 0 var(--s-3) 5px;
  grid-column: 1 / -1;
  background: var(--ink-850);
  font-size: var(--t-xs);
  color: var(--accent-400);
  text-align: right;
}
.figure__delta:empty { display: none; }

/* Keep the live numbers visible before the tool controls, even when a tool
   has several settings panels. Preserve their existing DOM and JS hooks. */
.workspace__aside > .side[data-remember$="-stats"],
.workspace__aside > .side[data-remember="tts-estimate"] { order: -1; }
/* Statistic colours live in parts/tools.css, keyed to what the figure MEANS
   rather than to its position, so "words" is the same colour in every tool.
   The four nth-child colours that used to sit here measured 1.58-1.96 contrast
   in light mode against a 4.5 requirement. */

/* --- Popover (word lookup) ---------------------------------------------- */

.popover {
  position: absolute;
  z-index: 120;
  min-width: 220px; max-width: 320px;
  background: var(--ink-800);
  border: var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
}
.popover__head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-2);
  padding: var(--s-2) var(--s-3);
  border-bottom: var(--line);
  font-size: var(--t-sm);
}
.popover__body { padding: var(--s-2); display: flex; flex-direction: column; gap: 2px; max-height: 260px; overflow-y: auto; }
.popover__option {
  display: block; width: 100%; text-align: left;
  padding: var(--s-2) var(--s-3);
  background: none; border: 0; border-radius: var(--r-md);
  color: var(--paper-100); font-family: inherit; font-size: var(--t-base);
  cursor: pointer;
}
.popover__option:hover { background: var(--ink-750); }
.popover__empty { padding: var(--s-3); font-size: var(--t-sm); color: var(--paper-400); }

/* --- Teleprompter ------------------------------------------------------- */

.teleprompter {
  position: fixed; inset: 0; z-index: 300;
  background: #000; color: #fff;
  display: flex; flex-direction: column;
}
.teleprompter__bar {
  display: flex; flex-wrap: wrap; gap: var(--s-3); align-items: center;
  padding: var(--s-3) var(--s-4);
  background: rgba(20, 19, 15, 0.92);
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.teleprompter__bar label { display: flex; align-items: center; gap: var(--s-2); font-size: var(--t-xs); color: #bbb; }
.teleprompter__bar input[type="range"] { width: 110px; accent-color: var(--accent-400); }
.teleprompter__view {
  flex: 1; overflow-y: auto; position: relative;
  padding: 40vh var(--s-6); text-align: center;
  scroll-behavior: auto;
}
.teleprompter__view p { margin: 0 auto var(--s-5); max-width: 22ch; white-space: pre-wrap; }
.teleprompter__guide {
  position: absolute; left: 0; right: 0; top: 50%;
  border-top: 2px solid rgba(217, 164, 65, 0.55);
  pointer-events: none;
}

.prompter-screen[hidden] { display: none; }
.prompter-screen {
  position: fixed; inset: 0; z-index: 300;
  display: flex; flex-direction: column;
  background: var(--prompter-bg, #090909); color: var(--prompter-text, #fff);
}
.prompter-screen__bar {
  display: flex; flex-wrap: wrap; gap: var(--s-3); align-items: center;
  padding: var(--s-3) var(--s-4);
  background: #181612; color: #fff; border-bottom: 1px solid #42403b;
}
.prompter-screen__dial, .prompter-screen__check {
  display: flex; align-items: center; gap: var(--s-2); font-size: var(--t-xs);
}
.prompter-screen__dial input { width: 100px; accent-color: var(--accent-400); }
.prompter-screen__color { display: flex; align-items: center; gap: var(--s-2); font-size: var(--t-xs); }
.prompter-screen__color input { width: 32px; height: 26px; padding: 0; border: 0; background: none; cursor: pointer; }
.prompter-screen__at { min-width: 4ch; color: #e3c787; }
.prompter-screen__stage { position: relative; flex: 1; min-height: 0; }
.prompter-screen__view {
  height: 100%; overflow-y: auto; padding: 40vh var(--s-4);
  font-size: 48px; line-height: 1.45;
}
.prompter-screen__guide {
  position: absolute; top: 50%; left: 0; right: 0;
  border-top: 2px solid var(--accent-400); pointer-events: none;
}
.prompter-paragraph {
  display: grid; grid-template-columns: 2.5ch minmax(0, 1fr); gap: 0.5ch;
  max-width: 24ch; margin: 0 auto 1.2em;
  white-space: pre-wrap; color: var(--prompter-text, #fff); opacity: .65;
}
.prompter-paragraph.is-current { opacity: 1; }
.prompter-paragraph__number { color: var(--accent-400); font-size: 0.45em; padding-top: 0.7em; }
.prompter-screen.without-numbers .prompter-paragraph { grid-template-columns: minmax(0, 1fr); }
.prompter-screen.without-numbers .prompter-paragraph__number { display: none; }
.prompter-screen__hint { margin: 0; padding: var(--s-2) var(--s-4); color: #b4b0a7; font-size: var(--t-xs); }

/* --- Tool catalogue card ------------------------------------------------ */

.tool-card {
  display: flex; gap: var(--s-4); align-items: flex-start;
  text-decoration: none; color: inherit;
  transition: border-color 0.12s, transform 0.08s;
}
a.tool-card:hover { border-color: var(--accent-600); transform: translateY(-1px); }
a.tool-card:hover .card__title { color: var(--accent-400); }
.tool-card__icon {
  display: grid; place-items: center; flex: none;
  width: 44px; height: 44px;
  border-radius: var(--r-md);
  background: var(--ink-800);
  border: var(--line);
  color: var(--accent-400);
}
.tool-card--locked { opacity: 0.72; }
.tool-card--locked .tool-card__icon { color: var(--paper-500); }
.tool-card--locked .card__title { display: flex; align-items: center; gap: var(--s-2); }

/* --- Language switch ---------------------------------------------------- */

.langswitch {
  display: inline-flex;
  padding: 2px;
  gap: 2px;
  background: var(--ink-800);
  border: var(--line);
  border-radius: var(--r-md);
}
.langswitch button {
  /*
   * 30px + 2px padding each side + the 1px borders = 36px overall, matching
   * .btn--icon beside it in the masthead. It was 26px, so the language switch
   * sat 4px shorter than the theme button on every page at every width.
   */
  min-height: 30px;
  padding: 0 var(--s-2);
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--paper-400);
  font-family: inherit;
  font-size: var(--t-xs);
  font-weight: 650;
  letter-spacing: 0.04em;
  cursor: pointer;
}
.langswitch button:hover { color: var(--paper-100); }
.langswitch button[aria-pressed="true"] { background: var(--ink-700); color: var(--paper-100); }
.vision-stage { position: relative; display: inline-block; max-width: 100%; touch-action: none; }
.vision-guide-step { min-width: 0; padding: var(--s-3); border: var(--line); border-radius: var(--r-md); background: var(--ink-800); }
.vision-guide-step .row { flex-wrap: wrap; }
.vision-guide-step .card__title { margin: 0; }
.vision-stage[hidden] { display: none; }
.vision-stage img { display: block; max-width: 100%; max-height: 460px; width: auto; height: auto; }
.vision-stage svg { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; }
.mask-stage { position: relative; display: inline-block; max-width: 100%; width: fit-content; align-self: flex-start; }
.mask-stage img { display: block; max-width: 100%; max-height: 50vh; width: auto; height: auto; }
.mask-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; opacity: .6; touch-action: none; cursor: crosshair; }
.vision-region { fill: color-mix(in srgb, var(--accent-400) 17%, transparent); stroke: var(--accent-400); stroke-width: 3; vector-effect: non-scaling-stroke; }
.vision-region.is-selected { stroke: var(--warn-400); fill: var(--warn-tint); }

/* --- A "Contact us" link, and the short inputs beside a question --------- */

/*
 * The mail link is wording, not an address, so it needs to read as a link
 * rather than as something to copy. The mail-app glyph is decorative and
 * sits in the pseudo-element so no markup carries it.
 */
.mail-link {
  color: var(--accent-400);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}
.mail-link:hover,
.mail-link:focus-visible { color: var(--accent-300); }
.mail-link::after {
  content: "\2709";          /* envelope */
  margin-inline-start: 0.35em;
  font-size: 0.9em;
  opacity: 0.75;
}

/*
 * The captcha answer is two digits. A full-width field invites a sentence and
 * makes a one-number answer look like a mistake, so the box is the size of
 * what goes in it — while staying a comfortable tap target on a phone.
 */
.input--short {
  max-width: 10rem;
}

/* --- Two components that were only ever painted in the admin area -------- */

/*
 * Both of these live in `parts/admin.css` behind `body.is-admin`, which is
 * where they were first needed — and both are ordinary components that any
 * screen may reasonably use. Outside the admin area they rendered as bare text
 * on the page background, which is a large part of why the account screens
 * looked unfinished, and `.select--inline` was simply inert on every tool
 * screen so an inline dropdown grew to 613px inside a toolbar and gave the
 * strip a scrollbar.
 *
 * Defined here unscoped so the component works wherever it is used. The
 * admin-scoped copies still win on admin screens and say the same thing, so
 * nothing there changes; they are now redundant and can be deleted from
 * admin.css in a quiet moment.
 */

/* A checkbox presented as a pickable card. */
.option-card {
  align-items: flex-start;
  gap: var(--s-3);
  padding: var(--s-3);
  border: var(--line);
  border-radius: var(--r-md);
  background: var(--ink-800);
}
.option-card:hover { border-color: var(--ink-600); }
.option-card:has(input:checked) {
  border-color: var(--accent-500);
  background: var(--accent-tint);
}

/*
 * A dropdown that sits in a line of controls, sized to its content instead of
 * filling the row. Without this it inherits `width: 100%` from the shared
 * input rule, which is right for a form field and wrong inside a toolbar.
 */
.select--inline {
  width: auto;
  min-width: 0;
  max-width: 100%;
}
