/* ==========================================================================
   ClipChat design system
   One stylesheet, no build step, no CDN. Replaces the Tailwind runtime
   (~400KB of JS that compiled styles in the browser on every page load) and
   Font Awesome (icons are now inline SVG from a sprite).

   Light, monochrome, single theme.
   ========================================================================== */

:root {
  color-scheme: light;

  /* Monochrome by default. Colour is reserved for the two things that need to
     be unmissable: a recording indicator and a destructive action. */
  --bg: #f6f6f6;
  --bg-elevated: #ffffff;
  --surface: #ffffff;
  --surface-2: #f4f4f4;
  --surface-3: #ebebeb;
  --border: #e4e4e4;
  --border-strong: #d0d0d0;

  --text: #0d0d0d;
  --text-muted: #6a6a6a;
  --text-subtle: #9b9b9b;

  --accent: #111111;
  --accent-hover: #2b2b2b;
  --accent-soft: #f0f0f0;
  --accent-contrast: #ffffff;

  --danger: #b42318;
  --danger-soft: #f7eceb;
  --success: #1f1f1f;
  --success-soft: #efefef;
  --warning: #1f1f1f;
  --warning-soft: #efefef;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;

  --shadow-sm: 0 1px 2px rgba(16, 16, 30, 0.06), 0 1px 1px rgba(16, 16, 30, 0.04);
  --shadow: 0 4px 16px rgba(16, 16, 30, 0.08), 0 1px 2px rgba(16, 16, 30, 0.04);
  --shadow-lg: 0 24px 60px rgba(16, 16, 30, 0.22), 0 2px 8px rgba(16, 16, 30, 0.08);

  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --header-height: 52px;
}

/* --- Base ---------------------------------------------------------------- */

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

html {
  -webkit-text-size-adjust: 100%;
  /* Stops the rubber-band bounce that drags a sticky header around on a
     swipe, and the pull-to-refresh that comes with it. */
  overscroll-behavior-y: none;
}

body {
  margin: 0;
  min-height: 100vh;
  padding-top: var(--header-height);   /* the header is fixed, not sticky */
  overscroll-behavior-y: none;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.015em; line-height: 1.25; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img, video { display: block; max-width: 100%; }

:focus-visible {
  outline: 2px solid var(--border-strong);
  outline-offset: 2px;
  border-radius: 4px;
}

.icon { width: 1em; height: 1em; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.icon-filled { fill: currentColor; stroke: none; }
.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;
}

.container { width: 100%; margin: 0 auto; padding: 0 20px; }

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

.header {
  /* Fixed rather than sticky: a sticky header is still part of the scrolling
     box, so an overscroll swipe carries it with the page. Fixed, promoted to
     its own layer, it stays put. */
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  height: var(--header-height);
  display: flex;
  align-items: center;
  background: color-mix(in srgb, var(--bg-elevated) 62%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid color-mix(in srgb, var(--border) 65%, transparent);
  transform: translateZ(0);
  will-change: transform;
  -webkit-backface-visibility: hidden;
}

.header .container { display: flex; align-items: center; gap: 12px; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
  color: var(--text);
}
.brand:hover { text-decoration: none; }

.header-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }

/* --- Workspace picker --------------------------------------------------- */

.ws-picker { position: relative; flex: none; }
.ws-current { font-weight: 600; }
.ws-current .icon { font-size: 0.9rem; color: var(--text-subtle); transition: transform 0.16s var(--ease); }
.ws-picker.is-open .ws-current { background: var(--surface-3); }
.ws-picker.is-open .ws-current .icon { transform: rotate(180deg); }

.ws-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 60;
  display: none;
  min-width: 180px;
  padding: 4px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  animation: pop-in 0.14s var(--ease);
}
.ws-picker.is-open .ws-menu { display: block; }

.ws-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 550;
  color: var(--text);
}
.ws-option:hover { background: var(--surface-2); text-decoration: none; }
.ws-option.is-current { font-weight: 650; }
.ws-option .icon { font-size: 0.9rem; color: var(--text-subtle); }

/* --- Unlock -------------------------------------------------------------- */

.unlock { max-width: 420px; text-align: center; }
.unlock .panel-header { margin-bottom: 20px; }
.unlock .form-actions { justify-content: center; }
.unlock .label { text-align: left; }
.unlock .form-error { display: flex; align-items: center; gap: 8px; justify-content: center; }
.unlock-art {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin: 0 auto 12px;
  border-radius: 18px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 1.4rem;
}

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

.btn {
  --btn-bg: var(--surface-2);
  --btn-fg: var(--text);
  --btn-border: var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 12px;
  height: 32px;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 550;
  color: var(--btn-fg);
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.16s var(--ease), border-color 0.16s var(--ease),
              transform 0.16s var(--ease), opacity 0.16s var(--ease), box-shadow 0.16s var(--ease);
}
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn.is-disabled { opacity: 0.45; pointer-events: none; }
.btn .icon { font-size: 1rem; }

.btn-primary {
  --btn-bg: var(--accent);
  --btn-fg: #fff;
  --btn-border: transparent;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-ghost { --btn-bg: transparent; --btn-border: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }

.btn-danger { --btn-bg: var(--danger); --btn-fg: #fff; --btn-border: transparent; }
.btn-danger:hover { background: var(--danger); filter: brightness(1.08); }

.btn-sm { height: 28px; padding: 0 9px; font-size: 0.8125rem; border-radius: 8px; }
.btn-lg { height: 38px; padding: 0 16px; font-size: 0.9rem; border-radius: 10px; }
.btn-block { width: 100%; }

.btn-icon {
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 10px;
  --btn-bg: transparent;
  --btn-border: transparent;
  color: var(--text-muted);
}
.btn-icon:hover { background: var(--surface-3); color: var(--text); }
.btn-icon.is-danger:hover { background: var(--danger-soft); color: var(--danger); }
.btn-icon .icon { font-size: 1.05rem; }

/* --- Badges & pills ------------------------------------------------------ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 550;
  background: var(--surface-3);
  color: var(--text-muted);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 0.16s var(--ease), color 0.16s var(--ease);
}
.badge .icon { font-size: 0.8rem; }
.badge-private { background: var(--surface-3); color: var(--text); }
.badge-public { background: transparent; color: var(--text-subtle); border-color: var(--border); }
.badge:hover { filter: brightness(0.97); }

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

.field { margin-bottom: 14px; }
.label {
  display: block;
  margin-bottom: 7px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
}
.input, .select select, textarea.input {
  width: 100%;
  height: 42px;
  padding: 0 13px;
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.16s var(--ease), box-shadow 0.16s var(--ease);
}
.input:focus, .select select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
.select { position: relative; display: block; }
.select select { appearance: none; padding-right: 38px; cursor: pointer; }
.select::after {
  content: '';
  position: absolute;
  right: 15px;
  top: 50%;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--text-subtle);
  border-bottom: 2px solid var(--text-subtle);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border-radius: 10px;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.16s var(--ease);
}
.check:hover { background: var(--surface-2); }
.check input { width: 17px; height: 17px; accent-color: var(--accent); cursor: pointer; }
.check input:disabled { cursor: default; }
.check-label { font-size: 0.9rem; }
.check-hint { color: var(--text-subtle); font-size: 0.8rem; }

.form-actions { display: flex; gap: 8px; align-items: center; margin-top: 18px; }
.form-error {
  padding: 11px 14px;
  margin-bottom: 18px;
  border-radius: var(--radius);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 0.875rem;
}

/* --- Panels -------------------------------------------------------------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 22px;
}
.panel-narrow { max-width: 560px; margin: 0 auto; }
.panel-header { margin-bottom: 16px; }
.panel-header p { color: var(--text-muted); margin-top: 5px; font-size: 0.9rem; }

.page { padding: 18px 0 56px; }

.notice {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 10px 14px;
  margin-bottom: 16px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--text);
}
.notice .icon { color: var(--accent); font-size: 1.2rem; margin-top: 2px; }
.notice p { color: var(--text-muted); font-size: 0.875rem; margin-top: 3px; }

/* --- Topic ---------------------------------------------------------------- */

.topic {
  margin-bottom: 16px;
  padding: 14px 16px 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  scroll-margin-top: calc(var(--header-height) + 16px);
  transition: box-shadow 0.4s var(--ease);
}
.topic.is-highlighted { animation: topic-flash 2s var(--ease); }

@keyframes topic-flash {
  0%   { background: var(--surface-3); }
  100% { background: var(--surface); }
}

.topic-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 9px;
}
.topic-title {
  font-size: 1.4rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  cursor: text;
  padding: 2px 6px;
  margin-left: -6px;
  border-radius: 7px;
  transition: background-color 0.16s var(--ease);
}
.topic-title:hover { background: var(--surface-3); }
.topic-title-input {
  font: inherit;
  font-size: 1.4rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 2px 6px;
  min-width: 260px;
}
.topic-title-input:focus { outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }

.topic-meta { color: var(--text-subtle); font-size: 0.8rem; }
.topic-tools { display: flex; align-items: center; gap: 6px; margin-left: auto; }

/* --- Rail ---------------------------------------------------------------- */

.rail {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 4px 4px 10px;
  margin: -4px -4px -6px;
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
.rail::-webkit-scrollbar { height: 8px; }
.rail::-webkit-scrollbar-track { background: transparent; }
.rail::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 99px; }
.rail::-webkit-scrollbar-thumb:hover { background: var(--text-subtle); }

/* --- Clip card ----------------------------------------------------------- */

.clip {
  position: relative;
  flex: none;
  width: 190px;
  scroll-snap-align: start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: box-shadow 0.2s var(--ease), border-color 0.2s var(--ease);
}
.clip:hover { box-shadow: var(--shadow); border-color: var(--border-strong); }

.clip-media {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 9 / 16;
  border: none;
  padding: 0;
  background: linear-gradient(160deg, var(--surface-3), var(--surface-2));
  cursor: pointer;
  overflow: hidden;
}
.clip-media img, .clip-media video {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
/* A cropped slice of a desktop says nothing; show the whole screen. */
.clip-media.is-screen img, .clip-media.is-screen video {
  object-fit: contain;
  background: #000;
}

/* Sits behind the poster: what you see when a thumbnail is missing, still
   being generated, or fails to load. */
.clip-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: linear-gradient(150deg, #4a4a4a, #1c1c1c);
  color: rgba(255, 255, 255, 0.6);
  font-size: 2.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: -0.02em;
}
.clip-spinner {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  color: rgba(255, 255, 255, 0.85);
  font-size: 1.4rem;
}

.clip-media::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 2;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.55) 0%, rgba(0, 0, 0, 0) 45%);
  opacity: 0.9;
  pointer-events: none;
}

/* Silent hover preview, layered over the poster and under the overlays.
   Selector has to outrank `.clip-media video` above, or the preview is laid
   out in flow after the poster and clipped out of sight. */
.clip-media video.clip-preview {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
  opacity: 0;
  transition: opacity 0.25s var(--ease);
}
.clip-media video.clip-preview.is-ready { opacity: 1; }

.clip-play {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  opacity: 0;
  transition: opacity 0.2s var(--ease);
  z-index: 3;
}
.clip:hover .clip-play, .clip-media:focus-visible .clip-play { opacity: 1; }
.clip-play span {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  padding-left: 3px;              /* optical centring for the triangle */
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 1.35rem;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.22), 0 8px 24px rgba(0, 0, 0, 0.45);
}

.clip-duration {
  position: absolute;
  right: 8px;
  bottom: 8px;
  z-index: 3;
  padding: 2px 7px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.62);
  color: #fff;
  font-size: 0.6875rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  backdrop-filter: blur(4px);
}

.clip-flag {
  position: absolute;
  left: 8px;
  top: 8px;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 7px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.62);
  color: #fff;
  font-size: 0.6875rem;
  font-weight: 550;
  backdrop-filter: blur(4px);
}

.clip-body { padding: 6px 8px 7px; }

.clip-line {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}
.clip-who {
  display: flex;
  align-items: baseline;
  gap: 5px;
  min-width: 0;
  flex: 1;
}
.clip-author {
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.clip-time { color: var(--text-subtle); font-size: 0.6875rem; white-space: nowrap; flex: none; }

.clip-actions {
  display: flex;
  align-items: center;
  gap: 0;
  margin-left: auto;
  flex: none;
}
.clip-actions .btn-icon { width: 24px; height: 24px; border-radius: 6px; }
.clip-actions .btn-icon .icon { font-size: 0.85rem; }

/* --- Reactions ----------------------------------------------------------- */

.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.reactions:empty { display: none; }

.reaction {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 24px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: transform 0.14s var(--ease), background-color 0.14s var(--ease), border-color 0.14s var(--ease);
}
.reaction:hover { transform: scale(1.06); background: var(--surface-3); }
.reaction.is-mine { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 45%, transparent); color: var(--accent); }
.reaction-emoji { font-size: 0.875rem; line-height: 1; }

.reaction-picker {
  position: fixed; /* positioned from viewport rects in app.js */
  z-index: 60;
  display: none;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  padding: 7px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  animation: pop-in 0.14s var(--ease);
}
.reaction-picker.is-open { display: grid; }
.reaction-picker button {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  font-size: 1.15rem;
  background: transparent;
  border: none;
  border-radius: 9px;
  cursor: pointer;
  transition: transform 0.12s var(--ease), background-color 0.12s var(--ease);
}
.reaction-picker button:hover { background: var(--surface-3); transform: scale(1.18); }

/* --- Add-reply card ------------------------------------------------------ */

.clip-add {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 9px;
  flex: none;
  width: 190px;
  aspect-ratio: 9 / 16;
  scroll-snap-align: start;
  background: var(--surface-2);
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--text-muted);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.18s var(--ease), color 0.18s var(--ease),
              background-color 0.18s var(--ease);
}
.clip-add:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}
.clip-add .icon { font-size: 1.5rem; }

/* --- Empty state --------------------------------------------------------- */

.empty {
  text-align: center;
  padding: 44px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
}
.empty-art {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin: 0 auto 14px;
  border-radius: 20px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 1.6rem;
}
.empty h2 { margin-bottom: 6px; }
.empty p { color: var(--text-muted); margin-bottom: 18px; }

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

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(10, 10, 16, 0.62);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.modal.is-open { display: flex; animation: fade-in 0.16s var(--ease); }

.modal-card {
  position: relative;
  width: 100%;
  max-width: 460px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  animation: pop-in 0.2s var(--ease);
}
.modal-card-wide { max-width: 620px; }
.modal-body { padding: 20px; }
.modal-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.modal-head h3 { font-size: 1.1rem; }
.modal-head .btn-icon { margin-left: auto; }
.modal-text { color: var(--text-muted); font-size: 0.9rem; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.modal-actions-start { justify-content: flex-start; }

.prose {
  padding: 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9375rem;
  line-height: 1.65;
  white-space: pre-wrap;
  max-height: 52vh;
  overflow-y: auto;
}

/* Video player modal.
   Everything is shown portrait, whatever it was recorded at: the frame is a
   9:16 box and landscape footage is cropped to fill it, matching the cards.
   Only the display is cropped - the stored file keeps its full frame. */
.player {
  width: auto;
  max-width: calc(100vw - 24px);
  background: var(--bg-elevated);
  overflow: hidden;
}
.player video {
  display: block;
  height: min(78vh, 860px);
  aspect-ratio: 9 / 16;
  width: auto;
  max-width: calc(100vw - 24px);
  object-fit: cover;
  object-position: center;
  background: #000;
}
/* Screen recordings are landscape and full of detail: show all of it. */
.player.is-screen video {
  height: auto;
  width: min(1280px, calc(100vw - 24px));
  max-height: 78vh;
  aspect-ratio: 16 / 9;
  object-fit: contain;
}

.player-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
}
.player-info { min-width: 0; }
.player-info strong { display: block; font-size: 0.9375rem; }
.player-info span { color: var(--text-subtle); font-size: 0.8125rem; }
.player-nav { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.player-count {
  font-size: 0.75rem;
  color: var(--text-subtle);
  font-variant-numeric: tabular-nums;
  min-width: 52px;
  text-align: center;
}
.player-close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: background-color 0.16s var(--ease);
}
.player-close:hover { background: rgba(0, 0, 0, 0.78); }

/* Recorder */
.recorder { text-align: center; }
.recorder-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  max-height: 54vh;
  margin: 0 auto 16px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: linear-gradient(160deg, var(--surface-3), var(--surface-2));
}
.recorder-stage video { width: 100%; height: 100%; object-fit: cover; }
.recorder-stage video.is-mirrored { transform: scaleX(-1); }
.recorder-stage.is-screen { background: #000; }
.recorder-stage.is-screen video { object-fit: contain; }
.recorder-hint {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--text-muted);
  font-size: 0.875rem;
  text-align: center;
}

.rec-pill {
  position: absolute;
  top: 12px;
  left: 12px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 11px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.62);
  color: #fff;
  font-size: 0.8125rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  backdrop-filter: blur(6px);
}
.rec-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #f43f5e;
  animation: pulse 1.4s ease-in-out infinite;
}

.recorder-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.progress {
  height: 6px;
  margin-top: 16px;
  border-radius: 99px;
  background: var(--surface-3);
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0;
  border-radius: 99px;
  background: var(--accent);
  transition: width 0.2s var(--ease);
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
  color: var(--text-subtle);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

#previewDebug {
  position: fixed;
  left: 12px;
  bottom: 12px;
  z-index: 500;
  margin: 0;
  padding: 10px 12px;
  max-width: 460px;
  border-radius: 10px;
  background: rgba(10, 10, 10, 0.9);
  color: #d8ffd8;
  font-size: 11px;
  line-height: 1.5;
  white-space: pre;
  pointer-events: none;
}

/* --- Tooltips ------------------------------------------------------------ */

.tip {
  position: fixed;
  z-index: 300;
  max-width: 260px;
  padding: 5px 9px;
  border-radius: 7px;
  background: #1a1a1a;
  color: #fafafa;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(3px);
  transition: opacity 0.12s var(--ease), transform 0.12s var(--ease);
}
.tip.is-visible { opacity: 1; transform: none; }

/* --- Structured summary --------------------------------------------------- */

.prose.is-structured { white-space: normal; }
.prose.is-structured p { margin: 0 0 12px; }
.prose.is-structured ul { margin: 0; padding: 0; list-style: none; }
.prose.is-structured li {
  position: relative;
  padding-left: 18px;
  margin-bottom: 8px;
}
.prose.is-structured li:last-child { margin-bottom: 0; }
.prose.is-structured li::before {
  content: '';
  position: absolute;
  left: 3px;
  top: 0.62em;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-subtle);
}

/* --- Clickable transcript lines ------------------------------------------ */

.prose.is-cued { padding: 6px; white-space: normal; }
.cue {
  display: block;
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text);
  cursor: pointer;
  transition: background-color 0.12s var(--ease);
}
.cue:hover { background: var(--surface-3); }
.cue-time {
  display: inline-block;
  min-width: 38px;
  margin-right: 8px;
  color: var(--text-subtle);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}

/* --- Recorder countdown -------------------------------------------------- */

.countdown {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(2px);
  color: #fff;
  font-size: 5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.04em;
  text-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
}
.countdown span { animation: countdown-tick 1s var(--ease); }

@keyframes countdown-tick {
  0% { opacity: 0; transform: scale(1.6); }
  25% { opacity: 1; transform: scale(1); }
  100% { opacity: 0.85; transform: scale(0.94); }
}

/* --- Scrub bar on the cards ---------------------------------------------- */

.clip-scrub {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 4;
  height: 3px;
  background: rgba(255, 255, 255, 0.25);
  opacity: 0;
  transition: opacity 0.15s var(--ease);
}
.clip-scrub.is-visible { opacity: 1; }
.clip-scrub span {
  display: block;
  height: 100%;
  width: 0;
  background: #fff;
}

/* --- Player extras -------------------------------------------------------- */

.player-speed { min-width: 42px; font-variant-numeric: tabular-nums; }
.player-nav .btn-icon[data-action='player-captions'] {
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.player-nav .is-active { background: var(--accent); color: var(--accent-contrast); }
/* Captions are drawn by us, not by the browser: its cue box cannot be given a
   position, padding or a sensible width. The native one stays disabled. */
.player-stage { position: relative; }

.player-caption {
  position: absolute;
  left: 50%;
  bottom: 58px;                 /* clear of the native control bar */
  z-index: 2;
  transform: translateX(-50%);
  width: max-content;
  max-width: 92%;
  padding: 7px 12px;
  border-radius: 10px;
  background: rgba(12, 12, 12, 0.66);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 550;
  line-height: 1.45;
  text-align: center;
  white-space: pre-line;        /* the server already balances each cue over two lines */
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  transition: opacity 0.12s var(--ease);
}
.player-caption.is-empty { opacity: 0; }

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

.toasts {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 9px;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 210px;
  max-width: min(380px, calc(100vw - 36px));
  padding: 11px 15px;
  border-radius: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  font-size: 0.875rem;
  color: var(--text);
  animation: toast-in 0.22s var(--ease);
}
.toast.is-leaving { animation: toast-out 0.2s var(--ease) forwards; }
.toast .icon { font-size: 1rem; flex: none; }
.toast-success .icon { color: var(--text); }
.toast-error .icon { color: var(--danger); }
.toast-info .icon { color: var(--text-muted); }

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

.spin { animation: spin 0.9s linear infinite; }
.is-hidden { display: none !important; }
.stack { display: flex; flex-direction: column; gap: 6px; }
.muted { color: var(--text-muted); }

/* --- Animation ----------------------------------------------------------- */

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px) scale(0.97); }
  to { opacity: 1; transform: none; }
}
@keyframes toast-out { to { opacity: 0; transform: translateX(16px); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
@keyframes spin { to { transform: rotate(360deg); } }

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

/* --- Responsive ---------------------------------------------------------- */

@media (max-width: 720px) {
  .container { padding: 0 14px; }
  .header-actions .btn-label { display: none; }
  .header-actions .btn { padding: 0 10px; }
  .clip, .clip-add { width: 158px; }
  .clip, .clip-add { width: 158px; }
  .topic-tools { width: 100%; margin-left: 0; }
  .topic-tools .btn-label { display: none; }
  .player video { height: min(66vh, 700px); }
  .player-caption { bottom: 48px; font-size: 0.875rem; max-width: 92%; }
  .toasts { right: 12px; left: 12px; bottom: 12px; }
}

@media (max-width: 560px) {
  .brand-name { display: none; }
}
