:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --sunk: #f0f0ed;
  --line: #e4e4e0;
  --ink: #0b0b0c;
  --muted: #66666b;
  --soft: #f1f9d6;
  --lime: #e4f7a1;
  --lime-ink: #0b0b0c;
  --lime-line: #d2ea80;
  --good: #1f8a46;
  --warn: #9a6a00;
  --bad: #c0261e;
  --blue: #2a5bd7;
  --night: #000;
  --night-ink: #fff;
  --night-muted: #a6a6a6;
  --mark: rgba(214, 240, 120, 0.7);
  --glow-a: rgba(214, 240, 140, 0.5);
  --glow-b: rgba(196, 176, 245, 0.45);
  --grid: rgba(0, 0, 0, 0.045);
  --display: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --body: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  --hand: "Caveat", cursive;
  --paper: #fbf6ea;
  --pen: #243056;
  --board: var(--surface);
  --board-dot: #e0e3e8;
  --board-ink: #243056;
  --board-blue: #2f6fed;
  --board-card: var(--surface);
  --board-line: var(--line);
  --board-controls: var(--bg);
  --rule: rgba(88, 130, 190, 0.38);
  --margin-rule: rgba(214, 92, 92, 0.7);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 18px 40px -18px rgba(0, 0, 0, 0.22);
  color-scheme: light;
}
:root[data-theme="dark"] {
    --bg: #0b0b0c;
    --surface: #151516;
    --sunk: #1e1e20;
    --line: #2b2b2e;
    --ink: #f2f2f0;
    --muted: #a2a2a8;
    --soft: #232a12;
    --lime: #e4f7a1;
    --lime-ink: #0b0b0c;
    --lime-line: #c9e277;
    --good: #6fd38f;
    --warn: #e7b850;
    --bad: #f2877f;
    --blue: #7b9ef3;
    --paper: #1c2430;
    --pen: #d6e3fa;
    --board: #1b222c;
    --board-dot: #35404f;
    --board-ink: #d6e3fa;
    --board-blue: #86b4ff;
    --board-card: #252e3b;
    --board-line: #3c4858;
    --board-controls: #283240;
    --rule: rgba(130, 170, 230, 0.18);
    --mark: rgba(214, 240, 120, 0.32);
    --glow-a: rgba(190, 230, 90, 0.14);
    --glow-b: rgba(150, 120, 240, 0.18);
    --grid: rgba(255, 255, 255, 0.04);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 18px 40px -18px rgba(0, 0, 0, 0.8);
    color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: var(--sunk);
  color: var(--ink);
  font: 15px/1.6 var(--body);
  -webkit-font-smoothing: antialiased;
}
#root {
  width: 96vw;
  height: 96vh;
  height: 96dvh;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: clamp(20px, 2.5vw, 36px);
  background: var(--bg);
  box-shadow: 0 24px 64px -24px rgba(24, 28, 38, 0.25), 0 2px 8px rgba(24, 28, 38, 0.04);
}
h1, h2, h3, h4 { font-family: var(--display); margin: 0; letter-spacing: -0.035em; }
p { margin: 0; }
button, input, textarea, select { font: inherit; color: inherit; }
.theme-toggle { flex: none; min-height: 44px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--ink); padding: 8px 12px; cursor: pointer; font-size: 13px; font-weight: 600; }
.home-link { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px; text-decoration: none; color: var(--ink); background: var(--surface); font-size: 14px; font-weight: 600; }
.home-link svg, .leave svg, .chat-home svg { width: 17px; height: 17px; flex: none; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; border-radius: 8px; }
mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 1px; }
.kicker { display: block; font-size: 12px; font-weight: 600; letter-spacing: 0.22em; text-transform: uppercase; color: var(--muted); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: 999px; padding: 12px 24px; font-weight: 600; border: 1px solid transparent;
  cursor: pointer; background: none; white-space: nowrap;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-lime { background: var(--lime); color: var(--lime-ink); border-color: var(--lime-line); }
.btn-dark { background: var(--ink); color: var(--bg); }
.btn-ghost { border-color: color-mix(in srgb, var(--ink) 22%, transparent); }
.btn-sm { padding: 7px 15px; font-size: 13.5px; }
.linky { border: 0; background: none; padding: 0; color: var(--ink); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }

.onb {
  height: 100%; min-height: 0; position: relative; overflow: auto; display: flex; flex-direction: column;
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 72px 72px;
}
.onb::before, .onb::after { content: ""; position: absolute; border-radius: 50%; filter: blur(80px); pointer-events: none; }
.onb::before { width: 520px; height: 520px; right: -160px; top: -120px; background: var(--glow-a); }
.onb::after { width: 480px; height: 480px; left: -160px; bottom: -200px; background: var(--glow-b); }
.onb-top, .onb-main { position: relative; z-index: 1; }
.onb-top { display: flex; flex: none; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: center; padding: 18px 20px; }
.onb-main { flex: 1 0 auto; min-width: 0; display: grid; place-items: center; padding: 24px 16px 56px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 19px; letter-spacing: -0.03em; }
.brand svg { width: 30px; height: 30px; }
.card {
  width: 100%; max-width: 560px; background: var(--surface); border-radius: 28px;
  box-shadow: var(--shadow); padding: clamp(24px, 5vw, 44px); display: flex; flex-direction: column; gap: 18px;
}
.card.wide { max-width: 760px; }
.card h1 { font-size: clamp(32px, 5vw, 46px); line-height: 1; font-weight: 800; letter-spacing: -0.05em; }
.sub { color: var(--muted); font-size: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; }
.field input, .field textarea, .field select {
  border: 1px solid var(--line); background: var(--bg); border-radius: 14px; padding: 13px 16px; font-size: 16px; outline: none; width: 100%;
}
.field textarea { min-height: 88px; resize: vertical; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--ink); }
.code-input { font-family: var(--mono); font-size: 32px; letter-spacing: 0.4em; text-align: center; }
.err { color: var(--bad); font-size: 13.5px; }
.roles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 520px) { .roles { grid-template-columns: minmax(0, 1fr); } }
.role {
  border: 1.5px solid var(--line); border-radius: 20px; padding: 18px; text-align: left; background: var(--surface);
  cursor: pointer; display: flex; flex-direction: column; gap: 6px;
}
.role[aria-pressed="true"] { border-color: var(--ink); box-shadow: 0 0 0 3px var(--lime); }
.role b { font-size: 18px; }
.role span { color: var(--muted); font-size: 14px; }
.card-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.fine { font-size: 12.5px; color: var(--muted); }

.drop {
  border: 1.5px dashed color-mix(in srgb, var(--ink) 25%, transparent); border-radius: 22px; padding: 28px 18px;
  display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; background: var(--bg); cursor: pointer;
}
.drop.over { background: var(--soft); border-color: var(--ink); }
.drop b { font-size: 17px; }
.drop span, .fmeta { color: var(--muted); font-size: 13px; }
.upload-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.files-view { gap: 12px; }
.files-view > .vhead, .files-view > .drop, .files-view > .file-help, .files-view > .paste { flex: none; }
.drop-compact { flex-direction: row; justify-content: space-between; flex-wrap: wrap; gap: 8px 16px; padding: 10px 14px; border-radius: 14px; }
.drop-compact .upload-actions { justify-content: flex-start; }
.drop-compact .btn { min-height: 40px; }
@media (max-width: 600px) {
  .drop-compact { padding: 10px; }
  .drop-compact .upload-actions { gap: 6px; }
  .drop-compact .btn { padding: 7px 8px; font-size: 12px; }
}
.file-total { display: inline-block; vertical-align: middle; font-size: 14px; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.file-help { font-size: 12px; color: var(--muted); }
.file-help summary { cursor: pointer; }
.file-help p { padding-top: 6px; }
.file-search { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; flex: none; }
.file-search input { width: min(100%, 360px); min-height: 40px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.files-view > .file-split { flex: 1; min-height: 280px; align-items: stretch; }
.files-view .file-split > .files { min-height: 0; overflow: auto; }
.files-view .file-split > .preview { min-height: 0; max-height: none; height: 100%; }
.files-view .frow[aria-current="page"] { border-color: var(--blue); background: var(--bg); }
@media (max-width: 860px) {
  .files-view > .file-split { flex: none; min-height: 0; }
  .files-view .file-split > .files { max-height: 180px; }
  .files-view .file-split > .preview { height: 55dvh; min-height: 260px; }
}
.files { display: flex; flex-direction: column; gap: 8px; }
.frow {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: center;
  border: 1px solid var(--line); border-radius: 16px; padding: 10px 12px; background: var(--surface);
}
.ftype {
  width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
  font-size: 10.5px; font-weight: 700; background: var(--soft);
}
.ftype.pdf { background: #fde3e1; color: #9b1c13; }
.fname {
  display: block; width: 100%; text-align: left; border: 0; background: none; padding: 0; cursor: pointer;
  font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  text-decoration: underline; text-underline-offset: 3px;
}
.fname:hover { color: var(--blue); }
.file-split { display: grid; grid-template-columns: minmax(240px, 28%) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 860px) { .file-split { grid-template-columns: minmax(0, 1fr); } }
.sheet {
  --line-h: 32px;
  background-color: var(--paper);
  background-image:
    linear-gradient(90deg, transparent 34px, var(--margin-rule) 34px, var(--margin-rule) 35px, transparent 35px),
    repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--line-h) - 1px), var(--rule) var(--line-h));
  background-attachment: local;
  color: var(--pen);
  font-family: var(--hand);
  font-size: 26px;
  font-weight: 600;
  line-height: var(--line-h);
}
.preview {
  background: var(--surface);
  border: 1px solid var(--line); border-radius: 22px; padding: 20px;
  min-height: 70vh; max-height: calc(100vh - 160px); display: flex; flex-direction: column; gap: 8px;
}
.preview header { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.preview h3 { font-family: var(--body); font-size: 20px; font-weight: 600; color: var(--ink); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview .fine { color: var(--muted); }
.preview .btn { font-family: var(--body); }
.preview-body {
  margin: 0; overflow: auto; white-space: pre-wrap; flex: 1; border: 0; background: transparent;
  color: var(--ink); font-family: var(--body); font-size: 16px; font-weight: 400; line-height: 1.75;
  padding: 8px 0;
}
.fstate { font-size: 12px; font-weight: 600; }
.fstate.ok { color: var(--good); }
.fstate.bad { color: var(--bad); }
.fstate.warn { color: var(--warn); }
.iconbtn { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 4px; border-radius: 8px; }
.iconbtn:hover { color: var(--ink); background: var(--sunk); }

.app { height: 100%; display: grid; grid-template-columns: 190px minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
.beta {
  grid-column: 1 / -1; background: var(--night); color: var(--night-ink); font-size: 13px;
  display: flex; justify-content: center; gap: 8px 18px; flex-wrap: wrap; padding: 7px 16px;
}
.beta b { color: var(--lime); font-weight: 600; }
.beta span { color: var(--night-muted); }
.banner { grid-column: 1 / -1; background: var(--soft); color: var(--ink); padding: 8px 16px; font-size: 13.5px; }
.rail {
  border-right: 1px solid var(--line); padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; overflow: hidden;
}
.rail .brand { padding: 4px 6px 14px; font-size: 15px; min-width: 0; }
.rail .brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grp { font-size: 11px; font-weight: 600; letter-spacing: 0.18em; text-transform: uppercase; color: var(--muted); padding: 12px 10px 4px; }
.nav {
  display: flex; align-items: center; gap: 10px; border: 0; background: none; text-align: left;
  padding: 9px 10px; border-radius: 12px; cursor: pointer; font-size: 14.5px; font-weight: 500; color: var(--ink);
}
.nav:hover { background: var(--sunk); }
.nav[aria-current="page"] { background: var(--ink); color: var(--bg); }
.nav svg { width: 17px; height: 17px; flex: none; }
.nav .count { margin-left: auto; font-size: 11px; border: 1px solid var(--line); border-radius: 999px; padding: 0 7px; }
.nav[aria-current="page"] .count { border-color: transparent; }
.me { margin-top: auto; padding: 12px 10px 4px; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--muted); }
.me b { display: block; color: var(--ink); font-size: 13.5px; }
@media (max-width: 1100px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr); }
  .rail { flex-direction: row; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; align-items: center; }
  .rail .brand span, .grp, .me { display: none; }
  .rail .brand { padding: 0 8px 0 0; }
  .nav { white-space: nowrap; }
}
.main { min-width: 0; min-height: 0; overflow: hidden; padding: 0; display: flex; flex-direction: column; }
.view { width: 100%; max-width: none; margin: 0; display: flex; flex-direction: column; gap: 20px; flex: 1; min-height: 0; overflow: auto; padding: 28px 28px 40px; }
.vhead h2 { font-size: clamp(28px, 3.4vw, 40px); line-height: 1.05; font-weight: 800; }
.vhead p { color: var(--muted); margin-top: 6px; }
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
@media (max-width: 760px) { .tiles { grid-template-columns: minmax(0, 1fr); } }
.tile {
  background: var(--surface); border: 1px solid var(--line); border-radius: 22px; padding: 22px;
  display: flex; flex-direction: column; gap: 8px; text-align: left; cursor: pointer;
}
.tile.dark { background: var(--night); color: var(--night-ink); border-color: var(--night); }
.tile.dark p { color: var(--night-muted); }
.tile h3 { font-size: 20px; }
.tile p { color: var(--muted); font-size: 14px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 22px; padding: 20px; }
.panel h3 { font-size: 18px; margin-bottom: 8px; }
.tech { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 18px; margin: 8px 0 0; padding: 0; list-style: none; }
@media (max-width: 700px) { .tech { grid-template-columns: minmax(0, 1fr); } }
.tech li { font-size: 14px; }
.tech b { display: block; }

.ask { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; height: 100%; min-height: 0; }
.ask.passages-open { grid-template-columns: minmax(0, 1fr) minmax(240px, 25%); }
.chat {
  background: var(--surface); border: 1px solid var(--line); border-radius: 22px;
  display: flex; flex-direction: column; min-height: 0; min-width: 0; overflow: hidden;
}
.scope, .modes { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; padding: 12px 16px 0; flex-shrink: 0; position: sticky; background: var(--surface); z-index: 9; }
.msgs {
  flex: 1; min-height: 0; overflow: auto; padding: 24px max(20px, calc((100% - 760px) / 2)); display: flex; flex-direction: column; gap: 28px;
  background: var(--surface); scroll-padding: 16px;
}
.me-msg {
  align-self: flex-end; background: var(--sunk); color: var(--ink);
  font-family: var(--body); font-size: 16px; font-weight: 400; line-height: 1.65;
  padding: 12px 18px; border-radius: 20px; max-width: 85%; white-space: pre-wrap; overflow-wrap: anywhere;
}
.bot { max-width: 100%; display: flex; flex-direction: column; gap: 8px; padding: 0; color: var(--ink); }
.bot .lbl { font-family: var(--body); font-size: 12px; font-weight: 600; color: var(--muted); }
.bot .body { font-family: var(--body); font-size: 16px; font-weight: 400; line-height: 1.75; overflow-wrap: anywhere; }
.bot .body p { margin: 0 0 8px; }
.bot .body p:last-child { margin: 0; }
.bot .body ul, .bot .body ol { margin: 0 0 8px; padding-left: 18px; }
.bot .body code { font-family: var(--mono); font-size: 0.92em; background: var(--sunk); padding: 1px 5px; border-radius: 5px; }
.bot .body pre { background: var(--sunk); padding: 10px 12px; border-radius: 12px; overflow: auto; }
.cite {
  border: 0; background: var(--lime); color: var(--lime-ink); font-family: var(--mono);
  font-size: 10.5px; border-radius: 5px; padding: 1px 5px; cursor: pointer; vertical-align: 1px;
}
.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pill { font-size: 11.5px; font-weight: 600; border-radius: 999px; padding: 2px 8px; background: var(--soft); }
.chip, .mode {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 5px 12px; font-size: 12.5px; cursor: pointer;
}
.mode { font-weight: 600; }
.modes { top: 40px; z-index: 10; }
.scope { top: 88px; z-index: 9; }
.mode[aria-pressed="true"], .chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.composer { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); align-items: flex-end; flex-shrink: 0; }
.composer textarea {
  flex: 1; min-width: 0; min-height: 46px; max-height: 160px; border: 1px solid var(--line);
  background: var(--bg); border-radius: 16px; padding: 10px 16px; outline: none; resize: vertical;
}
.composer textarea:focus { border-color: var(--ink); }
.refs {
  background: var(--surface); border: 1px solid var(--line); border-radius: 22px; padding: 16px;
  overflow: auto; display: flex; flex-direction: column; gap: 8px; min-width: 0; min-height: 0;
}
.refs h4 { font-size: 12px; font-weight: 600; letter-spacing: 0.18em; text-transform: uppercase; color: var(--muted); margin: 0; }
.ref { border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; font-size: 14px; font-family: var(--body); font-weight: 400; line-height: 1.65; color: var(--ink); background: var(--bg); }
.ref.hit { background: var(--soft); border-color: var(--lime-line); }
.ref .t { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.ref code { display: block; margin-top: 6px; font-family: var(--mono); font-size: 10.5px; color: var(--muted); }
.typing { display: flex; gap: 4px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: b 1s infinite; }
.typing i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes b { 50% { opacity: 0.25; transform: translateY(-2px); } }
.chat-tools { display: flex; gap: 8px; align-items: center; padding: 10px 16px 0; flex-shrink: 0; position: sticky; top: 0; background: var(--surface); z-index: 10; }
.chat-tools select { border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 6px 12px; max-width: 240px; }
.chat-tools { flex-wrap: wrap; }
.share-link { padding: 10px 16px; display: grid; gap: 6px; border-bottom: 1px solid var(--line); }
.share-link input { width: 100%; min-width: 0; padding: 8px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); }
.shared-message { white-space: pre-wrap; overflow-wrap: anywhere; }
.shared-chat section { border-top: 1px solid var(--line); padding-top: 12px; }
.empty { color: var(--muted); font-size: 14px; text-align: center; padding: 28px 12px; }
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: 10px 18px; border-radius: 999px; font-size: 14px; z-index: 20; box-shadow: var(--shadow);
}
[hidden] { display: none !important; }
.app-studio { height: 100%; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); background: var(--board); }
.app-studio .main { height: 100%; min-height: 0; padding: 0; overflow: hidden; display: flex; }
.app-studio .view { overflow: hidden; padding: 0; }
.studio {
  position: relative; flex: 1; width: 100%; height: 100%; min-width: 0; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr);
  background: var(--board-controls); overflow: hidden;
}
.studio-top { display: flex; align-items: center; gap: 12px; background: var(--surface); padding: 12px 16px; }
.studio-top { border-bottom: 1px solid var(--board-line); }
.studio-id { display: flex; align-items: center; gap: 10px; min-width: 0; }
.studio-id b { display: block; font-size: 15px; line-height: 1.1; }
.studio-id span { color: var(--muted); font-size: 12px; }
.studio-id > div { min-width: 0; }
.studio-id .avatar { color: #fff; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; background: #e23b4a; color: #fff;
  display: grid; place-items: center; font-weight: 700; flex: none;
}
.studio-header-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; margin-left: auto; }
.studio-pills { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; }
.studio-pills .mode[aria-pressed="true"] { background: #e23b4a; color: #fff; border-color: #e23b4a; }
.topic {
  max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; font-size: 13px; color: var(--muted);
}
.leave {
  border: 1px solid var(--board-line); background: var(--surface); border-radius: 999px;
  padding: 7px 14px; font-weight: 600; cursor: pointer; flex: none; display: inline-flex; align-items: center; gap: 6px; color: var(--ink);
}
.studio-body { min-height: 0; display: grid; grid-template-columns: 72px minmax(0, 1fr); }
.tools {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 14px 8px; overflow: auto;
}
.tools button {
  width: 44px; height: 44px; flex: none; border: 0; border-radius: 14px; background: var(--surface); cursor: pointer;
  box-shadow: 0 1px 2px rgba(40, 32, 16, 0.08); font-family: var(--mono); font-size: 13px; color: var(--ink);
}
.tools button:hover { outline: 1px solid var(--ink); }
.tools .ink { width: 22px; height: 22px; border-radius: 50%; box-shadow: none; }
.tools .ink-black { background: #243056; }
.tools .ink-blue { background: #2f6fed; }
.tools .ink[aria-pressed="true"] { outline: 2px solid var(--ink); outline-offset: 2px; }
.canvas {
  min-width: 0; min-height: 0; overflow: auto; padding: 28px 36px 112px; scroll-padding-bottom: 112px;
  background-color: var(--board);
  background-image: radial-gradient(circle, var(--board-dot) 1.15px, transparent 1.2px);
  background-size: 22px 22px;
}
.canvas textarea {
  width: 100%; border: 0; resize: none; outline: none; background: transparent; overflow: hidden;
  font-family: var(--hand); font-size: 44px; font-weight: 700; line-height: 1.25; min-height: 58px;
  color: var(--board-ink);
}
.canvas.pen-blue textarea { color: var(--board-blue); }
.suggest { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 4px; }
.ink-lines { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }
.ink-line {
  display: block; width: fit-content; max-width: 100%; text-align: left; border: 0; background: none; cursor: pointer;
  font-family: var(--hand); font-size: 40px; font-weight: 700; line-height: 1.15; color: var(--board-blue); padding: 0;
}
.ink-line small { display: block; margin-top: 2px; font-family: var(--body); font-size: 14px; font-weight: 500; color: #6d89b8; }
.ink-exact { margin: 18px 0 0; font-family: var(--hand); font-size: 48px; font-weight: 700; color: var(--board-blue); overflow-wrap: anywhere; }
.board-notes { margin-top: 24px; width: 100%; }
.board-notes:empty { display: none; }
.coach-note { margin: 0; padding: 18px 22px; border: 1px solid var(--board-line); border-radius: 18px; background: var(--board-card); font-family: var(--body); font-size: 18px; font-weight: 400; line-height: 1.65; color: var(--board-ink); overflow-wrap: anywhere; }
.coach-note p { margin: 0 0 10px; max-width: none; }
.coach-note p:last-child { margin-bottom: 0; }
.coach-heading { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.coach-heading b { font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--board-blue); }
.coach-text { margin-top: 8px; }
.coach-text ul, .coach-text ol { padding-left: 22px; }
.coach-text pre { overflow: auto; white-space: pre-wrap; }
.studio-actions { position: absolute; right: 24px; bottom: max(20px, env(safe-area-inset-bottom)); display: flex; align-items: center; gap: 8px; max-width: calc(100% - 96px); padding: 8px; border: 1px solid var(--board-line); border-radius: 999px; background: var(--board-controls); box-shadow: 0 4px 18px rgba(40, 32, 16, 0.12); }
.recent { position: relative; }
.recent summary { padding: 10px 12px; cursor: pointer; font-size: 13px; color: var(--muted); list-style: none; }
.recent summary::-webkit-details-marker { display: none; }
.recent-list { position: absolute; left: 0; bottom: calc(100% + 18px); display: grid; gap: 6px; width: min(240px, 60vw); padding: 10px; border: 1px solid var(--board-line); border-radius: 16px; background: var(--board-card); box-shadow: var(--shadow); }
.recent .chip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.check-work, .ask-coach {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px; cursor: pointer; font-weight: 600;
}
.check-work { padding: 12px 18px; color: var(--board-ink); }
.ask-coach { height: 44px; padding: 0 16px; background: var(--board-ink); color: var(--board-card); border-color: var(--board-ink); }
.studio-actions button:disabled { opacity: 0.6; cursor: wait; }
.studio-actions button:focus-visible, .recent summary:focus-visible { outline: 2px solid #2f6fed; outline-offset: 3px; }
@media (max-width: 1100px) {
  .studio-top { flex-wrap: wrap; gap: 8px; }
  .studio-id { flex: 1; }
  .studio-id b { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .studio-header-controls { order: 1; width: 100%; margin-left: 0; }
  .topic { display: none; }
  .studio-body { grid-template-columns: 56px minmax(0, 1fr); }
  .tools { padding: 12px 4px; }
  .tools button { width: 44px; height: 44px; }
  .canvas { padding: 22px 16px 112px; }
  .coach-note { padding: 14px 16px; font-size: 16px; }
  .studio-actions { right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); max-width: calc(100% - 68px); gap: 6px; padding: 6px; }
  .check-work { padding: 12px; font-size: 13px; }
  .ask-coach { padding: 0 12px; font-size: 13px; }
  .recent summary { padding: 10px 8px; font-size: 12px; }
  .canvas textarea, .ink-line { font-size: 32px; }
}

@media (max-width: 1100px) {
  .view { padding: clamp(12px, 2vw, 24px); }
  .rail { gap: 4px; padding: 8px; flex-shrink: 0; }
  .nav { min-height: 44px; padding: 8px 12px; }
  .ask, .ask.passages-open { height: auto; flex: 1; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(360px, 1fr); }
  .ask.passages-open { grid-template-rows: minmax(360px, 1fr) auto; }
  .refs { max-height: 160px; }
  .chat-tools { flex-wrap: wrap; }
  .chat-tools select { min-width: 0; max-width: 100%; flex: 1; }
  .scope { max-height: 90px; overflow: auto; }
  .preview { min-height: 240px; max-height: 60dvh; }
}
@media (max-width: 600px) {
  .studio-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .tools { flex-direction: row; justify-content: flex-start; gap: 8px; padding: 8px 12px; overflow-x: auto; border-bottom: 1px solid var(--board-line); }
  .tools .ink { flex: 0 0 26px; width: 26px; height: 26px; margin: 0 4px; }
  .canvas { padding: 18px 14px 112px; }
  .studio-actions { max-width: calc(100% - 24px); }
  .studio-top { padding: 10px 12px; }
  .studio-id .avatar { width: 36px; height: 36px; }
  .canvas textarea { font-size: clamp(26px, 7vw, 34px); }
  .canvas textarea, .coach-text, .bot .body, .preview-body { overflow-wrap: anywhere; }
  .card { padding: 20px; }
  .card h1 { font-size: clamp(28px, 8vw, 36px); }
  .onb-top { padding: 12px; }
  .onb-main { padding: 16px 12px 24px; }
  .brand { font-size: 16px; }
  .composer { padding: 8px; }
  .composer .btn { padding: 12px; }
  .scope, .modes, .chat-tools { padding-left: 10px; padding-right: 10px; }
  .bot { padding-left: 20px; }
  .msgs { padding-right: 10px; }
  .frow { gap: 8px; padding: 10px 8px; }
  .frow > div:last-child { flex-wrap: wrap; justify-content: flex-end; max-width: 76px; }
}
@media (max-width: 360px) {
  .studio-actions { gap: 4px; }
  .recent summary { padding: 10px 4px; }
  .check-work { padding: 12px 8px; }
  .ask-coach { padding: 0 10px; }
}
.suggest button {
  border: 1px solid var(--board-line); background: var(--board-card); color: var(--pen);
  border-radius: 999px; padding: 5px 10px; font-size: 13px; cursor: pointer; font-family: var(--body);
}
.suggest button kbd { font-family: var(--mono); font-size: 12px; margin-left: 6px; }
.suggest button[aria-selected="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
@media (max-width: 860px) {
  .paper-wrap, .expr-row textarea { min-height: 48vh; height: 48vh; }
  .suggest { right: 14px; bottom: 58px; }
}
.keypad { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
@media (max-width: 860px) { .keypad { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
.keypad button {
  border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 10px 0;
  font-family: var(--mono); font-size: 13px; cursor: pointer;
}
.keypad button:hover { border-color: var(--ink); }
.step-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.step-list li {
  display: grid; grid-template-columns: 36px minmax(0, 1fr); gap: 12px;
  background-color: var(--paper);
  background-image: repeating-linear-gradient(to bottom, transparent 0, transparent 31px, var(--rule) 32px);
  background-attachment: local;
  border: 1px solid #e4dcc6; border-radius: 18px; padding: 10px 14px; color: var(--pen);
  font-family: var(--hand); font-size: 26px; font-weight: 600; line-height: 32px;
}
.step-n {
  width: 36px; height: 36px; border-radius: 12px; background: var(--ink); color: var(--bg);
  display: grid; place-items: center; font-weight: 700;
}
.step-list pre {
  margin: 0; font-family: var(--hand); font-size: 30px; font-weight: 700; line-height: 32px;
  white-space: pre-wrap; background: transparent; color: var(--pen); border-radius: 0; padding: 0;
}
.exact-card { background: var(--paper); border-color: #e4dcc6; color: var(--pen); }
.exact-card .exact { font-family: var(--hand); font-size: clamp(32px, 4vw, 48px); font-weight: 700; letter-spacing: 0; margin-top: 8px; color: var(--pen); }
.plot-card { width: 100%; max-width: 480px; margin: 12px 0; padding: 8px; background: var(--surface); border: 1px solid var(--board-line); border-radius: 16px; }
.plot { display: block; width: 100%; height: auto; }
.plot line { stroke: var(--line); stroke-width: 1; }
.plot .plot-axes line { stroke: var(--muted); stroke-width: 1.5; }
.plot-boundary { fill: none; stroke: var(--muted); stroke-width: 1; }
.plot path { fill: none; stroke: var(--ink); stroke-width: 2; }
.plot circle { fill: var(--lime); stroke: var(--ink); }
.plot text { fill: var(--ink); font-size: 11px; font-family: var(--mono); }
.plot .plot-axis-label { font-weight: 700; font-size: 13px; }
.plot-marks { display: flex; flex-wrap: wrap; gap: 6px 12px; padding: 4px 8px; font-family: var(--mono); font-size: 12px; color: var(--ink); }
.plot-marks > span:first-child { color: var(--muted); }
.xy { width: 100%; border-collapse: collapse; font-family: var(--mono); }
.xy th, .xy td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

.app-chat { height: 100%; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
.tutor-shell { display: grid; grid-template-columns: 240px minmax(0, 1fr); flex: 1; min-width: 0; min-height: 0; overflow: hidden; position: relative; }
.chat-sidebar { display: flex; flex-direction: column; gap: 12px; padding: 16px 12px; background: var(--bg); border-right: 1px solid var(--line); min-height: 0; min-width: 0; }
.sidebar-brand { display: flex; align-items: center; gap: 8px; }
.sidebar-brand .brand { font-size: 16px; }
.sidebar-brand .brand svg { width: 24px; height: 24px; }
.chat-sidebar nav { display: grid; gap: 2px; }
.chat-sidebar .nav { min-height: 44px; }
#chat-search { width: 100%; min-width: 0; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); padding: 9px 10px; font-size: 14px; }
.chat-history { flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; gap: 4px; }
.chat-history-item { display: block; flex: none; width: 100%; min-height: 44px; border: 0; background: transparent; border-radius: 10px; padding: 10px; text-align: left; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.chat-history-item:hover, .chat-history-item[aria-current="page"] { background: var(--sunk); }
.chat-history-item:disabled { opacity: 0.6; cursor: wait; }
.sidebar-account { display: grid; gap: 8px; border-top: 1px solid var(--line); padding-top: 12px; font-size: 12px; }
.sidebar-account b { font-size: 14px; }
.sidebar-account .theme-toggle { justify-self: start; }
#close-chats, #chats-toggle, .chat-home, .sidebar-backdrop { display: none; }
.tutor-shell .ask { gap: 0; }
.tutor-shell .chat { border: 0; border-radius: 0; }
.tutor-shell .chat-tools { padding: 14px 20px; gap: 6px; border-bottom: 1px solid var(--line); position: static; }
.chat-title { flex: 1; min-width: 80px; font-size: 16px; font-weight: 600; letter-spacing: -0.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-tools .btn { font-weight: 500; }
.chat-actions { position: relative; }
.chat-actions summary { display: grid; place-items: center; min-width: 44px; min-height: 44px; border-radius: 12px; cursor: pointer; list-style: none; }
.chat-actions summary::-webkit-details-marker { display: none; }
.chat-actions summary:hover { background: var(--sunk); }
.chat-actions-menu { position: absolute; top: calc(100% + 8px); right: 0; z-index: 12; display: grid; gap: 6px; width: 160px; border: 1px solid var(--line); background: var(--surface); padding: 8px; border-radius: 14px; box-shadow: var(--shadow); }
.chat-welcome { margin: auto 0; display: grid; justify-items: center; gap: 14px; padding: 28px 0; }
.chat-welcome h1 { font-size: clamp(24px, 3vw, 32px); font-weight: 600; letter-spacing: -0.03em; }
.chat-welcome p { font-size: 15px; }
.starter-questions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 8px; }
.starter-questions .chip { padding: 10px 14px; font-size: 14px; }
.learning-options { width: calc(100% - 40px); max-width: 760px; margin: 0 auto 8px; font-size: 13px; flex: none; }
.learning-options summary { cursor: pointer; color: var(--muted); padding: 8px 4px; }
.learning-options .modes, .learning-options .scope { position: static; padding: 6px 0; }
.learning-options .scope { max-height: 100px; overflow: auto; }
.tutor-shell .composer { width: calc(100% - 40px); max-width: 760px; margin: 0 auto; padding: 8px; border: 1px solid var(--line); border-radius: 22px; background: var(--bg); }
.tutor-shell .composer textarea { border: 0; background: transparent; resize: none; border-radius: 14px; font-size: 16px; padding: 10px 12px; }
.tutor-shell .composer textarea:focus-visible { outline: 2px solid var(--blue); outline-offset: -2px; }
.tutor-shell .composer .btn { padding: 10px 16px; }
.chat-disclaimer { font-size: 11px; text-align: center; color: var(--muted); padding: 8px 16px 12px; flex: none; }
.tutor-shell .refs { border-radius: 0; border: 0; border-left: 1px solid var(--line); }
@media (max-width: 1100px) {
  .tutor-shell { grid-template-columns: minmax(0, 1fr); }
  .tutor-shell .ask { height: 100%; grid-template-rows: minmax(0, 1fr); }
  .tutor-shell .ask.passages-open { grid-template-rows: minmax(0, 1fr) minmax(0, 160px); }
  .tutor-shell .chat-sidebar { display: none; position: absolute; inset: 0 auto 0 0; width: min(280px, 85%); z-index: 15; }
  .tutor-shell.chats-open .chat-sidebar { display: flex; }
  #close-chats { display: block; margin-left: auto; }
  #chats-toggle, .chat-home { display: inline-flex; }
  .tutor-shell.chats-open .sidebar-backdrop { display: block; position: absolute; inset: 0; z-index: 14; background: rgba(0, 0, 0, 0.4); border: 0; }
  .tutor-shell .refs { border-left: 0; border-top: 1px solid var(--line); }
}
@media (max-width: 600px) {
  .tutor-shell .chat-tools { padding: 10px 12px; }
  .chat-title { flex-basis: 100%; order: -1; }
  .chat-home span { display: none; }
  .tutor-shell .chat-home { padding: 8px 12px; min-height: 44px; }
  .tutor-shell .msgs { padding: 20px 16px; }
  .tutor-shell .bot { padding: 0; }
  .me-msg { max-width: 94%; }
  .tutor-shell .composer, .learning-options { width: calc(100% - 24px); }
  .chat-disclaimer { font-size: 10px; }
}

.trial-dialog { width: min(560px, calc(100% - 24px)); max-height: calc(100dvh - 32px); margin: auto; padding: 22px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow); overflow: auto; overflow-wrap: anywhere; }
.trial-dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
.trial-dialog header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.trial-dialog h2 { font-size: 22px; }
.trial-dialog section, .delete-account { margin: 18px 0; }
.trial-dialog p { margin: 10px 0; }
.trial-dialog label, .inline-guide label { display: block; margin: 10px 0 6px; }
.trial-dialog input, .inline-guide select { width: 100%; max-width: 100%; }
.trial-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.delete-account { border-top: 1px solid var(--line); padding-top: 16px; }
.delete-account summary { color: var(--bad); cursor: pointer; min-height: 36px; }
.home-shortcuts { display: flex; gap: 12px; margin: 0 0 14px; }
.files-reload { align-self: flex-start; }
.index-error { color: var(--bad); overflow-wrap: anywhere; }
.inline-guide ol { padding-left: 22px; line-height: 1.7; margin: 10px 0; }
.inline-guide select { font-size: 16px; }
.inline-guide #guide-question { margin: 12px 0; }
.privacy-notice { line-height: 1.5; text-align: left; }
.drop .privacy-notice { max-width: 760px; font-size: 12px; }
.drop-compact { flex-wrap: wrap; }
.tutor-shell .chat > .privacy-notice, .chat-guide { flex: none; width: calc(100% - 40px); max-width: 760px; margin: 0 auto 8px; font-size: 12px; }
.chat-guide { border-left: 3px solid var(--blue); background: var(--sunk); padding: 10px 12px; line-height: 1.5; }
.chat-guide .linky { margin-left: 6px; }
.reply-feedback { font-size: 12px; color: var(--muted); margin-top: 12px; }
.reply-feedback summary { cursor: pointer; padding: 8px 0; }
.reply-feedback fieldset { display: flex; flex-wrap: wrap; gap: 16px; border: 0; padding: 8px 0; }
.reply-feedback fieldset label { display: inline-flex; gap: 6px; align-items: center; min-height: 36px; }
.reply-feedback input[type="radio"] { width: auto; margin: 0; }
.reply-feedback textarea { width: 100%; min-height: 60px; display: block; margin: 6px 0; font-size: 16px; }
.reply-feedback [data-feedback-status] { margin-top: 8px; color: var(--ink); }
.failed-turn { border: 1px solid var(--bad); border-radius: 12px; padding: 12px; margin: 12px 0; }
.failed-turn p { margin-bottom: 8px; }
.failed-turn .fine { display: block; margin-top: 6px; }
.missing-source { color: var(--muted); }
@media (max-width: 600px) {
  .trial-dialog { padding: 16px; }
  .tutor-shell .chat > .privacy-notice, .chat-guide { width: calc(100% - 24px); }
  .frow { grid-template-columns: 36px minmax(0, 1fr); }
  .frow > div:last-child { grid-column: 2; flex-wrap: wrap; max-width: none; justify-content: flex-start; }
}
