:root {
  --bg: #faf9f5;
  --sidebar: #f3f1ea;
  --surface: #ffffff;
  --surface-2: #f5f4ee;
  --border: #e6e3d8;
  --border-strong: #d6d2c4;
  --text: #1f1e1d;
  --muted: #6e6b63;
  --faint: #9a968c;
  --accent: #c96442;
  --accent-hover: #b4553a;
  --accent-soft: #f6e6de;
  --user-bubble: #efece3;
  --code-bg: #f3f1ea;
  --ok: #3f8a4f;
  --ok-soft: #e4f1e5;
  --bad: #c0453a;
  --bad-soft: #f8e3e0;
  --warn: #b8862b;
  --shadow: 0 1px 2px rgba(30, 25, 15, .05), 0 4px 16px rgba(30, 25, 15, .06);
  --shadow-lg: 0 12px 40px rgba(30, 25, 15, .16);
  --radius: 14px;
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #262624; --sidebar: #1f1e1c; --surface: #30302d; --surface-2: #2b2b28;
    --border: #3d3c37; --border-strong: #4c4a44; --text: #ecebe5; --muted: #a8a59c; --faint: #7c7a72;
    --accent: #d97757; --accent-hover: #e3896b; --accent-soft: #4a2f25; --user-bubble: #141413;
    --code-bg: #1d1d1b; --ok: #6cbf7b; --ok-soft: #22382a; --bad: #e57368; --bad-soft: #432623; --warn: #d9a548;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25); --shadow-lg: 0 12px 40px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #262624; --sidebar: #1f1e1c; --surface: #30302d; --surface-2: #2b2b28;
  --border: #3d3c37; --border-strong: #4c4a44; --text: #ecebe5; --muted: #a8a59c; --faint: #7c7a72;
  --accent: #d97757; --accent-hover: #e3896b; --accent-soft: #4a2f25; --user-bubble: #141413;
  --code-bg: #1d1d1b; --ok: #6cbf7b; --ok-soft: #22382a; --bad: #e57368; --bad-soft: #432623; --warn: #d9a548;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25); --shadow-lg: 0 12px 40px rgba(0,0,0,.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.55 var(--sans); -webkit-font-smoothing: antialiased; overflow: hidden; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: inherit; text-decoration: none; }
.ic { flex: none; display: block; }
.serif { font-family: var(--serif); font-weight: 500; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.sm { font-size: 12.5px; }
.pre { white-space: pre-wrap; }
.spacer { flex: 1; }
[hidden] { display: none !important; }

#app { display: flex; height: 100vh; height: 100dvh; }

/* ---------- sidebar ---------- */
#sidebar { width: 272px; flex: none; background: var(--sidebar); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; transition: margin .2s ease; }
body.sb-collapsed #sidebar { margin-left: -272px; }
.sb-top { display: flex; align-items: center; justify-content: space-between; padding: 14px 12px 8px 16px; }
.brand { display: flex; align-items: center; gap: 9px; font-family: var(--serif); font-size: 19px; font-weight: 600; }
.logo { width: 26px; height: 26px; border-radius: 8px; background: var(--accent); color: #fff; display: grid; place-items: center; font: 600 15px var(--serif); flex: none; }
.logo.lg { width: 44px; height: 44px; border-radius: 12px; font-size: 25px; }
.new-chat { margin: 6px 10px 8px; display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px; font-weight: 500; color: var(--accent); }
.new-chat .plus { width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; }
.new-chat:hover { background: var(--surface-2); }
.sb-nav { display: flex; flex-direction: column; gap: 1px; padding: 0 10px; }
.sb-nav a { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 9px; color: var(--text); }
.sb-nav a:hover { background: rgba(0,0,0,.04); }
:root[data-theme="dark"] .sb-nav a:hover, :root[data-theme="dark"] .chat-item:hover { background: rgba(255,255,255,.05); }
.sb-nav a.active { background: var(--surface); box-shadow: var(--shadow); }
.badge { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent); color: #fff; font-size: 11.5px; font-weight: 600; display: grid; place-items: center; }
.sb-search { margin: 12px 10px 4px; position: relative; }
.sb-search input { width: 100%; padding: 7px 10px 7px 32px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface); outline: none; font-size: 13.5px; }
.sb-search input:focus { border-color: var(--border-strong); }
.sb-search .ic { position: absolute; left: 10px; top: 9px; color: var(--faint); }
.chat-list { flex: 1; overflow-y: auto; padding: 4px 10px 12px; min-height: 0; }
.sb-section { font-size: 12px; color: var(--faint); font-weight: 500; padding: 14px 12px 4px; }
.chat-item { display: flex; align-items: center; gap: 6px; padding: 6px 6px 6px 12px; border-radius: 8px; font-size: 13.8px; position: relative; }
.chat-item:hover { background: rgba(0,0,0,.04); }
.chat-item.active { background: var(--surface); box-shadow: var(--shadow); }
.ci-title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ci-menu { opacity: 0; width: 24px; height: 24px; border-radius: 6px; display: grid; place-items: center; color: var(--muted); }
.chat-item:hover .ci-menu, .chat-item.active .ci-menu { opacity: 1; }
.ci-menu:hover { background: var(--border); }
.ci-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: pulse 1s infinite; }
.sb-foot { border-top: 1px solid var(--border); padding: 10px; }
.profile { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px; border-radius: 10px; text-align: left; }
.profile:hover { background: rgba(0,0,0,.04); }
.avatar-sm { width: 32px; height: 32px; border-radius: 50%; background: var(--text); color: var(--bg); display: grid; place-items: center; font-weight: 600; font-size: 13px; flex: none; }

#scrim { display: none; }

/* ---------- buttons ---------- */
.icon-btn { width: 34px; height: 34px; border-radius: 9px; display: inline-grid; place-items: center; color: var(--muted); flex: none; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.sm { width: 28px; height: 28px; border-radius: 7px; }
.icon-btn.on { color: var(--accent); background: var(--accent-soft); }
.btn { display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px; border-radius: 10px; border: 1px solid var(--border-strong); background: var(--surface); font-weight: 500; font-size: 14px; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn.primary:hover { opacity: .88; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.accent:hover { background: var(--accent-hover); }
.btn.ghost { border-color: transparent; background: none; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------- main ---------- */
#main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
.topbar { display: flex; align-items: center; gap: 8px; padding: 10px 16px; min-height: 54px; }
.topbar .title-btn { font-weight: 500; padding: 5px 10px; border-radius: 8px; max-width: 50vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .title-btn:hover { background: var(--surface-2); }
.proj-badge { font-size: 12.5px; color: var(--muted); display: inline-flex; gap: 5px; align-items: center; padding: 3px 9px; border-radius: 20px; border: 1px solid var(--border); }
.proj-badge:hover { color: var(--text); }
.sb-toggle-main { display: none; }
body.sb-collapsed .sb-toggle-main { display: inline-grid; }

/* new chat */
.new-view { flex: 1; overflow-y: auto; display: flex; flex-direction: column; align-items: center; padding: 12vh 20px 40px; }
.hero { text-align: center; margin-bottom: 26px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.hero h1 { font-size: 38px; margin: 6px 0 0; line-height: 1.15; }
.hero p { margin: 0; }
.new-view .composer { width: min(680px, 100%); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 18px; max-width: 700px; }
.chip { display: inline-flex; gap: 7px; align-items: center; padding: 7px 13px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); font-size: 13.5px; }
.chip:hover { color: var(--text); border-color: var(--border-strong); }
.chip.active { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.proj-note { margin-top: 14px; font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; }

/* chat */
.chat-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.messages { flex: 1; overflow-y: auto; min-height: 0; }
.messages-inner { max-width: 760px; margin: 0 auto; padding: 12px 24px 30px; display: flex; flex-direction: column; gap: 26px; }
.composer-wrap { padding: 0 20px 14px; }
.composer-wrap .composer { max-width: 760px; margin: 0 auto; }
.disclaimer { text-align: center; font-size: 11.5px; color: var(--faint); margin-top: 8px; }

.msg.user { display: flex; flex-direction: column; align-items: flex-end; }
.msg.user .bubble { background: var(--user-bubble); border-radius: 16px; padding: 10px 15px; max-width: 85%; white-space: pre-wrap; word-wrap: break-word; }
.msg.user .bubble img { max-width: 220px; max-height: 220px; border-radius: 10px; display: block; margin-bottom: 8px; }
.msg.user .imgs { display: flex; gap: 6px; flex-wrap: wrap; }
.msg.user textarea { width: 100%; min-width: min(500px, 70vw); border: 0; background: none; outline: none; resize: vertical; min-height: 60px; }
.msg-actions { display: flex; gap: 2px; margin-top: 6px; opacity: 0; transition: opacity .15s; }
.msg:hover .msg-actions, .msg.last .msg-actions { opacity: 1; }
.msg-actions .icon-btn { width: 30px; height: 30px; }
.msg.assistant { display: flex; gap: 14px; }
.msg.assistant .avatar { margin-top: 2px; }
.msg-body { flex: 1; min-width: 0; }
.meta-note { font-size: 12px; color: var(--faint); margin-top: 6px; }
.err { background: var(--bad-soft); color: var(--bad); padding: 10px 14px; border-radius: 10px; font-size: 14px; margin-top: 6px; display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.typing { display: flex; gap: 5px; padding: 10px 0; align-items: center; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: bounce 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .15s; } .typing span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-4px); } }
@keyframes pulse { 50% { opacity: .35; } }
details.thinking { margin-bottom: 10px; border: 1px solid var(--border); border-radius: 10px; padding: 7px 12px; font-size: 13.5px; color: var(--muted); }
details.thinking summary { cursor: pointer; list-style: none; display: flex; gap: 6px; align-items: center; }
details.thinking summary::-webkit-details-marker { display: none; }
details.thinking .md { margin-top: 6px; font-size: 13.5px; }
.thinking.live summary { animation: pulse 1.6s infinite; }

/* markdown */
.md { word-wrap: break-word; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 .8em; }
.md h1, .md h2, .md h3, .md h4 { font-family: var(--serif); font-weight: 600; line-height: 1.3; margin: 1.2em 0 .5em; }
.md h1 { font-size: 1.5em; } .md h2 { font-size: 1.3em; } .md h3 { font-size: 1.12em; }
.md ul, .md ol { padding-left: 1.4em; margin: 0 0 .8em; }
.md li { margin: .2em 0; }
.md code { background: var(--code-bg); padding: .1em .35em; border-radius: 5px; font-size: .9em; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.md pre { background: var(--code-bg); padding: 12px 14px; border-radius: 10px; overflow-x: auto; border: 1px solid var(--border); }
.md pre code { background: none; padding: 0; }
.md blockquote { margin: 0 0 .8em; padding: 2px 14px; border-left: 3px solid var(--accent); color: var(--muted); }
.md table { border-collapse: collapse; margin: 0 0 1em; display: block; overflow-x: auto; max-width: 100%; font-size: .94em; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 11px; text-align: left; }
.md th { background: var(--surface-2); font-weight: 600; }
.md a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 1.2em 0; }
.md strong { font-weight: 600; }

/* artifact chip */
.art-chip { display: flex; align-items: center; gap: 12px; width: min(420px, 100%); text-align: left; border: 1px solid var(--border); background: var(--surface); border-radius: 12px; padding: 10px 14px 10px 10px; margin: 10px 0 12px; box-shadow: var(--shadow); transition: border-color .15s; }
.art-chip:hover { border-color: var(--border-strong); }
.art-chip.open { border-color: var(--accent); }
.art-chip-ic { width: 42px; height: 42px; border-radius: 9px; background: var(--surface-2); display: grid; place-items: center; color: var(--accent); flex: none; border: 1px solid var(--border); }
.art-chip-title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.art-chip-sub { font-size: 12.5px; color: var(--muted); }
.art-chip > div:nth-child(2) { min-width: 0; flex: 1; }

/* composer */
.composer { background: var(--surface); border: 1px solid var(--border-strong); border-radius: 18px; box-shadow: var(--shadow); padding: 10px 10px 8px 14px; transition: border-color .15s, box-shadow .15s; }
.composer:focus-within { border-color: var(--faint); box-shadow: var(--shadow), 0 0 0 3px rgba(201,100,66,.08); }
.composer textarea { width: 100%; border: 0; outline: none; resize: none; background: none; min-height: 26px; max-height: 260px; padding: 4px 2px; font-size: 15.5px; line-height: 1.5; }
.composer.big textarea { min-height: 52px; }
.composer-bar { display: flex; align-items: center; gap: 4px; margin-top: 4px; }
.model-label { font-size: 12.5px; color: var(--faint); margin-right: 6px; }
.send-btn { width: 34px; height: 34px; border-radius: 10px; background: var(--accent); color: #fff; display: grid; place-items: center; }
.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { opacity: .4; cursor: default; }
.send-btn.stop { background: var(--text); color: var(--bg); }
.attach-row { display: flex; gap: 8px; flex-wrap: wrap; }
.attach-row:not(:empty) { margin-bottom: 8px; }
.thumb { position: relative; width: 64px; height: 64px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb button { position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; border-radius: 50%; background: rgba(0,0,0,.65); color: #fff; display: grid; place-items: center; }

/* ---------- artifact panel ---------- */
#panel { width: 48%; max-width: 820px; min-width: 380px; flex: none; border-left: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; min-height: 0; }
.panel-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px 10px 18px; border-bottom: 1px solid var(--border); min-height: 54px; }
.panel-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.panel-sub { font-size: 12px; color: var(--muted); }
.panel-head > div:first-child { min-width: 0; flex: 1; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 3px; border: 1px solid var(--border); }
.seg button { padding: 4px 10px; border-radius: 7px; font-size: 13px; color: var(--muted); display: inline-flex; gap: 5px; align-items: center; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.panel-body { flex: 1; overflow-y: auto; min-height: 0; }
.panel-body > .md.doc { padding: 26px 32px 40px; font-size: 15.5px; }
.panel-body pre.code { margin: 0; padding: 18px 20px; font: 12.8px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; word-break: break-word; }
.art-frame { width: 100%; height: 100%; border: 0; display: block; background: #fff; }
.panel-body.frame { overflow: hidden; }
.ver-btn { font-size: 12.5px; color: var(--muted); padding: 3px 8px; border-radius: 7px; border: 1px solid var(--border); }

/* flashcards artifact */
.fc-toolbar { display: flex; align-items: center; gap: 8px; padding: 14px 20px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1; flex-wrap: wrap; }
.fc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; padding: 18px 20px 30px; }
.flip { perspective: 900px; height: 150px; cursor: pointer; }
.flip-inner { position: relative; width: 100%; height: 100%; transition: transform .45s cubic-bezier(.3,.7,.3,1); transform-style: preserve-3d; }
.flip.flipped .flip-inner { transform: rotateY(180deg); }
.face { position: absolute; inset: 0; backface-visibility: hidden; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); padding: 14px; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; gap: 6px; overflow: hidden; }
.face.back { transform: rotateY(180deg); background: var(--surface-2); }
.face .icon-btn { position: absolute; top: 6px; right: 6px; }
.fc-word { font-family: var(--serif); font-size: 19px; font-weight: 500; line-height: 1.25; }
.fc-ex { font-size: 12.5px; color: var(--muted); line-height: 1.35; }
.fc-notes { font-size: 11.5px; color: var(--faint); }

/* quiz */
.quiz { padding: 20px 26px 40px; display: flex; flex-direction: column; gap: 18px; }
.q-card { border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; }
.q-num { font-size: 12px; color: var(--faint); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.q-text { font-weight: 500; margin: 4px 0 12px; font-size: 15.5px; }
.q-opts { display: flex; flex-direction: column; gap: 7px; }
.q-opt { text-align: left; padding: 9px 13px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface); display: flex; gap: 10px; align-items: center; }
.q-opt:hover:not(:disabled) { border-color: var(--border-strong); background: var(--surface-2); }
.q-opt .letter { width: 22px; height: 22px; border-radius: 6px; background: var(--surface-2); display: grid; place-items: center; font-size: 12px; font-weight: 600; flex: none; color: var(--muted); }
.q-opt.right { border-color: var(--ok); background: var(--ok-soft); }
.q-opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.q-opt:disabled { cursor: default; color: var(--text); }
.q-expl { margin-top: 10px; font-size: 13.5px; color: var(--muted); padding: 8px 12px; border-radius: 8px; background: var(--surface-2); }
.q-expl p { display: inline; margin: 0; }
.q-score { text-align: center; padding: 18px; border-radius: 12px; background: var(--surface-2); }
.q-score .big { font-family: var(--serif); font-size: 34px; }

/* ---------- pages ---------- */
.page { flex: 1; overflow-y: auto; min-height: 0; }
.page-inner { max-width: 1000px; margin: 0 auto; padding: 18px 32px 60px; }
.page-head { display: flex; align-items: center; gap: 12px; margin: 10px 0 6px; flex-wrap: wrap; }
.page-head h1 { font-size: 30px; margin: 0; flex: 1; min-width: 0; }
.page-desc { color: var(--muted); margin: 0 0 22px; }
.crumbs { font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.crumbs a:hover { color: var(--text); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.card { border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px; transition: border-color .15s, transform .15s; }
a.card:hover, .card.click:hover { border-color: var(--border-strong); transform: translateY(-1px); cursor: pointer; }
.card-title { font-weight: 600; font-size: 15.5px; }
.card-desc { font-size: 13.5px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-meta { font-size: 12.5px; color: var(--faint); margin-top: auto; padding-top: 6px; display: flex; gap: 10px; align-items: center; }
.empty { text-align: center; padding: 60px 20px; color: var(--muted); border: 1.5px dashed var(--border-strong); border-radius: var(--radius); }
.empty .ic { margin: 0 auto 10px; color: var(--faint); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 18px 0 24px; }
.stat { border: 1px solid var(--border); border-radius: 12px; padding: 12px 16px; background: var(--surface); }
.stat .v { font-family: var(--serif); font-size: 28px; font-weight: 500; line-height: 1.1; }
.stat .l { font-size: 12.5px; color: var(--muted); }
.stat.hl .v { color: var(--accent); }
.deck-due { color: var(--accent); font-weight: 600; }
.pill { font-size: 11.5px; padding: 2px 8px; border-radius: 20px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.pill.new { color: #3b6fb6; border-color: rgba(59,111,182,.3); }
.pill.due { color: var(--accent); border-color: rgba(201,100,66,.35); }
.pill.mature { color: var(--ok); border-color: rgba(63,138,79,.3); }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.search-input { padding: 8px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); outline: none; min-width: 200px; flex: 1; max-width: 320px; }
.card-rows { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.card-row { display: grid; grid-template-columns: 1fr 1fr auto auto; gap: 14px; align-items: center; padding: 11px 16px; border-top: 1px solid var(--border); }
.card-row:first-child { border-top: 0; }
.card-row .f { font-weight: 500; }
.card-row .ex { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.card-row .acts { display: flex; gap: 2px; opacity: .5; }
.card-row:hover .acts { opacity: 1; }
.project-grid { display: grid; grid-template-columns: 1fr 300px; gap: 28px; align-items: start; }
.side-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; background: var(--surface); margin-bottom: 14px; }
.side-head { display: flex; justify-content: space-between; align-items: center; font-weight: 600; font-size: 14px; margin-bottom: 8px; }
.side-card .clamp { font-size: 13.5px; max-height: 160px; overflow: hidden; }
.doc-item { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 8px; font-size: 13.5px; border: 1px solid var(--border); margin-bottom: 6px; }
.doc-item span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-rows { margin-top: 18px; }
.list-row { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.list-row:hover { background: var(--surface-2); }
.list-row .t { flex: 1; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .d { font-size: 12.5px; color: var(--faint); }
.filter-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.art-card-ic { width: 38px; height: 38px; border-radius: 9px; background: var(--surface-2); color: var(--accent); display: grid; place-items: center; border: 1px solid var(--border); margin-bottom: 4px; }

/* ---------- review ---------- */
.review-page { flex: 1; overflow-y: auto; display: flex; flex-direction: column; align-items: center; padding: 8px 20px 40px; min-height: 0; }
.review-top { width: min(720px, 100%); display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 26px; }
.progress { flex: 1; min-width: 120px; height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); transition: width .3s; }
.select { padding: 6px 10px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface); font-size: 13.5px; }
.rcard { width: min(640px, 100%); min-height: 320px; border: 1px solid var(--border); border-radius: 20px; background: var(--surface); box-shadow: var(--shadow); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 34px 30px; text-align: center; position: relative; gap: 10px; }
.rcard.clickable { cursor: pointer; }
.rcard .dir { position: absolute; top: 14px; left: 18px; font-size: 12px; color: var(--faint); }
.rcard .spk { position: absolute; top: 10px; right: 10px; }
.r-prompt { font-family: var(--serif); font-size: 34px; line-height: 1.2; font-weight: 500; }
.r-answer { font-family: var(--serif); font-size: 26px; color: var(--accent); }
.r-divider { width: 60px; height: 1px; background: var(--border-strong); margin: 8px 0; }
.r-ex { color: var(--muted); font-size: 14.5px; max-width: 480px; }
.r-notes { color: var(--faint); font-size: 13px; }
.r-hint { color: var(--faint); font-size: 13px; margin-top: 18px; }
.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; width: min(640px, 100%); margin-top: 20px; }
.grade { padding: 10px 6px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); font-weight: 500; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.grade small { font-size: 11.5px; color: var(--faint); font-weight: 400; }
.grade:hover { border-color: var(--border-strong); background: var(--surface-2); }
.grade.again { color: var(--bad); } .grade.hard { color: var(--warn); } .grade.good { color: var(--ok); } .grade.easy { color: #3b6fb6; }
.type-input { width: min(420px, 100%); padding: 12px 16px; border-radius: 12px; border: 1.5px solid var(--border-strong); background: var(--bg); text-align: center; font-size: 18px; outline: none; margin-top: 10px; }
.type-input:focus { border-color: var(--accent); }
.type-input.ok { border-color: var(--ok); background: var(--ok-soft); }
.type-input.bad { border-color: var(--bad); background: var(--bad-soft); }
.verdict { font-weight: 600; }
.verdict.ok { color: var(--ok); } .verdict.bad { color: var(--bad); } .verdict.close { color: var(--warn); }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: min(640px, 100%); margin-top: 18px; }
.choice { padding: 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); font-size: 15.5px; text-align: center; }
.choice:hover:not(:disabled) { border-color: var(--border-strong); background: var(--surface-2); }
.choice.right { border-color: var(--ok); background: var(--ok-soft); }
.choice.wrong { border-color: var(--bad); background: var(--bad-soft); }
.choice:disabled { cursor: default; color: var(--text); }
.next-row { display: flex; gap: 10px; justify-content: center; margin-top: 20px; }
.kbd { font-size: 11px; border: 1px solid var(--border-strong); border-radius: 4px; padding: 0 4px; color: var(--faint); margin-left: 4px; }
.done-box { width: min(560px, 100%); text-align: center; padding: 40px 20px; }
.done-box h2 { font-size: 30px; margin: 10px 0; }
.wrong-list { text-align: left; border: 1px solid var(--border); border-radius: 12px; margin: 20px 0; background: var(--surface); }
.wrong-list div { padding: 8px 14px; border-top: 1px solid var(--border); font-size: 14px; }
.wrong-list div:first-child { border-top: 0; }

/* ---------- modal / menu / toast ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(20,18,12,.42); display: grid; place-items: center; z-index: 50; padding: 16px; animation: fade .15s; }
.modal { background: var(--surface); border-radius: 18px; box-shadow: var(--shadow-lg); width: min(560px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; padding: 22px 24px; animation: pop .18s ease; }
.modal.wide { width: min(760px, 100%); }
.modal h2 { margin: 0 0 4px; font-size: 22px; }
.modal .sub { color: var(--muted); margin: 0 0 16px; font-size: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; flex-wrap: wrap; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.97) translateY(6px); } }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 13px; }
.field label { font-size: 13px; font-weight: 500; color: var(--muted); }
.field input, .field textarea, .field select { padding: 9px 12px; border-radius: 10px; border: 1px solid var(--border-strong); background: var(--bg); outline: none; width: 100%; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--accent); }
.field textarea { resize: vertical; min-height: 80px; line-height: 1.5; }
.field .hint { font-size: 12px; color: var(--faint); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.section-label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); font-weight: 600; margin: 18px 0 10px; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; margin-bottom: 10px; }
.key-ok { color: var(--ok); font-size: 12.5px; }
.menu { position: fixed; z-index: 60; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 5px; min-width: 190px; animation: pop .12s; }
.menu button { display: flex; width: 100%; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 8px; font-size: 14px; text-align: left; }
.menu button:hover { background: var(--surface-2); }
.menu button.danger { color: var(--bad); }
#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 70; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; box-shadow: var(--shadow-lg); animation: pop .18s; pointer-events: auto; display: flex; gap: 12px; align-items: center; max-width: 90vw; }
.toast a { text-decoration: underline; font-weight: 600; }
#sel-toolbar { position: fixed; z-index: 55; background: var(--text); color: var(--bg); border-radius: 10px; padding: 4px; display: flex; gap: 2px; box-shadow: var(--shadow-lg); }
#sel-toolbar button { padding: 5px 10px; border-radius: 7px; font-size: 13px; display: flex; gap: 6px; align-items: center; }
#sel-toolbar button:hover { background: rgba(127,127,127,.25); }
.spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.preview-list { max-height: 300px; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; }
.preview-list label { display: flex; gap: 10px; padding: 8px 12px; border-top: 1px solid var(--border); font-size: 14px; align-items: flex-start; }
.preview-list label:first-child { border-top: 0; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  body.panel-open #panel { position: fixed; inset: 0 0 0 auto; width: min(640px, 100%); max-width: none; min-width: 0; z-index: 40; box-shadow: var(--shadow-lg); }
}
@media (max-width: 800px) {
  #sidebar { position: fixed; inset: 0 auto 0 0; z-index: 45; margin-left: -272px; box-shadow: var(--shadow-lg); }
  body.sidebar-open #sidebar { margin-left: 0; }
  body.sidebar-open #scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 44; }
  .sb-toggle-main { display: inline-grid !important; }
  .sb-collapse { display: none; }
  .messages-inner { padding: 8px 16px 24px; }
  .composer-wrap { padding: 0 12px 10px; }
  .page-inner { padding: 10px 16px 40px; }
  .project-grid { grid-template-columns: 1fr; }
  .hero h1 { font-size: 30px; }
  .new-view { padding-top: 8vh; }
  .card-row { grid-template-columns: 1fr auto; }
  .card-row > :nth-child(2) { grid-column: 1; }
  .grades { grid-template-columns: repeat(2, 1fr); }
  .choices { grid-template-columns: 1fr; }
  .r-prompt { font-size: 28px; }
  .row2, .row3 { grid-template-columns: 1fr; }
  .panel-body > .md.doc { padding: 20px 18px 30px; }
  .model-label { display: none; }
}

/* ---------- auth ---------- */
body.auth-mode #app { display: none; }
.auth-wrap { position: fixed; inset: 0; overflow-y: auto; display: grid; place-items: center; padding: 24px 16px; background: var(--bg); }
.auth-card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow); padding: 28px 28px 24px; }
.auth-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.auth-card h2 { font-size: 22px; margin: 0 0 14px; }
.auth-btn { width: 100%; justify-content: center; padding: 11px; margin-top: 6px; }
.auth-note { margin: 16px 0 0; text-align: center; }
.auth-card .err { margin: 0 0 12px; }

/* ---------- admin ---------- */
.admin-card { margin-bottom: 8px; }
.admin-status { display: flex; gap: 6px; align-items: center; font-size: 14px; font-weight: 500; margin-bottom: 14px; }
.admin-status.ok { color: var(--ok); } .admin-status.bad { color: var(--bad); }
.invite-form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.invite-form input[type=text], .invite-form .search-input { flex: 1; min-width: 180px; }
.link-box { margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: var(--accent-soft); }
.link-box code { display: block; word-break: break-all; font-size: 13px; margin-top: 4px; user-select: all; cursor: text; }
.admin-list { margin-top: 10px; }
.admin-row { display: flex; align-items: center; gap: 14px; padding: 11px 14px; border-top: 1px solid var(--border); }
.admin-row:first-child { border-top: 0; }
.admin-row > div:first-child:not(.avatar-sm) { flex: 1; min-width: 0; }
.admin-row .acts { display: flex; gap: 2px; }
.admin-usage { text-align: right; min-width: 64px; }
@media (max-width: 800px) { .hide-sm { display: none; } .admin-row { gap: 10px; } .admin-usage { min-width: 48px; } }
