/* ============================================================
   FaceSwap Studio — shadcn/ui design system (vanilla CSS port)
   Geist typography · zinc neutrals · HSL tokens · light + dark
   ============================================================ */

:root {
  /* ---- shadcn tokens (light · zinc) ---- */
  --background: 0 0% 100%;
  --foreground: 240 10% 3.9%;

  --card: 0 0% 100%;
  --card-foreground: 240 10% 3.9%;

  --popover: 0 0% 100%;
  --popover-foreground: 240 10% 3.9%;

  --primary: 240 5.9% 10%;
  --primary-foreground: 0 0% 98%;

  --secondary: 240 4.8% 95.9%;
  --secondary-foreground: 240 5.9% 10%;

  --muted: 240 4.8% 95.9%;
  --muted-foreground: 240 3.8% 46.1%;

  --accent: 240 4.8% 95.9%;
  --accent-foreground: 240 5.9% 10%;

  --destructive: 0 72% 51%;
  --destructive-foreground: 0 0% 98%;

  --success: 142 71% 36%;
  --success-foreground: 0 0% 100%;
  --warning: 38 92% 45%;
  --warning-foreground: 0 0% 100%;

  --border: 240 5.9% 90%;
  --input: 240 5.9% 90%;
  --ring: 240 5.9% 10%;

  /* app canvas — a hair off-white so cards read as elevated */
  --app-bg: 240 5% 96%;

  --radius: 0.625rem;
  --radius-lg: var(--radius);
  --radius-md: calc(var(--radius) - 2px);
  --radius-sm: calc(var(--radius) - 4px);

  --shadow-xs: 0 1px 2px 0 hsl(240 10% 3.9% / 0.04);
  --shadow-sm: 0 1px 2px 0 hsl(240 10% 3.9% / 0.05);
  --shadow: 0 1px 3px 0 hsl(240 10% 3.9% / 0.07), 0 1px 2px -1px hsl(240 10% 3.9% / 0.07);
  --shadow-md: 0 4px 6px -1px hsl(240 10% 3.9% / 0.08), 0 2px 4px -2px hsl(240 10% 3.9% / 0.06);
  --shadow-lg: 0 10px 24px -6px hsl(240 10% 3.9% / 0.12);
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: 240 10% 3.9%;
    --foreground: 0 0% 98%;

    --card: 240 10% 5.9%;
    --card-foreground: 0 0% 98%;

    --popover: 240 10% 5.9%;
    --popover-foreground: 0 0% 98%;

    --primary: 0 0% 98%;
    --primary-foreground: 240 5.9% 10%;

    --secondary: 240 3.7% 15.9%;
    --secondary-foreground: 0 0% 98%;

    --muted: 240 3.7% 15.9%;
    --muted-foreground: 240 5% 64.9%;

    --accent: 240 3.7% 15.9%;
    --accent-foreground: 0 0% 98%;

    --destructive: 0 72% 51%;
    --destructive-foreground: 0 0% 98%;

    --success: 142 64% 45%;
    --success-foreground: 0 0% 100%;
    --warning: 38 92% 55%;
    --warning-foreground: 240 10% 3.9%;

    --border: 240 3.7% 17%;
    --input: 240 3.7% 17%;
    --ring: 240 4.9% 83.9%;

    --app-bg: 240 10% 3%;

    --shadow-xs: 0 1px 2px 0 hsl(0 0% 0% / 0.3);
    --shadow-sm: 0 1px 2px 0 hsl(0 0% 0% / 0.3);
    --shadow: 0 1px 3px 0 hsl(0 0% 0% / 0.4), 0 1px 2px -1px hsl(0 0% 0% / 0.4);
    --shadow-md: 0 4px 6px -1px hsl(0 0% 0% / 0.45);
    --shadow-lg: 0 10px 24px -6px hsl(0 0% 0% / 0.55);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
*::selection { background: hsl(var(--primary) / 0.16); }

html, body { height: 100%; }

body {
  font-family: 'Geist', ui-sans-serif, -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: hsl(var(--app-bg));
  color: hsl(var(--foreground));
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { letter-spacing: -0.012em; line-height: 1.25; }

a { color: inherit; }

:where(button, a, input, label, [tabindex]):focus-visible {
  outline: 2px solid hsl(var(--ring));
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

code, .mono, .tabnum { font-variant-numeric: tabular-nums; }

/* ===================== App shell ===================== */
.app { min-height: 100vh; display: flex; flex-direction: column; }

.page-scroll { flex: 1; }

.page-inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 24px 32px 64px;
}

.page-narrow { max-width: 720px; }

/* ===================== Top app bar (light, bordered) ===================== */
.appbar {
  position: sticky; top: 0; z-index: 60;
  display: flex; align-items: center; gap: 24px;
  min-height: 64px; padding: 12px 24px;
  background: hsl(var(--background) / 0.8);
  backdrop-filter: saturate(180%) blur(10px);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid hsl(var(--border));
}

.appbar-brand {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none; flex-shrink: 0;
}
.brand-mark {
  width: 30px; height: 30px; border-radius: var(--radius-md);
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  display: grid; place-items: center;
  box-shadow: var(--shadow-sm);
}
.brand-name { color: hsl(var(--foreground)); font-weight: 600; font-size: 14.5px; white-space: nowrap; letter-spacing: -0.01em; }

.appbar-steps {
  display: flex; align-items: center; gap: 2px;
  flex: 1; justify-content: center;
}
.hstep {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: var(--radius-md);
  text-decoration: none; color: hsl(var(--muted-foreground));
  transition: background .15s ease, color .15s ease;
}
a.hstep:hover { background: hsl(var(--accent)); color: hsl(var(--accent-foreground)); }
.hstep.active { background: hsl(var(--accent)); color: hsl(var(--foreground)); }
.hstep.done { color: hsl(var(--foreground)); }
.hstep.locked { opacity: .45; cursor: not-allowed; }

.hstep-num {
  width: 21px; height: 21px; border-radius: 50%;
  display: grid; place-items: center; flex-shrink: 0;
  font-size: 11px; font-weight: 600;
  background: hsl(var(--secondary)); color: hsl(var(--muted-foreground));
  border: 1px solid hsl(var(--border));
}
.hstep.active .hstep-num { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); border-color: transparent; }
.hstep.done .hstep-num { background: hsl(var(--success) / 0.14); color: hsl(var(--success)); border-color: transparent; }
.hstep-label { font-size: 13px; font-weight: 500; white-space: nowrap; }
@media (max-width: 720px) { .hstep-label { display: none; } }

.hstep-sep { width: 16px; height: 1px; background: hsl(var(--border)); flex-shrink: 0; }

.appbar-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.engine-chip {
  display: flex; align-items: center; gap: 7px;
  font-size: 11.5px; color: hsl(var(--muted-foreground)); white-space: nowrap;
}
.engine-chip .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: hsl(var(--success)); box-shadow: 0 0 0 3px hsl(var(--success) / 0.16);
}
@media (max-width: 900px) { .engine-chip { display: none; } }

.project-chip {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12px; font-weight: 500;
  color: hsl(var(--secondary-foreground));
  background: hsl(var(--secondary));
  border: 1px solid hsl(var(--border));
  padding: 5px 10px; border-radius: var(--radius-md);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.project-chip svg { color: hsl(var(--muted-foreground)); }

/* ===================== Page heading ===================== */
.page-head {
  background: hsl(var(--background));
  border-bottom: 1px solid hsl(var(--border));
}
.page-head-inner {
  max-width: 1320px; margin: 0 auto;
  padding: 24px 32px;
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
}
.page-title { font-size: 20px; font-weight: 600; letter-spacing: -0.02em; }
.page-sub { font-size: 13.5px; color: hsl(var(--muted-foreground)); margin-top: 3px; }
.step-counter {
  font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
  color: hsl(var(--secondary-foreground)); background: hsl(var(--secondary));
  border: 1px solid hsl(var(--border));
  padding: 4px 10px; border-radius: 999px; white-space: nowrap;
}

/* ===================== Cards / panels ===================== */
.card {
  background: hsl(var(--card));
  color: hsl(var(--card-foreground));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}

.panel { display: flex; flex-direction: column; }

.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid hsl(var(--border));
}
.panel-head-title { display: flex; align-items: center; gap: 10px; }
.panel-head h2 { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.panel-body { padding: 20px; flex: 1; }
.panel-foot {
  padding: 16px 20px;
  border-top: 1px solid hsl(var(--border));
  display: flex; align-items: center; gap: 12px;
  background: hsl(var(--muted) / 0.4);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.muted-label {
  font-size: 11px; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; color: hsl(var(--muted-foreground));
}

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

/* ===================== Buttons ===================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 16px;
  border-radius: var(--radius-md);
  font-size: 13.5px; font-weight: 500;
  font-family: inherit; line-height: 1;
  cursor: pointer; border: 1px solid transparent;
  text-decoration: none; white-space: nowrap;
  transition: background .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease, opacity .15s ease;
}
.btn svg { flex-shrink: 0; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; pointer-events: none; }

.btn-primary { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); box-shadow: var(--shadow-xs); }
.btn-primary:hover:not(:disabled) { background: hsl(var(--primary) / 0.9); }

.btn-outline { background: hsl(var(--background)); color: hsl(var(--foreground)); border-color: hsl(var(--border)); box-shadow: var(--shadow-xs); }
.btn-outline:hover:not(:disabled) { background: hsl(var(--accent)); color: hsl(var(--accent-foreground)); }

.btn-ghost { background: transparent; color: hsl(var(--foreground)); border-color: transparent; }
.btn-ghost:hover:not(:disabled) { background: hsl(var(--accent)); color: hsl(var(--accent-foreground)); }

.btn-secondary { background: hsl(var(--secondary)); color: hsl(var(--secondary-foreground)); }
.btn-secondary:hover:not(:disabled) { background: hsl(var(--secondary) / 0.8); }

.btn-sm { height: 32px; padding: 0 12px; font-size: 12.5px; gap: 6px; }

/* ===================== Upload ===================== */
.upload-card { padding: 22px; }

.drop-zone {
  border: 1.5px dashed hsl(var(--border));
  border-radius: var(--radius-lg);
  background: hsl(var(--muted) / 0.4);
  padding: 56px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s ease, background .2s ease;
}
.drop-zone:hover, .drop-zone.dragover { border-color: hsl(var(--ring)); background: hsl(var(--accent)); }

.drop-icon {
  width: 56px; height: 56px; border-radius: var(--radius-lg);
  background: hsl(var(--background)); border: 1px solid hsl(var(--border));
  display: grid; place-items: center; margin: 0 auto 16px;
  color: hsl(var(--foreground)); box-shadow: var(--shadow-sm);
}
.drop-zone h3 { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.drop-zone p { color: hsl(var(--muted-foreground)); margin-bottom: 18px; }
.drop-meta { display: block; margin-top: 14px; font-size: 11.5px; color: hsl(var(--muted-foreground)); }

.upload-progress { padding: 8px 4px; }
.up-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 9px; }
.up-file { font-size: 13.5px; font-weight: 500; }
.up-pct { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }

.progress-bar { height: 8px; background: hsl(var(--secondary)); border-radius: 99px; overflow: hidden; }
.progress-fill {
  height: 100%; width: 0%;
  background: hsl(var(--primary));
  border-radius: 99px; transition: width .2s ease;
}
.progress-status { margin-top: 10px; font-size: 12.5px; color: hsl(var(--muted-foreground)); }

.upload-success { text-align: center; padding: 30px 8px; }
.success-icon {
  width: 52px; height: 52px; border-radius: 50%;
  background: hsl(var(--success) / 0.14); color: hsl(var(--success));
  display: grid; place-items: center; margin: 0 auto 14px;
}
.upload-success h3 { font-size: 16px; margin-bottom: 3px; }
.upload-success p { color: hsl(var(--muted-foreground)); }

.feature-row {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 14px; margin-top: 20px;
}
.feature {
  display: flex; gap: 12px; align-items: flex-start;
  background: hsl(var(--card)); border: 1px solid hsl(var(--border));
  border-radius: var(--radius-lg); padding: 16px;
  box-shadow: var(--shadow-xs);
}
.feature-ic {
  width: 28px; height: 28px; border-radius: var(--radius-md); flex-shrink: 0;
  background: hsl(var(--primary)); color: hsl(var(--primary-foreground));
  display: grid; place-items: center; font-size: 12.5px; font-weight: 600;
}
.feature strong { font-size: 13.5px; display: block; margin-bottom: 2px; font-weight: 600; }
.feature p { font-size: 12px; color: hsl(var(--muted-foreground)); line-height: 1.5; }

/* ===================== Split layout (transcribe) ===================== */
.split-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
  gap: 20px;
  align-items: start;
}
@media (max-width: 1000px) { .split-layout { grid-template-columns: 1fr; } }

.transcript-panel { max-height: calc(100vh - 210px); }
.transcript-panel .panel-body { overflow-y: auto; }

.full-transcript { font-size: 14.5px; line-height: 1.8; color: hsl(var(--foreground) / 0.85); }

.word-list { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 10px; }
.word-item {
  padding: 3px 7px; border-radius: var(--radius-sm);
  font-size: 13px; cursor: pointer; color: hsl(var(--muted-foreground));
  transition: background .12s ease, color .12s ease;
}
.word-item:hover { background: hsl(var(--accent)); color: hsl(var(--accent-foreground)); }
.word-item.active { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); }

.video-wrapper {
  border-radius: var(--radius-md); overflow: hidden; background: #000;
  display: flex; align-items: center; justify-content: center;
  max-height: 58vh; border: 1px solid hsl(var(--border));
}
.video-wrapper video {
  width: 100%; max-height: 58vh;
  object-fit: contain; display: block;
}

.caption-bar {
  margin-top: 14px; padding: 12px 16px;
  background: hsl(var(--muted) / 0.5); border: 1px solid hsl(var(--border));
  border-radius: var(--radius-md);
  display: flex; align-items: center; gap: 12px; min-height: 48px;
}
.caption-label {
  font-size: 10px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  color: hsl(var(--muted-foreground)); background: hsl(var(--background)); border: 1px solid hsl(var(--border));
  padding: 3px 7px; border-radius: var(--radius-sm);
}
.caption-text { font-size: 14.5px; font-weight: 500; }

.time-display { font-size: 12.5px; color: hsl(var(--muted-foreground)); font-variant-numeric: tabular-nums; }

/* ===================== States / spinner ===================== */
.state-block { text-align: center; padding: 56px 24px; }
.state-title { font-size: 14.5px; font-weight: 600; margin-top: 4px; }
.state-sub { font-size: 13px; color: hsl(var(--muted-foreground)); margin-top: 3px; }

.spinner {
  width: 32px; height: 32px;
  border: 2.5px solid hsl(var(--border));
  border-top-color: hsl(var(--primary));
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin: 0 auto 14px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-text { color: hsl(var(--destructive)); font-weight: 500; }

/* ===================== Editor layout ===================== */
.editor-workspace { display: flex; flex-direction: column; gap: 20px; }

.editor-stage {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(300px, 1fr);
  gap: 20px;
  align-items: start;
}
@media (max-width: 980px) { .editor-stage { grid-template-columns: 1fr; } }

/* ===== Editor: fill the viewport, no page scroll (panels scroll internally) ===== */
.editor-page .page-head { display: none; }

@media (min-width: 1201px) {
  .editor-page { height: 100vh; overflow: hidden; }
  .editor-page .page-scroll { flex: 1; min-height: 0; display: flex; }
  .editor-page .page-inner {
    flex: 1; min-height: 0; max-width: 1720px; width: 100%;
    display: flex; flex-direction: column; padding: 14px 24px 18px; overflow: hidden;
  }
  .editor-page .page-head-inner { padding-top: 14px; padding-bottom: 14px; }

  .editor-page .editor-workspace { flex: 1; min-height: 0; gap: 14px; }
  .editor-page .editor-stage {
    flex: 1; min-height: 0; align-items: stretch; gap: 16px;
    grid-template-columns: minmax(0, 1.55fr) minmax(280px, 0.9fr) minmax(270px, 0.95fr);
  }
  /* Unwrap the right group so its two panels become real grid columns. */
  .editor-page .editor-right { display: contents; }

  /* Left column: preview grows, timeline pinned at the bottom edge. */
  .editor-page .editor-left { height: 100%; min-height: 0; gap: 14px; }
  .editor-page .editor-left .preview-panel { flex: 1; min-height: 0; }
  .editor-page .editor-left .timeline-section { flex-shrink: 0; }

  /* Face Mapping + Characters run full height. */
  .editor-page .editor-right > .panel { height: 100%; min-height: 0; }

  .editor-page .panel-body { flex: 1; min-height: 0; overflow-y: auto; padding: 16px; }
  .editor-page .panel-head { padding: 12px 16px; }
  .editor-page .panel-foot { padding: 12px 16px; }

  /* Show the original + generated clips side by side (when both exist). */
  .editor-page .preview-stack { flex-direction: row; align-items: flex-start; gap: 14px; }
  .editor-page .preview-stack > * { flex: 1 1 0; min-width: 0; }
  .editor-page .generated-preview { margin-top: 0; }
  .editor-page .video-player,
  .editor-page .video-player video,
  .editor-page .generated-preview video { max-height: 46vh; }
}

.source-preview { display: flex; flex-direction: column; gap: 10px; min-width: 0; }

/* Timeline header: single clean row — title left, action buttons right. */
.timeline-section .badge { white-space: nowrap; }
.timeline-section .panel-head-title { flex-shrink: 0; }
.timeline-legend { margin-top: 10px; justify-content: flex-end; }

/* Compact Face Mapping + Characters so preview/timeline get more room. */
.editor-page .faces-toolbar { margin-bottom: 10px; }
.editor-page .faces-hint { font-size: 12px; margin-bottom: 10px; line-height: 1.4; }
.editor-page .face-slots { gap: 8px; }
.editor-page .face-slot { padding: 9px 11px; gap: 7px; }
.editor-page .face-main { gap: 10px; }
.editor-page .face-review { padding-top: 7px; gap: 7px; }
.editor-page .face-crop,
.editor-page .face-thumb { width: 46px; height: 46px; }
.editor-page .face-num { font-size: 19px !important; }
.editor-page .face-cell figcaption { font-size: 9.5px; }
.editor-page .prompt-field { margin-top: 10px; }
.editor-page .prompt-input { min-height: 46px; }
.editor-page .character-card { padding: 8px 10px; gap: 10px; }
.editor-page .character-card .char-thumb { width: 44px; height: 44px; }
.editor-page .character-list { gap: 8px; }

.badge {
  background: hsl(var(--secondary)); border: 1px solid hsl(var(--border));
  padding: 2px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 500; color: hsl(var(--secondary-foreground));
}

.scene-pill {
  background: hsl(var(--primary)); color: hsl(var(--primary-foreground));
  padding: 2px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
}
.scene-time { font-size: 12.5px; color: hsl(var(--muted-foreground)); font-variant-numeric: tabular-nums; }

.legend { display: flex; gap: 14px; }
.lg { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: hsl(var(--muted-foreground)); }
.lg-dot { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }
.lg-default { background: hsl(var(--muted-foreground) / 0.5); }
.lg-proc { background: hsl(var(--warning)); }
.lg-done { background: hsl(var(--success)); }

/* Left: preview */
.preview-stack { display: flex; flex-direction: column; gap: 16px; }

.video-player {
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #000;
  border: 1px solid hsl(var(--border));
  max-height: 60vh;
  line-height: 0;
}
.video-player video {
  width: 100%;
  max-height: 60vh;
  object-fit: contain;
  display: block;
}
#faceOverlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Left: preview + timeline stacked; Right: faces + characters */
.editor-left { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.editor-right { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.faces-hint { font-size: 12.5px; color: hsl(var(--muted-foreground)); margin-bottom: 14px; line-height: 1.5; }

/* ===================== Characters panel ===================== */
.character-list { display: flex; flex-direction: column; gap: 10px; }
.character-card {
  display: flex; align-items: center; gap: 12px;
  border: 1px solid hsl(var(--border)); border-radius: var(--radius-md);
  padding: 10px 12px; background: hsl(var(--card));
}
.character-card .char-thumb {
  width: 52px; height: 52px; flex-shrink: 0; border-radius: var(--radius-sm);
  overflow: hidden; border: 2px solid; display: grid; place-items: center;
  font-size: 20px; font-weight: 700; background: hsl(var(--secondary));
}
.character-card .char-thumb img { width: 100%; height: 100%; object-fit: cover; }
.character-card .char-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.character-card .char-name { font-size: 13px; font-weight: 600; color: hsl(var(--foreground)); white-space: nowrap; }
.character-card .char-sub { font-size: 11px; color: hsl(var(--muted-foreground)); white-space: nowrap; }
.character-card .char-repl {
  width: 44px; height: 44px; flex-shrink: 0; margin-left: auto; border-radius: var(--radius-sm);
  overflow: hidden; background: hsl(var(--secondary));
  border: 1px dashed hsl(var(--border)); display: grid; place-items: center; color: hsl(var(--muted-foreground));
}
.character-card .char-repl.filled { border-style: solid; }
.character-card .char-repl img { width: 100%; height: 100%; object-fit: cover; }
.character-card .face-upload-label {
  flex-shrink: 0; font-size: 12px; font-weight: 500; cursor: pointer;
  padding: 7px 12px; border-radius: var(--radius-sm);
  color: hsl(var(--foreground)); background: hsl(var(--secondary)); border: 1px solid hsl(var(--border));
}
.character-card .face-upload-label:hover { border-color: hsl(var(--muted-foreground) / 0.5); }
.character-card .face-upload-label input { display: none; }

/* ===================== Structured timeline ===================== */
.timeline-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.timeline-body { padding-top: 14px; }

.timeline-ruler {
  position: relative;
  display: flex; justify-content: space-between;
  height: 18px; margin: 0 2px 6px;
  font-variant-numeric: tabular-nums;
}
.timeline-ruler .tick { position: relative; display: flex; flex-direction: column; align-items: center; }
.timeline-ruler .tick i { width: 1px; height: 6px; background: hsl(var(--border)); display: block; }
.timeline-ruler .tick label { font-size: 10.5px; color: hsl(var(--muted-foreground)); margin-top: 2px; }
.timeline-ruler .tick:first-child { align-items: flex-start; }
.timeline-ruler .tick:last-child { align-items: flex-end; }

.timeline-track {
  display: flex; gap: 4px; height: 76px;
  background:
    repeating-linear-gradient(90deg, hsl(var(--muted) / 0.5) 0 39px, hsl(var(--border)) 39px 40px);
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-md);
  padding: 5px; overflow-x: auto;
}
.timeline-segment {
  min-width: 64px;
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  color: hsl(var(--foreground));
  border-radius: var(--radius-sm); cursor: pointer;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 6px 7px; overflow: hidden;
  transition: border-color .15s ease, box-shadow .15s ease, transform .08s ease;
  position: relative;
}
.timeline-segment:hover { border-color: hsl(var(--muted-foreground) / 0.45); transform: translateY(-1px); }
.timeline-segment.selected {
  border-color: hsl(var(--ring));
  box-shadow: 0 0 0 2px hsl(var(--ring) / 0.18);
}
.timeline-segment.processing { border-color: hsl(var(--warning)); background: hsl(var(--warning) / 0.1); }
.timeline-segment.generated { border-color: hsl(var(--success)); background: hsl(var(--success) / 0.1); }

.seg-top { display: flex; align-items: center; justify-content: space-between; }
.seg-num { font-size: 11.5px; font-weight: 700; }
.seg-flag {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 16px; height: 16px; padding: 0 4px;
  font-size: 10px; font-weight: 700; border-radius: var(--radius-sm);
  background: hsl(var(--secondary)); color: hsl(var(--secondary-foreground));
}
.timeline-segment.generated .seg-flag { background: hsl(var(--success)); color: hsl(var(--success-foreground)); }
.timeline-segment.processing .seg-flag { background: hsl(var(--warning)); color: hsl(var(--warning-foreground)); }
.seg-flag:empty { display: none; }

.seg-strip { display: flex; gap: 2px; flex: 1; align-items: center; }
.seg-strip i { flex: 1; height: 14px; background: hsl(var(--border)); border-radius: 2px; opacity: .8; }
.timeline-segment.selected .seg-strip i { background: hsl(var(--muted-foreground) / 0.4); }
.timeline-segment.generated .seg-strip i { background: hsl(var(--success) / 0.4); }
.timeline-segment.processing .seg-strip i { background: hsl(var(--warning) / 0.4); }

.seg-dur { font-size: 10px; color: hsl(var(--muted-foreground)); font-variant-numeric: tabular-nums; }

.seg-spin {
  width: 10px; height: 10px; border-radius: 50%;
  border: 2px solid hsl(var(--warning-foreground) / 0.5); border-top-color: hsl(var(--warning-foreground));
  display: inline-block; animation: spin .7s linear infinite;
}

.face-slots { display: flex; flex-direction: column; gap: 12px; }
.face-slot {
  display: flex; flex-direction: column; gap: 10px;
  border: 1px solid hsl(var(--border)); border-radius: var(--radius-md);
  padding: 12px 14px; background: hsl(var(--card));
  transition: border-color .15s ease, box-shadow .15s ease;
}
.face-slot:hover { border-color: hsl(var(--muted-foreground) / 0.4); box-shadow: var(--shadow-xs); }
.face-main { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.face-review {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
  padding-top: 10px; border-top: 1px dashed hsl(var(--border));
}
.face-review .rev-hint {
  font-size: 11px; color: hsl(var(--muted-foreground)); font-weight: 500; margin-right: auto;
}
.face-review .rev-field {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; color: hsl(var(--muted-foreground)); font-weight: 500;
}
.face-review select {
  height: 28px; padding: 0 8px; font-size: 12px; font-weight: 500;
  color: hsl(var(--foreground)); background: hsl(var(--secondary));
  border: 1px solid hsl(var(--border)); border-radius: var(--radius-sm); cursor: pointer;
}
.face-review select:hover { border-color: hsl(var(--muted-foreground) / 0.5); }
.face-review input[type="number"] {
  width: 52px; height: 28px; padding: 0 6px; font-size: 12px; font-weight: 600;
  color: hsl(var(--foreground)); background: hsl(var(--secondary));
  border: 1px solid hsl(var(--border)); border-radius: var(--radius-sm); text-align: center;
}
.face-review input[type="number"]:focus { outline: none; border-color: hsl(var(--ring)); }

/* Editable generation prompt */
.prompt-field { margin-top: 16px; }
.prompt-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.prompt-label {
  font-size: 11px; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; color: hsl(var(--muted-foreground));
}
.prompt-reset {
  font-size: 11px; font-weight: 500; cursor: pointer;
  color: hsl(var(--muted-foreground)); background: transparent; border: 0; padding: 2px 4px;
  transition: color .15s ease;
}
.prompt-reset:hover { color: hsl(var(--foreground)); }
.prompt-input {
  width: 100%; box-sizing: border-box; resize: vertical; min-height: 64px;
  padding: 10px 12px; font: inherit; font-size: 12.5px; line-height: 1.5;
  color: hsl(var(--foreground)); background: hsl(var(--secondary));
  border: 1px solid hsl(var(--border)); border-radius: var(--radius-md);
}
.prompt-input:focus { outline: none; border-color: hsl(var(--ring)); }

/* Add-face toolbar + draw mode */
.faces-toolbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.faces-toolbar .faces-hint { margin-bottom: 0; }
#addFaceBtn { flex-shrink: 0; gap: 6px; }
#addFaceBtn.active { border-color: hsl(var(--destructive) / 0.5); color: hsl(var(--destructive)); }
.draw-hint { font-size: 12px; font-weight: 500; color: hsl(var(--warning)); margin: -4px 0 12px; }
.video-player.drawing #faceOverlay { pointer-events: auto; cursor: crosshair; }
.face-review .rev-del {
  height: 28px; padding: 0 10px; font-size: 12px; font-weight: 500; cursor: pointer;
  color: hsl(var(--destructive)); background: transparent;
  border: 1px solid hsl(var(--destructive) / 0.4); border-radius: var(--radius-sm);
  transition: background .15s ease, color .15s ease;
}
.face-review .rev-del:hover { background: hsl(var(--destructive)); color: hsl(var(--destructive-foreground)); }

.face-pair { display: flex; align-items: center; gap: 10px; }

.face-cell {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  position: relative; margin: 0;
}
.face-cell figcaption {
  font-size: 10px; color: hsl(var(--muted-foreground)); font-weight: 500;
  white-space: nowrap;
}

.face-crop, .face-thumb {
  width: 58px; height: 58px; border-radius: var(--radius-md);
  object-fit: cover; flex-shrink: 0; display: block;
  background: hsl(var(--muted));
}
.face-crop { border: 2px solid hsl(var(--ring)); }
.face-crop.placeholder, .face-thumb.empty {
  display: grid; place-items: center;
  border: 1px dashed hsl(var(--border)); color: hsl(var(--muted-foreground));
  font-size: 14px; font-weight: 700;
}
.face-num {
  border-style: solid !important; border-width: 2px !important;
  font-size: 24px !important; font-weight: 800;
  background: hsl(var(--muted) / 0.5);
}
.face-thumb { border: 1px solid hsl(var(--border)); }

.face-tag {
  position: absolute; top: -7px; left: -7px;
  min-width: 18px; height: 18px; padding: 0 4px;
  border-radius: 9px; background: hsl(var(--primary)); color: hsl(var(--primary-foreground));
  font-size: 10px; font-weight: 700;
  display: grid; place-items: center;
}

.face-arrow { color: hsl(var(--muted-foreground)); font-size: 16px; margin-top: -14px; }

.face-upload-label {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 14px; background: hsl(var(--primary)); color: hsl(var(--primary-foreground));
  border-radius: var(--radius-md); font-size: 12.5px; font-weight: 500; cursor: pointer;
  transition: background .15s ease; flex-shrink: 0;
}
.face-upload-label:hover { background: hsl(var(--primary) / 0.9); }
.face-upload-label input { display: none; }

.scene-foot { justify-content: space-between; }

.gen-status { font-size: 12.5px; color: hsl(var(--muted-foreground)); font-weight: 500; }
.gen-status.done { color: hsl(var(--success)); }
.gen-status.error { color: hsl(var(--destructive)); }
.gen-status.processing { color: hsl(var(--warning)); }

.generated-preview { margin-top: 20px; display: flex; flex-direction: column; gap: 10px; }
.generated-preview video {
  width: 100%; max-height: 320px; border-radius: var(--radius-md); background: #000;
  border: 1px solid hsl(var(--border));
}

.empty-state { color: hsl(var(--muted-foreground)); font-size: 13px; text-align: center; padding: 28px 16px; }

/* ===================== Merge ===================== */
.merge-actions { display: flex; align-items: center; gap: 12px; }
.merge-status { font-size: 12.5px; color: hsl(var(--muted-foreground)); }

.merge-clips {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px; min-height: 120px;
}
.clip-card {
  border: 1px solid hsl(var(--border)); border-radius: var(--radius-md); overflow: hidden;
  background: hsl(var(--card)); box-shadow: var(--shadow-xs);
  transition: box-shadow .15s ease, border-color .15s ease;
}
.clip-card:hover { box-shadow: var(--shadow-sm); border-color: hsl(var(--muted-foreground) / 0.4); }
.clip-card video { width: 100%; display: block; background: #000; }
.clip-label {
  padding: 9px 12px; font-size: 12px; font-weight: 500;
  display: flex; align-items: center; justify-content: space-between;
}
.clip-label .tag {
  font-size: 10.5px; color: hsl(var(--success)); background: hsl(var(--success) / 0.12);
  padding: 2px 8px; border-radius: 999px; font-weight: 600;
}

.final-video { margin-top: 20px; }
.final-video video { width: 100%; border-radius: var(--radius-md); background: #000; border: 1px solid hsl(var(--border)); }

/* ===================== Utilities ===================== */
.hidden { display: none !important; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: hsl(var(--muted-foreground) / 0.3); border-radius: 99px; border: 2px solid hsl(var(--app-bg)); }
::-webkit-scrollbar-thumb:hover { background: hsl(var(--muted-foreground) / 0.5); }

@media (max-width: 760px) {
  .page-inner, .page-head-inner { padding-left: 18px; padding-right: 18px; }
  .feature-row { grid-template-columns: 1fr; }
  .appbar { gap: 12px; }
}

/* ===================== Login ===================== */
.logout-form { margin: 0; }

.login-page { background: hsl(var(--app-bg)); }
.login-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 400px;
  padding: 32px 30px;
  box-shadow: var(--shadow-lg);
}
.login-brand {
  display: flex; align-items: center; gap: 10px; margin-bottom: 22px;
}
.login-brand .brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: var(--radius-md);
  background: hsl(var(--primary)); color: hsl(var(--primary-foreground));
}
.login-brand .brand-name { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }

.login-title { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; }
.login-sub { margin-top: 4px; font-size: 13.5px; color: hsl(var(--muted-foreground)); }

.login-alert {
  margin-top: 18px; padding: 10px 12px;
  border-radius: var(--radius-md);
  background: hsl(var(--destructive) / 0.1);
  color: hsl(var(--destructive));
  border: 1px solid hsl(var(--destructive) / 0.25);
  font-size: 13px; font-weight: 500;
}

.login-form { margin-top: 22px; display: flex; flex-direction: column; gap: 16px; }
.login-field { display: flex; flex-direction: column; gap: 6px; }
.login-label { font-size: 12.5px; font-weight: 500; color: hsl(var(--foreground)); }
.login-input {
  height: 40px; padding: 0 12px;
  border: 1px solid hsl(var(--input)); border-radius: var(--radius-md);
  background: hsl(var(--background)); color: hsl(var(--foreground));
  font-family: inherit; font-size: 14px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.login-input:focus {
  outline: none; border-color: hsl(var(--ring));
  box-shadow: 0 0 0 3px hsl(var(--ring) / 0.15);
}
.login-submit { width: 100%; height: 40px; margin-top: 4px; }
.login-note { margin-top: 16px; font-size: 12px; color: hsl(var(--muted-foreground)); text-align: center; }
