:root {
  --bg: #f6f7f4; --surface: #ffffff; --ink: #1d2a22; --muted: #5d6b62; --line: #dfe5df;
  --accent: #2f7d4f; --accent-ink: #ffffff; --accent-soft: #e5f2ea;
  --pupil: #e8eef9; --warn: #fff4d6; --warn-ink: #6b4e00; --danger: #b3261e; --flag: #fde8e6;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121714; --surface: #1b221e; --ink: #e6ece7; --muted: #9aa89f; --line: #2c3630;
    --accent: #5cb784; --accent-ink: #0d1510; --accent-soft: #1f3327;
    --pupil: #22304a; --warn: #3a2f12; --warn-ink: #f5d98a; --danger: #ff8a80; --flag: #3d1f1d;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 8px 14px; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button:disabled { opacity: .55; cursor: default; }
button.link { border: 0; background: none; color: var(--accent); padding: 4px 6px; text-decoration: underline; }
button.danger { color: var(--danger); }
input, select, textarea { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
label { display: block; font-size: 14px; color: var(--muted); margin: 10px 0 4px; }
.hidden { display: none !important; }
.wrap { max-width: 760px; margin: 0 auto; padding: 16px; }
.wide { max-width: 1200px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.err { color: var(--danger); min-height: 1.5em; font-size: 14px; }
.muted { color: var(--muted); font-size: 14px; }
header.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--surface); }
header.top h1 { font-size: 18px; margin: 0; }

/* AI notice – always visible on the pupil page */
.ai-notice { background: var(--warn); color: var(--warn-ink); padding: 8px 16px; font-size: 14px; border-bottom: 1px solid var(--line); }
.ai-notice strong { font-weight: 700; }

/* chat */
.chat-shell { display: flex; flex-direction: column; height: 100dvh; }
.lesson-bar { padding: 10px 16px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.lesson-bar .t { font-weight: 600; }
.log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 85%; padding: 10px 14px; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.pupil { align-self: flex-end; background: var(--pupil); border-bottom-right-radius: 4px; }
.msg.tutor { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.tutor .who { font-size: 12px; color: var(--muted); display: block; margin-bottom: 2px; }
.msg ul { margin: 4px 0; padding-left: 20px; white-space: normal; }
.msg .game-offer { margin-top: 8px; }
.typing { color: var(--muted); font-style: italic; }
.composer { border-top: 1px solid var(--line); padding: 10px 16px; background: var(--surface); }
.composer form { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { resize: none; min-height: 44px; max-height: 140px; }
.composer .count { font-size: 12px; color: var(--muted); text-align: right; }

/* teacher */
.grid { display: grid; grid-template-columns: 280px 1fr; gap: 16px; align-items: start; }
@media (max-width: 860px) { .grid { grid-template-columns: 1fr; } }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 8px 10px; border-radius: 8px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
.list li:hover, .list li.sel { background: var(--accent-soft); }
.badge { font-size: 12px; border-radius: 999px; padding: 0 8px; background: var(--flag); color: var(--danger); white-space: nowrap; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs button.on { background: var(--accent-soft); border-color: var(--accent); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > * { flex: 0 0 auto; }
.row input, .row select { flex: 1 1 200px; width: auto; }
.tmsg { padding: 6px 10px; border-radius: 8px; margin: 4px 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; }
.tmsg.pupil { background: var(--pupil); }
.tmsg.tutor { background: var(--bg); }
.tmsg.flag { background: var(--flag); }
.pins { font-family: ui-monospace, monospace; }
.section { margin-top: 16px; }
h2 { font-size: 17px; margin: 0 0 8px; }
h3 { font-size: 15px; margin: 14px 0 6px; }

/* textbook picker */
.book-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-top: 12px; }
.book-card { text-align: left; padding: 16px; border-radius: var(--radius); display: flex; flex-direction: column; gap: 4px; }
.book-card:hover { border-color: var(--accent); background: var(--accent-soft); }
.book-card .subj { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.book-card .bt { font-weight: 700; }

/* light maths rendering in tutor messages */
.frac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; font-size: .9em; margin: 0 2px; }
.frac > span:first-child { border-bottom: 1px solid currentColor; padding: 0 2px; }
.frac > span:last-child { padding: 0 2px; }
.sqrt { white-space: nowrap; }
.sqrt > span { border-top: 1px solid currentColor; padding: 0 2px; }
