:root {
  --bg: #0f1012;
  --bg-soft: #141618;
  --panel: #18191d;
  --panel-muted: #1e2024;
  --panel-strong: #252830;
  --stroke: rgba(255, 255, 255, 0.07);
  --stroke-soft: rgba(255, 255, 255, 0.04);
  --text: #f0f1f3;
  --muted: #6b7280;
  --muted-light: #9ca3af;
  --accent: #7c6bff;
  --accent-strong: #5f4fe8;
  --accent-soft: rgba(124, 107, 255, 0.12);
  --accent-glow: rgba(124, 107, 255, 0.22);
  --success: #34d399;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.4), 0 1px 4px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5), 0 4px 12px rgba(0, 0, 0, 0.3);
  --radius-xl: 18px;
  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 8px;
  --ui-font: "Inter", "Avenir Next", "Segoe UI", sans-serif;
  --display-font: "Inter", "Avenir Next", "Segoe UI", sans-serif;
  --mono-font: "Courier New", Courier, monospace;
}

/* ── Light Theme ────────────────────────────────────────────── */
html[data-theme="light"] {
  --bg: #f5f6f8;
  --bg-soft: #eceef2;
  --panel: #ffffff;
  --panel-muted: #f8f9fb;
  --panel-strong: #eef0f4;
  --stroke: rgba(0, 0, 0, 0.09);
  --stroke-soft: rgba(0, 0, 0, 0.055);
  --text: #111318;
  --muted: #6b7280;
  --muted-light: #8b909a;
  --accent: #6450d8;
  --accent-strong: #4e3ec4;
  --accent-soft: rgba(100, 80, 216, 0.1);
  --accent-glow: rgba(100, 80, 216, 0.18);
  --success: #059669;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.08), 0 1px 4px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.12), 0 4px 12px rgba(0, 0, 0, 0.07);
}

html[data-theme="light"] body {
  background: var(--bg);
  color: var(--text);
}

html[data-theme="light"] .topbar {
  background: rgba(245, 246, 248, 0.9);
  border-bottom-color: rgba(0, 0, 0, 0.08);
}

html[data-theme="light"] .ambient-one {
  background: radial-gradient(circle, rgba(100, 80, 216, 0.1) 0%, transparent 70%);
  opacity: 0.5;
}

html[data-theme="light"] .ambient-two {
  background: radial-gradient(circle, rgba(37, 99, 235, 0.08) 0%, transparent 70%);
  opacity: 0.5;
}

html[data-theme="light"] textarea,
html[data-theme="light"] input,
html[data-theme="light"] select {
  background: rgba(0, 0, 0, 0.03);
  border-color: rgba(0, 0, 0, 0.1);
}

html[data-theme="light"] textarea:hover,
html[data-theme="light"] input:hover,
html[data-theme="light"] select:hover {
  border-color: rgba(0, 0, 0, 0.18);
  background: rgba(0, 0, 0, 0.05);
}

html[data-theme="light"] textarea::placeholder,
html[data-theme="light"] input::placeholder {
  color: #b0b5be;
}

html[data-theme="light"] .panel-card {
  background: rgba(255, 255, 255, 0.85);
}

html[data-theme="light"] .sidebar-block,
html[data-theme="light"] .sidebar-tip {
  background: rgba(0, 0, 0, 0.025);
}

html[data-theme="light"] .sidebar-link.active,
html[data-theme="light"] .dashboard-tab.active {
  color: #4e3ec4;
  background: rgba(100, 80, 216, 0.1);
  border-color: rgba(100, 80, 216, 0.22);
}

html[data-theme="light"] .ghost-button.is-active {
  color: #4e3ec4;
  background: rgba(100, 80, 216, 0.1);
  border-color: rgba(100, 80, 216, 0.22);
}

html[data-theme="light"] .editor-history-controls {
  background: rgba(255, 255, 255, 0.72);
  border-color: rgba(0, 0, 0, 0.09);
}

html[data-theme="light"] .editor-history-btn:not(:disabled):hover {
  background: rgba(100, 80, 216, 0.1);
  color: #4e3ec4;
}

html[data-theme="light"] .workspace-sidebar-scrim {
  background: linear-gradient(90deg, rgba(59, 55, 89, 0.1), rgba(59, 55, 89, 0.04) 30%, transparent 56%);
}

html[data-theme="light"] .left-panel .panel-card {
  background: rgba(255, 255, 255, 0.97);
  border-color: rgba(80, 85, 104, 0.08);
  box-shadow: 0 24px 56px rgba(94, 99, 122, 0.14);
}

html[data-theme="light"] code {
  color: #5040a8;
  background: rgba(100, 80, 216, 0.08);
}

html[data-theme="light"] .eyebrow {
  color: #8b909a;
}

/* Screenplay block accent colors */
html[data-theme="light"] .block-type-label,
html[data-theme="light"] .scene-nav-number,
html[data-theme="light"] .assist-chip {
  background: rgba(100, 80, 216, 0.12);
  color: #4e3ec4;
}

html[data-theme="light"] .draft-block[data-type="note"] .draft-block-input,
html[data-theme="light"] .draft-block[data-type="note"] .spell-overlay {
  color: #6c5fa8;
}

html[data-theme="light"] .draft-block-input::placeholder {
  color: #b8bdc6;
}

html[data-theme="light"] .draft-block.active {
  border-color: rgba(100, 80, 216, 0.35);
  background: rgba(100, 80, 216, 0.04);
}

/* Spell overlay error color — darker red for light bg */
html[data-theme="light"] .spell-error {
  text-decoration-color: #dc2626;
}

/* Spell context menu */
html[data-theme="light"] .spell-context-menu {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.1);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.08);
}

html[data-theme="light"] .spell-menu-header {
  color: #8b909a;
}

html[data-theme="light"] .spell-menu-item {
  color: #111318;
}

html[data-theme="light"] .spell-menu-item:hover {
  background: rgba(0, 0, 0, 0.05);
  color: #000;
}

html[data-theme="light"] .spell-menu-item.spell-menu-suggestion {
  color: #1a1d26;
}

html[data-theme="light"] .spell-menu-item.spell-menu-ignore {
  color: #8b909a;
}

html[data-theme="light"] .spell-menu-item.spell-menu-ignore:hover {
  color: #6b7280;
}

html[data-theme="light"] .spell-menu-separator {
  background: rgba(0, 0, 0, 0.07);
}

html[data-theme="light"] .spell-menu-no-suggestions {
  color: #8b909a;
}

/* Page preview */
html[data-theme="light"] .preview-page {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.1);
  color: #111318;
}

html[data-theme="light"] .editor-page-divider::before {
  background: linear-gradient(
    90deg,
    rgba(0, 0, 0, 0),
    rgba(15, 23, 42, 0.09) 16%,
    rgba(15, 23, 42, 0.09) 84%,
    rgba(0, 0, 0, 0)
  );
}

html[data-theme="light"] .editor-page-divider-label {
  background: rgba(255, 255, 255, 0.96);
  border-color: rgba(15, 23, 42, 0.08);
  color: #6b7280;
}

/* Status pill */
html[data-theme="light"] .status-pill {
  background: rgba(0, 0, 0, 0.06);
  color: #6b7280;
}

html[data-theme="light"] .project-list {
  background: rgba(255, 255, 255, 0.76);
  border-color: rgba(15, 23, 42, 0.08);
}

html[data-theme="light"] .project-row {
  background:
    linear-gradient(90deg, color-mix(in srgb, var(--project-accent-soft) 82%, rgba(255, 255, 255, 0.9)) 0, transparent 20%),
    rgba(255, 255, 255, 0.72);
  border-bottom-color: rgba(15, 23, 42, 0.07);
}

html[data-theme="light"] .project-row:hover {
  background:
    linear-gradient(90deg, color-mix(in srgb, var(--project-accent-soft) 92%, rgba(255, 255, 255, 0.94)) 0, transparent 24%),
    rgba(255, 255, 255, 0.92);
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.05);
}

html[data-theme="light"] .project-row.active {
  background:
    linear-gradient(90deg, color-mix(in srgb, var(--project-accent-soft) 100%, rgba(255, 255, 255, 0.96)) 0, transparent 26%),
    rgba(255, 255, 255, 0.97);
  box-shadow: inset 0 0 0 1px rgba(100, 80, 216, 0.14);
}

html[data-theme="light"] .project-row-icon {
  border-color: color-mix(in srgb, var(--project-accent) 46%, rgba(15, 23, 42, 0.12));
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--project-accent) 18%, rgba(255, 255, 255, 0.9)), rgba(255, 255, 255, 0.7));
  color: #1c2330;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.92),
    0 8px 18px color-mix(in srgb, var(--project-accent) 18%, rgba(15, 23, 42, 0.06));
}

html[data-theme="light"] .project-row-title {
  color: #161b26;
}

html[data-theme="light"] .project-row-subtitle {
  color: #697386;
}

html[data-theme="light"] .row-tag {
  background: rgba(255, 255, 255, 0.82);
  border-color: rgba(15, 23, 42, 0.08);
  color: #667085;
}

html[data-theme="light"] .row-action {
  color: #6b7280;
}

html[data-theme="light"] .project-row:hover .project-row-title,
html[data-theme="light"] .project-row.active .project-row-title {
  color: #111827;
}

html[data-theme="light"] .project-row:hover .project-row-subtitle,
html[data-theme="light"] .project-row.active .project-row-subtitle {
  color: #566173;
}

/* ── Theme Toggle Button ─────────────────────────────────────── */
.theme-toggle-btn {
  display: grid;
  place-items: center;
  width: 2.1rem;
  height: 2.1rem;
  padding: 0;
  border: 1px solid var(--stroke);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted-light);
  font-size: 1rem;
  cursor: pointer;
  transition: background 150ms, border-color 150ms, color 150ms, transform 150ms;
  flex-shrink: 0;
}

.theme-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--stroke);
  color: var(--text);
  transform: rotate(20deg);
}

html[data-theme="light"] .theme-toggle-btn {
  background: rgba(0, 0, 0, 0.04);
  border-color: rgba(0, 0, 0, 0.1);
  color: #6b7280;
}

html[data-theme="light"] .theme-toggle-btn:hover {
  background: rgba(0, 0, 0, 0.08);
  color: #111318;
}

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

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--ui-font);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea,
select {
  font: inherit;
  -webkit-font-smoothing: antialiased;
}

button {
  appearance: none;
}

button,
a {
  transition:
    transform 120ms ease,
    background-color 120ms ease,
    border-color 120ms ease,
    color 120ms ease,
    box-shadow 120ms ease,
    opacity 120ms ease;
}

button:hover,
a:hover {
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--stroke);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  padding: 0.75rem 0.9rem;
  transition: border-color 150ms ease, background 150ms ease, box-shadow 150ms ease;
}

textarea:hover,
input:hover,
select:hover {
  border-color: rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.055);
}

textarea::placeholder,
input::placeholder {
  color: #4b5563;
}

textarea:focus,
input:focus,
select:focus,
button:focus-visible,
a:focus-visible {
  outline: none;
  border-color: rgba(124, 107, 255, 0.4);
  box-shadow: 0 0 0 3px rgba(124, 107, 255, 0.12);
}

code {
  padding: 0.1rem 0.4rem;
  border-radius: 6px;
  background: rgba(124, 107, 255, 0.1);
  color: #a89fff;
  font-size: 0.9em;
}

.is-hidden {
  display: none !important;
}

/* ─── Ambient background ─── */
.ambient {
  position: fixed;
  pointer-events: none;
  z-index: 0;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.25;
}

.ambient-one {
  width: 600px;
  height: 600px;
  top: -200px;
  left: -150px;
  background: radial-gradient(circle, #5b4fe9 0%, transparent 70%);
}

.ambient-two {
  width: 500px;
  height: 500px;
  bottom: -150px;
  right: -100px;
  background: radial-gradient(circle, #2563eb 0%, transparent 70%);
}

.site-shell {
  position: relative;
  z-index: 1;
  width: min(100%, 2048px);
  margin: 0 auto;
}

/* ─── Topbar ─── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 1000;
  isolation: isolate;
  display: grid;
  grid-template-columns: auto minmax(320px, 1fr) auto;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--stroke-soft);
  background: rgba(15, 16, 18, 0.85);
  backdrop-filter: blur(24px) saturate(1.4);
  -webkit-backdrop-filter: blur(24px) saturate(1.4);
  pointer-events: auto;
  overflow: visible;
}

.topbar-center {
  grid-column: 2;
  min-width: 0;
}

.topbar-actions {
  grid-column: 3;
  grid-row: 1; /* Explicit row — prevents cursor drift when breadcrumb is in col 2 */
  min-width: 0;
  justify-self: end;
}

.topbar-center,
.focus-project-title,
.topbar-actions,
.editor-tools,
.editor-primary-nav {
  position: relative;
  z-index: 1;
  pointer-events: auto;
}

.topbar > * {
  min-width: 0;
}

.brand {
  grid-column: 1;
}

.editor-breadcrumb,
.focus-project-title {
  grid-column: 2;
  min-width: 0;
}

body.editor-view .topbar {
  padding-block: 0.65rem;
}

body.editor-view .brand-copy .eyebrow {
  display: none;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  color: inherit;
  text-decoration: none;
}

.brand-button {
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.brand-button:hover {
  transform: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 11px;
  background: linear-gradient(145deg, #6366f1, #7c6bff, #4f46e5);
  color: white;
  font-weight: 800;
  font-size: 1rem;
  letter-spacing: -0.02em;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35), inset 0 1px 0 rgba(255,255,255,0.15);
}

.brand-copy {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.brand-copy strong,
.panel-card h2,
.dashboard-heading h1,
.sidebar-tip h3 {
  font-family: var(--display-font);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-copy strong {
  font-size: 0.95rem;
}

.eyebrow {
  display: block;
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--muted);
}

.topbar-center {
  display: flex;
  align-items: center;
}

.editor-switchers {
  display: flex;
  align-items: flex-end;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.focus-project-title {
  display: none;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--display-font);
  font-size: 1.02rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.inline-select {
  min-width: 0;
  display: grid;
  gap: 0.28rem;
}

.inline-select select {
  min-width: 170px;
}

.topbar-actions,
.editor-tools,
.editor-primary-nav,
.card-heading,
.editor-actions,
.block-controls,
.block-buttons,
.editor-meta,
.banner-actions,
.project-row-actions,
.section-toolbar,
.dashboard-tabs {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: nowrap;
  gap: 0.4rem;
}

.editor-tools {
  justify-content: flex-end;
  flex-wrap: nowrap;
  flex-shrink: 0;
  min-width: 0;
  gap: 0.5rem;
}

.editor-primary-nav,
.banner-actions,
.editor-actions,
.block-buttons,
.project-row-actions,
.dashboard-tabs {
  flex-wrap: wrap;
}

.editor-primary-nav {
  gap: 0.5rem;
  flex-wrap: nowrap;
  flex-shrink: 0;
}

body.editor-view .dashboard-only {
  display: none !important;
}

/* ─── Buttons ─── */
.ghost-button,
.accent-button,
.type-pill,
.icon-button,
.row-action,
.sidebar-link,
.dashboard-tab {
  border: 1px solid var(--stroke);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.85rem;
  cursor: pointer;
  text-decoration: none;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted-light);
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease,
              box-shadow 140ms ease, transform 100ms ease;
}

.ghost-button:hover,
.row-action:hover,
.icon-button:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.14);
  color: var(--text);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.ghost-button:active,
.row-action:active,
.icon-button:active {
  transform: translateY(0);
  box-shadow: none;
}

.ghost-button.is-active {
  background: rgba(124, 107, 255, 0.12);
  border-color: rgba(124, 107, 255, 0.34);
  color: var(--text);
}

.sidebar-toggle-button {
  display: inline-grid;
  place-items: center;
  width: 2.2rem;
  height: 2.2rem;
  padding: 0;
  border-radius: 0.7rem;
  flex: 0 0 auto;
}

.editor-history-controls {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.18rem;
  border: 1px solid var(--stroke);
  border-radius: 0.8rem;
  background: rgba(255, 255, 255, 0.035);
  flex: 0 0 auto;
}

.editor-history-btn {
  display: grid;
  place-items: center;
  width: 1.95rem;
  height: 1.95rem;
  padding: 0;
  border: 0;
  border-radius: 0.62rem;
  background: transparent;
  color: var(--muted-light);
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease, opacity 140ms ease;
}

.editor-history-btn:not(:disabled):hover {
  background: rgba(124, 107, 255, 0.14);
  color: var(--text);
}

.editor-history-btn:disabled {
  cursor: default;
  opacity: 0.36;
}

.sidebar-toggle-button svg {
  width: 1rem;
  height: 1rem;
  transition: opacity 140ms ease;
}

.sidebar-toggle-button[aria-pressed="true"] {
  background: rgba(124, 107, 255, 0.12);
  border-color: rgba(124, 107, 255, 0.3);
  color: #c4bcff;
}

.accent-button {
  border-color: transparent;
  background: linear-gradient(135deg, #6366f1, var(--accent-strong));
  color: white;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.3), inset 0 1px 0 rgba(255,255,255,0.1);
}

.accent-button:hover {
  background: linear-gradient(135deg, #7879f1, var(--accent));
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.45), inset 0 1px 0 rgba(255,255,255,0.2);
  color: white;
  transform: translateY(-1px);
}

.accent-button:active {
  transform: translateY(0);
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.3), inset 0 1px 0 rgba(255,255,255,0.1);
}

.small-button {
  padding: 0.42rem 0.7rem;
  font-size: 0.82rem;
}

.stretch-button {
  display: inline-flex;
  width: 100%;
  justify-content: center;
}

/* ─── Dashboard ─── */
.dashboard-view,
.workspace-view {
  min-height: calc(100vh - 65px);
}

.dashboard-shell {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  min-height: calc(100vh - 65px);
}

.dashboard-sidebar {
  display: grid;
  gap: 1rem;
  align-content: start;
  padding: 1.25rem 1rem;
  background: rgba(255, 255, 255, 0.015);
  border-right: 1px solid var(--stroke-soft);
}

.sidebar-header,
.sidebar-block,
.sidebar-tip {
  border-radius: var(--radius-lg);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.9rem 1rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--stroke);
  border-radius: var(--radius-lg);
}

.sidebar-avatar {
  display: grid;
  place-items: center;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 8px;
  background: linear-gradient(145deg, #6366f1, #7c6bff);
  color: white;
  font-size: 0.72rem;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.sidebar-brand-copy {
  display: grid;
  gap: 0.12rem;
}

.sidebar-brand-copy strong {
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.sidebar-brand-copy span,
.sidebar-label,
.section-sort,
.dashboard-updated {
  color: var(--muted);
  font-size: 0.82rem;
}

.sidebar-nav {
  display: grid;
  gap: 0.3rem;
}

.sidebar-link {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
  font-weight: 500;
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.85rem;
  background: transparent;
  border-color: transparent;
  color: var(--muted-light);
}

.sidebar-link:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--stroke);
  color: var(--text);
}

.sidebar-link.active,
.dashboard-tab.active {
  background: rgba(124, 107, 255, 0.1);
  border-color: rgba(124, 107, 255, 0.25);
  color: #c4bcff;
}

.sidebar-block {
  display: grid;
  gap: 0.7rem;
  padding: 1rem;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--stroke-soft);
  border-radius: var(--radius-lg);
}

.sidebar-label {
  margin: 0;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 600;
}

.sidebar-metrics {
  display: grid;
  gap: 0.55rem;
}

.sidebar-metric {
  display: grid;
  gap: 0.18rem;
  padding: 0.8rem 0.9rem;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--stroke-soft);
}

.sidebar-metric strong {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.sidebar-metric span,
.sidebar-tip p {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.5;
}

.sidebar-tip {
  padding: 1.1rem;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.08), rgba(124, 107, 255, 0.04));
  border: 1px solid rgba(124, 107, 255, 0.15);
  border-radius: var(--radius-lg);
  margin-top: auto;
}

.sidebar-tip h3 {
  margin: 0.35rem 0 0.55rem;
  font-size: 1.3rem;
  line-height: 1.1;
  color: var(--text);
}

/* ─── Dashboard main ─── */
.dashboard-main {
  padding: 0;
  background: transparent;
}

.dashboard-panel {
  min-height: 100%;
  padding: 1.5rem;
}

.dashboard-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.25rem 0 1.25rem;
  border-bottom: 1px solid var(--stroke-soft);
  margin-bottom: 1.5rem;
}

.dashboard-heading h1 {
  margin: 0.3rem 0 0;
  font-size: 1.9rem;
  letter-spacing: -0.03em;
  color: var(--text);
}

.dashboard-updated {
  margin: 0;
  font-size: 0.85rem;
}

.dashboard-search {
  display: block;
  margin-bottom: 2rem;
}

.dashboard-search input {
  height: 3.8rem;
  padding-inline: 1.25rem;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--stroke);
  font-size: 0.95rem;
  color: var(--text);
}

.dashboard-search input:focus {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(124, 107, 255, 0.35);
  box-shadow: 0 0 0 3px rgba(124, 107, 255, 0.1);
}

/* ─── Tutorials / guide page ─── */
.guide-shell {
  width: min(1320px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.5rem 0 3rem;
}

.guide-topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 0 1rem;
  margin-bottom: 1.25rem;
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
}

.guide-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.guide-page {
  display: grid;
  gap: 1.4rem;
}

.guide-hero {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(280px, 0.9fr);
  gap: 1rem;
  align-items: stretch;
}

.guide-hero-card,
.guide-nav-card,
.guide-section {
  border: 1px solid var(--stroke);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.025);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.guide-hero-card {
  padding: 1.5rem;
  background:
    radial-gradient(circle at top left, rgba(124, 107, 255, 0.15), transparent 46%),
    rgba(255, 255, 255, 0.025);
}

.guide-hero-card h1 {
  margin: 0.3rem 0 0.75rem;
  font-size: clamp(2rem, 4vw, 3.2rem);
  letter-spacing: -0.04em;
  line-height: 0.95;
}

.guide-hero-card p {
  margin: 0;
  max-width: 64ch;
  color: var(--muted-light);
  font-size: 1rem;
  line-height: 1.65;
}

.guide-hero-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1.25rem;
}

.guide-microstats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-top: 1rem;
}

.guide-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--stroke-soft);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted-light);
  font-size: 0.82rem;
  font-weight: 500;
}

.guide-nav-card {
  padding: 1.15rem;
  display: grid;
  gap: 0.9rem;
}

.guide-nav-card h2 {
  margin: 0;
  font-size: 0.98rem;
}

.guide-anchor-list {
  display: grid;
  gap: 0.45rem;
}

.guide-anchor {
  display: grid;
  gap: 0.16rem;
  padding: 0.75rem 0.85rem;
  border-radius: 14px;
  border: 1px solid var(--stroke-soft);
  background: rgba(255, 255, 255, 0.02);
  color: inherit;
  text-decoration: none;
  transition: border-color 120ms ease, background 120ms ease, transform 120ms ease;
}

.guide-anchor strong {
  font-size: 0.9rem;
}

.guide-anchor span {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.guide-anchor:hover {
  transform: translateY(-1px);
  background: rgba(124, 107, 255, 0.06);
  border-color: rgba(124, 107, 255, 0.22);
}

.guide-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.guide-section {
  padding: 1.2rem 1.15rem;
  scroll-margin-top: 5.5rem;
}

.guide-section h2 {
  margin: 0.35rem 0 0.8rem;
  font-size: 1.08rem;
}

.guide-section p {
  margin: 0;
  color: var(--muted-light);
  line-height: 1.65;
}

.guide-section ul,
.guide-section ol {
  margin: 0.9rem 0 0;
  padding-left: 1.1rem;
  color: var(--muted-light);
  line-height: 1.7;
}

.guide-section li + li {
  margin-top: 0.35rem;
}

.guide-example {
  margin-top: 1rem;
  padding: 0.95rem 1rem;
  border-radius: 16px;
  border: 1px solid var(--stroke-soft);
  background: rgba(255, 255, 255, 0.02);
}

.guide-example strong {
  display: block;
  margin-bottom: 0.45rem;
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #cfc8ff;
}

.guide-example code,
.guide-shortcut-grid code {
  font-family: var(--mono-font);
  font-size: 0.84rem;
}

.guide-shortcut-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
  margin-top: 1rem;
}

.guide-shortcut {
  padding: 0.75rem 0.85rem;
  border-radius: 14px;
  border: 1px solid var(--stroke-soft);
  background: rgba(255, 255, 255, 0.02);
}

.guide-shortcut strong {
  display: block;
  margin-bottom: 0.28rem;
  font-size: 0.9rem;
}

.guide-footer {
  padding: 1rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.dashboard-section {
  margin-bottom: 2.5rem;
}

.section-heading,
.section-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.section-heading h2,
.section-toolbar h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.section-sort {
  margin: 0;
  font-size: 0.82rem;
}

/* ─── Dashboard tabs ─── */
.dashboard-tabs {
  gap: 0.3rem;
}

.dashboard-tab {
  padding: 0.42rem 0.85rem;
  font-size: 0.82rem;
  font-weight: 500;
  border-radius: 7px;
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}

.dashboard-tab:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted-light);
}

/* ─── Project rows ─── */
.project-list {
  display: grid;
  gap: 0;
  border-radius: var(--radius-lg);
  border: 1px solid var(--stroke-soft);
  overflow: hidden;
  background: rgba(255, 255, 255, 0.01);
}

.project-row {
  position: relative;
  --project-accent: #7c6bff;
  --project-accent-soft: rgba(124, 107, 255, 0.14);
  --project-accent-line: rgba(124, 107, 255, 0.5);
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) auto auto;
  align-items: center;
  gap: 1rem;
  min-height: 4rem;
  padding: 0.85rem 1rem 0.85rem 1.15rem;
  border-bottom: 1px solid var(--stroke-soft);
  background:
    linear-gradient(90deg, var(--project-accent-soft) 0, transparent 17%),
    rgba(255, 255, 255, 0.015);
  transition: background 140ms ease, transform 140ms ease, box-shadow 140ms ease;
}

.project-row::before {
  content: "";
  position: absolute;
  left: 0.28rem;
  top: 0.72rem;
  bottom: 0.72rem;
  width: 3px;
  border-radius: 999px;
  background: var(--project-accent-line);
  opacity: 0.95;
}

.project-row:last-child {
  border-bottom: none;
}

.project-row:hover {
  background:
    linear-gradient(90deg, var(--project-accent-soft) 0, transparent 23%),
    rgba(255, 255, 255, 0.035);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.project-row.active {
  background:
    linear-gradient(90deg, var(--project-accent-soft) 0, transparent 26%),
    rgba(255, 255, 255, 0.05);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.project-row-main {
  display: grid;
  grid-template-columns: 2.55rem minmax(0, 1fr);
  align-items: center;
  gap: 0.95rem;
  min-width: 0;
  padding: 0.12rem 0.1rem 0.12rem 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: inherit;
  text-align: left;
}

.project-row-main:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--project-accent-line);
}

.project-row-icon {
  display: grid;
  place-items: center;
  width: 2.45rem;
  height: 2.45rem;
  border: 1px solid color-mix(in srgb, var(--project-accent) 48%, rgba(255, 255, 255, 0.08));
  border-radius: 11px;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--project-accent) 24%, rgba(255, 255, 255, 0.03)), rgba(255, 255, 255, 0.03));
  color: #f6f3ff;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.project-row-copy {
  display: grid;
  gap: 0.2rem;
  min-width: 0;
}

.project-row-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.02em;
  color: #f4f5fa;
}

.project-row-subtitle {
  color: rgba(220, 224, 235, 0.68);
  font-size: 0.84rem;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-row-tags {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.row-tag {
  display: inline-flex;
  align-items: center;
  padding: 0.28rem 0.62rem;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--stroke-soft);
  color: rgba(220, 224, 235, 0.74);
  font-size: 0.76rem;
  font-weight: 500;
}

.row-action {
  padding: 0.38rem 0.65rem;
  background: transparent;
  font-size: 0.82rem;
  color: var(--muted);
}

.project-row:hover .project-row-title,
.project-row.active .project-row-title {
  color: #ffffff;
}

.project-row:hover .project-row-subtitle,
.project-row.active .project-row-subtitle {
  color: rgba(234, 237, 245, 0.8);
}

.project-row:hover .project-row-icon,
.project-row.active .project-row-icon {
  transform: translateY(-1px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    0 10px 18px rgba(0, 0, 0, 0.18);
}

.empty-project-row {
  grid-template-columns: 1fr;
  padding: 1.5rem 1rem;
}

.project-row-empty-copy {
  display: grid;
  gap: 0.2rem;
}

.project-row-empty-copy span {
  color: var(--muted);
  font-size: 0.85rem;
}

/* ─── Workspace ─── */
.workspace-view {
  padding: 1rem 1.25rem;
  /* `hidden` creates a clipping ancestor in Safari and can break sticky sidebars. */
  overflow-x: clip;
  position: relative;
  z-index: 0;
}

@supports not (overflow: clip) {
  .workspace-view {
    overflow-x: visible;
  }
}

main,
.dashboard-view,
.project-view,
.workspace-view,
.workspace-grid,
.panel,
.editor-column {
  position: relative;
  z-index: 0;
}

.panel-card {
  border: 1px solid var(--stroke);
  border-radius: var(--radius-xl);
  background: rgba(255, 255, 255, 0.025);
  box-shadow: var(--shadow);
  padding: 1.1rem;
  backdrop-filter: blur(8px);
}

.workspace-banner {
  display: none;
}

.workspace-subtitle {
  display: none;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  width: fit-content;
  flex-shrink: 0;
  border-radius: 999px;
  padding: 0.32rem 0.75rem;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  white-space: nowrap;
  background: rgba(52, 211, 153, 0.1);
  color: var(--success);
  border: 1px solid rgba(52, 211, 153, 0.2);
}

.status-pill.is-saving {
  background: rgba(124, 107, 255, 0.1);
  color: #c4bcff;
  border-color: rgba(124, 107, 255, 0.2);
}

.status-pill:not(.is-saving)[title] {
  cursor: help;
}

.workspace-grid {
  display: grid;
  /* Default: hidden left slot + editor fills all remaining space */
  grid-template-columns: 0 minmax(0, 1fr);
  gap: 1.15rem;
  align-items: start;
  max-width: 1480px;
  margin: 0 auto;
  position: relative;
  z-index: 0;
  transition: grid-template-columns 280ms cubic-bezier(0.22, 1, 0.36, 1);
}

/* Sidebar open: sidebar + editor */
.workspace-view.sidebar-expanded .workspace-grid {
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
}

/* Sidebar closed: hidden slot + editor — column-gap:0 removes left offset */
.workspace-view.sidebar-collapsed .workspace-grid {
  grid-template-columns: 0 minmax(0, 1fr);
  column-gap: 0;
}

.panel,
.editor-column {
  min-width: 0;
  position: relative;
  z-index: 0;
}

.left-panel,
.right-panel,
.editor-column {
  display: grid;
  gap: 1rem;
  align-content: start;
}

/* Tabbed sidebar — override grid with flex column */
.left-panel {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-content: unset;
}

.workspace-sidebar-scrim {
  display: none;
  pointer-events: none;
}

.left-panel {
  position: sticky;
  top: calc(4.6rem + 1rem);
  align-self: start;
  height: calc(100dvh - 6.4rem);
  max-height: calc(100vh - 6.4rem);
  min-width: 0;
  width: 100%;
  padding-right: 0.2rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.08) transparent;
  opacity: 0;
  pointer-events: none;
  clip-path: inset(0 100% 0 0 round 1.2rem);
  transform: translateX(-16px);
  transition:
    opacity 180ms ease,
    transform 260ms cubic-bezier(0.22, 1, 0.36, 1),
    clip-path 260ms cubic-bezier(0.22, 1, 0.36, 1);
}

.right-panel {
  /* Stack below editor by default — spans all columns */
  grid-column: 1 / -1;
  position: static;
}

.workspace-view.sidebar-expanded .left-panel {
  opacity: 1;
  pointer-events: auto;
  clip-path: inset(0 0 0 0 round 1.2rem);
  transform: translateX(0);
}

.workspace-view.sidebar-collapsed .left-panel {
  opacity: 0;
  overflow: hidden;
  padding-right: 0;
}

.card-heading {
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.editor-card > .card-heading {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.5rem;
  flex-wrap: nowrap;
  margin-bottom: 0.65rem;
}

/* With .editor-heading hidden, .editor-actions is the sole child — fill width */
.editor-card > .card-heading > .editor-actions {
  flex: 1;
  display: flex;
  flex-wrap: nowrap !important;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.editor-heading {
  display: none; /* Removed from header — redundant label during writing */
}

.left-panel .panel-card {
  padding: 0.82rem 0.84rem;
  border-radius: 1.15rem;
  background: rgba(19, 20, 25, 0.97);
  border-color: rgba(255, 255, 255, 0.055);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.26);
}

.left-panel .card-heading {
  margin-bottom: 0.62rem;
}

.left-panel .card-heading h2 {
  margin-top: 0.18rem;
  font-size: 0.88rem;
}

.left-panel .field span {
  font-size: 0.74rem;
}

.left-panel .field + .field {
  margin-top: 0.58rem;
}

.left-panel .outline-list {
  gap: 0.5rem;
  margin-bottom: 0.62rem;
}

.left-panel .outline-item {
  padding: 0.66rem 0.72rem;
  border-radius: 1rem;
}

.left-panel .scene-nav-item,
.left-panel .character-list-item {
  border-radius: 0.95rem;
}

.editor-actions {
  justify-content: flex-end;
  align-self: center;
  flex-wrap: nowrap;
  gap: 0.5rem;
}

.card-heading h2 {
  margin: 0.25rem 0 0;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.field,
.compact-field {
  display: grid;
  gap: 0.4rem;
}

.field + .field {
  margin-top: 0.85rem;
}

.field span {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--muted-light);
}

.outline-list {
  display: grid;
  gap: 0.65rem;
  margin-bottom: 0.85rem;
}

.outline-item {
  display: grid;
  gap: 0.55rem;
  padding: 0.85rem 0.9rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.02);
  transition: border-color 120ms ease;
}

.outline-item:hover {
  border-color: rgba(255, 255, 255, 0.1);
}

.outline-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
}

.outline-index {
  min-width: 2rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: #a89fff;
}

/* ─── Editor ─── */
.editor-card {
  padding-bottom: 0;
  overflow: visible;
  display: flex;
  flex-direction: column;
}

.editor-mode-switch {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 0.15rem;
  padding: 0.18rem;
  border: 1px solid var(--stroke);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.025);
}

.mode-chip {
  flex: 0 0 auto;
  white-space: nowrap;
  padding: 0.3rem 0.65rem;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 500;
  transition: background 130ms ease, color 130ms ease;
}

.mode-chip:hover {
  color: var(--muted-light);
  background: rgba(255, 255, 255, 0.04);
}

.mode-chip.active {
  background: rgba(124, 107, 255, 0.14);
  color: var(--text);
  box-shadow: inset 0 0 0 1px rgba(124, 107, 255, 0.22);
}

.editor-mode-copy {
  display: none;
}

.type-toolbar,
.free-toolbar {
  display: none;
}

.type-pill {
  white-space: nowrap;
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--stroke);
  color: var(--muted-light);
  font-size: 0.8rem;
  padding: 0.38rem 0.72rem;
  border-radius: 7px;
}

.type-pill:hover {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
}

.type-pill.active {
  background: rgba(124, 107, 255, 0.12);
  border-color: rgba(124, 107, 255, 0.28);
  color: #c4bcff;
}

/* editor-meta is no longer rendered — kept for legacy compat */
.editor-meta {
  display: none;
}

.editor-sprint {
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: center;
  padding: 0;
}

.editor-sprint-inline {
  display: flex;
  align-items: center;
}

.meta-cluster {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  flex: 1 1 auto;
  min-width: 0;
  gap: 0.4rem;
}

.meta-tag {
  padding: 0.24rem 0.58rem;
  font-size: 0.74rem;
  color: var(--muted);
  border: 1px solid var(--stroke-soft);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.025);
}

.sprint-box {
  display: inline-flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 0.4rem;
  padding: 0.22rem 0.28rem 0.22rem 0.5rem;
  border: 1px solid var(--stroke-soft);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.02);
  transition: border-color 180ms ease;
}

.sprint-box:hover {
  border-color: var(--stroke);
}

.sprint-box .ghost-button[disabled] {
  opacity: 1;
  cursor: default;
  transform: none;
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--stroke-soft);
  color: var(--text);
  box-shadow: none;
}

.sprint-box .ghost-button[disabled]:hover {
  transform: none;
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--stroke-soft);
  color: var(--text);
}

.sprint-label {
  font-size: 0.74rem;
  color: var(--muted);
}

/* ─── Topbar metrics ─── */
.topbar-stats {
  gap: 0.3rem;
  flex-shrink: 1;
  min-width: 0;
}

.topbar-stats .meta-tag {
  background: transparent;
  border-color: transparent;
  padding: 0.2rem 0.3rem;
  font-size: 0.76rem;
  color: var(--muted);
}

.topbar-stat-sep {
  color: var(--muted);
  opacity: 0.3;
  font-size: 0.7rem;
  pointer-events: none;
  user-select: none;
}

.topbar-divider {
  width: 1px;
  height: 1.1rem;
  background: var(--stroke);
  flex-shrink: 0;
  opacity: 0.6;
}

.script-editor {
  display: grid;
  gap: 0;
  padding: 0.6rem 0 2rem;
  max-width: 780px;
  margin: 0 auto;
  width: 100%;
}

/* ─── Free writer ─── */
.free-writer-shell {
  margin-top: 0.4rem;
  width: 100%;
}

.draft-stage {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 0.3rem 0 2rem;
  width: 100%;
}

.draft-sheet {
  --draft-sheet-a4-height: max(72vh, min(calc((100vw - 2rem) * 1.4142), 1103px));
  width: min(780px, 100%);
  flex-shrink: 0;
  min-height: var(--draft-sheet-a4-height);
  padding: 1.5rem;
  border: 1px solid var(--stroke);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.02);
  box-shadow: var(--shadow-lg);
}

.draft-sheet-header {
  padding: 0 0.4rem 0.75rem;
  margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--stroke-soft);
}

.draft-sheet-header strong {
  font-size: 0.94rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text);
}

.free-assist-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 0.4rem 0.75rem;
  flex-wrap: wrap;
}

.free-assist-status {
  display: contents;
}

.assist-chip {
  display: inline-flex;
  align-items: center;
  height: 1.35rem;
  padding: 0 0.48rem;
  border-radius: 4px;
  background: rgba(124, 107, 255, 0.1);
  border: 1px solid rgba(124, 107, 255, 0.2);
  color: rgba(196, 188, 255, 0.9);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.free-character-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.suggestion-chip {
  padding: 0.42rem 0.72rem;
  border: 1px solid var(--stroke);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted-light);
  font-size: 0.8rem;
  cursor: pointer;
}

.suggestion-chip:hover {
  background: rgba(124, 107, 255, 0.1);
  border-color: rgba(124, 107, 255, 0.25);
  color: var(--text);
}

.suggestion-empty {
  color: var(--muted);
  font-size: 0.82rem;
}

.free-draft-editor {
  display: grid;
  align-content: start;
  gap: 0.35rem;
  min-height: calc(var(--draft-sheet-a4-height) - 5.4rem);
  padding: 1.2rem 1.5rem 3rem;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.015);
  cursor: text;
}

.editor-page-divider {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  margin: 1.45rem 0 1rem;
  color: var(--muted);
}

.editor-page-divider::before {
  content: "";
  position: absolute;
  inset: 50% 0 auto;
  height: 1px;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0),
    rgba(255, 255, 255, 0.08) 16%,
    rgba(255, 255, 255, 0.08) 84%,
    rgba(255, 255, 255, 0)
  );
  transform: translateY(-50%);
}

.editor-page-divider-label {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  min-height: 1.7rem;
  padding: 0 0.72rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(17, 18, 24, 0.92);
  color: var(--muted-light);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.draft-block {
  position: relative;
  width: 100%;
  padding: 0.12rem 0;
  border-radius: 10px;
  transition: background-color 120ms ease, box-shadow 120ms ease;
  cursor: text;
}

.draft-block.active {
  background: rgba(124, 107, 255, 0.06);
  box-shadow: inset 0 0 0 1px rgba(124, 107, 255, 0.16);
}

.draft-block .ai-block-trigger {
  position: absolute;
  top: 50%;
  right: 0.15rem;
  transform: translateY(-50%);
  opacity: 0;
  pointer-events: none;
  z-index: 3;
  min-width: 1.9rem;
  min-height: 1.9rem;
  padding-inline: 0.42rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
}

.draft-block .block-type-trigger {
  position: absolute;
  top: 50%;
  right: 2.45rem;
  z-index: 3;
  min-height: 1.9rem;
  min-width: 2.75rem;
  padding: 0 0.5rem;
  border: 1px solid rgba(124, 107, 255, 0.22);
  border-radius: 0.7rem;
  background: rgba(20, 21, 27, 0.9);
  color: rgba(224, 220, 255, 0.9);
  font: 700 0.58rem/1 var(--sans-font);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transform: translateY(-50%);
  opacity: 0;
  pointer-events: none;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  transition: opacity 120ms ease, background 120ms ease, border-color 120ms ease, color 120ms ease;
}

.draft-block:hover .ai-block-trigger,
.draft-block.active .ai-block-trigger,
.draft-block:hover .block-type-trigger,
.draft-block.active .block-type-trigger {
  opacity: 1;
  pointer-events: auto;
}

.draft-block .block-type-trigger:hover {
  border-color: rgba(124, 107, 255, 0.42);
  background: rgba(124, 107, 255, 0.16);
  color: #fff;
}

.block-type-menu {
  position: fixed;
  z-index: 575;
  display: grid;
  gap: 0.25rem;
  width: min(13rem, calc(100vw - 1.5rem));
  padding: 0.45rem;
  border: 1px solid rgba(124, 107, 255, 0.2);
  border-radius: 1rem;
  background: rgba(18, 19, 25, 0.96);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(18px);
}

.block-type-option {
  display: grid;
  grid-template-columns: 3.7rem 1fr;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  padding: 0.55rem 0.65rem;
  border: 1px solid transparent;
  border-radius: 0.72rem;
  background: transparent;
  color: rgba(238, 240, 248, 0.78);
  text-align: left;
  cursor: pointer;
}

.block-type-option:hover,
.block-type-option.active {
  border-color: rgba(124, 107, 255, 0.28);
  background: rgba(124, 107, 255, 0.12);
  color: #fff;
}

.block-type-option-code {
  color: rgba(196, 188, 255, 0.92);
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.block-type-option-label {
  font-size: 0.86rem;
  font-weight: 700;
}

.editor-field-shell {
  width: 100%;
  height: 100%;
  min-height: inherit;
}

.spell-shell {
  display: grid;
}

.spell-shell > * {
  grid-area: 1 / 1;
}

.spell-overlay {
  width: 100%;
  min-height: 1.75em;
  box-sizing: border-box;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  font: inherit;
  line-height: inherit;
  letter-spacing: inherit;
  pointer-events: none;
  user-select: none;
}

.draft-block .spell-overlay {
  padding: 0;
  font-family: var(--mono-font);
  font-size: 1.05rem;
  line-height: 1.75;
}

.script-block .spell-overlay {
  padding: 0.75rem 0.9rem;
  font-family: var(--mono-font);
  font-size: 0.95rem;
  line-height: 1.65;
}

.spell-error {
  background: transparent;
  color: #ff9b9b;
  text-decoration-line: underline;
  text-decoration-style: wavy;
  text-decoration-color: #ff6f6f;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 0.16em;
}

.block-text.has-spell-overlay,
.draft-block-input.has-spell-overlay {
  position: relative;
  z-index: 1;
  background: transparent;
}

.block-text.has-spell-overlay.spell-overlay-active,
.draft-block-input.has-spell-overlay.spell-overlay-active {
  color: transparent;
  -webkit-text-fill-color: transparent;
  caret-color: var(--text);
}

.draft-block-input {
  width: 100%;
  min-height: 1.8rem;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font-family: var(--mono-font);
  font-size: 1.05rem;
  line-height: 1.75;
  resize: none;
  overflow: hidden;
  box-shadow: none;
}

.draft-block-input::placeholder {
  color: #444b57;
}

.draft-block-input:focus {
  outline: none;
  box-shadow: none;
}

.draft-block[data-type="scene"] .draft-block-input,
.draft-block[data-type="shot"] .draft-block-input,
.draft-block[data-type="character"] .draft-block-input,
.draft-block[data-type="transition"] .draft-block-input {
  text-transform: uppercase;
}

.draft-block[data-type="action"],
.draft-block[data-type="scene"],
.draft-block[data-type="shot"],
.draft-block[data-type="note"] {
  width: 100%;
}

.draft-block[data-type="character"] {
  width: min(17rem, 100%);
  margin-left: 38%;
}

.draft-block[data-type="dialogue"] {
  width: min(32rem, 100%);
  margin-left: 16%;
}

.draft-block[data-type="parenthetical"] {
  width: min(20rem, 100%);
  margin-left: 24%;
}

.draft-block[data-type="transition"] {
  width: min(18rem, 100%);
  margin-left: auto;
}

.draft-block[data-type="transition"] .draft-block-input {
  text-align: right;
}

.draft-block[data-type="note"] .draft-block-input {
  color: #b7b0ef;
  font-style: italic;
}

.draft-block[data-type="note"] .spell-overlay {
  color: #b7b0ef;
  font-style: italic;
}

.script-block[data-type="note"] .spell-overlay {
  color: #b7b0ef;
  font-style: italic;
}

/* ─── Script blocks ─── */
.script-block {
  position: relative;
  display: grid;
  gap: 0;
  padding: 0.35rem 0.75rem 0.45rem 0.9rem;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  cursor: text;
  transition: background 100ms ease, border-color 100ms ease;
}

/* Left accent line */
.script-block::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.4rem;
  bottom: 0.4rem;
  width: 2px;
  border-radius: 2px;
  background: transparent;
  transition: background 120ms ease;
}

.script-block:hover::before {
  background: rgba(255, 255, 255, 0.07);
}

.script-block.active::before {
  background: rgba(124, 107, 255, 0.6);
}

.script-block:hover {
  background: rgba(255, 255, 255, 0.015);
}

.script-block.active {
  background: rgba(124, 107, 255, 0.03);
  border-color: rgba(124, 107, 255, 0.13);
}

.script-block button,
.script-block select {
  cursor: default;
}

/* Controls: collapse when inactive, expand on hover/active — stays in flow so
   it never overlaps the textarea and can't intercept clicks on the text */
.script-block .block-controls {
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  pointer-events: none;
  transition: max-height 130ms ease, opacity 130ms ease;
}

.script-block:hover .block-controls,
.script-block.active .block-controls {
  max-height: 3.5rem;
  opacity: 1;
  pointer-events: auto;
}

.block-controls {
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: nowrap;
  padding-bottom: 0.3rem;
}

.block-controls .compact-field {
  min-width: min(200px, 100%);
  flex: 1 1 auto;
}

.block-buttons {
  justify-content: flex-end;
  flex: 0 0 auto;
  gap: 0.25rem;
}

.ai-block-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  padding-inline: 0.55rem;
  color: rgba(196, 188, 255, 0.88);
  border-color: rgba(124, 107, 255, 0.2);
  background: rgba(124, 107, 255, 0.08);
  opacity: 0.58;
  cursor: pointer !important;
  transition: opacity 120ms ease, background 120ms ease, border-color 120ms ease, color 120ms ease;
}

.ai-block-trigger svg {
  opacity: 0.95;
}

.script-block:hover .ai-block-trigger,
.script-block.active .ai-block-trigger {
  opacity: 1;
}

.ai-block-trigger:hover {
  background: rgba(124, 107, 255, 0.14);
  border-color: rgba(124, 107, 255, 0.3);
  color: #ebe7ff;
}

/* Contextual type indicator — collapses when block is inactive */
.block-assist {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  pointer-events: none;
  padding-bottom: 0;
  transition: max-height 130ms ease, opacity 130ms ease, padding-bottom 130ms ease;
}

.script-block.active .block-assist {
  max-height: 2rem;
  opacity: 1;
  pointer-events: auto;
  padding-bottom: 0.25rem;
}

.block-kind {
  display: inline-flex;
  align-items: center;
  height: 1.35rem;
  padding: 0 0.48rem;
  border-radius: 4px;
  background: rgba(124, 107, 255, 0.1);
  border: 1px solid rgba(124, 107, 255, 0.2);
  color: rgba(196, 188, 255, 0.85);
  font-size: 0.63rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.block-next {
  font-size: 0.63rem;
  color: rgba(255, 255, 255, 0.18);
  font-style: italic;
}

.block-input-shell {
  display: block;
  width: 100%;
  min-height: 2.8rem;
  cursor: text;
}

.block-text {
  width: 100%;
  min-height: 2.4rem;
  resize: vertical;
  font-family: var(--mono-font);
  font-size: 0.95rem;
  line-height: 1.65;
  background: rgba(255, 255, 255, 0.02);
  border-color: var(--stroke-soft);
}

.block-text:is(input) {
  min-height: 0;
  resize: none;
}

.script-block[data-type="scene"] .block-text,
.script-block[data-type="shot"] .block-text,
.script-block[data-type="character"] .block-text,
.script-block[data-type="transition"] .block-text {
  text-transform: uppercase;
}

.script-block[data-type="action"] .block-input-shell,
.script-block[data-type="scene"] .block-input-shell,
.script-block[data-type="shot"] .block-input-shell,
.script-block[data-type="note"] .block-input-shell {
  width: 100%;
}

.script-block[data-type="character"] .block-input-shell {
  width: min(17rem, 100%);
  margin-left: 38%;
}

.script-block[data-type="dialogue"] .block-input-shell {
  width: min(32rem, 100%);
  margin-left: 16%;
}

.script-block[data-type="parenthetical"] .block-input-shell {
  width: min(20rem, 100%);
  margin-left: 24%;
}

.script-block[data-type="transition"] .block-input-shell {
  width: min(18rem, 100%);
  margin-left: auto;
}

.script-block[data-type="transition"] .block-text {
  text-align: right;
}

.ai-popover {
  position: fixed;
  z-index: 560;
  width: min(340px, calc(100vw - 1.5rem));
  display: grid;
  gap: 0.8rem;
  padding: 0.9rem;
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  animation: menuFadeIn 120ms ease;
}

.ai-popover-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.8rem;
}

.ai-popover-kicker {
  margin: 0 0 0.15rem;
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.ai-popover-header strong {
  display: block;
  font-size: 0.95rem;
  color: var(--text);
  letter-spacing: -0.01em;
}

.ai-provider-inline-toolbar {
  display: grid;
  gap: 0.42rem;
}

.ai-provider-inline-toolbar--modal {
  padding: 0.2rem 1.4rem 0;
}

.ai-provider-inline-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.ai-provider-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 0.42rem;
}

.ai-provider-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2rem;
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--stroke);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted-light);
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}

.ai-provider-chip:hover {
  background: rgba(124, 107, 255, 0.08);
  border-color: rgba(124, 107, 255, 0.22);
  color: var(--text);
}

.ai-provider-chip.is-active {
  background: rgba(124, 107, 255, 0.12);
  border-color: rgba(124, 107, 255, 0.32);
  color: #ebe7ff;
  box-shadow: inset 0 0 0 1px rgba(124, 107, 255, 0.1);
}

.ai-provider-chip.is-degraded {
  border-color: rgba(255, 163, 64, 0.35);
}

.ai-provider-chip.is-unavailable {
  opacity: 0.45;
  cursor: not-allowed;
}

.ai-action-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
}

.ai-action-chip {
  min-height: 2.5rem;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--stroke);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  font-size: 0.8rem;
  line-height: 1.25;
  text-align: left;
  cursor: pointer;
}

.ai-action-chip:hover {
  background: rgba(124, 107, 255, 0.08);
  border-color: rgba(124, 107, 255, 0.22);
}

.ai-popover-divider {
  height: 1px;
  background: var(--stroke-soft);
}

.ai-custom-request {
  display: grid;
  gap: 0.45rem;
}

.ai-custom-request span {
  font-size: 0.78rem;
  color: var(--muted-light);
}

.ai-custom-request textarea {
  min-height: 4.5rem;
  resize: vertical;
  font-family: var(--ui-font);
  font-size: 0.85rem;
  line-height: 1.45;
}

.ai-popover-footer {
  display: flex;
  justify-content: flex-end;
}

/* ─── Preview rail ─── */
.preview-rail {
  display: grid;
  gap: 0.85rem;
  position: sticky;
  top: 5rem;
  overflow: hidden;
}

.preview-copy {
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.6;
  color: var(--muted);
}

.page-preview {
  display: grid;
  gap: 1rem;
  max-height: calc(100vh - 14rem);
  overflow: auto;
  padding-right: 0.2rem;
}

.shortcuts-card {
  display: none;
}

.preview-page {
  position: relative;
  width: 100%;
  max-width: 100%;
  padding: 1rem;
  border-radius: var(--radius-lg);
  border: 1px solid #dde0e5;
  background: #fafafa;
  color: #111;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
  overflow: hidden;
}

.preview-page::before {
  content: "";
  position: absolute;
  top: 1.2rem;
  bottom: 1.2rem;
  left: 1.25rem;
  width: 1px;
  background: #e4e6ea;
}

.page-title {
  margin: 0 0 0.75rem;
  padding-left: 0.7rem;
  color: #9aa0aa;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 600;
}

.preview-sheet {
  display: grid;
  gap: 0.2rem;
  min-height: 10rem;
  padding-left: 0.7rem;
  font-family: var(--mono-font);
  font-size: 0.78rem;
  line-height: 1.3;
}

.preview-block {
  display: grid;
  gap: 0;
  margin: 0;
}

.preview-line {
  min-height: 1.3em;
  white-space: pre;
}

.preview-scene,
.preview-shot,
.preview-transition,
.preview-character {
  text-transform: uppercase;
}

.preview-character {
  width: 48%;
  margin-left: 40%;
}

.preview-dialogue {
  width: 68%;
  margin-left: 16%;
}

.preview-parenthetical {
  width: 56%;
  margin-left: 22%;
}

.preview-transition {
  text-align: right;
}

.preview-note {
  padding: 0.5rem 0.7rem;
  border-left: 3px solid rgba(124, 107, 255, 0.3);
  background: rgba(124, 107, 255, 0.06);
  color: #666;
}

/* ─── Utils ─── */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.muted {
  color: var(--muted);
}

/* ─── Focus mode ─── */
body.focus-mode .left-panel,
body.focus-mode .right-panel {
  display: none;
}

body.focus-mode .workspace-grid {
  display: block;
  max-width: 1220px;
  margin: 0 auto;
}

body.focus-mode .editor-column {
  width: 100%;
}

body.focus-mode .site-shell {
  width: min(1440px, calc(100% - 2rem));
  margin: 0 auto;
}

body.focus-mode .topbar {
  gap: 0.9rem;
  padding: 0.48rem 1rem;
  background: rgba(10, 11, 15, 0.76);
  border-bottom-color: rgba(255, 255, 255, 0.06);
}

html[data-theme="light"] body.focus-mode .topbar {
  background: rgba(245, 246, 248, 0.92);
  border-bottom-color: rgba(0, 0, 0, 0.08);
}

body.focus-mode .brand,
body.focus-mode .topbar-center,
body.focus-mode #createProjectTop,
body.focus-mode #createDemoProject,
body.focus-mode #themeToggle,
body.focus-mode #userMenuShell,
body.focus-mode #sidebarToggle,
body.focus-mode #backToProjects,
body.focus-mode #editorMenuShell,
body.focus-mode .topbar-stats,
body.focus-mode .topbar-divider {
  display: none !important;
}

body.focus-mode .focus-project-title {
  display: block;
  grid-column: 2;
  flex: 1 1 auto;
  max-width: 40rem;
}

body.focus-mode .topbar-actions {
  grid-column: 3;
  gap: 0;
}

body.focus-mode .editor-tools,
body.focus-mode .editor-primary-nav {
  flex-wrap: nowrap;
  gap: 0.65rem;
  margin-left: 0;
}

body.focus-mode .status-pill {
  white-space: nowrap;
  padding-inline: 0.84rem;
}

body.focus-mode #focusToggle {
  white-space: nowrap;
  padding-inline: 0.92rem;
  min-height: 2.4rem;
}

body.focus-mode .editor-card {
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
}

body.focus-mode .editor-card > .card-heading,
body.focus-mode .free-assist-bar,
body.focus-mode .draft-sheet-header {
  display: none;
}

body.focus-mode .script-editor {
  max-width: 920px;
  padding-top: 0.5rem;
  padding-bottom: 4rem;
}

body.focus-mode .draft-stage {
  padding-top: 0;
}

body.focus-mode .draft-sheet {
  --draft-sheet-a4-height: max(calc(100vh - 10.5rem), min(calc((100vw - 2rem) * 1.4142), 1301px));
  width: min(920px, 100%);
  min-height: var(--draft-sheet-a4-height);
  padding: 1.35rem 2rem 3.2rem;
  background: rgba(255, 255, 255, 0.014);
  border-color: rgba(255, 255, 255, 0.055);
  box-shadow: 0 32px 72px rgba(0, 0, 0, 0.26);
}

body.focus-mode .editor-page-divider {
  margin: 1.15rem 0 0.85rem;
}

body.focus-mode .editor-page-divider-label {
  background: rgba(17, 18, 24, 0.88);
  color: rgba(255, 255, 255, 0.46);
}

body.focus-mode .script-block,
body.focus-mode .draft-block {
  transition:
    background 120ms ease,
    border-color 120ms ease,
    box-shadow 120ms ease;
}

body.focus-mode .script-block:not(.active),
body.focus-mode .draft-block:not(.active) {
  opacity: 1;
  transform: none;
  filter: none;
}

body.focus-mode .script-block.active,
body.focus-mode .draft-block.active {
  opacity: 1;
  transform: none;
  filter: none;
}

body.focus-mode .script-block.active {
  background: transparent;
  border-color: var(--stroke-soft);
  box-shadow: none;
}

body.focus-mode .draft-block.active {
  background: transparent;
  box-shadow: none;
}

body.focus-mode .script-block::before {
  opacity: 0.45;
}

body.focus-mode .script-block.active::before {
  opacity: 0.45;
}

body.focus-mode .script-block:not(.active) .block-controls,
body.focus-mode .script-block:not(.active) .block-assist {
  max-height: 0;
  opacity: 0;
  pointer-events: none;
  padding-bottom: 0;
}

body.focus-mode .script-block:not(.active) .ai-block-trigger,
body.focus-mode .draft-block:not(.active) .ai-block-trigger,
body.focus-mode .draft-block:not(.active) .block-type-trigger {
  opacity: 0;
  pointer-events: none;
}

body.focus-mode .script-block:not(.active) .block-kind,
body.focus-mode .draft-block:not(.active) .assist-chip {
  opacity: 1;
}

/* ─── Responsive ─── */
@media (max-width: 1640px) {
  .page-preview {
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    max-height: none;
    overflow: visible;
  }

  .preview-rail {
    position: static;
  }
}

@media (max-width: 1240px) {
  .workspace-banner {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .banner-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .workspace-grid {
    grid-template-columns: 1fr;
  }

  .workspace-view.sidebar-expanded .workspace-grid,
  .workspace-view.sidebar-collapsed .workspace-grid {
    grid-template-columns: 1fr;
  }

  .left-panel,
  .right-panel {
    position: static;
  }

  .left-panel {
    width: 100%;
    height: auto;
    max-height: none;
    padding-right: 0;
    clip-path: none;
    transform: none;
  }

  .workspace-view.sidebar-collapsed .left-panel {
    display: none;
    pointer-events: none;
  }

  .workspace-view.sidebar-expanded .left-panel {
    display: grid;
    opacity: 1;
    pointer-events: auto;
    margin-bottom: 0.35rem;
  }

  .editor-sprint,
  .editor-actions {
    justify-content: flex-start;
  }

  .draft-sheet {
    width: 100%;
  }
}

@media (max-width: 1180px) {
  .topbar {
    grid-template-columns: minmax(0, 1fr);
    gap: 0.5rem;
  }

  .brand,
  .topbar-center,
  .editor-breadcrumb,
  .focus-project-title,
  .topbar-actions {
    grid-column: auto;
  }

  .topbar-actions {
    flex-wrap: wrap;
    justify-content: flex-start;
    width: 100%;
    justify-self: stretch;
  }

  .dashboard-shell {
    grid-template-columns: 1fr;
  }

  .dashboard-sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--stroke-soft);
  }

  body.focus-mode .topbar {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.65rem;
  }

  body.focus-mode .focus-project-title {
    grid-column: 1 / -1;
    flex-basis: 100%;
    max-width: none;
  }

  body.focus-mode .editor-tools {
    justify-content: flex-end;
  }

  body.focus-mode .topbar-actions,
  body.focus-mode .editor-tools,
  body.focus-mode .topbar-stats {
    flex-wrap: wrap;
  }
}

@media (min-width: 1400px) {
  body.editor-view .editor-tools,
  body.editor-view .editor-primary-nav,
  body.editor-view .topbar-stats {
    flex-wrap: nowrap;
  }
}

@media (max-width: 900px) {
  .workspace-grid,
  .project-row {
    grid-template-columns: 1fr;
  }

  .project-row {
    gap: 0.7rem;
    align-items: start;
  }

  .project-row-tags,
  .project-row-actions {
    justify-content: flex-start;
  }

  .editor-card > .card-heading {
    flex-wrap: wrap;
  }

  .editor-actions {
    flex-wrap: wrap;
  }

  .editor-mode-switch {
    width: 100%;
    justify-content: stretch;
  }

  .mode-chip {
    flex: 1 1 0;
  }

  .draft-sheet {
    min-height: 64vh;
    padding: 1rem;
  }


  .free-draft-editor {
    min-height: calc(64vh - 5rem);
    padding-inline: 1rem;
  }

  .draft-block,
  .draft-block[data-type="character"],
  .draft-block[data-type="dialogue"],
  .draft-block[data-type="parenthetical"],
  .draft-block[data-type="shot"],
  .draft-block[data-type="transition"] {
    width: 100%;
    margin-left: 0;
  }

  .draft-block-input {
    font-size: 1rem;
  }

  body.focus-mode .site-shell {
    width: min(100%, calc(100% - 1rem));
  }

  body.focus-mode .focus-project-title {
    width: 100%;
    font-size: 0.96rem;
  }

  body.focus-mode .script-editor {
    max-width: 100%;
  }

  body.focus-mode .draft-sheet {
    width: 100%;
    padding: 1.35rem 1rem 2rem;
    min-height: 72vh;
  }

  .topbar-actions,
  .editor-meta,
  .block-controls {
    align-items: stretch;
  }

  .block-input-shell,
  .script-block[data-type="character"] .block-input-shell,
  .script-block[data-type="dialogue"] .block-input-shell,
  .script-block[data-type="parenthetical"] .block-input-shell,
  .script-block[data-type="shot"] .block-input-shell,
  .script-block[data-type="transition"] .block-input-shell {
    width: 100%;
    margin-left: 0;
  }

  .block-controls {
    flex-wrap: wrap;
  }

  .block-controls .compact-field,
  .block-buttons {
    min-width: 100%;
    width: 100%;
    justify-content: flex-start;
  }
}

/* ─── Left panel scrollable ─── */
.left-panel {
  max-height: calc(100vh - 6.4rem);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.08) transparent;
}

/* ─── Scene navigator ─── */
.scene-nav-list {
  display: grid;
  gap: 0.25rem;
}

.scene-nav-item {
  display: grid;
  grid-template-columns: 1.5rem 1fr;
  align-items: start;
  gap: 0.5rem;
  padding: 0.5rem 0.6rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted-light);
  text-align: left;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}

.scene-nav-item:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--stroke);
  color: var(--text);
  transform: none;
}

.scene-nav-number {
  font-size: 0.7rem;
  font-weight: 700;
  color: #a89fff;
  padding-top: 0.05rem;
  text-align: right;
}

.scene-nav-text {
  font-size: 0.78rem;
  font-weight: 500;
  font-family: var(--mono-font);
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ─── Character tracker ─── */
.character-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.character-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.6rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--stroke);
}

.character-name {
  font-size: 0.78rem;
  font-weight: 600;
  font-family: var(--mono-font);
  color: var(--text);
}

.character-count {
  font-size: 0.7rem;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  padding: 0.05rem 0.35rem;
  min-width: 1.2rem;
  text-align: center;
}

/* ─── Beat colors ─── */
.outline-item {
  border-left: 3px solid transparent;
  padding-left: 0.85rem;
  transition: border-left-color 150ms ease;
}

.outline-item-header {
  flex-wrap: nowrap;
  gap: 0.5rem;
}

.outline-header-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
  flex-shrink: 0;
}

.drag-handle {
  cursor: grab;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
  user-select: none;
  flex-shrink: 0;
}

.drag-handle:active {
  cursor: grabbing;
}

.beat-color-row {
  display: flex;
  align-items: center;
  gap: 0.22rem;
}

.beat-color-dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 2px solid transparent;
  padding: 0;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 120ms ease, border-color 120ms ease;
}

.beat-color-dot:hover {
  transform: scale(1.25);
}

.beat-color-dot.active {
  border-color: rgba(255, 255, 255, 0.8);
  transform: scale(1.15);
}

.beat-color-none {
  background: rgba(255, 255, 255, 0.12) !important;
  border: 2px dashed rgba(255, 255, 255, 0.25) !important;
}

.beat-color-none.active {
  border-color: rgba(255, 255, 255, 0.6) !important;
}

/* ─── Drag states ─── */
.outline-item.dragging {
  opacity: 0.35;
}

.outline-item.drag-over {
  outline: 2px solid rgba(124, 107, 255, 0.45);
  outline-offset: 2px;
  background: rgba(124, 107, 255, 0.05);
}

/* ─── Nav empty state ─── */
.nav-empty {
  margin: 0;
  padding: 0.25rem 0;
  color: var(--muted);
  font-size: 0.82rem;
}

@media (max-width: 640px) {
  .topbar,
  .workspace-view,
  .dashboard-sidebar,
  .dashboard-panel {
    padding-inline: 1rem;
  }

  .panel-card,
  .preview-page {
    padding: 0.9rem;
    border-radius: var(--radius-lg);
  }

  .workspace-banner h1 {
    font-size: clamp(1.6rem, 9vw, 2.4rem);
  }

  .brand-copy .eyebrow {
    display: none;
  }

  .preview-character,
  .preview-dialogue,
  .preview-parenthetical {
    width: 100%;
    margin-left: 0;
  }

}

/* ── Spell Context Menu ─────────────────────────────────────── */
.spell-context-menu {
  position: fixed;
  z-index: 9999;
  min-width: 11rem;
  max-width: 16rem;
  background: #1e2025;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 0.6rem;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6), 0 2px 8px rgba(0,0,0,0.4);
  padding: 0.35rem 0;
  overflow: hidden;
  animation: spell-menu-in 0.1s ease;
}

@keyframes spell-menu-in {
  from { opacity: 0; transform: scale(0.95) translateY(-4px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.spell-menu-header {
  padding: 0.3rem 0.8rem 0.25rem;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #556;
}

.spell-menu-item {
  display: block;
  width: 100%;
  padding: 0.48rem 0.85rem;
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--text);
  font-size: 0.9rem;
  font-family: var(--ui-font);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-radius: 0;
  transition: background 0.08s;
}

.spell-menu-item:hover {
  background: rgba(255,255,255,0.07);
  color: #fff;
}

.spell-menu-item.spell-menu-suggestion {
  font-weight: 500;
  color: #e0dff5;
}

.spell-menu-item.spell-menu-ignore {
  color: #778;
  font-size: 0.82rem;
}

.spell-menu-item.spell-menu-ignore:hover {
  color: #aab;
}

.spell-menu-separator {
  height: 1px;
  background: rgba(255,255,255,0.07);
  margin: 0.3rem 0;
}

.spell-menu-no-suggestions {
  padding: 0.45rem 0.85rem;
  color: #556;
  font-size: 0.82rem;
  font-style: italic;
}

.spell-error {
  cursor: context-menu;
}

/* ── PDF Export Modal ───────────────────────────────────────── */
.export-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: export-bg-in 0.18s ease;
}

@keyframes export-bg-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.export-modal {
  width: min(480px, calc(100vw - 2rem));
  max-height: calc(100vh - 3rem);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: export-modal-in 0.18s cubic-bezier(0.34, 1.3, 0.64, 1);
}

@keyframes export-modal-in {
  from { opacity: 0; transform: scale(0.94) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.export-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.4rem 1rem;
  border-bottom: 1px solid var(--stroke-soft);
  flex-shrink: 0;
}

.export-modal-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.export-close-btn {
  display: grid;
  place-items: center;
  width: 1.8rem;
  height: 1.8rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 120ms, color 120ms;
}

.export-close-btn:hover {
  background: var(--panel-strong);
  color: var(--text);
}

.export-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 0.6rem 0;
}

.export-field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem 1.4rem;
}

.export-field-label {
  font-size: 0.9rem;
  color: var(--text);
  flex: 1;
}

.export-select {
  width: auto;
  min-width: 9rem;
  padding: 0.38rem 0.7rem;
  font-size: 0.85rem;
  background: var(--panel-strong);
  border-color: var(--stroke);
  border-radius: var(--radius-sm);
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
}

.export-inline-input {
  width: auto;
  min-width: 9rem;
  padding: 0.38rem 0.7rem;
  font-size: 0.85rem;
  background: var(--panel-strong);
  border-color: var(--stroke);
  border-radius: var(--radius-sm);
  color: var(--text);
  flex-shrink: 0;
}

.export-filename-row {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.export-filename-input {
  width: 8rem;
  min-width: 0;
}

.export-ext {
  font-size: 0.82rem;
  color: var(--muted);
  white-space: nowrap;
}

/* Toggle switch */
.export-toggle {
  position: relative;
  display: inline-flex;
  width: 2.5rem;
  height: 1.45rem;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--panel-strong);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 180ms;
}

.export-toggle.is-on {
  background: var(--accent);
}

.export-toggle-thumb {
  position: absolute;
  top: 0.18rem;
  left: 0.18rem;
  width: 1.1rem;
  height: 1.1rem;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
  transition: transform 180ms cubic-bezier(0.34, 1.4, 0.64, 1);
}

.export-toggle.is-on .export-toggle-thumb {
  transform: translateX(1.05rem);
}

.export-divider {
  height: 1px;
  background: var(--stroke-soft);
  margin: 0.5rem 1.4rem;
}

.export-section-label {
  margin: 0.5rem 1.4rem 0.1rem;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Scene list */
.export-scene-list {
  padding: 0.4rem 1.4rem 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  max-height: 12rem;
  overflow-y: auto;
  border: 1px solid var(--stroke-soft);
  border-radius: var(--radius-md);
  margin: 0 1.4rem;
  background: var(--panel-muted);
}

.export-scene-check {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.35rem 0.3rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 100ms;
  user-select: none;
}

.export-scene-check:hover {
  background: var(--panel-strong);
}

.export-scene-check input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
  accent-color: var(--accent);
  border-radius: 3px;
  cursor: pointer;
}

.export-scene-check-label {
  font-size: 0.82rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.export-scene-check-num {
  font-size: 0.75rem;
  color: var(--muted);
  flex-shrink: 0;
}

/* Footer */
.export-modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.6rem;
  padding: 0.85rem 1.4rem;
  border-top: 1px solid var(--stroke-soft);
  flex-shrink: 0;
}

/* Light theme overrides */
html[data-theme="light"] .export-backdrop {
  background: rgba(0, 0, 0, 0.35);
}

html[data-theme="light"] .export-select,
html[data-theme="light"] .export-inline-input {
  background: #f5f6f8;
  border-color: rgba(0,0,0,0.12);
}

html[data-theme="light"] .export-toggle {
  background: #d1d5db;
}

html[data-theme="light"] .export-toggle.is-on {
  background: var(--accent);
}

.ai-assist-modal {
  width: min(720px, calc(100vw - 2rem));
}

.ai-assist-subtitle {
  margin: 0.22rem 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.ai-assist-body {
  display: grid;
  gap: 0.9rem;
}

.ai-assist-status {
  display: grid;
  place-items: center;
  gap: 0.8rem;
  padding: 2rem 1.4rem;
  color: var(--muted-light);
  text-align: center;
}

.ai-assist-status p {
  margin: 0;
  max-width: 32rem;
  line-height: 1.55;
}

.ai-assist-spinner {
  width: 1.8rem;
  height: 1.8rem;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.08);
  border-top-color: var(--accent);
  animation: aiSpin 0.8s linear infinite;
}

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

.ai-assist-results {
  display: grid;
  gap: 0.75rem;
  padding: 0.2rem 1.4rem 1rem;
}

.ai-suggestion-card {
  display: grid;
  gap: 0.55rem;
  width: 100%;
  padding: 0.95rem 1rem;
  border: 1px solid var(--stroke);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.025);
  text-align: left;
  cursor: pointer;
}

.ai-suggestion-card:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(124, 107, 255, 0.16);
}

.ai-suggestion-card.is-selected {
  border-color: rgba(124, 107, 255, 0.28);
  background: rgba(124, 107, 255, 0.08);
  box-shadow: inset 0 0 0 1px rgba(124, 107, 255, 0.14);
}

.ai-suggestion-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
  flex-wrap: wrap;
}

.ai-suggestion-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.ai-suggestion-type {
  display: inline-flex;
  align-items: center;
  padding: 0.18rem 0.5rem;
  border-radius: 999px;
  background: rgba(124, 107, 255, 0.1);
  border: 1px solid rgba(124, 107, 255, 0.18);
  color: rgba(196, 188, 255, 0.88);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.ai-suggestion-text {
  margin: 0;
  white-space: pre-wrap;
  color: var(--muted-light);
  font-family: var(--mono-font);
  font-size: 0.9rem;
  line-height: 1.6;
}

.ai-assist-footer {
  justify-content: space-between;
  flex-wrap: wrap;
}

.ai-assist-footer .accent-button,
.ai-assist-footer .ghost-button {
  min-width: 9rem;
  justify-content: center;
}

html[data-theme="light"] .ai-block-trigger {
  color: #4e3ec4;
  border-color: rgba(100, 80, 216, 0.18);
  background: rgba(100, 80, 216, 0.08);
}

html[data-theme="light"] .ai-block-trigger:hover {
  background: rgba(100, 80, 216, 0.12);
  border-color: rgba(100, 80, 216, 0.28);
  color: #3f31a8;
}

html[data-theme="light"] .draft-block .block-type-trigger {
  color: #5141c7;
  border-color: rgba(100, 80, 216, 0.18);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.12);
}

html[data-theme="light"] .draft-block .block-type-trigger:hover {
  background: rgba(100, 80, 216, 0.1);
  border-color: rgba(100, 80, 216, 0.28);
  color: #3f31a8;
}

html[data-theme="light"] .block-type-menu {
  background: rgba(255, 255, 255, 0.96);
  border-color: rgba(15, 23, 42, 0.1);
  box-shadow: 0 18px 38px rgba(15, 23, 42, 0.12), 0 5px 14px rgba(15, 23, 42, 0.08);
}

html[data-theme="light"] .block-type-option {
  color: #1f2937;
}

html[data-theme="light"] .block-type-option:hover,
html[data-theme="light"] .block-type-option.active {
  background: rgba(100, 80, 216, 0.1);
  border-color: rgba(100, 80, 216, 0.2);
}

html[data-theme="light"] .block-type-option-code {
  color: #5141c7;
}

html[data-theme="light"] .ai-popover {
  background: rgba(255, 255, 255, 0.94);
  border-color: rgba(15, 23, 42, 0.1);
  box-shadow: 0 18px 38px rgba(15, 23, 42, 0.12), 0 5px 14px rgba(15, 23, 42, 0.08);
}

html[data-theme="light"] .ai-provider-chip {
  background: rgba(255, 255, 255, 0.82);
  border-color: rgba(15, 23, 42, 0.08);
  color: #5b6474;
}

html[data-theme="light"] .ai-provider-chip:hover {
  background: rgba(100, 80, 216, 0.08);
  border-color: rgba(100, 80, 216, 0.18);
  color: #312f4a;
}

html[data-theme="light"] .ai-provider-chip.is-active {
  background: rgba(100, 80, 216, 0.1);
  border-color: rgba(100, 80, 216, 0.28);
  color: #4333b4;
}

html[data-theme="light"] .ai-action-chip,
html[data-theme="light"] .ai-suggestion-card {
  background: rgba(255, 255, 255, 0.8);
  border-color: rgba(15, 23, 42, 0.08);
}

html[data-theme="light"] .ai-action-chip:hover {
  background: rgba(100, 80, 216, 0.08);
  border-color: rgba(100, 80, 216, 0.2);
}

html[data-theme="light"] .ai-suggestion-card:hover {
  background: rgba(255, 255, 255, 0.96);
  border-color: rgba(100, 80, 216, 0.16);
}

html[data-theme="light"] .ai-suggestion-card.is-selected {
  background: rgba(100, 80, 216, 0.08);
  border-color: rgba(100, 80, 216, 0.26);
}

html[data-theme="light"] .ai-suggestion-type {
  color: #4e3ec4;
  background: rgba(100, 80, 216, 0.1);
  border-color: rgba(100, 80, 216, 0.18);
}

html[data-theme="light"] .ai-suggestion-text,
html[data-theme="light"] .ai-assist-status {
  color: #667085;
}

/* ── Title Page Editor ──────────────────────────────────────── */
.tpe-shell {
  margin: 0.2rem 1.4rem 0.6rem;
  padding: 0.75rem 0.9rem 0.85rem;
  background: var(--panel-muted);
  border: 1px solid var(--stroke-soft);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.tpe-preview-label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.2rem;
}

.tpe-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.tpe-contact-row {
  gap: 0.5rem;
}

.tpe-field {
  flex: 1;
  min-width: 0;
  padding: 0.38rem 0.6rem;
  font-size: 0.84rem;
  background: var(--panel-strong);
  border: 1px solid var(--stroke);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--mono-font);
  transition: border-color 120ms;
}

.tpe-field:focus {
  border-color: var(--accent);
  outline: none;
}

.tpe-title-field {
  font-size: 0.94rem;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.tpe-subtitle-field {
  font-size: 0.84rem;
}

.tpe-contact-field {
  font-size: 0.78rem;
  resize: none;
  line-height: 1.5;
}

.tpe-fmt-group {
  display: flex;
  gap: 0.25rem;
  flex-shrink: 0;
}

.tpe-fmt-btn {
  display: grid;
  place-items: center;
  width: 1.8rem;
  height: 1.8rem;
  padding: 0;
  border: 1px solid var(--stroke);
  border-radius: var(--radius-sm);
  background: var(--panel-strong);
  color: var(--muted);
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 110ms, color 110ms, border-color 110ms;
}

.tpe-fmt-btn:hover {
  background: var(--panel-muted);
  color: var(--text);
}

.tpe-fmt-btn.is-on {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

/* Light theme */
html[data-theme="light"] .tpe-field {
  background: #ffffff;
  border-color: rgba(0,0,0,0.1);
}

html[data-theme="light"] .tpe-fmt-btn {
  background: #f5f6f8;
  border-color: rgba(0,0,0,0.1);
}

html[data-theme="light"] .tpe-fmt-btn.is-on {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Auth gate (full-screen loading overlay) ─────────────────────────────── */
#authGate {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-gate-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--stroke);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ── Editor actions menu (topbar ··· button) ─────────────────────────────── */
.editor-menu-shell {
  position: relative;
  display: flex;
  align-items: center;
  z-index: 2;
}

.editor-menu-btn {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 8px;
  background: transparent;
  border: 1px solid var(--stroke);
  color: var(--muted-light);
  cursor: pointer;
  transition: background 120ms, color 120ms, border-color 120ms;
  flex-shrink: 0;
}

.editor-menu-btn:hover,
.editor-menu-btn[aria-expanded="true"] {
  background: var(--panel-muted);
  border-color: var(--stroke-soft);
  color: var(--text);
}

.editor-menu-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 190px;
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 500;
  overflow: hidden;
  animation: menuFadeIn 120ms ease;
}

.editor-menu-divider {
  height: 1px;
  background: var(--stroke);
}

.editor-menu-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  padding: 0.6rem 0.9rem;
  font-size: 0.85rem;
  color: var(--text);
  background: none;
  border: none;
  text-align: left;
  font-family: var(--ui-font);
  cursor: pointer;
  transition: background 100ms;
}

.editor-menu-item svg {
  flex-shrink: 0;
  opacity: 0.55;
}

.editor-menu-item:hover {
  background: var(--panel-muted);
}

.editor-menu-item--accent {
  color: var(--accent-light, #a5a0ff);
  font-weight: 600;
}

.editor-menu-item--accent svg {
  opacity: 0.8;
}

.editor-menu-item--accent:hover {
  background: rgba(124, 107, 255, 0.08);
}

.script-selection-modal {
  width: min(880px, calc(100vw - 2rem));
}

.script-selection-body {
  padding-top: 1rem;
}

.script-selection-text {
  width: 100%;
  min-height: min(60vh, 34rem);
  resize: vertical;
  border-radius: 18px;
  padding: 1rem 1.1rem;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  font-family: var(--mono-font);
  font-size: 0.96rem;
  line-height: 1.7;
  white-space: pre-wrap;
}

.script-selection-text:focus {
  outline: none;
  border-color: rgba(124, 107, 255, 0.38);
  box-shadow: 0 0 0 3px rgba(124, 107, 255, 0.12);
}

/* ── User menu (topbar avatar + dropdown) ────────────────────────────────── */
.user-menu-shell {
  position: relative;
  display: flex;
  align-items: center;
  z-index: 2;
}

.user-avatar-btn {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  font-family: var(--ui-font);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 120ms, transform 120ms;
  flex-shrink: 0;
}

.user-avatar-btn:hover {
  background: var(--accent);
  color: #fff;
  transform: scale(1.06);
}

.user-menu-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 200px;
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 500;
  overflow: hidden;
  animation: menuFadeIn 120ms ease;
}

@keyframes menuFadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.user-menu-email {
  padding: 0.65rem 0.9rem;
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-menu-divider {
  height: 1px;
  background: var(--stroke);
}

.user-menu-section-title {
  padding: 0.7rem 0.9rem 0.45rem;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}

.ai-provider-menu {
  display: grid;
  gap: 0.42rem;
  padding: 0 0.8rem 0.8rem;
}

.ai-provider-option {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.52rem 0.68rem;
  border: 1px solid var(--stroke);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
  color: var(--text);
  font-size: 0.82rem;
  font-family: var(--ui-font);
  text-align: left;
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease, transform 120ms ease;
}

.ai-provider-option:hover {
  background: var(--panel-muted);
  border-color: rgba(124, 107, 255, 0.18);
}

.ai-provider-option.is-active {
  background: rgba(124, 107, 255, 0.1);
  border-color: rgba(124, 107, 255, 0.34);
  box-shadow: inset 0 0 0 1px rgba(124, 107, 255, 0.12);
}

.ai-provider-option.is-degraded {
  border-color: rgba(255, 163, 64, 0.35);
}

.ai-provider-option.is-unavailable {
  opacity: 0.45;
  cursor: not-allowed;
}

.ai-provider-icon {
  display: inline-grid;
  place-items: center;
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  color: #fff;
  flex-shrink: 0;
}

.ai-provider-icon[data-provider-icon="auto"] {
  background: linear-gradient(135deg, #7c6bff, #9c7bff);
}

.ai-provider-icon[data-provider-icon="grok"] {
  background: linear-gradient(135deg, #0f172a, #334155);
}

.ai-provider-icon[data-provider-icon="openai"] {
  background: linear-gradient(135deg, #10a37f, #0b7a63);
}

.ai-provider-icon[data-provider-icon="gemini"] {
  background: linear-gradient(135deg, #4285f4, #7b61ff);
}

.user-menu-item {
  display: block;
  width: 100%;
  padding: 0.6rem 0.9rem;
  font-size: 0.85rem;
  color: var(--text);
  text-decoration: none;
  background: none;
  border: none;
  text-align: left;
  font-family: var(--ui-font);
  cursor: pointer;
  transition: background 100ms;
}

.user-menu-item:hover {
  background: var(--panel-muted);
}

.user-menu-signout {
  color: var(--muted-light);
}

.user-menu-signout:hover {
  color: var(--text);
}

/* Light theme overrides */
html[data-theme="light"] .user-menu-dropdown {
  box-shadow: 0 8px 24px rgba(0,0,0,0.1), 0 2px 8px rgba(0,0,0,0.06);
}

html[data-theme="light"] .ai-provider-option {
  background: rgba(255, 255, 255, 0.82);
  border-color: rgba(15, 23, 42, 0.08);
}

html[data-theme="light"] .ai-provider-option:hover {
  background: rgba(100, 80, 216, 0.06);
  border-color: rgba(100, 80, 216, 0.18);
}

html[data-theme="light"] .ai-provider-option.is-active {
  background: rgba(100, 80, 216, 0.09);
  border-color: rgba(100, 80, 216, 0.28);
  box-shadow: inset 0 0 0 1px rgba(100, 80, 216, 0.12);
}

html[data-theme="light"] .script-selection-text {
  background: rgba(248, 246, 255, 0.9);
  border-color: rgba(123, 107, 220, 0.16);
  color: var(--text);
}


/* ─── Collaboration — shared project badge ──────────────────────────────────── */

.shared-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.18rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: 1px solid rgba(124, 107, 255, 0.3);
  color: rgba(180, 170, 255, 0.9);
  background: rgba(124, 107, 255, 0.08);
  white-space: nowrap;
}

.shared-badge.is-viewer {
  border-color: rgba(180, 170, 255, 0.2);
  color: rgba(180, 170, 255, 0.65);
  background: rgba(100, 90, 180, 0.06);
}

html[data-theme="light"] .shared-badge {
  border-color: rgba(80, 60, 200, 0.25);
  color: #4e3ec4;
  background: rgba(80, 60, 200, 0.07);
}

html[data-theme="light"] .shared-badge.is-viewer {
  color: #7b6fd8;
  border-color: rgba(80, 60, 200, 0.15);
}

/* Shared project row — subtle tint */
.project-row.is-shared::before {
  width: 4px;
}

/* Hide owner-only / member-only buttons based on role (set via JS) */
.project-row[data-role="owner"]  .leave-project  { display: none; }
.project-row[data-role="editor"] .share-project  { display: none; }
.project-row[data-role="editor"] .delete-project { display: none; }
.project-row[data-role="viewer"] .share-project  { display: none; }
.project-row[data-role="viewer"] .delete-project { display: none; }


/* ─── Viewer notice banner ──────────────────────────────────────────────────── */

.viewer-notice {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 1.25rem;
  background: rgba(124, 107, 255, 0.08);
  border-bottom: 1px solid rgba(124, 107, 255, 0.2);
  font-size: 0.87rem;
  color: rgba(200, 195, 255, 0.9);
}

html[data-theme="light"] .viewer-notice {
  background: rgba(80, 60, 200, 0.06);
  border-bottom-color: rgba(80, 60, 200, 0.15);
  color: #4e3ec4;
}

.viewer-notice.is-hidden {
  display: none;
}

.viewer-notice-icon {
  font-size: 1rem;
  flex-shrink: 0;
}

/* In viewer mode — editor inputs become visually read-only */
.workspace-view.is-viewer .draft-block-input,
.workspace-view.is-viewer .block-text {
  cursor: default;
  color: var(--muted);
}

.workspace-view.is-viewer #addBlock,
.workspace-view.is-viewer #clearScript,
.workspace-view.is-viewer .block-buttons,
.workspace-view.is-viewer .block-controls select,
.workspace-view.is-viewer .freeToolbar,
.workspace-view.is-viewer .typeToolbar {
  pointer-events: none;
  opacity: 0.4;
}


/* ─── Share Modal ───────────────────────────────────────────────────────────── */

.share-modal {
  width: min(500px, calc(100vw - 2rem));
}

.vault-modal {
  width: min(540px, calc(100vw - 2rem));
}

.vault-modal-body {
  padding: 0.4rem 0 0;
}

.vault-copy {
  margin: 0 0 0.9rem;
  color: var(--muted-light);
  font-size: 0.9rem;
  line-height: 1.6;
}

.vault-field + .vault-field {
  margin-top: 0.8rem;
}

.vault-modal .export-modal-footer {
  justify-content: space-between;
}

.vault-modal .accent-button[disabled],
.vault-modal .ghost-button[disabled] {
  opacity: 0.6;
  cursor: wait;
}

.share-modal-body {
  padding: 0.4rem 0;
}

.share-section {
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--stroke);
}

.share-section:last-of-type {
  border-bottom: none;
}

.share-section-label {
  margin: 0 0 0.6rem;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Members list */
.share-members-list {
  display: grid;
  gap: 0.35rem;
}

.share-member-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 0.6rem;
  padding: 0.42rem 0.6rem;
  border-radius: 8px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--stroke);
}

html[data-theme="light"] .share-member-row {
  background: rgba(0,0,0,0.02);
}

.share-member-email {
  font-size: 0.87rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}

.share-member-role {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  white-space: nowrap;
}

.share-remove-btn {
  padding: 0.22rem 0.55rem;
  border-radius: 6px;
  border: 1px solid rgba(255, 80, 80, 0.25);
  background: transparent;
  color: rgba(255, 110, 110, 0.8);
  font-size: 0.78rem;
  cursor: pointer;
  transition: background 120ms;
  white-space: nowrap;
}

.share-remove-btn:hover {
  background: rgba(255, 80, 80, 0.12);
  color: #ff6b6b;
}

.share-empty-msg {
  color: var(--muted);
  font-size: 0.87rem;
  padding: 0.3rem 0;
}

/* Add member form */
.share-add-form {
  display: grid;
  gap: 0.55rem;
}

.share-add-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.5rem;
}

.share-email-input {
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--stroke);
  background: var(--panel);
  color: var(--text);
  font-size: 0.87rem;
  min-width: 0;
}

.share-email-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(124, 107, 255, 0.18);
}

.share-role-select {
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--stroke);
  background: var(--panel);
  color: var(--text);
  font-size: 0.87rem;
  cursor: pointer;
}

.share-add-btn {
  width: 100%;
  justify-content: center;
}

.share-form-msg {
  margin: 0;
  font-size: 0.82rem;
  min-height: 1.2em;
}

.share-form-msg.is-error   { color: #ff6b6b; }
.share-form-msg.is-success { color: #6bffb8; }
html[data-theme="light"] .share-form-msg.is-error   { color: #c0392b; }
html[data-theme="light"] .share-form-msg.is-success { color: #1a7a4a; }

.share-modal-note {
  margin: 0;
  padding: 0.85rem 1.25rem 0.6rem;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.5;
}

/* ── Project View ─────────────────────────────────────────────── */

.project-view {
  min-height: calc(100vh - 60px);
  padding: 2rem 2rem 4rem;
}

.pv-shell {
  max-width: 1100px;
  margin: 0 auto;
}

/* Breadcrumb */
.pv-breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 2rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.pv-breadcrumb-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: none;
  border: none;
  color: var(--muted-light);
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: var(--radius-sm);
  font-size: inherit;
  transition: color 150ms, background 150ms;
}

.pv-breadcrumb-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  transform: none;
}

.pv-breadcrumb-sep {
  color: var(--stroke);
  font-size: 1rem;
}

.pv-breadcrumb-current {
  color: var(--text);
  font-weight: 500;
}

/* Content layout */
.pv-content {
  display: grid;
  grid-template-columns: 1fr minmax(0, 280px);
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 900px) {
  .pv-content {
    grid-template-columns: 1fr;
  }
}

/* Project header */
.pv-header {
  display: flex;
  align-items: center;
  gap: 1.1rem;
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--stroke);
  flex-wrap: wrap;
}

.pv-header-icon {
  width: 3.4rem;
  height: 3.4rem;
  border-radius: var(--radius-md);
  background: linear-gradient(160deg, var(--project-accent-soft) 0%, transparent 100%);
  border: 1px solid color-mix(in srgb, var(--project-accent) 28%, var(--stroke));
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1rem;
  color: var(--project-accent);
  letter-spacing: -0.02em;
  flex-shrink: 0;
}

.pv-header-info {
  flex: 1;
  min-width: 0;
}

.pv-title {
  margin: 0 0 0.2rem;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pv-meta {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.pv-header-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  flex-shrink: 0;
}

/* Scripts section */
.pv-scripts-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 1rem;
  gap: 1rem;
}

.pv-scripts-header h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

/* Script cards */
.pv-script-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.script-card {
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: var(--radius-md);
  transition: background 150ms, border-color 150ms, box-shadow 150ms;
  overflow: hidden;
}

.script-card:hover {
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: var(--shadow-sm);
}

.script-card.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(124, 107, 255, 0.18);
}

.script-card-main {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.9rem;
  padding: 0.9rem 1rem;
}

.script-card-icon {
  width: 2.2rem;
  height: 2.2rem;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  color: var(--accent);
  flex-shrink: 0;
}

.script-card.is-active .script-card-icon {
  background: var(--accent);
  color: #fff;
}

.script-card-info {
  min-width: 0;
}

.script-card-title {
  display: block;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.script-card-meta {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.15rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.script-card-actions {
  display: flex;
  gap: 0.35rem;
  flex-shrink: 0;
}

.sc-btn {
  background: none;
  border: 1px solid var(--stroke);
  border-radius: var(--radius-sm);
  color: var(--muted-light);
  font-size: 0.78rem;
  padding: 0.3rem 0.6rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 150ms, color 150ms, border-color 150ms;
}

.sc-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.12);
  transform: none;
}

.sc-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}

.sc-btn.sc-open {
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 500;
}

.sc-btn.sc-open:hover {
  background: var(--accent);
  color: #fff;
  transform: none;
}

.sc-btn.sc-delete {
  color: #ff6b6b;
  border-color: rgba(255, 107, 107, 0.3);
}

.sc-btn.sc-delete:hover {
  background: rgba(255, 107, 107, 0.1);
  border-color: rgba(255, 107, 107, 0.5);
  color: #ff6b6b;
  transform: none;
}

.pv-empty {
  color: var(--muted);
  font-size: 0.88rem;
  padding: 1.5rem 0;
  text-align: center;
}

/* Sidebar */
.pv-sidebar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* pv-meta-card fields rely on the global .field + .field margin-top */

.pv-tip-text {
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.55;
  margin: 0;
}

/* Editor breadcrumb (in topbar, shown when in editor navigated from project) */
.editor-breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.editor-breadcrumb-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: inherit;
  padding: 0.15rem 0.3rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
  transition: background 150ms, color 150ms;
}

.editor-breadcrumb-btn:hover {
  background: var(--accent-soft);
  transform: none;
}

.editor-breadcrumb-sep {
  color: var(--stroke);
}

.editor-breadcrumb-script {
  color: var(--text);
  font-weight: 500;
  max-width: 18ch;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Dashboard project rows — folder tab only on .is-folder rows */
.project-row-icon {
  position: relative;
}

/* Light theme overrides for project view */
html[data-theme="light"] .script-card {
  background: #fff;
  border-color: rgba(0,0,0,0.08);
}

html[data-theme="light"] .script-card:hover {
  border-color: rgba(0,0,0,0.14);
}

html[data-theme="light"] .sc-btn:hover {
  background: rgba(0,0,0,0.04);
  color: #111318;
}

html[data-theme="light"] .pv-breadcrumb-btn:hover {
  background: rgba(0,0,0,0.05);
  color: #111318;
}

html[data-theme="light"] .pv-header-icon {
  background: linear-gradient(160deg, var(--project-accent-soft) 0%, rgba(255,255,255,0.8) 100%);
}

/* Danger button */
.danger-button {
  color: #ff6b6b !important;
}

.danger-button:hover {
  background: rgba(255, 107, 107, 0.08) !important;
  border-color: rgba(255, 107, 107, 0.3) !important;
  color: #ff6b6b !important;
}

/* ── Standalone Script Rows ─────────────────────────────────── */

.standalone-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 1rem;
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: var(--radius-md);
  border-left: 3px solid var(--project-accent);
  transition: background 150ms, border-color 150ms, box-shadow 150ms;
  cursor: default;
}

.standalone-row:hover {
  background: var(--panel-muted);
  border-color: color-mix(in srgb, var(--project-accent) 30%, var(--stroke));
  box-shadow: var(--shadow-sm);
}

.standalone-row.active {
  background: var(--panel-muted);
  border-color: var(--project-accent);
}

.standalone-row.is-dragging {
  opacity: 0.5;
  cursor: grabbing;
}

.standalone-row-main {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  text-align: left;
  min-width: 0;
  color: inherit;
}

.standalone-row-icon {
  width: 2rem;
  height: 2rem;
  display: grid;
  place-items: center;
  background: var(--project-accent-soft);
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.standalone-row-copy {
  min-width: 0;
}

.standalone-row-title {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.standalone-row-subtitle {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.standalone-row-tags {
  display: flex;
  gap: 0.35rem;
  flex-shrink: 0;
}

.standalone-row-actions {
  display: flex;
  gap: 0.35rem;
  flex-shrink: 0;
}

/* Folder row: add folder indicator to icon */
.project-row-icon.is-folder::before {
  content: "";
  position: absolute;
  top: -4px;
  left: 3px;
  right: 6px;
  height: 5px;
  border-radius: 3px 3px 0 0;
  background: color-mix(in srgb, var(--project-accent) 50%, transparent);
}

.project-row-icon {
  position: relative;
}

/* Dashboard standalone zone drag target */
.dashboard-standalone-zone {
  position: relative;
}

.standalone-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  min-height: 3rem;
  border-radius: var(--radius-md);
  transition: background 200ms, border-color 200ms;
}

.standalone-list.drag-over-zone {
  background: var(--accent-soft);
  outline: 2px dashed var(--accent);
  outline-offset: 4px;
}

.section-drop-hint {
  font-size: 0.75rem;
  color: var(--muted);
  margin: 0;
}

/* Drag-over state on folder rows */
.project-row.drag-over-target {
  outline: 2px dashed var(--accent);
  outline-offset: 2px;
  background: var(--accent-soft) !important;
}

/* Color picker */
.pv-color-picker-container {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--stroke);
}

.color-picker-label {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 500;
  margin: 0 0 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.color-swatches {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.color-swatch {
  width: 2rem;
  height: 2rem;
  min-width: 44px;
  min-height: 44px;
  border-radius: 50%;
  border: 2px solid transparent;
  background: var(--swatch-color, var(--panel-strong));
  cursor: pointer;
  transition: transform 120ms, border-color 120ms, box-shadow 120ms;
  padding: 0;
  display: grid;
  place-items: center;
}

.color-swatch:hover {
  transform: scale(1.15);
  border-color: rgba(255,255,255,0.3);
}

.color-swatch.is-selected {
  border-color: white;
  box-shadow: 0 0 0 2px var(--swatch-color, var(--accent));
  transform: scale(1.1);
}

.color-swatch--auto {
  background: var(--panel-strong);
  color: var(--muted);
}

.color-swatch--auto.is-selected {
  box-shadow: 0 0 0 2px var(--accent);
}

/* Standalone row - remove from project button */
.sc-remove {
  color: var(--muted) !important;
  border-color: var(--stroke) !important;
}

.sc-remove:hover {
  color: var(--text) !important;
  background: rgba(255,255,255,0.06) !important;
  transform: none;
}

/* Light theme overrides for new elements */
html[data-theme="light"] .standalone-row {
  background: #fff;
  border-color: rgba(0,0,0,0.08);
}

html[data-theme="light"] .standalone-row:hover {
  background: rgba(0,0,0,0.02);
}

html[data-theme="light"] .standalone-list.drag-over-zone {
  background: rgba(100,80,216,0.06);
}

/* Dashboard tabs — hide since we replaced with two sections */
.dashboard-tabs {
  display: none;
}

/* ── Mobile overrides for new components (< 640px) ─────────── */
@media (max-width: 640px) {
  /* Project view header: stack actions below title */
  .pv-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .pv-header-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  /* Standalone rows: hide tags column, keep main + actions */
  .standalone-row {
    grid-template-columns: 1fr auto;
  }

  .standalone-row-tags {
    display: none;
  }

  /* Color swatches: slightly smaller but still ≥ 44px touch */
  .color-swatches {
    gap: 0.5rem;
  }

  /* Project view: full-width single column */
  .pv-content {
    grid-template-columns: 1fr;
  }

  .pv-header-icon {
    width: 2.6rem;
    height: 2.6rem;
    font-size: 0.85rem;
  }

  .pv-title {
    font-size: 1.2rem;
  }
}

/* ── Sidebar Tabs ────────────────────────────────────────────── */

.sidebar-tab-bar {
  display: flex;
  align-items: stretch;
  gap: 0.15rem;
  padding: 0.28rem;
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: var(--radius-lg);
  flex-shrink: 0;
  /* Stick to the top of the scrollable left-panel */
  position: sticky;
  top: 0;
  z-index: 2;
}

.sidebar-tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.24rem;
  padding: 0.5rem 0.2rem 0.42rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  line-height: 1;
  white-space: nowrap;
  transition: background 130ms, color 130ms, border-color 130ms;
}

.sidebar-tab-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted-light);
  transform: none;
  box-shadow: none;
}

.sidebar-tab-btn.is-active {
  background: var(--accent-soft);
  border-color: rgba(124, 107, 255, 0.22);
  color: var(--accent);
}

.sidebar-tab-btn svg {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
}

/* Tab panels — only one visible at a time */
.sidebar-tab-panel {
  display: none;
}

.sidebar-tab-panel.is-active {
  display: block;
}

/* Panel card inside a tab gets no extra margin — tab gap handles spacing */
.sidebar-tab-panel .panel-card {
  margin: 0;
}

/* Notas textarea — give it more room since it's the only content */
#stab-notas .panel-card textarea {
  min-height: 40vh;
  resize: vertical;
}

/* Light theme overrides */
html[data-theme="light"] .sidebar-tab-bar {
  background: #fff;
  border-color: rgba(0, 0, 0, 0.08);
}

html[data-theme="light"] .sidebar-tab-btn:hover {
  background: rgba(0, 0, 0, 0.04);
  color: #111318;
}

html[data-theme="light"] .sidebar-tab-btn.is-active {
  background: rgba(100, 80, 216, 0.09);
  border-color: rgba(100, 80, 216, 0.22);
  color: #4e3ec4;
}
