    *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
    :root {
      --navy-950: #070a12; --navy-900: #0b0f1e; --navy-800: #111828;
      --blue:    #3b82f6; --blue-dk: #2563eb; --blue-lt: rgba(59,130,246,.16);
      --brand-50:  #070a12; --brand-100: rgba(255,255,255,.06); --brand-200: rgba(255,255,255,.12);
      --brand-300: rgba(255,255,255,.22);
      --brand-400: #7c88a3; --brand-500: #9aa6bd; --brand-600: #b9c2d6; --brand-700: #d6dcea;
      --brand-800: #ecf0f8; --brand-900: #f7f9fd;
      --accent-400: #60a5fa; --accent-600: #3b82f6;
      --red: #f87171; --green: #34d399;
      --radius: 12px;
      --sidebar-w: 218px;
      --glass: rgba(255,255,255,.045);
      --glass-strong: rgba(255,255,255,.085);
      --border-strong: rgba(255,255,255,.18);
      --shadow-lg: 0 24px 60px -20px rgba(0,0,0,.65);
    }
    body {
      font-family: 'Instrument Sans', system-ui, sans-serif; color: var(--brand-900);
      background: var(--navy-950); position: relative;
    }
    body::before, body::after {
      content: ''; position: fixed; z-index: -1; border-radius: 50%;
      filter: blur(120px); opacity: .24; pointer-events: none;
    }
    body::before { width: 620px; height: 620px; top: -220px; left: -180px; background: radial-gradient(circle at 30% 30%, #1d5fa8, transparent 70%); }
    body::after  { width: 560px; height: 560px; bottom: -220px; right: -180px; background: radial-gradient(circle at 60% 40%, #2b3d82, transparent 70%); }

    /* ── Screens ──────────────────────────────────────────────────── */
    .app-screen { display: none; }
    #auth-screen.active  { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: transparent; }
    #home-screen.active  { display: block; min-height: 100vh; }
    #editor-screen.active {
      display: grid;
      grid-template-columns: var(--sidebar-w) 1fr;
      height: 100vh; overflow: hidden;
    }

    /* ── Typography ───────────────────────────────────────────────── */
    .h1 { font-family: 'Instrument Serif', serif; font-style: italic; font-weight: 400; font-size: 2.15rem; line-height: 1.15; letter-spacing: -.01em; }
    .h2 { font-family: 'Instrument Serif', serif; font-style: italic; font-weight: 400; font-size: 1.4rem; margin-bottom: .75rem; }
    .sub { font-size: 1rem; color: var(--brand-500); margin-top: .5rem; }

    /* ── Forms ────────────────────────────────────────────────────── */
    label { display: block; font-size: .875rem; font-weight: 500; color: var(--brand-700); margin-bottom: .375rem; }
    input[type=text], input[type=email], input[type=password], input[type=url], textarea {
      width: 100%; padding: .625rem .875rem; border: 1px solid var(--brand-300);
      border-radius: var(--radius); font-size: .9375rem; font-family: inherit;
      color: var(--brand-900); background: var(--glass-strong); outline: none;
      backdrop-filter: blur(10px); transition: border-color .2s ease, background .2s ease, box-shadow .2s ease;
    }
    input::placeholder, textarea::placeholder { color: var(--brand-400); }
    input:focus, textarea:focus { border-color: var(--blue); background: var(--glass-strong); box-shadow: 0 0 0 3px rgba(59,130,246,.2); }
    textarea { resize: vertical; line-height: 1.6; }
    .form-group { margin-bottom: 1rem; }
    .field-label-row { display: flex; align-items: center; gap: .375rem; margin-bottom: .25rem; }
    .field-label-row label { margin-bottom: 0; }
    .info-pill { display: inline-flex; align-items: center; justify-content: center;
      width: 16px; height: 16px; border-radius: 50%; background: var(--brand-300);
      color: var(--brand-700); font-size: .65rem; font-weight: 700; cursor: pointer;
      flex-shrink: 0; user-select: none; transition: background .15s; }
    .info-pill:hover { background: var(--blue); color: #fff; }
    .info-box { display: none; background: var(--navy-900); border: 1px solid var(--brand-200);
      border-radius: 8px; padding: .75rem .875rem; font-size: .8rem; line-height: 1.6;
      color: var(--brand-600); margin-bottom: .5rem; }
    .info-box.open { display: block; }
    .info-box strong { color: var(--brand-800); display: block; margin-bottom: .25rem; }
    .info-box ul { margin: .375rem 0 0 1rem; padding: 0; }
    .info-box ul li { margin-bottom: .2rem; }

    /* ── Buttons ──────────────────────────────────────────────────── */
    .btn {
      display: inline-flex; align-items: center; gap: .4rem;
      padding: .625rem 1.25rem; border-radius: var(--radius);
      font-size: .9375rem; font-weight: 500; cursor: pointer;
      border: none; transition: background .2s ease, opacity .2s ease, transform .3s cubic-bezier(.2,.8,.2,1), box-shadow .25s ease;
      text-decoration: none; font-family: inherit;
    }
    .btn .material-symbols-outlined { font-size: 1rem; }
    .btn-primary { background: linear-gradient(135deg, var(--blue), var(--blue-dk)); color: #fff; box-shadow: 0 8px 22px -9px rgba(59,130,246,.6); }
    .btn-primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 12px 28px -9px rgba(59,130,246,.75); }
    .btn-secondary { background: var(--glass); color: var(--brand-700); border: 1px solid var(--brand-200); backdrop-filter: blur(10px); }
    .btn-secondary:hover:not(:disabled) { background: var(--glass-strong); color: var(--brand-900); border-color: var(--border-strong); }
    .btn:disabled { opacity: .4; cursor: not-allowed; }
    .btn-row { display: flex; gap: .75rem; margin-top: 1.25rem; align-items: center; }
    .mt1 { margin-top: 1rem; }
    .mt2 { margin-top: 2rem; }

    /* ── Auth screen ──────────────────────────────────────────────── */
    .auth-wrap { width: 100%; max-width: 440px; padding: 2rem 1.25rem; }
    .auth-hero { text-align: center; padding: 2rem 0 1.75rem; }
    .kr-brand { display: inline-flex; align-items: center; gap: .45rem; margin-bottom: 1.5rem; opacity: .6; }
    .kr-brand-name { font-family: 'Manrope', system-ui, sans-serif; font-weight: 800; font-size: .9rem; color: var(--brand-600); letter-spacing: -.01em; }
    .askme-mark { font-family: 'Manrope', system-ui, sans-serif; font-weight: 800; font-size: 2.5rem; color: var(--brand-900); letter-spacing: -.045em; line-height: 1; margin-bottom: .5rem; }
    .auth-card {
      background: var(--glass); border: 1px solid var(--border-strong); border-radius: 18px; padding: 1.75rem;
      backdrop-filter: blur(22px) saturate(160%); box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255,255,255,.07);
    }
    .auth-toggle { display: flex; border-bottom: 1px solid var(--brand-200); margin-bottom: 1.25rem; }
    .auth-toggle-btn {
      flex: 1; padding: .75rem; text-align: center; font-size: .9375rem; font-weight: 500;
      color: var(--brand-500); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
      background: none; border-top: none; border-left: none; border-right: none; font-family: inherit;
      transition: color .2s ease, border-color .2s ease;
    }
    .auth-toggle-btn.active { color: var(--blue); border-bottom-color: var(--blue); }

    /* ── Home screen ──────────────────────────────────────────────── */
    .home-page { max-width: 900px; margin: 0 auto; padding: 2.5rem 1.25rem; }
    .card {
      background: var(--glass); border: 1px solid var(--brand-200); border-radius: 16px; padding: 1.25rem;
      backdrop-filter: blur(16px) saturate(150%); transition: border-color .25s ease, background .25s ease;
    }
    .card + .card { margin-top: .75rem; }
    .nav-tabs { display: flex; border-bottom: 1px solid var(--brand-200); margin-bottom: 1.5rem; }
    .nav-tab {
      padding: .625rem 1.25rem; font-size: .9375rem; font-weight: 500;
      color: var(--brand-500); cursor: pointer; border-bottom: 2px solid transparent;
      margin-bottom: -1px; background: none; border-top: none; border-left: none; border-right: none;
      font-family: inherit; transition: color .2s ease, border-color .2s ease;
    }
    .nav-tab.active { color: var(--blue); border-bottom-color: var(--blue); }
    .course-group { margin-bottom: 1.5rem; position: relative; }
    .course-menu-wrap { position: relative; display: inline-flex; }
    .course-menu-btn {
      width: 1.75rem; height: 1.75rem; border-radius: 6px;
      border: 1px solid var(--brand-200); background: var(--glass);
      cursor: pointer; color: var(--brand-500);
      display: flex; align-items: center; justify-content: center;
      font-size: 1.125rem; line-height: 1; transition: background .15s ease, color .15s ease;
    }
    .course-menu-btn:hover { background: var(--glass-strong); color: var(--brand-900); }
    .course-menu-btn.open { background: var(--glass-strong); color: var(--brand-900); }
    .course-menu-dropdown {
      position: absolute; right: 0; top: calc(100% + 4px); z-index: 200;
      background: #1a1f2e; border: 1px solid var(--brand-200); border-radius: 10px;
      box-shadow: 0 8px 24px rgba(0,0,0,.45); padding: .375rem;
      min-width: 170px; display: none;
    }
    .course-menu-dropdown.open { display: block; }
    .course-menu-item {
      display: flex; align-items: center; gap: .625rem;
      padding: .5rem .75rem; border-radius: 6px; cursor: pointer;
      font-size: .875rem; color: var(--brand-700); font-family: inherit;
      background: none; border: none; width: 100%; text-align: left;
      transition: background .12s ease, color .12s ease;
    }
    .course-menu-item:hover { background: var(--glass-strong); color: var(--brand-900); }
    .course-menu-item .material-symbols-outlined { font-size: 1rem; color: var(--brand-500); }
    .course-group-title {
      font-size: .8125rem; font-weight: 700; text-transform: uppercase;
      letter-spacing: .06em; color: var(--brand-400); margin-bottom: .5rem;
    }
    .course-module-label {
      font-size: .72rem; font-weight: 600; text-transform: uppercase;
      letter-spacing: .07em; color: var(--brand-400); opacity: .7;
      padding: .625rem .875rem .25rem; margin-top: .25rem;
      display: flex; align-items: center; justify-content: space-between;
      cursor: pointer; user-select: none;
    }
    .course-module-label:hover { opacity: 1; }
    .module-chev { font-size: .85rem; opacity: .7; flex-shrink: 0; }
    .module-expand-controls {
      display: flex; gap: .5rem; padding: .5rem .875rem .25rem;
    }
    .module-expand-controls button {
      background: var(--glass); border: 1px solid var(--brand-200); border-radius: 999px;
      cursor: pointer; padding: .175rem .65rem;
      font-size: .68rem; font-weight: 600; text-transform: uppercase;
      letter-spacing: .06em; color: var(--brand-400); transition: background .12s, border-color .12s, color .12s;
    }
    .module-expand-controls button:hover { background: var(--glass-strong); border-color: var(--brand-300); color: var(--brand-600); }
    .activity-row {
      display: flex; align-items: center; gap: .75rem;
      padding: .625rem .875rem; background: var(--glass);
      border: 1px solid var(--brand-200); border-radius: var(--radius); margin-bottom: .375rem;
      backdrop-filter: blur(10px); transition: border-color .2s ease, background .2s ease;
    }
    .activity-row:hover { border-color: var(--border-strong); background: var(--glass-strong); }
    .activity-row-title { flex: 1; font-size: .9rem; font-weight: 500; }
    .act-rename-input { flex: 1; font-size: .9rem; font-weight: 500; width: 100%; border: 1px solid var(--brand-300); border-radius: 4px; padding: .125rem .375rem; background: var(--surface); color: var(--brand-900); outline: none; }
    .act-rename-input:focus { border-color: var(--brand-500); box-shadow: 0 0 0 2px var(--brand-100); }
    .activity-row-model {
      font-size: .75rem; color: var(--brand-400);
      background: var(--brand-100); padding: .1875rem .5rem; border-radius: 12px;
    }
    .activity-row-icon {
      width: 1.75rem; height: 1.75rem; border-radius: 6px; flex-shrink: 0;
      background: var(--brand-100); display: flex; align-items: center; justify-content: center;
      color: var(--brand-500);
    }
    .activity-row-icon .material-symbols-outlined { font-size: .9375rem; }
    .act-menu-wrap { display: inline-flex; flex-shrink: 0; }
    .act-menu-btn {
      width: 1.75rem; height: 1.75rem; border-radius: 6px;
      border: 1px solid transparent; background: none;
      cursor: pointer; color: var(--brand-400);
      display: flex; align-items: center; justify-content: center;
      font-size: 1.125rem; line-height: 1; transition: background .15s ease, color .15s ease, border-color .15s ease;
    }
    .act-menu-btn:hover { background: var(--glass-strong); color: var(--brand-900); border-color: var(--brand-200); }
    .act-menu-btn.open { background: var(--glass-strong); color: var(--brand-900); border-color: var(--brand-200); }
    #act-menu-popup {
      position: fixed; z-index: 9999; display: none;
      background: #1a1f2e; border: 1px solid var(--brand-200); border-radius: 10px;
      box-shadow: 0 8px 24px rgba(0,0,0,.45); padding: .375rem; min-width: 170px;
    }
    #act-menu-popup.open { display: block; }
    .act-menu-item {
      display: flex; align-items: center; gap: .625rem;
      padding: .5rem .75rem; border-radius: 6px; cursor: pointer;
      font-size: .875rem; color: var(--brand-700); font-family: inherit;
      background: none; border: none; width: 100%; text-align: left;
      transition: background .12s ease, color .12s ease;
    }
    .act-menu-item:hover { background: var(--glass-strong); color: var(--brand-900); }
    .act-menu-item.danger { color: var(--red); }
    .act-menu-item.danger:hover { background: rgba(239,68,68,.12); color: var(--red); }
    .act-menu-item .material-symbols-outlined { font-size: 1rem; color: var(--brand-500); }
    .act-menu-item.danger .material-symbols-outlined { color: var(--red); }
    .act-menu-sep { height: 1px; background: var(--brand-200); margin: .25rem 0; }
    .fb-type-btn { background: var(--surface-2,#0d1117); border: 1.5px solid var(--brand-200); border-radius: .375rem; color: var(--brand-500); cursor: pointer; font-size: .8125rem; font-weight: 600; padding: .375rem .875rem; transition: border-color .15s, color .15s, background .15s; }
    .fb-type-btn:hover { border-color: var(--blue); color: var(--blue); }
    .fb-type-btn.fb-type-active { border-color: var(--blue); color: var(--blue); background: rgba(96,165,250,.1); }

    /* ── Editor: sidebar ──────────────────────────────────────────── */
    #ed-sidebar {
      background: linear-gradient(180deg, var(--navy-900), var(--navy-950));
      border-right: 1px solid rgba(255,255,255,.08);
      display: flex; flex-direction: column;
      height: 100vh; overflow-y: auto; overflow-x: hidden;
      flex-shrink: 0; width: 220px;
    }
    .ed-sidebar-footer {
      flex-shrink: 0; padding: .875rem; border-top: 1px solid rgba(255,255,255,.07);
      display: flex; align-items: center; gap: 8px;
    }
    .ed-sidebar-footer img { width: 20px; height: 20px; object-fit: contain; border-radius: 5px; flex-shrink: 0; }
    .ed-sidebar-footer span { font-size: .7rem; color: rgba(255,255,255,.3); letter-spacing: .02em; }
    .ed-back {
      display: flex; align-items: center; gap: 8px;
      padding: 1rem .875rem; border-bottom: 1px solid rgba(255,255,255,.07);
      color: rgba(255,255,255,.45); font-size: .82rem; cursor: pointer;
      transition: color .15s; flex-shrink: 0; user-select: none;
    }
    .ed-back:hover { color: rgba(255,255,255,.85); }
    .ed-back .material-symbols-outlined { font-size: .9rem; }
    .wf-list { padding: .375rem 0; flex: 1; }
    .wf-divider {
      font-size: .68rem; font-weight: 800; text-transform: uppercase; letter-spacing: .1em;
      color: #60a5fa;
      margin: .75rem .375rem .25rem;
      padding: .4rem .75rem;
      border-left: 3px solid #60a5fa;
      background: var(--glass-strong);
      border-radius: 0 6px 6px 0;
    }
    .wf-btn {
      display: flex; align-items: center; gap: 9px;
      width: calc(100% - .75rem); margin: 1px .375rem;
      padding: .5rem .75rem; border: none; border-radius: 7px;
      background: none; cursor: pointer; font-family: inherit;
      color: rgba(255,255,255,.48); font-size: .8125rem; font-weight: 600;
      transition: background .15s, color .15s; text-align: left;
    }
    .wf-btn:hover:not(.disabled) { background: rgba(255,255,255,.07); color: rgba(255,255,255,.85); }
    .wf-btn.active { background: rgba(59,130,246,.28); color: #fff; }
    .wf-btn.disabled { opacity: .28; cursor: not-allowed; pointer-events: none; }
    .wf-num {
      width: 20px; height: 20px; border-radius: 50%; flex-shrink: 0;
      background: rgba(255,255,255,.1); color: rgba(255,255,255,.55);
      font-size: .69rem; font-weight: 800;
      display: flex; align-items: center; justify-content: center;
    }
    .wf-btn.active .wf-num { background: rgba(59,130,246,.6); color: #fff; }
    .wf-icon { font-size: 1rem !important; flex-shrink: 0; }
    .wf-label { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; flex: 1; }
    .wf-course {
      display: flex; align-items: center; gap: 9px;
      width: calc(100% - .75rem); margin: 1px .375rem;
      padding: .5rem .75rem; border-radius: 7px;
      background: rgba(255,255,255,.08);
      color: #fff; font-size: .8125rem; font-weight: 700;
      cursor: default; overflow: hidden;
    }
    .wf-course .wf-icon { color: #60a5fa; flex-shrink: 0; }
    .wf-course .wf-label,
    .wf-activity-meta .wf-label { overflow: visible; text-overflow: clip; }
    .wf-course:hover .wf-label,
    .wf-activity.visible:hover .wf-activity-meta .wf-label {
      animation: sidebar-scroll 3s .4s ease-in-out infinite;
    }
    @keyframes sidebar-scroll {
      0%, 15%  { transform: translateX(0); }
      70%, 100% { transform: translateX(var(--scroll-dist, 0px)); }
    }
    .wf-activity {
      display: none; align-items: center; gap: 9px;
      width: calc(100% - .75rem); margin: 1px .375rem;
      padding: .35rem .75rem; border-radius: 7px;
      color: rgba(255,255,255,.55); font-size: .775rem; font-weight: 600;
    }
    .wf-activity.visible { display: flex; }
    .wf-activity .wf-icon { color: rgba(255,255,255,.35); font-size: .9rem !important; flex-shrink: 0; }
    .wf-activity-meta { flex: 1; min-width: 0; overflow: hidden; display: flex; flex-direction: column; gap: .15rem; }
    .wf-activity-pill {
      font-size: .6rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
      color: rgba(255,255,255,.28); white-space: nowrap;
    }

    /* ── Editor: main area ────────────────────────────────────────── */
    #ed-main { position: relative; flex: 1; height: 100vh; overflow: hidden; }

    /* ── Slideout backdrop ────────────────────────────────────────── */
    #ed-backdrop {
      position: absolute; inset: 0; z-index: 10;
      background: rgba(3,5,10,.45); backdrop-filter: blur(2px);
      display: none; cursor: pointer;
    }
    #ed-backdrop.open { display: block; }

    /* ── Slideout drawer ──────────────────────────────────────────── */
    #ed-panels {
      position: absolute; top: 0; left: 0; height: 100%; width: 800px;
      background: rgba(11,15,30,.86); z-index: 20;
      display: flex; flex-direction: column; overflow: hidden;
      border-right: 1px solid var(--border-strong);
      box-shadow: 10px 0 40px rgba(0,0,0,.5);
      backdrop-filter: blur(26px) saturate(160%);
      transform: translateX(-100%);
      transition: transform .25s cubic-bezier(.4,0,.2,1);
    }
    #ed-panels.open { transform: translateX(0); }

    #slideout-header {
      display: flex; align-items: center; justify-content: space-between;
      padding: 1rem 1.25rem .875rem; border-bottom: 1px solid var(--brand-100);
      flex-shrink: 0;
    }
    #slideout-title { font-size: .9375rem; font-weight: 700; color: var(--brand-900); }
    .slideout-close {
      background: none; border: none; cursor: pointer; padding: .25rem;
      border-radius: 6px; color: var(--brand-400); display: flex; align-items: center;
      transition: background .15s, color .15s;
    }
    .slideout-close:hover { background: var(--brand-100); color: var(--brand-700); }
    .slideout-close .material-symbols-outlined { font-size: 1.1rem; }
    #slideout-body { flex: 1; overflow: hidden; display: flex; flex-direction: column; }

    .wf-panel { display: none; padding: 1.25rem 1.5rem 1.5rem; }
    .wf-panel.active { display: flex; flex-direction: column; flex: 1; overflow-y: auto; }
    /* Describe panel: form scrolls, Generate button stays pinned at bottom */
    #wfpanel-describe.active { overflow: hidden; padding: 0; }
    #describe-scroll { flex: 1; overflow-y: auto; padding: 1.25rem 1.5rem 1rem; }
    #describe-footer { flex-shrink: 0; padding: .75rem 1.5rem 1.25rem; border-top: 1px solid var(--border-strong); }
    #describe-footer .btn-row { margin-top: 0; }
    .panel-title { font-size: 1.0625rem; font-weight: 700; color: var(--brand-900); margin-bottom: .3rem; }
    .panel-sub { font-size: .8125rem; color: var(--brand-500); line-height: 1.55; margin-bottom: 1rem; }
    .optional-badge {
      font-size: .7rem; font-weight: 600; color: var(--brand-400);
      background: var(--brand-100); padding: .125rem .45rem;
      border-radius: 20px; margin-left: .3rem; vertical-align: middle;
    }

    /* ── Full-canvas preview ──────────────────────────────────────── */
    #ed-preview {
      position: absolute; inset: 0;
      display: flex; flex-direction: column; background: var(--navy-950);
    }
    #ed-preview-bar {
      background: rgba(255,255,255,.04); border-bottom: 1px solid var(--brand-200);
      padding: .5rem 1rem; display: flex; align-items: center; gap: .5rem;
      flex-shrink: 0; font-size: .78rem; font-weight: 600; color: var(--brand-500);
      backdrop-filter: blur(14px);
    }
    #ed-preview-bar .material-symbols-outlined { font-size: .95rem; }
    #preview-empty {
      flex: 1; display: flex; flex-direction: column;
      align-items: center; justify-content: center;
      gap: .5rem; color: var(--brand-400);
    }
    #preview-empty .material-symbols-outlined { font-size: 3rem; color: var(--brand-300); }
    #preview-empty p { font-size: .9rem; }
    #preview-empty p.hint { font-size: .8125rem; color: var(--brand-400); }
    #preview-generating {
      display: none; flex-direction: column; align-items: center;
      justify-content: center; flex: 1; gap: 1rem;
      background: var(--navy-950); font-size: .9rem; color: var(--brand-500);
    }
    .gen-loading-spinner { width: 28px; height: 28px; border: 3px solid var(--brand-200); border-top-color: var(--accent-600); border-radius: 50%; animation: spin .7s linear infinite; }
    .gen-stages { display: flex; flex-direction: column; gap: 7px; min-width: 200px; }
    .gen-stage-row { display: flex; align-items: center; gap: 9px; font-size: .76rem; }
    .gen-stage-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--brand-500); flex-shrink: 0; transition: background .2s; }
    .gen-stage-row.active .gen-stage-dot { background: var(--accent-400); box-shadow: 0 0 0 3px rgba(96,165,250,.2); }
    .gen-stage-row.done   .gen-stage-dot { background: var(--green); }
    .gen-stage-name { flex: 1; color: var(--brand-500); }
    .gen-stage-row.active .gen-stage-name { color: var(--brand-900); font-weight: 700; }
    .gen-stage-row.done   .gen-stage-name { color: var(--brand-800); }
    .gen-stage-time { font-variant-numeric: tabular-nums; font-size: .72rem; color: var(--brand-500); min-width: 38px; text-align: right; }
    .gen-stage-row.active .gen-stage-time { color: var(--accent-400); font-weight: 600; }
    .gen-stage-row.done   .gen-stage-time { color: var(--brand-700); }
    #preview-iframe { flex: 1; border: none; width: 100%; display: none; background: #fff; }

    /* ── Activity type grid ───────────────────────────────────────── */
    .type-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .75rem; }
    .type-card {
      border: 1px solid var(--brand-200); border-radius: 12px; padding: .875rem;
      cursor: pointer; background: var(--glass); backdrop-filter: blur(10px);
      transition: border-color .2s ease, background .2s ease;
      display: flex; flex-direction: column; align-items: flex-start;
    }
    .type-card:hover:not(.disabled) { border-color: var(--blue); background: var(--blue-lt); }
    .type-card.selected { border-color: var(--blue); background: var(--blue-lt); box-shadow: 0 0 0 1px var(--blue) inset; }
    .type-card.disabled { opacity: .4; cursor: not-allowed; }

    .type-card img { width: 44px; height: 44px; object-fit: contain; border-radius: 8px; margin-bottom: .5rem; display: block; }
    .type-card .type-icon-fallback { width: 44px; height: 44px; border-radius: 8px; margin-bottom: .5rem; background: rgba(99,102,241,.18); display: flex; align-items: center; justify-content: center; }
    .type-card .type-icon-fallback .material-symbols-outlined { font-size: 1.5rem; color: #818cf8; }
    .type-card .type-name { font-size: .875rem; font-weight: 600; margin-bottom: .2rem; }
    .type-card .type-desc { font-size: .75rem; color: var(--brand-500); line-height: 1.45; }
    .type-blurb { display: none; margin-top: .875rem; padding: .75rem 1rem; background: var(--blue-lt); border: 1px solid rgba(59,130,246,.3); border-radius: var(--radius); font-size: .8125rem; color: var(--brand-700); line-height: 1.55; }
    .type-blurb.active { display: block; }
    .sample-section { margin-top: 1rem; }
    .sample-label { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--brand-400); margin-bottom: .5rem; }
    .sample-card {
      padding: .625rem .875rem; margin-bottom: .5rem;
      border: 1px solid var(--brand-200); border-radius: var(--radius);
      font-size: .8125rem; color: var(--brand-600); line-height: 1.55;
      cursor: pointer; background: var(--glass); backdrop-filter: blur(8px);
      transition: border-color .2s ease, background .2s ease;
    }
    .sample-card:hover { border-color: var(--blue); background: var(--blue-lt); color: var(--brand-900); }

    /* ── Tweak bar ────────────────────────────────────────────────── */
    .tweak-label { font-size: .8125rem; font-weight: 500; color: var(--brand-500); margin-bottom: .5rem; }
    .tweak-presets { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .75rem; }
    .tweak-btn {
      padding: .375rem .875rem; border-radius: 20px; border: 1px solid rgba(255,255,255,.25);
      background: rgba(255,255,255,.1); color: var(--brand-900); font-size: .8125rem; cursor: pointer; font-family: inherit;
      backdrop-filter: blur(8px); transition: background .2s ease, border-color .2s ease, color .2s ease;
    }
    .tweak-btn:hover { background: var(--blue-lt); border-color: var(--blue); color: var(--blue); }
    .tweak-btn.selected { border-color: var(--blue); background: rgba(59,130,246,.15); color: var(--brand-900); }
    .tweak-custom { display: flex; gap: .5rem; }
    .tweak-custom input { flex: 1; }

    /* ── Prompt editor ────────────────────────────────────────────── */
    .prompt-field-label { font-size: .875rem; font-weight: 600; margin-bottom: .2rem; }
    .prompt-field-hint { font-size: .78rem; color: var(--brand-400); margin-bottom: .375rem; }
    .prompt-field textarea { font-size: .8125rem; min-height: 90px; }

    /* ── Embed blocks ─────────────────────────────────────────────── */
    .embed-block { background: var(--glass-strong); border: 1px solid var(--border-strong); border-radius: 12px; overflow: hidden; margin-top: .875rem; }
    .embed-label { display: flex; align-items: center; gap: .6rem; padding: .6rem 1rem; border-bottom: 1px solid var(--border-strong); border-left: 3px solid var(--accent-400); font-size: .68rem; font-weight: 800; color: var(--accent-400); text-transform: uppercase; letter-spacing: .1em; }
    .embed-url-row { display: flex; gap: .5rem; align-items: center; padding: .75rem 1rem; }
    .embed-url-row code { flex: 1; font-size: .78rem; background: var(--navy-950); border: 1px solid var(--brand-200); border-radius: 6px; padding: .375rem .625rem; word-break: break-all; color: var(--brand-700); }
    .embed-block > p { padding: 0 1rem .75rem; margin-top: 0; }

    /* ── Data tab ─────────────────────────────────────────────────── */
    .data-tabs { display: flex; border-bottom: 1px solid var(--brand-200); margin-bottom: 1.25rem; }
    .data-tab-btn {
      padding: .5rem 1rem; font-size: .875rem; font-weight: 500; color: var(--brand-500);
      cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
      background: none; border-top: none; border-left: none; border-right: none; font-family: inherit;
      transition: color .2s ease, border-color .2s ease;
    }
    .data-tab-btn.active { color: var(--blue); border-bottom-color: var(--blue); }
    .data-panel { display: none; }
    .data-panel.active { display: block; }
    .sub-split { display: flex; border: 1px solid var(--brand-200); border-radius: 14px; overflow: hidden; min-height: 420px; background: var(--glass); backdrop-filter: blur(14px); }
    .sub-list-pane { width: 300px; flex-shrink: 0; border-right: 1px solid var(--brand-200); overflow-y: auto; }
    .sub-detail-pane { flex: 1; padding: 1.25rem; overflow-y: auto; }
    .sub-item { padding: .75rem 1rem; cursor: pointer; border-bottom: 1px solid var(--brand-100); transition: background .2s ease; }
    .sub-item:hover, .sub-item.active { background: var(--blue-lt); }
    .sub-item-title { font-size: .8125rem; font-weight: 600; color: var(--brand-700); }
    .sub-item-email { font-size: .8rem; color: var(--brand-500); margin-top: .125rem; }
    .pii-email { transition: filter .15s ease; }
    .privacy-mode .pii-email { filter: blur(4px); user-select: none; cursor: pointer; }
    .privacy-mode .pii-email:hover { filter: none; }
    .sub-item-meta  { font-size: .75rem; color: var(--brand-400); margin-top: .25rem; }
    .sub-filter { padding: .5rem .875rem; border-bottom: 1px solid var(--brand-100); }
    .sub-filter input { padding: .375rem .625rem; font-size: .8125rem; }

    /* ── Misc ─────────────────────────────────────────────────────── */
    .notice { font-size: .875rem; color: var(--brand-500); line-height: 1.6; }
    .notice.err { color: var(--red); }
    .spinner {
      display: inline-block; width: 20px; height: 20px;
      border: 2px solid var(--brand-200); border-top-color: var(--blue);
      border-radius: 50%; animation: spin .7s linear infinite;
    }
    @keyframes spin { to { transform: rotate(360deg); } }
    @keyframes cc-apply-pulse { 0%,100% { box-shadow:0 0 0 0 rgba(96,165,250,0); } 50% { box-shadow:0 0 0 7px rgba(96,165,250,.35); } }
    .cc-apply-ready { animation: cc-apply-pulse 1.1s ease .4s 3; }
    .md-prose { font-size:.875rem; line-height:1.7; color:var(--brand-700); }
    .md-prose p { margin-bottom:.75rem; }
    .md-prose p:last-child { margin-bottom:0; }
    .md-prose strong { font-weight:600; color:var(--brand-900); }
    .md-prose ul,.md-prose ol { padding-left:1.25rem; margin-bottom:.75rem; }
    .md-prose li { margin-bottom:.25rem; }
    .md-prose hr { border:none; border-top:1px solid var(--brand-200); margin:.875rem 0; }
    .course-card { cursor: pointer; transition: border-color .2s ease, box-shadow .2s ease, background .2s ease; }
    .course-card:hover { border-color: var(--blue); background: var(--glass-strong); box-shadow: 0 0 0 3px rgba(59,130,246,.14); }

    /* ── Knowledge / Ingest ─────────────────────────────────────────── */
    .kn-table { width: 100%; border-collapse: collapse; font-size: .825rem; }
    .kn-table th { text-align: left; font-size: .69rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--brand-400); padding: .375rem .625rem; border-bottom: 1px solid var(--brand-200); }
    .kn-table td { padding: .5rem .625rem; border-bottom: 1px solid var(--brand-100); vertical-align: middle; }
    .kn-table tr:last-child td { border-bottom: none; }
    .kn-badge { display: inline-block; font-size: .72rem; font-weight: 500; padding: .1rem .5rem; border-radius: 20px; background: var(--brand-100); color: var(--brand-600); }
    .kn-drop-zone { border: 2px dashed var(--brand-200); border-radius: var(--radius); padding: 1.25rem; text-align: center; font-size: .85rem; color: var(--brand-400); cursor: pointer; transition: border-color .15s, background .15s; position: relative; }
    .kn-drop-zone:hover, .kn-drop-zone.drag-over { border-color: var(--blue); background: rgba(59,130,246,.04); color: var(--blue); }
    .kn-drop-zone input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
    .kn-extract-banner { display: none; border-radius: var(--radius); padding: .5rem .75rem; font-size: .8rem; margin-bottom: .75rem; }
    .kn-extract-banner.ok      { display: block; background: #ecfdf5; border: 1px solid #6ee7b7; color: #065f46; }
    .kn-extract-banner.warning { display: block; background: #fffbeb; border: 1px solid #fcd34d; color: #92400e; }
    .kn-word-count { font-size: .72rem; color: var(--brand-400); text-align: right; margin-top: 3px; }
    select.kn-select { width: 100%; padding: .5rem .75rem; border: 1px solid var(--brand-200); border-radius: var(--radius); font-size: .875rem; font-family: inherit; color: var(--brand-900); background: var(--glass); outline: none; cursor: pointer; }
    select.kn-select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(59,130,246,.2); }

    /* ── Organize Screen ───────────────────────────────────────────── */
    #organize-screen.active { display: block; min-height: 100vh; }
    .org-module {
      background: var(--glass); border: 1px solid var(--brand-200);
      border-radius: var(--radius); margin-bottom: 1rem; overflow: hidden;
    }
    .org-module.drag-over-module { border-color: var(--accent-600); }
    .org-module-header {
      display: flex; align-items: center; gap: .75rem;
      padding: .75rem 1rem; border-bottom: 1px solid var(--brand-100);
      cursor: grab;
    }
    .org-module-name {
      flex: 1; background: transparent; border: none; outline: none;
      font-family: var(--font, 'Instrument Sans', system-ui, sans-serif);
      font-size: .9rem; font-weight: 600; color: var(--brand-900);
      cursor: text;
    }
    .org-module-name:focus { color: var(--accent-400); }
    .org-drag-handle {
      color: var(--brand-400); font-size: 1.1rem; cursor: grab; flex-shrink: 0;
    }
    .org-module-delete {
      background: none; border: none; cursor: pointer;
      color: var(--brand-400); padding: .25rem; border-radius: 6px;
      display: flex; align-items: center; transition: color .15s;
    }
    .org-module-delete:not(.disabled):hover { color: var(--red); }
    .org-module-delete.disabled { opacity: .35; cursor: not-allowed; }
    .org-activity-list {
      min-height: 2.5rem; padding: .25rem 0;
      transition: background .15s;
    }
    .org-activity-list.drag-over { background: rgba(59,130,246,.08); }
    .org-activity {
      display: flex; align-items: center; gap: .625rem;
      padding: .5rem 1rem; cursor: grab; user-select: none;
    }
    .org-activity:hover { background: var(--glass-strong); }
    .org-activity.dragging { opacity: .4; }
    .org-activity-title { flex: 1; font-size: .875rem; font-weight: 500; color: var(--brand-800); }
    .org-unassigned .org-module-header { cursor: default; }
    .org-unassigned .org-drag-handle { visibility: hidden; }
    .org-drop-indicator {
      height: 3px; background: var(--accent-600); border-radius: 2px;
      margin: 2px 1rem; pointer-events: none;
      box-shadow: 0 0 6px rgba(59,130,246,.45);
    }
    .org-drop-indicator.org-drop-indicator--module {
      margin: 4px 0;
    }

    /* ── DnD tile manager dialog — hardcoded dark theme (immune to app2 light vars) ── */
    .tile-dialog-overlay {
      position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 9999;
      display: flex; align-items: center; justify-content: center;
    }
    .tile-dialog-box {
      background: #0f172a; border: 1px solid #334155;
      border-radius: 12px; width: min(900px,94vw); max-height: 80vh;
      display: flex; flex-direction: column; overflow: hidden;
    }
    .tile-dialog-header {
      display: flex; align-items: center; justify-content: space-between;
      padding: .75rem 1.25rem; border-bottom: 1px solid #334155;
    }
    .tile-dialog-header h3 { margin: 0; font-size: 1rem; font-weight: 600; color: #f1f5f9; }
    .tile-dialog-close { background: none; border: none; color: #94a3b8; font-size: 1.2rem; cursor: pointer; }
    /* Two-panel body */
    .tile-dialog-body {
      display: flex; flex-direction: row;
      padding: 0; overflow: hidden; min-height: 480px;
    }
    .tile-grid-panel {
      flex: 0 0 58%; overflow-y: auto; padding: .875rem;
      border-right: 1px solid #334155;
    }
    .tile-detail-panel-wrap {
      flex: 1; overflow-y: auto; padding: .875rem;
    }
    .tile-dialog-footer {
      padding: .75rem 1.25rem; border-top: 1px solid #334155;
      display: flex; align-items: center; justify-content: space-between;
    }
    .tile-dialog-count { font-size: .8rem; color: #94a3b8; }

    /* Simplified grid — 3 columns */
    .tile-manager-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: .5rem; }

    /* Tile card */
    .tile-slot {
      border: 2px solid #334155; border-radius: 8px;
      background: #1e293b; overflow: hidden;
      cursor: pointer; position: relative; display: flex; flex-direction: column;
    }
    .tile-slot.selected { border-color: #818cf8; }
    .tile-slot.drag-over { border-color: #38bdf8; }
    .tile-slot-img { width: 100%; height: 90px; object-fit: cover; display: block; pointer-events: none; }
    .tile-slot-caption-label {
      font-size: .72rem; color: #cbd5e1; padding: .25rem .4rem;
      border-top: 1px solid #334155;
      white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    }

    /* Add image slot */
    .tile-slot-add {
      border: 2px dashed #475569; border-radius: 8px;
      background: transparent; display: flex; align-items: center; justify-content: center;
      height: 115px;
      cursor: pointer; color: #94a3b8; flex-direction: column; gap: .25rem; font-size: .75rem;
    }
    .tile-slot-add:hover { border-color: #818cf8; color: #818cf8; }
    .tile-slot-add input { display: none; }
    .tile-slot-add .material-symbols-outlined { font-size: 1.5rem; }

    /* Detail panel */
    .tile-detail-empty {
      display: flex; flex-direction: column; align-items: center; justify-content: center;
      min-height: 200px; color: #64748b; font-size: .85rem; gap: .5rem; text-align: center;
    }
    .tile-detail-img-wrap {
      width: 100%; border-radius: 8px; overflow: hidden; margin-bottom: .75rem;
      background: #0f172a;
    }
    .tile-detail-img { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; }
    .tile-detail-caption-label {
      font-size: .68rem; color: #94a3b8; margin-bottom: .2rem; display: block;
    }
    .tile-dialog-box .tile-detail-caption {
      width: 100%; box-sizing: border-box; background: #1e293b;
      border: 1px solid #334155; border-radius: 6px;
      color: #f1f5f9; font-size: .8rem; padding: .375rem .5rem; outline: none;
      margin-bottom: .625rem; width: auto; box-shadow: none; backdrop-filter: none;
    }
    .tile-dialog-box .tile-detail-caption:focus { border-color: #818cf8; }
    .tile-detail-replace {
      display: block; font-size: .75rem; color: #94a3b8; cursor: pointer;
      padding: .375rem .5rem; border: 1px solid #334155; border-radius: 6px;
      text-align: center; margin-bottom: .5rem;
    }
    .tile-detail-replace:hover { color: #818cf8; border-color: #818cf8; }
    .tile-detail-replace input { display: none; }
    .tile-detail-delete {
      display: block; width: 100%; font-size: .75rem; color: #f87171;
      background: none; border: 1px solid #334155; border-radius: 6px;
      padding: .375rem .5rem; cursor: pointer; margin-top: .5rem; text-align: center;
    }
    .tile-detail-delete:hover { border-color: #f87171; background: rgba(248,113,113,.1); }

    /* Meta rows in detail panel */
    .tile-meta-section { margin-top: .625rem; }
    .tile-meta-row { display: flex; align-items: center; gap: .25rem; margin-bottom: .25rem; }
    .tile-dialog-box .tile-meta-key, .tile-dialog-box .tile-meta-val {
      flex: 1; background: #1e293b; border: none; border-radius: 4px;
      border-bottom: 1px solid #334155; color: #94a3b8;
      font-size: .72rem; padding: .2rem .3rem; outline: none; min-width: 0;
      width: auto; box-shadow: none; backdrop-filter: none;
    }
    .tile-meta-vis { cursor: pointer; color: #64748b; font-size: .85rem; flex-shrink: 0; }
    .tile-meta-vis.on { color: #34d399; }
    .tile-meta-del { cursor: pointer; color: #475569; font-size: .75rem; flex-shrink: 0; }
    .tile-meta-add { font-size: .68rem; color: #64748b; cursor: pointer; padding: .1rem 0; }
    .tile-meta-add:hover { color: #818cf8; }

    /* ── Activity History Drawer ───────────────────────────── */
    .app-history-overlay {
      display: none; position: fixed; inset: 0;
      background: rgba(0,0,0,.45); z-index: 1200;
    }
    .app-history-overlay.open { display: flex; align-items: stretch; justify-content: flex-end; }
    .app-history-drawer {
      width: 380px; max-width: 90vw; background: #1e293b;
      border-left: 1px solid #334155; display: flex; flex-direction: column; overflow: hidden;
    }
    .app-history-header {
      display: flex; align-items: center; justify-content: space-between;
      padding: 16px 20px; border-bottom: 1px solid #334155;
    }
    .app-history-title { font-size: .875rem; font-weight: 600; color: #f1f5f9; }
    .app-history-close {
      background: none; border: none; color: #94a3b8; cursor: pointer;
      font-size: 1rem; padding: 4px 8px;
    }
    .app-history-close:hover { color: #f1f5f9; }
    .app-history-list {
      flex: 1; overflow-y: auto; padding: 12px;
      display: flex; flex-direction: column; gap: 10px;
    }
    .app-history-empty { color: #64748b; font-size: .8rem; text-align: center; padding: 24px 0; }
    .app-history-entry {
      background: #0f172a; border: 1px solid #334155; border-radius: 8px; padding: 12px 14px;
    }
    .app-history-entry-header { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
    .app-history-rev {
      font-size: .75rem; font-weight: 700; color: #60a5fa;
      background: rgba(96,165,250,.12); border-radius: 4px; padding: 2px 7px;
    }
    .app-history-date { font-size: .72rem; color: #64748b; margin-left: auto; }
    .app-history-refine { font-size: .78rem; color: #94a3b8; margin-bottom: 4px; }
    .app-history-refine strong { color: #cbd5e1; }
    .app-history-guidance {
      font-size: .75rem; color: #64748b; font-style: italic; margin-bottom: 8px;
      white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    }
    .app-history-actions { display: flex; gap: 8px; }
    .app-history-btn {
      flex: 1; font-size: .75rem; padding: 5px 0; border-radius: 5px;
      border: 1px solid #334155; cursor: pointer; background: #1e293b; color: #94a3b8;
      transition: background .15s, color .15s;
    }
    .app-history-btn:hover { background: #334155; color: #f1f5f9; }
    .app-history-btn.restore { background: #1d4ed8; border-color: #2563eb; color: #fff; }
    .app-history-btn.restore:hover { background: #2563eb; }
    .app-history-entry-previewing {
      border-color: #3b82f6; box-shadow: 0 0 0 2px rgba(59,130,246,.25);
    }
    .app-history-warn-badge {
      font-size: .68rem; font-weight: 600; color: #b45309;
      background: #fef3c7; border: 1px solid #fcd34d; border-radius: 4px; padding: 1px 5px;
    }
    .app-history-trigger-btn {
      font-size: .75rem; color: #60a5fa; background: none; border: none;
      cursor: pointer; padding: 2px 0; display: inline-flex; align-items: center; gap: 4px;
    }
    .app-history-trigger-btn:hover { text-decoration: underline; }
