:root {
  --bg: #f4f5fa;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --ink: #1b1e2b;
  --muted: #5f6678;
  --line: #e2e5ee;
  --accent: #4f46e5;
  --accent-ink: #ffffff;
  --accent-soft: #eceafe;
  --warm: #fff4e2;
  --mark: rgba(255, 196, 0, 0.5);
  --danger: #c2410c;
  --ok: #0f8a5f;
  --shadow: 0 1px 2px rgba(20, 24, 40, 0.06), 0 6px 24px rgba(20, 24, 40, 0.08);
  --radius: 14px;
  --page-bg: #e9ebf2;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1117;
    --surface: #181b24;
    --surface-2: #1e222d;
    --ink: #e8eaf1;
    --muted: #a0a7b8;
    --line: #2a2f3b;
    --accent: #8d88ff;
    --accent-ink: #11131a;
    --accent-soft: #262546;
    --warm: #2c2416;
    --page-bg: #0b0d12;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 24px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1117;
  --surface: #181b24;
  --surface-2: #1e222d;
  --ink: #e8eaf1;
  --muted: #a0a7b8;
  --line: #2a2f3b;
  --accent: #8d88ff;
  --accent-ink: #11131a;
  --accent-soft: #262546;
  --warm: #2c2416;
  --page-bg: #0b0d12;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Devanagari", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.5; }
a { color: var(--accent); }

/* ---------- top bar ---------- */
.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  height: 56px; padding: 0 16px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.bar h1 { flex: 1; min-width: 0; margin: 0; font-size: 16px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: linear-gradient(135deg, #6366f1, #ec4899 60%, #f59e0b); flex: none; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: #fff; }
.pager { display: flex; align-items: center; gap: 4px; flex: none; }
.pageno { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 14px; }
.pageno input { width: 48px; padding: 4px 6px; text-align: center; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); }
.icon { width: 34px; height: 34px; border: 0; border-radius: 9px; background: transparent; font-size: 20px; line-height: 1; }
.icon:hover { background: var(--surface-2); }

/* ---------- reader layout ---------- */
.reader { overflow: hidden; }
.layout { display: grid; grid-template-columns: 1fr 380px; height: calc(100dvh - 56px); }
.pages { overflow-y: auto; overflow-x: hidden; background: var(--page-bg); padding: 12px 8px 40px; display: flex; flex-direction: column; align-items: center; gap: 12px; overscroll-behavior: contain; }
.page { position: relative; flex: none; background: #fff; box-shadow: var(--shadow); border-radius: 4px; overflow: hidden; --scale-round-x: 1px; --scale-round-y: 1px; }
.page canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.page-num { position: absolute; right: 8px; bottom: 6px; z-index: 3; font-size: 11px; color: #667; background: rgba(255, 255, 255, 0.85); padding: 1px 6px; border-radius: 6px; pointer-events: none; }
.empty { color: var(--muted); padding: 40px 16px; text-align: center; }

/* pdf.js text layer (transparent, selectable text over the drawing) */
.textLayer { position: absolute; inset: 0; overflow: clip; line-height: 1; text-align: initial; transform-origin: 0 0; z-index: 2; -webkit-text-size-adjust: none; text-size-adjust: none; forced-color-adjust: none;
  --min-font-size: 1; --text-scale-factor: calc(var(--total-scale-factor) * var(--min-font-size)); --min-font-size-inv: calc(1 / var(--min-font-size)); }
.textLayer :is(span, br) { color: transparent; position: absolute; white-space: pre; cursor: text; transform-origin: 0% 0%; }
.textLayer > :not(.markedContent), .textLayer .markedContent span:not(.markedContent) { z-index: 1; --font-height: 0; font-size: calc(var(--text-scale-factor) * var(--font-height)); --scale-x: 1; --rotate: 0deg; transform: rotate(var(--rotate)) scaleX(var(--scale-x)) scale(var(--min-font-size-inv)); }
.textLayer .markedContent { display: contents; }
.textLayer ::selection { background: rgba(79, 70, 229, 0.25); }
.textLayer span.hl { background: var(--mark); border-radius: 3px; box-shadow: 0 0 0 2px var(--mark); mix-blend-mode: multiply; animation: pulse 1.6s ease-out 2; }
@keyframes pulse { 0% { box-shadow: 0 0 0 2px var(--mark); } 50% { box-shadow: 0 0 0 7px rgba(255, 196, 0, 0.15); } 100% { box-shadow: 0 0 0 2px var(--mark); } }

/* ---------- tutor panel ---------- */
.panel { display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-left: 1px solid var(--line); }
.panel-head { display: flex; justify-content: space-between; gap: 8px; padding: 14px 16px 10px; border-bottom: 1px solid var(--line); }
.panel-head strong { display: block; font-size: 15px; }
.status { display: block; color: var(--muted); font-size: 13px; }
[data-state="listening"] .status { color: var(--ok); }
[data-state="thinking"] .status, [data-state="connecting"] .status { color: var(--accent); }
.chat { flex: 1; min-height: 0; overflow-y: auto; list-style: none; margin: 0; padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.chat .hint { display: flex; flex-direction: column; gap: 6px; padding: 14px; border-radius: var(--radius); background: var(--accent-soft); color: var(--ink); font-size: 14px; }
.msg { max-width: 88%; padding: 9px 12px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word; font-size: 14.5px; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.msg.model { align-self: flex-start; background: var(--warm); border-bottom-left-radius: 4px; }
.msg.partial { opacity: 0.75; }
.tool { align-self: center; font-size: 12px; color: var(--muted); background: var(--surface-2); border: 1px solid var(--line); padding: 2px 10px; border-radius: 999px; }
.ask { display: flex; gap: 8px; padding: 10px 16px 0; }
.ask input { flex: 1; min-width: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); }
.ask input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.send { width: 42px; border: 0; border-radius: 12px; background: var(--accent-soft); color: var(--accent); font-size: 16px; }
.dock { position: relative; display: flex; align-items: center; justify-content: center; gap: 12px; padding: 14px 16px calc(14px + env(safe-area-inset-bottom)); }
.talk { position: relative; display: inline-flex; align-items: center; gap: 10px; height: 56px; padding: 0 26px 0 20px; border: 0; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-weight: 650; font-size: 16px; box-shadow: 0 8px 24px rgba(79, 70, 229, 0.35); }
.talk svg { width: 24px; height: 24px; fill: currentColor; position: relative; }
.talk span { position: relative; }
.talk .ring { position: absolute; inset: 0; border-radius: inherit; background: var(--accent); opacity: 0.35; transition: transform 0.08s linear; }
[data-state="listening"] .talk, [data-state="speaking"] .talk, [data-state="thinking"] .talk { background: #e11d48; box-shadow: 0 8px 24px rgba(225, 29, 72, 0.35); }
[data-state="listening"] .talk .ring, [data-state="speaking"] .talk .ring { background: #e11d48; }
[data-state="connecting"] .talk { opacity: 0.8; }
.ghost { position: absolute; left: 16px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); font-size: 13px; }
.ghost.on { background: #fde68a; color: #1b1e2b; }
.model-name { position: absolute; right: 16px; bottom: calc(6px + env(safe-area-inset-bottom)); font-size: 11px; color: var(--muted); }
.only-mobile { display: none; }

.toast { position: fixed; left: 50%; top: 68px; transform: translateX(-50%); z-index: 20; max-width: min(92vw, 520px); padding: 10px 14px; border-radius: 12px; background: #1b1e2b; color: #fff; box-shadow: var(--shadow); font-size: 14px; }

@media (max-width: 899px) {
  .layout { grid-template-columns: 1fr; height: calc(100dvh - 56px); }
  .pages { padding-bottom: 210px; }
  .panel { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; max-height: 62dvh; border-left: 0; border-top: 1px solid var(--line); border-radius: 18px 18px 0 0; box-shadow: 0 -8px 30px rgba(20, 24, 40, 0.15); }
  .panel .chat { display: none; }
  .chat-open .panel .chat { display: flex; height: 34dvh; flex: none; }
  .panel-head { padding: 10px 16px 6px; border-bottom: 0; }
  .only-mobile { display: block; }
  .chat-open #toggleChat { transform: rotate(180deg); }
  .dock { padding-top: 10px; }
  .bar { padding: 0 10px; gap: 8px; }
  .bar h1 { font-size: 14px; }
  .model-name { display: none; }
}

/* ---------- staff library page ---------- */
.lib { max-width: 980px; margin: 0 auto; padding: 24px 16px 60px; }
.lib h2 { font-size: 20px; margin: 28px 0 12px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.drop { display: grid; gap: 12px; }
.drop .zone { display: grid; place-items: center; gap: 6px; padding: 28px 16px; border: 2px dashed var(--line); border-radius: 12px; background: var(--surface-2); text-align: center; color: var(--muted); }
.drop .zone.over { border-color: var(--accent); background: var(--accent-soft); }
.drop .zone b { color: var(--ink); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.field { flex: 1; min-width: 200px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); }
.btn { padding: 10px 16px; border: 0; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.soft { background: var(--accent-soft); color: var(--accent); }
.btn.plain { background: var(--surface-2); color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.list { display: grid; gap: 12px; }
.item { display: grid; grid-template-columns: 1fr auto; gap: 10px 16px; align-items: center; }
.item h3 { margin: 0 0 2px; font-size: 16px; }
.item .meta { color: var(--muted); font-size: 13px; }
.item .link { grid-column: 1 / -1; display: flex; gap: 8px; align-items: center; min-width: 0; }
.item .link code { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 6px 10px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--line); font-size: 13px; }
.item .actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.muted { color: var(--muted); }
.progress { height: 6px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }
dialog { border: 0; border-radius: var(--radius); padding: 20px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow); max-width: 92vw; }
dialog::backdrop { background: rgba(10, 12, 20, 0.5); }
.qr { display: grid; justify-items: center; gap: 12px; text-align: center; }
.qr img { width: 260px; height: 260px; background: #fff; border-radius: 12px; padding: 8px; }
@media (max-width: 600px) {
  .item { grid-template-columns: 1fr; }
  .item .actions { justify-content: flex-start; }
}
.teacher-preview { display: grid; justify-items: center; gap: 6px; }
.teacher-preview canvas { width: min(360px, 100%); height: auto; border-radius: 12px; background: var(--surface-2); }
select.field { appearance: auto; }

/* ---------- blackboard teacher ---------- */
.stage { position: relative; display: flex; min-width: 0; min-height: 0; }
.stage .pages { flex: 1; min-width: 0; }
.classroom { position: absolute; z-index: 4; left: 0; right: 0; top: 0; height: 56%; padding: 12px 14px 0; pointer-events: none; }
.classroom > * { pointer-events: auto; }
.board {
  position: relative; height: 100%; display: flex; flex-direction: column; overflow: hidden;
  padding: 16px 22px 30px; border: 10px solid #7a5230; border-radius: 14px;
  background:
    radial-gradient(ellipse at 22% 18%, rgba(255, 255, 255, 0.06), transparent 45%),
    radial-gradient(ellipse at 78% 70%, rgba(255, 255, 255, 0.04), transparent 50%),
    radial-gradient(ellipse at 30% 20%, #2f4a3d 0%, #26392f 55%, #1d2f27 100%);
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.45), inset 0 0 0 2px #5c3d22, 0 10px 30px rgba(0, 0, 0, 0.35);
  color: #f3f0e6; font-family: Kalam, "Comic Sans MS", "Noto Sans Devanagari", cursive;
}
.board-title { margin: 0 0 6px; padding-right: 84px; font-size: clamp(20px, 2.4vw, 30px); font-weight: 700; color: #fff7d1; text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 6px; min-height: 1.2em; }
.board-lines { flex: 1; min-height: 0; overflow-y: auto; list-style: none; margin: 0; padding: 0 250px 8px 0; font-size: clamp(17px, 2vw, 26px); line-height: 1.45; text-shadow: 0 0 1px rgba(255, 255, 255, 0.6), 0 0 6px rgba(255, 255, 255, 0.15); scrollbar-width: none; }
.board-lines::-webkit-scrollbar { display: none; }
.board-lines li { margin: 2px 0; transition: opacity 0.25s, filter 0.25s; }
.board-lines li.wiping { opacity: 0; filter: blur(3px); }
.board-lines b { color: #ffe680; font-weight: 700; }
.board-lines sup { font-size: 0.62em; }
.board-lines li.answer span { display: inline-block; padding: 0 10px; border: 2px solid #ffe680; border-radius: 8px; color: #ffe680; }
.board-lines li.tip { color: #ffb8cc; }
.tray { position: absolute; left: 0; right: 0; bottom: 0; height: 12px; background: linear-gradient(#6b4626, #4c311a); }
.tray i { position: absolute; bottom: 6px; width: 26px; height: 6px; border-radius: 3px; background: #f4f1e8; }
.tray i:first-child { left: 18%; } .tray i:last-child { left: 24%; width: 18px; background: #ffe680; }
.board-hide { position: absolute; top: 8px; right: 10px; z-index: 2; padding: 3px 10px; border: 1px solid rgba(255, 255, 255, 0.35); border-radius: 999px; background: rgba(0, 0, 0, 0.25); color: #f3f0e6; font: 600 12px system-ui; }
.board-show { position: absolute; z-index: 4; top: 10px; left: 50%; transform: translateX(-50%); padding: 7px 14px; border: 0; border-radius: 999px; background: #26392f; color: #f3f0e6; font: 600 13px system-ui; box-shadow: var(--shadow); }
.teacher { position: absolute; right: 18px; bottom: -12px; width: 250px; margin: 0; transform-origin: bottom center; animation: pop-in 0.6s cubic-bezier(0.2, 1.4, 0.4, 1); }
.teacher-char canvas { display: block; width: 100%; height: auto; border: 3px solid #fff; border-radius: 16px; background: #c9ccd3; box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45); }
.teacher video { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; object-position: 50% 22%; border-radius: 16px; border: 3px solid #fff; }
.teacher [hidden] { display: none; }
.teacher.live::after { content: "LIVE"; position: absolute; top: 6px; left: 6px; padding: 1px 6px; border-radius: 6px; background: #e11d48; color: #fff; font: 700 10px system-ui; }
.teacher figcaption { position: absolute; left: 50%; bottom: -10px; transform: translateX(-50%); display: flex; gap: 6px; align-items: baseline; padding: 3px 10px; border-radius: 999px; background: #fff; color: #1f2f5a; font: 700 12px system-ui; white-space: nowrap; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25); }
.teacher figcaption small { font-weight: 600; color: #d42e2e; font-size: 10px; }
[data-state="speaking"] .teacher-char canvas { box-shadow: 0 0 0 3px #ffe680, 0 0 24px rgba(255, 230, 128, 0.45), 0 12px 30px rgba(0, 0, 0, 0.45); }
@keyframes pop-in { from { transform: scale(0.3) translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.modes { display: inline-flex; gap: 2px; padding: 2px; margin-bottom: 6px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); }
.modes button { padding: 4px 10px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-size: 12px; font-weight: 600; }
.modes button[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); }
@media (max-width: 899px) {
  .classroom { height: 47%; padding: 8px 8px 0; }
  .board { padding: 10px 12px 22px; border-width: 7px; }
  .board-title { font-size: 19px; padding-right: 64px; }
  .board-lines { padding: 0 150px 8px 0; font-size: 18px; }
  .teacher { width: 150px; right: 8px; bottom: -8px; }
  .teacher figcaption { font-size: 10px; padding: 2px 8px; bottom: -8px; }
  .teacher figcaption small { display: none; }
}
