/* MotionForge Studio - styles */
    :root {
      --bg-canvas: #f3f5f9;
      --bg-panel: #ffffff;
      --bg-surface: #f6f8fb;
      --bg-elevated: #eceff5;
      --bg-input: #ffffff;
      --border-subtle: rgba(15, 23, 42, 0.10);
      --border-strong: rgba(15, 23, 42, 0.22);
      --text-primary: #0f172a;
      --text-secondary: #475569;
      --text-muted: #7b8798;
      --accent: #2563eb;
      --accent-hover: #1d4ed8;
      --accent-soft: rgba(37, 99, 235, 0.12);
      --accent-blue: #0284c7;
      --accent-blue-soft: rgba(2, 132, 199, 0.12);
      --ok: #16a34a;
      --ok-soft: rgba(34, 197, 94, 0.14);
      --warn: #d97706;
      --warn-soft: rgba(245, 158, 11, 0.14);
      --err: #dc2626;
      --err-soft: rgba(239, 68, 68, 0.14);
      --font-display: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
      --font-body: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
      --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
      --radius-sm: 7px;
      --radius-md: 10px;
      --radius-lg: 12px;
      --ease: cubic-bezier(0.16, 1, 0.3, 1);
    }

    *, *::before, *::after { box-sizing: border-box; }
    html, body {
      margin: 0; padding: 0;
      background: var(--bg-canvas);
      color: var(--text-primary);
      font-family: var(--font-body);
      font-size: 14px;
      line-height: 1.5;
      -webkit-font-smoothing: antialiased;
      min-height: 100vh;
      overflow-x: hidden;
    }

    h1, h2, h3, h4 {
      font-family: var(--font-display);
      margin: 0;
      letter-spacing: -0.02em;
      text-wrap: balance;
    }

    .mono, .tabular {
      font-family: var(--font-mono);
      font-variant-numeric: tabular-nums;
    }

    button, input, select, textarea {
      font-family: inherit;
      font-size: inherit;
      color: inherit;
    }

    button {
      cursor: pointer;
      border: 1px solid transparent;
      background: none;
      padding: 0;
      transition: background 150ms var(--ease), border-color 150ms var(--ease), color 150ms var(--ease), transform 120ms var(--ease), box-shadow 150ms var(--ease);
    }
    button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
      outline: 2px solid var(--accent);
      outline-offset: 2px;
    }
    button:disabled {
      opacity: 0.42;
      cursor: not-allowed;
    }

    /* Scrollbar */
    ::-webkit-scrollbar { width: 8px; height: 8px; }
    ::-webkit-scrollbar-track { background: var(--bg-canvas); }
    ::-webkit-scrollbar-thumb { background: #c3cad8; border-radius: 4px; }
    ::-webkit-scrollbar-thumb:hover { background: #a0a9bc; }

    /* App root — the element that goes full screen (app only, not the browser page) */
    #appRoot { min-height: 100vh; background: var(--bg-canvas, #f3f5f9); }
    #appRoot:fullscreen { overflow: auto; width: 100vw; height: 100vh; }
    #appRoot:-webkit-full-screen { overflow: auto; width: 100vw; height: 100vh; }
    #appRoot.app-maximized { position: fixed; inset: 0; z-index: 9000; overflow: auto; }
    body.has-maximized { overflow: hidden; }
    .brand-pill { margin-left: 8px; padding: 2px 8px; font-size: 10px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; border-radius: 999px; color: #0b0e14; background: linear-gradient(135deg,#ffd54a,#ff8a3d); }
    .sync-badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; font-size: 11.5px; font-weight: 700; border-radius: 999px; color: #92400e; background: rgba(245,158,11,.14); border: 1px solid rgba(217,119,6,.4); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .sync-badge::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: #d97706; box-shadow: none; }

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

    /* Top Bar — Precision Obsidian Workstation Header */
    .topbar {
      position: sticky;
      top: 0;
      z-index: 40;
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 20px;
      height: 58px;
      padding: 0 20px;
      background: rgba(255, 255, 255, 0.94);
      backdrop-filter: blur(18px);
      border-bottom: 1px solid var(--border-subtle);
      box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
    }

    .topbar-left {
      display: flex;
      align-items: center;
      gap: 14px;
      min-width: 0;
      flex-shrink: 0;
    }

    .brand {
      display: flex;
      align-items: center;
      gap: 9px;
      font-family: var(--font-display);
      font-weight: 700;
      font-size: 15px;
      letter-spacing: -0.02em;
      white-space: nowrap;
      color: var(--text-primary);
    }
    .brand-mark {
      width: 28px;
      height: 28px;
      border-radius: 7px;
      background: linear-gradient(135deg, #528bff 0%, #2558d4 100%);
      display: grid;
      place-items: center;
      color: #ffffff;
      box-shadow: 0 4px 14px rgba(82, 139, 255, 0.35);
      flex-shrink: 0;
    }

    .v-sep {
      width: 1px;
      height: 20px;
      background: var(--border-subtle);
      flex-shrink: 0;
    }

    .project-title-input {
      background: transparent;
      border: 1px solid transparent;
      border-radius: var(--radius-sm);
      padding: 4px 8px;
      font-family: var(--font-display);
      font-weight: 600;
      font-size: 13.5px;
      color: var(--text-primary);
      width: 210px;
      max-width: 28vw;
      text-overflow: ellipsis;
      transition: background 150ms, border-color 150ms;
    }
    .project-title-input:hover { background: var(--bg-surface); }
    .project-title-input:focus {
      background: var(--bg-input);
      border-color: var(--border-strong);
      outline: none;
    }

    .save-meta {
      font-size: 12px;
      color: var(--text-muted);
      white-space: nowrap;
    }

    /* Workflow Navigation Tabs (Center Zone) */
    .workflow-nav {
      display: flex;
      align-items: center;
      gap: 4px;
      background: var(--bg-input);
      border: 1px solid var(--border-subtle);
      border-radius: var(--radius-md);
      padding: 3px;
      overflow-x: auto;
      max-width: 100%;
    }

    .workflow-tab {
      display: inline-flex;
      align-items: center;
      gap: 7px;
      padding: 6px 13px;
      border-radius: 5px;
      font-size: 12.5px;
      font-weight: 600;
      color: var(--text-secondary);
      white-space: nowrap;
      flex-shrink: 0;
    }
    .workflow-tab:hover {
      color: var(--text-primary);
      background: rgba(15,23,42,0.05);
    }
    .workflow-tab.active {
      background: var(--accent-soft);
      color: var(--accent);
      border-color: rgba(37,99,235,0.3);
    }
    .workflow-tab .step-num {
      font-family: var(--font-mono);
      font-size: 11px;
      color: var(--text-muted);
    }
    .workflow-tab.active .step-num { color: var(--accent); }
    .workflow-tab.done .step-num { color: var(--ok); }
    .workflow-arrow {
      color: var(--text-muted);
      font-size: 11px;
      opacity: 0.45;
      user-select: none;
    }

    /* Topbar Right Actions */
    .topbar-right {
      display: flex;
      align-items: center;
      gap: 6px;
      flex-shrink: 0;
    }

    /* Buttons */
    .btn {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 7px;
      padding: 7px 14px;
      border-radius: var(--radius-sm);
      font-size: 12.5px;
      font-weight: 600;
      white-space: nowrap;
      flex-shrink: 0;
      line-height: 1.2;
      min-height: 34px;
    }
    .btn-sm { padding: 5px 10px; font-size: 12px; min-height: 28px; }
    .btn-xs { padding: 3px 8px; font-size: 11.5px; min-height: 24px; }
    .btn-icon { padding: 6px; min-width: 32px; min-height: 32px; }
    .btn-primary {
      background: linear-gradient(180deg, #5b93ff 0%, #3d75eb 100%);
      color: #ffffff;
      border-color: rgba(122, 168, 255, 0.45);
      box-shadow: 0 2px 10px rgba(61, 117, 235, 0.28);
    }
    .btn-primary:hover:not(:disabled) {
      background: linear-gradient(180deg, #6ea0ff 0%, #4d83f5 100%);
      box-shadow: 0 4px 14px rgba(61, 117, 235, 0.38);
    }
    .btn-secondary {
      background: var(--bg-elevated);
      color: var(--text-primary);
      border-color: var(--border-subtle);
    }
    .btn-secondary:hover:not(:disabled) {
      background: #2b303d;
      border-color: var(--border-strong);
    }
    .btn-ghost {
      background: transparent;
      color: var(--text-secondary);
      border-color: transparent;
    }
    .btn-ghost:hover:not(:disabled) {
      background: rgba(15,23,42,0.06);
      color: var(--text-primary);
    }
    .btn-blue {
      background: var(--accent-blue);
      color: #ffffff;
      border-color: var(--accent-blue);
    }
    .btn-blue:hover:not(:disabled) { background: #0369a1; }
    .btn-danger {
      background: var(--err-soft);
      color: #b91c1c;
      border-color: rgba(220,38,38,0.35);
    }
    .btn-danger:hover:not(:disabled) { background: rgba(239,68,68,0.24); }

    /* Form Controls */
    .field { display: flex; flex-direction: column; gap: 5px; }
    .field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
    .field-row-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
    .field label, .label {
      font-size: 12px;
      font-weight: 500;
      color: var(--text-secondary);
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
    }
    .req { color: var(--accent); }

    input[type="text"], input[type="number"], select, textarea {
      width: 100%;
      background: var(--bg-input);
      border: 1px solid var(--border-subtle);
      border-radius: var(--radius-sm);
      padding: 8px 10px;
      color: var(--text-primary);
      font-size: 13px;
      transition: border-color 150ms, background 150ms;
    }
    input[type="text"]:hover, input[type="number"]:hover, select:hover, textarea:hover {
      border-color: var(--border-strong);
    }
    input[type="text"]:focus, input[type="number"]:focus, select:focus, textarea:focus {
      border-color: var(--accent);
      outline: none;
    }
    textarea { resize: vertical; line-height: 1.5; }
    input[type="color"] {
      width: 36px; height: 30px; padding: 2px;
      background: var(--bg-input);
      border: 1px solid var(--border-subtle);
      border-radius: var(--radius-sm);
      cursor: pointer;
    }
    input[type="range"] {
      -webkit-appearance: none;
      appearance: none;
      width: 100%;
      height: 4px;
      background: #2b303d;
      border-radius: 2px;
      outline: none;
    }
    input[type="range"]::-webkit-slider-thumb {
      -webkit-appearance: none;
      width: 14px; height: 14px;
      border-radius: 50%;
      background: var(--accent);
      cursor: pointer;
      border: 2px solid #ffffff;
    }

    /* Tab Panels */
    .main-viewport {
      flex: 1;
      display: flex;
      flex-direction: column;
      min-height: 0;
    }
    .tab-pane { display: none; flex: 1; }
    .tab-pane.active { display: flex; flex-direction: column; }

    /* Sub-header bar inside tabs */
    .stage-strip {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 16px;
      padding: 12px 24px;
      background: var(--bg-panel);
      border-bottom: 1px solid var(--border-subtle);
      flex-wrap: wrap;
    }
    .stage-strip-title {
      display: flex;
      align-items: baseline;
      gap: 12px;
      flex-wrap: wrap;
    }
    .stage-strip-title h1 {
      font-size: 16px;
      font-weight: 700;
    }
    .meta-inline {
      font-size: 12.5px;
      color: var(--text-secondary);
      display: flex;
      align-items: center;
      gap: 8px;
      flex-wrap: wrap;
    }
    .meta-sep { opacity: 0.4; }

    /* Generic Panel & Section */
    .panel {
      background: var(--bg-panel);
      border: 1px solid var(--border-subtle);
      border-radius: var(--radius-lg);
      padding: 20px;
    }
    .panel-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
      padding-bottom: 14px;
      margin-bottom: 16px;
      border-bottom: 1px solid var(--border-subtle);
    }
    .panel-header h2 { font-size: 14.5px; font-weight: 700; }
    .panel-sub { font-size: 12.5px; color: var(--text-secondary); margin-top: 2px; }

    /* TAB 1: Story & AI Director */
    .story-grid {
      display: grid;
      grid-template-columns: minmax(340px, 440px) minmax(0, 1fr);
      gap: 20px;
      padding: 20px 24px 32px;
      max-width: 1600px;
      width: 100%;
      margin: 0 auto;
    }
    .story-right-col {
      display: flex;
      flex-direction: column;
      gap: 20px;
      min-width: 0;
    }
    .code-box {
      font-family: var(--font-mono);
      font-size: 12px;
      line-height: 1.55;
      min-height: 220px;
      background: #f6f8fb;
      color: #1e293b;
    }
    .validation-banner {
      padding: 12px 14px;
      border-radius: var(--radius-md);
      border: 1px solid var(--border-subtle);
      background: var(--bg-surface);
      font-size: 12.5px;
      display: flex;
      flex-direction: column;
      gap: 6px;
    }
    .validation-banner.ok { border-color: rgba(34,197,94,0.35); background: rgba(34,197,94,0.08); }
    .validation-banner.warn { border-color: rgba(245,158,11,0.35); background: rgba(245,158,11,0.08); }
    .validation-banner.err { border-color: rgba(239,68,68,0.35); background: rgba(239,68,68,0.08); }
    .validation-list { margin: 4px 0 0 18px; padding: 0; color: var(--text-secondary); }
    .scene-preview-table {
      width: 100%;
      border-collapse: collapse;
      font-size: 12.5px;
      margin-top: 8px;
    }
    .scene-preview-table th {
      text-align: left;
      font-weight: 600;
      color: var(--text-muted);
      padding: 6px 8px;
      border-bottom: 1px solid var(--border-subtle);
    }
    .scene-preview-table td {
      padding: 7px 8px;
      border-bottom: 1px solid rgba(15,23,42,0.06);
      vertical-align: top;
    }

    /* TAB 2: Visual Motion Studio — NLE Workstation */
    .nle-layout {
      display: grid;
      grid-template-columns: 270px minmax(0, 1fr) 340px;
      grid-template-rows: minmax(380px, 1fr) 330px;
      height: calc(100vh - 58px);
      min-height: 680px;
      background: var(--bg-canvas);
    }
    .nle-scenes {
      grid-column: 1;
      grid-row: 1 / 3;
      background: var(--bg-panel);
      border-right: 1px solid var(--border-subtle);
      display: flex;
      flex-direction: column;
      min-height: 0;
    }
    .nle-stage {
      grid-column: 2;
      grid-row: 1;
      display: flex;
      flex-direction: column;
      min-width: 0;
      min-height: 0;
      background: #e9edf3;
    }
    .nle-inspector {
      grid-column: 3;
      grid-row: 1 / 3;
      background: var(--bg-panel);
      border-left: 1px solid var(--border-subtle);
      display: flex;
      flex-direction: column;
      min-height: 0;
    }
    .nle-timeline {
      grid-column: 2;
      grid-row: 2;
      background: var(--bg-panel);
      border-top: 1px solid var(--border-subtle);
      display: flex;
      flex-direction: column;
      min-width: 0;
      min-height: 0;
    }

    .pane-head {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
      padding: 10px 14px;
      border-bottom: 1px solid var(--border-subtle);
      flex-shrink: 0;
    }
    .pane-head h3 { font-size: 13px; font-weight: 700; }

    .scene-list-scroll {
      flex: 1;
      overflow-y: auto;
      padding: 10px;
      display: flex;
      flex-direction: column;
      gap: 8px;
    }

    .scene-card {
      background: var(--bg-surface);
      border: 1px solid var(--border-subtle);
      border-radius: var(--radius-md);
      padding: 8px;
      cursor: pointer;
      display: flex;
      flex-direction: column;
      gap: 7px;
      transition: border-color 140ms, background 140ms;
    }
    .scene-card:hover { border-color: var(--border-strong); }
    .scene-card.selected {
      border-color: var(--accent);
      background: #eef4ff;
    }
    .scene-card-top {
      display: flex;
      gap: 9px;
      align-items: flex-start;
    }
    .scene-thumb {
      width: 78px;
      height: 44px;
      border-radius: 4px;
      background: #1b1f2a;
      border: 1px solid rgba(15,23,42,0.15);
      flex-shrink: 0;
      display: block;
    }
    .scene-card-info {
      flex: 1;
      min-width: 0;
    }
    .scene-card-title {
      font-size: 12.5px;
      font-weight: 600;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .scene-card-meta {
      font-size: 11px;
      color: var(--text-muted);
      margin-top: 2px;
      display: flex;
      align-items: center;
      gap: 6px;
      flex-wrap: wrap;
    }
    .scene-card-actions {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 4px;
      border-top: 1px solid rgba(15,23,42,0.07);
      padding-top: 6px;
    }

    /* Preview Monitor */
    .monitor-bar {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 10px;
      padding: 8px 14px;
      background: var(--bg-panel);
      border-bottom: 1px solid var(--border-subtle);
      flex-wrap: wrap;
    }
    .monitor-viewport {
      flex: 1;
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 14px;
      min-height: 0;
      position: relative;
      overflow: hidden;
    }
    .canvas-frame {
      position: relative;
      max-width: 100%;
      max-height: 100%;
      background: #000;
      box-shadow: 0 12px 34px rgba(15, 23, 42, 0.28);
      border: 1px solid rgba(15, 23, 42, 0.15);
      border-radius: 4px;
      overflow: hidden;
      display: flex;
      align-items: center;
      justify-content: center;
    }
    #previewCanvas {
      display: block;
      max-width: 100%;
      max-height: 100%;
      width: auto;
      height: auto;
    }

    .transport-bar {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
      padding: 9px 14px;
      background: var(--bg-panel);
      border-top: 1px solid var(--border-subtle);
      flex-wrap: wrap;
    }
    .transport-group {
      display: flex;
      align-items: center;
      gap: 6px;
    }
    .timecode-readout {
      font-family: var(--font-mono);
      font-variant-numeric: tabular-nums;
      font-size: 12.5px;
      color: var(--text-primary);
      background: var(--bg-input);
      border: 1px solid var(--border-subtle);
      padding: 4px 10px;
      border-radius: var(--radius-sm);
      white-space: nowrap;
    }

    /* Inspector Tabs */
    .inspector-tabs {
      display: grid;
      grid-template-columns: repeat(4, 1fr);
      border-bottom: 1px solid var(--border-subtle);
      background: var(--bg-input);
      flex-shrink: 0;
    }
    .inspector-tab {
      padding: 9px 6px;
      font-size: 12px;
      font-weight: 600;
      color: var(--text-muted);
      border-bottom: 2px solid transparent;
      text-align: center;
    }
    .inspector-tab:hover { color: var(--text-primary); }
    .inspector-tab.active {
      color: var(--accent);
      border-bottom-color: var(--accent);
      background: var(--bg-panel);
    }
    .inspector-body {
      flex: 1;
      overflow-y: auto;
      padding: 14px;
      display: flex;
      flex-direction: column;
      gap: 14px;
    }
    .insp-section {
      display: flex;
      flex-direction: column;
      gap: 10px;
      padding-bottom: 14px;
      border-bottom: 1px solid var(--border-subtle);
    }
    .insp-section:last-child { border-bottom: none; padding-bottom: 0; }
    .insp-section-title {
      font-family: var(--font-display);
      font-size: 12px;
      font-weight: 700;
      color: var(--text-primary);
      display: flex;
      align-items: center;
      justify-content: space-between;
    }
    .checkbox-grid {
      display: grid;
      grid-template-columns: repeat(2, 1fr);
      gap: 8px;
    }
    .check-item {
      display: flex;
      align-items: center;
      gap: 7px;
      font-size: 12.5px;
      color: var(--text-secondary);
      cursor: pointer;
    }
    .check-item input[type="checkbox"] {
      accent-color: var(--accent);
      width: 14px; height: 14px;
    }

    /* Timeline */
    .timeline-toolbar {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
      padding: 6px 12px;
      border-bottom: 1px solid var(--border-subtle);
      background: var(--bg-surface);
      flex-shrink: 0;
    }
    .timeline-body {
      flex: 1;
      display: flex;
      min-height: 0;
      overflow: hidden;
    }
    .timeline-labels {
      width: 96px;
      flex-shrink: 0;
      border-right: 1px solid var(--border-subtle);
      background: var(--bg-panel);
      display: flex;
      flex-direction: column;
    }
    .tl-label-cell {
      height: 32px;
      padding: 0 10px;
      display: flex;
      align-items: center;
      font-size: 11px;
      font-weight: 600;
      color: var(--text-secondary);
      border-bottom: 1px solid rgba(15,23,42,0.06);
      white-space: nowrap;
    }
    .tl-label-ruler { height: 24px; color: var(--text-muted); font-family: var(--font-mono); }
    .timeline-scroll {
      flex: 1;
      overflow-x: auto;
      overflow-y: hidden;
      position: relative;
      background: #fafbfd;
      user-select: none;
    }
    .timeline-tracks {
      position: relative;
      min-width: 100%;
    }
    .tl-ruler {
      height: 24px;
      position: relative;
      border-bottom: 1px solid var(--border-subtle);
      background: var(--bg-input);
      cursor: pointer;
    }
    .tl-tick {
      position: absolute;
      top: 0; bottom: 0;
      border-left: 1px solid rgba(15,23,42,0.14);
      padding-left: 4px;
      font-family: var(--font-mono);
      font-size: 10px;
      color: var(--text-muted);
      line-height: 22px;
      pointer-events: none;
    }
    .tl-row {
      height: 32px;
      position: relative;
      border-bottom: 1px solid rgba(15,23,42,0.06);
    }
    .tl-block {
      position: absolute;
      top: 3px; bottom: 3px;
      border-radius: 4px;
      padding: 0 7px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 6px;
      font-size: 11px;
      overflow: hidden;
      white-space: nowrap;
      cursor: pointer;
      border: 1px solid rgba(15,23,42,0.18);
    }
    .tl-block.scene-blk { background: #dbe4f3; color: #1e293b; }
    .tl-block.scene-blk.selected {
      background: #bfd3f7;
      border-color: var(--accent);
    }
    .tl-block.caption-blk { background: rgba(229, 154, 60, 0.22); border-color: rgba(229, 154, 60, 0.45); color: #7c4a03; }
    .tl-block.narr-blk { background: rgba(79, 143, 247, 0.22); border-color: rgba(79, 143, 247, 0.45); color: #1e3a8a; }
    .tl-block.music-blk { background: rgba(34, 197, 94, 0.2); border-color: rgba(34, 197, 94, 0.42); color: #14532d; }
    .tl-block.sfx-blk { background: rgba(168, 85, 247, 0.24); border-color: rgba(168, 85, 247, 0.45); color: #581c87; }

    .tl-playhead {
      position: absolute;
      top: 0; bottom: 0;
      width: 2px;
      background: var(--accent);
      pointer-events: none;
      z-index: 15;
    }
    .tl-playhead::before {
      content: '';
      position: absolute;
      top: 0; left: -5px;
      width: 12px; height: 10px;
      background: var(--accent);
      clip-path: polygon(0 0, 100% 0, 50% 100%);
    }

    /* TAB 3: Voice & Sound Studio */
    .audio-grid {
      display: grid;
      grid-template-columns: minmax(340px, 1.05fr) minmax(360px, 1fr);
      gap: 20px;
      padding: 20px 24px 36px;
      max-width: 1600px;
      width: 100%;
      margin: 0 auto;
    }
    .mixer-strip {
      background: var(--bg-surface);
      border: 1px solid var(--border-subtle);
      border-radius: var(--radius-md);
      padding: 14px;
      display: flex;
      flex-direction: column;
      gap: 10px;
    }
    .mixer-head {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 10px;
      flex-wrap: wrap;
    }
    .waveform-canvas {
      width: 100%;
      height: 54px;
      background: #f1f5f9;
      border-radius: var(--radius-sm);
      border: 1px solid var(--border-subtle);
      display: block;
    }
    .sfx-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
      gap: 8px;
    }
    .sfx-tile {
      background: var(--bg-surface);
      border: 1px solid var(--border-subtle);
      border-radius: var(--radius-sm);
      padding: 9px 10px;
      display: flex;
      flex-direction: column;
      gap: 7px;
    }
    .sfx-tile-name { font-size: 12.5px; font-weight: 600; }
    .sfx-tile-desc { font-size: 11px; color: var(--text-muted); }

    /* TAB 4: Export Studio */
    .export-grid {
      display: grid;
      grid-template-columns: minmax(360px, 470px) minmax(0, 1fr);
      gap: 20px;
      padding: 20px 24px 36px;
      max-width: 1520px;
      width: 100%;
      margin: 0 auto;
    }
    .progress-track {
      width: 100%;
      height: 10px;
      background: var(--bg-input);
      border: 1px solid var(--border-subtle);
      border-radius: 5px;
      overflow: hidden;
    }
    .progress-fill {
      height: 100%;
      width: 0%;
      background: linear-gradient(90deg, #3d75eb, #6ea0ff);
      transition: width 160ms linear;
    }
    .spec-grid {
      display: grid;
      grid-template-columns: repeat(2, minmax(0, 1fr));
      gap: 10px;
    }
    .spec-item {
      background: var(--bg-surface);
      border: 1px solid var(--border-subtle);
      border-radius: var(--radius-sm);
      padding: 10px 12px;
    }
    .spec-label { font-size: 11.5px; color: var(--text-muted); }
    .spec-value { font-size: 14px; font-weight: 600; margin-top: 2px; }

    /* Element list items */
    .elem-row {
      background: var(--bg-surface);
      border: 1px solid var(--border-subtle);
      border-radius: var(--radius-sm);
      padding: 9px 10px;
      display: flex;
      flex-direction: column;
      gap: 8px;
    }

    /* Modals */
    .modal-backdrop {
      position: fixed;
      inset: 0;
      background: rgba(15, 23, 42, 0.45);
      backdrop-filter: blur(6px);
      display: none;
      align-items: center;
      justify-content: center;
      padding: 20px;
      z-index: 100;
    }
    .modal-backdrop.open { display: flex; }
    .modal-dialog {
      width: 100%;
      max-width: 640px;
      max-height: 86vh;
      overflow-y: auto;
      background: var(--bg-panel);
      border: 1px solid var(--border-strong);
      border-radius: var(--radius-lg);
      padding: 22px;
      box-shadow: 0 24px 70px rgba(15,23,42,0.28);
    }

    /* Toasts */
    .toast-stack {
      position: fixed;
      bottom: 20px;
      right: 20px;
      z-index: 120;
      display: flex;
      flex-direction: column;
      gap: 8px;
      max-width: 360px;
    }
    .toast {
      background: var(--bg-elevated);
      border: 1px solid var(--border-strong);
      color: var(--text-primary);
      padding: 11px 14px;
      border-radius: var(--radius-md);
      font-size: 13px;
      box-shadow: 0 12px 30px rgba(15,23,42,0.18);
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 10px;
    }
    .toast.ok { border-color: rgba(34,197,94,0.5); }
    .toast.warn { border-color: rgba(245,158,11,0.5); }
    .toast.err { border-color: rgba(239,68,68,0.5); }

    .notice-box {
      padding: 11px 13px;
      border-radius: var(--radius-sm);
      background: var(--bg-surface);
      border: 1px solid var(--border-subtle);
      font-size: 12.5px;
      color: var(--text-secondary);
      line-height: 1.5;
    }
    .notice-box.warn {
      background: rgba(245,158,11,0.08);
      border-color: rgba(245,158,11,0.3);
      color: #92400e;
    }
    .notice-box.info {
      background: rgba(79,143,247,0.08);
      border-color: rgba(79,143,247,0.28);
      color: #cfe0fc;
    }

    /* Responsive Breakpoints */
    @media (max-width: 1180px) {
      .nle-layout {
        grid-template-columns: 230px minmax(0, 1fr);
        grid-template-rows: auto 330px auto;
        height: auto;
      }
      .nle-scenes { grid-column: 1; grid-row: 1 / 3; max-height: 760px; }
      .nle-stage { grid-column: 2; grid-row: 1; min-height: 360px; }
      .nle-timeline { grid-column: 2; grid-row: 2; }
      .nle-inspector {
        grid-column: 1 / 3;
        grid-row: 3;
        border-left: none;
        border-top: 1px solid var(--border-subtle);
      }
      .story-grid, .audio-grid, .export-grid {
        grid-template-columns: 1fr;
      }
    }

    @media (max-width: 820px) {
      .topbar {
        height: auto;
        padding: 8px 12px;
        flex-wrap: wrap;
        gap: 8px;
      }
      .project-title-input { width: 140px; }
      .save-meta { display: none; }
      .workflow-nav { width: 100%; order: 3; }
      .workflow-arrow { display: none; }
      .nle-layout {
        display: flex;
        flex-direction: column;
        height: auto;
      }
      .nle-scenes { max-height: 290px; border-right: none; border-bottom: 1px solid var(--border-subtle); }
      .nle-stage { min-height: 280px; }
      .nle-timeline { height: 330px; }
      .story-grid, .audio-grid, .export-grid { padding: 14px; }
      .field-row, .field-row-3 { grid-template-columns: 1fr; }
      .btn { min-height: 38px; }
    }
    /* --- timeline: dynamic rows, element lanes, audio selection --- */
    .timeline-body { overflow: hidden; }
    .timeline-scroll { overflow: auto !important; }
    .timeline-labels { width: 128px; overflow: hidden; align-self: stretch; }
    .timeline-scroll { min-width: 0; }
    .tl-label-cell { height: 28px; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; box-sizing: border-box; }
    .tl-label-cell.tl-label-ruler { height: 24px; }
    .tl-row { height: 28px; box-sizing: border-box; }
    .tl-row.lane-head { background: var(--bg-surface); }
    .tl-hint { position: sticky; left: 8px; font-size: 10.5px; color: var(--text-muted); line-height: 28px; padding-left: 8px; white-space: nowrap; }
    .tl-label-head { color: var(--accent-blue); font-weight: 600; }
    .tl-label-lyr { cursor: pointer; color: var(--text-secondary); padding-left: 16px; }
    .tl-label-lyr:hover { color: var(--text-primary); }
    .tl-label-lyr.selected { color: var(--accent-blue); font-weight: 600; background: rgba(37,99,235,0.08); }
    .tl-block.lyr-blk { background: rgba(14,165,233,0.22); border-color: rgba(14,165,233,0.55); color: #075985; cursor: grab; touch-action: none; user-select: none; }
    .tl-block.lyr-blk.selected { background: rgba(37,99,235,0.35); border-color: #2563eb; box-shadow: 0 0 0 1.5px #2563eb; }
    .tl-block.lyr-blk.dragging { cursor: grabbing; opacity: 0.9; }
    .tl-block.lyr-blk.hidden-layer { opacity: 0.45; }
    .tl-block.amb-blk { background: rgba(20,184,166,0.22); border-color: rgba(20,184,166,0.5); color: #0f766e; }
    .tl-block.audio-blk { cursor: pointer; }
    .tl-block.selected-audio { box-shadow: 0 0 0 2px #ef4444; border-color: #ef4444; z-index: 3; }
    .tl-x { display: none; margin-left: 6px; width: 16px; height: 16px; line-height: 15px; text-align: center; border-radius: 50%; background: #ef4444; color: #fff; font-size: 13px; flex-shrink: 0; cursor: pointer; }
    .tl-block.selected-audio .tl-x { display: inline-block; }
    .elem-row.active { border-color: var(--accent-blue); box-shadow: 0 0 0 2px rgba(37,99,235,0.25); }
    .elem-row { cursor: pointer; }
    .layer-handle { position: absolute; width: 22px; height: 22px; margin: -11px 0 0 -11px; border-radius: 50%; background: rgba(37,99,235,0.35); border: 2px solid #2563eb; box-shadow: 0 0 0 2px #fff, 0 2px 8px rgba(0,0,0,0.4); cursor: move; z-index: 6; touch-action: none; }
    .layer-handle::after { content: ''; position: absolute; left: 50%; top: 50%; width: 6px; height: 6px; margin: -3px 0 0 -3px; border-radius: 50%; background: #2563eb; }
  
/* v7 Studio Polish: Premium Buttons, Cards & Audio Strips */
.btn {
  border-radius: 9px;
  letter-spacing: -0.01em;
}
.btn:hover:not(:disabled) {
  transform: translateY(-1px);
}
.btn:active:not(:disabled) {
  transform: translateY(0);
}
.btn-primary {
  background: linear-gradient(135deg, #2563eb 0%, #4f46e5 100%);
  border-color: rgba(147, 197, 253, 0.5);
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.28);
}
.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #1d4ed8 0%, #4338ca 100%);
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.36);
}
.panel {
  border-radius: 14px;
  box-shadow: 0 6px 24px rgba(15, 23, 42, 0.05);
}
.mixer-strip {
  border-radius: 12px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  border: 1px solid rgba(15, 23, 42, 0.11);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}
.sfx-tile {
  border-radius: 10px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}
.canvas-frame {
  border-radius: 10px;
  box-shadow: 0 18px 44px rgba(15, 23, 42, 0.24);
}

/* v8 UI & Format Selector Polish */
#topFormatSelect {
  background: linear-gradient(180deg, #ffffff 0%, #f1f5f9 100%);
  color: var(--text-primary);
  border: 1px solid rgba(37, 99, 235, 0.28);
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.06);
}
#topFormatSelect:hover {
  border-color: var(--accent);
}
.topbar {
  background: linear-gradient(180deg, rgba(255,255,255,0.97) 0%, rgba(248,250,252,0.95) 100%);
  box-shadow: 0 4px 18px rgba(15, 23, 42, 0.06);
}
.workflow-nav {
  background: #f1f5f9;
  border: 1px solid rgba(15, 23, 42, 0.12);
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.04);
}
.workflow-tab.active {
  background: linear-gradient(135deg, #2563eb 0%, #4f46e5 100%);
  color: #ffffff;
  border-color: transparent;
  box-shadow: 0 3px 10px rgba(37, 99, 235, 0.26);
}
.workflow-tab.active .step-num {
  color: rgba(255, 255, 255, 0.88);
}
.scene-card {
  border-radius: 12px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}
.scene-card.selected {
  background: linear-gradient(180deg, #eff6ff 0%, #dbeafe 100%);
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.14);
}

#topThemeSelect {
  background: linear-gradient(180deg, #ffffff 0%, #f1f5f9 100%);
  color: var(--text-primary);
  border: 1px solid rgba(79, 70, 229, 0.28);
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.06);
}
#topThemeSelect:hover {
  border-color: #4f46e5;
}
