/* Study Desk design system.
   Tokens follow the Silex dashboard: dark neutral surfaces, soft borders,
   one accent, Ubuntu for interface text. A light theme mirrors every token. */

:root {
  color-scheme: dark;
  --bg-0: #111111;        /* page */
  --bg-1: #1A1A1A;        /* panels, cards */
  --bg-2: #1D1D1D;        /* raised */
  --bg-3: #252525;        /* buttons, badges */
  --hover: #222222;
  --active: #2A2A2A;
  --input: #141414;
  --text-1: #E5E5E5;
  --text-2: #A8A8A8;
  --text-3: #707070;
  --text-inverse: #FFFFFF;
  --border: rgba(255, 255, 255, 0.08);
  --border-visible: rgba(255, 255, 255, 0.16);
  --border-strong: #2E2E2E;
  --accent: #8873FE;
  --accent-strong: #6A55D9;
  --accent-strong-hover: #5A45C8;
  --accent-soft: rgba(136, 115, 254, 0.14);
  --success: #5FD68F;
  --success-soft: rgba(95, 214, 143, 0.14);
  --warning: #FFA94D;
  --warning-soft: rgba(255, 169, 77, 0.14);
  --error: #FF6B6B;
  --error-soft: rgba(255, 107, 107, 0.14);
  --danger: #C93C3C;
  --danger-hover: #B53333;
  --backdrop: rgba(0, 0, 0, 0.6);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
  --sans: 'Ubuntu', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  --serif: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px; --s8: 32px; --s10: 40px; --s12: 48px;
  --r-sm: 6px; --r-md: 8px; --r-lg: 12px;
  --t-fast: 0.15s; --t-med: 0.2s;
  --sidebar-w: 240px;
  --rail-w: 240px;
  --tutor-w: 400px;
  --topbar-h: 56px;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg-0: #F4F4F5; --bg-1: #FFFFFF; --bg-2: #FAFAFA; --bg-3: #EFEFF1;
  --hover: #F1F1F3; --active: #E9E9EC; --input: #FFFFFF;
  --text-1: #18181B; --text-2: #5C5C66; --text-3: #8E8E96; --text-inverse: #FFFFFF;
  --border: rgba(0, 0, 0, 0.08); --border-visible: rgba(0, 0, 0, 0.16); --border-strong: #E4E4E7;
  --accent: #6A55D9; --accent-strong: #6A55D9; --accent-strong-hover: #5A45C8; --accent-soft: rgba(106, 85, 217, 0.12);
  --success: #1E9E5A; --success-soft: rgba(30, 158, 90, 0.12);
  --warning: #C77A1A; --warning-soft: rgba(199, 122, 26, 0.12);
  --error: #D23F3F; --error-soft: rgba(210, 63, 63, 0.10);
  --backdrop: rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06); --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.08); --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg-0); color: var(--text-1);
  font-family: var(--sans); font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; overscroll-behavior: none;
}
h1, h2, h3, h4 { margin: 0; font-weight: 500; line-height: 1.25; }
h1 { font-size: 24px; } h2 { font-size: 18px; } h3 { font-size: 15px; }
p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.hidden { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }

/* ---------- Controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  height: 36px; padding: 0 var(--s4); border: none; border-radius: var(--r-sm);
  background: color-mix(in srgb, var(--text-1) 8%, transparent); color: inherit;
  font-weight: 500; white-space: nowrap; text-decoration: none;
  transition: background var(--t-fast) ease, opacity var(--t-fast) ease;
}
.btn:hover { background: color-mix(in srgb, var(--text-1) 12%, transparent); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--accent-strong); color: var(--text-inverse); }
.btn.primary:hover { background: var(--accent-strong-hover); }
.btn.danger { background: var(--danger); color: var(--text-inverse); }
.btn.danger:hover { background: var(--danger-hover); }
.btn.ghost { background: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--hover); color: var(--text-1); }
.btn.sm { height: 30px; padding: 0 var(--s3); font-size: 13px; }
.btn svg { width: 16px; height: 16px; flex: none; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px;
  border: none; border-radius: var(--r-sm); background: transparent; color: var(--text-2);
}
.icon-btn:hover { background: var(--hover); color: var(--text-1); }
.icon-btn svg { width: 18px; height: 18px; }
.field {
  width: 100%; height: 38px; padding: 0 var(--s3); border: 1px solid var(--border-visible);
  border-radius: var(--r-sm); background: var(--input); color: var(--text-1);
  transition: border-color var(--t-fast) ease;
}
.field:focus { border-color: var(--accent); outline: none; }
textarea.field { height: auto; min-height: 96px; padding: var(--s2) var(--s3); resize: vertical; line-height: 1.5; }
select.field { appearance: none; padding-right: var(--s8); background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23a8a8a8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><path d='M6 9l6 6 6-6'/></svg>"); background-repeat: no-repeat; background-position: right 12px center; }
label.lbl { display: grid; gap: var(--s1); font-size: 13px; color: var(--text-2); }
label.lbl > span { font-weight: 500; }
.error { color: var(--error); font-size: 13px; min-height: 1.2em; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 var(--s2);
  border-radius: 999px; background: var(--bg-3); color: var(--text-2); font-size: 12px; font-weight: 500;
  white-space: nowrap;
}
.pill.finance { background: var(--accent-soft); color: var(--accent); }
.pill.mining { background: var(--warning-soft); color: var(--warning); }
.pill.done { background: var(--success-soft); color: var(--success); }
.pill.reading { background: var(--warning-soft); color: var(--warning); }
.progress { height: 6px; border-radius: 999px; background: var(--bg-3); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width var(--t-med) ease; }
.progress.complete > i { background: var(--success); }

/* Menus (dropdown) */
.menu {
  position: absolute; z-index: 40; min-width: 170px; padding: var(--s1);
  background: var(--bg-2); border: 1px solid var(--border-visible); border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
}
.menu button {
  display: flex; width: 100%; align-items: center; justify-content: space-between; gap: var(--s4);
  padding: var(--s2) var(--s3); border: none; border-radius: var(--r-sm); background: transparent; text-align: left;
}
.menu button:hover { background: var(--hover); }
.menu button.danger { color: var(--error); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: var(--s1) 0; }

/* Dialogs */
dialog {
  border: 1px solid var(--border-visible); border-radius: var(--r-lg); background: var(--bg-1); color: var(--text-1);
  padding: 0; width: min(520px, calc(100vw - 32px)); box-shadow: var(--shadow-lg);
}
dialog::backdrop { background: var(--backdrop); }
dialog form { display: grid; gap: var(--s4); padding: var(--s6); }
dialog h2 { font-size: 18px; }
dialog .dlg-sub { color: var(--text-2); margin-top: -8px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: var(--s2); margin-top: var(--s2); }
.dlg-actions .spacer { flex: 1; }
.btn.danger-text { color: var(--error); }
.btn.danger-text:hover { background: var(--error-soft); }
.voice-row .btn.sm { height: 28px; }
.drop {
  display: flex; align-items: center; justify-content: center; gap: var(--s2); min-height: 72px; padding: var(--s3);
  border: 1px dashed var(--border-visible); border-radius: var(--r-md); color: var(--text-2); text-align: center; cursor: pointer;
}
.drop:hover, .drop.has { border-color: var(--accent); color: var(--text-1); }
.drop input { display: none; }
.or { text-align: center; color: var(--text-3); font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60;
  padding: 10px 14px; border-radius: var(--r-md); background: var(--bg-2); border: 1px solid var(--border-visible);
  box-shadow: var(--shadow-lg); font-size: 13px; max-width: calc(100vw - 32px);
}
.toast.err { color: var(--error); }

/* ---------- Login ---------- */
#login { min-height: 100%; display: grid; place-items: center; padding: var(--s6); }
.login-card {
  width: 100%; max-width: 360px; padding: var(--s8); display: grid; gap: var(--s4);
  background: var(--bg-1); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-md);
}
.brand { display: flex; align-items: center; gap: var(--s3); font-size: 16px; font-weight: 500; letter-spacing: 0.02em; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 7px; background: var(--accent-strong); color: #fff;
  display: grid; place-items: center; flex: none;
}
.brand-mark svg { width: 16px; height: 16px; }
.login-card h1 { font-size: 22px; }
.login-card p { color: var(--text-2); }

/* ---------- Shell ---------- */
#shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); height: 100dvh; }
#sidebar {
  display: flex; flex-direction: column; gap: var(--s6); padding: var(--s8) var(--s3) var(--s4);
  background: var(--bg-0); border-right: 1px solid var(--border); min-height: 0;
}
#sidebar .brand { padding: 0 var(--s3); height: 30px; }
.nav { display: flex; flex-direction: column; gap: var(--s1); }
.nav-label { padding: 0 var(--s3); font-size: 11px; font-weight: 500; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-3); margin-bottom: var(--s1); }
.nav-item {
  display: flex; align-items: center; gap: var(--s3); height: 36px; padding: 0 var(--s3);
  border: none; border-radius: var(--r-sm); background: transparent; color: var(--text-2); text-align: left; width: 100%;
  text-decoration: none; transition: background var(--t-fast) ease, color var(--t-fast) ease;
}
.nav-item:hover { background: var(--hover); color: var(--text-1); }
.nav-item.on { background: var(--active); color: var(--text-1); }
.nav-item svg { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-item .dot { width: 10px; height: 10px; border-radius: 3px; flex: none; margin: 0 4px; }
.nav-item .txt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .cnt { font-size: 12px; color: var(--text-3); }
.nav-scroll { overflow-y: auto; min-height: 0; flex: 1; }
.side-foot { display: grid; gap: var(--s1); padding-top: var(--s3); border-top: 1px solid var(--border); }
.side-foot .model { padding: var(--s1) var(--s3); font-size: 12px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#main { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--bg-1); }
#topbar {
  display: flex; align-items: center; gap: var(--s3); height: var(--topbar-h); padding: 0 var(--s6);
  border-bottom: 1px solid var(--border); flex: none;
}
#topbar .crumbs { flex: 1; min-width: 0; display: flex; align-items: center; gap: var(--s2); color: var(--text-2); overflow: hidden; white-space: nowrap; }
#topbar .crumbs a { color: var(--text-2); }
#topbar .crumbs a:hover { color: var(--text-1); }
#topbar .crumbs .sep { color: var(--text-3); }
#topbar .crumbs .cur { color: var(--text-1); font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
#topbar .actions { display: flex; align-items: center; gap: var(--s2); flex: none; }
#menu-btn { display: none; }
#page { flex: 1; min-height: 0; overflow-y: auto; }
#scrim { display: none; position: fixed; inset: 0; background: var(--backdrop); z-index: 29; }

/* ---------- Pages (dashboard / project) ---------- */
.page-inner { max-width: 1080px; margin: 0 auto; padding: var(--s8) var(--s6) var(--s12); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s4); margin-bottom: var(--s6); flex-wrap: wrap; }
.page-head h1 { font-size: 26px; }
.page-head .sub { color: var(--text-2); margin-top: var(--s1); }
.section-title { font-size: 13px; font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-3); margin: var(--s8) 0 var(--s3); display: flex; align-items: center; justify-content: space-between; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s3); }
.stat { padding: var(--s4); background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--r-md); }
.stat .k { font-size: 12px; color: var(--text-2); }
.stat .v { font-size: 26px; font-weight: 500; line-height: 1.2; margin-top: var(--s1); }
.stat .v small { font-size: 13px; color: var(--text-3); font-weight: 400; margin-left: 4px; }

.continue {
  color: inherit; display: flex; align-items: center; gap: var(--s4); padding: var(--s4) var(--s5);
  background: var(--bg-2); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: var(--r-md);
}
.continue .body { flex: 1; min-width: 0; }
.continue .k { font-size: 12px; color: var(--text-2); }
.continue .t { font-weight: 500; font-size: 15px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.continue .m { font-size: 13px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--s4); }
.card {
  position: relative; display: flex; flex-direction: column; gap: var(--s3); padding: var(--s4);
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--r-md);
  transition: border-color var(--t-fast) ease, transform var(--t-fast) ease;
}
.card:hover { border-color: var(--border-visible); }
.card .tile {
  width: 44px; height: 44px; border-radius: var(--r-md); display: grid; place-items: center;
  color: rgba(255, 255, 255, 0.9); font-size: 16px; font-weight: 500;
}
.card .head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s2); }
.card .name {
  display: block; width: 100%; padding: 0; border: none; background: none; text-align: left;
  font-size: 16px; font-weight: 500; line-height: 1.3; overflow-wrap: anywhere;
}
.card .name:hover { color: var(--accent); }
.card .goal { color: var(--text-2); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .meta { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); font-size: 12px; color: var(--text-3); }
.card .more { position: absolute; top: var(--s3); right: var(--s3); }
.card.new {
  justify-content: center; align-items: center; min-height: 170px; border-style: dashed; color: var(--text-2); cursor: pointer;
}
.card.new:hover { color: var(--text-1); border-color: var(--accent); }
.card.new svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.empty {
  padding: var(--s12) var(--s6); text-align: center; color: var(--text-2);
  border: 1px dashed var(--border-visible); border-radius: var(--r-lg);
}
.empty h3 { color: var(--text-1); margin-bottom: var(--s2); }
.empty .btn { margin-top: var(--s4); }

/* Project page */
.proj-head { display: flex; gap: var(--s4); align-items: flex-start; }
.proj-head .tile { width: 56px; height: 56px; border-radius: var(--r-lg); display: grid; place-items: center; color: rgba(255,255,255,.9); font-size: 20px; font-weight: 500; flex: none; }
.proj-head .body { flex: 1; min-width: 0; }
.proj-head .row { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; }
.proj-head .goal { color: var(--text-2); margin-top: var(--s2); max-width: 70ch; }
.proj-progress { display: grid; grid-template-columns: 1fr auto; gap: var(--s3); align-items: center; margin-top: var(--s5); font-size: 13px; color: var(--text-2); }
.material { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--r-md); margin-bottom: var(--s3); overflow: hidden; }
.material .mhead { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s4); border-bottom: 1px solid var(--border); }
.material .mhead h3 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.material .mhead .pill { flex: none; }
.sec-row {
  display: grid; grid-template-columns: 22px 1fr auto; align-items: center; gap: var(--s3);
  width: 100%; padding: 10px var(--s4); border: none; border-top: 1px solid var(--border); background: transparent; text-align: left;
  color: var(--text-1);
}
.sec-row:first-of-type { border-top: 0; }
.sec-row:hover { background: var(--hover); }
.sec-row .st { width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid var(--border-visible); margin: 0 auto; }
.sec-row .st.reading { border-color: var(--warning); background: var(--warning-soft); }
.sec-row .st.done { border-color: var(--success); background: var(--success); }
.sec-row .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sec-row .t small { color: var(--text-3); margin-right: var(--s2); font-variant-numeric: tabular-nums; }
.sec-row .r { font-size: 12px; color: var(--text-3); display: flex; gap: var(--s2); align-items: center; }

/* ---------- Study view ---------- */
.study { display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr) var(--tutor-w); height: 100%; }
.rail { border-right: 1px solid var(--border); background: var(--bg-0); display: flex; flex-direction: column; min-height: 0; }
.rail-head { padding: var(--s4) var(--s4) var(--s2); }
.rail-head .k { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-3); }
.rail-head .t { font-weight: 500; margin-top: 2px; overflow-wrap: anywhere; }
.rail-list { overflow-y: auto; flex: 1; padding: 0 var(--s2) var(--s4); }
.rail-item {
  display: grid; grid-template-columns: 14px 1fr auto; align-items: center; gap: var(--s2);
  width: 100%; padding: 8px 10px; border: none; border-radius: var(--r-sm); background: transparent; text-align: left; color: var(--text-2);
  font-size: 13px;
}
.rail-item:hover { background: var(--hover); color: var(--text-1); }
.rail-item.on { background: var(--active); color: var(--text-1); }
.rail-item .st { width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--border-visible); }
.rail-item .st.reading { border-color: var(--warning); }
.rail-item .st.done { border-color: var(--success); background: var(--success); }
.rail-item .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-item .sc { font-size: 11px; color: var(--text-3); }
.rail-foot { padding: var(--s3); border-top: 1px solid var(--border); }

.reader { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.reader-scroll { overflow-y: auto; flex: 1; }
.reader-inner { max-width: 700px; margin: 0 auto; padding: var(--s10) var(--s8) 140px; }
.sec-kicker { color: var(--text-3); font-size: 13px; margin-bottom: var(--s2); }
.sec-title {
  font-family: var(--serif); font-weight: 500; font-size: clamp(28px, 3.4vw, 38px); line-height: 1.15;
  letter-spacing: -0.01em; margin-bottom: var(--s6); padding-bottom: var(--s5); border-bottom: 1px solid var(--border);
}
.prose { font-family: var(--serif); font-size: 18.5px; line-height: 1.65; color: var(--text-1); }
.prose > * { position: relative; }
.prose p { margin: 0 0 1.1em; }
.prose h1, .prose h2, .prose h3 { font-weight: 600; line-height: 1.25; margin: 1.5em 0 0.5em; }
.prose h1 { font-size: 1.45em; } .prose h2 { font-size: 1.25em; } .prose h3 { font-size: 1.08em; }
.prose ul, .prose ol { padding-left: 1.3em; margin: 0 0 1.1em; }
.prose li { margin: 0.25em 0; }
.prose blockquote { margin: 1em 0; padding: 0.2em 0 0.2em 1em; border-left: 2px solid var(--accent); color: var(--text-2); }
.prose code { font-family: var(--mono); font-size: 0.82em; background: var(--bg-3); padding: 0.1em 0.35em; border-radius: 4px; }
.prose pre { background: var(--bg-3); padding: 12px 14px; border-radius: var(--r-md); overflow-x: auto; font-size: 0.8em; }
.prose pre code { background: none; padding: 0; }
.prose table { border-collapse: collapse; width: 100%; font-size: 0.82em; font-family: var(--sans); margin: 1em 0; }
.prose th, .prose td { border-bottom: 1px solid var(--border); padding: 6px 8px; text-align: left; }
.prose strong { font-weight: 600; }
.prose a { text-decoration: underline; }
.prose img { max-width: 100%; height: auto; }
.para-btn {
  position: absolute; left: -44px; top: 2px; width: 30px; height: 30px; border-radius: var(--r-sm);
  border: 1px solid var(--border-visible); background: var(--bg-2); color: var(--text-2);
  display: grid; place-items: center; opacity: 0; transition: opacity var(--t-fast) ease;
  font-family: var(--sans);
}
.para-btn svg { width: 15px; height: 15px; }
.prose > *:hover > .para-btn, .para-btn:focus-visible { opacity: 1; }
.para-btn:hover { color: var(--accent); border-color: var(--accent); }
.reader-actions {
  margin-top: var(--s10); padding-top: var(--s5); border-top: 1px solid var(--border);
  display: flex; gap: var(--s2); flex-wrap: wrap; align-items: center;
}
.reader-actions .spacer { flex: 1; }
.selection-tip {
  position: fixed; z-index: 20; display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent-strong); color: #fff; border-radius: var(--r-sm); padding: 7px 11px;
  font-size: 13px; font-weight: 500; border: 0; box-shadow: var(--shadow-md);
}
.selection-tip svg { width: 14px; height: 14px; }
.sec-done-note svg { width: 16px; height: 16px; flex: none; }
.sec-done-note { margin-top: var(--s6); padding: var(--s3) var(--s4); border-radius: var(--r-md); background: var(--success-soft); color: var(--success); font-size: 13px; display: flex; gap: var(--s2); align-items: center; }

/* Glossary terms, reading position, understanding note */
abbr.term { text-decoration: none; border-bottom: 1px dotted var(--accent); cursor: help; }
abbr.term:hover, abbr.term:focus-visible { background: var(--accent-soft); border-bottom-style: solid; }
.term-pop {
  position: fixed; z-index: 45; max-width: 320px; padding: var(--s3) var(--s4); background: var(--bg-2);
  border: 1px solid var(--border-visible); border-radius: var(--r-md); box-shadow: var(--shadow-lg); font-family: var(--sans); font-size: 13.5px;
}
.term-pop strong { display: block; margin-bottom: 4px; }
.term-pop p { color: var(--text-2); margin-bottom: var(--s2); }
.prose > .in-view::before { content: ''; position: absolute; left: -16px; top: 0.35em; bottom: 0.35em; width: 2px; border-radius: 2px; background: var(--accent); opacity: 0.45; }
.note-card {
  margin: 0 0 var(--s6); padding: var(--s4) var(--s5); background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: var(--r-md); font-family: var(--sans);
}
.note-card-head { display: flex; justify-content: space-between; align-items: center; gap: var(--s2); font-size: 12px; font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase; color: var(--accent); margin-bottom: var(--s2); }
.note-card-head span:first-child { display: inline-flex; align-items: center; gap: 6px; }
.note-card-head svg { width: 14px; height: 14px; }
.note-card p { font-size: 15px; line-height: 1.55; white-space: pre-wrap; }
.note-card-actions { display: flex; gap: var(--s1); margin-top: var(--s2); margin-left: -8px; }
.mastered { display: flex; align-items: center; gap: var(--s2); margin-top: var(--s3); padding: var(--s2) var(--s3); border-radius: var(--r-sm); background: var(--success-soft); color: var(--success); font-size: 13px; }
.mastered svg { width: 16px; height: 16px; flex: none; }

/* Project page: notes and glossary */
.notes { display: grid; gap: var(--s3); }
.note { padding: var(--s4); background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--r-md); }
.note-head { display: flex; justify-content: space-between; gap: var(--s3); flex-wrap: wrap; margin-bottom: var(--s2); font-size: 13px; }
.note-title { font-weight: 500; color: var(--text-1); }
.note-title:hover { color: var(--accent); }
.note p { color: var(--text-2); white-space: pre-wrap; line-height: 1.55; }
.glossary { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--s3); }
.gloss { padding: var(--s3) var(--s4); background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--r-md); }
.gloss-head { display: flex; justify-content: space-between; align-items: center; gap: var(--s2); margin-bottom: 4px; }
.gloss p { color: var(--text-2); font-size: 13.5px; }
.icon-btn.sm { width: 26px; height: 26px; }
.icon-btn.sm svg { width: 15px; height: 15px; }
.cards-head { display: flex; justify-content: space-between; align-items: baseline; }
.card-face { min-height: 180px; display: grid; align-content: center; gap: var(--s3); padding: var(--s6); text-align: center; background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--r-md); }
.card-term { font-size: 24px; font-weight: 500; }
.card-def { color: var(--text-2); font-size: 15px; line-height: 1.5; }

/* Reviews, exams, overview, voices, player */
.stat.warn .v { color: var(--warning); }
.review-list { display: grid; gap: var(--s2); }
.review-row { display: grid; grid-template-columns: 10px 1fr auto auto; align-items: center; gap: var(--s4); padding: var(--s3) var(--s4); background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--r-md); color: inherit; }
.review-row:hover { border-color: var(--border-visible); }
.review-row .st { width: 10px; height: 10px; border-radius: 50%; background: var(--warning); }
.review-row .t { display: grid; min-width: 0; } .review-row .t > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.review-row .r { font-size: 12px; color: var(--text-3); white-space: nowrap; }
.review-banner { display: flex; align-items: center; gap: var(--s3); margin: 0 0 var(--s5); padding: var(--s3) var(--s4); border-radius: var(--r-md); background: var(--success-soft); color: var(--success); font-family: var(--sans); font-size: 13.5px; }
.review-banner.due { background: var(--warning-soft); color: var(--warning); }
.review-banner svg { width: 16px; height: 16px; flex: none; } .review-banner span { flex: 1; }
.tb-score { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s3); align-items: center; margin-top: var(--s3); font-size: 12.5px; color: var(--text-2); }
.tb-score .k { font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase; font-size: 11px; color: var(--accent); }
.tb-score .sc strong { color: var(--text-1); }
.tb-score .tip { flex-basis: 100%; color: var(--text-2); font-style: italic; }
.mmeta { font-size: 12px; white-space: nowrap; }
.pill.scanning { background: var(--accent-soft); color: var(--accent); }
.spin { width: 10px; height: 10px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.sec-row .pg { margin-left: var(--s2); font-size: 12px; }
.exam-card { display: flex; gap: var(--s4); align-items: center; justify-content: space-between; flex-wrap: wrap; margin-top: var(--s6); padding: var(--s4) var(--s5); background: var(--bg-2); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: var(--r-md); }
.exam-card > div:first-child { flex: 1; min-width: 240px; }
.exam-actions { display: flex; gap: var(--s2); }
dialog.wide { width: min(720px, calc(100vw - 32px)); }
.ov-body { max-height: 60vh; overflow-y: auto; display: grid; gap: var(--s3); font-size: 14px; }
.ov-body h3 { margin-top: var(--s2); } .ov-about { font-size: 15px; } .ov-body p strong { color: var(--text-2); }
.ov-ideas { padding-left: 1.3em; display: grid; gap: 4px; }
.ov-outline { border-collapse: collapse; width: 100%; font-size: 13px; }
.ov-outline td { padding: 6px 8px 6px 0; border-top: 1px solid var(--border); vertical-align: top; }
.short-answer { font-family: var(--sans); font-size: 14px; margin: 6px 0; }
.short-answer.right { border-color: var(--success); } .short-answer.wrong { border-color: var(--error); }
.q-key { margin-top: var(--s2); font-size: 13.5px; color: var(--text-2); }
.q-sec { display: block; font-weight: 400; font-size: 12px; margin-top: 2px; }
.exam-wrap { padding-top: var(--s8); }
.voice-status { font-size: 13px; }
.voice-list { display: grid; gap: var(--s2); }
.voice-row { display: grid; grid-template-columns: auto 1fr auto auto; gap: var(--s3); align-items: center; padding: var(--s2) var(--s3); background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--r-md); cursor: pointer; }
.voice-row .vn { display: grid; min-width: 0; } .voice-row .vn > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.voice-row audio { height: 30px; width: 180px; }
.voice-row input { accent-color: var(--accent); }
label.lbl.check { grid-template-columns: auto 1fr; align-items: center; gap: var(--s2); display: flex; color: var(--text-1); }
.msg.assistant { position: relative; padding-right: 36px; }
.msg.assistant .say { position: absolute; right: 6px; bottom: 6px; opacity: 0; }
.msg.assistant:hover .say, .msg.assistant .say:focus-visible { opacity: 1; }
.prose > .speaking { background: var(--accent-soft); box-shadow: 0 0 0 8px var(--accent-soft); border-radius: 4px; }
#player { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 55; display: flex; align-items: center; gap: var(--s3); padding: var(--s2) var(--s2) var(--s2) var(--s4); background: var(--bg-2); border: 1px solid var(--border-visible); border-radius: 999px; box-shadow: var(--shadow-lg); font-size: 13px; }
#player .pl-voice { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; } #player .pl-voice svg { width: 16px; height: 16px; }
#player .pl-count { color: var(--text-3); }
@media (max-width: 860px) { #player { bottom: 76px; } .review-row { grid-template-columns: 10px 1fr auto; } .review-row .r { display: none; } }

.show-all { width: 100%; padding: 10px; border: 0; border-top: 1px solid var(--border); background: transparent; color: var(--accent); font-weight: 500; }
.show-all:hover { background: var(--hover); }

.pill.video { background: var(--error-soft); color: var(--error); text-decoration: none; }
.pill.video svg { width: 12px; height: 12px; fill: currentColor; stroke: none; }
.video-block { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; margin: 0 0 var(--s5); font-family: var(--sans); }
.video-block .btn svg { fill: currentColor; stroke: none; }
.video-hint { flex-basis: 100%; font-size: 12px; }
.video-block.open { position: sticky; top: 0; z-index: 5; padding: var(--s2) 0; background: var(--bg-1); }
.video-block.open .video-hint { display: none; }
.video-frame { flex-basis: 100%; aspect-ratio: 16 / 9; border-radius: var(--r-md); overflow: hidden; background: #000; border: 1px solid var(--border-visible); box-shadow: var(--shadow-lg); }
.video-frame iframe, .video-frame > div { width: 100%; height: 100%; border: 0; display: block; }
.para-time { float: left; margin: 0.35em 10px 0 0; padding: 1px 6px; border: 1px solid var(--border-visible); border-radius: 4px; background: var(--bg-2); color: var(--text-3); font-family: var(--sans); font-size: 11px; line-height: 1.4; font-variant-numeric: tabular-nums; }
.para-time:hover { color: var(--accent); border-color: var(--accent); }
.prose > .spoken { background: var(--warning-soft); box-shadow: 0 0 0 8px var(--warning-soft); border-radius: 4px; }
@media (min-width: 1000px) { .video-frame { width: min(100%, 440px); margin-left: auto; } }
#up-modes { margin-bottom: var(--s2); }

/* Tutor panel */
.tutor { border-left: 1px solid var(--border); background: var(--bg-0); display: flex; flex-direction: column; min-height: 0; }
.tutor-head { display: flex; align-items: center; gap: var(--s2); padding: var(--s3) var(--s3); border-bottom: 1px solid var(--border); }
.modes { display: flex; flex: 1; gap: 2px; padding: 2px; background: var(--bg-3); border-radius: var(--r-sm); }
.modes button {
  flex: 1; height: 30px; border: none; border-radius: 5px; background: transparent; color: var(--text-2); font-size: 13px; font-weight: 500;
}
.modes button.on { background: var(--bg-1); color: var(--text-1); box-shadow: var(--shadow-sm); }
.chat-scroll { overflow-y: auto; flex: 1; padding: var(--s4) var(--s3); display: flex; flex-direction: column; gap: var(--s3); }
.chat-hint { color: var(--text-2); font-size: 13px; padding: var(--s2) var(--s1); }
.chat-hint p { margin-bottom: var(--s3); }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  height: 30px; padding: 0 var(--s3); border: 1px solid var(--border-visible); border-radius: 999px; background: transparent;
  color: var(--text-1); font-size: 13px; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.msg { max-width: 92%; border-radius: var(--r-lg); padding: 10px 14px; font-size: 14.5px; line-height: 1.55; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--accent-strong); color: #fff; border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.assistant { align-self: flex-start; background: var(--bg-2); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.error { align-self: stretch; background: var(--error-soft); color: var(--error); font-size: 13px; }
.msg .md > :first-child { margin-top: 0; } .msg .md > :last-child { margin-bottom: 0; }
.msg .md p { margin: 0 0 0.7em; }
.msg .md ul, .msg .md ol { padding-left: 1.2em; margin: 0 0 0.7em; }
.msg .md code { font-family: var(--mono); font-size: 0.85em; background: var(--bg-3); padding: 0.1em 0.3em; border-radius: 4px; }
.msg .md pre { background: var(--bg-3); padding: 10px; border-radius: var(--r-sm); overflow-x: auto; font-size: 0.8em; }
.msg .md strong { font-weight: 600; }
.typing { color: var(--text-3); }
.typing::after { content: ''; animation: dots 1.2s steps(4, end) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }
.followups { display: flex; flex-wrap: wrap; gap: 6px; margin-top: -4px; }
.composer { display: flex; gap: var(--s2); align-items: flex-end; padding: var(--s3); border-top: 1px solid var(--border); }
.composer textarea {
  flex: 1; min-height: 40px; max-height: 160px; padding: 10px 12px; resize: none; border: 1px solid var(--border-visible);
  border-radius: var(--r-md); background: var(--input); color: var(--text-1); line-height: 1.4;
}
.composer textarea:focus { border-color: var(--accent); outline: none; }
.composer .send { width: 40px; height: 40px; padding: 0; border-radius: var(--r-md); flex: none; }

/* Quiz */
.quiz-wrap { max-width: 700px; margin: 0 auto; padding: var(--s10) var(--s8) 140px; }
.quiz-wrap h2 { font-family: var(--serif); font-size: 28px; font-weight: 500; margin-bottom: var(--s2); }
.quiz-sub { color: var(--text-2); margin-bottom: var(--s6); }
.q { padding: var(--s5) 0; border-top: 1px solid var(--border); }
.q-prompt { font-size: 16px; font-weight: 500; margin-bottom: var(--s3); display: flex; gap: var(--s2); }
.q-num { color: var(--text-3); flex: none; font-variant-numeric: tabular-nums; }
.opt {
  display: flex; gap: var(--s3); align-items: flex-start; padding: 10px 12px; margin: 6px 0; border: 1px solid var(--border);
  border-radius: var(--r-md); cursor: pointer; background: var(--bg-2);
}
.opt:hover { border-color: var(--border-visible); }
.opt input { margin-top: 3px; accent-color: var(--accent); }
.opt.right { border-color: var(--success); background: var(--success-soft); }
.opt.wrong { border-color: var(--error); background: var(--error-soft); }
.q-explain { margin-top: var(--s2); padding: 10px 12px; border-radius: var(--r-md); background: var(--success-soft); color: var(--success); font-size: 13.5px; }
.q-explain.miss { background: var(--warning-soft); color: var(--warning); }
.score { display: flex; align-items: center; gap: var(--s4); padding: var(--s4) var(--s5); margin-bottom: var(--s5); background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--r-md); flex-wrap: wrap; }
.score .big { font-size: 30px; font-weight: 500; }
.score .big.perfect { color: var(--success); }
.score .sub { flex: 1; min-width: 180px; color: var(--text-2); }
.attempts { color: var(--text-3); font-size: 13px; margin-top: var(--s3); }

/* Mobile tab bar for the study view */
#tabbar { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  :root { --rail-w: 200px; --tutor-w: 360px; }
}
@media (max-width: 1280px) {
  body[data-route="study"] #shell { grid-template-columns: minmax(0, 1fr); }
  body[data-route="study"] #sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; width: var(--sidebar-w); z-index: 30; border-right: 1px solid var(--border-visible);
    transform: translateX(-100%); transition: transform var(--t-med) ease;
  }
  body[data-route="study"] #sidebar.open { transform: none; }
  body[data-route="study"] #scrim.on { display: block; }
  body[data-route="study"] #menu-btn { display: inline-flex; }
}
@media (max-width: 1000px) {
  .study { grid-template-columns: minmax(0, 1fr) var(--tutor-w); }
  .rail { display: none; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  #shell { grid-template-columns: minmax(0, 1fr); }
  #sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; width: var(--sidebar-w); z-index: 30; border-right: 1px solid var(--border-visible);
    transform: translateX(-100%); transition: transform var(--t-med) ease;
  }
  #sidebar.open { transform: none; }
  #scrim.on { display: block; }
  #menu-btn { display: inline-flex; }
  #topbar { padding: 0 var(--s4); }
  .page-inner { padding: var(--s5) var(--s4) var(--s10); }
  .reader-inner, .quiz-wrap { padding: var(--s6) var(--s4) 120px; }
  .prose { font-size: 17.5px; }
  .para-btn { position: static; float: right; width: 26px; height: 26px; margin: 4px 0 4px 10px; opacity: 0.7; }
  .study { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .study .tutor { display: none; border-left: 0; }
  .study[data-view="chat"] .tutor { display: flex; }
  .study[data-view="chat"] .reader { display: none; }
  #tabbar {
    display: flex; justify-content: space-around; border-top: 1px solid var(--border); background: var(--bg-0);
    padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
  }
  #tabbar button { display: grid; justify-items: center; gap: 2px; border: none; background: none; color: var(--text-3); font-size: 11px; padding: 4px 14px; border-radius: var(--r-sm); }
  #tabbar button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  #tabbar button.on { color: var(--accent); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
