/* ==========================================================================
   Cartoon Studio — studio.css
   One stylesheet for the signed-in studio, public pages, auth and external review.
   Order: 1 Tokens · 2 Base · 3 Type · 4 Controls · 5 Feedback · 6 Surfaces ·
          7 Story-strip frames · 8 Dialogs/overlays · 9 App shell · 10 Screens ·
          11 Editor · 12 Media/player · 13 Responsive · 14 Preferences
   Specification tokens (section 4.2) are the source of every colour below.
   No inline styles, data: URIs or remote assets are used anywhere.
   ========================================================================== */

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

  --bg-app: #F7F8FA;
  --bg-surface: #FFFFFF;
  --bg-subtle: #F0F2F6;
  --bg-canvas: #141823;
  --canvas-raised: #1D2233;
  --canvas-line: #2C3350;

  --text: #202433;
  --text-2: #626979;
  --text-inverse: #FFFFFF;
  --text-inverse-2: #B9BFD0;

  --action: #5546D9;
  --action-hover: #4436B8;
  --action-press: #392E9C;
  --action-tint: #EFEDFC;

  --border: #E0E4EB;
  --border-control: #788394;
  --focus: #284BDB;

  --success: #17623C;
  --success-bg: #EAF6EE;
  --success-line: #C3E3D0;
  --warning: #7A4800;
  --warning-bg: #FFF4DB;
  --warning-line: #EFDCAA;
  --danger: #A02535;
  --danger-bg: #FFF0F2;
  --danger-line: #F1C6CC;
  --info: #1C4CA1;
  --info-bg: #EDF3FF;
  --info-line: #C9D9F6;

  --font-sans: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial,
    "Noto Sans", "PingFang SC", "PingFang HK", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC",
    "Noto Sans CJK TC", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-6: 24px;
  --s-8: 32px;
  --s-12: 48px;
  --s-16: 64px;

  --r-card: 12px;
  --r-control: 8px;
  --r-pop: 12px;

  --sidebar-w: 240px;
  --rail-w: 72px;
  --header-h: 64px;
  --stagenav-h: 48px;
  --control-h: 44px;
  --page-pad: 32px;
  --page-max: 1280px;
  --form-max: 840px;

  --dur-fast: 140ms;
  --dur-drawer: 220ms;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);

  --shadow-overlay: 0 16px 40px rgba(20, 24, 35, 0.18), 0 2px 8px rgba(20, 24, 35, 0.1);
}

/* 2 ── Base ─────────────────────────────────────────────────────────────── */
*,
*::before,
*::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: calc(var(--header-h) + 16px);
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg-app);
  color: var(--text);
  font: 400 16px/24px var(--font-sans);
  font-feature-settings: "cv11", "ss03";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-wrap: break-word;
}

[hidden] { display: none !important; }

img, svg, video, canvas, audio { max-width: 100%; }
img { height: auto; }

a {
  color: var(--action);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}
a:hover { color: var(--action-hover); text-decoration-thickness: 2px; }

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

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

hr { border: 0; border-top: 1px solid var(--border); margin: var(--s-6) 0; }

::selection { background: var(--action-tint); color: var(--text); }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  left: 12px; top: -80px;
  z-index: 1000;
  padding: 12px 16px;
  background: var(--action);
  color: #fff;
  font: 600 14px/20px var(--font-sans);
  border-radius: var(--r-control);
  text-decoration: none;
}
.skip-link:focus { top: 12px; color: #fff; }

/* 3 ── Type ─────────────────────────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 { margin: 0; color: var(--text); font-family: var(--font-sans); }
h1, .t-page { font-size: 32px; line-height: 40px; font-weight: 650; letter-spacing: -0.022em; }
h2, .t-panel { font-size: 24px; line-height: 32px; font-weight: 650; letter-spacing: -0.016em; }
h3, .t-sub { font-size: 18px; line-height: 26px; font-weight: 650; letter-spacing: -0.008em; }
h4, .t-body-strong { font-size: 16px; line-height: 24px; font-weight: 650; }
p { margin: 0; }
.t-small { font-size: 14px; line-height: 20px; }
.t-meta { font-size: 12px; line-height: 18px; }
.muted { color: var(--text-2); }
.strong { font-weight: 650; }
.tabular { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.clamp-3 { display: -webkit-box; -webkit-line-clamp: 3; line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.prose p + p { margin-top: var(--s-3); }
.prose { max-width: 68ch; }
.measure { max-width: 68ch; }
.pre-wrap { white-space: pre-wrap; }
code, kbd, samp { font-family: var(--font-mono); font-size: 0.9em; }
kbd {
  display: inline-block; min-width: 22px; padding: 1px 6px;
  text-align: center; font-size: 12px; line-height: 18px;
  background: var(--bg-surface); border: 1px solid var(--border-control); border-bottom-width: 2px;
  border-radius: 6px; color: var(--text);
}

/* Layout utilities (small, intentional) */
.stack { display: flex; flex-direction: column; gap: var(--gap, 16px); min-width: 0; }
.stack--tight { --gap: 8px; }
.stack--loose { --gap: 24px; }
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--gap, 12px); min-width: 0; }
.cluster--end { justify-content: flex-end; }
.cluster--between { justify-content: space-between; }
.cluster--top { align-items: flex-start; }
.grow { flex: 1 1 auto; min-width: 0; }
.shrink-0 { flex: none; }

/* 4 ── Controls ─────────────────────────────────────────────────────────── */
.icon {
  width: 20px; height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: middle;
}
.icon--sm { width: 16px; height: 16px; }
.icon--lg { width: 24px; height: 24px; }
.icon--xl { width: 32px; height: 32px; }

.btn {
  --btn-bg: var(--bg-surface);
  --btn-fg: var(--text);
  --btn-bd: var(--border-control);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--control-h);
  padding: 0 16px;
  font: 600 14px/20px var(--font-sans);
  color: var(--btn-fg);
  background: var(--btn-bg);
  border: 1px solid var(--btn-bd);
  border-radius: var(--r-control);
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease);
}
.btn:hover { --btn-bg: var(--bg-subtle); color: var(--btn-fg); text-decoration: none; }
.btn:active { --btn-bg: #E5E8EF; }
.btn--primary { --btn-bg: var(--action); --btn-fg: #fff; --btn-bd: var(--action); }
.btn--primary:hover { --btn-bg: var(--action-hover); --btn-bd: var(--action-hover); color: #fff; }
.btn--primary:active { --btn-bg: var(--action-press); --btn-bd: var(--action-press); }
.btn--quiet { --btn-bg: transparent; --btn-fg: var(--action); --btn-bd: transparent; }
.btn--quiet:hover { --btn-bg: var(--action-tint); color: var(--action-hover); }
.btn--plain { --btn-bg: transparent; --btn-fg: var(--text); --btn-bd: transparent; }
.btn--plain:hover { --btn-bg: var(--bg-subtle); }
.btn--danger { --btn-fg: var(--danger); --btn-bd: var(--danger); }
.btn--danger:hover { --btn-bg: var(--danger-bg); color: var(--danger); }
.btn--danger-solid { --btn-bg: var(--danger); --btn-fg: #fff; --btn-bd: var(--danger); }
.btn--danger-solid:hover { --btn-bg: #861E2C; --btn-bd: #861E2C; color: #fff; }
.btn--sm { min-height: 36px; padding: 0 12px; }
.btn--icon { width: var(--control-h); padding: 0; }
.btn--icon.btn--sm { width: 36px; }
.btn--block { width: 100%; }
.btn--wrap { white-space: normal; text-align: left; }
.btn[disabled],
.btn[aria-disabled="true"] {
  --btn-bg: var(--bg-subtle);
  --btn-fg: #5B6272;
  --btn-bd: var(--border);
  cursor: not-allowed;
  text-decoration: none;
}
.btn--primary[disabled],
.btn--primary[aria-disabled="true"] { --btn-bg: #E3E1F6; --btn-fg: #4B4A66; --btn-bd: #D3D0F0; }
.btn[data-busy="true"] { cursor: progress; }

.link-btn {
  display: inline; padding: 0; margin: 0; border: 0; background: none;
  color: var(--action); font: inherit; font-weight: 600;
  text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; cursor: pointer;
}
.link-btn:hover { color: var(--action-hover); text-decoration-thickness: 2px; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.label { font: 600 14px/20px var(--font-sans); color: var(--text); }
.label .req { color: var(--danger); font-weight: 600; margin-left: 2px; }
.label .opt { color: var(--text-2); font-weight: 400; margin-left: 6px; }
.hint { font-size: 14px; line-height: 20px; color: var(--text-2); }
/* AI Detect sits under its field as a small quiet action, and the row disappears when the action is hidden. */
.ai-detect:has(> button[hidden]) { display: none; }
.error {
  display: flex; gap: 6px; align-items: flex-start;
  font: 500 14px/20px var(--font-sans); color: var(--danger);
}
.error .icon { margin-top: 2px; width: 16px; height: 16px; }

.input, .select, .textarea {
  display: block; width: 100%;
  min-height: var(--control-h);
  padding: 10px 12px;
  font: 400 14px/20px var(--font-sans);
  color: var(--text);
  background: var(--bg-surface);
  border: 1px solid var(--border-control);
  border-radius: var(--r-control);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.input::placeholder, .textarea::placeholder { color: #6B7283; opacity: 1; }
.input:hover, .select:hover, .textarea:hover { border-color: #5E6879; }
.input:focus, .select:focus, .textarea:focus {
  outline: 3px solid var(--focus);
  outline-offset: 1px;
  border-color: var(--focus);
}
.textarea { min-height: 112px; resize: vertical; line-height: 22px; }
.textarea--tall { min-height: 280px; }
.textarea--mono { font-family: var(--font-mono); font-size: 13px; line-height: 20px; }
.input[aria-invalid="true"], .select[aria-invalid="true"], .textarea[aria-invalid="true"] {
  border-color: var(--danger);
  box-shadow: inset 0 0 0 1px var(--danger);
}
.input[readonly], .textarea[readonly] { background: var(--bg-subtle); }
.input:disabled, .select:disabled, .textarea:disabled {
  background: var(--bg-subtle); color: #5B6272; border-color: var(--border); cursor: not-allowed;
}
.input--num { font-variant-numeric: tabular-nums; }
.input--sm, .select--sm { min-height: 36px; padding-top: 6px; padding-bottom: 6px; }
input[type="file"].input { padding: 8px 12px; }
input[type="file"].input::file-selector-button {
  margin-right: 12px; padding: 6px 12px; min-height: 28px;
  font: 600 13px/18px var(--font-sans); color: var(--text);
  background: var(--bg-subtle); border: 1px solid var(--border-control); border-radius: 6px; cursor: pointer;
}
.input[type="date"], .input[type="datetime-local"], .input[type="time"] { min-width: 0; }

.select-wrap { position: relative; display: block; }
.select-wrap::after {
  content: ""; position: absolute; right: 15px; top: 50%;
  width: 7px; height: 7px;
  border-right: 2px solid var(--text-2); border-bottom: 2px solid var(--text-2);
  transform: translateY(-72%) rotate(45deg);
  pointer-events: none;
}
.select { appearance: none; -webkit-appearance: none; padding-right: 38px; text-overflow: ellipsis; }

.check {
  display: flex; align-items: flex-start; gap: 12px;
  min-height: var(--control-h);
  padding: 10px 0;
  cursor: pointer;
}
.check input[type="checkbox"], .check input[type="radio"] {
  flex: none; width: 20px; height: 20px; margin: 2px 0 0;
  accent-color: var(--action);
  cursor: pointer;
}
.check__text { display: flex; flex-direction: column; gap: 2px; font-size: 14px; line-height: 22px; }
.check__text small { font-size: 14px; line-height: 20px; color: var(--text-2); }

.fieldset { border: 0; margin: 0; padding: 0; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.fieldset > legend { padding: 0; margin-bottom: 4px; font: 600 14px/20px var(--font-sans); }
.fieldset > legend .req { margin-left: 2px; color: var(--danger); }
.fieldset > legend .opt { margin-left: 6px; color: var(--text-2); font-weight: 400; }
.choice-row { display: flex; flex-wrap: wrap; gap: 8px; }
.choice {
  position: relative; display: inline-flex; align-items: center; gap: 8px;
  min-height: var(--control-h); padding: 0 16px;
  border: 1px solid var(--border-control); border-radius: var(--r-control);
  background: var(--bg-surface);
  font: 600 14px/20px var(--font-sans); cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.choice:hover { background: var(--bg-subtle); }
.choice input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.choice:has(input:checked) { background: var(--action-tint); border-color: var(--action); color: var(--action-hover); box-shadow: inset 0 0 0 1px var(--action); }
.choice:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.choice:has(input:disabled) { background: var(--bg-subtle); color: #5B6272; border-color: var(--border); cursor: not-allowed; }
.choice small { font-weight: 400; color: var(--text-2); }

.form-grid { display: grid; gap: var(--s-4) var(--s-6); grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid > .full { grid-column: 1 / -1; }
.form-actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; padding-top: var(--s-2); }
.form-narrow { max-width: var(--form-max); }

.error-summary {
  padding: 16px; border-radius: var(--r-control);
  background: var(--danger-bg); border: 1px solid var(--danger-line); color: var(--danger);
}
.error-summary:focus { outline: 3px solid var(--focus); outline-offset: 2px; }
.error-summary h3 { font-size: 16px; line-height: 24px; color: var(--danger); }
.error-summary ul { margin: 8px 0 0; padding-left: 20px; }
.error-summary a { color: var(--danger); font-weight: 600; }

/* Tabs (buttons with role=tab, or links) */
.tabs {
  display: flex; gap: 4px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto; overflow-y: hidden; scrollbar-width: thin;
}
.tab {
  position: relative;
  display: inline-flex; align-items: center; gap: 8px;
  min-height: var(--control-h); padding: 0 16px; margin-bottom: -1px;
  background: none; border: 0; border-bottom: 2px solid transparent; border-radius: 0;
  font: 600 14px/20px var(--font-sans); color: var(--text-2);
  white-space: nowrap; text-decoration: none; cursor: pointer;
  transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab[aria-selected="true"], .tab[aria-current="page"], .tab[aria-current="true"] {
  color: var(--action); border-bottom-color: var(--action);
}
.tab:focus-visible { outline-offset: -3px; border-radius: 6px; }
.tab .count {
  min-width: 22px; padding: 0 6px; text-align: center;
  font-size: 12px; line-height: 20px; font-weight: 600;
  color: var(--text-2); background: var(--bg-subtle); border-radius: 999px;
}

.segmented {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--bg-subtle); border-radius: var(--r-control);
}
.segmented button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; min-width: 44px; padding: 0 12px;
  border: 0; border-radius: 6px; background: transparent;
  font: 600 14px/20px var(--font-sans); color: var(--text-2);
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-pressed="true"] { background: var(--bg-surface); color: var(--action); box-shadow: 0 1px 2px rgba(20, 24, 35, 0.12); }

/* 5 ── Feedback ─────────────────────────────────────────────────────────── */
.alert {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px 16px;
  border: 1px solid var(--info-line); border-radius: var(--r-control);
  background: var(--info-bg); color: var(--info);
  font-size: 14px; line-height: 20px;
}
.alert > .icon { margin-top: 0; }
.alert__body { display: flex; flex-direction: column; gap: 4px; min-width: 0; flex: 1; }
.alert__title { font-weight: 650; }
.alert__body p + p { margin-top: 4px; }
.alert a, .alert .link-btn { color: inherit; font-weight: 650; }
.alert--success { background: var(--success-bg); border-color: var(--success-line); color: var(--success); }
.alert--warning { background: var(--warning-bg); border-color: var(--warning-line); color: var(--warning); }
.alert--danger { background: var(--danger-bg); border-color: var(--danger-line); color: var(--danger); }
.alert--quiet { background: var(--bg-subtle); border-color: var(--border); color: var(--text); }
.alert__actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 24px; padding: 2px 10px;
  border-radius: 999px; border: 1px solid var(--border);
  background: var(--bg-subtle); color: var(--text);
  font: 600 12px/18px var(--font-sans);
  white-space: nowrap;
}
.badge .icon { width: 14px; height: 14px; }
.badge--success { background: var(--success-bg); border-color: var(--success-line); color: var(--success); }
.badge--warning { background: var(--warning-bg); border-color: var(--warning-line); color: var(--warning); }
.badge--danger { background: var(--danger-bg); border-color: var(--danger-line); color: var(--danger); }
.badge--info { background: var(--info-bg); border-color: var(--info-line); color: var(--info); }
.badge--action { background: var(--action-tint); border-color: #D8D3F7; color: var(--action-hover); }
.badge--plain { background: transparent; }

.spinner {
  width: 18px; height: 18px; flex: none;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: cs-spin 800ms linear infinite;
}
@keyframes cs-spin { to { transform: rotate(360deg); } }

.skeleton {
  display: block; min-height: 16px; border-radius: 6px;
  background: linear-gradient(90deg, var(--bg-subtle) 0%, #E7EAF0 50%, var(--bg-subtle) 100%);
  background-size: 200% 100%;
  animation: cs-shimmer 1.4s ease-in-out infinite;
}
@keyframes cs-shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* 6 ── Surfaces ─────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  min-width: 0;
}
.card--pad { padding: var(--s-6); }
.card--subtle { background: var(--bg-subtle); border-color: transparent; }
.card__head {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 24px; border-bottom: 1px solid var(--border);
}
.card__head h2, .card__head h3 { font-size: 18px; line-height: 26px; }
.card__body { padding: 24px; }
.card__foot { padding: 16px 24px; border-top: 1px solid var(--border); }

.divided > * + * { border-top: 1px solid var(--border); }

.table-wrap { position: relative; overflow-x: auto; background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--r-card); }
.table { width: 100%; border-collapse: collapse; font-size: 14px; line-height: 20px; }
.table caption { text-align: left; padding: 12px 16px; font-weight: 650; }
.table th {
  padding: 10px 16px; text-align: left; white-space: nowrap;
  font-weight: 600; color: var(--text-2); background: var(--bg-subtle);
}
.table td { padding: 12px 16px; border-top: 1px solid var(--border); vertical-align: top; }
.table tbody tr:hover td { background: #FAFBFD; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table .row-title { font-weight: 650; color: var(--text); }
.table .row-title a { color: inherit; text-decoration: none; }
.table .row-title a:hover { color: var(--action); text-decoration: underline; }

.empty {
  display: flex; flex-direction: column; align-items: flex-start; gap: 12px;
  padding: 32px;
  background: var(--bg-surface);
  border: 1px dashed #B7BECB; border-radius: var(--r-card);
}
.empty h2, .empty h3 { font-size: 18px; line-height: 26px; }
.empty p { color: var(--text-2); max-width: 60ch; }
.empty__actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 4px; }
.empty--compact { padding: 20px; gap: 8px; }

.chip-list { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; margin: 0; padding: 0; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 32px; padding: 0 6px 0 12px;
  background: var(--action-tint); color: var(--action-hover);
  border: 1px solid #D8D3F7; border-radius: 999px;
  font: 600 13px/18px var(--font-sans);
}
.chip button {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border: 0; border-radius: 50%; background: transparent; color: inherit;
}
.chip button:hover { background: #E1DDFA; }

.kv { display: grid; grid-template-columns: minmax(120px, 200px) 1fr; gap: 8px 24px; margin: 0; font-size: 14px; line-height: 20px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 599.98px) {
  .kv, .kv--tight { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .kv dt { margin-top: 12px; font-size: 13px; line-height: 18px; }
  .kv dt:first-child { margin-top: 0; }
}
.divider { border: 0; border-top: 1px solid var(--border); margin: 0; }

/* 7 ── Story-strip frames ───────────────────────────────────────────────── */
/* The recurring motif: a frame on the dark canvas with a safe-area guide.
   Empty frames are honest placeholders (typography only); real artwork replaces them. */
.frame {
  --ratio: 9 / 16;
  position: relative;
  display: block;
  aspect-ratio: var(--ratio);
  background: var(--bg-canvas);
  color: var(--text-inverse);
  border-radius: 10px;
  overflow: hidden;
  isolation: isolate;
  min-width: 0;
}
.frame::after {
  content: ""; position: absolute; inset: 7%;
  border: 1px dashed rgba(255, 255, 255, 0.16); border-radius: 6px;
  pointer-events: none; z-index: 2;
}
.frame--art::after { border-color: rgba(255, 255, 255, 0.28); opacity: 0; transition: opacity var(--dur-fast) var(--ease); }
.frame--guides::after { opacity: 1; }
.frame__img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 1; }
.frame__img--contain { object-fit: contain; }
.frame__text {
  position: absolute; inset: 0; z-index: 1;
  display: flex; flex-direction: column; justify-content: flex-end; gap: 4px;
  padding: 14% 12%;
  color: var(--text-inverse);
}
.frame__text strong { font-size: 14px; line-height: 18px; font-weight: 650; letter-spacing: -0.005em; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; line-clamp: 3; -webkit-box-orient: vertical; }
.frame__text span { font-size: 12px; line-height: 16px; color: var(--text-inverse-2); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; }
/* An empty frame in a card or the home hero is a quiet outline, not a black block: dark staging is for real artwork. */
.mcard__media:has(> .frame:not(.frame--art)),
.ov-continue__stage:has(> .frame:not(.frame--art)) { background: var(--bg-subtle); }
.mcard__media > .frame:not(.frame--art),
.ov-continue__stage > .frame:not(.frame--art) { background: var(--bg-surface); color: var(--text); box-shadow: inset 0 0 0 1px var(--border); }
.mcard__media > .frame:not(.frame--art)::after,
.ov-continue__stage > .frame:not(.frame--art)::after { border-color: var(--border); }
.mcard__media > .frame:not(.frame--art) .frame__text,
.ov-continue__stage > .frame:not(.frame--art) .frame__text { color: var(--text); }
.mcard__media > .frame:not(.frame--art) .frame__text span,
.ov-continue__stage > .frame:not(.frame--art) .frame__text span { color: var(--text-2); }
.frame__num, .frame__dur {
  position: absolute; z-index: 3;
  padding: 1px 6px; border-radius: 4px;
  font: 600 11px/16px var(--font-sans); font-variant-numeric: tabular-nums;
  color: var(--text-inverse); background: rgba(20, 24, 35, 0.72);
}
.frame__num { left: 6px; top: 6px; }
.frame__dur { right: 6px; bottom: 6px; }
.frame__badge { position: absolute; z-index: 3; right: 6px; top: 6px; }
.frame--landscape { --ratio: 16 / 9; }
.frame--square { --ratio: 1 / 1; }
.frame--four-five { --ratio: 4 / 5; }
.frame--cover { --ratio: 16 / 10; }

.strip { display: flex; gap: 8px; align-items: stretch; min-width: 0; }
.strip > .frame { flex: 1 1 0; min-width: 0; }

/* 8 ── Dialogs / overlays ───────────────────────────────────────────────── */
dialog.dialog {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0; margin: auto;
  color: var(--text); background: var(--bg-surface);
  border: 0; border-radius: var(--r-pop);
  box-shadow: var(--shadow-overlay);
  overflow: hidden;
}
dialog.dialog[open] { display: flex; flex-direction: column; animation: cs-pop var(--dur-drawer) var(--ease); }
dialog.dialog::backdrop { background: rgba(20, 24, 35, 0.56); }
dialog.dialog--wide { width: min(760px, calc(100vw - 24px)); }
dialog.dialog--narrow { width: min(440px, calc(100vw - 24px)); }
.dialog__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 20px 24px 12px; }
.dialog__head h2 { font-size: 20px; line-height: 28px; }
.dialog__body { padding: 4px 24px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; min-height: 0; }
.dialog__foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 12px; padding: 16px 24px; background: var(--bg-subtle); border-top: 1px solid var(--border); }
@keyframes cs-pop { from { opacity: 0; transform: translateY(8px) scale(0.985); } to { opacity: 1; transform: none; } }

/* Long forms become full-height drawers on small/short screens; simple confirmations stay compact. */
@media (max-width: 767.98px), (max-height: 500px) {
  dialog.dialog--drawer {
    inset: var(--dialog-visible-top, 0px) 0 auto; margin: 0;
    width: 100%; max-width: none; height: var(--dialog-visible-height, 100dvh);
    max-height: var(--dialog-visible-height, 100dvh); border-radius: 0;
  }
  dialog.dialog--drawer[open] { animation: none; }
  .dialog--drawer .dialog__head { flex: none; padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 12px; border-bottom: 1px solid var(--border); }
  .dialog--drawer .dialog__head h2 { font-size: 18px; line-height: 24px; }
  .dialog--drawer .dialog__head > button { flex: none; width: 44px; min-height: 44px; }
  .dialog--drawer .dialog__body { flex: 1; padding: 16px 16px calc(16px + env(safe-area-inset-bottom, 0px)); overscroll-behavior: contain; scroll-padding-block: 16px var(--dialog-action-clearance, 112px); }
  .dialog--drawer .dialog__body > .lib-create { flex: 1 0 auto; }
  .dialog--drawer .dialog__foot { flex: none; padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px)); }
  .dialog--drawer :is(input, select, textarea) { font-size: 16px; }
  .dialog--drawer .btn { min-height: 44px; }
  .dialog--drawer .lib-create__actions { margin-top: auto; }
  .dialog--drawer .ai-character-setup > .form-actions { bottom: -16px; padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
}

.toasts {
  position: fixed; z-index: 900; right: 16px; bottom: 16px;
  display: flex; flex-direction: column; gap: 8px;
  width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px 12px 12px 16px;
  background: var(--bg-canvas); color: var(--text-inverse);
  border-radius: var(--r-control); box-shadow: var(--shadow-overlay);
  font-size: 14px; line-height: 20px;
  animation: cs-toast var(--dur-drawer) var(--ease);
}
.toast--danger { background: #5E1520; }
.toast .icon { margin-top: 0; }
.toast__body { flex: 1; min-width: 0; }
.toast button { color: var(--text-inverse); background: transparent; border: 0; width: 32px; height: 32px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; margin: -4px 0; }
.toast button:hover { background: rgba(255, 255, 255, 0.14); }
@keyframes cs-toast { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* Preferences (kept here so every later section inherits them) */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  .spinner { animation: none; border-right-color: currentColor; opacity: 0.6; }
  .skeleton { animation: none; }
}
@media (forced-colors: active) {
  .btn, .input, .select, .textarea, .choice, .badge, .card, .alert, .table-wrap, .frame { border: 1px solid CanvasText; }
  .btn--primary { background: Highlight; color: HighlightText; }
  :focus-visible { outline-color: Highlight; }
}
@media (pointer: coarse), (max-width: 767px) {
  .btn--sm { min-height: var(--control-h); }
  .btn--icon.btn--sm { width: var(--control-h); }
  .input--sm, .select--sm { min-height: var(--control-h); }
  .input, .select, .textarea { font-size: 16px; line-height: 22px; }
}



/* 9 ── Brand ────────────────────────────────────────────────────────────── */
.wordmark {
  display: inline-flex; align-items: center; gap: 10px;
  color: var(--text); text-decoration: none;
  font: 650 16px/24px var(--font-sans); letter-spacing: -0.012em;
}
.wordmark:hover { color: var(--text); text-decoration: none; }
.wordmark__full { display: block; width: 180px; height: auto; max-width: 100%; }
.wordmark__symbol { display: none; width: 32px; height: 32px; }

/* 10 ── Shared layout layer (used by every signed-in screen) ───────────── */
.page { width: 100%; max-width: var(--page-max); margin: 0 auto; padding: var(--page-pad); }
.page-head {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between;
  gap: 16px 24px; margin-bottom: 24px;
}
.page-head__text { flex: 1 1 360px; min-width: 0; }
.page-head__desc { margin-top: 4px; color: var(--text-2); max-width: 68ch; }
.page-head__meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 8px; }
.page-head__actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.back-link {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: var(--control-h); margin: 0 0 2px -10px; padding: 0 10px;
  border-radius: var(--r-control);
  color: var(--text-2); font: 600 14px/20px var(--font-sans); text-decoration: none;
}
.back-link:hover { color: var(--text); background: var(--bg-subtle); text-decoration: none; }
.section { margin-top: 32px; }
.section:first-child { margin-top: 0; }
.section__head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin-bottom: 12px; }
.section__head h2 { font-size: 18px; line-height: 26px; }
.section__head p { color: var(--text-2); font-size: 14px; line-height: 20px; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 16px; }
.toolbar__spacer { flex: 1 1 auto; }
.search { position: relative; flex: 1 1 260px; max-width: 420px; min-width: 200px; }
.search > .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-2); pointer-events: none; }
.search .input { padding-left: 40px; }
.filter-select { flex: 0 1 200px; min-width: 150px; }

.cards { display: grid; gap: 24px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.cards--sm { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.cards--lg { grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); }

.mcard {
  position: relative; display: flex; flex-direction: column; min-width: 0;
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--r-card);
  overflow: hidden;
  transition: border-color var(--dur-fast) var(--ease);
}
.mcard:hover { border-color: #B3BAC8; }
.mcard:focus-within { border-color: var(--focus); }
.mcard__media { position: relative; aspect-ratio: 16 / 10; background: var(--bg-canvas); overflow: hidden; }
.mcard__media > .frame { position: absolute; top: 7%; bottom: 7%; left: 50%; transform: translateX(-50%); height: 86%; width: auto; }
.mcard__media > .frame--fill { inset: 0; transform: none; height: 100%; width: 100%; border-radius: 0; }
.mcard__media > .frame--fill::after { display: none; }
.mcard__media > .mcard__media-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.mcard__media > .mcard__media-img--contain { object-fit: contain; }
.mcard__body { display: flex; flex-direction: column; gap: 8px; padding: 16px; flex: 1; min-width: 0; }
.mcard__title { font: 650 16px/24px var(--font-sans); letter-spacing: -0.006em; overflow-wrap: anywhere; }
.mcard__title a { color: inherit; text-decoration: none; }
.mcard__title a::after { content: ""; position: absolute; inset: 0; z-index: 0; }
.mcard__title a:hover { color: var(--action-hover); text-decoration: underline; }
.mcard__title a:focus-visible { outline: none; }
.mcard__title a:focus-visible::after { outline: 3px solid var(--focus); outline-offset: -3px; border-radius: var(--r-card); }
.mcard__meta { display: flex; flex-wrap: wrap; gap: 2px 12px; font-size: 14px; line-height: 20px; color: var(--text-2); }
.mcard__foot { position: relative; z-index: 1; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 0 16px 16px; }
.mcard__next { display: flex; align-items: center; gap: 6px; font-size: 14px; line-height: 20px; font-weight: 600; color: var(--action-hover); min-width: 0; }
.mcard--archived { opacity: 0.78; }
.mcard--archived .mcard__media { filter: grayscale(0.7); }
.mcard__select { position: absolute; z-index: 2; left: 8px; top: 8px; background: var(--bg-surface); border-radius: 8px; padding: 0 8px; }

.with-aside { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 32px; align-items: start; }
.aside-panel { position: sticky; top: calc(var(--header-h) + 16px); }

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; }
.stat { display: flex; flex-direction: column; gap: 2px; padding: 16px; background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--r-card); }
.stat__value { font: 650 28px/36px var(--font-sans); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat__label { font-size: 14px; line-height: 20px; color: var(--text-2); }

.list-rows { list-style: none; margin: 0; padding: 0; background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--r-card); }
.list-rows > li { display: flex; align-items: center; gap: 16px; padding: 12px 16px; min-width: 0; }
.list-rows > li + li { border-top: 1px solid var(--border); }
.list-rows .row-main { flex: 1; min-width: 0; }
.list-rows .row-title { font-weight: 650; overflow-wrap: anywhere; }
.list-rows .row-sub { font-size: 14px; line-height: 20px; color: var(--text-2); }

.tag-row { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; }
.swatch { display: inline-block; width: 20px; height: 20px; border-radius: 6px; border: 1px solid rgba(20, 24, 35, 0.2); vertical-align: middle; }

/* 11 ── App shell ───────────────────────────────────────────────────────── */
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.app-boot { grid-column: 1 / -1; display: flex; align-items: center; justify-content: center; gap: 12px; min-height: 60vh; color: var(--text-2); }

.app-side {
  position: sticky; top: 0; z-index: 40;
  display: flex; flex-direction: column; gap: 16px;
  height: 100vh; height: 100dvh;
  padding: 16px 12px;
  background: var(--bg-surface); border-right: 1px solid var(--border);
  overflow-y: auto; overscroll-behavior: contain;
}
.app-side:focus { outline: none; }
.app-side__top { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 40px; padding: 0 4px; }
.app-side__close { display: none; }
.ws-switch {
  width: 100%; justify-content: flex-start; text-align: left; gap: 10px;
  min-height: 52px; padding: 6px 10px;
  background: var(--bg-app); border: 1px solid var(--border);
}
.ws-switch:hover { background: var(--bg-subtle); }
.ws__mark {
  display: grid; place-items: center; flex: none; width: 32px; height: 32px;
  border-radius: 8px; background: var(--bg-canvas); color: #fff;
  font: 650 14px/1 var(--font-sans);
}
.ws__text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.ws__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 650 14px/20px var(--font-sans); }
.ws__role { font: 400 12px/18px var(--font-sans); color: var(--text-2); }
.app-side__brand { gap: 4px; }
.app-side__label { font: 600 12px/18px var(--font-sans); color: var(--text-2); }

.app-nav ul { display: flex; flex-direction: column; gap: 2px; margin: 0; padding: 0; list-style: none; }
.app-nav--bottom { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }
.app-nav__item {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  min-height: var(--control-h); padding: 0 12px;
  border-radius: var(--r-control);
  color: var(--text); font: 600 14px/20px var(--font-sans); text-decoration: none;
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.app-nav__item:hover { background: var(--bg-subtle); color: var(--text); text-decoration: none; }
.app-nav__item[aria-current="page"] { background: var(--action-tint); color: var(--action-hover); }
.app-nav__label { flex: 1; min-width: 0; }
.app-nav__count {
  min-width: 22px; padding: 0 6px; border-radius: 999px;
  background: var(--action); color: #fff; text-align: center;
  font: 650 12px/22px var(--font-sans); font-variant-numeric: tabular-nums;
}

.app-main { display: flex; flex-direction: column; min-width: 0; min-height: 100vh; }
.app-header {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  height: var(--header-h); padding: 0 var(--page-pad);
  background: var(--bg-app); border-bottom: 1px solid var(--border);
}
.app-header__spacer { flex: 1 1 auto; }
.app-nav-toggle { display: none; }
.search-pill {
  display: flex; align-items: center; gap: 10px;
  flex: 0 1 520px; min-width: 0; min-height: var(--control-h); padding: 0 12px;
  background: var(--bg-surface); color: var(--text-2);
  border: 1px solid var(--border-control); border-radius: var(--r-control);
  font: 400 14px/20px var(--font-sans); text-align: left;
  transition: border-color var(--dur-fast) var(--ease);
}
.search-pill:hover { border-color: #5E6879; color: var(--text); }
.search-pill__text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-pill__kbd { flex: none; font-size: 12px; }
.app-actions { display: flex; align-items: center; gap: 4px; }
.bell { position: relative; }
.bell__count {
  position: absolute; top: 3px; right: 1px;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: var(--action); color: #fff; text-align: center;
  font: 700 11px/18px var(--font-sans); font-variant-numeric: tabular-nums;
}
.user-btn { padding: 0; }
.avatar {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%;
  background: var(--action-tint); color: var(--action-hover); border: 1px solid #D8D3F7;
  font: 650 14px/1 var(--font-sans);
}
.main { flex: 1; min-width: 0; }
.main:focus, .main h1:focus, h1[tabindex="-1"]:focus { outline: none; }
.skeleton--title { height: 40px; width: min(420px, 60%); }
.skeleton--block { height: 120px; width: 100%; border-radius: var(--r-card); }
.app-scrim { display: none; }

/* Editor mode: 72px rail, no global header (the editor supplies its own) */
body[data-shell="editor"] .app-header { display: none; }
@media (min-width: 1024px) {
  body[data-shell="editor"] .app { grid-template-columns: var(--rail-w) minmax(0, 1fr); }
  body[data-shell="editor"] .app-side { align-items: stretch; padding: 12px 8px; }
  body[data-shell="editor"] .app-side__ws,
  body[data-shell="editor"] .app-side__brand { display: none; }
  body[data-shell="editor"] .app-side__top { justify-content: center; padding: 0; }
  body[data-shell="editor"] .wordmark__full { display: none; }
  body[data-shell="editor"] .wordmark__symbol { display: block; }
  body[data-shell="editor"] .app-nav__label {
    position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
    clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
  }
  body[data-shell="editor"] .app-nav__item { justify-content: center; padding: 0; }
  body[data-shell="editor"] .app-nav__count { position: absolute; top: 4px; right: 4px; min-width: 18px; font-size: 11px; line-height: 18px; padding: 0 4px; }
}

/* 12 ── Popovers, menus, notifications, search palette ─────────────────── */
.popover {
  position: fixed; z-index: 80;
  min-width: 220px; max-width: min(400px, calc(100vw - 16px));
  background: var(--bg-surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--r-pop);
  box-shadow: var(--shadow-overlay);
  animation: cs-pop var(--dur-fast) var(--ease);
}
.popover--menu { padding: 6px; }
.popover--panel { width: 400px; max-height: min(72vh, 580px); overflow: auto; padding: 0; }
.menu__list { display: flex; flex-direction: column; min-width: 220px; }
.menu__item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  min-height: var(--control-h); padding: 0 12px;
  background: none; border: 0; border-radius: var(--r-control);
  color: var(--text); font: 600 14px/20px var(--font-sans); text-align: left; text-decoration: none; cursor: pointer;
}
.menu__item:hover, .menu__item:focus-visible { background: var(--bg-subtle); color: var(--text); text-decoration: none; }
.menu__item:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; }
.menu__item[aria-disabled="true"] { color: #5B6272; cursor: not-allowed; }
.menu__item--danger { color: var(--danger); }
.menu__label { flex: 1; min-width: 0; }
.menu__hint { color: var(--text-2); font: 400 12px/18px var(--font-sans); }
.menu__check { color: var(--action); }
.menu__sep { height: 1px; margin: 6px 4px; background: var(--border); }
.menu__heading { padding: 8px 12px 4px; color: var(--text-2); font: 600 12px/18px var(--font-sans); overflow-wrap: anywhere; }
.menu__form { margin: 0; }

.pop-empty { display: flex; flex-direction: column; gap: 4px; padding: 20px; }
.notifs__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.notifs__list { margin: 0; padding: 0; list-style: none; }
.notif { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 12px 16px; }
.notif + .notif { border-top: 1px solid var(--border); }
.notif--unread { background: var(--action-tint); }
.notif__main { min-width: 0; }
.notif__title { font-weight: 650; overflow-wrap: anywhere; }
.notif__actions { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; flex: none; }
.notifs__foot { padding: 12px 16px; border-top: 1px solid var(--border); }
.notifs__queue .notifs__list { max-height: min(40vh, 360px); overflow-y: auto; }
.notifs__queue .notif > .btn { flex: none; min-height: 44px; }
.notifs__queue .notif__main p + p { margin-top: 4px; }
.bell--active .bell__count { background: var(--action); color: var(--text-inverse); }
.notifs__queue .notifs__head { flex-wrap: wrap; }

dialog.dialog--palette { margin: 10vh auto auto; }
.palette__input { min-height: 48px; font-size: 16px; }
.palette__list { max-height: min(50vh, 420px); margin: 0; padding: 0; overflow: auto; list-style: none; }
.palette__item {
  display: grid; grid-template-columns: 20px minmax(0, 1.4fr) minmax(0, 1fr) auto; align-items: center; gap: 12px;
  min-height: var(--control-h); padding: 4px 12px; border-radius: var(--r-control); cursor: pointer;
}
.palette__item.is-active { background: var(--action-tint); box-shadow: inset 0 0 0 1px var(--action); }
.palette__title { font-weight: 600; }
.palette__sub { color: var(--text-2); font-size: 14px; }
.palette__empty { padding: 16px 12px; color: var(--text-2); }

/* 13 ── Shared widgets used by core helpers ─────────────────────────────── */
.save-indicator { display: inline-flex; align-items: center; gap: 6px; min-height: 24px; color: var(--text-2); font: 500 13px/18px var(--font-sans); }
.save-indicator[data-state="dirty"] { color: var(--warning); }
.save-indicator[data-state="saved"] { color: var(--success); }
.save-indicator[data-state="error"], .save-indicator[data-state="conflict"] { color: var(--danger); }
.save-indicator[data-state="saving"] .icon { animation: cs-spin 900ms linear infinite; }
.save-indicator__icon:empty { display: none; }

.tabset > .tabpanel { padding-top: 24px; }
.tabpanel:focus-visible { outline-offset: 6px; }

.form { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.form-alerts { display: flex; flex-direction: column; gap: 12px; }
.form-alerts:empty { display: none; }
.form-alerts > div:empty { display: none; }
.issue-list { margin: 8px 0 0; padding-left: 20px; }
.choice.is-checked { background: var(--action-tint); border-color: var(--action); color: var(--action-hover); box-shadow: inset 0 0 0 1px var(--action); }
.choice.is-focus { outline: 3px solid var(--focus); outline-offset: 2px; }
.asset-field__tools { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; }
.asset-field__upload { width: 100%; padding: 16px; background: var(--bg-app); border: 1px solid var(--border); border-radius: var(--r-card); }
.asset-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 8px; max-height: 260px; overflow-y: auto; padding: 2px; }
.asset-pick[hidden] { display: none; }
.asset-pick__item { display: block; padding: 0; aspect-ratio: 1; overflow: hidden; border: 2px solid var(--border); border-radius: 8px; background: var(--bg-subtle); cursor: pointer; }
.asset-pick__item img { display: block; width: 100%; height: 100%; object-fit: cover; }
.asset-pick__item:hover { border-color: #8A93A6; }
.asset-pick__item.is-on { border-color: var(--action); box-shadow: 0 0 0 2px var(--action-tint); }
.asset-pick__item:disabled { cursor: not-allowed; opacity: .6; }
.asset-pick__item { position: relative; }
.asset-pick__n { position: absolute; top: 4px; right: 4px; display: grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; background: var(--action); color: #fff; font: 650 12px/1 var(--font-sans); }
.asset-pick__count { margin: 0; }

.asset-thumb { display: block; width: 100%; height: 100%; object-fit: cover; background: var(--bg-subtle); }
.asset-tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  width: 100%; height: 100%; min-height: 96px; padding: 12px;
  background: var(--bg-subtle); color: var(--text-2); text-align: center; overflow: hidden;
}
.mcard__media > .asset-thumb, .mcard__media > .asset-tile { position: absolute; inset: 0; }

.diff { overflow: auto; background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--r-control); font: 13px/20px var(--font-mono); }
.diff__line { display: flex; gap: 8px; padding: 0 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.diff__mark { flex: none; width: 12px; color: var(--text-2); }
.diff__line--add { background: var(--success-bg); color: var(--success); }
.diff__line--del { background: var(--danger-bg); color: var(--danger); }
.diff__line--add .diff__mark { color: var(--success); }
.diff__line--del .diff__mark { color: var(--danger); }

.upload { display: flex; flex-direction: column; gap: 16px; }
.upload__drop {
  display: flex; flex-direction: column; align-items: flex-start; gap: 12px; padding: 24px;
  background: var(--bg-app); border: 2px dashed var(--border-control); border-radius: var(--r-card);
  transition: border-color var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease);
}
.upload__drop[data-drag="true"] { background: var(--action-tint); border-color: var(--action); }
.upload__lead { font-weight: 600; }
.upload__pick { position: relative; cursor: pointer; }
.upload__pick:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.upload__list { display: flex; flex-direction: column; gap: 12px; margin: 0; padding: 0; list-style: none; }
.upload__row {
  display: grid; grid-template-columns: minmax(160px, 1fr) minmax(0, 2.4fr) minmax(130px, 0.9fr) auto; gap: 12px 16px; align-items: start;
  padding: 12px; background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--r-card);
}
.upload__row[data-status="error"] { background: var(--danger-bg); border-color: var(--danger-line); }
.upload__row[data-status="done"] { border-color: var(--success-line); }
.upload__file { display: flex; align-items: flex-start; gap: 10px; min-width: 0; }
.upload__meta { display: flex; flex-direction: column; min-width: 0; }
.upload__fields { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 8px; }
.upload__state { display: flex; flex-direction: column; gap: 6px; }
.upload__progress { width: 100%; height: 8px; accent-color: var(--action); }
.upload__status { display: inline-flex; align-items: flex-start; gap: 6px; font-size: 13px; line-height: 18px; }
.upload__status .icon { margin-top: 1px; }
.upload__status--error { color: var(--danger); }
.upload__status--done { color: var(--success); }
.upload__actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }

/* 14 ── Workspace screens ───────────────────────────────────────────────── */

/* Shared: production stepper, scene strip, checklist */
/* Every step in one row of equal columns, whatever the number of steps; narrow screens scroll the row sideways. */
.stepper {
  display: grid; grid-template-columns: repeat(var(--steps, 10), minmax(108px, 1fr)); gap: 8px;
  margin: 0; padding: 0 0 4px; list-style: none; overflow-x: auto; scrollbar-width: thin;
}
/* Wide screens: all steps fit across the content width; smaller screens keep one row that scrolls sideways. */
@media (min-width: 1280px) {
  .stepper { grid-template-columns: repeat(var(--steps, 10), minmax(0, 1fr)); gap: 6px; overflow-x: visible; }
  .stepper .stepper__link { padding: 10px; min-height: 104px; }
  .stepper .stepper__name { font-size: 13px; line-height: 18px; }
}
.stepper__link {
  display: flex; flex-direction: column; gap: 8px; height: 100%; min-height: 96px; padding: 12px;
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--r-card);
  color: var(--text); text-decoration: none;
  transition: border-color var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease);
}
.stepper__link:hover { border-color: #B3BAC8; color: var(--text); text-decoration: none; }
.stepper__icon { display: inline-flex; color: var(--text-2); }
.stepper__label { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stepper__name { font: 650 14px/20px var(--font-sans); }
.stepper__state { font: 400 12px/18px var(--font-sans); color: var(--text-2); }
.stepper__item[data-state="complete"] .stepper__icon { color: var(--success); }
.stepper__item[data-state="complete"] .stepper__link { background: var(--success-bg); border-color: var(--success-line); }
.stepper__item[data-state="complete"] .stepper__state { color: var(--success); }
.stepper__item[data-state="current"] .stepper__link { background: var(--action-tint); border-color: var(--action); box-shadow: inset 0 0 0 1px var(--action); }
.stepper__item[data-state="current"] .stepper__icon, .stepper__item[data-state="current"] .stepper__state { color: var(--action-hover); }
.stepper__item[data-state="stale"] .stepper__link { background: var(--warning-bg); border-color: var(--warning-line); }
.stepper__item[data-state="stale"] .stepper__icon, .stepper__item[data-state="stale"] .stepper__state { color: var(--warning); }
.stepper__item[data-state="review"] .stepper__link { background: var(--info-bg); border-color: var(--info-line); }
.stepper__item[data-state="review"] .stepper__icon, .stepper__item[data-state="review"] .stepper__state { color: var(--info); }
.stepper__item[data-state="blocked"] .stepper__link { background: var(--warning-bg); border-color: var(--warning-line); }
.stepper__item[data-state="blocked"] .stepper__icon, .stepper__item[data-state="blocked"] .stepper__state { color: var(--warning); }
.stepper__item[data-state="pending"] .stepper__name { color: var(--text-2); }

.strip--scenes { margin: 0; padding: 0 0 4px; list-style: none; overflow-x: auto; scrollbar-width: thin; }
.strip--scenes > .strip__item { flex: 1 1 148px; min-width: 96px; max-width: 230px; }

.checklist { margin: 0; padding: 0; list-style: none; background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--r-card); }
.checklist__item { display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 8px 16px; }
.checklist__item + .checklist__item { border-top: 1px solid var(--border); }
.checklist__item .icon { color: var(--text-2); }
.checklist__item[data-done="true"] .icon { color: var(--success); }

.list-rows--flat { background: transparent; border: 0; border-radius: 0; }
.list-rows--flat > li { padding-left: 0; padding-right: 0; }
.table-wrap--flat { border: 0; border-radius: 0; border-top: 1px solid var(--border); }

/* Overview */
.ov-top { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(300px, 1fr); gap: 24px; align-items: stretch; }
.ov-continue { display: grid; grid-template-columns: minmax(200px, 40%) minmax(0, 1fr); background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--r-card); overflow: hidden; min-width: 0; }
.ov-continue__stage { display: grid; place-items: center; min-height: 280px; padding: 20px; background: var(--bg-canvas); overflow: hidden; }
.ov-continue__stage > .frame { height: 240px; width: auto; max-width: 100%; }
.ov-continue__body { display: flex; flex-direction: column; justify-content: center; gap: 12px; padding: 24px; min-width: 0; }
.ov-continue__body h2 a { color: var(--text); text-decoration: none; }
.ov-continue__body h2 a:hover { color: var(--action-hover); text-decoration: underline; }
.ov-continue__next { display: flex; align-items: center; gap: 6px; font-weight: 650; color: var(--action-hover); }
.ov-attention { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.ov-attn { margin: 0; padding: 0; list-style: none; background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--r-card); }
.ov-attn__item { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 6px 8px 6px 16px; }
.ov-attn__item + .ov-attn__item { border-top: 1px solid var(--border); }
.ov-attn__item .icon { flex: none; }
.ov-attn__item[data-kind="warning"] .icon { color: var(--warning); }
.ov-attn__item[data-kind="info"] .icon { color: var(--info); }
.ov-attn__text { flex: 1; min-width: 0; overflow-wrap: anywhere; font-size: 14px; line-height: 20px; }
.ov-more { margin-top: 8px; }
.ov-more > summary { display: flex; align-items: center; min-height: var(--control-h); cursor: pointer; font-weight: 600; color: var(--action); }
.ov-clear { display: flex; align-items: flex-start; gap: 12px; padding: 16px; background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--r-card); }
.ov-clear .icon { color: var(--success); flex: none; }
.ov-secondary { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 32px; margin-top: 32px; }
.ov-secondary--single { grid-template-columns: minmax(0, 1fr); }
.ov-thumb { display: grid; place-items: center; flex: none; width: 48px; height: 48px; overflow: hidden; border-radius: 10px; background: var(--bg-canvas); color: #fff; }
.ov-thumb .asset-thumb { width: 100%; height: 100%; }
.ov-thumb__initial { font: 650 18px/1 var(--font-sans); }
.ov-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-top: 48px; padding-top: 16px; border-top: 1px solid var(--border); }

/* Projects library */
.pl-chips { margin: -4px 0 12px; }
.pl-count { margin: 0 0 12px; }
.pl-archived { min-height: var(--control-h); padding: 0; }
.pl-check { width: 44px; }
.pl-bulk { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 12px; padding: 8px 12px; background: var(--action-tint); border: 1px solid #D8D3F7; border-radius: var(--r-control); }

/* Project overview */
.po-next { display: flex; align-items: center; gap: 6px; margin: -8px 0 8px; font-weight: 650; color: var(--action-hover); }
.po-grid { column-count: 2; column-gap: 24px; margin-top: 32px; }
.po-grid > .card { display: block; margin-bottom: 24px; break-inside: avoid; }
.po-board { margin-top: 24px; padding: 16px 20px 20px; background: var(--bg-canvas); border-radius: var(--r-card); color: var(--text-inverse); }
.po-board__head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-bottom: 14px; }
.po-board__head h2 { color: var(--text-inverse); font-size: 18px; line-height: 26px; }
.po-board__meta { flex: 1 1 auto; color: var(--text-inverse-2); font-size: 14px; line-height: 20px; }
.po-board .btn { --btn-bg: transparent; --btn-fg: var(--text-inverse); --btn-bd: var(--canvas-line); }
.po-board .btn:hover { --btn-bg: var(--canvas-raised); --btn-fg: var(--text-inverse); }
.po-board__strip { display: flex; gap: 12px; margin: 0; padding: 0 0 6px; list-style: none; overflow-x: auto; scrollbar-width: thin; }
.po-board__item { flex: 1 0 128px; max-width: 220px; min-width: 0; }
.po-board__link { display: flex; flex-direction: column; gap: 8px; color: inherit; text-decoration: none; border-radius: 10px; }
.po-board__link:hover { color: inherit; }
.po-board__link:hover .po-board__title { text-decoration: underline; }
.po-board__link:focus-visible { outline-color: #fff; }
.po-board__title { display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font: 600 13px/18px var(--font-sans); overflow-wrap: anywhere; }
.po-cast__thumb { flex: none; width: 84px; }
.po-cast__thumb .frame::after { display: none; }

/* Settings, members, help */
.st-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 32px; align-items: start; margin-top: 24px; }
.st-layout > .form { gap: 24px; }
.st-notifs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 24px; }
.mb-preview { margin-top: 4px; }
.hp-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; align-items: start; }
.hp-steps { display: flex; flex-direction: column; gap: 8px; margin: 0; padding-left: 20px; }
.hp-links { display: flex; flex-direction: column; gap: 4px; margin: 0; padding: 0; list-style: none; }
.hp-links a { display: inline-flex; align-items: center; min-height: var(--control-h); }

/* 15 ── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 1279.98px) {
  :root { --page-pad: 24px; }
  .stepper { gap: 6px; }
}

@media (max-width: 1099.98px) {
  .with-aside { grid-template-columns: minmax(0, 1fr); }
  .aside-panel { position: static; }
  .ov-top { grid-template-columns: minmax(0, 1fr); }
  .ov-secondary, .hp-grid { grid-template-columns: minmax(0, 1fr); }
  .po-grid { column-count: 1; }
  .st-layout { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 1023.98px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .app-side {
    position: fixed; inset: 0 auto 0 0; z-index: 60;
    width: min(320px, 88vw); height: 100dvh;
    transform: translateX(-102%); visibility: hidden;
    transition: transform var(--dur-drawer) var(--ease), visibility 0s linear var(--dur-drawer);
  }
  body[data-nav-open="true"] .app-side {
    transform: none; visibility: visible; box-shadow: var(--shadow-overlay);
    transition: transform var(--dur-drawer) var(--ease), visibility 0s;
  }
  body[data-nav-open="true"] .app-scrim { display: block; position: fixed; inset: 0; z-index: 55; background: rgba(20, 24, 35, 0.5); }
  .app-side__close { display: inline-flex; }
  .app-nav-toggle { display: inline-flex; }
  .app-header { padding: 0 var(--page-pad); gap: 8px; }
  .search-pill { flex: 1 1 auto; }
  .search-pill__kbd { display: none; }
  .app-header__spacer { display: none; }
}

@media (max-width: 767.98px) {
  :root { --page-pad: 16px; }
  h1, .t-page { font-size: 28px; line-height: 36px; }
  h2, .t-panel { font-size: 22px; line-height: 30px; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .stepper { grid-template-columns: repeat(var(--steps, 10), minmax(108px, 1fr)); }
  .page-head { margin-bottom: 16px; }
  .page-head__actions { width: 100%; }
  .search-pill__text { display: none; }
  .search-pill { flex: 0 0 auto; width: var(--control-h); padding: 0; justify-content: center; }
  .app-header { gap: 4px; }
  .app-header__new span { display: none; }
  .app-header__new { width: var(--control-h); padding: 0; }
  .app-header .search-pill { margin-left: auto; }
  .ov-continue { grid-template-columns: minmax(0, 1fr); }
  .ov-continue__stage { min-height: 220px; }
  .ov-continue__stage > .frame { height: 190px; }
  .ov-continue__body { padding: 16px; }
  .st-notifs { grid-template-columns: minmax(0, 1fr); }
  .upload__row { grid-template-columns: minmax(0, 1fr); }
  .upload__fields { grid-template-columns: minmax(0, 1fr); }
  .upload__actions { justify-content: flex-start; }
  .card__head, .card__body, .card__foot { padding-left: 16px; padding-right: 16px; }
  .empty { padding: 24px 16px; }
  .popover--panel { width: calc(100vw - 16px); }
  .palette__item { grid-template-columns: 20px minmax(0, 1fr) auto; }
  .palette__sub { display: none; }
  .toasts { right: 8px; left: 8px; bottom: 8px; width: auto; }

  /* Bottom-sheet dialogs on phones */
  dialog.dialog:not(.dialog--drawer) { width: 100%; max-width: none; max-height: 92dvh; margin: auto 0 0; border-radius: 16px 16px 0 0; }
  dialog.dialog--palette { margin: 0 0 auto; border-radius: 0 0 16px 16px; }
  .dialog__foot { padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
  .dialog__foot .btn { flex: 1 1 auto; }

  /* Tables read as labelled cards where comparison is not lost */
  .table--cards thead { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); }
  .table--cards, .table--cards tbody, .table--cards tr, .table--cards td, .table--cards th[scope="row"] { display: block; width: 100%; }
  .table--cards tr { padding: 12px 16px; }
  .table--cards tr + tr { border-top: 1px solid var(--border); }
  .table--cards td, .table--cards th[scope="row"] { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 6px 0; border: 0; background: none; text-align: right; }
  .table--cards td::before, .table--cards th[scope="row"]::before { content: attr(data-label); flex: none; max-width: 42%; font-weight: 600; color: var(--text-2); text-align: left; }
  .table--cards td:empty { display: none; }
  .table--cards td.num { justify-content: flex-end; }
  .table--cards td.num::before { content: none; }
  .table--cards .pl-check { width: auto; }
  .table--cards .tag-row { justify-content: flex-end; }
  .po-appr td:has(> .po-dash) { display: none; }
}

@media (max-width: 479.98px) {
  .cards, .cards--lg { grid-template-columns: minmax(0, 1fr); }
  .stepper { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .stepper__link { flex-direction: row; align-items: center; min-height: 52px; padding: 8px 12px; gap: 12px; }
  .stepper__label { flex: 1 1 auto; flex-direction: row; align-items: baseline; justify-content: space-between; gap: 8px; }
  .stepper__state { text-align: right; }
  .ov-attn__item { flex-wrap: wrap; }
}

/* Variants (BUILD-13) */
.vr { display: flex; flex-direction: column; gap: 24px; max-width: 1080px; min-width: 0; }
.vr-title { font-size: 24px; line-height: 32px; }
.vr-check { width: 44px; }
.vr-changes { display: flex; flex-direction: column; gap: 2px; margin: 0; padding: 0; list-style: none; font-size: 14px; line-height: 20px; }
.vr-confirm { max-height: 240px; margin: 8px 0 0; padding-left: 20px; overflow: auto; }
.vr-matrix { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.vr-count { margin-left: auto; }

/* One contextual next action, shared by all signed-in screens. */
.next-action { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px 20px; margin: 0 0 20px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg-surface); }
.next-action__copy { min-width: 0; }
.next-action__copy strong { display: block; font-size: 15px; line-height: 22px; }
.next-action__copy p { margin: 4px 0 0; max-width: 72ch; color: var(--text-2); font-size: 14px; line-height: 21px; overflow-wrap: break-word; }
.next-action > .btn { flex-shrink: 0; }
.ed > .next-action { margin: 16px var(--ed-pad); }
@media (max-width: 599px) {
  .next-action { align-items: stretch; flex-direction: column; padding: 14px; gap: 12px; }
  .next-action > .btn { align-self: flex-start; max-width: 100%; white-space: normal; }
}
