/* ───────────── tokens ─────────────
   Quiet greys, one blue, and the paper itself in serif. */
:root {
  --bg: #f5f5f7;
  --panel: #ffffff;
  --panel-2: #f9f9fb;
  --line: #e8e8ed;
  --line-2: #d2d2d7;
  --text: #1d1d1f;
  --text-2: #6e6e73;
  --text-3: #a1a1a6;
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --on-accent: #ffffff;
  --accent-soft: #eaf3fe;
  --accent-ink: #0066cc;
  --focus-ring: rgba(0, 113, 227, 0.22);
  --switch: #34c759;
  --mint: #248a3d;
  --mint-soft: #e9f7ee;
  --amber: #b25000;
  --amber-soft: #fff4e5;
  --red: #d70015;
  --red-soft: #fdebed;
  --glass: rgba(251, 251, 253, 0.78);
  --shadow: 0 1px 1px rgba(0, 0, 0, 0.02), 0 2px 8px -2px rgba(0, 0, 0, 0.06);
  --shadow-pop: 0 24px 64px -16px rgba(0, 0, 0, 0.22), 0 2px 8px rgba(0, 0, 0, 0.06);
  --radius: 18px;
  --radius-sm: 12px;
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Inter', 'Segoe UI Variable Text', 'Segoe UI', system-ui, sans-serif;
  --display: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Inter', 'Segoe UI Variable Display', 'Segoe UI', system-ui, sans-serif;
  --mono: 'SF Mono', 'JetBrains Mono', ui-monospace, 'Cascadia Code', Consolas, monospace;
  --serif: 'Source Serif 4', 'New York', 'Iowan Old Style', Georgia, 'Times New Roman', serif;
  --ease: cubic-bezier(0.25, 0.1, 0.25, 1);
  --left-w: clamp(270px, 27vw, 380px);
  --right-w: 42%;
  --gap: 10px;
  --editor-size: 14px;

  /* editor syntax */
  --cm-bg: #ffffff;
  --cm-gutter: #ffffff;
  --cm-ln: #c7c7cc;
  --cm-active: #f7f7f9;
  --cm-sel: #d6e7fb;
  --cm-tag: #0066cc;
  --cm-bracket: #8e8e93;
  --cm-comment: #8e8e93;
  --cm-keyword: #ad3da4;
  --cm-string: #248a3d;
  --cm-number: #b25000;
  --cm-math: #0f7c8c;
  color-scheme: light;
}

[data-theme='dark'] {
  --bg: #000000;
  --panel: #1c1c1e;
  --panel-2: #232325;
  --line: #2c2c2e;
  --line-2: #3a3a3c;
  --text: #f5f5f7;
  --text-2: #a1a1a6;
  --text-3: #6e6e73;
  --accent: #0a84ff;
  --accent-hover: #409cff;
  --on-accent: #ffffff;
  --accent-soft: #0b2847;
  --accent-ink: #64aaff;
  --focus-ring: rgba(10, 132, 255, 0.35);
  --switch: #30d158;
  --mint: #30d158;
  --mint-soft: #10301b;
  --amber: #ff9f0a;
  --amber-soft: #352208;
  --red: #ff453a;
  --red-soft: #3a1513;
  --glass: rgba(28, 28, 30, 0.72);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  --shadow-pop: 0 28px 72px -16px rgba(0, 0, 0, 0.8), 0 2px 8px rgba(0, 0, 0, 0.5);

  --cm-bg: #1c1c1e;
  --cm-gutter: #1c1c1e;
  --cm-ln: #48484a;
  --cm-active: #232325;
  --cm-sel: #1f3b5c;
  --cm-tag: #64aaff;
  --cm-bracket: #8e8e93;
  --cm-comment: #6e6e73;
  --cm-keyword: #ff7ab2;
  --cm-string: #67d47a;
  --cm-number: #ffa94d;
  --cm-math: #5ed3e3;
  color-scheme: dark;
}

/* ───────────── base ───────────── */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.006em;
  text-rendering: optimizeLegibility;
}
b, strong { font-weight: 600; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input:focus-visible, textarea:focus-visible, select:focus-visible { outline: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
kbd {
  font-family: var(--mono); font-size: 11px; padding: 1px 6px; border-radius: 6px;
  background: var(--panel-2); border: 1px solid var(--line-2); box-shadow: 0 1px 0 var(--line-2);
}
[hidden] { display: none !important; }
.spacer { flex: 1; }
i[data-icon] { display: inline-flex; width: 16px; height: 16px; flex: none; }
i[data-icon] svg { width: 100%; height: 100%; }
.flip svg { transform: rotate(180deg); transition: transform 0.2s; }
::selection { background: var(--cm-sel); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 10px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ───────────── buttons ───────────── */
.icon-btn {
  width: 34px; height: 34px; border-radius: 10px; display: inline-grid; place-items: center;
  color: var(--text-2); transition: background 0.15s, color 0.15s, transform 0.1s;
}
.icon-btn.small { width: 30px; height: 30px; border-radius: 8px; }
.icon-btn:hover { background: color-mix(in srgb, var(--text) 6%, transparent); color: var(--text); }
.icon-btn:active { transform: scale(0.94); }
.chip-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px;
  border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line);
  color: var(--text-2); font-weight: 500; font-size: 13px; cursor: pointer; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.chip-btn:hover { background: color-mix(in srgb, var(--text) 6%, transparent); border-color: transparent; color: var(--text); }
.chip-btn.accent { background: var(--accent-soft); color: var(--accent-ink); border-color: transparent; }
.chip-btn.accent:hover { background: var(--accent); color: var(--on-accent); }
.btn-primary {
  display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 18px;
  background: var(--accent); color: var(--on-accent); font-weight: 500; letter-spacing: -0.01em;
  border-radius: 980px; white-space: nowrap;
  transition: background 0.2s var(--ease), transform 0.1s, opacity 0.2s;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: scale(0.97); }
.btn-primary[disabled] { opacity: 0.6; cursor: progress; }
.btn-ghost {
  height: 36px; padding: 0 16px; border-radius: 980px; font-weight: 500; color: var(--text);
  background: color-mix(in srgb, var(--text) 7%, transparent); border: 0;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; transition: background 0.2s;
}
.btn-ghost:hover { background: color-mix(in srgb, var(--text) 11%, transparent); }
.btn-danger { color: var(--red); }

/* ───────────── top bar ───────────── */
.topbar {
  display: flex; align-items: center; gap: 8px; padding: 0 16px;
  height: 52px; flex: none; position: relative; z-index: 5;
  background: var(--glass); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; padding-right: 8px; }
.brand img { border-radius: 7px; }
.brand-name { font: 600 16px/1 var(--display); letter-spacing: -0.022em; }
.project-btn { background: transparent; border-color: transparent; max-width: 260px; color: var(--text); font-weight: 500; }
.project-btn span { overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.save-status {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 500;
  color: var(--text-3); padding: 0 6px; transition: color 0.2s;
}
.save-status i { width: 14px; height: 14px; }
.save-status[data-state='dirty'] { color: var(--amber); }
.save-status[data-state='saving'] { color: var(--accent); }
.save-status[data-state='error'] { color: var(--red); }
.compile-group { display: flex; }
.compile-group .btn-primary:first-child { border-radius: 980px 0 0 980px; padding-right: 14px; }
.compile-group .caret { border-radius: 0 980px 980px 0; padding: 0 9px; border-left: 1px solid color-mix(in srgb, var(--on-accent) 25%, transparent); }
.compile-group .caret i { width: 14px; }
#compileBtn.busy i { animation: spin 0.9s linear infinite; }

/* ───────────── workspace ───────────── */
.workspace {
  flex: 1; min-height: 0; display: grid; padding: 12px 14px 14px;
  grid-template-columns: min(var(--left-w), 36vw) 6px minmax(0, 1fr) 6px min(var(--right-w), 52vw);
  gap: 0 4px;
}
.panel {
  background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden;
  border: 1px solid var(--line);
}
.panel-head {
  display: flex; align-items: center; gap: 4px; padding: 8px 10px 8px 14px; height: 46px; flex: none;
  border-bottom: 1px solid var(--line);
}
.gutter { cursor: col-resize; border-radius: 6px; position: relative; }
.gutter::after {
  content: ''; position: absolute; inset: 40% 2px; border-radius: 4px; background: var(--line-2);
  opacity: 0; transition: opacity 0.2s;
}
.gutter:hover::after, .gutter.dragging::after { opacity: 1; background: var(--accent); }
body.resizing { cursor: col-resize; user-select: none; }
body.resizing iframe, body.resizing .pdf-scroll { pointer-events: none; }

/* segmented tabs */
.seg { display: flex; gap: 4px; padding: 8px; flex: none; align-items: center; }
.seg-btn {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; border-radius: 11px; font-weight: 600; color: var(--text-3); transition: all 0.15s;
}
.seg-btn i { width: 15px; height: 15px; }
.seg-btn:hover { color: var(--text-2); background: var(--panel-2); }
.seg-btn.active { background: var(--accent-soft); color: var(--accent-ink); }
.seg.small { padding: 6px 10px; }
.seg.small .seg-btn { flex: none; height: 28px; padding: 0 12px; font-size: 12.5px; }

/* ───────────── chat ───────────── */
.side-panel { position: relative; }
.chat-view, .files-view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.chat-head { display: flex; gap: 6px; padding: 0 10px 8px; align-items: center; border-bottom: 1px solid var(--line); }
.model-pill {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 7px 10px 7px 12px;
  border-radius: 14px; background: var(--panel-2); border: 1px solid var(--line); text-align: left;
  transition: border-color 0.15s, background 0.15s;
}
.model-pill:hover { border-color: var(--line-2); background: var(--panel); }
.model-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.model-text b { font-size: 13px; }
.model-text small { font-size: 11.5px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-3); flex: none; box-shadow: 0 0 0 3px var(--panel-2); }
.dot.on { background: var(--mint); box-shadow: 0 0 0 3px var(--mint-soft); }
.dot.off { background: var(--amber); box-shadow: 0 0 0 3px var(--amber-soft); }

.messages { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 12px 6px; display: flex; flex-direction: column; gap: 12px; scroll-behavior: smooth; }
.msg { display: flex; flex-direction: column; gap: 6px; max-width: 100%; animation: pop 0.22s ease-out; }
.msg.user { align-items: flex-end; }
.bubble {
  padding: 10px 13px; border-radius: 16px; line-height: 1.55; font-size: 13.5px; word-wrap: break-word;
  overflow-wrap: anywhere; max-width: 100%;
}
.msg.user .bubble {
  background: var(--accent); color: var(--on-accent); border-radius: 18px 18px 6px 18px; white-space: pre-wrap;
}
.msg.assistant .bubble { background: color-mix(in srgb, var(--text) 5%, transparent); border-radius: 18px 18px 18px 6px; }
.msg-meta { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-3); font-weight: 500; padding: 0 4px; }
.msg-meta img { width: 16px; height: 16px; }
.msg-meta .ctx { background: var(--accent-soft); color: var(--accent-ink); border-radius: 999px; padding: 1px 8px; }
.bubble p { margin: 0 0 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 4px 0 8px; padding-left: 20px; }
.bubble h4 { margin: 8px 0 4px; font-size: 14px; }
.bubble code { font-family: var(--mono); font-size: 12px; background: var(--accent-soft); color: var(--accent-ink); padding: 1px 5px; border-radius: 6px; }
.bubble .err { color: var(--red); font-weight: 500; }
.typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); animation: bounce 1.1s infinite; }
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }

/* edit + code cards */
.card {
  border: 1px solid var(--line); border-radius: 14px; overflow: hidden; margin: 8px 0; background: var(--panel);
}
.card-head {
  display: flex; align-items: center; gap: 6px; padding: 6px 6px 6px 10px; font-size: 12px; font-weight: 600;
  color: var(--text-2); background: var(--panel-2); border-bottom: 1px solid var(--line);
}
.card-head > * { flex: none; white-space: nowrap; }
.card-head > .spacer { flex: 1; }
.card-head > .tag { flex: 0 1 auto; min-width: 0; }
.card-head i { width: 14px; height: 14px; }
.card-head .tag { font-weight: 500; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-head button {
  height: 26px; padding: 0 10px; border-radius: 9px; font-size: 12px; font-weight: 600;
  background: var(--accent-soft); color: var(--accent-ink);
}
.card-head button:hover { background: var(--accent); color: var(--on-accent); }
.card-head .state { font-size: 11.5px; padding: 2px 8px; border-radius: 999px; }
.card.applied .state { background: var(--mint-soft); color: var(--mint); }
.card.failed .state { background: var(--red-soft); color: var(--red); }
.card.reverted .state { background: var(--amber-soft); color: var(--amber); }
.diff, .code {
  margin: 0; font-family: var(--mono); font-size: 11.5px; line-height: 1.55; max-height: 260px; overflow: auto;
  padding: 6px 0;
}
.diff div, .code { white-space: pre-wrap; word-break: break-word; }
.diff div { padding: 0 10px 0 22px; position: relative; }
.diff div::before { position: absolute; left: 8px; color: var(--text-3); }
.diff .add { background: var(--mint-soft); }
.diff .add::before { content: '+'; color: var(--mint); }
.diff .del { background: var(--red-soft); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--red) 40%, transparent); }
.diff .del::before { content: '−'; color: var(--red); }
.diff .ctx { color: var(--text-3); }
.diff .gap { color: var(--text-3); text-align: center; padding: 0; }
.code { padding: 8px 12px; }
.card.pending .diff { opacity: 0.85; }

.msg-actions { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 2px; }
.msg-actions button { font-size: 11.5px; font-weight: 600; color: var(--text-3); padding: 3px 8px; border-radius: 8px; }
.msg-actions button:hover { background: var(--accent-soft); color: var(--accent-ink); }

/* empty chat */
.chat-empty { margin: auto 0; text-align: center; padding: 10px 8px 20px; }
.chat-empty img { width: 76px; height: 76px; }
.chat-empty h3 { margin: 10px 0 2px; font-size: 18px; font-weight: 600; }
.chat-empty p { margin: 0 0 16px; color: var(--text-2); }
.suggestions { display: flex; flex-direction: column; gap: 8px; }
.suggestion {
  text-align: left; padding: 10px 12px; border-radius: 14px; background: var(--panel-2); border: 1px solid var(--line);
  font-weight: 500; font-size: 13px; display: flex; gap: 10px; align-items: center; transition: all 0.15s;
}
.suggestion:hover { border-color: var(--line-2); background: var(--panel); transform: translateY(-1px); box-shadow: var(--shadow); }
.suggestion .emo { font-size: 17px; }

/* composer */
.composer {
  margin: 8px 10px 10px; border-radius: 20px; background: var(--panel); border: 1px solid var(--line-2);
  padding: 8px 8px 6px 12px; transition: border-color 0.15s, box-shadow 0.15s;
}
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--focus-ring); }
.composer textarea {
  width: 100%; border: 0; outline: 0; resize: none; background: transparent; line-height: 1.5;
  max-height: 180px; min-height: 22px; padding: 4px 0; font-size: 14px;
}
.composer textarea::placeholder { color: var(--text-3); }
.composer-foot { display: flex; align-items: center; gap: 8px; }
.hint { font-size: 11px; color: var(--text-3); flex: 1; text-align: right; white-space: nowrap; overflow: hidden; }
.send-btn {
  width: 32px; height: 32px; border-radius: 50%; background: var(--accent); color: var(--on-accent); display: grid; place-items: center;
  transition: transform 0.1s, background 0.15s; flex: none;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:active { transform: scale(0.92); }
.send-btn.stop { background: var(--red); color: #fff; }
.ctx-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.ctx-chips:not(:empty) { margin-bottom: 6px; }
.ctx-chip {
  display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; height: 24px; padding: 0 4px 0 9px;
  border-radius: 999px; background: var(--accent-soft); color: var(--accent-ink);
}
.ctx-chip.warn { background: var(--red-soft); color: var(--red); }
.ctx-chip.off { opacity: 0.45; text-decoration: line-through; }
.ctx-chip button { width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; }
.ctx-chip button:hover { background: rgba(0, 0, 0, 0.08); }
.ctx-chip i { width: 12px; height: 12px; }

/* toggle */
.toggle { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 500; color: var(--text-2); cursor: pointer; user-select: none; white-space: nowrap; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.toggle .track { width: 36px; height: 22px; border-radius: 999px; background: color-mix(in srgb, var(--text) 16%, transparent); position: relative; transition: background 0.25s var(--ease); flex: none; }
.toggle .track::after {
  content: ''; position: absolute; width: 18px; height: 18px; border-radius: 50%; background: #fff; top: 2px; left: 2px;
  transition: transform 0.25s var(--ease); box-shadow: 0 2px 4px rgba(0, 0, 0, 0.18), 0 0 0 0.5px rgba(0, 0, 0, 0.04);
}
.toggle input:checked + .track { background: var(--switch); }
.toggle input:checked + .track::after { transform: translateX(14px); }
.toggle input:focus-visible + .track { box-shadow: 0 0 0 3px var(--focus-ring); }

/* ───────────── files ───────────── */
.files-toolbar { display: flex; align-items: center; gap: 5px; padding: 0 10px 8px; border-bottom: 1px solid var(--line); }
.files-toolbar .chip-btn { padding: 0 9px; gap: 5px; font-size: 12.5px; }
.file-list { list-style: none; margin: 0; padding: 8px; overflow-y: auto; flex: 1; }
.tree-row {
  display: flex; align-items: center; gap: 6px; min-height: 32px; padding: 3px 6px 3px calc(4px + var(--depth, 0) * 16px); border-radius: 9px; cursor: pointer;
  font-weight: 500; color: var(--text-2); font-size: 13px; outline: none; user-select: none;
}
.tree-row > i { width: 15px; height: 15px; }
.tree-row:hover { background: var(--panel-2); }
.tree-row:focus-visible { box-shadow: inset 0 0 0 2px var(--text-3); }
.tree-row.active { background: var(--accent-soft); color: var(--accent-ink); }
.tree-row.dragging { opacity: 0.45; }
.tree-row.drop-target { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--text); color: var(--text); }
.file-list.drop-root { box-shadow: inset 0 0 0 2px var(--line-2); border-radius: 12px; }
.folder-row { color: var(--text); }
.twist { width: 16px; height: 16px; display: inline-grid; place-items: center; flex: none; color: var(--text-3); }
.twist i { width: 13px; height: 13px; transform: rotate(-90deg); transition: transform 0.12s; }
.twist.open i { transform: none; }
.tree-row .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-row .size { font-size: 11px; color: var(--text-3); font-weight: 600; white-space: nowrap; }
.tree-row .acts { display: none; gap: 1px; }
.tree-row:hover .acts:not([hidden]), .tree-row:focus-within .acts:not([hidden]) { display: flex; }
.tree-row:hover .acts:not([hidden]) ~ .size, .tree-row:focus-within .acts:not([hidden]) ~ .size { display: none; }
.tree-row .acts button { width: 24px; height: 24px; border-radius: 7px; display: grid; place-items: center; color: var(--text-3); }
.tree-row .acts button:hover { background: var(--panel); color: var(--accent-ink); }
.tree-row .acts i { width: 13px; height: 13px; }
.tree-empty { color: var(--text-3); font-size: 13px; padding: 16px 8px; text-align: center; }
.files-filter {
  display: flex; align-items: center; gap: 7px; margin: 8px 10px 0; padding: 0 10px; height: 34px; border-radius: 10px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text-3);
}
.files-filter:focus-within { border-color: var(--text-3); }
.files-filter i { width: 14px; height: 14px; flex: none; }
.files-filter input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font-size: 13px; color: var(--text); }
.file-item .main-star { color: var(--amber); }
.file-item .main-star i { width: 14px; height: 14px; }
.files-tip { font-size: 12px; color: var(--text-3); padding: 0 16px 14px; margin: 0; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.files-tip i { width: 12px; height: 12px; color: var(--amber); }
.files-view.drop { outline: 2px dashed var(--accent); outline-offset: -8px; border-radius: var(--radius); }

/* ───────────── editor ───────────── */
.file-tab {
  display: inline-flex; align-items: center; gap: 7px; font-weight: 600; padding: 6px 12px; border-radius: 11px;
  background: var(--accent-soft); color: var(--accent-ink); font-size: 13px; max-width: 60%;
}
.file-tab span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-tab i { width: 14px; height: 14px; }
.dirty-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--amber); opacity: 0; transition: opacity 0.2s; flex: none; }
.dirty-dot.on { opacity: 1; }
.editor-host { flex: 1; min-height: 0; position: relative; }
.editor-host .CodeMirror { position: absolute; inset: 0; height: auto; }
.statusbar {
  display: flex; gap: 14px; align-items: center; padding: 6px 14px; font-size: 11.5px; font-weight: 500; color: var(--text-3);
  border-top: 1px solid var(--line); flex: none;
}
.statusbar span { white-space: nowrap; }
.editor-panel, .pdf-panel { container-type: inline-size; }
@container (max-width: 340px) {
  #undoBtn, #redoBtn, #wordCount, #engineLabel { display: none; }
}
@container (max-width: 300px) {
  #zoomOutBtn, #zoomInBtn { display: none; }
}
#engineLabel { background: var(--panel-2); padding: 1px 8px; border-radius: 999px; border: 1px solid var(--line); }

.CodeMirror {
  font-family: var(--mono); font-size: var(--editor-size); line-height: 1.65; background: var(--cm-bg); color: var(--text);
}
.CodeMirror-gutters { background: var(--cm-gutter); border-right: 1px solid var(--line); }
.CodeMirror-linenumber { color: var(--cm-ln); padding: 0 10px 0 6px; font-size: 12px; }
.CodeMirror-cursor { border-left: 2px solid var(--text); }
.CodeMirror-activeline-background { background: var(--cm-active); }
.CodeMirror-activeline-gutter { background: var(--cm-active); }
.CodeMirror-activeline .CodeMirror-linenumber { color: var(--text); font-weight: 500; }
.CodeMirror-selected, .CodeMirror-focused .CodeMirror-selected { background: var(--cm-sel) !important; }
.CodeMirror-line::selection, .CodeMirror-line > span::selection, .CodeMirror-line > span > span::selection { background: var(--cm-sel); }
.CodeMirror-lines { padding: 10px 0; }
.CodeMirror pre.CodeMirror-line, .CodeMirror pre.CodeMirror-line-like { padding: 0 14px; }
.CodeMirror-matchingbracket { color: var(--text) !important; background: var(--cm-sel); border-radius: 3px; }
.cm-s-default .cm-tag { color: var(--cm-tag); font-weight: 500; }
.cm-s-default .cm-bracket { color: var(--cm-bracket); }
.cm-s-default .cm-comment { color: var(--cm-comment); font-style: italic; }
.cm-s-default .cm-keyword { color: var(--cm-keyword); }
.cm-s-default .cm-atom { color: var(--cm-string); }
.cm-s-default .cm-string { color: var(--cm-string); }
.cm-s-default .cm-number { color: var(--cm-number); }
.cm-s-default .cm-variable-2 { color: var(--cm-math); }
.cm-s-default .cm-builtin { color: var(--cm-number); }
.cm-s-default .cm-error { color: var(--red); }
.CodeMirror-gutter.pw-errors { width: 14px; }
.err-marker { width: 8px; height: 8px; border-radius: 50%; background: var(--red); margin: 7px 0 0 3px; box-shadow: 0 0 0 3px var(--red-soft); }
.err-marker.warn { background: var(--amber); box-shadow: 0 0 0 3px var(--amber-soft); }
.line-error { background: color-mix(in srgb, var(--red-soft) 70%, transparent); }
.ai-flash { background: color-mix(in srgb, var(--mint) 22%, transparent); border-radius: 3px; transition: background 1s; }
.CodeMirror-dialog { background: var(--panel-2); color: var(--text); border-color: var(--line) !important; font-family: var(--font); padding: 6px 12px; }
.CodeMirror-dialog input { font-family: var(--mono); background: var(--panel); border: 1px solid var(--line) !important; border-radius: 8px; padding: 3px 8px; }
.CodeMirror-search-match { background: var(--amber-soft); border-radius: 2px; }

/* ───────────── pdf ───────────── */
.page-ind { font-size: 12.5px; font-weight: 600; color: var(--text-2); padding-left: 2px; }
.zoom-label { min-width: 62px; justify-content: center; height: 28px; }
.pdf-scroll { flex: 1; min-height: 0; overflow: auto; position: relative; background: var(--panel-2); }
.pdf-pages { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 16px; min-width: min-content; }
.pdf-page { background: #fff; border-radius: 6px; box-shadow: 0 2px 4px rgba(40, 20, 80, 0.06), 0 12px 30px -14px rgba(40, 20, 80, 0.3); overflow: hidden; line-height: 0; }
[data-theme='dark'] .pdf-page { box-shadow: 0 12px 30px -10px rgba(0, 0, 0, 0.7); }
.pdf-empty {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; color: var(--text-2); padding: 20px; overflow: auto;
}
.pdf-empty > * { max-width: 360px; }
.pdf-empty img { margin: 0 auto 6px; }
.pdf-empty h3 { margin: 4px 0 2px; color: var(--text); font-weight: 600; }
.pdf-empty p { margin: 4px 0 14px; }
.pdf-empty .btn-primary, .pdf-empty .btn-ghost { margin: 4px auto 0; }
.pdf-empty .actions { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.pdf-busy {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%); display: inline-flex; align-items: center; gap: 10px;
  background: var(--panel); padding: 8px 16px 8px 12px; border-radius: 999px; box-shadow: var(--shadow-pop); font-weight: 600; font-size: 13px;
  z-index: 3; animation: pop 0.2s ease-out; white-space: nowrap;
}
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--text); animation: spin 0.8s linear infinite; flex: none; }

/* log drawer */
.log-drawer { border-top: 1px solid var(--line); flex: none; display: flex; flex-direction: column; max-height: 45%; }
.log-bar { display: flex; align-items: center; gap: 8px; padding: 9px 14px; font-weight: 600; font-size: 12.5px; text-align: left; width: 100%; }
.log-bar:hover { background: var(--panel-2); }
.log-state { display: inline-flex; align-items: center; gap: 7px; color: var(--text-2); }
.log-state i { width: 15px; height: 15px; }
.log-state.ok { color: var(--mint); }
.log-state.err { color: var(--red); }
.log-state.warn { color: var(--amber); }
.log-body { display: none; flex-direction: column; min-height: 0; border-top: 1px solid var(--line); }
.log-drawer.open .log-body { display: flex; height: 260px; }
.log-drawer.open .log-bar .flip svg { transform: rotate(0deg); }
.issue-list { list-style: none; margin: 0; padding: 4px 8px 10px; overflow: auto; flex: 1; }
.issue { display: flex; gap: 10px; padding: 8px 10px; border-radius: 11px; cursor: pointer; font-size: 12.5px; align-items: flex-start; }
.issue:hover { background: var(--panel-2); }
.issue .badge { font-family: var(--mono); font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 7px; background: var(--red-soft); color: var(--red); flex: none; }
.issue.warn .badge { background: var(--amber-soft); color: var(--amber); }
.issue .text { line-height: 1.45; word-break: break-word; }
.issue-empty { color: var(--text-3); padding: 14px; text-align: center; font-weight: 500; }
.raw-log { margin: 0; padding: 10px 14px; overflow: auto; flex: 1; font-family: var(--mono); font-size: 11px; line-height: 1.5; color: var(--text-2); white-space: pre-wrap; word-break: break-all; }

/* ───────────── popover & modal ───────────── */
.popover {
  position: fixed; z-index: 50; background: var(--glass); -webkit-backdrop-filter: saturate(180%) blur(30px); backdrop-filter: saturate(180%) blur(30px);
  border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow-pop); padding: 8px; min-width: 240px; max-width: calc(100vw - 20px);
  max-height: min(70vh, 560px); overflow: auto; animation: pop 0.16s ease-out;
}
.pop-title { font-size: 12px; font-weight: 600; color: var(--text-2); padding: 8px 10px 4px; }
.pop-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 10px; border-radius: 8px; text-align: left;
  font-weight: 400; font-size: 13.5px;
}
.pop-item:hover { background: var(--accent); color: #fff; }
.pop-item:hover .sub, .pop-item:hover i { color: inherit; }
.pop-item.active { background: var(--accent-soft); color: var(--accent-ink); }
.pop-item .sub { display: block; font-size: 11.5px; font-weight: 600; color: var(--text-3); }
.pop-item .grow { flex: 1; min-width: 0; }
.pop-item .grow > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pop-item .check { color: var(--accent); }
.pop-item.disabled { opacity: 0.55; }
.pop-sep { height: 1px; background: var(--line); margin: 6px 4px; }
.pop-row { display: flex; gap: 6px; padding: 6px 4px; }
.input {
  width: 100%; height: 36px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--panel);
  padding: 0 12px; outline: 0; transition: border-color 0.15s, box-shadow 0.15s; font-size: 13.5px; min-width: 0;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--focus-ring); }
select.input { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%), linear-gradient(135deg, var(--text-3) 50%, transparent 50%); background-position: calc(100% - 17px) 16px, calc(100% - 12px) 16px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 28px; }
.model-pop { width: 360px; }
.provider-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 4px; }
.prov {
  display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: 13px; border: 1.5px solid var(--line);
  text-align: left; font-weight: 600; font-size: 12.5px; background: var(--panel-2); min-width: 0;
}
.prov span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prov:hover { border-color: var(--line-2); background: var(--panel); }
.prov.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); }
.prov .dot { box-shadow: none; }
.prov-detail { font-size: 12px; color: var(--text-2); padding: 6px 10px 2px; font-weight: 600; }
.prov-detail a { cursor: pointer; font-weight: 600; }
.model-list { max-height: 220px; overflow: auto; }

.modal-backdrop {
  position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, 0.28); -webkit-backdrop-filter: blur(14px) saturate(140%); backdrop-filter: blur(14px) saturate(140%);
  display: grid; place-items: center; padding: 16px; animation: fade 0.15s ease-out;
}
.modal {
  width: min(640px, 100%); max-height: min(88vh, 860px); overflow: auto; background: var(--panel); border-radius: 24px;
  box-shadow: var(--shadow-pop); border: 1px solid var(--line); animation: pop 0.2s ease-out;
}
.modal-head { display: flex; align-items: center; gap: 12px; padding: 18px 18px 8px 22px; position: sticky; top: 0; background: var(--panel); z-index: 1; }
.modal-head h2 { margin: 0; font: 700 22px/1.2 var(--display); letter-spacing: -0.022em; flex: 1; }
.modal-head img { width: 30px; height: 30px; border-radius: 7px; }
.modal-body { padding: 4px 22px 22px; }
.modal-section { margin-top: 18px; }
.modal-section h3 { margin: 0 0 10px; font-size: 15px; color: var(--text); font-weight: 600; letter-spacing: -0.01em; }
.setting-card { border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; margin-bottom: 10px; background: var(--panel-2); }
.setting-row { display: flex; align-items: center; gap: 10px; }
.setting-row + .setting-row { margin-top: 8px; }
.setting-row .label { flex: 1; min-width: 0; }
.setting-row .label b { display: block; font-size: 14px; }
.setting-row .label small { display: block; color: var(--text-2); font-size: 12px; font-weight: 600; overflow-wrap: anywhere; }
.badge-pill { font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--line); color: var(--text-2); white-space: nowrap; }
.badge-pill.ok { background: var(--mint-soft); color: var(--mint); }
.badge-pill.warn { background: var(--amber-soft); color: var(--amber); }
.key-row { display: flex; gap: 6px; margin-top: 8px; }
.key-row .input { flex: 1; font-family: var(--mono); font-size: 12.5px; }
.engine-grid { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.note { font-size: 12px; color: var(--text-2); margin: 8px 0 0; line-height: 1.5; }
.note code { font-family: var(--mono); font-size: 11.5px; background: var(--accent-soft); color: var(--accent-ink); padding: 1px 5px; border-radius: 5px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 0 22px 20px; }

/* toasts */
.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 10px; background: color-mix(in srgb, var(--text) 92%, transparent); color: var(--bg);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px); padding: 10px 16px; border-radius: 999px;
  font-weight: 500; font-size: 13px; box-shadow: var(--shadow-pop); animation: toastIn 0.25s cubic-bezier(0.3, 1.4, 0.6, 1); max-width: calc(100vw - 32px);
  pointer-events: auto;
}
.toast.err { background: var(--red); color: #fff; }
.toast.ok { background: color-mix(in srgb, var(--text) 92%, transparent); color: var(--bg); }
.toast.ok i { color: var(--switch); }
.toast i { width: 16px; height: 16px; }
.toast.out { animation: toastOut 0.2s ease-in forwards; }

/* mobile nav */
.mobile-nav { display: none; }

/* ───────────── collaboration ───────────── */
.share-btn { display: inline-flex; align-items: center; gap: 7px; height: 38px; }
.share-btn i { width: 16px; height: 16px; }
.presence { display: flex; align-items: center; padding-right: 2px; }
.presence .avatar + .avatar { margin-left: -8px; }
.avatar {
  --c: #71717a;
  width: 30px; height: 30px; border-radius: 50%; display: inline-grid; place-items: center; flex: none;
  background: var(--c); color: #fff; font-size: 11.5px; font-weight: 600; letter-spacing: 0.3px;
  border: 2px solid var(--bg); user-select: none;
}
.avatar.small { width: 28px; height: 28px; font-size: 11px; }
.avatar.more { background: var(--panel-2); color: var(--text-2); border-color: var(--bg); }
.avatar-btn { border-radius: 50%; padding: 0; line-height: 0; }
.avatar-btn .avatar { border-color: var(--line); }
.avatar-btn:hover .avatar { border-color: var(--text-3); }
.role-chip {
  display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: 999px;
  background: var(--amber-soft); color: var(--amber); font-size: 12px; font-weight: 600; white-space: nowrap;
}
.role-chip i { width: 14px; height: 14px; }

/* remote cursors (y-codemirror) */
.remote-caret { position: relative; border-left: 2px solid; margin-left: -1px; margin-right: -1px; box-sizing: border-box; }
.remote-caret > div {
  position: absolute; top: -1.35em; left: -2px; font: 600 10.5px/1 var(--font); color: #fff; white-space: nowrap;
  padding: 3px 6px; border-radius: 6px 6px 6px 0; user-select: none; pointer-events: none; opacity: 1; transition: opacity 0.3s;
}
.remote-caret.hide-name > div { opacity: 0; }
.remote-caret:hover > div { opacity: 1; }

/* share dialog */
.modal-body.share { padding-top: 6px; }
.invite-row { display: flex; gap: 8px; margin-bottom: 4px; }
.invite-row .input[type='email'] { flex: 1; }
.invite-row select { width: auto; }
.invite-row .btn-primary i { width: 15px; }
.share-h { margin: 20px 0 8px; font-size: 15px; color: var(--text); font-weight: 600; letter-spacing: -0.01em; }
.member-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; max-height: 260px; overflow: auto; }
.member-list li { display: flex; align-items: center; gap: 12px; padding: 6px 4px; }
.member-list .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.member-list .grow b { font-size: 13.5px; }
.member-list .grow small { color: var(--text-2); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-list .avatar { border-color: var(--panel); width: 34px; height: 34px; }
.role-label { font-size: 12.5px; color: var(--text-2); font-weight: 500; padding-right: 6px; }
.role-select { width: auto; height: 32px; font-size: 12.5px; }
.access-row { display: flex; gap: 12px; align-items: flex-start; }
.access-row .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.access-row small { color: var(--text-2); font-size: 12px; padding-left: 2px; }
.access-icon { width: 34px; height: 34px; border-radius: 50%; background: var(--accent-soft); display: grid; place-items: center; flex: none; }
.access-icon i { width: 16px; height: 16px; }
.modal-foot .spacer { flex: 1; }
.modal-foot .btn-ghost i { width: 15px; height: 15px; }
.modal-foot .btn-ghost { display: inline-flex; align-items: center; gap: 6px; }
.steps { padding-left: 20px; line-height: 1.7; }
.steps code, .modal-body p code { font-family: var(--mono); font-size: 12px; background: var(--accent-soft); padding: 1px 5px; border-radius: 5px; }

/* share links & guests */
.link-list { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.link-list li { display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel-2); flex-wrap: wrap; }
.link-list li.empty, .member-list li.empty { color: var(--text-3); font-size: 13px; justify-content: center; border-style: dashed; }
.member-list li.empty { padding: 10px; }
.link-list .grow { flex: 1; min-width: 160px; display: flex; flex-direction: column; gap: 2px; }
.link-list small { color: var(--text-3); font-size: 11.5px; }
.link-url { font: 12px var(--mono); color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-list .access-icon { width: 30px; height: 30px; }
.btn-ghost.small { height: 32px; padding: 0 10px; font-size: 12.5px; display: inline-flex; align-items: center; gap: 5px; }
.btn-ghost.small i { width: 14px; height: 14px; }
#newLink { align-items: center; flex-wrap: wrap; }
#newLink select { width: auto; }
#newLink .toggle { margin-right: auto; }
.warn-line { display: flex; gap: 8px; align-items: flex-start; font-size: 12.5px; color: var(--amber); background: var(--amber-soft); padding: 8px 12px; border-radius: 10px; margin: 0 0 10px; }
.warn-line i { width: 15px; height: 15px; flex: none; margin-top: 1px; }
.setting-row code { font: 11.5px var(--mono); background: var(--accent-soft); padding: 1px 5px; border-radius: 5px; word-break: break-all; }
.composer.locked { opacity: 0.6; }
.composer.locked .send-btn { pointer-events: none; }
body.guest #settingsBtn, body.guest #compileMenuBtn { display: none; }
body.guest .compile-group .btn-primary:first-child { border-radius: 980px; }

/* sign-in */
.auth-screen { position: fixed; inset: 0; z-index: 90; background: var(--bg); display: flex; flex-direction: column; align-items: center; overflow-y: auto; padding: 16px; }
.auth-screen > * { margin: auto 0; flex: none; }
.auth-card {
  width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow-pop);
  padding: 32px 28px 24px; display: flex; flex-direction: column; gap: 12px; text-align: center; animation: pop 0.25s ease-out;
}
.auth-card img { margin: 0 auto 4px; }
.auth-card h1 { margin: 0; font-size: 22px; font-weight: 600; }
.auth-card p { margin: 0 0 6px; color: var(--text-2); line-height: 1.5; }
.auth-card .input { height: 44px; font-size: 15px; }
.auth-card .btn-primary { height: 44px; justify-content: center; }
.auth-card .note { min-height: 1.2em; margin: 0; }

/* ───────────── visual editor ───────────── */
.seg.mini { padding: 0 0 0 8px; gap: 2px; }
.seg.mini .seg-btn { flex: none; height: 28px; padding: 0 11px; font-size: 12.5px; border-radius: 9px; }
.seg.mini .seg-btn[disabled] { opacity: 0.4; cursor: not-allowed; }
.visual-host { flex: 1; min-height: 0; overflow: auto; background: var(--panel-2); padding: 24px 16px 80px; }
.v-page {
  max-width: 780px; margin: 0 auto; background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
  box-shadow: var(--shadow); padding: 56px 56px 72px 64px; font-family: var(--serif); font-size: 16.5px; line-height: 1.65;
  color: var(--text); counter-reset: sec sub subsub eq;
}
.vb { position: relative; margin: 0 -10px; padding: 2px 10px; border-radius: 8px; transition: background 0.12s; }
.vb:hover { background: color-mix(in srgb, var(--accent-soft) 55%, transparent); }
.vb.dragging { opacity: 0.4; }
.vb.drop-before { box-shadow: 0 -3px 0 0 var(--text); }
.vb.drop-after { box-shadow: 0 3px 0 0 var(--text); }
.vb-gutter { position: absolute; left: -44px; top: 4px; display: flex; gap: 2px; opacity: 0; transition: opacity 0.12s; }
.vb:hover .vb-gutter, .vb:focus-within .vb-gutter { opacity: 1; }
.vb-btn {
  width: 20px; height: 24px; border-radius: 6px; display: grid; place-items: center; color: var(--text-3);
  font: 700 15px/1 var(--font); cursor: pointer; user-select: none;
}
.vb-btn:hover { background: var(--accent-soft); color: var(--text); }
.vb-handle { cursor: grab; font-size: 14px; }
.vb-handle:active { cursor: grabbing; }
.vb-src {
  position: absolute; right: -2px; top: 4px; opacity: 0; font: 700 11px/1 var(--mono); color: var(--text-3);
  padding: 4px 6px; border-radius: 6px; background: var(--panel); border: 1px solid var(--line); transition: opacity 0.12s;
}
.vb:hover .vb-src { opacity: 1; }
.vb-src:hover { color: var(--text); border-color: var(--text-3); }
.vb-body [contenteditable='true'] { outline: none; cursor: text; }
.vb-body [contenteditable='true']:focus { box-shadow: inset 2px 0 0 var(--text-3); }
.v-para { margin: 0 0 10px; text-align: justify; hyphens: auto; }
.v-h { font-weight: 700; line-height: 1.3; margin: 22px 0 8px; }
.v-l1 { font-size: 1.7em; }
.v-l2 { font-size: 1.35em; counter-increment: sec; counter-reset: sub; }
.v-l2:not(.nonum)::before { content: counter(sec) '\2003'; }
.v-l3 { font-size: 1.15em; counter-increment: sub; counter-reset: subsub; }
.v-l3:not(.nonum)::before { content: counter(sec) '.' counter(sub) '\2003'; }
.v-l4 { font-size: 1.02em; counter-increment: subsub; }
.v-l4:not(.nonum)::before { content: counter(sec) '.' counter(sub) '.' counter(subsub) '\2003'; }
.v-l5 { font-size: 1em; }
.v-h::before { color: var(--text-2); }
.v-list { margin: 4px 0 12px; padding-left: 28px; }
.v-list li { margin: 2px 0; }
.v-env { margin: 8px 0 16px; }
.v-abstract { padding: 0 34px; font-size: 0.93em; }
.v-env-label { text-align: center; font-weight: 700; margin-bottom: 4px; font-size: 0.95em; }
.v-quote, .v-quotation { padding: 0 30px; font-style: italic; }
.v-center .v-para { text-align: center; }
.v-math { margin: 10px 0 14px; padding: 4px 0; cursor: pointer; position: relative; overflow-x: auto; overflow-y: hidden; }
.v-math:not(.nonum) { counter-increment: eq; }
.v-math:not(.nonum)::after { content: '(' counter(eq) ')'; position: absolute; right: 0; top: 50%; transform: translateY(-50%); color: var(--text-2); }
.v-math .katex-display { margin: 0; }
.v-titleblock { text-align: center; margin: 4px 0 26px; }
.v-title { font-size: 1.75em; font-weight: 700; line-height: 1.25; margin-bottom: 10px; }
.v-author { font-size: 1.1em; margin-bottom: 4px; }
.v-date { color: var(--text-2); }
.v-raw {
  margin: 6px 0 12px; padding: 10px 12px; border-radius: 8px; background: var(--panel-2); border: 1px dashed var(--line-2);
  font: 12.5px/1.55 var(--mono); color: var(--text-2); white-space: pre-wrap; word-break: break-word; cursor: pointer;
}
.v-raw.v-comment { color: var(--text-3); font-style: italic; }
.v-figure { margin: 12px 0 16px; text-align: center; cursor: pointer; }
.v-imgwrap img { max-width: 100%; max-height: 360px; border-radius: 4px; }
.v-imgph {
  display: inline-grid; place-items: center; min-width: 60%; min-height: 140px; padding: 16px; border-radius: 8px;
  background: var(--panel-2); border: 1px dashed var(--line-2); color: var(--text-3); font: 13px var(--font);
}
.v-figure figcaption, .v-tablecap { font-size: 0.92em; margin-top: 8px; }
.v-tablewrap { margin: 12px 0 16px; cursor: pointer; overflow-x: auto; }
.v-tablecap { text-align: center; margin: 0 0 6px; }
.v-table { margin: 0 auto; border-collapse: collapse; font-size: 0.95em; }
.v-table td { padding: 4px 14px; border-bottom: 1px solid var(--line); }
.v-table tr.head td { border-top: 1.5px solid var(--text); border-bottom: 1px solid var(--text); font-weight: 600; }
.v-table tr:last-child td { border-bottom: 1.5px solid var(--text); }
.vc {
  display: inline-block; font: 600 0.78em/1.45 var(--mono); padding: 0 5px; margin: 0 1px; border-radius: 5px; vertical-align: 0.08em;
  background: var(--accent-soft); color: var(--text-2); cursor: pointer; max-width: 22em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.vc:hover { color: var(--text); }
.vc-brace { background: transparent; color: var(--text-3); padding: 0 1px; }
.vc-comment { color: var(--text-3); }
.vm { cursor: pointer; border-radius: 4px; padding: 0 1px; }
.vm:hover { background: var(--accent-soft); }
.v-empty { text-align: center; color: var(--text-2); font-family: var(--font); padding: 40px 0; }
.v-srcedit { margin: 6px 0 12px; border: 1.5px solid var(--text-3); border-radius: 10px; overflow: hidden; background: var(--panel-2); }
.v-srcedit textarea {
  display: block; width: 100%; border: 0; outline: 0; resize: none; background: transparent; padding: 10px 12px;
  font: 13px/1.55 var(--mono); color: var(--text); min-height: 60px;
}
.v-srcedit-foot { display: flex; gap: 6px; align-items: center; padding: 6px 8px; border-top: 1px solid var(--line); font-family: var(--font); }
.v-srcedit-foot .chip-btn { height: 28px; }
.v-preview { overflow-x: auto; max-width: 70%; }
.v-preview .katex-display { margin: 0; }
.v-page.readonly .vb:hover { background: transparent; }
.v-toolbar {
  position: fixed; z-index: 70; display: flex; gap: 2px; padding: 4px; background: var(--accent); color: var(--on-accent);
  border-radius: 10px; box-shadow: var(--shadow-pop);
}
.v-toolbar button { min-width: 30px; height: 28px; border-radius: 7px; font: 700 13px var(--serif); color: inherit; }
.v-toolbar button:hover { background: color-mix(in srgb, var(--on-accent) 16%, transparent); }
.v-toolbar .sep { width: 1px; margin: 4px 3px; background: color-mix(in srgb, var(--on-accent) 25%, transparent); }
.v-addmenu {
  position: fixed; z-index: 70; display: flex; flex-direction: column; min-width: 180px; padding: 6px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-pop); animation: pop 0.12s ease-out;
}
.v-addmenu button { text-align: left; padding: 7px 10px; border-radius: 8px; font-weight: 700; font-size: 13px; }
.v-addmenu button:hover { background: var(--panel-2); }
@media (max-width: 960px) {
  .share-btn span, .role-chip { display: none; }
  .share-btn { padding: 0 10px; }
  .presence .avatar:nth-child(n + 3) { display: none; }
  .visual-host { padding: 10px 6px 60px; }
  .v-page { padding: 28px 22px 40px 34px; font-size: 15.5px; }
  .v-para { text-align: left; }
  .vb-gutter { left: -30px; flex-direction: column; opacity: 0.6; }
  .v-abstract { padding: 0 8px; }
  .invite-row { flex-wrap: wrap; }
  .invite-row .input[type='email'] { flex-basis: 100%; }
}

/* ───────────── animations ───────────── */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(0.98); } }
@keyframes fade { from { opacity: 0; } }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.6; } 30% { transform: translateY(-5px); opacity: 1; } }
@keyframes toastIn { from { opacity: 0; transform: translateY(14px) scale(0.9); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(8px) scale(0.95); } }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-6px) rotate(2deg); } }
.bob { animation: bob 3.2s ease-in-out infinite; }

/* ───────────── responsive ───────────── */
@media (max-width: 1280px) {
  .hint { display: none; }
}

@media (max-width: 960px) {
  body { padding-bottom: calc(68px + env(safe-area-inset-bottom)); }
  .topbar { padding: 0 10px; gap: 6px; height: 52px; }
  .brand-name, .save-status span { display: none; }
  .project-btn { max-width: 44vw; }
  .compile-group .btn-primary span { display: none; }
  .compile-group .btn-primary:first-child { padding: 0 12px; }
  .workspace { display: flex; padding: 8px 10px 10px; }
  .workspace > .panel, .gutter { display: none; }
  .workspace[data-view='chat'] .side-panel,
  .workspace[data-view='files'] .side-panel,
  .workspace[data-view='editor'] .editor-panel,
  .workspace[data-view='pdf'] .pdf-panel { display: flex; flex: 1; }
  .side-panel .seg { display: none; }
  .chat-head, .files-toolbar { padding-top: 8px; }
  .mobile-nav {
    display: flex; position: fixed; left: 10px; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom)); height: 58px;
    background: var(--glass); -webkit-backdrop-filter: saturate(180%) blur(24px); backdrop-filter: saturate(180%) blur(24px);
    border-radius: 22px; box-shadow: var(--shadow-pop); border: 1px solid var(--line); padding: 6px; gap: 4px; z-index: 40;
  }
  .mobile-nav button {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border-radius: 14px;
    font-size: 11px; font-weight: 600; color: var(--text-3);
  }
  .mobile-nav button i { width: 19px; height: 19px; }
  .mobile-nav button.active { background: var(--accent-soft); color: var(--accent-ink); }
  .tree-row .acts:not([hidden]) { display: flex; }
  .tree-row .size { display: none; }
  .model-pop { width: calc(100vw - 20px); }
  .log-drawer.open .log-body { height: 40vh; }
}

@media (max-width: 420px) {
  #themeBtn { display: none; }
  .provider-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* PDF → source jump */
.pdf-page canvas { cursor: pointer; }
.sync-flash { background: color-mix(in srgb, var(--amber) 28%, transparent); transition: background 1s; }
.sync-word { background: color-mix(in srgb, var(--amber) 55%, transparent); border-radius: 3px; box-shadow: 0 0 0 2px color-mix(in srgb, var(--amber) 55%, transparent); }

/* ───────────── segmented controls (Apple-style track with a raised thumb) ───────────── */
.side-panel > .seg, .seg.mini, .seg.pills {
  background: color-mix(in srgb, var(--text) 6%, transparent); border-radius: 11px; padding: 2px; gap: 2px;
}
.side-panel > .seg { margin: 10px 10px 8px; }
.seg.mini { margin-left: 8px; }
.side-panel > .seg .seg-btn, .seg.mini .seg-btn, .seg.pills .seg-btn { height: 30px; border-radius: 9px; color: var(--text-2); font-weight: 500; }
.side-panel > .seg .seg-btn:hover, .seg.mini .seg-btn:hover, .seg.pills .seg-btn:hover { background: transparent; color: var(--text); }
.side-panel > .seg .seg-btn.active, .seg.mini .seg-btn.active, .seg.pills .seg-btn.active {
  background: var(--panel); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 0 0 0.5px rgba(0, 0, 0, 0.05);
}
[data-theme='dark'] .side-panel > .seg .seg-btn.active, [data-theme='dark'] .seg.mini .seg-btn.active, [data-theme='dark'] .seg.pills .seg-btn.active { background: #636366; }
.seg.mini .seg-btn { height: 26px; }

/* ───────────── shared pieces for full-screen pages ───────────── */
.btn-primary.pill, .btn-ghost.pill { border-radius: 980px; }
.btn-primary.lg, .btn-ghost.lg { height: 44px; padding: 0 22px; font-size: 15px; }
.btn-primary i, .btn-ghost i { width: 16px; height: 16px; }
.link-btn { color: var(--accent-ink); font-size: 14px; font-weight: 400; padding: 4px 0; }
.link-btn:hover { text-decoration: underline; }
.input.lg { height: 44px; font-size: 15px; border-radius: 12px; padding: 0 14px; }
.input.mono { font-family: var(--mono); font-size: 13px; }
.display {
  font-family: var(--display); font-size: clamp(44px, 7vw, 80px); line-height: 1.02; letter-spacing: -0.035em;
  font-weight: 700; margin: 0; color: var(--text);
}
.display em, .display-sm em {
  font-family: var(--serif); font-style: italic; font-weight: 400; letter-spacing: -0.02em;
}
.display-sm { font-family: var(--display); font-size: clamp(30px, 4vw, 40px); line-height: 1.08; letter-spacing: -0.028em; font-weight: 700; margin: 0; }
.lede { font-size: clamp(17px, 1.6vw, 21px); line-height: 1.45; color: var(--text-2); margin: 14px 0 0; letter-spacing: -0.01em; max-width: 34em; }
.welcome-brand { display: flex; align-items: center; gap: 10px; font: 600 17px/1 var(--display); letter-spacing: -0.02em; color: var(--text); }
.welcome-brand img { border-radius: 9px; }

/* ───────────── welcome / join ───────────── */
.auth-screen:has(.welcome), .auth-screen:has(.setup) { padding: 0; }
.welcome {
  width: min(1180px, 100%); min-height: 100%; margin: 0 auto; padding: clamp(28px, 6vw, 72px) clamp(20px, 5vw, 64px);
  display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: clamp(32px, 6vw, 88px); align-items: center;
}
.welcome-copy { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; animation: rise 0.7s var(--ease) both; }
.welcome-copy .welcome-brand { margin-bottom: clamp(28px, 5vh, 56px); }
.code-form {
  display: flex; align-items: center; gap: 6px; margin-top: 36px; padding: 6px 6px 6px 22px; width: min(440px, 100%);
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 980px; transition: border-color 0.2s, box-shadow 0.2s;
}
.code-form:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--focus-ring); }
.code-input {
  flex: 1; min-width: 0; width: 100%; border: 0; outline: 0; background: transparent; font: 500 22px/1 var(--mono); letter-spacing: 0.14em;
  text-transform: uppercase; height: 48px; color: var(--text);
}
.code-input::placeholder { color: var(--text-3); letter-spacing: 0.14em; }
.code-form .btn-primary { height: 48px; padding: 0 22px 0 24px; font-size: 16px; }
.form-msg { margin: 14px 0 0 4px; font-size: 13px; color: var(--text-2); min-height: 1.4em; max-width: 440px; line-height: 1.45; }
.form-msg.err { color: var(--red); }
.host-entry { margin-top: clamp(28px, 6vh, 64px); padding-top: 20px; border-top: 1px solid var(--line); width: min(440px, 100%); }
.host-entry .note { margin: 0; }
.host-form { display: flex; gap: 8px; }
.host-form .input { height: 40px; }

/* the signature: a page being written by two people at once */
.welcome-art { display: grid; place-items: center; perspective: 1600px; animation: rise 0.9s 0.1s var(--ease) both; }
.sheet {
  width: min(460px, 100%); aspect-ratio: 1 / 1.2; background: #fff; color: #1d1d1f; border-radius: 4px;
  padding: 11% 10% 8%; font: 15px/1.6 var(--serif); position: relative;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04), 0 30px 60px -20px rgba(0, 0, 0, 0.25), 0 60px 120px -40px rgba(0, 0, 0, 0.2);
  transform: rotateX(6deg) rotateY(-10deg) rotateZ(1deg); animation: drift 9s ease-in-out infinite;
}
[data-theme='dark'] .sheet { box-shadow: 0 40px 100px -30px rgba(0, 120, 255, 0.25), 0 30px 60px -20px rgba(0, 0, 0, 0.8); }
.sheet p { margin: 0 0 10px; text-align: justify; hyphens: auto; font-size: 13.5px; }
.sheet-title { font-size: 21px; font-weight: 600; text-align: center; line-height: 1.25; letter-spacing: -0.01em; }
.sheet-authors { text-align: center; color: #6e6e73; font-size: 13px; margin: 8px 0 22px; }
.sheet-abstract { padding: 0 6%; }
.sheet-h { font-weight: 600; font-size: 15px !important; margin: 18px 0 8px !important; text-align: left !important; }
.sheet-lines { display: grid; gap: 11px; margin-top: 8px; }
.sheet-lines span { height: 7px; border-radius: 4px; background: #ececf0; }
.sheet-lines span:nth-child(2) { width: 92%; }
.sheet-lines span:nth-child(3) { width: 96%; }
.sheet-lines span:nth-child(5) { width: 88%; }
.sheet-lines span:nth-child(6) { width: 40%; }
.peer-sel { background: color-mix(in srgb, var(--c) 18%, transparent); border-radius: 2px; }
.peer-caret { position: relative; display: inline-block; width: 2px; height: 1.15em; margin: 0 1px; vertical-align: -0.2em; background: var(--c); animation: blink 1.2s steps(1) infinite; }
.peer-caret::after {
  content: attr(data-name); position: absolute; left: -1px; bottom: 100%; margin-bottom: 2px; padding: 2px 7px 3px;
  border-radius: 6px 6px 6px 0; background: var(--c); color: #fff; font: 600 11px/1.2 var(--font); white-space: nowrap; letter-spacing: 0;
}
.peer-caret.late { animation-delay: 0.6s; }

/* ───────────── setup guide ───────────── */
.setup { width: min(680px, 100%); min-height: 100%; margin: 0 auto; display: flex; flex-direction: column; padding: 22px clamp(20px, 4vw, 32px) 28px; }
.setup-top { display: flex; align-items: center; gap: 16px; }
.setup-steps { display: flex; gap: 6px; list-style: none; margin: 0 auto; padding: 0; counter-reset: step; }
.setup-steps li { font-size: 12px; color: var(--text-3); display: flex; align-items: center; gap: 6px; }
.setup-steps li + li::before { content: ''; width: 18px; height: 1px; background: var(--line-2); }
.setup-steps li.current { color: var(--text); font-weight: 600; }
.setup-steps li.done { color: var(--accent-ink); }
.setup-stage { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: clamp(28px, 7vh, 72px) 0 28px; }
.setup-stage.enter { animation: rise 0.45s var(--ease) both; }
.setup-stage .lede { margin-bottom: 30px; font-size: 18px; }
.setup-foot { display: flex; align-items: center; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--text); }
.field > span em { font-style: normal; font-weight: 400; color: var(--text-3); margin-left: 4px; }
.field > small { font-size: 12.5px; color: var(--text-2); }
.choices { display: flex; flex-direction: column; gap: 10px; margin-bottom: 24px; }
.choice {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-radius: 16px; cursor: pointer;
  background: var(--panel); border: 1px solid var(--line); transition: border-color 0.15s, box-shadow 0.15s;
}
.choice:hover { border-color: var(--line-2); }
.choice.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice:has(input:focus-visible) { box-shadow: 0 0 0 4px var(--focus-ring); }
.choice .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.choice b { font-size: 15px; font-weight: 600; }
.choice small { font-size: 13px; color: var(--text-2); line-height: 1.4; }
.choice-icon { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: var(--panel-2); color: var(--text-2); flex: none; border: 1px solid var(--line); }
.choice.on .choice-icon { background: var(--accent); color: #fff; border-color: transparent; }
.choice-icon i { width: 18px; height: 18px; }
.radio { width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid var(--line-2); flex: none; transition: border 0.15s; }
.choice.on .radio { border: 6px solid var(--accent); }
.found { list-style: none; margin: 0 0 24px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.found li { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: 12px; background: var(--mint-soft); }
.found li > i { color: var(--mint); width: 18px; height: 18px; }
.found .grow { display: flex; flex-direction: column; }
.found b { font-weight: 600; font-size: 14px; }
.found small { font-size: 12.5px; color: var(--text-2); }
.seg.pills { display: inline-flex; align-self: flex-start; flex-wrap: wrap; }
.seg.pills .seg-btn { flex: none; padding: 0 14px; font-size: 13px; }
.status-line { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); margin-bottom: 14px; font-size: 14px; }
.status-line i { width: 18px; height: 18px; flex: none; }
.status-line.ok { background: var(--mint-soft); border-color: transparent; }
.status-line.ok i { color: var(--mint); }
.status-line.err { background: var(--red-soft); border-color: transparent; color: var(--red); }
.status-line + .btn-ghost { align-self: flex-start; margin-bottom: 14px; }
.setup-stage .setting-card { background: var(--panel); }
.setup-stage .setting-row + .setting-row { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.done-mark { width: 64px; height: 64px; border-radius: 50%; background: var(--switch); color: #fff; display: grid; place-items: center; margin-bottom: 24px; animation: pop 0.5s var(--ease) both; }
.done-mark i { width: 30px; height: 30px; }
.done-mark svg { stroke-width: 2.6; }

/* ───────────── invites ───────────── */
.invite-code {
  align-self: flex-start; font: 600 15px/1 var(--mono); letter-spacing: 0.1em; color: var(--text); padding: 6px 10px; margin-left: -10px;
  border-radius: 8px; transition: background 0.15s;
}
.invite-code:hover { background: var(--accent-soft); color: var(--accent-ink); }
.link-list li.expired { opacity: 0.55; }
#newLink select[name='expires'] { width: auto; }

@keyframes rise { from { opacity: 0; transform: translateY(16px); } }
@keyframes blink { 50% { opacity: 0.35; } }
@keyframes drift { 0%, 100% { transform: rotateX(6deg) rotateY(-10deg) rotateZ(1deg) translateY(0); } 50% { transform: rotateX(4deg) rotateY(-7deg) rotateZ(0.5deg) translateY(-8px); } }

@media (max-width: 900px) {
  .welcome { grid-template-columns: minmax(0, 1fr); align-content: start; }
  .welcome-art { order: 2; }
  .sheet { width: min(380px, 92%); transform: none; animation: none; }
  .setup-steps li + li::before { width: 8px; }
}
@media (max-width: 560px) {
  .setup-steps { display: none; }
  .setup-top { justify-content: space-between; }
  .code-form { padding-left: 16px; }
  .code-input { font-size: 18px; }
  .welcome-art { display: none; }
}

/* ───────────── shared AI chat ───────────── */
.msg.other { align-items: flex-start; }
.msg.user.other .bubble { background: color-mix(in srgb, var(--text) 5%, transparent); color: var(--text); border-radius: 18px 18px 18px 6px; }
.msg-author { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--text-2); padding: 0 4px; }
.avatar.tiny { width: 20px; height: 20px; font-size: 9px; border-width: 0; }
.host-tag { font-size: 10.5px; font-weight: 600; padding: 1px 6px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-ink); }
.msg.other .msg-meta { padding-left: 4px; }
.msg.divider { flex-direction: row; align-items: center; gap: 10px; color: var(--text-3); font-size: 11.5px; }
.msg.divider::before, .msg.divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.card.shared .state { display: none; }
.pc-row { margin-top: 6px; border: 1px dashed var(--line-2); }

/* ───────────── version history ───────────── */
.modal.wide { width: min(1040px, 100%); max-height: min(90vh, 900px); display: flex; flex-direction: column; overflow: hidden; }
.modal.wide .modal-head .btn-ghost.small { margin-right: 4px; }
.history { flex: 1; min-height: 0; display: grid; grid-template-columns: 280px minmax(0, 1fr); border-top: 1px solid var(--line); }
.version-list { overflow-y: auto; padding: 8px; border-right: 1px solid var(--line); background: var(--panel-2); }
.v-day { font-size: 12px; font-weight: 600; color: var(--text-2); padding: 12px 10px 6px; }
.v-item { display: flex; flex-direction: column; gap: 2px; width: 100%; text-align: left; padding: 9px 12px; border-radius: 10px; transition: background 0.15s; }
.v-item:hover { background: color-mix(in srgb, var(--text) 5%, transparent); }
.v-item.active { background: var(--accent); color: #fff; }
.v-item.active .v-by, .v-item.active .v-files { color: rgba(255, 255, 255, 0.85); }
.v-time { font-size: 13.5px; font-weight: 600; }
.v-label { font-size: 13px; font-weight: 500; }
.v-by { font-size: 12px; color: var(--text-2); }
.v-files { font-size: 11.5px; color: var(--text-3); font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.version-view { display: flex; flex-direction: column; min-height: 0; padding: 16px 20px 20px; gap: 12px; }
.vv-head { display: flex; align-items: center; gap: 8px; }
.vv-head .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.vv-head b { font: 600 17px/1.3 var(--display); letter-spacing: -0.015em; }
.vv-head small { color: var(--text-2); font-size: 12.5px; }
.vv-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.vv-bar select { width: auto; max-width: 100%; font-family: var(--mono); font-size: 12.5px; }
.vv-diff { flex: 1; min-height: 160px; max-height: none; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); font-size: 12px; }
.vv-note { padding: 12px 14px !important; color: var(--text-2); font-family: var(--font); }
.vv-legend { display: flex; gap: 8px; padding: 6px 10px !important; position: sticky; top: 0; background: var(--panel); border-bottom: 1px solid var(--line); font-family: var(--font); }
.vv-legend span { font-size: 11.5px; padding: 1px 8px; border-radius: 6px; }
.vv-legend span::before { display: none; }
@media (max-width: 760px) {
  .history { grid-template-columns: 1fr; grid-template-rows: 200px minmax(0, 1fr); }
  .version-list { border-right: 0; border-bottom: 1px solid var(--line); }
  .version-view { padding: 12px; }
  .vv-head { flex-wrap: wrap; }
}
.vv-legend .del { text-decoration: none; }

/* ───────────── setup guide: choosing an AI ───────────── */
.found-line { display: flex; align-items: center; gap: 8px; margin: -12px 0 18px; font-size: 13.5px; color: var(--mint); }
.found-line i { width: 16px; height: 16px; }
.ai-opts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; }
.ai-opt {
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding: 12px 14px; border-radius: 14px; text-align: left;
  background: var(--panel); border: 1px solid var(--line); transition: border-color 0.15s, box-shadow 0.15s;
}
.ai-opt:hover { border-color: var(--line-2); }
.ai-opt.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.ai-opt b { font-size: 14.5px; font-weight: 600; display: flex; align-items: center; gap: 4px; }
.ai-opt .tick i { width: 14px; height: 14px; color: var(--mint); }
.ai-opt .badge-pill { font-weight: 500; }
.ai-guide { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px 20px; display: flex; flex-direction: column; gap: 12px; animation: rise 0.3s var(--ease) both; }
.ai-sub { margin: 0; font-size: 15px; font-weight: 600; }
.ai-steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; font-size: 14px; color: var(--text-2); }
.ai-steps li::marker { color: var(--accent-ink); font-weight: 600; }
.cmd-row { display: flex; align-items: center; gap: 8px; margin-top: 6px; padding: 4px 4px 4px 12px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line); }
.cmd-row code { flex: 1; min-width: 0; font: 12.5px var(--mono); color: var(--text); overflow-x: auto; white-space: nowrap; }
.ai-site { align-self: flex-start; text-decoration: none !important; }
.key-line { display: flex; gap: 8px; }
.key-line .input { flex: 1; min-width: 0; }
.key-line .btn-primary { height: 44px; padding: 0 18px; flex: none; }
.ai-guide > .btn-primary { align-self: flex-start; }
.ai-small { font-size: 12px; color: var(--text-3); margin-top: -6px; }
.ai-guide .status-line { margin: 0; }
.ai-guide .note { margin: 0; }
.ai-more { margin-top: 16px; }
.ai-more summary { cursor: pointer; font-size: 14px; font-weight: 500; color: var(--text-2); padding: 6px 0; }
.ai-more summary:hover { color: var(--text); }
.ai-more .setting-card { margin-top: 8px; }
@media (max-width: 560px) {
  .ai-opts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .key-line { flex-direction: column; }
  .key-line .btn-primary { align-self: flex-start; }
}
.setup { min-width: 0; max-width: 100%; }
.setup-stage, .ai-guide, .ai-steps li { min-width: 0; }
/* Narrow phones: keep the top bar inside the screen */
@media (max-width: 480px) {
  .topbar { gap: 4px; padding: 0 8px; }
  .brand, .presence, .compile-group .caret { display: none; }
  body:not(.guest) .compile-group .btn-primary:first-child { border-radius: 980px; }
  .project-btn { max-width: 40vw; padding: 0 8px; }
  .share-btn { padding: 0 9px; }
  .compile-group .btn-primary:first-child { padding: 0 11px; }
  .save-status { padding: 0 2px; }
}

/* ───────── TopA Writes Papers: accounts, projects home ───────── */
.modal.wide { width: min(860px, 100%); }
.share-h .count { color: var(--text-3); font-weight: 500; margin-left: 4px; }
.login-form { display: flex; flex-direction: column; gap: 12px; max-width: 360px; margin-top: 24px; }
.login-form .field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-2); }
.login-form .btn-primary { align-self: flex-start; margin-top: 4px; }
.invite-entry { margin-top: 28px; max-width: 420px; }
.invite-entry summary { cursor: pointer; color: var(--accent-ink); font-size: 14px; }
.invite-entry .code-form { margin-top: 12px; }
.modal-body .field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-2); margin-bottom: 12px; }
.projects-home .ph-bar { display: flex; gap: 8px; align-items: center; margin: 4px 0 8px; }
.projects-home .ph-bar .grow { flex: 1; }
.ph-list { list-style: none; margin: 0 0 8px; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.ph-list li.empty { color: var(--text-2); font-size: 13.5px; padding: 18px; text-align: center; border: 1px dashed var(--line-2); border-radius: var(--radius-sm); }
.ph-item { width: 100%; display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-sm); text-align: left; cursor: pointer; color: var(--text); font: inherit; }
.ph-item:hover { border-color: var(--accent); background: var(--accent-soft); }
.ph-item.active { border-color: var(--accent); }
.ph-item .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ph-item .grow b { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ph-item .grow small { color: var(--text-2); font-size: 12px; }
.ph-icon { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; background: var(--accent-soft); color: var(--accent-ink); flex: none; }
.user-form { display: grid; grid-template-columns: 1.1fr 1.2fr 1.2fr auto auto auto; gap: 8px; }
@media (max-width: 720px) { .user-form { grid-template-columns: 1fr 1fr; } }
.member-list li.expired { opacity: 0.55; }
