/* ==========================================================================
   Codex 分镜台 — Apple Design System
   主色调: Pinguo Blue #007aff | Space Black #0a0a0a | Silver Mist #f5f5f7
   字体: DM Sans (正文) + JetBrains Mono (等宽)
   圆角: 全局 1.2rem, 按钮 pill
   阴影: 极淡 1px → hover 8px
   动效: cubic-bezier(0.32, 0.72, 0, 1) 150ms/250ms/350ms
   ========================================================================== */

/* --- Google Fonts preconnect (loaded in HTML <head>) --- */

:root {
  color-scheme: light;

  /* Color tokens — mapped to Apple Design */
  --ink: #1d1d1f;
  --muted: #8e8e93;
  --line: #e5e5ea;
  --line-soft: #f0f0f2;
  --paper: #ffffff;
  --ground: #f5f5f7;
  --surface-hover: #f0f0f2;
  --surface-raised: #ffffff;
  --surface-subtle: #f5f5f7;
  --control-border: #d1d1d6;
  --control-ink: #1d1d1f;
  --topbar: rgba(255, 255, 255, 0.72);
  --grid-line: #e5e5ea;
  --preview-ground: #f5f5f7;
  --shadow-color: rgba(0, 0, 0, 0.04);
  --accent: #007aff;
  --accent-dark: #0064d6;
  --focus: rgba(0, 122, 255, 0.18);
  --blue: #007aff;
  --orange: #ff9500;
  --green: #34c759;
  --preview-ratio: 16 / 9;

  /* Spacing */
  --radius: 1.2rem;
  --radius-sm: 0.75rem;
  --radius-pill: 9999px;

  /* Z-index */
  --z-dropdown: 40;
  --z-sticky: 20;
  --z-lightbox: 100;

  /* Motion */
  --ease-apple: cubic-bezier(0.32, 0.72, 0, 1);
  --duration-fast: 150ms;
  --duration-normal: 250ms;
  --duration-slow: 350ms;
}

/* --- Dark Mode --- */
:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #f5f5f7;
  --muted: #98989d;
  --line: #3a3a3c;
  --line-soft: #2c2c2e;
  --paper: #000000;
  --ground: #000000;
  --surface-hover: #1c1c1e;
  --surface-raised: #1c1c1e;
  --surface-subtle: #2c2c2e;
  --control-border: #3a3a3c;
  --control-ink: #f5f5f7;
  --topbar: rgba(0, 0, 0, 0.72);
  --grid-line: #2c2c2e;
  --preview-ground: #1c1c1e;
  --shadow-color: rgba(0, 0, 0, 0.24);
  --accent: #2e8dff;
  --accent-dark: #4da3ff;
  --focus: rgba(46, 141, 255, 0.24);
  --green: #30d158;
  --orange: #ffb340;
}

/* --- Reset & Base --- */
* { box-sizing: border-box; }

html, body {
  min-width: 980px;
  min-height: 100%;
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: "DM Sans", "PingFang SC", -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

button, input, textarea, select { font: inherit; }
button { border: 0; cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: not-allowed; }
[hidden] { display: none !important; }

/* --- Topbar --- */
.topbar {
  position: relative;
  z-index: 30;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  background: var(--topbar);
  border-bottom: 0.5px solid var(--line);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
}

/* --- Brand --- */
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0;
  background: transparent;
  color: var(--ink);
  transition: opacity var(--duration-fast) var(--ease-apple);
}
.brand:hover { opacity: 0.72; }

.brand strong {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.mark {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-pill);
  background: var(--ink);
  color: white;
}
.mark svg {
  width: 18px;
  height: 18px;
  overflow: visible;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* --- Layout Utilities --- */
.header-actions,
.storyboard-header,
.project-heading,
.summary,
.duration-input,
.dialog-actions {
  display: flex;
  align-items: center;
}
.header-actions { gap: 10px; }

.storyboard-header {
  min-width: 0;
  flex: 1;
  justify-content: space-between;
  margin-left: 24px;
}

.project-heading { min-width: 0; gap: 10px; }
.editable-header-title {
  max-width: 280px;
  overflow: hidden;
  padding: 4px 6px;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.editable-header-title:hover,
.editable-header-title:focus-visible { background: var(--surface-hover); color: var(--accent); }
.project-heading > strong {
  max-width: 280px;
  overflow: hidden;
  font-size: 14px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- Back Button --- */
.back-button {
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--accent);
  font-size: 13px;
  font-weight: 500;
  transition: background var(--duration-fast) var(--ease-apple);
}
.back-button:hover { background: var(--surface-hover); color: var(--ink); }
.header-divider { width: 1px; height: 20px; background: var(--line); }

.ratio-badge {
  padding: 4px 10px;
  border: 1px solid var(--control-border);
  border-radius: var(--radius-pill);
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.active-content-title {
  max-width: 210px;
  overflow: hidden;
  padding: 4px 9px;
  border-radius: var(--radius-pill);
  background: var(--surface-subtle);
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.editable-header-title.active-content-title { border: 0; }

/* --- Summary --- */
.summary { gap: 12px; color: var(--muted); font-size: 12px; font-weight: 500; }
.summary strong {
  min-width: 34px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.summary-label { color: var(--muted); }

/* --- Design Menu --- */
.design-menu { position: relative; }
.design-menu-trigger {
  min-height: 36px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid var(--control-border);
  border-radius: var(--radius);
  background: var(--surface-raised);
  color: var(--control-ink);
  font-size: 13px;
  font-weight: 500;
  transition: border-color var(--duration-fast) var(--ease-apple),
              background var(--duration-fast) var(--ease-apple);
}
.design-menu-trigger:hover,
.design-menu-trigger[aria-expanded="true"] {
  border-color: var(--accent);
  background: var(--surface-hover);
}
.design-dot {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #c7c7cc;
}
.design-menu[data-active="true"] .design-dot {
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(52, 199, 89, 0.16);
}
.design-chevron {
  width: 6px;
  height: 6px;
  margin: -3px 1px 0 2px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  color: var(--muted);
  transform: rotate(45deg);
  transition: transform var(--duration-fast) var(--ease-apple);
}
.design-menu-trigger[aria-expanded="true"] .design-chevron {
  margin-top: 3px;
  transform: rotate(225deg);
}

/* --- Design Menu Popover --- */
.design-menu-popover {
  position: absolute;
  z-index: var(--z-dropdown);
  top: calc(100% + 6px);
  right: 0;
  width: 260px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-raised);
  box-shadow: 0 8px 24px -8px rgba(0, 0, 0, 0.08), 0 1px 2px 0 rgba(0, 0, 0, 0.04);
  animation: menu-in var(--duration-fast) var(--ease-apple);
}
.design-section-title {
  display: flex;
  align-items: center;
  gap: 7px;
}
.status-light {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #c7c7cc;
  box-shadow: 0 0 0 3px rgba(199, 199, 204, 0.14);
}
.status-light[data-active="true"] {
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(52, 199, 89, 0.14);
}
.menu-separator {
  height: 1px;
  margin: 6px 4px;
  background: var(--line-soft);
}
.menu-section-title {
  padding: 8px 10px 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.design-menu-item {
  width: 100%;
  min-height: 36px;
  padding: 8px 10px;
  border-radius: 0.5rem;
  background: transparent;
  color: var(--control-ink);
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  transition: background var(--duration-fast) var(--ease-apple);
}
.design-menu-item:hover,
.design-menu-item:focus-visible {
  outline: 0;
  background: var(--surface-hover);
  color: var(--ink);
}
.design-menu-item.danger { color: #ff3b30; }
.design-menu-item.danger:hover,
.design-menu-item.danger:focus-visible { background: rgba(255, 59, 48, 0.08); color: #ff3b30; }

/* --- Buttons --- */
.primary,
.secondary,
.danger-button,
.theme-toggle {
  min-height: 40px;
  padding: 10px 24px;
  border-radius: var(--radius-pill);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: -0.01em;
  transition: background var(--duration-fast) var(--ease-apple),
              transform var(--duration-fast) var(--ease-apple),
              box-shadow var(--duration-fast) var(--ease-apple);
}
.primary {
  background: var(--accent);
  color: white;
}
.primary:hover {
  background: var(--accent-dark);
  box-shadow: 0 2px 8px -2px rgba(0, 122, 255, 0.32);
}
.primary:active { transform: scale(0.97); }

.secondary {
  border: 1px solid var(--control-border);
  background: var(--surface-raised);
  color: var(--control-ink);
}
.secondary:hover { background: var(--surface-hover); border-color: var(--muted); }
.secondary:disabled { opacity: 0.4; }

.danger-button {
  background: #ff3b30;
  color: white;
}
.danger-button:hover { background: #e0342b; box-shadow: 0 2px 8px -2px rgba(255, 59, 48, 0.32); }
.danger-button:active { transform: scale(0.97); }

.theme-toggle {
  position: relative;
  width: 36px;
  height: 36px;
  min-height: 0;
  padding: 0;
  border: 1px solid var(--control-border);
  border-radius: 50%;
  background: var(--surface-raised);
  color: var(--control-ink);
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }
.theme-icon::before {
  display: block;
  font-size: 16px;
  line-height: 1;
}
:root[data-theme="light"] .theme-icon::before { content: "☾"; transform: translateY(-1px); }
:root[data-theme="dark"] .theme-icon::before { content: "☀"; font-size: 14px; }

/* --- Projects View --- */
.projects-view {
  width: min(1200px, calc(100% - 48px));
  margin: 0 auto;
  padding: 80px 0 120px;
}

.projects-intro {
  display: flex;
  align-items: end;
  justify-content: space-between;
  margin-bottom: 32px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.projects-intro h1 {
  margin: 0;
  font-size: clamp(36px, 5vw, 56px);
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1.08;
  color: var(--ink);
}
.projects-intro p:last-child {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 17px;
  font-weight: 400;
  line-height: 1.5;
}
.project-count {
  padding-bottom: 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

/* --- Projects Grid --- */
.projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 24px;
}

/* --- Project Card --- */
.project-card,
.new-project-card {
  min-height: 320px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--paper);
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.04);
  transition: border-color var(--duration-normal) var(--ease-apple),
              box-shadow var(--duration-normal) var(--ease-apple),
              transform var(--duration-normal) var(--ease-apple);
}
.project-card:hover,
.new-project-card:hover {
  border-color: var(--control-border);
  box-shadow: 0 20px 40px -12px rgba(0, 0, 0, 0.12);
  transform: translateY(-4px);
}

.project-open {
  width: 100%;
  padding: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}
.project-cover {
  position: relative;
  height: 210px;
  overflow: hidden;
  display: grid;
  place-items: center;
  border-radius: 19px 19px 0 0;
  background:
    linear-gradient(rgba(255,255,255,0.6), rgba(255,255,255,0.2)),
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px),
    var(--ground);
  background-size: auto, 24px 24px, 24px 24px, auto;
}
.project-cover img { width: 100%; height: 100%; object-fit: cover; display: none; }
.has-cover .project-cover img { display: block; }
.has-cover .project-placeholder { display: none; }
.project-placeholder {
  display: grid;
  justify-items: center;
  gap: 8px;
  color: var(--muted);
}
.project-placeholder strong {
  font-size: 20px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.project-placeholder span { font-size: 12px; font-weight: 500; }
.project-card-body { display: grid; gap: 6px; padding: 20px 22px 16px; }
.project-card-title {
  overflow: hidden;
  font-size: 18px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: -0.01em;
}
.project-meta { color: var(--muted); font-size: 12px; font-weight: 500; }
.project-card-actions { display: flex; gap: 4px; padding: 0 12px 12px; }
.card-action {
  padding: 6px 10px;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  transition: background var(--duration-fast) var(--ease-apple),
              color var(--duration-fast) var(--ease-apple);
}
.card-action:hover { background: var(--surface-hover); color: var(--ink); }
.card-action.danger:hover { background: rgba(255, 59, 48, 0.08); color: #ff3b30; }

.new-project-card {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  border: 2px dashed var(--line);
  color: var(--muted);
}
.new-project-card span {
  font-size: 40px;
  font-weight: 300;
  color: var(--accent);
  line-height: 1;
}
.new-project-card strong { font-size: 15px; font-weight: 600; }
.new-project-card small { color: var(--muted); font-size: 12px; }

/* --- Storyboard View --- */
.storyboard-view {
  height: calc(100vh - 56px);
  display: grid;
  grid-template-columns: 268px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  gap: 12px;
  padding: 16px 24px;
}
.compact-button { min-height: 30px; padding: 6px 14px; font-size: 12px; }

.episode-switcher {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  min-width: 0;
  min-height: 0;
  padding: 13px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: 0 4px 14px var(--shadow-color);
}
.episode-switcher-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding: 0 3px; }
.episode-switcher-heading strong { font-size: 12px; }
.episode-switcher-heading span { color: var(--muted); font-family: "JetBrains Mono", monospace; font-size: 10px; }
.episode-list {
  display: grid;
  align-content: start;
  gap: 8px;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding: 1px;
}
.episode-tree { min-width: 0; border: 1px solid transparent; border-radius: 10px; }
.episode-tree[data-active="true"] { border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); background: color-mix(in srgb, var(--accent) 3%, var(--paper)); }
.episode-tree-heading { display: grid; grid-template-columns: 22px minmax(0, 1fr) 26px; align-items: center; gap: 2px; }
.episode-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  width: 100%;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  transition: border-color var(--duration-fast) var(--ease-apple), background var(--duration-fast) var(--ease-apple);
}
.episode-item:hover { border-color: var(--accent); background: var(--surface-hover); }
.episode-item[aria-current="true"] { background: color-mix(in srgb, var(--accent) 7%, var(--surface-raised)); }
.episode-number { color: var(--muted); font-family: "JetBrains Mono", monospace; font-size: 10px; font-variant-numeric: tabular-nums; }
.episode-item[aria-current="true"] .episode-number { color: var(--accent); }
.episode-copy { min-width: 0; display: grid; gap: 2px; }
.episode-copy strong, .episode-copy small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.episode-copy strong { font-size: 11px; font-weight: 600; }
.episode-copy small { color: var(--muted); font-size: 9px; }
.episode-section-list { display: grid; gap: 2px; padding: 0 6px 8px 30px; }
.section-nav-row { display: grid; grid-template-columns: minmax(0, 1fr) 22px 22px; align-items: center; gap: 2px; }
.section-nav-item {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  align-items: center;
  gap: 5px;
  width: 100%;
  min-width: 0;
  padding: 5px 6px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 11px;
  text-align: left;
}
.section-nav-item:hover { background: var(--surface-hover); color: var(--ink); }
.section-nav-item[data-active="true"] { background: color-mix(in srgb, var(--accent) 11%, var(--surface-raised)); color: var(--accent); font-weight: 600; }
.section-nav-number { color: inherit; font-family: "JetBrains Mono", monospace; font-size: 9px; font-variant-numeric: tabular-nums; }
.section-nav-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.section-nav-all { display: block; padding-left: 6px; }
.episode-sections-empty { margin: 2px 0 0; color: var(--muted); font-size: 10px; line-height: 1.4; }
.episode-rename, .section-rename, .section-delete {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  line-height: 1;
}
.episode-collapse-toggle {
  display: grid;
  width: 22px;
  height: 24px;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 17px;
  line-height: 1;
}
.episode-collapse-toggle:hover { background: var(--surface-hover); color: var(--accent); }
.episode-rename, .section-rename { transform: scaleX(-1); }
.episode-rename:hover, .section-rename:hover { background: var(--surface-hover); color: var(--accent); }
.section-delete:hover { background: color-mix(in srgb, #ff3b30 10%, var(--surface-hover)); color: #ff3b30; }

.table-shell {
  height: 100%;
  overflow: auto;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

/* --- Table --- */
table {
  width: 100%;
  min-width: 1800px;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}
.col-index { width: 48px; }
.col-roll { width: 128px; }
.col-media { width: 108px; }
.col-duration { width: 86px; }
.col-scene { width: 170px; }
.col-dialogue { width: 260px; }
.col-visual { width: 310px; }
.col-video { width: 340px; }
.col-generator { width: 150px; }
.col-preview { width: 220px; }
.col-notes { width: 190px; }
.col-actions { width: 104px; }

th {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  height: 48px;
  padding: 0 12px;
  background: var(--ground);
  border-right: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-align: left;
  white-space: nowrap;
}
td {
  height: 200px;
  padding: 12px;
  vertical-align: top;
  border-right: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
  background: var(--paper);
}
th:last-child, td:last-child { border-right: 0; }
.shot-row td:last-child { padding-right: 0; }
.shot-actions-cell { display: grid; align-content: start; gap: 6px; padding: 10px 6px !important; }
.revise-shot, .shot-version-button {
  min-height: 28px;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--muted);
  font-size: 11px;
}
.revise-shot:hover, .shot-version-button:hover { border-color: var(--accent); color: var(--accent); }
.shot-actions-cell .delete-shot { justify-self: center; }
.shot-row:hover td {
  background: rgba(0, 122, 255, 0.03);
  border-bottom-color: var(--line);
}
.shot-row:hover td:first-child {
  box-shadow: inset 3px 0 0 var(--accent);
}
.index-cell {
  padding-top: 18px;
  color: var(--muted);
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  text-align: center;
  font-weight: 500;
}

/* --- Inputs --- */
input, textarea, select {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 0.5rem;
  background: transparent;
  color: var(--ink);
  transition: border-color var(--duration-fast) var(--ease-apple),
              background var(--duration-fast) var(--ease-apple),
              box-shadow var(--duration-fast) var(--ease-apple);
}
input { padding: 8px 10px; font-size: 13px; }
textarea {
  height: 164px;
  padding: 8px 10px;
  resize: none;
  font-size: 13px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}
input:hover, textarea:hover, select:hover { background: var(--surface-hover); }
input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 0;
  border-color: var(--accent);
  background: var(--surface-raised);
  box-shadow: 0 0 0 3px var(--focus);
}

.duration-input { position: relative; }
.duration-input span {
  position: absolute;
  right: 10px;
  color: var(--muted);
  font-size: 11px;
  pointer-events: none;
  font-weight: 500;
}
.duration-input input {
  padding-right: 27px;
  font-variant-numeric: tabular-nums;
  appearance: textfield;
}
.duration-input input::-webkit-inner-spin-button,
.duration-input input::-webkit-outer-spin-button {
  margin: 0;
  appearance: none;
}

.production-settings-dialog { width: min(720px, calc(100vw - 40px)); }
.scene-cards-dialog { width: min(940px, calc(100vw - 40px)); }
.form-dialog.character-cards-dialog { width: min(1320px, calc(100vw - 32px)); max-width: none; max-height: calc(100vh - 24px); overflow: hidden; }
.character-cards-dialog form { padding: 20px 22px; }
.character-cards-dialog .dialog-heading h2 { font-size: 24px; line-height: 1.15; }
.character-cards-dialog .eyebrow { margin-bottom: 3px; font-size: 10px; }
.character-cards-dialog .dialog-description { margin: 5px 0 14px; font-size: 13px; line-height: 1.45; }
.contents-header-actions { display: flex; align-items: center; gap: 10px; }
.dialog-description { margin: -6px 0 18px; color: var(--muted); line-height: 1.6; }
.production-settings-grid { display: grid; grid-template-columns: 1fr; gap: 18px; }
.production-settings-grid > section { padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-subtle); }
.production-settings-grid section > header { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.production-settings-grid section > header span { color: var(--muted); font-size: 12px; }
.constraint-field { display: grid; grid-template-columns: 86px minmax(0, 1fr) 54px; align-items: start; gap: 8px; margin-top: 10px; }
.constraint-field > span { padding-top: 9px; color: var(--muted); font-size: 12px; }
.constraint-field textarea { height: 64px; background: var(--paper); border-color: var(--line-soft); }
.constraint-field input[type="text"], .constraint-field > input:not([type]) { background: var(--paper); border-color: var(--line-soft); }
.lock-toggle { display: flex; align-items: center; gap: 4px; padding-top: 8px; color: var(--muted); font-size: 11px; cursor: pointer; }
.lock-toggle input { width: auto; accent-color: var(--accent); }

.scene-cards-layout { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 18px; min-height: 410px; }
.scene-cards-sidebar { padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-subtle); }
.scene-cards-sidebar-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.scene-cards-sidebar-heading strong { font-size: 13px; }
.scene-cards-sidebar .compact { min-height: 30px; padding: 5px 9px; font-size: 12px; }
.scene-cards-list { display: grid; gap: 7px; max-height: 340px; overflow-y: auto; padding-right: 2px; }
.scene-card-list-item { width: 100%; padding: 10px 11px; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); color: var(--ink); text-align: left; cursor: pointer; }
.scene-card-list-item:hover { border-color: color-mix(in srgb, var(--accent) 48%, var(--line)); }
.scene-card-list-item.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--paper)); }
.scene-card-list-item strong, .scene-card-list-item small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scene-card-list-item strong { font-size: 13px; }
.scene-card-list-item small { margin-top: 3px; color: var(--muted); font-size: 11px; }
.scene-cards-empty { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.55; }
.scene-card-editor { padding: 2px 2px 0; }
.scene-card-editor .form-field { margin-top: 0; margin-bottom: 14px; }
.scene-card-editor .form-field input, .scene-card-editor .form-field textarea { border-color: var(--control-border); background: var(--surface-raised); }
.scene-card-editor textarea { height: 68px; min-height: 68px; }
.scene-cards-dialog .dialog-actions > span { flex: 1; }
.scene-cards-dialog .dialog-actions .danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 42%, var(--line)); }

.character-cards-layout { display: grid; grid-template-columns: 190px minmax(0, 1fr); gap: 14px; align-items: start; }
.character-cards-sidebar { padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-subtle); }
.character-cards-sidebar .scene-cards-list { max-height: 520px; }
.character-card-editor { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; align-content: start; }
.character-card-editor > .form-field, .character-card-guide { grid-column: auto; }
.character-card-image { grid-column: 1 / -1; }
.character-card-editor .form-field { margin: 0; }
.character-card-editor > .form-field { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-subtle); }
.character-card-editor > .form-field > span { color: var(--ink); font-size: 16px; font-weight: 700; line-height: 1.25; }
.character-card-editor > .form-field > span em { color: var(--accent); font-size: 11px; font-style: normal; font-weight: 650; }
.character-card-guide { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-subtle); }
.character-card-guide > header { grid-column: 1 / -1; display: flex; justify-content: space-between; gap: 10px; margin-bottom: 1px; }
.character-card-guide header strong, .character-card-section header strong, .character-card-image header strong { font-size: 16px; line-height: 1.25; }
.character-card-guide header span { color: var(--muted); font-size: 11px; }
.character-card-guide .form-field { margin: 0; }
.character-card-section, .character-card-image { padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-subtle); }
.character-card-section { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 10px; row-gap: 8px; align-content: start; }
.character-card-section > header, .character-card-image > header { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.character-card-section > header { grid-column: 1 / -1; }
.character-card-section header span, .character-card-image header span { color: var(--muted); font-size: 11px; }
.character-card-section .form-field { margin: 0; }
.character-card-section > .form-field:nth-of-type(5) { grid-column: 1 / -1; }
.character-card-section textarea { height: 48px; }
.character-card-editor .form-field span { font-size: 12px; line-height: 1.2; }
.character-card-editor .form-field input, .character-card-editor .form-field textarea, .character-card-editor .form-field select, .outfit-toolbar select { border-color: var(--control-border); background: var(--surface-raised); font-size: 13px; }
.character-card-editor .form-field input, .character-card-editor .form-field select, .outfit-toolbar select { min-height: 36px; height: 36px; padding: 0 10px; }
.character-card-editor .form-field textarea { min-height: 48px; padding: 7px 10px; }
.outfit-toolbar { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 6px; }
.outfit-toolbar { grid-column: 1 / -1; }
.outfit-toolbar select { min-width: 0; }
.outfit-section .outfit-toolbar { margin-top: 28px; }
.outfit-section .character-reference-block { margin-top: -6px; }
.character-cards-dialog .secondary, .character-cards-dialog .primary { min-height: 36px; padding: 7px 13px; font-size: 13px; }
.character-card-image { display: grid; grid-template-columns: 126px minmax(0, 1fr) auto; column-gap: 12px; align-items: center; }
.character-card-image > header { grid-column: 1 / -1; }
.character-card-image-preview { display: grid; place-items: center; min-height: 82px; overflow: hidden; border: 1px dashed var(--control-border); border-radius: 9px; background: var(--surface-raised); color: var(--muted); font-size: 11px; text-align: center; }
.character-card-image-preview img { width: 100%; height: 82px; object-fit: contain; background: var(--ink); }
.character-card-image-prompt { display: -webkit-box; max-height: 56px; margin: 0; overflow: hidden; color: var(--muted); font-size: 11px; line-height: 1.5; -webkit-box-orient: vertical; -webkit-line-clamp: 3; }
.character-card-image .secondary { grid-column: auto; justify-self: end; }
.character-reference-block { display: grid; grid-template-columns: 68px minmax(0, 1fr); gap: 7px 10px; grid-column: 1 / -1; padding-top: 1px; }
.character-reference-block > header { grid-column: 1 / -1; display: flex; justify-content: space-between; gap: 10px; }
.character-reference-block > header strong { font-size: 14px; }
.character-reference-block > header span { color: var(--muted); font-size: 11px; }
.character-reference-preview { display: grid; min-height: 62px; place-items: center; overflow: hidden; border: 1px dashed var(--control-border); border-radius: 8px; background: var(--surface-raised); color: var(--muted); font-size: 10px; line-height: 1.35; text-align: center; }
.character-reference-preview img { width: 100%; height: 62px; object-fit: cover; }
.reference-image-actions { display: flex; flex-wrap: wrap; align-content: center; gap: 6px; }
.reference-image-actions .danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 42%, var(--line)); }
.character-reference-block .form-field { grid-column: 1 / -1; }
.character-card-list-item { display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 9px; align-items: center; }
.character-card-list-copy { min-width: 0; }
.character-card-thumbnail { display: grid; width: 44px; height: 44px; place-items: center; overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-subtle); color: var(--muted); font-size: 10px; line-height: 1.3; text-align: center; }
.character-card-thumbnail img { width: 100%; height: 100%; object-fit: cover; }
.character-card-thumbnail[data-state="pending"], .character-card-thumbnail[data-state="processing"] { color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--paper)); }
.character-cards-dialog .dialog-actions { margin-top: 14px; }
.character-cards-dialog .dialog-actions > span { flex: 1; }
.character-cards-dialog .dialog-actions .danger, .outfit-toolbar .danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 42%, var(--line)); }
.role-mention-menu { position: fixed; z-index: 30; width: min(280px, calc(100vw - 24px)); max-height: 220px; overflow-y: auto; padding: 6px; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); box-shadow: 0 12px 28px rgba(20, 20, 19, .16); }
.role-mention-option { display: grid; width: 100%; gap: 2px; padding: 8px 9px; border: 0; border-radius: 7px; background: transparent; color: var(--ink); text-align: left; cursor: pointer; }
.role-mention-option:hover { background: var(--surface-hover); }
.role-mention-option small { color: var(--muted); font-size: 11px; }
.shot-scene-card { min-width: 150px; }

.shot-revision-dialog { width: min(920px, calc(100vw - 40px)); }
.quality-dialog, .snapshots-dialog, .analytics-dialog { width: min(860px, calc(100vw - 40px)); }
.quality-summary { display: flex; flex-wrap: wrap; gap: 10px; margin: 16px 0; }
.quality-summary span { padding: 8px 11px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); font-size: 13px; }
.quality-issues { display: grid; gap: 10px; max-height: 46vh; overflow: auto; }
.quality-issue { border: 1px solid var(--line); border-left: 4px solid var(--muted); border-radius: 12px; padding: 12px 14px; background: var(--panel); }
.quality-issue.priority-high { border-left-color: #e85742; }
.quality-issue.priority-medium { border-left-color: #e9a11a; }
.quality-issue.priority-low { border-left-color: #4b8bff; }
.quality-issue p { margin: 6px 0; color: var(--muted); font-size: 13px; }
.quality-issue small { color: var(--muted); }
.quality-issue button { margin-top: 10px; }
.revision-diff-item { padding: 10px 0; border-top: 1px solid var(--line); }
.revision-diff-item p { margin: 6px 0; font-size: 13px; color: var(--muted); }
.locked-constraints { margin-bottom: 14px; padding: 10px 12px; border: 1px solid color-mix(in srgb, var(--accent) 32%, var(--line)); border-radius: 10px; background: color-mix(in srgb, var(--accent) 7%, var(--paper)); color: var(--muted); font-size: 12px; line-height: 1.6; }
.locked-constraints strong { color: var(--ink); }
.preserve-fields { margin: 14px 0; padding: 12px; border: 1px solid var(--line); border-radius: 12px; }
.preserve-fields legend { padding: 0 6px; font-weight: 650; }
.preserve-fields p { margin: 0 0 10px; color: var(--muted); font-size: 12px; }
.preserve-fields > div { display: flex; flex-wrap: wrap; gap: 8px; }
.preserve-fields label { display: flex; align-items: center; gap: 5px; padding: 6px 9px; border-radius: 8px; background: var(--surface-subtle); font-size: 12px; }
.preserve-fields input { width: auto; accent-color: var(--accent); }
.revision-status { padding: 10px 12px; border-radius: 10px; background: var(--surface-subtle); color: var(--muted); font-size: 12px; }
.revision-status[data-state="loading"] { color: var(--accent); }
.revision-status[data-state="error"] { color: var(--danger); background: var(--danger-soft); }
.revision-comparison, .shot-version-history { margin-top: 16px; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.revision-comparison > header, .shot-version-history > header { display: flex; justify-content: space-between; gap: 16px; padding: 11px 13px; border-bottom: 1px solid var(--line); background: var(--surface-subtle); }
.revision-comparison header span, .shot-version-history header span { color: var(--muted); font-size: 12px; }
.revision-diff-row { display: grid; grid-template-columns: 110px 1fr 24px 1fr; gap: 10px; padding: 10px 13px; border-bottom: 1px solid var(--line-soft); font-size: 12px; line-height: 1.55; }
.revision-diff-row:last-child { border-bottom: 0; }
.revision-diff-field { color: var(--muted); font-weight: 600; }
.revision-diff-before, .revision-diff-after { white-space: pre-wrap; overflow-wrap: anywhere; }
.revision-diff-arrow { color: var(--accent); text-align: center; }
.version-history-item { padding: 10px 13px; border-bottom: 1px solid var(--line-soft); font-size: 12px; }
.version-history-item:last-child { border-bottom: 0; }
.version-history-item strong { margin-right: 8px; }
.version-history-item span { color: var(--muted); }
.version-history-empty { padding: 14px; color: var(--muted); font-size: 12px; }

.generation-conflict-dialog { width: min(820px, calc(100vw - 40px)); }
.generation-conflicts { margin-top: 14px; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.generation-conflicts.blocking { border-color: color-mix(in srgb, var(--danger) 42%, var(--line)); }
.generation-conflict-heading { padding: 10px 13px; background: var(--surface-subtle); border-bottom: 1px solid var(--line); font-weight: 650; }
.generation-conflicts.blocking .generation-conflict-heading { background: var(--danger-soft); color: var(--danger); }
.generation-conflict-item { padding: 12px 13px; border-bottom: 1px solid var(--line-soft); }
.generation-conflict-item:last-child { border-bottom: 0; }
.generation-conflict-item p { margin: 0; line-height: 1.6; font-size: 13px; }
.generation-conflict-item .conflict-values { margin-top: 7px; color: var(--muted); font-size: 12px; }
.conflict-resolution-options { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.conflict-resolution-options label { display: flex; align-items: center; gap: 6px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; font-size: 12px; }
.conflict-resolution-options input { width: auto; accent-color: var(--accent); }
.unlocked-conflict-note { color: var(--accent); }

@media (max-width: 900px) {
  .production-settings-grid { grid-template-columns: 1fr; }
  .scene-cards-layout { grid-template-columns: 1fr; }
  .character-cards-layout { grid-template-columns: 1fr; }
  .character-card-editor { grid-template-columns: 1fr; }
  .character-card-guide { grid-template-columns: 1fr; }
  .character-card-section { grid-template-columns: 1fr; }
  .character-card-image { grid-template-columns: 1fr; }
  .character-card-image .secondary { grid-column: auto; }
  .character-reference-block { grid-template-columns: 1fr; }
  .scene-cards-list { max-height: 160px; }
}

/* --- Select --- */
.select-trigger {
  width: 100%;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--surface-raised);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  transition: border-color var(--duration-fast) var(--ease-apple),
              background var(--duration-fast) var(--ease-apple),
              box-shadow var(--duration-fast) var(--ease-apple);
}
.select-trigger:hover { background: var(--surface-hover); }
.select-trigger[aria-expanded="true"],
.select-trigger:focus-visible {
  outline: 0;
  border-color: var(--accent);
  background: var(--surface-raised);
  box-shadow: 0 0 0 3px var(--focus);
}
.select-chevron {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'%3E%3Cpath d='M2.5 3.75L5 6.25L7.5 3.75' fill='none' stroke='%238e8e93' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}
.select-value.roll-a,
.select-value.roll-b {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  white-space: nowrap;
}
.select-value.roll-a::before,
.select-value.roll-b::before {
  width: 6px;
  height: 6px;
  content: "";
  border-radius: 50%;
  background: var(--blue);
}
.select-value.roll-b::before { background: var(--orange); }

.select-menu {
  position: fixed;
  z-index: var(--z-dropdown);
  min-width: 120px;
  max-width: 200px;
  padding: 5px;
  border: 1px solid var(--control-border);
  border-radius: 12px;
  background: var(--surface-raised);
  box-shadow: 0 12px 40px -8px rgba(0, 0, 0, 0.14), 0 4px 12px -2px rgba(0, 0, 0, 0.06);
  animation: menu-in var(--duration-fast) var(--ease-apple);
  word-break: keep-all;
  white-space: nowrap;
}
.select-option {
  width: 100%;
  min-height: 36px;
  display: flex;
  align-items: center;
  padding: 7px 10px;
  border-radius: 0.5rem;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  transition: background var(--duration-fast) var(--ease-apple);
}
.select-option:hover,
.select-option:focus-visible { outline: 0; background: var(--surface-hover); }
.select-option[aria-selected="true"] {
  background: rgba(0, 122, 255, 0.08);
  color: var(--accent);
  font-weight: 600;
}

/* --- Preview --- */
.preview-stack { display: flex; flex-direction: column; gap: 8px; }
.preview-slot {
  min-height: 158px;
  display: grid;
  place-items: center;
}
.preview-frame {
  position: relative;
  width: 100%;
  display: grid;
  place-items: center;
}
.preview-frame.portrait-preview {
  width: auto;
  height: 158px;
  max-width: 100%;
}
.preview {
  width: 100%;
  height: 100%;
  overflow: hidden;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  background-color: var(--preview-ground);
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 20px 20px;
  color: inherit;
  transition: border-color var(--duration-fast) var(--ease-apple);
}
.preview:not(:disabled):hover { border-color: var(--control-border); }
.preview:not(:disabled):hover img,
.preview:not(:disabled):hover video { transform: scale(1.025); }
.preview.is-uploadable:hover { border-color: var(--accent); background-color: rgba(0, 122, 255, 0.04); }
.preview img, .preview video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #111;
  transition: transform var(--duration-normal) var(--ease-apple);
}
.empty-preview { max-width: 150px; padding: 12px; color: var(--muted); font-size: 12px; line-height: 1.5; font-weight: 500; }

.media-kind {
  position: absolute;
  left: 8px;
  bottom: 8px;
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  background: rgba(0, 0, 0, 0.56);
  color: white;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.06em;
  backdrop-filter: blur(8px);
}
.remove-media {
  position: absolute;
  z-index: 2;
  top: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  padding: 0 0 2px;
  border: none;
  border-radius: var(--radius-pill);
  background: rgba(0, 0, 0, 0.56);
  color: white;
  font-size: 16px;
  line-height: 1;
  opacity: 0;
  transform: scale(0.9);
  transition: opacity var(--duration-fast) var(--ease-apple),
              transform var(--duration-fast) var(--ease-apple),
              background var(--duration-fast) var(--ease-apple);
  backdrop-filter: blur(8px);
}
.preview-frame:hover .remove-media,
.preview-frame:focus-within .remove-media {
  opacity: 1;
  transform: scale(1);
}
.remove-media:hover,
.remove-media:focus-visible {
  outline: 0;
  background: #ff3b30;
  box-shadow: 0 0 0 3px rgba(255, 59, 48, 0.2);
}

/* --- Generation Controls --- */
.generation-controls {
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.generation-status {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.generation-status[data-status="pending"] { color: var(--orange); }
.generation-status[data-status="processing"] { color: var(--accent); }
.generation-status[data-status="ready"] { color: var(--green); }
.generation-status[data-status="failed"] { color: #ff3b30; }

.generate-shot {
  flex: 0 0 auto;
  min-height: 28px;
  padding: 5px 12px;
  border: 1px solid var(--control-border);
  border-radius: var(--radius-pill);
  background: var(--surface-raised);
  color: var(--control-ink);
  font-size: 11px;
  font-weight: 500;
  transition: border-color var(--duration-fast) var(--ease-apple),
              color var(--duration-fast) var(--ease-apple),
              background var(--duration-fast) var(--ease-apple);
}
.generate-shot:hover { border-color: var(--accent); color: var(--accent); }
.generate-shot[data-action="cancel"] {
  border-color: var(--orange);
  color: var(--orange);
}
.generate-shot[data-action="cancel"]:hover {
  border-color: #e08600;
  background: rgba(255, 149, 0, 0.08);
  color: #e08600;
}
.generate-shot:disabled { opacity: 0.4; }

/* --- Delete Shot --- */
.delete-shot {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  transition: background var(--duration-fast) var(--ease-apple),
              color var(--duration-fast) var(--ease-apple);
}
.delete-shot:hover { background: rgba(255, 59, 48, 0.08); color: #ff3b30; }

/* --- Add Row --- */
.add-row {
  display: block;
  margin: 12px auto 0;
  min-height: 40px;
  padding: 8px 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface-raised);
  color: var(--accent);
  font-size: 14px;
  font-weight: 500;
  transition: border-color var(--duration-fast) var(--ease-apple),
              background var(--duration-fast) var(--ease-apple);
}
.add-row:hover { border-color: var(--accent); background: rgba(0, 122, 255, 0.04); }

/* --- Form Dialog --- */
.form-dialog {
  width: min(520px, calc(100vw - 40px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface-raised);
  color: var(--ink);
  box-shadow: 0 24px 64px -12px rgba(0, 0, 0, 0.12);
}
.form-dialog::backdrop {
  background: rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.form-dialog form { padding: 28px; }
.dialog-heading { display: flex; align-items: start; justify-content: space-between; }
.dialog-heading h2 {
  margin: 0;
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.03em;
}
.dialog-close {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  transition: background var(--duration-fast) var(--ease-apple),
              color var(--duration-fast) var(--ease-apple);
}
.dialog-close:hover { background: var(--surface-hover); color: var(--ink); }

.form-field { display: grid; gap: 8px; margin-top: 24px; }
.form-field span, .ratio-options legend {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}
.form-field input {
  height: 44px;
  padding: 0 14px;
  border-color: var(--control-border);
  border-radius: var(--radius);
  background: var(--surface-raised);
  font-size: 15px;
  font-weight: 400;
}

/* --- Ratio Options --- */
.ratio-options {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin: 24px 0 0;
  padding: 0;
  border: 0;
}
.ratio-options legend { margin-bottom: 12px; }
.ratio-option {
  position: relative;
  display: grid;
  grid-template-rows: 38px 14px;
  justify-items: center;
  align-items: center;
  gap: 5px;
  padding: 8px 5px 9px;
  border: 1px solid var(--control-border);
  border-radius: 12px;
  cursor: pointer;
  transition: border-color var(--duration-fast) var(--ease-apple),
              background var(--duration-fast) var(--ease-apple),
              box-shadow var(--duration-fast) var(--ease-apple);
}
.ratio-option input { position: absolute; opacity: 0; pointer-events: none; }
.ratio-option:has(input:checked) {
  border-color: var(--accent);
  background: rgba(0, 122, 255, 0.06);
  box-shadow: 0 0 0 2px var(--focus);
}
.ratio-shape-stage {
  width: 42px;
  height: 38px;
  display: grid;
  place-items: center;
}
.ratio-shape {
  width: auto;
  height: auto;
  max-width: 38px;
  max-height: 34px;
  border: 1.5px solid var(--muted);
  border-radius: 3px;
}
.ratio-option strong {
  line-height: 14px;
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* --- Design Import --- */
.design-import {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 20px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-subtle);
}
.design-import > div { min-width: 0; display: grid; gap: 4px; }
.design-import strong { color: var(--ink); font-size: 13px; font-weight: 600; }
.design-import span {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dialog-actions { justify-content: flex-end; gap: 10px; margin-top: 28px; }
.delete-message { margin: 24px 0 0; color: var(--muted); font-size: 14px; line-height: 1.7; }
.danger-text { color: #ff3b30; }

/* --- Design Dialog --- */
.design-dialog { width: min(720px, calc(100vw - 32px)); }
.design-content {
  max-height: min(62vh, 620px);
  margin: 20px 0 0;
  overflow: auto;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-subtle);
  color: var(--ink);
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  line-height: 1.75;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* --- Lightbox --- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: var(--z-lightbox);
  display: grid;
  place-items: center;
  padding: 72px 48px 92px;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  animation: lightbox-in var(--duration-normal) var(--ease-apple);
}
.lightbox-stage {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  pointer-events: none;
}
.lightbox-stage img,
.lightbox-stage video {
  max-width: 94vw;
  max-height: calc(100vh - 180px);
  object-fit: contain;
  border-radius: 12px;
  background: #090a0b;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  pointer-events: auto;
}
.lightbox-close {
  position: fixed;
  top: 24px;
  right: 24px;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 24px;
  transition: background var(--duration-fast) var(--ease-apple);
  backdrop-filter: blur(8px);
}
.lightbox-close:hover { background: rgba(255, 255, 255, 0.24); }

.lightbox-toolbar {
  position: fixed;
  left: 50%;
  bottom: 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 16px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-pill);
  background: rgba(20, 20, 22, 0.72);
  color: #f5f5f7;
  font-size: 13px;
  font-weight: 500;
  transform: translateX(-50%);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
}
.lightbox-upload {
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  background: white;
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  transition: transform var(--duration-fast) var(--ease-apple);
}
.lightbox-upload:hover { transform: scale(1.04); }
.lightbox-open { overflow: hidden; }

/* --- Cover Panel --- */
.cover-panel {
  position: fixed;
  inset: 0;
  z-index: calc(var(--z-lightbox) - 5);
}
.cover-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.cover-sheet {
  position: absolute;
  top: 0;
  right: 0;
  width: min(480px, 100vw);
  height: 100%;
  overflow: auto;
  padding: 24px;
  background: var(--paper);
  border-left: 1px solid var(--line);
  box-shadow: -18px 0 56px rgba(0, 0, 0, 0.08);
  animation: cover-in var(--duration-normal) var(--ease-apple);
}
.cover-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}
.cover-heading h2 {
  margin: 0;
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.03em;
}
.cover-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 20px;
}
.cover-tab {
  min-height: 38px;
  border: 1px solid var(--control-border);
  border-radius: var(--radius-pill);
  background: var(--surface-raised);
  color: var(--control-ink);
  font-size: 13px;
  font-weight: 500;
  transition: border-color var(--duration-fast) var(--ease-apple),
              background var(--duration-fast) var(--ease-apple),
              color var(--duration-fast) var(--ease-apple);
}
.cover-tab[aria-selected="true"] {
  border-color: var(--accent);
  background: rgba(0, 122, 255, 0.08);
  color: var(--accent);
}

.cover-editor {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 20px;
}
.cover-preview-column { display: grid; align-content: start; gap: 10px; }
.cover-preview-frame {
  display: grid;
  width: 100%;
  aspect-ratio: 9 / 16;
}
.cover-preview-frame[data-cover-type="horizontal"] { aspect-ratio: 16 / 9; }
.cover-preview {
  min-height: 0;
  height: 100%;
}
.cover-form { display: grid; gap: 14px; }
.cover-field { margin-top: 0; }
.cover-field textarea {
  height: 150px;
  padding: 10px;
  resize: vertical;
  border: 1px solid var(--control-border);
  border-radius: 0.75rem;
  background: var(--surface-raised);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.6;
}
.cover-select {
  height: 40px;
  padding: 0 14px;
  border: 1px solid var(--control-border);
  border-radius: 0.75rem;
  background: var(--surface-raised);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
}
.cover-reference {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--control-border);
  border-radius: 12px;
  background: var(--surface-raised);
}
.cover-reference-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}
.cover-reference-preview {
  display: grid;
  place-items: center;
  min-height: 86px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  background:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px),
    var(--ground);
  background-size: 16px 16px;
  color: var(--muted);
  font-size: 12px;
}
.cover-reference-preview img {
  width: 100%;
  height: 110px;
  object-fit: cover;
}
.cover-generate { width: 100%; }
.cover-hint {
  min-height: 32px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

/* --- Toast --- */
.toast {
  position: fixed;
  z-index: 150;
  left: 50%;
  bottom: 32px;
  padding: 10px 20px;
  border-radius: 12px;
  background: var(--ink);
  color: var(--paper);
  font-size: 13px;
  font-weight: 500;
  transform: translateX(-50%);
  box-shadow: 0 8px 24px -4px rgba(0, 0, 0, 0.16);
  animation: toast-in var(--duration-normal) var(--ease-apple);
}
.toast[data-type="error"] { background: #ff3b30; color: white; }

/* ===================================================================
   Dark Mode Overrides
   =================================================================== */

:root[data-theme="dark"] .mark {
  background: #f5f5f7;
  color: #000000;
}
:root[data-theme="dark"] .back-button { color: var(--accent); }
:root[data-theme="dark"] .ratio-badge {
  border-color: var(--control-border);
  color: var(--muted);
}
:root[data-theme="dark"] .projects-intro h1 {
  color: #f5f5f7;
}
:root[data-theme="dark"] .project-cover {
  background:
    linear-gradient(rgba(0,0,0,0.3), rgba(0,0,0,0.6)),
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px),
    #1c1c1e;
  background-size: auto, 22px 22px, 22px 22px, auto;
}
:root[data-theme="dark"] .project-placeholder,
:root[data-theme="dark"] .project-meta,
:root[data-theme="dark"] .new-project-card,
:root[data-theme="dark"] .new-project-card small {
  color: var(--muted);
}
:root[data-theme="dark"] .card-action { color: var(--muted); }
:root[data-theme="dark"] .card-action:hover { background: var(--surface-hover); color: var(--ink); }
:root[data-theme="dark"] .card-action.danger:hover { background: rgba(255, 59, 48, 0.12); color: #ff6961; }
:root[data-theme="dark"] .shot-row:hover td {
  background: rgba(46, 141, 255, 0.05);
  border-bottom-color: var(--line);
}
:root[data-theme="dark"] .shot-row:hover td:first-child {
  box-shadow: inset 3px 0 0 var(--accent);
}
:root[data-theme="dark"] input,
:root[data-theme="dark"] textarea { caret-color: var(--accent); }
:root[data-theme="dark"] .select-option:hover,
:root[data-theme="dark"] .select-option:focus-visible {
  background: var(--surface-hover);
}
:root[data-theme="dark"] .select-option[aria-selected="true"] {
  background: rgba(46, 141, 255, 0.12);
  color: var(--accent);
}
:root[data-theme="dark"] .preview.is-uploadable:hover { background-color: rgba(46, 141, 255, 0.06); }
:root[data-theme="dark"] .empty-preview { color: var(--muted); }
:root[data-theme="dark"] .generate-shot[data-action="cancel"] {
  border-color: #ffb340;
  color: #ffb340;
}
:root[data-theme="dark"] .generate-shot[data-action="cancel"]:hover {
  border-color: #e8a020;
  background: rgba(255, 179, 64, 0.1);
  color: #ffc860;
}
:root[data-theme="dark"] .delete-shot:hover { background: rgba(255, 59, 48, 0.12); color: #ff6961; }
:root[data-theme="dark"] .design-menu-item.danger { color: #ff6961; }
:root[data-theme="dark"] .design-menu-item.danger:hover,
:root[data-theme="dark"] .design-menu-item.danger:focus-visible { background: rgba(255, 59, 48, 0.1); }
:root[data-theme="dark"] .add-row:hover { border-color: var(--accent); background: rgba(46, 141, 255, 0.04); }
:root[data-theme="dark"] .dialog-close:hover { background: var(--surface-hover); }
:root[data-theme="dark"] .ratio-option { border-color: var(--control-border); }
:root[data-theme="dark"] .ratio-option:has(input:checked) {
  border-color: var(--accent);
  background: rgba(46, 141, 255, 0.1);
}
:root[data-theme="dark"] .ratio-shape { border-color: var(--muted); }
:root[data-theme="dark"] .design-import { background: var(--surface-subtle); }
:root[data-theme="dark"] .form-field span,
:root[data-theme="dark"] .ratio-options legend,
:root[data-theme="dark"] .delete-message { color: var(--muted); }
:root[data-theme="dark"] .lightbox {
  background: rgba(0, 0, 0, 0.82);
}
:root[data-theme="dark"] .lightbox-toolbar {
  border-color: rgba(255, 255, 255, 0.08);
  background: rgba(20, 20, 22, 0.82);
}
:root[data-theme="dark"] .lightbox-upload {
  background: var(--ink);
  color: var(--paper);
}
:root[data-theme="dark"] .cover-backdrop { background: rgba(0, 0, 0, 0.48); }
:root[data-theme="dark"] .cover-tab[aria-selected="true"] {
  background: rgba(46, 141, 255, 0.1);
  color: var(--accent);
}
:root[data-theme="dark"] .toast { background: #2c2c2e; color: #f5f5f7; }
:root[data-theme="dark"] .toast[data-type="error"] { background: #ff3b30; color: white; }

/* --- Focus Ring --- */
button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* ===================================================================
   Animations
   =================================================================== */
@keyframes menu-in {
  from { opacity: 0; transform: translateY(-4px) scale(0.98); }
}
@keyframes lightbox-in {
  from { opacity: 0; }
}
@keyframes cover-in {
  from { transform: translateX(24px); opacity: 0.7; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(12px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

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

/* --- Responsive --- */
@media (max-width: 1180px) {
  .summary-label, #save-status { display: none; }
  .editable-header-title { max-width: 150px; }
}

/* ===================================================================
   镜序 AI — Brief and structured-script workflow
   =================================================================== */
.brand-copy {
  display: grid;
  gap: 1px;
  text-align: left;
}

.brand-copy small {
  color: var(--muted);
  font-family: "JetBrains Mono", monospace;
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.workflow-header {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 18px;
  margin-left: 28px;
}

.workflow-header-copy {
  min-width: 150px;
  display: grid;
  gap: 2px;
  padding-left: 18px;
  border-left: 1px solid var(--line);
}

.workflow-header-copy strong {
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.workflow-header-copy span {
  color: var(--muted);
  font-size: 11px;
}

.workflow-steps {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface-subtle);
}

.workflow-steps span {
  padding: 7px 12px;
  border-radius: var(--radius-pill);
  color: var(--muted);
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  transition: 160ms ease;
}

.workflow-steps span[data-active="true"] {
  background: var(--ink);
  color: var(--paper);
  box-shadow: 0 2px 8px var(--shadow-color);
}

.workflow-steps span[data-complete="true"] { color: var(--green); }

.workflow-view {
  min-height: calc(100vh - 57px);
  padding: 38px 42px 80px;
}

.workflow-shell {
  width: min(1080px, calc(100vw - 84px));
  margin: 0 auto;
}

.create-shell { width: min(980px, calc(100vw - 84px)); }

.workflow-intro {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 40px;
  margin-bottom: 26px;
}

.workflow-intro h1 {
  margin: 5px 0 7px;
  font-size: clamp(30px, 3vw, 44px);
  letter-spacing: -0.045em;
  line-height: 1.08;
}

.workflow-intro p:last-child {
  max-width: 660px;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.local-badge,
.ai-status {
  flex: 0 0 auto;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface-raised);
  color: var(--muted);
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
}

.ai-status[data-status="generating"] { border-color: var(--accent); color: var(--accent); }
.ai-status[data-status="review"] { border-color: var(--orange); color: var(--orange); }
.ai-status[data-status="modified"] { border-color: var(--blue); color: var(--blue); }
.ai-status[data-status="confirmed"] { border-color: var(--green); color: var(--green); }
.ai-status[data-status="failed"] { border-color: #ff3b30; color: #ff3b30; }

.requirements-form,
.brief-form {
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  background: var(--paper);
  box-shadow: 0 12px 42px var(--shadow-color);
}

.form-grid {
  display: grid;
  gap: 20px;
}

.two-columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.three-columns { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span-two { grid-column: span 2; }

.workflow-view .form-field {
  align-content: start;
  gap: 8px;
  margin: 0;
}

.workflow-view .form-field > span {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
}

.workflow-view .form-field > span em {
  color: var(--accent);
  font-size: 10px;
  font-style: normal;
}

.workflow-view .form-field > span small,
.workflow-view .form-field > small {
  color: var(--muted);
  font-size: 10px;
  font-weight: 400;
}

.workflow-view input,
.workflow-view textarea,
.workflow-view select {
  width: 100%;
  min-height: 44px;
  padding: 11px 13px;
  border: 1px solid var(--control-border);
  border-radius: 10px;
  outline: none;
  background: var(--surface-raised);
  color: var(--control-ink);
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.workflow-view textarea {
  min-height: 92px;
  resize: vertical;
  line-height: 1.55;
}

.workflow-view input:focus,
.workflow-view textarea:focus,
.workflow-view select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus);
}

.request-field { margin: 24px 0 !important; }
.request-field textarea { min-height: 170px; font-size: 16px; }

.input-suffix { position: relative; }
.input-suffix input { padding-right: 42px; }
.input-suffix > span {
  position: absolute;
  right: 13px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 11px;
}

.advanced-settings {
  margin-top: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-subtle);
}

.advanced-settings summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}

.advanced-settings summary span { color: var(--muted); font-size: 11px; font-weight: 400; }
.advanced-grid { padding: 6px 18px 20px; }

.workflow-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-top: 24px;
}

.workflow-footer p { margin: 0; color: var(--muted); font-size: 12px; }
.large-button { min-height: 44px; padding-inline: 22px; }

.sticky-footer {
  position: sticky;
  z-index: 10;
  bottom: 20px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  box-shadow: 0 12px 38px rgba(0, 0, 0, 0.08);
  backdrop-filter: blur(18px);
}

.inline-error {
  margin-top: 18px;
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(255, 59, 48, 0.08);
  color: #d92d20;
  font-size: 12px;
}

.generation-state,
.empty-workflow {
  display: grid;
  justify-items: center;
  gap: 8px;
  margin-bottom: 24px;
  padding: 42px 24px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  text-align: center;
}

.generation-state p,
.empty-workflow p { margin: 0; color: var(--muted); font-size: 12px; }
.error-state { border-color: rgba(255, 59, 48, 0.28); background: rgba(255, 59, 48, 0.035); }

.spinner {
  width: 26px;
  height: 26px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

.brief-form { padding: 26px; }
.question-field textarea { border-color: rgba(255, 149, 0, 0.42); background: rgba(255, 149, 0, 0.035); }

.script-summary {
  display: flex;
  gap: 12px;
  margin-bottom: 18px;
}

.script-summary span {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--paper);
  color: var(--muted);
  font-size: 11px;
}

.script-sections { display: grid; gap: 14px; }

.script-card {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--paper);
  box-shadow: 0 5px 20px var(--shadow-color);
}

.script-card-index {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 21px;
  border-right: 1px solid var(--line);
  background: var(--surface-subtle);
  color: var(--muted);
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
}

.script-card-body { padding: 18px; }
.script-card-head { display: grid; grid-template-columns: 1.2fr 1fr auto; gap: 12px; align-items: end; }
.script-card-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.script-card-grid .wide { grid-column: span 2; }

.script-field { display: grid; gap: 6px; }
.script-field span { color: var(--muted); font-size: 10px; }
.script-card textarea { min-height: 82px; }

.script-card-actions { display: flex; gap: 5px; align-items: center; }
.script-card-actions button {
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-subtle);
  color: var(--muted);
}
.script-card-actions button:hover { color: var(--ink); border-color: var(--control-border); }
.script-card-actions .delete-section:hover { color: #ff3b30; }

.section-meta-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; margin-top: 12px; }
.add-section-button { width: 100%; margin-top: 14px; border-style: dashed; }

@keyframes spin { to { transform: rotate(360deg); } }

:root[data-theme="dark"] .sticky-footer {
  background: color-mix(in srgb, var(--surface-raised) 88%, transparent);
}

@media (max-width: 1180px) {
  .workflow-steps span { padding-inline: 8px; }
  .workflow-header-copy { display: none; }
}

/* --- Project / content-unit creation model --- */
.wizard-step {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.wizard-step > legend {
  width: 100%;
  margin: 0 0 16px;
  color: var(--ink);
  font-size: 17px;
  font-weight: 600;
}
.content-step-legend {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.create-project-actions { display: flex; align-items: center; gap: 10px; }

.create-progress {
  display: grid;
  grid-template-columns: max-content 1fr max-content;
  align-items: center;
  gap: 14px;
  margin: -4px 0 28px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
}

.create-progress span {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.create-progress b {
  display: grid;
  place-items: center;
  width: 25px;
  height: 25px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface-subtle);
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
}

.create-progress i { height: 1px; background: var(--line); }
.create-progress span[data-active="true"] { color: var(--ink); }
.create-progress span[data-active="true"] b { border-color: var(--ink); background: var(--ink); color: var(--paper); }
.create-progress span[data-complete="true"] { color: var(--green); }
.create-progress span[data-complete="true"] b { border-color: var(--green); color: var(--green); }

.mode-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 26px;
}

.mode-option { display: block; cursor: pointer; }
.mode-option input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.mode-option > span {
  display: grid;
  gap: 5px;
  min-height: 88px;
  align-content: center;
  padding: 17px 18px;
  border: 1px solid var(--control-border);
  border-radius: var(--radius);
  background: var(--surface-raised);
  transition: border-color 150ms ease, box-shadow 150ms ease, background 150ms ease;
}
.mode-option strong { font-size: 14px; }
.mode-option small { color: var(--muted); font-size: 11px; line-height: 1.45; }
.mode-option:has(input:checked) > span {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 5%, var(--surface-raised));
  box-shadow: 0 0 0 3px var(--focus);
}

.section-caption {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 18px;
  margin: 0 0 14px;
  padding-top: 2px;
}
.section-caption strong { font-size: 13px; }
.section-caption span { color: var(--muted); font-size: 11px; }

.inheritance-note {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
  padding: 12px 14px;
  border: 1px solid color-mix(in srgb, var(--green) 28%, var(--line));
  border-radius: 10px;
  background: color-mix(in srgb, var(--green) 5%, var(--surface-raised));
}
.inheritance-note strong { color: var(--green); font-size: 11px; }
.inheritance-note span { overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.wizard-step .workflow-footer > div { display: flex; align-items: center; gap: 14px; }

/* --- Series content hub --- */
.contents-shell { width: min(1120px, calc(100vw - 84px)); }
.contents-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 28px;
  margin-bottom: 22px;
}
.contents-header h1 { margin: 5px 0 6px; font-size: 38px; letter-spacing: -0.04em; }
.contents-header p:last-child { margin: 0; color: var(--muted); font-size: 13px; }
.profile-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 24px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-subtle);
}
.profile-summary span { display: flex; align-items: baseline; gap: 7px; padding: 6px 9px; border-radius: 8px; background: var(--surface-raised); }
.profile-summary small { color: var(--muted); font-size: 9px; }
.profile-summary strong { font-size: 11px; font-weight: 600; }
.new-content-form {
  display: grid;
  gap: 16px;
  margin-bottom: 18px;
  padding: 22px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: 0 10px 30px var(--shadow-color);
}
.new-content-form > header { display: flex; justify-content: space-between; align-items: flex-start; }
.new-content-form > header div { display: grid; gap: 3px; }
.new-content-form > header span { color: var(--muted); font-size: 10px; }
.new-content-form > header button { width: 30px; height: 30px; border-radius: 50%; color: var(--muted); font-size: 18px; }
.new-content-form footer { display: flex; justify-content: flex-end; }
.content-units-grid { display: grid; gap: 10px; }
.content-unit-card {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) max-content;
  align-items: stretch;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: 0 5px 18px var(--shadow-color);
}
.content-unit-card[data-active="true"] { border-color: color-mix(in srgb, var(--accent) 36%, var(--line)); }
.content-unit-index { display: grid; place-items: center; border-right: 1px solid var(--line); background: var(--surface-subtle); color: var(--muted); font-family: "JetBrains Mono", monospace; font-size: 12px; }
.content-unit-main { min-width: 0; padding: 16px 18px; }
.content-unit-heading { display: flex; align-items: center; gap: 10px; }
.content-unit-heading strong { font-size: 15px; }
.content-unit-heading span { padding: 4px 7px; border-radius: var(--radius-pill); background: var(--surface-subtle); color: var(--muted); font-size: 9px; }
.content-unit-main p { max-width: 760px; margin: 7px 0; overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.content-unit-meta { display: flex; gap: 12px; color: var(--muted); font-family: "JetBrains Mono", monospace; font-size: 9px; }
.content-unit-actions { display: flex; align-items: center; gap: 7px; padding: 14px 16px; }
.delete-content { color: var(--muted); font-size: 11px; }
.delete-content:hover, .delete-content.is-armed { color: #ff3b30; }

@media (max-width: 760px) {
  .mode-options, .two-columns, .three-columns { grid-template-columns: 1fr; }
  .span-two { grid-column: span 1; }
  .content-unit-card { grid-template-columns: 42px minmax(0, 1fr); }
  .content-unit-actions { grid-column: 2; padding-top: 0; }
}

@media (max-width: 1180px) {
  .active-content-title { max-width: 120px; }
  .storyboard-view { grid-template-columns: 224px minmax(0, 1fr); }
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg, #f4f5f7);
}

.auth-gate[hidden] { display: none; }

.auth-card {
  width: min(420px, 100%);
  display: grid;
  gap: 16px;
  padding: 36px;
  border: 1px solid var(--line, #d9dee7);
  border-radius: 20px;
  background: var(--panel, #fff);
  box-shadow: 0 24px 70px rgb(15 23 42 / 12%);
}

.auth-card h1,
.auth-card p { margin: 0; }

.auth-card label {
  display: grid;
  gap: 7px;
  color: var(--muted, #667085);
  font-size: 13px;
}

.auth-card input {
  min-height: 44px;
  padding: 0 13px;
  border: 1px solid var(--line, #d9dee7);
  border-radius: 9px;
  color: inherit;
  background: var(--panel, #fff);
  font: inherit;
}

.auth-card .primary { min-height: 44px; }
.auth-mark { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 12px; }
.auth-error { color: #c83b3b; font-size: 13px; }
.text-button { border: 0; color: var(--accent, #2868d8); background: transparent; cursor: pointer; }
.session-badge { padding: 6px 10px; border-radius: 999px; color: var(--muted, #667085); background: var(--soft, #eef1f5); font-size: 12px; white-space: nowrap; }
