:root {
  --sidebar: #181818; --main: #232329; --hover: #2b2b32; --selected: #34343b; --border: #46464f;
  --primary: #647bf7; --text: #ececec; --muted: #97979b; --folder: #408cf0; --doc: #6e708c;
  --red: #e5484d; --orange: #f09632; --green: #46a758;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--main); color: var(--text);
  font: 15px/1.45 "Segoe UI", Inter, -apple-system, BlinkMacSystemFont, "Noto Sans", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; }
#app { display: flex; height: 100vh; height: 100dvh; }

/* sidebar */
#sidebar { width: 300px; flex: none; background: var(--sidebar); padding: 4px 8px 16px; overflow-y: auto; }
.ws { display: flex; align-items: center; justify-content: space-between; gap: 10px; height: 60px; padding: 0 8px; }
.ws-logo { width: auto; height: 32px; }
.icon-btn { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 4px 6px; border-radius: 6px; font-size: 16px; }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn:disabled { opacity: .4; cursor: default; background: none; }
.nav, .tree-row { display: flex; align-items: center; height: 33px; padding: 0 8px; border-radius: 8px;
  cursor: pointer; color: var(--text); text-decoration: none; user-select: none; white-space: nowrap; }
.nav { margin-bottom: 6px; }
.nav:hover, .tree-row:hover { background: var(--hover); }
.nav.active, .tree-row.active { background: var(--selected); }
.nav .ic { width: 24px; color: var(--muted); text-align: center; margin-right: 8px; }
.nav.strong { font-weight: 700; }
.badges { margin-left: auto; display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 13px; }
.pill { border: 1px solid var(--border); border-radius: 8px; padding: 2px 10px; }
.section-label { color: var(--muted); font-size: 13px; padding: 18px 12px 4px; }
.tree-row { gap: 8px; }
.tree-row .name { overflow: hidden; text-overflow: ellipsis; }

/* icons */
.i-folder { width: 18px; height: 14px; border-radius: 3px; background: linear-gradient(#78b4ff 0 28%, var(--folder) 28%); flex: none; position: relative; margin-top: 2px; }
.i-folder::before { content: ""; position: absolute; left: 0; top: -3px; width: 8px; height: 5px; border-radius: 2px 2px 0 0; background: #3a7ad8; }
.i-doc { width: 13px; height: 16px; border-radius: 2px; background: var(--doc); flex: none; position: relative; }
.i-doc::after { content: ""; position: absolute; right: 0; top: 0; border-width: 0 4px 4px 0; border-style: solid; border-color: var(--main) #a0a2be; }

/* main */
#main { flex: 1; min-width: 0; overflow-y: auto; padding: 12px 28px 40px 36px; }
.topbar { display: flex; gap: 10px; height: 40px; align-items: center; }
.arrow { font-size: 26px; line-height: 1; }
#btn-menu { display: none; }
.head { display: flex; align-items: center; gap: 12px; margin: 18px 0 22px; flex-wrap: wrap; }
.head h1 { flex: 1; margin: 0; font-size: 32px; font-weight: 700; line-height: 1.2; min-width: 200px; }
.btn { border: 1px solid var(--border); background: var(--main); border-radius: 6px; padding: 5px 14px; font-weight: 700;
  font-size: 16px; cursor: pointer; height: 34px; white-space: nowrap; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: #7890fa; }
.btn.small { font-size: 13px; height: 28px; padding: 2px 10px; font-weight: 600; }
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 4px); background: #2a2a31; border: 1px solid var(--border); border-radius: 8px;
  padding: 4px; min-width: 190px; z-index: 20; box-shadow: 0 8px 24px #0008; }
.menu button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 7px 10px; border-radius: 6px; cursor: pointer; }
.menu button:hover { background: var(--selected); }
.menu .danger { color: var(--red); }

.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.search { position: relative; }
.search input, input.text, textarea.text { background: #1e1e23; border: 1px solid var(--border); color: var(--text); border-radius: 6px;
  height: 32px; padding: 4px 10px 4px 34px; font: inherit; font-size: 16px; width: 224px; outline: none; }
input.text, textarea.text { padding-left: 10px; }
.search input:focus, input.text:focus { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.search::before { content: "⌕"; position: absolute; left: 11px; top: 3px; color: var(--muted); font-size: 18px; }
.chip { display: inline-flex; align-items: center; gap: 8px; height: 31px; padding: 0 15px; border-radius: 16px; background: var(--hover);
  border: 1.5px solid transparent; font-weight: 700; font-size: 14px; cursor: pointer; }
.chip:hover { background: var(--selected); }
.chip.on { border-color: #78787f; }
.chip i { width: 11px; height: 11px; border-radius: 2px; display: inline-block; }
.chip small { color: var(--muted); font-weight: 600; font-size: 14px; }
select.sort { margin-left: auto; background: var(--hover); color: var(--text); border: 0; border-radius: 16px; height: 31px; padding: 0 12px;
  font: inherit; font-weight: 700; font-size: 14px; cursor: pointer; }

.day { color: var(--muted); margin: 14px 4px 8px; }
.row { display: flex; align-items: center; gap: 12px; height: 54px; padding: 0 4px; border-radius: 6px; cursor: pointer; }
.row:hover { background: var(--hover); }
.row .box { width: 32px; height: 32px; border: 1px solid var(--border); border-radius: 6px; display: grid; place-items: center; flex: none; }
.row .t { flex: 1; min-width: 0; }
.row .t div:first-child { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .t div:last-child { font-size: 13px; color: var(--muted); }
.row .more { color: var(--muted); letter-spacing: 1px; font-weight: 700; }
.empty { color: var(--muted); padding: 30px 4px; }

/* editor */
.crumbs { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 8px; min-height: 34px; flex-wrap: wrap; }
.crumbs a { color: var(--muted); cursor: pointer; }
.crumbs .sp { flex: 1; }
.save-status { font-size: 12px; color: var(--muted); white-space: nowrap; }
.save-status.ok { color: var(--green); }
.save-status.err, .blk-conflict { color: var(--red); font-size: 12px; white-space: nowrap; }
.blk-conflict { padding-top: 6px; }
.blk-conflict[hidden] { display: none; }
.link-btn { background: none; border: 0; padding: 0; color: inherit; text-decoration: underline; cursor: pointer; font: inherit; }
.doc-title { font-size: 32px; font-weight: 700; outline: none; margin: 10px 0 14px; min-height: 44px; }
.doc-title:empty::before { content: "Untitled"; color: #5c5c64; }
.blk { display: flex; align-items: flex-start; gap: 6px; min-height: 30px; }
.bullet { width: 18px; height: 28px; flex: none; display: grid; place-items: center; cursor: pointer; }
.bullet::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.bullet.closed { background: radial-gradient(circle, transparent 3px, var(--selected) 3.5px 7px, transparent 7.5px); }
.btext { flex: 1; outline: none; font-size: 16px; padding: 2px 0; white-space: pre-wrap; word-break: break-word; min-height: 28px; }
.btext .arr { color: var(--primary); font-weight: 600; }
.btext .cz { background: #3a3f6b; border-radius: 4px; padding: 0 3px; }
.ncards { color: var(--primary); font-size: 12px; padding-top: 6px; white-space: nowrap; }
.add-area { min-height: 160px; cursor: text; }

.ai-panel { background: var(--hover); border-radius: 10px; padding: 14px 16px; margin: 6px 0 12px; }
.ai-panel textarea.text { width: 100%; height: auto; min-height: 90px; margin: 10px 0 6px; padding: 8px 10px; resize: vertical; }
.ai-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.ai-card { display: flex; gap: 10px; align-items: center; margin: 6px 0; }
.ai-card input.text { flex: 1; width: auto; padding-left: 10px; }
.ai-sugg { margin: 6px 0 10px; }
.ai-kind { font-size: 12px; color: var(--primary); white-space: nowrap; min-width: 96px; }
.ai-panel textarea.ai-items { min-height: 0; margin: 2px 0 0 132px; width: calc(100% - 132px); font-size: 14px; }
@media (max-width: 820px) { .ai-panel textarea.ai-items { margin-left: 0; width: 100%; } }

/* flashcards */
.stats { display: flex; gap: 12px; flex-wrap: wrap; }
.stat { background: var(--hover); border-radius: 10px; padding: 14px 18px; min-width: 160px; flex: 1; max-width: 220px; }
.stat div:first-child { color: var(--muted); font-size: 13px; }
.stat div:last-child { font-size: 24px; font-weight: 700; }
.bar { height: 8px; background: #1b1b20; border-radius: 4px; overflow: hidden; margin: 14px 0 22px; max-width: 900px; }
.bar > div { height: 100%; background: var(--green); }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; }
.cols h3 { margin: 0 0 8px; font-size: 17px; }
.deck { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.deck .m { color: var(--muted); font-size: 13px; flex: 1; }
.up { padding: 3px 0; font-size: 14px; } .up b { color: var(--primary); font-weight: 600; margin-right: 8px; font-size: 13px; }

.review { max-width: 760px; margin: 0 auto; text-align: center; }
.review .meta { color: var(--muted); font-size: 13px; margin: 18px 0 22px; }
.flash { background: var(--hover); border-radius: 12px; padding: 28px; }
.flash .kind { color: var(--primary); font-size: 12px; margin-bottom: 8px; }
.flash .front { font-size: 24px; white-space: pre-wrap; }
.flash .front.concept { font-weight: 700; }
.flash hr { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }
.flash .back { font-size: 20px; color: #c8d2ff; white-space: pre-wrap; }
.grades { display: grid; grid-template-columns: repeat(4, 1fr) auto; gap: 8px; margin-top: 24px; }
.grade { border: 0; border-radius: 8px; color: #fff; padding: 8px; min-height: 52px; cursor: pointer; font-size: 13px; }
.grade:disabled { opacity: .55; cursor: wait; }
.grade b { display: block; font-size: 14px; }
.g0 { background: #c8434a; } .g1 { background: #cf8530; } .g2 { background: #3f9750; } .g3 { background: #5870dc; }
.grade.skip { background: var(--hover); color: var(--text); padding: 8px 16px; }
.progress { height: 6px; background: #1b1b20; border-radius: 3px; overflow: hidden; margin-top: 10px; }
.progress > div { height: 100%; background: var(--primary); }

.grade.suggest { outline: 3px solid #fff; outline-offset: 2px; }

/* pictures and image occlusion */
.img-note { flex: 1; min-width: 0; padding: 4px 0 8px; }
.img-stage { position: relative; display: inline-block; max-width: 100%; line-height: 0; user-select: none; }
.img-stage img { max-width: 100%; max-height: 420px; border-radius: 6px; display: block; }
.img-bar { display: flex; align-items: center; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.img-cap { color: var(--muted); font-size: 13px; margin-right: auto; }
.btn.small { padding: 2px 10px; font-size: 13px; }
.occ { position: absolute; box-sizing: border-box; border-radius: 3px; display: grid; place-items: center; line-height: 1.2; font-size: 13px; font-weight: 700; color: #fff; overflow: hidden; }
.occ.preview { border: 2px dashed var(--orange); background: #f0963226; }
.occ.tested { background: var(--orange); border: 2px solid #ffc27a; font-size: 20px; }
.occ.other { background: #6e708c; border: 1px solid #9a9cb8; }
.occ.revealed { border: 3px solid var(--green); background: #46a75822; }
.occ.revealed span { background: var(--green); padding: 1px 6px; border-radius: 4px; align-self: end; margin-bottom: -2px; }
.occl-review { margin: 16px 0 4px; }
.occl-review .img-stage img { max-height: 60vh; }
.flash .front.small { font-size: 16px; color: var(--muted); }
.type-in { width: min(420px, 100%); margin-top: 12px; padding: 8px 10px; }
.verdict { margin-top: 12px; font-weight: 700; font-size: 15px; }
.verdict.ok { color: var(--green); } .verdict.bad { color: var(--red); }
.choices { display: grid; gap: 8px; margin: 18px auto 0; max-width: 520px; text-align: left; }
.choice { display: flex; gap: 12px; align-items: center; background: var(--main); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 10px 14px; font-size: 16px; cursor: pointer; }
.choice b { color: var(--primary); width: 18px; }
.choice:hover:not(:disabled) { border-color: var(--primary); }
.choice.right { border-color: var(--green); background: #46a7582e; }
.choice.wrong { border-color: var(--red); background: #e5484d2e; }
.choice.dim { opacity: .55; }
.list-ans { text-align: left; max-width: 520px; margin: 18px auto 0; font-size: 18px; padding-left: 28px; }
.list-ans li { padding: 4px 0; color: var(--muted); }
.list-ans li.on { color: #c8d2ff; }
.occl-dlg { width: min(1100px, 96vw); max-height: 94vh; background: var(--main); color: var(--text); border: 1px solid var(--border); border-radius: 12px; padding: 16px 20px; }
.occl-dlg::backdrop { background: #000a; }
.occl-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.occl-head h2 { margin: 0 8px 0 0; font-size: 20px; }
.occl-head .sp { flex: 1; }
.occl-head input.text { width: 220px; padding: 5px 8px; }
.occl-check { display: flex; gap: 6px; align-items: center; font-size: 14px; cursor: pointer; }
.occl-body { display: grid; grid-template-columns: 1fr 300px; gap: 16px; align-items: start; }
.occl-stage { position: relative; line-height: 0; user-select: none; touch-action: none; cursor: crosshair; justify-self: center; }
.occl-stage img { max-width: 100%; max-height: 72vh; display: block; border-radius: 6px; pointer-events: none; }
.occ.edit { background: #f09632cc; border: 2px solid #ffc27a; cursor: move; }
.occ.edit.sel { outline: 3px solid var(--primary); outline-offset: 1px; }
.occ.edit span { pointer-events: none; }
.occ-resize { position: absolute; right: -2px; bottom: -2px; width: 12px; height: 12px; background: #fff; border-radius: 2px; cursor: nwse-resize; }
.occl-list { max-height: 72vh; overflow-y: auto; display: grid; gap: 6px; align-content: start; }
.occl-row { display: flex; gap: 6px; align-items: center; padding: 4px; border-radius: 6px; }
.occl-row.sel { background: var(--selected); }
.occl-row b { width: 20px; color: var(--orange); }
.occl-row input.text { flex: 1; min-width: 0; padding: 4px 6px; }
.occl-row input.grp { flex: 0 0 64px; }

.form { display: grid; grid-template-columns: 240px 220px; gap: 10px 24px; align-items: center; margin: 8px 0 16px; }
.form input { width: 100%; }
.note { color: var(--muted); font-size: 14px; }
code { background: #1b1b20; padding: 1px 6px; border-radius: 4px; font-size: 13px; }
pre { background: #1b1b20; padding: 12px; border-radius: 8px; overflow-x: auto; font-size: 13px; }

.hits .row .t div:first-child { font-size: 16px; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--selected); padding: 10px 16px; border-radius: 8px; z-index: 50; display: flex; align-items: center; gap: 12px; }
#toast[hidden] { display: none; }
.toast-act { background: var(--primary); color: #fff; border: 0; border-radius: 6px; padding: 4px 10px; font-size: 13px; font-weight: 700; cursor: pointer; }

/* phone */
@media (max-width: 820px) {
  #sidebar { position: fixed; z-index: 30; left: 0; top: 0; bottom: 0; transform: translateX(-100%); transition: transform .2s; width: 280px; }
  body.nav-open #sidebar { transform: none; }
  body.nav-open #scrim { position: fixed; inset: 0; background: #0007; z-index: 25; }
  #btn-menu { display: inline-block; }
  #main { padding: 8px 14px 40px; padding-top: max(8px, env(safe-area-inset-top)); }
  .head h1, .doc-title { font-size: 26px; }
  .search input { width: 100%; }
  .search { flex: 1 1 100%; }
  select.sort { margin-left: 0; }
  .cols { grid-template-columns: 1fr; }
  .grades { grid-template-columns: 1fr 1fr; }
  .grade.skip { grid-column: span 2; }
  .form { grid-template-columns: 1fr; }
  .flash { padding: 20px 14px; }
  .occl-body { grid-template-columns: 1fr; }
}
.nav.tutor-entry { width: 100%; border: 0; background: transparent; text-align: left; }
.nav.tutor-entry:hover { background: var(--hover); }
#tutor { position: fixed; inset: 0 0 0 auto; margin: 0; width: min(480px, 100%); max-width: none;
  height: 100dvh; max-height: none; padding: 0; color: var(--text); color-scheme: dark;
  background: var(--main); border: 0; border-left: 1px solid var(--border); }
#tutor[open] { display: flex; flex-direction: column; }
#tutor::backdrop { background: rgb(12 12 17 / .5); }
.tutor-head, .tutor-footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.tutor-head { padding: 16px 20px; border-bottom: 1px solid var(--border); }
.tutor-head h2 { margin: 0; font-size: 19px; }
.tutor-scope { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.tutor-log { flex: 1; overflow-y: auto; min-height: 0; padding: 16px 20px; }
.tutor-log article + article { margin-top: 24px; }
.tutor-start { padding: 12px 0; }
.tutor-start > div { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tutor-user { width: fit-content; max-width: 90%; margin: 0 0 10px auto; padding: 8px 12px;
  background: var(--selected); border-radius: 10px 10px 2px 10px; }
.tutor-user, .tutor-answer { white-space: pre-wrap; overflow-wrap: anywhere; }
.tutor-form { display: grid; gap: 8px; padding: 12px 20px max(14px, env(safe-area-inset-bottom)); border-top: 1px solid var(--border); }
.tutor-controls { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; }
.tutor-controls[hidden] { display: none; }
.tutor-form label, .tutor-draft label, .tutor-options label { color: var(--muted); font-size: 13px; }
.tutor-form select { background: var(--hover); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 5px 7px; font: inherit; }
.tutor-form .tutor-count { width: 58px; }
.tutor-keywords, .tutor-draft label, .tutor-options label { display: grid; gap: 3px; }
#tutor textarea { width: 100%; min-height: 48px; height: auto; resize: vertical; padding: 7px 9px; }
.tutor-citations, .tutor-quiz, .tutor-draft { margin-top: 12px; padding: 12px; border: 1px solid var(--border); border-radius: 8px; }
.tutor-source { display: flex; flex-direction: column; width: 100%; margin-top: 6px; text-align: left; }
.tutor-source span { color: var(--muted); font-weight: 400; overflow-wrap: anywhere; }
.tutor-draft label { margin: 8px 0; }
.tutor-options { display: grid; gap: 6px; }
.tutor-options button { white-space: normal; text-align: left; }
.tutor-quiz p { margin: 0 0 8px; }
.tutor-feedback:not(:empty) { margin-top: 12px; }

.pdf-controls, .pdf-library-row { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.pdf-controls input[type=number] { width: 64px; }
.pdf-controls input[type=file] { display: block; max-width: 100%; margin-top: 5px; }
.pdf-controls .btn, .head a.btn { text-decoration: none; }
.pdf-library-row { padding: 12px 0; border-bottom: 1px solid var(--border); }
.pdf-library-row > a { flex: 1 1 220px; color: inherit; overflow-wrap: anywhere; }
.pdf-title { overflow-wrap: anywhere; }
.pdf-canvas { margin-top: 16px; text-align: center; }
.pdf-canvas canvas { max-width: 100%; height: auto; background: white; border: 1px solid var(--border); }

.ai-settings-list { display: grid; gap: 8px; margin: 10px 0 12px; max-width: 720px; }
.ai-provider-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 12px;
  background: var(--hover); border: 1px solid var(--border); border-radius: 8px; }
.ai-provider-info { flex: 1 1 260px; min-width: 0; }
.ai-provider-info .m { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.ai-provider-badge { display: inline-block; font-size: 11px; font-weight: 600; color: var(--primary);
  border: 1px solid var(--border); border-radius: 999px; padding: 1px 7px; margin-left: 6px; vertical-align: middle; }
.ai-provider-form { max-width: 720px; margin: 12px 0; padding: 14px 16px; background: var(--hover);
  border: 1px solid var(--border); border-radius: 10px; }
.ai-provider-form .form { grid-template-columns: 160px minmax(0, 1fr); }
.ai-provider-form select.text { background: #1e1e23; border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; height: 32px; padding: 4px 10px; font: inherit; font-size: 15px; width: 100%; }
.ai-task-list { display: grid; gap: 10px; margin: 10px 0 12px; max-width: 780px; }
.ai-task-card { padding: 12px 14px; background: var(--hover); border: 1px solid var(--border); border-radius: 8px; }
.ai-task-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.ai-target-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.ai-target-row select.text, .ai-target-row input.text { background: #1e1e23; border: 1px solid var(--border);
  color: var(--text); border-radius: 6px; height: 30px; padding: 3px 8px; font: inherit; font-size: 14px; width: auto; }
.ai-target-row input.text { min-width: 170px; flex: 1 1 170px; }
.ai-target-tag { font-size: 12px; color: var(--muted); min-width: 72px; }
.tutor-form .tutor-model { width: 145px; height: 30px; font-size: 13px; padding: 3px 8px; }
@media (max-width: 820px) { .ai-provider-form .form { grid-template-columns: 1fr; } }
