:root {
  --bg: #120e12;
  --surface: #1b161c;
  --surface-2: #241d26;
  --border: #362d34;
  --text: #e6e9f0;
  --text-dim: #9aa0b3;
  --accent: #fb7a5a;
  --accent-2: #ee6644;
  --success: #6ed09a;
  --warn: #ffb86b;
  --danger: #ff7676;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif; }

#app { display: flex; flex-direction: column; min-height: 100vh; }

/* Header */
.v3-header { display: flex; align-items: center; gap: 16px; padding: 12px 20px; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 10; }
.v3-header-left, .v3-header-right { display: flex; align-items: center; gap: 10px; }
.v3-header-state { display: flex; align-items: center; gap: 8px; flex: 1; justify-content: center; }
.brand { color: var(--text); font-weight: 700; text-decoration: none; font-size: 16px; }
.brand-tag { color: var(--accent); font-size: 11px; font-weight: 600; }
.curriculum-switcher { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; }
.state-label { color: var(--text-dim); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.state-badge { padding: 4px 10px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; font-size: 12px; }
.state-badge.empty { color: var(--text-dim); }
.state-badge.brief_collected { color: var(--warn); border-color: rgba(255,184,107,0.4); }
.state-badge.outline_drafted { color: var(--accent); border-color: rgba(251, 122, 90,0.4); }
.state-badge.outline_confirmed { color: var(--accent); border-color: rgba(251, 122, 90,0.4); }
.state-badge.content_in_progress { color: var(--warn); border-color: rgba(255,184,107,0.4); }
.state-badge.content_drafted { color: var(--success); border-color: rgba(110,208,154,0.4); }
.state-badge.version_published { color: var(--success); border-color: rgba(110,208,154,0.4); background: rgba(110,208,154,0.1); }
.next-action { color: var(--text-dim); font-size: 13px; max-width: 380px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Buttons */
button { font: inherit; cursor: pointer; border-radius: 8px; }
.primary-btn { background: var(--accent-2); color: white; border: none; padding: 9px 16px; font-weight: 600; border-radius: 8px; transition: background 0.15s, transform 0.05s; }
.primary-btn:hover:not(:disabled) { background: var(--accent); }
.primary-btn:active:not(:disabled) { transform: translateY(1px); }
.primary-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.ghost-btn { background: transparent; color: var(--text); border: 1px solid var(--border); padding: 7px 12px; font-size: 13px; border-radius: 8px; transition: background 0.15s, border-color 0.15s; }
.ghost-btn:hover { background: var(--surface-2); border-color: var(--text-dim); }
.danger-btn { background: rgba(255,118,118,0.15); color: var(--danger); border: 1px solid rgba(255,118,118,0.3); padding: 7px 12px; font-size: 13px; border-radius: 8px; }
.link-btn { background: none; border: none; color: var(--accent); padding: 0; }

/* Main layout */
.v3-main { display: grid; grid-template-columns: 1fr 380px; gap: 0; flex: 1; }
/* Aiko dock — the chat column is collapsed by default (see initAikoDock in
   the page JS). A floating launcher (.aiko-fab) reopens it. Collapsing the
   grid column lets the canvas reclaim the full width. */
.v3-main.chat-collapsed { grid-template-columns: 1fr; }
.chat-panel.collapsed { display: none; }

.canvas { padding: 24px 28px 72px; max-width: 1040px; margin: 0 auto; width: 100%; }

/* Cards */
.brief-card, .outline-card, .publish-card, .login-card, .lesson-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 20px;
  overflow: hidden;
  box-shadow: 0 4px 18px rgba(0,0,0,0.18);
}
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 15px 18px 12px; border-bottom: 1px solid var(--border); background: transparent; }
.card-title { font-weight: 600; font-size: 15px; letter-spacing: -0.01em; }
.card-body { padding: 18px; }

/* Empty / calm states — used across class + studio + home panels. */
.empty-state-line {
  text-align: center;
  color: var(--text-dim);
  padding: 44px 24px;
  font-size: 14px;
  line-height: 1.6;
}
.empty-state-line strong { color: var(--text); }

/* Floating Aiko launcher (shown when the dock is collapsed) */
.aiko-fab {
  position: fixed; right: 22px; bottom: 22px; z-index: 40;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 11px 18px; border-radius: 999px;
  border: 1px solid rgba(251,122,90,0.5);
  background: var(--accent-2); color: #fff; font-weight: 600; font-size: 14px;
  box-shadow: 0 12px 34px rgba(0,0,0,0.4); transition: background 0.15s, transform 0.08s;
}
.aiko-fab:hover { background: var(--accent); }
.aiko-fab:active { transform: translateY(1px); }
.aiko-fab[hidden] { display: none; }

.empty-hero { padding: 40px 0; text-align: center; }
.empty-hero h1 { font-size: 28px; margin: 0 0 12px 0; }
.empty-hero p { color: var(--text-dim); max-width: 460px; margin: 0 auto; }

.revision-lock-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
  padding: 16px 18px;
  border: 1px solid rgba(110,208,154,0.35);
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(110,208,154,0.11), rgba(251,122,90,0.05));
}
.revision-lock-banner[hidden] { display: none; }
.revision-lock-banner strong { color: var(--success); font-size: 15px; }
.revision-lock-banner p { margin: 3px 0 0; color: var(--text-dim); font-size: 13px; }
.course-readonly .brief-card input:disabled,
.course-readonly .brief-card textarea:disabled {
  opacity: 0.78;
  cursor: default;
}
.brief-card.readonly .drop-zone {
  border-style: solid;
  opacity: 0.72;
}
.lesson-card .readonly-pill {
  color: var(--success);
  border: 1px solid rgba(110,208,154,0.28);
  background: rgba(110,208,154,0.08);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  white-space: nowrap;
}

.login-card { max-width: 380px; margin: 40px auto; padding: 20px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; }
.login-card input { background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; color: var(--text); }
.error-text { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 1em; }

/* Brief */
.field-stack { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field-stack textarea, .brief-row input { background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 10px; color: var(--text); font: inherit; }
.brief-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.brief-row label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-dim); }
.brief-row input { color: var(--text); }

.drop-zone { border: 1px dashed var(--border); border-radius: 8px; padding: 14px; margin: 12px 0; background: rgba(255,255,255,0.02); }
.drop-zone.dragover { border-color: var(--accent); background: rgba(251, 122, 90,0.06); }
.drop-zone p { margin: 0 0 8px 0; color: var(--text-dim); }
.source-list { list-style: none; padding: 0; margin: 6px 0 0 0; }
.source-list li { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 13px; }
.source-list .badge { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--surface-2); }
.source-list .badge.ready { color: var(--success); border: 1px solid rgba(110,208,154,0.3); }
.source-list .badge.processing { color: var(--warn); border: 1px solid rgba(255,184,107,0.3); }
.source-list .badge.failed { color: var(--danger); border: 1px solid rgba(255,118,118,0.3); }

.inline-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.brief-suggest-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 6px 0 2px; }
.brief-suggest-row .helper-text { color: var(--muted, #8a93a6); font-size: 12px; }

/* Outline */
.outline-list { list-style: none; padding: 0; margin: 0 0 12px 0; }
.outline-list li { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 6px; }
.outline-list li:hover { background: var(--surface-2); }
.outline-list .ord { color: var(--text-dim); font-variant-numeric: tabular-nums; min-width: 24px; }
.outline-list .title-input { background: transparent; border: 1px solid transparent; color: var(--text); padding: 4px 6px; flex: 1; border-radius: 4px; font: inherit; }
.outline-list .title-input:focus { background: var(--surface-2); border-color: var(--border); outline: none; }
.outline-list .kind-pill { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: rgba(251, 122, 90,0.15); color: var(--accent); }
.outline-list .kind-pill.exam { background: rgba(255,184,107,0.15); color: var(--warn); }
.outline-list .remove-btn { background: transparent; border: none; color: var(--text-dim); cursor: pointer; padding: 2px 6px; font-size: 16px; }
.outline-list .remove-btn:hover { color: var(--danger); }

.grounded-badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 999px; margin: 6px 0 2px; }
.grounded-badge.high { background: rgba(94,200,142,0.16); color: var(--ok, #5ec88e); }
.grounded-badge.mid { background: rgba(255,184,107,0.16); color: var(--warn, #ffb86b); }
.grounded-badge.low { background: rgba(255,107,107,0.16); color: var(--danger, #ff6b6b); }
.grounded-badge.created { background: rgba(251, 122, 90,0.14); color: var(--accent); }


/* Lesson card */
.lesson-grid { display: flex; flex-direction: column; gap: 16px; }
.lesson-card { padding: 16px; position: relative; }
.lesson-card .lesson-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; gap: 12px; }
.lesson-card .lesson-head-actions { display: flex; gap: 6px; }
.lesson-card h3 { font-size: 15px; margin: 0; display: flex; align-items: center; gap: 8px; flex: 1; }
.lesson-card .status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.lesson-card .status-dot.queued { background: var(--text-dim); }
.lesson-card .status-dot.drafting { background: var(--warn); animation: pulse 1.5s infinite; }
.lesson-card .status-dot.ready { background: var(--success); }
.lesson-card .status-dot.failed { background: var(--danger); }
@keyframes pulse { 50% { opacity: 0.4; } }
.lesson-card .skeleton-block { background: var(--surface-2); border-radius: 4px; height: 12px; margin: 4px 0; animation: skel 1.5s ease-in-out infinite; }
.lesson-card .skeleton-block.long { width: 100%; }
.lesson-card .skeleton-block.med { width: 70%; }
.lesson-card .skeleton-block.short { width: 40%; }
@keyframes skel { 50% { opacity: 0.4; } }
.lesson-card .lesson-section { margin-top: 12px; position: relative; }
.lesson-card .lesson-section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.lesson-card .lesson-section-label { color: var(--text-dim); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.lesson-card .lesson-section p, .lesson-card .lesson-section li { margin: 4px 0; font-size: 13px; line-height: 1.55; }
.lesson-card .lesson-section ul { padding-left: 18px; }
.lesson-card .lesson-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.lesson-card .rewrite-btn { background: transparent; border: none; color: var(--accent); cursor: pointer; font-size: 12px; padding: 2px 6px; border-radius: 4px; opacity: 0.7; transition: opacity 0.15s; }
.lesson-card .rewrite-btn:hover { opacity: 1; background: rgba(251, 122, 90,0.08); }

/* Rewrite popover */
.rewrite-popover { background: var(--surface-2); border: 1px solid var(--accent); border-radius: 8px; padding: 8px; margin: 6px 0; display: flex; flex-direction: column; gap: 6px; box-shadow: 0 2px 8px rgba(0,0,0,0.3); }
.rewrite-popover input { background: var(--bg); border: 1px solid var(--border); border-radius: 4px; padding: 6px 8px; color: var(--text); font: inherit; }
.rewrite-popover .chips { display: flex; flex-wrap: wrap; gap: 4px; }
.rewrite-popover .chip { background: var(--bg); border: 1px solid var(--border); border-radius: 12px; padding: 2px 8px; font-size: 11px; cursor: pointer; color: var(--text-dim); }
.rewrite-popover .chip:hover { color: var(--accent); border-color: var(--accent); }
.rewrite-popover .actions { display: flex; gap: 6px; justify-content: flex-end; }
.rewrite-popover .actions button { font-size: 12px; padding: 4px 10px; }

/* Preview pane */
.v3-main.preview-on { grid-template-columns: 1fr 1fr 380px; }
.v3-main.preview-on.chat-collapsed { grid-template-columns: 1fr 1fr; }
.preview-pane { background: var(--bg); border-left: 1px solid var(--border); padding: 20px 20px; overflow-y: auto; position: sticky; top: 53px; height: calc(100vh - 53px); display: none; }
.v3-main.preview-on .preview-pane { display: block; }
.preview-pane h2 { font-size: 18px; margin: 0 0 10px 0; }
.preview-pane .preview-body { max-width: 640px; }
.preview-pane .preview-section { margin-top: 18px; padding: 12px; background: var(--surface); border-radius: 8px; }
.preview-pane .preview-section-title { font-weight: 600; font-size: 14px; margin-bottom: 6px; color: var(--accent); }
.preview-pane .preview-meta { color: var(--text-dim); font-size: 12px; }
/* Rendered markdown inside lesson cards + preview pane */
.preview-toggle-btn { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); padding: 6px 10px; border-radius: 6px; font-size: 13px; cursor: pointer; }
.preview-toggle-btn.active { background: var(--accent-2); color: white; border-color: var(--accent-2); }
.lesson-card .lesson-section h2,
.lesson-card .lesson-section h3,
.lesson-card .lesson-section h4,
.preview-item h2, .preview-item h3, .preview-item h4,
.preview-section h2, .preview-section h3, .preview-section h4 {
  margin: 8px 0 4px 0;
  color: var(--text);
  font-weight: 600;
}
.lesson-card .lesson-section h2, .preview-section h2 { font-size: 16px; }
.lesson-card .lesson-section h3, .preview-section h3 { font-size: 14px; }
.lesson-card .lesson-section h4, .preview-section h4 { font-size: 13px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.03em; }
.lesson-card .lesson-section code, .preview-item code, .preview-section code {
  background: var(--bg);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.92em;
  font-family: ui-monospace, "SF Mono", monospace;
}
.lesson-card .lesson-section pre, .preview-item pre, .preview-section pre {
  background: var(--bg);
  padding: 8px;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 12px;
}
.lesson-card .lesson-section blockquote, .preview-item blockquote, .preview-section blockquote {
  border-left: 3px solid var(--accent);
  margin: 6px 0;
  padding: 2px 10px;
  color: var(--text-dim);
}
.lesson-card .lesson-section table, .preview-section table, .preview-item table {
  border-collapse: collapse;
  font-size: 12px;
  margin: 6px 0;
}
.lesson-card .lesson-section table th, .preview-section table th, .preview-item table th,
.lesson-card .lesson-section table td, .preview-section table td, .preview-item table td {
  border: 1px solid var(--border);
  padding: 4px 8px;
}
/* KaTeX inline + display styling so it sits cleanly with surrounding text. */
.katex { font-size: 1.02em !important; }
.katex-display { margin: 8px 0 !important; padding: 4px 0; overflow-x: auto; }

/* Items on lesson cards */
.lesson-item-list { list-style: none; padding: 0; margin: 6px 0 0 0; }
.lesson-item-row { display: flex; align-items: center; gap: 10px; padding: 6px 8px; background: var(--surface-2); border-radius: 6px; margin: 4px 0; font-size: 13px; }
.lesson-item-row .item-kind { color: var(--text-dim); min-width: 90px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
.lesson-item-row .item-title { flex: 1; font-weight: 500; }
.lesson-item-row .item-meta { color: var(--text-dim); font-size: 12px; }
.lesson-item-row .item-meta.error { color: var(--danger); }
.lesson-item-row .ghost-btn.small { padding: 2px 8px; font-size: 11px; }

/* Preview item rendering */
.preview-item { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin: 8px 0; }
.preview-item.focus { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.preview-item-head { margin-bottom: 8px; }
.preview-q-list { padding-left: 20px; }
.preview-q-list ul.mc { list-style: lower-alpha; padding-left: 20px; }
.preview-item details { background: var(--bg); padding: 6px 10px; border-radius: 4px; margin: 6px 0; }
.preview-item details summary { cursor: pointer; color: var(--text-dim); font-size: 12px; }
.rubric-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 6px; }
.rubric-table th, .rubric-table td { border: 1px solid var(--border); padding: 6px 8px; vertical-align: top; }
.rubric-table th { background: var(--surface-2); text-align: left; }
.rubric-table ul { padding-left: 16px; margin: 0; }
.rubric { margin-top: 12px; }

.publish-warnings { margin-bottom: 12px; }
.publish-warnings .warn { color: var(--warn); font-size: 13px; padding: 4px 0; }
.publish-warnings .error { color: var(--danger); font-size: 13px; padding: 4px 0; }
.post-publish-cta { margin: 16px 0; padding: 14px; background: rgba(110,208,154,0.06); border: 1px solid rgba(110,208,154,0.25); border-radius: 8px; }
.post-publish-cta .published-banner { color: var(--success); margin: 0 0 10px 0; font-weight: 500; }
.version-list { list-style: none; padding: 0; margin-top: 12px; }
.version-list li { padding: 6px 0; font-size: 13px; color: var(--text-dim); }

/* Chat panel */
.chat-panel { border-left: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; position: sticky; top: 53px; height: calc(100vh - 53px); }
.chat-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.chat-messages { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.chat-msg { padding: 10px 12px; border-radius: 8px; max-width: 90%; font-size: 13px; line-height: 1.5; }
.chat-msg.user { background: var(--accent-2); color: white; align-self: flex-end; }
.chat-msg.assistant { background: var(--surface-2); }
.chat-msg.tool { background: rgba(255,184,107,0.08); color: var(--text-dim); font-size: 12px; font-family: ui-monospace, monospace; align-self: stretch; max-width: 100%; }
.chat-msg.thinking { border: 1px dashed var(--border); background: rgba(251, 122, 90,0.04); }
.thinking-head { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-dim); }
.dots { display: inline-flex; gap: 3px; }
.dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); display: inline-block; animation: dot-bounce 1.4s infinite ease-in-out both; }
.dots i:nth-child(1) { animation-delay: -0.32s; }
.dots i:nth-child(2) { animation-delay: -0.16s; }
@keyframes dot-bounce { 0%, 80%, 100% { transform: scale(0.4); opacity: 0.4; } 40% { transform: scale(1); opacity: 1; } }
.chat-msg.thinking .activity { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); font-size: 12px; font-family: ui-monospace, monospace; max-height: 220px; overflow-y: auto; }
.activity-line { display: flex; gap: 6px; align-items: flex-start; padding: 2px 0; }
.activity-line .icon { width: 14px; display: inline-block; text-align: center; }
.activity-line.running { color: var(--warn); }
.activity-line.ok { color: var(--success); }
.activity-line.fail { color: var(--danger); }
.chat-input-row { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border); }
.chat-input-row textarea { flex: 1; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; color: var(--text); font: inherit; resize: vertical; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--surface-2); border: 1px solid var(--border); padding: 10px 16px; border-radius: 8px; font-size: 13px; box-shadow: 0 4px 16px rgba(0,0,0,0.4); z-index: 100; }

/* ── Pending file-upload rows in the source list ─────────────────────── */
.source-list .pending-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}
.source-list .pending-row.uploading {
  color: var(--text-dim, #9aa);
}
.source-list .pending-row.failed {
  color: var(--danger, #f99);
}
.source-list .source-size {
  font-size: 11px;
  color: var(--text-dim, #9aa);
}
.source-list .x-btn {
  margin-left: auto;
  padding: 0 6px;
  font-size: 12px;
}
.spinner-inline {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--accent, #6cf);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Source preview ─────────────────────────────────────────────────── */
.source-name-btn {
  background: none;
  border: none;
  color: var(--text, #fff);
  font: inherit;
  cursor: pointer;
  padding: 0;
  text-align: left;
  text-decoration: underline dotted;
  text-decoration-color: rgba(255,255,255,0.3);
}
.source-name-btn:hover { color: var(--accent, #6cf); text-decoration-style: solid; }
.source-preview-card {
  max-width: 720px;
  width: 100%;
}
.source-preview-meta {
  font-size: 12px;
  color: var(--text-dim, #9aa);
  margin-bottom: 8px;
}
.source-preview-text {
  background: var(--surface-2, rgba(255,255,255,0.04));
  border: 1px solid var(--border, rgba(255,255,255,0.1));
  border-radius: 6px;
  padding: 12px;
  max-height: 400px;
  overflow-y: auto;
  font-family: ui-monospace, monospace;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── Version view modal ────────────────────────────────────────────── */
.version-view-card { max-width: 720px; width: 100%; }
.version-meta {
  font-size: 12px;
  color: var(--text-dim, #9aa);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border, rgba(255,255,255,0.08));
}
.version-lessons ol {
  padding-left: 22px;
  margin: 0;
}
.version-lessons li {
  padding: 8px 0;
  border-bottom: 1px solid var(--border, rgba(255,255,255,0.04));
}
.version-objective {
  font-size: 12px;
  color: var(--text-dim, #9aa);
  margin-top: 2px;
}

/* ── Aiko suggestion strip (above chat input) ──────────────────────────
 *
 * Renders a phase badge + 1 primary CTA + 2-3 secondary CTAs that map to
 * the current journey state. Hidden when teacher starts typing custom
 * prompt (so chips don't feel like a cage). Click → sends chip.intent as
 * a regular chat message.
 */
.aiko-suggest {
  border-top: 1px solid var(--border);
  padding: 10px 12px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: linear-gradient(180deg, rgba(251, 122, 90,0.03), transparent);
}
.aiko-phase {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.aiko-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 11px;
  color: var(--text);
  white-space: nowrap;
}
.aiko-badge.tone-running { border-color: rgba(255,184,107,0.5); color: var(--warn); }
.aiko-badge.tone-ready   { border-color: rgba(110,208,154,0.4); color: var(--success); }
.aiko-badge.tone-done    { border-color: rgba(110,208,154,0.6); color: var(--success); }
.aiko-phase-summary {
  font-size: 11px;
  color: var(--text-dim);
  flex: 1;
  line-height: 1.3;
}
.aiko-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.aiko-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 18px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s ease, transform 0.05s ease, border-color 0.12s ease;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.aiko-chip:hover { background: var(--surface); border-color: var(--accent); }
.aiko-chip:active { transform: translateY(1px); }
.aiko-chip.primary {
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  border-color: var(--accent);
  color: #0a0c11;
  font-weight: 600;
  padding: 8px 14px;
  font-size: 13px;
}
.aiko-chip.primary:hover { filter: brightness(1.08); }
.aiko-chip.tone-edit  { border-color: rgba(255,184,107,0.35); }
.aiko-chip.tone-info  { color: var(--text-dim); }
.aiko-chip[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  background: var(--surface-2);
  color: var(--text-dim);
  border-color: var(--border);
  font-weight: normal;
}
.aiko-chip-icon { font-size: 14px; line-height: 1; }
.aiko-chip-estimate {
  font-size: 10px;
  color: rgba(0,0,0,0.55);
  margin-left: 4px;
  font-weight: 500;
}
.aiko-chip:not(.primary) .aiko-chip-estimate { color: var(--text-dim); }

/* Aiko greeting bubble (rendered as a soft system-style message at top
 * of chat when there's no recent assistant message). */
.chat-msg.greeting {
  background: linear-gradient(135deg, rgba(251, 122, 90,0.08), rgba(251, 122, 90,0.02));
  border: 1px dashed rgba(251, 122, 90,0.4);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  color: var(--text);
}
.chat-msg.greeting strong { color: var(--accent); }

/* ── Chat-rendered markdown (assistant turns) — mirrors class.css ───── */
.chat-msg.assistant p { margin: 0 0 8px 0; }
.chat-msg.assistant p:last-child { margin-bottom: 0; }
.chat-msg.assistant h1,
.chat-msg.assistant h2,
.chat-msg.assistant h3 {
  margin: 8px 0 4px 0;
  font-size: 14px;
  color: var(--text);
}
.chat-msg.assistant ul,
.chat-msg.assistant ol { margin: 4px 0 8px 0; padding-left: 20px; }
.chat-msg.assistant li { margin: 2px 0; }
.chat-msg.assistant code {
  background: rgba(251, 122, 90,0.12);
  padding: 1px 4px;
  border-radius: 3px;
  font-family: ui-monospace, monospace;
  font-size: 12px;
}
.chat-msg.assistant pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px;
  margin: 6px 0;
  overflow-x: auto;
}
.chat-msg.assistant pre code { background: none; padding: 0; }
.chat-msg.assistant strong { color: var(--text); }
.chat-msg.assistant a { color: var(--accent); }
.chat-msg.assistant blockquote {
  border-left: 3px solid var(--border);
  padding-left: 10px;
  margin: 6px 0;
  color: var(--text-dim);
}
.chat-msg.assistant table { border-collapse: collapse; margin: 6px 0; font-size: 12px; }
.chat-msg.assistant th, .chat-msg.assistant td {
  border: 1px solid var(--border);
  padding: 4px 8px;
  text-align: left;
}
.chat-msg.assistant .katex-display { margin: 6px 0; }

/* ── Aiko focus bar (studio mirror of class.css) ──────────────────── */
.aiko-focus-bar {
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.aiko-focus-bar .aiko-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.aiko-focus-bar .aiko-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 4px 10px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
  line-height: 1.3;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.aiko-focus-bar .aiko-chip:hover:not([disabled]) {
  background: var(--bg);
  border-color: var(--accent);
  color: var(--accent);
}
.aiko-focus-bar .aiko-chip[disabled] { opacity: 0.4; cursor: default; }
.aiko-focus-line {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-dim);
  min-height: 16px;
}
.aiko-focus-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.aiko-focus-label.has-focus { color: var(--accent); }
.aiko-focus-clear {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0 4px;
}
.aiko-focus-clear:hover { color: var(--accent); }
[data-aiko-focus].aiko-focused {
  outline: 1px solid var(--accent);
  outline-offset: 1px;
}

/* ── Direct content editor (non-AI edit/delete) ─────────────────────────── */
.lesson-section-btns { display: flex; gap: 6px; }
.edit-btn {
  background: transparent; border: 1px solid var(--border); color: var(--text-dim);
  border-radius: 6px; padding: 2px 8px; font-size: 12px; cursor: pointer;
}
.edit-btn:hover { color: var(--text); border-color: var(--accent); }

.modal[hidden] { display: none !important; }
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; z-index: 60;
}
.modal-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); width: min(640px, 92vw); max-height: 90vh;
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.modal-head h3 { margin: 0; font-size: 16px; font-weight: 600; }
.modal-body { padding: 18px; display: flex; flex-direction: column; gap: 12px; overflow-y: auto; flex: 1; min-height: 0; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); flex-shrink: 0; }

.pack-edit-label { font-size: 12px; color: var(--text-dim); font-weight: 600; }
.pack-edit-textarea, .pack-edit-row input, .pack-edit-row textarea {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px 10px; color: var(--text); font: inherit;
  width: 100%; box-sizing: border-box; resize: vertical;
}
.pack-edit-rows { display: flex; flex-direction: column; gap: 14px; }
.pack-edit-row {
  display: flex; flex-direction: column; gap: 6px;
  border: 1px solid var(--border); border-radius: 8px; padding: 10px;
  background: var(--surface-2);
}
.pack-row-head { display: flex; align-items: center; justify-content: space-between; }
.prov-pill { font-size: 11px; padding: 1px 7px; border-radius: 10px; }
.prov-pill.source { background: rgba(56,189,248,0.15); color: #38bdf8; }
.prov-pill.ai { background: rgba(167,139,250,0.15); color: #a78bfa; }

/* ── Research (deep) overlay ─────────────────────────────────────────────── */
.research-panel { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; padding: 24px; background: rgba(9,7,9,0.6); backdrop-filter: blur(3px); }
.research-panel[hidden] { display: none; }
/* hidden must win over the flex/block display of children (.inline-actions etc.) */
.research-panel [hidden] { display: none !important; }
.research-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; width: 100%; max-width: 580px; max-height: 86vh; overflow-y: auto; box-shadow: 0 24px 60px rgba(0,0,0,0.45); }
.research-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); font-size: 15px; }
.research-body { padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; }
.research-body .field-stack { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-dim); }
.research-body textarea, .research-body input { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; color: var(--text); font: inherit; }

.research-ledger { display: flex; flex-direction: column; gap: 6px; }
.research-ledger .rl-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; font-size: 13px; }
.research-ledger .rl-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--text-dim); }
.research-ledger .rl-dot.running { background: var(--accent); box-shadow: 0 0 0 3px rgba(251,122,90,0.2); animation: rlPulse 1.3s ease-in-out infinite; }
.research-ledger .rl-dot.succeeded { background: var(--success); }
.research-ledger .rl-dot.failed { background: var(--danger); }
.research-ledger .rl-title { flex: 1; }
.research-ledger .rl-sum { color: var(--text-dim); font-size: 11px; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.research-ledger .rl-cites { color: var(--accent); font-size: 11px; }
@keyframes rlPulse { 0%,100% { opacity: 1; } 50% { opacity: 0.45; } }

.research-plan { border-top: 1px solid var(--border); padding-top: 14px; }
.research-plan-head { font-weight: 600; font-size: 14px; margin-bottom: 10px; }
.research-plan-list { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 8px; }
.research-plan-list li { font-size: 13px; }
.research-plan-list .rp-obj { color: var(--text-dim); font-size: 12px; margin-top: 2px; }
.research-status { color: var(--text-dim); font-size: 13px; margin: 0; }
.research-status[hidden] { display: none; }

/* Deep research mode toggle (setup card). */
.deep-toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-dim); cursor: pointer; user-select: none; padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-2); }
.deep-toggle input { accent-color: var(--accent-2); cursor: pointer; margin: 0; }
.deep-toggle[hidden] { display: none; }
.deep-toggle-status { font-size: 12px; color: var(--text-dim); align-self: center; }
.deep-toggle-status[hidden] { display: none; }

/* ── Lesson video lecture section ─────────────────────────────────────────── */
.lesson-video .lesson-section-label { color: var(--accent); }
.video-status { font-size: 13px; padding: 4px 0 2px; }
.video-status a { color: var(--accent); font-weight: 600; }
.video-working { color: var(--accent); }
.video-ready { color: #4caf82; font-weight: 600; }
.video-failed { color: var(--danger); }

/* "N videos generating" header indicator (studio + class) */
.video-gen-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600;
  color: var(--accent); text-decoration: none;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  border-radius: 999px; padding: 4px 10px;
  animation: videoGenPulse 1.8s ease-in-out infinite;
}
.video-gen-badge[hidden] { display: none; }
@keyframes videoGenPulse { 0%,100% { opacity: 1; } 50% { opacity: 0.6; } }

/* ── Teacher mobile layout ───────────────────────────────────────────── */
@media (max-width: 760px) {
  :is(.teacher-home, .teacher-studio, .teacher-class) {
    max-width: 100%;
    overflow-x: hidden;
  }

  :is(.teacher-home, .teacher-studio, .teacher-class) .v3-header {
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 10px;
  }
  .teacher-studio .v3-header-left,
  .teacher-class .v3-header-left {
    flex: 1 1 100%;
    min-width: 0;
    gap: 6px;
  }
  .teacher-studio .v3-header-state,
  .teacher-class .v3-header-state {
    order: 3;
    flex: 1 1 120px;
    min-width: 0;
    justify-content: flex-start;
  }
  .teacher-studio .v3-header-right,
  .teacher-class .v3-header-right {
    order: 4;
    margin-left: auto;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
  }
  .teacher-studio .curriculum-switcher {
    flex: 1;
    min-width: 0;
    max-width: none;
  }
  .teacher-studio .next-action {
    max-width: 100%;
    white-space: normal;
    line-height: 1.3;
    font-size: 11px;
  }

  :is(.teacher-studio, .teacher-class) .v3-main,
  :is(.teacher-studio, .teacher-class) .v3-main.chat-collapsed,
  :is(.teacher-studio, .teacher-class) .v3-main.preview-on,
  :is(.teacher-studio, .teacher-class) .v3-main.preview-on.chat-collapsed {
    display: block;
    min-width: 0;
  }
  :is(.teacher-studio, .teacher-class) .canvas {
    width: 100%;
    min-width: 0;
    padding: 16px 12px 96px;
  }
  :is(.teacher-studio, .teacher-class) .card-head {
    gap: 10px;
    padding: 13px 14px 11px;
    flex-wrap: wrap;
  }
  :is(.teacher-studio, .teacher-class) .card-body { padding: 14px; }
  .teacher-studio .brief-row { grid-template-columns: 1fr; gap: 10px; }
  .teacher-studio .revision-lock-banner {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
    padding: 14px;
  }
  .teacher-studio .revision-lock-banner .primary-btn { width: 100%; }
  .teacher-studio .outline-list li {
    align-items: flex-start;
    flex-wrap: wrap;
  }
  .teacher-studio .outline-list .title-input {
    flex: 1 1 calc(100% - 44px);
    min-width: 0;
  }
  .teacher-studio .lesson-card { padding: 14px; }
  .teacher-studio .lesson-card .lesson-head {
    align-items: flex-start;
    flex-direction: column;
  }
  .teacher-studio .lesson-card .lesson-head-actions {
    width: 100%;
    flex-wrap: wrap;
  }
  .teacher-studio .lesson-card .lesson-section-head {
    align-items: flex-start;
    flex-wrap: wrap;
  }
  .teacher-studio .lesson-item-row {
    align-items: flex-start;
    flex-wrap: wrap;
  }
  .teacher-studio .lesson-item-row .item-kind { min-width: 72px; }
  .teacher-studio .lesson-item-row .item-title { min-width: calc(100% - 100px); }
  .teacher-studio .lesson-item-row .item-meta { width: 100%; }
  .teacher-studio .lesson-card .lesson-section table,
  .teacher-studio .preview-section table,
  .teacher-studio .preview-item table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
  }

  /* Preview replaces the canvas on phones instead of creating another column. */
  .teacher-studio .v3-main.preview-on .canvas { display: none; }
  .teacher-studio .preview-pane {
    position: static;
    top: auto;
    width: 100%;
    height: auto;
    min-height: calc(100dvh - 112px);
    padding: 16px 14px 72px;
    border-left: 0;
  }

  /* Aiko opens as a contained sheet and keeps its own close control visible. */
  :is(.teacher-studio, .teacher-class) .chat-panel:not(.collapsed) {
    position: fixed;
    inset: 0 0 0 auto;
    z-index: 70;
    height: 100dvh;
    border-left: 1px solid var(--border);
    box-shadow: -12px 0 36px rgba(0,0,0,0.45);
  }
  /* Studio keeps a compact builder sheet on small tablets; Class chat is immersive. */
  .teacher-studio .chat-panel:not(.collapsed) { width: min(100vw, 420px); }
  .teacher-class .chat-panel:not(.collapsed) { width: 100vw; }
  :is(.teacher-studio, .teacher-class) .chat-head {
    padding-top: max(12px, env(safe-area-inset-top));
  }
  :is(.teacher-studio, .teacher-class) .chat-input-row {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
  :is(.teacher-studio, .teacher-class) .aiko-fab {
    right: 12px;
    bottom: max(12px, env(safe-area-inset-bottom));
    padding: 10px 14px;
  }

  :is(.teacher-home, .teacher-studio, .teacher-class) .modal {
    align-items: flex-end;
  }
  :is(.teacher-home, .teacher-studio, .teacher-class) .modal-card {
    width: 100%;
    max-width: none;
    max-height: 94dvh;
    border-radius: 16px 16px 0 0;
  }
  :is(.teacher-home, .teacher-studio, .teacher-class) .modal-body { padding: 14px; }
  :is(.teacher-home, .teacher-studio, .teacher-class) .modal-foot {
    padding: 10px 14px max(10px, env(safe-area-inset-bottom));
  }
  .teacher-studio .research-panel {
    align-items: flex-end;
    padding: 0;
  }
  .teacher-studio .research-card {
    max-width: none;
    max-height: 94dvh;
    border-radius: 16px 16px 0 0;
  }
}

@media (max-width: 480px) {
  .teacher-studio .v3-header-left {
    display: grid;
    grid-template-columns: auto auto minmax(0, 1fr) auto;
    width: 100%;
  }
  .teacher-studio .v3-header-left .brand,
  .teacher-studio .v3-header-left .ghost-btn,
  .teacher-studio .v3-header-left .curriculum-switcher {
    min-width: 0;
  }
  .teacher-studio .v3-header-right .ghost-btn,
  .teacher-studio .preview-toggle-btn {
    padding: 6px 9px;
    font-size: 12px;
  }
  .teacher-studio .brief-card .inline-actions > button,
  .teacher-studio .outline-card .inline-actions > .primary-btn,
  .teacher-studio .publish-card .inline-actions > .primary-btn {
    flex: 1 1 100%;
  }
  .teacher-studio .deep-toggle { width: 100%; }
  :is(.teacher-studio, .teacher-class) .chat-input-row textarea { min-width: 0; }
}
