/* ==========================================================================
   Reel — design system
   A private, self-hosted Loom alternative on your own Cloudflare.

   Identity: warm "paper and ink" neutrals, one tally-light red that means
   "live / recording / where you are in the video", and monospace timecodes
   everywhere a time appears. Primary buttons are ink, not red: red is kept
   for Record, the playhead and the brand dot so it always means something.

   No external fonts or images. System fonts, CSS and inline SVG only.
   Light by default, dark via prefers-color-scheme or [data-theme="dark"].
   ========================================================================== */

/* ---------- Tokens ---------- */
:root {
  color-scheme: light;

  /* Neutrals: warm paper and ink */
  --paper: #f6f4f0;
  --surface: #ffffff;
  --surface-2: #f0ede7;
  --surface-3: #e7e2da;
  --line: #e3ded6;
  --line-strong: #cec7bc;
  --ink: #1b1815;
  --ink-2: #554f48;
  --ink-3: #736b62;
  --ink-inverse: #f6f4f0;

  /* Tally: the one colour that means live, recording, playhead */
  --tally: #d63b25;
  --tally-hover: #bd311d;
  --tally-ink: #ffffff;
  --tally-soft: #fbe6e1;
  --tally-text: #b02f1b;

  /* Status */
  --ok: #1d7a52;
  --ok-soft: #dff1e7;
  --warn: #8f5300;
  --warn-soft: #faefd8;
  --danger: #b42318;
  --danger-hover: #9a1d13;
  --danger-soft: #fde8e6;

  /* Highlighter for search matches */
  --mark: #ffe58f;
  --mark-ink: #1b1815;

  /* Player stays dark in both themes */
  --stage: #0e0d0c;
  --stage-ink: #f3efe9;

  /* Focus */
  --focus: #d63b25;

  /* Type */
  --font-sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --text-xs: 0.75rem;    /* 12 */
  --text-sm: 0.8125rem;  /* 13 */
  --text-md: 0.9375rem;  /* 15 — body */
  --text-lg: 1.0625rem;  /* 17 */
  --text-xl: 1.375rem;   /* 22 */
  --text-2xl: 1.75rem;   /* 28 */
  --text-3xl: 2.25rem;   /* 36 */
  --leading: 1.5;
  --leading-tight: 1.2;

  /* Space (4px grid) */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;
  --s-7: 48px;
  --s-8: 64px;

  /* Shape */
  --r-1: 6px;
  --r-2: 10px;
  --r-3: 14px;
  --r-4: 20px;
  --r-full: 999px;

  /* Depth */
  --shadow-1: 0 1px 2px rgb(27 24 21 / 0.06), 0 1px 1px rgb(27 24 21 / 0.04);
  --shadow-2: 0 4px 14px rgb(27 24 21 / 0.08), 0 1px 3px rgb(27 24 21 / 0.06);
  --shadow-3: 0 18px 50px rgb(27 24 21 / 0.18), 0 4px 12px rgb(27 24 21 / 0.08);

  /* Layout */
  --content: 960px;
  --content-narrow: 640px;
  --topbar-h: 60px;

  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --paper: #12100f;
    --surface: #1b1917;
    --surface-2: #24211e;
    --surface-3: #2e2a26;
    --line: #322e2a;
    --line-strong: #4a443d;
    --ink: #f3efe9;
    --ink-2: #c0b8ad;
    --ink-3: #998f84;
    --ink-inverse: #12100f;
    --tally: #ff5c43;
    --tally-hover: #ff7a65;
    --tally-ink: #1c0905;
    --tally-soft: #3b1a14;
    --tally-text: #ff8b77;
    --ok: #52c792;
    --ok-soft: #13301f;
    --warn: #f0b552;
    --warn-soft: #36270d;
    --danger: #ff6b5e;
    --danger-hover: #ff8a80;
    --danger-soft: #3d1714;
    --mark: #6b5414;
    --mark-ink: #fff4d1;
    --focus: #ff7a65;
    --shadow-1: 0 1px 2px rgb(0 0 0 / 0.4);
    --shadow-2: 0 6px 18px rgb(0 0 0 / 0.45), 0 1px 3px rgb(0 0 0 / 0.3);
    --shadow-3: 0 24px 60px rgb(0 0 0 / 0.6), 0 4px 12px rgb(0 0 0 / 0.35);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #12100f;
  --surface: #1b1917;
  --surface-2: #24211e;
  --surface-3: #2e2a26;
  --line: #322e2a;
  --line-strong: #4a443d;
  --ink: #f3efe9;
  --ink-2: #c0b8ad;
  --ink-3: #998f84;
  --ink-inverse: #12100f;
  --tally: #ff5c43;
  --tally-hover: #ff7a65;
  --tally-ink: #1c0905;
  --tally-soft: #3b1a14;
  --tally-text: #ff8b77;
  --ok: #52c792;
  --ok-soft: #13301f;
  --warn: #f0b552;
  --warn-soft: #36270d;
  --danger: #ff6b5e;
  --danger-hover: #ff8a80;
  --danger-soft: #3d1714;
  --mark: #6b5414;
  --mark-ink: #fff4d1;
  --focus: #ff7a65;
  --shadow-1: 0 1px 2px rgb(0 0 0 / 0.4);
  --shadow-2: 0 6px 18px rgb(0 0 0 / 0.45), 0 1px 3px rgb(0 0 0 / 0.3);
  --shadow-3: 0 24px 60px rgb(0 0 0 / 0.6), 0 4px 12px rgb(0 0 0 / 0.35);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-md);
  line-height: var(--leading);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
img, svg, video { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration-color: var(--line-strong); text-underline-offset: 3px; }
a:hover { text-decoration-color: currentColor; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--r-1); }
::selection { background: var(--tally-soft); color: var(--ink); }
hr { border: 0; border-top: 1px solid var(--line); margin: var(--s-5) 0; }
.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;
}

/* ---------- Type ---------- */
h1, h2, h3, h4 { margin: 0; line-height: var(--leading-tight); letter-spacing: -0.015em; font-weight: 650; }
.t-display { font-size: var(--text-3xl); font-weight: 700; letter-spacing: -0.03em; line-height: 1.1; }
h1, .t-h1 { font-size: var(--text-2xl); letter-spacing: -0.025em; }
h2, .t-h2 { font-size: var(--text-xl); }
h3, .t-h3 { font-size: var(--text-lg); }
h4, .t-h4 { font-size: var(--text-md); }
p { margin: 0; }
.t-lg { font-size: var(--text-lg); }
.t-sm { font-size: var(--text-sm); }
.t-xs { font-size: var(--text-xs); }
.t-muted { color: var(--ink-2); }
.t-faint { color: var(--ink-3); }
.t-mono, code, kbd, .timecode { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.timecode { font-size: 0.92em; letter-spacing: -0.01em; }
.eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
}
code {
  font-size: 0.88em;
  padding: 0.1em 0.4em;
  border-radius: 5px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}
kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.6em; height: 1.6em; padding: 0 0.4em;
  font-size: 0.78em; font-weight: 600;
  border-radius: 5px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  color: var(--ink-2);
}
mark, .mark { background: var(--mark); color: var(--mark-ink); border-radius: 3px; padding: 0 2px; }

/* ---------- Layout ---------- */
.container { width: 100%; max-width: var(--content); margin: 0 auto; padding: 0 var(--s-5); }
.container-narrow { max-width: var(--content-narrow); }
.stack { display: flex; flex-direction: column; gap: var(--s-4); }
.stack-sm { display: flex; flex-direction: column; gap: var(--s-2); }
.stack-lg { display: flex; flex-direction: column; gap: var(--s-6); }
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); }
.spread { display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); }
.grow { flex: 1 1 auto; min-width: 0; }
.page { padding-top: var(--s-6); padding-bottom: var(--s-8); }
.hide-sm { }
@media (max-width: 640px) {
  .container { padding: 0 var(--s-4); }
  .page { padding-top: var(--s-5); padding-bottom: var(--s-7); }
  .hide-sm { display: none !important; }
  h1, .t-h1 { font-size: 1.5rem; }
  .t-display { font-size: 1.875rem; }
}

/* ---------- Brand ---------- */
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -0.02em; font-size: 17px; text-decoration: none; color: var(--ink); }
.brand-mark {
  position: relative; width: 26px; height: 26px; border-radius: 8px;
  background: var(--ink);
  flex: none;
}
.brand-mark::after {
  content: ""; position: absolute; width: 8px; height: 8px; border-radius: 50%;
  background: var(--tally); top: 9px; left: 9px;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--tally) 25%, transparent);
}
.brand-domain { font-weight: 500; color: var(--ink-3); font-size: var(--text-sm); letter-spacing: 0; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  height: var(--topbar-h);
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner { height: 100%; display: flex; align-items: center; gap: var(--s-5); }
.nav { display: flex; align-items: center; gap: var(--s-1); }
.nav-link {
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 12px; border-radius: var(--r-full);
  font-size: var(--text-sm); font-weight: 550; color: var(--ink-2); text-decoration: none;
}
.nav-link:hover { background: var(--surface-2); color: var(--ink); }
.nav-link[aria-current="page"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1), inset 0 0 0 1px var(--line); }

/* ---------- Buttons ---------- */
.btn {
  --btn-bg: var(--surface);
  --btn-fg: var(--ink);
  --btn-bd: var(--line-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 16px;
  border-radius: var(--r-2);
  border: 1px solid var(--btn-bd);
  background: var(--btn-bg); color: var(--btn-fg);
  font-size: var(--text-sm); font-weight: 600; line-height: 1;
  white-space: nowrap; text-decoration: none; cursor: pointer;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), transform 0.1s var(--ease), box-shadow 0.15s var(--ease);
  box-shadow: var(--shadow-1);
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { --btn-bg: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn svg { width: 16px; height: 16px; flex: none; }
.btn-primary { --btn-bg: var(--ink); --btn-fg: var(--ink-inverse); --btn-bd: var(--ink); }
.btn-primary:hover { --btn-bg: color-mix(in srgb, var(--ink) 86%, var(--paper)); }
.btn-record { --btn-bg: var(--tally); --btn-fg: var(--tally-ink); --btn-bd: var(--tally); }
.btn-record:hover { --btn-bg: var(--tally-hover); --btn-bd: var(--tally-hover); }
.btn-danger { --btn-bg: var(--danger); --btn-fg: #fff; --btn-bd: var(--danger); }
.btn-danger:hover { --btn-bg: var(--danger-hover); --btn-bd: var(--danger-hover); }
:root[data-theme="dark"] .btn-danger { --btn-fg: #1c0905; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn-danger { --btn-fg: #1c0905; } }
.btn-ghost { --btn-bg: transparent; --btn-bd: transparent; box-shadow: none; color: var(--ink-2); }
.btn-ghost:hover { --btn-bg: var(--surface-2); color: var(--ink); }
.btn-sm { height: 32px; padding: 0 12px; border-radius: 8px; font-size: var(--text-xs); }
.btn-lg { height: 46px; padding: 0 22px; font-size: var(--text-md); border-radius: var(--r-3); }
.btn-block { width: 100%; }
.btn-icon { width: 38px; padding: 0; }
.btn-icon.btn-sm { width: 32px; }
.btn.is-done { --btn-bg: var(--ok-soft); --btn-fg: var(--ok); --btn-bd: color-mix(in srgb, var(--ok) 35%, transparent); }

/* ---------- Inputs ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.label { font-size: var(--text-sm); font-weight: 600; color: var(--ink); }
.hint { font-size: var(--text-xs); color: var(--ink-3); line-height: 1.45; }
.input {
  width: 100%; height: 40px; padding: 0 12px;
  border-radius: var(--r-2);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font-size: var(--text-md);
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.input::placeholder { color: var(--ink-3); }
.input:hover { border-color: color-mix(in srgb, var(--ink) 30%, var(--line-strong)); }
.input:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ink) 12%, transparent); }
.input.t-mono { font-size: var(--text-sm); }
.input[aria-invalid="true"] { border-color: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 14%, transparent); }
.field-error { font-size: var(--text-xs); color: var(--danger); font-weight: 550; display: flex; gap: 6px; align-items: flex-start; line-height: 1.4; }
.field-error svg { width: 14px; height: 14px; flex: none; margin-top: 1px; }

.search { position: relative; }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
.search .input { height: 44px; padding-left: 42px; padding-right: 64px; border-radius: var(--r-3); font-size: var(--text-md); box-shadow: var(--shadow-1); }
.search-icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--ink-3); pointer-events: none; }
.search-kbd { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); }
.search-clear { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); }

/* Copy field: a read-only value with a copy button (links, keys, URLs) */
.copy-field {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 4px 4px 12px;
  border: 1px solid var(--line-strong); border-radius: var(--r-2);
  background: var(--surface-2);
  min-width: 0;
}
.copy-field-value {
  flex: 1 1 auto; min-width: 0;
  font-family: var(--font-mono); font-size: var(--text-sm);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--ink);
}

/* ---------- Cards and panels ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-3);
  box-shadow: var(--shadow-1);
}
.card-pad { padding: var(--s-5); }
.card-head { padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); }
.card-body { padding: var(--s-5); }
@media (max-width: 640px) {
  .card-pad, .card-body { padding: var(--s-4); }
  .card-head { padding: var(--s-3) var(--s-4); }
}
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-4); margin-bottom: var(--s-3); }

/* ---------- Lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list-item {
  display: flex; align-items: center; gap: var(--s-4);
  padding: var(--s-3) var(--s-5);
  border-top: 1px solid var(--line);
}
.list-item:first-child { border-top: 0; }
@media (max-width: 640px) { .list-item { padding: var(--s-3) var(--s-4); } }

/* Video row (library) */
.video-row {
  position: relative;
  display: grid; grid-template-columns: 144px 1fr auto; align-items: center; gap: var(--s-4);
  padding: var(--s-3);
  border-radius: var(--r-3);
  transition: background 0.15s var(--ease);
}
.video-row:hover, .video-row:focus-within { background: var(--surface); box-shadow: var(--shadow-1), inset 0 0 0 1px var(--line); }
.video-row + .video-row { margin-top: 2px; }
.video-row-title { font-weight: 620; font-size: var(--text-md); letter-spacing: -0.01em; color: var(--ink); text-decoration: none; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.video-row-title::after { content: ""; position: absolute; inset: 0; border-radius: inherit; } /* whole row opens the video */
.video-row-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 3px; font-size: var(--text-sm); color: var(--ink-3); }
.video-row-snippet { margin-top: 6px; font-size: var(--text-sm); color: var(--ink-2); line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.video-row-actions { position: relative; z-index: 1; display: flex; gap: 6px; align-items: center; }
.video-row-actions:has(.menu) { z-index: 10; }
.dot-sep { width: 3px; height: 3px; border-radius: 50%; background: currentColor; opacity: 0.6; }
@media (max-width: 640px) {
  .video-row { grid-template-columns: 112px 1fr auto; gap: var(--s-3); padding: var(--s-2); align-items: start; }
  .video-row-actions { margin: -4px -4px 0 -8px; }
  .video-row-actions > .btn[data-act="copy-row"] { display: none; } /* Copy link moves into the row menu on phones */
  .video-row-snippet { -webkit-line-clamp: 3; }
  .video-row-title { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; font-size: var(--text-sm); }
  .video-row-meta { font-size: var(--text-xs); }
}

/* Thumbnail: poster frame of the video with its duration */
.thumb {
  position: relative; aspect-ratio: 16 / 10; border-radius: var(--r-2); overflow: hidden;
  background: var(--stage);
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.06);
}
.thumb > svg, .thumb > video, .thumb > img { width: 100%; height: 100%; object-fit: cover; }
.thumb-duration {
  position: absolute; right: 6px; bottom: 6px;
  padding: 2px 6px; border-radius: 5px;
  background: rgb(14 13 12 / 0.78); color: #fff;
  font-family: var(--font-mono); font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums;
}

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 8px; border-radius: var(--r-full);
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
  background: var(--surface-2); color: var(--ink-2);
  border: 1px solid var(--line);
}
.badge svg { width: 12px; height: 12px; }
.badge-ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge-tally { background: var(--tally-soft); color: var(--tally-text); border-color: transparent; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.status-dot.is-live { background: var(--tally); animation: tally-pulse 1.4s ease-in-out infinite; }
.status-dot.is-off { background: var(--ink-3); }
@keyframes tally-pulse { 0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--tally) 55%, transparent); } 50% { box-shadow: 0 0 0 5px transparent; } }

/* ---------- Empty states ---------- */
.empty {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: var(--s-3);
  padding: var(--s-8) var(--s-5);
}
.empty-art { width: 120px; height: 84px; margin-bottom: var(--s-2); color: var(--ink-3); }
.empty h2, .empty h3 { font-size: var(--text-xl); }
.empty p { max-width: 42ch; color: var(--ink-2); }
.empty .cluster { justify-content: center; margin-top: var(--s-2); }
@media (max-width: 640px) { .empty { padding: var(--s-7) var(--s-4); } }

/* ---------- Loading ---------- */
.skeleton {
  display: block; border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 50%, var(--surface-2) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
.spinner {
  width: 16px; height: 16px; border-radius: 50%; flex: none;
  border: 2px solid color-mix(in srgb, currentColor 22%, transparent);
  border-top-color: currentColor;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .skeleton, .spinner, .status-dot.is-live { animation: none; }
}

/* ---------- Notices ---------- */
.notice {
  display: flex; gap: var(--s-3); align-items: flex-start;
  padding: var(--s-3) var(--s-4); border-radius: var(--r-2);
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: var(--text-sm); color: var(--ink-2);
}
.notice svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.notice strong { color: var(--ink); }
.notice-warn { background: var(--warn-soft); border-color: transparent; color: var(--ink); }
.notice-warn svg { color: var(--warn); }
.notice-danger { background: var(--danger-soft); border-color: transparent; color: var(--ink); }
.notice-danger svg { color: var(--danger); }
.notice-ok { background: var(--ok-soft); border-color: transparent; color: var(--ink); }
.notice-ok svg { color: var(--ok); }

/* ---------- Toast ---------- */
.toast-region { position: fixed; left: 50%; bottom: var(--s-5); transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: var(--s-2); align-items: center; pointer-events: none; width: max-content; max-width: calc(100vw - 32px); }
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: var(--s-3);
  padding: 10px 12px 10px 16px; border-radius: var(--r-3);
  background: var(--ink); color: var(--ink-inverse);
  font-size: var(--text-sm); font-weight: 550;
  box-shadow: var(--shadow-3);
  animation: toast-in 0.25s var(--ease);
}
.toast .btn { --btn-bg: transparent; --btn-fg: var(--ink-inverse); --btn-bd: color-mix(in srgb, var(--ink-inverse) 30%, transparent); box-shadow: none; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Dialog ---------- */
.dialog-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgb(18 16 15 / 0.45);
  display: grid; grid-template-columns: minmax(0, 1fr); place-items: center; padding: var(--s-4);
  animation: fade-in 0.15s var(--ease);
}
.dialog {
  width: 100%; max-width: 440px; min-width: 0;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-4); box-shadow: var(--shadow-3);
  padding: var(--s-5);
  animation: dialog-in 0.2s var(--ease);
}
.dialog h2 { font-size: var(--text-lg); margin-bottom: var(--s-2); }
.dialog p { color: var(--ink-2); font-size: var(--text-sm); }
.dialog-actions { display: flex; justify-content: flex-end; gap: var(--s-2); margin-top: var(--s-5); }
@keyframes fade-in { from { opacity: 0; } }
@keyframes dialog-in { from { opacity: 0; transform: translateY(6px) scale(0.98); } }
@media (max-width: 640px) {
  .dialog-backdrop { place-items: end center; padding: 0; }
  .dialog { max-width: none; border-radius: var(--r-4) var(--r-4) 0 0; padding: var(--s-5) var(--s-4) calc(var(--s-5) + env(safe-area-inset-bottom)); }
  .dialog-actions .btn { flex: 1; }
}

/* ---------- Menu ---------- */
.menu {
  position: absolute; z-index: 30; right: 0; top: calc(100% + 6px);
  min-width: 200px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-3); box-shadow: var(--shadow-3);
  animation: dialog-in 0.12s var(--ease);
}
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  height: 36px; padding: 0 10px; border: 0; border-radius: 8px;
  background: transparent; text-align: left; cursor: pointer;
  font-size: var(--text-sm); font-weight: 520; color: var(--ink); text-decoration: none;
}
.menu-item svg { width: 16px; height: 16px; flex: none; color: var(--ink-3); }
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-2); outline: none; }
.menu-item.is-danger, .menu-item.is-danger svg { color: var(--danger); }
.menu-sep { height: 1px; background: var(--line); margin: 6px 4px; }

/* ---------- Segmented control / tabs ---------- */
.segmented { display: inline-flex; padding: 3px; gap: 2px; border-radius: var(--r-2); background: var(--surface-2); border: 1px solid var(--line); }
.segmented button { height: 30px; padding: 0 12px; border: 0; border-radius: 7px; background: transparent; font-size: var(--text-sm); font-weight: 560; color: var(--ink-2); cursor: pointer; }
.segmented button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }

/* ---------- Player (share page) ---------- */
.player {
  position: relative; overflow: hidden;
  border-radius: var(--r-3);
  background: var(--stage);
  aspect-ratio: 16 / 9;
  box-shadow: var(--shadow-2);
  color: var(--stage-ink);
}
.player-media { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.player-bigplay {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 72px; height: 72px; border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center;
  background: rgb(255 255 255 / 0.94); color: #1b1815;
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.35);
  transition: transform 0.15s var(--ease), opacity 0.2s var(--ease);
}
.player-bigplay:hover { transform: translate(-50%, -50%) scale(1.05); }
.player-bigplay svg { width: 28px; height: 28px; margin-left: 4px; }
.player.is-playing .player-bigplay { opacity: 0; pointer-events: none; }
.player-controls {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 28px 14px 10px;
  background: linear-gradient(to top, rgb(0 0 0 / 0.72), rgb(0 0 0 / 0));
  display: flex; flex-direction: column; gap: 6px;
}
.player-bar { display: flex; align-items: center; gap: 6px; }
.player-btn {
  width: 34px; height: 34px; border: 0; border-radius: 8px; padding: 0;
  display: grid; place-items: center; cursor: pointer;
  background: transparent; color: #fff;
}
.player-btn:hover { background: rgb(255 255 255 / 0.14); }
.player-btn svg { width: 18px; height: 18px; }
.player-time { font-family: var(--font-mono); font-size: 12.5px; font-variant-numeric: tabular-nums; color: rgb(255 255 255 / 0.92); padding: 0 6px; }
.player-rate { font-family: var(--font-mono); font-size: 12px; font-weight: 600; width: auto; padding: 0 8px; }
.scrubber { position: relative; height: 18px; cursor: pointer; display: flex; align-items: center; }
.scrubber-track { position: relative; width: 100%; height: 4px; border-radius: 4px; background: rgb(255 255 255 / 0.25); transition: height 0.1s var(--ease); }
.scrubber:hover .scrubber-track { height: 6px; }
.scrubber-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: inherit; background: var(--tally); }
.scrubber-knob { position: absolute; top: 50%; width: 14px; height: 14px; margin-left: -7px; border-radius: 50%; background: #fff; transform: translateY(-50%); box-shadow: 0 1px 4px rgb(0 0 0 / 0.4); }
.scrubber-cut { position: absolute; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; background: #ffd27a; border-radius: 1px; }

/* ---------- Transcript ---------- */
.transcript { list-style: none; margin: 0; padding: var(--s-2); }
.transcript-line {
  display: grid; grid-template-columns: 52px 1fr; gap: var(--s-3);
  width: 100%; padding: 8px 12px; border: 0; border-radius: var(--r-2);
  background: transparent; text-align: left; cursor: pointer;
  font-size: var(--text-md); line-height: 1.55; color: var(--ink-2);
  position: relative;
}
.transcript-line .timecode { color: var(--ink-3); font-size: 12.5px; padding-top: 2px; }
.transcript-line:hover { background: var(--surface-2); color: var(--ink); }
.transcript-line:hover .timecode { color: var(--ink); }
.transcript-line[aria-current="true"] { background: var(--tally-soft); color: var(--ink); }
.transcript-line[aria-current="true"] .timecode { color: var(--tally-text); font-weight: 600; }
.transcript-cut { display: flex; align-items: center; gap: var(--s-2); padding: 4px 12px 4px 76px; font-size: var(--text-xs); color: var(--ink-3); font-family: var(--font-mono); }
.transcript-cut::before, .transcript-cut::after { content: ""; flex: 1; border-top: 1px dashed var(--line-strong); }
.watch { max-width: 920px; }
.watch-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-4); margin-top: var(--s-5); }
.watch-head h1 { overflow-wrap: anywhere; }
.watch-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 6px; color: var(--ink-3); font-size: var(--text-sm); }
.transcript-card { margin-top: var(--s-5); }
.transcript-scroll { max-height: 440px; overflow: auto; overscroll-behavior: contain; }
.share-foot { margin-top: var(--s-6); display: flex; justify-content: center; gap: 8px; color: var(--ink-3); font-size: var(--text-xs); }
.clip-banner { margin-top: var(--s-4); }
.transcript-loading { padding: var(--s-4) var(--s-5); }
.transcript-skeleton { display: grid; grid-template-columns: 52px 1fr; gap: 12px; margin-bottom: 14px; }
.playback-error { position: absolute; inset: 20% 12px auto; align-items: center; justify-content: center; }
.player-processing { position: absolute; inset: 30% 12px auto; justify-content: center; }
[hidden] { display: none !important; }
@media (max-width: 640px) {
  .transcript-line { grid-template-columns: 44px 1fr; gap: var(--s-2); padding: 8px; font-size: var(--text-sm); }
  .transcript-cut { padding-left: 60px; }
}

/* ---------- Owner library and sign in ---------- */

.lib-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s-4); margin-bottom: var(--s-4); }
.lib-list { list-style: none; margin: 0 calc(var(--s-3) * -1); padding: 0; }
.lib-foot { display: flex; align-items: center; justify-content: space-between; padding: var(--s-4) 0 0; margin-top: var(--s-3); border-top: 1px solid var(--line); color: var(--ink-3); font-size: var(--text-sm); }
.snippet-jump { position: relative; z-index: 1; font-family: var(--font-mono); font-size: 12px; color: var(--tally-text); text-decoration: none; font-weight: 600; margin-right: 6px; }
.snippet-jump:hover { text-decoration: underline; }
.rename-row { display: flex; gap: 6px; position: relative; z-index: 2; }
.rename-row .input { height: 34px; font-weight: 600; }
@media (max-width: 640px) { .lib-list { margin: 0 calc(var(--s-2) * -1); } .lib-head { align-items: flex-start; flex-direction: column; gap: 2px; } }

/* Sign in */
.signin-wrap { min-height: calc(100vh - var(--topbar-h)); display: grid; place-items: center; padding: var(--s-6) var(--s-4); }
.signin { width: 100%; max-width: 420px; }


.signin .activity-icon { display:grid; place-items:center; width:44px; height:44px; border-radius:12px; background:var(--surface-2); color:var(--ink-3); }
.signin .activity-icon svg { width:20px; height:20px; }
.rename-row .input { min-width:0; }
.rename-error { grid-column:2 / -1; }
.library-search { margin-bottom:var(--s-5); }
.search-summary { margin:-8px 0 12px; }
.first-server { width:100%; max-width:420px; text-align:left; margin-top:var(--s-2); }
.dialog h2, .dialog .t-mono { overflow-wrap:anywhere; }
.mac-build { margin:0; padding:var(--s-3); border-radius:var(--r-2); background:var(--surface-2); font-size:var(--text-xs); white-space:pre-wrap; }
#libBody .empty h2, .search-summary { overflow-wrap:anywhere; }
@media (max-width:640px) {
  .video-row:has(.rename-row) { grid-template-columns:112px minmax(0,1fr); }
  .rename-row { flex-wrap:wrap; }
  .rename-row .input { flex-basis:100%; }
}

/* ---------- Settings (approved S4 layout) ---------- */

.settings > * { max-width: 760px; width: 100%; }
.settings .grow, .settings .kv dd { overflow-wrap: anywhere; }
.key-dialog { max-width: 560px; }
.dialog-backdrop:has(.key-dialog) { overflow-y: auto; }
.key-dialog { max-height: 100dvh; overflow-y: auto; }
.tool-name { font-family: var(--font-mono); font-size: var(--text-sm); font-weight: 600; color: var(--ink); min-width: 150px; }
.codeblock {
  position: relative; margin: 0; padding: 14px 16px; padding-right: 92px; border-radius: var(--r-2);
  background: var(--stage); color: #e9e4dc; font: 12.5px/1.6 var(--font-mono); white-space: pre-wrap; word-break: break-all;
}
.codeblock .btn { position: absolute; right: 8px; top: 8px; --btn-bg: #2a2622; --btn-fg: #f3efe9; --btn-bd: #3c3731; box-shadow: none; }
.codeblock .c-dim { color: #8d857b; } .codeblock .c-acc { color: #ffb38a; }
.activity-icon { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; flex: none; background: var(--surface-2); color: var(--ink-2); }
.activity-icon svg { width: 16px; height: 16px; }
.kv { margin: 0; display: grid; grid-template-columns: 150px 1fr; gap: 10px var(--s-4); align-items: center; font-size: var(--text-sm); }
.kv dt { color: var(--ink-3); } .kv dd { margin: 0; min-width: 0; }
@media (max-width: 640px) { .kv { grid-template-columns: 1fr; gap: 2px; } .kv dd { margin-bottom: 10px; } .tool-name { min-width: 0; } .list-item.tool { flex-direction: column; align-items: flex-start; gap: 2px; } }

/* ---------- Switch, compact select (S6) ---------- */

.switch {
  --sw-w: 38px; --sw-h: 22px;
  position: relative; flex: none; width: var(--sw-w); height: var(--sw-h); padding: 0;
  border: 0; border-radius: var(--r-full); background: var(--line-strong); cursor: pointer;
  transition: background .18s var(--ease);
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: calc(var(--sw-h) - 4px); height: calc(var(--sw-h) - 4px);
  border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / .25); transition: transform .18s var(--ease);
}
.switch[aria-checked="true"] { background: var(--ok); }
.switch[aria-checked="true"]::after { transform: translateX(calc(var(--sw-w) - var(--sw-h))); }
.switch:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.switch:disabled { opacity: .5; cursor: not-allowed; }

.select-compact {
  appearance: none; -webkit-appearance: none; min-width: 0; max-width: 100%; height: 28px;
  padding: 0 26px 0 10px; border: 1px solid var(--line); border-radius: var(--r-1);
  background-color: var(--surface-2);
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
  background-position: right 13px center, right 9px center; background-size: 4px 4px; background-repeat: no-repeat;
  font-size: var(--text-xs); color: var(--ink-2); text-overflow: ellipsis; cursor: pointer;
}
.select-compact:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

/* ---------- Camera bubble (S6). The Mac app draws the same look natively. ---------- */

.cam-bubble {
  --cam-size: 180px;
  position: absolute; z-index: 4; width: var(--cam-size); height: var(--cam-size);
  border-radius: 50%; cursor: grab; touch-action: none; user-select: none;
  transition: width .2s var(--ease), height .2s var(--ease);
}
.cam-bubble.is-s { --cam-size: 120px; }
.cam-bubble.is-l { --cam-size: 260px; }
.cam-bubble.is-dragging { cursor: grabbing; transition: none; }
.cam-feed {
  position: absolute; inset: 0; border-radius: 50%; overflow: hidden; background: #2a2622;
  box-shadow: 0 0 0 3px rgb(255 255 255 / .92), 0 14px 36px rgb(0 0 0 / .35);
}
.cam-feed svg { width: 100%; height: 100%; display: block; }
.cam-bubble:focus-visible { outline: none; }
.cam-bubble:focus-visible .cam-feed { box-shadow: 0 0 0 3px var(--focus), 0 14px 36px rgb(0 0 0 / .35); }
.cam-tools {
  position: absolute; left: 50%; bottom: calc(100% + 10px); transform: translateX(-50%);
  display: flex; align-items: center; gap: 2px; padding: 3px; border-radius: var(--r-full);
  background: rgb(20 18 16 / .84); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  color: #f3efe9; box-shadow: 0 6px 18px rgb(0 0 0 / .3), inset 0 0 0 1px rgb(255 255 255 / .14); white-space: nowrap;
  opacity: 0; pointer-events: none; transition: opacity .15s;
}
.cam-bubble:hover .cam-tools, .cam-bubble:focus-within .cam-tools, .cam-bubble.show-tools .cam-tools { opacity: 1; pointer-events: auto; }
.cam-tools.is-below { bottom: auto; top: calc(100% + 10px); }
.cam-tools button {
  height: 26px; min-width: 28px; padding: 0 8px; border: 0; border-radius: var(--r-full);
  background: transparent; color: inherit; font: 600 11.5px/1 var(--font-mono); cursor: pointer;
  display: grid; place-items: center;
}
.cam-tools button:hover { background: rgb(255 255 255 / .14); }
.cam-tools button[aria-pressed="true"] { background: #f3efe9; color: #1b1815; }
.cam-tools button svg { width: 13px; height: 13px; }
.cam-tools .sep { width: 1px; height: 16px; background: rgb(255 255 255 / .2); margin: 0 3px; }
@media (max-width: 640px) {
  .cam-bubble { --cam-size: 112px; }
  .cam-bubble.is-s { --cam-size: 84px; }
  .cam-bubble.is-l { --cam-size: 150px; }
}
@media (prefers-reduced-motion: reduce) { .switch, .switch::after, .cam-bubble { transition: none; } }
