:root {
  --bg: #f4f6fb; --card: #fff; --ink: #1d2433; --muted: #6b7489; --line: #e2e6ef;
  --brand: #2f6fdf; --brand-soft: #e6eefc; --ok: #1f9d55; --ok-soft: #e3f6eb; --bad: #d64545; --bad-soft: #fde8e8;
  --warn: #b7791f; --warn-soft: #fdf3e1; --radius: 12px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: Heebo, system-ui, sans-serif; background: var(--bg); color: var(--ink); font-size: 16px; }
button, input, select, textarea { font: inherit; }
a { color: var(--brand); }
.wrap { max-width: 980px; margin: 0 auto; padding: 16px; }
header.top { background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
header.top .wrap { display: flex; align-items: center; gap: 12px; padding-top: 10px; padding-bottom: 10px; flex-wrap: wrap; }
.logo { font-weight: 700; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.logo > span:first-child { background: var(--brand); color: #fff; width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; }
nav.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
nav.tabs button { border: 0; background: none; padding: 8px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); }
nav.tabs button.on { background: var(--brand-soft); color: var(--brand); font-weight: 500; }
.spacer { flex: 1; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card h3 { margin: 0 0 10px; font-size: 17px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 8px; }
.muted { color: var(--muted); font-size: 14px; }
.btn { border: 1px solid var(--line); background: var(--card); padding: 8px 14px; border-radius: 9px; cursor: pointer; color: var(--ink); }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.small { padding: 4px 10px; font-size: 14px; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; cursor: default; }
input, select, textarea { border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; background: #fff; color: var(--ink); min-width: 0; }
textarea { width: 100%; resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 13px; background: var(--brand-soft); color: var(--brand); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #c9ceda; display: inline-block; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.student-card { cursor: pointer; }
.student-card:hover { border-color: var(--brand); }
.student-card .name { font-weight: 700; font-size: 17px; }
.ex { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; }
.ex.ok { border-color: var(--ok); background: var(--ok-soft); }
.ex.revealed { border-color: var(--warn); background: var(--warn-soft); }
.ex .q { font-size: 19px; direction: rtl; unicode-bidi: plaintext; margin-bottom: 6px; }
.ex .q bdi { direction: ltr; }
.ex input.ans { width: 130px; direction: ltr; text-align: center; }
.attempts { font-size: 13px; color: var(--muted); }
.attempts .w { color: var(--bad); text-decoration: line-through; }
.attempts .r { color: var(--ok); font-weight: 500; }
.hint { background: var(--warn-soft); color: #7a5210; border-radius: 8px; padding: 6px 10px; font-size: 14px; margin-top: 6px; }
.edit-ex { display: grid; grid-template-columns: 1fr 110px 1fr auto; gap: 6px; margin-bottom: 6px; }
.edit-ex input.a { direction: ltr; text-align: center; }
.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--brand); }
.chat { display: flex; flex-direction: column; gap: 8px; max-height: 55vh; overflow-y: auto; padding: 4px; }
.msg { max-width: 78%; padding: 8px 12px; border-radius: 14px; word-wrap: break-word; }
.msg .txt { white-space: pre-wrap; display: block; }
.msg.me { align-self: flex-start; background: var(--brand); color: #fff; border-bottom-right-radius: 4px; }
.msg.them { align-self: flex-end; background: #eceff5; border-bottom-left-radius: 4px; }
.msg .t { font-size: 11px; opacity: .7; margin-top: 2px; }
.msg .ref { font-size: 13px; opacity: .85; border-bottom: 1px dashed currentColor; margin-bottom: 4px; }
.msg img, .thumbs img { max-width: 220px; max-height: 220px; border-radius: 8px; display: block; margin-top: 4px; cursor: zoom-in; }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
.levels { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; align-items: center; }
.stars { color: #e0a800; letter-spacing: 1px; }
.login { max-width: 380px; margin: 10vh auto; }
.login .big { font-size: 22px; text-align: center; letter-spacing: 4px; direction: ltr; width: 100%; }
.seg { display: flex; background: var(--bg); padding: 4px; border-radius: 10px; margin-bottom: 14px; }
.seg button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 8px; cursor: pointer; }
.seg button.on { background: var(--card); box-shadow: 0 1px 3px #0001; font-weight: 500; }
.ai-box { background: #f5f0ff; border: 1px solid #ddd0fb; border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.ai-box b { color: #5b3cc4; }
#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 20; }
#lightbox { position: fixed; inset: 0; background: #000c; display: grid; place-items: center; z-index: 30; cursor: zoom-out; }
#lightbox img { max-width: 95vw; max-height: 95vh; }
.empty { text-align: center; color: var(--muted); padding: 24px; }
nav.tabs button i { font-style: normal; margin-inline-end: 4px; }
.pair { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.pair .qr { width: 180px; flex: none; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; }
.pair .qr svg { display: block; width: 100%; height: auto; }
.install { background: #fff8ec; border-color: #f6dcae; }
.keys { display: inline-flex; gap: 4px; }
.keys .btn { min-width: 40px; font-size: 18px; font-weight: 700; }

/* ---- lesson boards ---- */
.big-touch { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.board-actions { display: flex; flex-direction: column; gap: 10px; }
.boards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.bcard { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; cursor: pointer; position: relative; display: flex; flex-direction: column; }
.bcard:hover { border-color: var(--brand); }
.bcard .thumb { height: 140px; background: #fff center/cover; border-bottom: 1px solid var(--line); overflow: hidden; }
.bcard .thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }
.thumb.paper-grid { background-image: linear-gradient(#cfe0f5 1px, transparent 1px), linear-gradient(90deg, #cfe0f5 1px, transparent 1px); background-size: 12px 12px; }
.thumb.paper-lines { background-image: linear-gradient(#d6dbe6 1px, transparent 1px); background-size: 100% 18px; }
.bcard .meta { padding: 8px 10px; }
.bcard .btn.danger { position: absolute; top: 6px; left: 6px; background: #fffd; }
body.board-open { overflow: hidden; }
#board { position: fixed; inset: 0; z-index: 40; background: #e6e9f0; display: flex; flex-direction: column; padding-top: env(safe-area-inset-top); }
.bd-top { display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: #fff; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.bd-title { border: 1px solid transparent; font-weight: 700; font-size: 16px; min-width: 120px; flex: 0 1 260px; }
.bd-title:hover, .bd-title:focus { border-color: var(--line); }
.bd-who { font-size: 13px; display: flex; align-items: center; gap: 5px; }
.bd-stage { flex: 1; position: relative; overflow: hidden; touch-action: none; }
.bd-stage canvas { position: absolute; inset: 0; touch-action: none; display: block; }
.bd-loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); pointer-events: none; }
.bd-loading[hidden] { display: none; }
.bd-text { position: absolute; width: 240px; min-height: 40px; background: #fffffff0; border: 2px dashed var(--brand); border-radius: 8px; padding: 4px 8px; font-weight: 600; z-index: 2; resize: both; }
.bd-tools { display: flex; gap: 6px; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); background: #fff; border-top: 1px solid var(--line); overflow-x: auto; justify-content: center; flex-wrap: wrap; }
.bd-group { display: flex; gap: 2px; padding: 2px; background: var(--bg); border-radius: 12px; flex: none; }
.bd-tools button { border: 0; background: none; min-width: 40px; height: 40px; border-radius: 10px; cursor: pointer; font-size: 18px; display: grid; place-items: center; color: var(--ink); }
.bd-tools button.on { background: #fff; box-shadow: 0 1px 4px #0002; outline: 2px solid var(--brand); }
.bd-tools [data-color] i { width: 22px; height: 22px; border-radius: 50%; background: var(--c); display: block; }
.bd-tools [data-width] i { border-radius: 50%; background: var(--ink); display: block; }
@media (max-width: 760px) {
  .bd-tools { gap: 3px; padding-left: 2px; padding-right: 2px; }
  .bd-group { gap: 0; padding: 1px; }
  .bd-tools button { min-width: 31px; width: 31px; height: 36px; font-size: 16px; }
  .bd-tools [data-color] i { width: 19px; height: 19px; }
  .bd-top .bd-title { flex: 1 1 100px; }
}
@media (pointer: coarse) { .bd-tools [data-b="zoomIn"], .bd-tools [data-b="zoomOut"] { display: none; } } /* pinch to zoom */
#photoReq { position: fixed; inset: 0; z-index: 50; background: #1d2433cc; display: grid; place-items: center; padding: 16px; }
#photoReq .card { max-width: 380px; text-align: center; display: flex; flex-direction: column; align-items: stretch; }
#photoReq h2 { margin: 6px 0; }

/* ---- student (phone / tablet app) ---- */
body.stu header.top { padding-top: env(safe-area-inset-top); }
body.stu .ex { padding: 14px; border-radius: 14px; background: #fff; }
body.stu .ex .q { font-size: 23px; }
body.stu .ex input.ans { width: 150px; font-size: 21px; padding: 9px 10px; }
body.stu .btn { min-height: 42px; }
body.stu .btn.small { min-height: 38px; }
body.stu .stu-login .big { font-size: 28px; padding: 12px; }
body.stu .big-btn { font-size: 19px; padding: 12px; }
body.stu .levels { font-size: 17px; }
body.stu .stars { font-size: 20px; }
@media (max-width: 760px), (pointer: coarse) and (max-width: 1366px) {
  body.stu .wrap { padding-left: 12px; padding-right: 12px; }
  body.stu main.wrap { padding-bottom: calc(86px + env(safe-area-inset-bottom)); }
  body.stu header.top .btn[data-a="logout"] { display: none; }
  body.stu nav.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: grid; grid-template-columns: repeat(4, 1fr); gap: 0;
    background: #fff; border-top: 1px solid var(--line); box-shadow: 0 -2px 10px #0000000d; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); }
  body.stu nav.tabs button { display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 6px 2px; font-size: 12.5px; position: relative; border-radius: 10px; }
  body.stu nav.tabs button i { font-size: 23px; margin: 0; line-height: 1.2; }
  body.stu nav.tabs button .badge { position: absolute; top: 2px; right: calc(50% - 26px); font-size: 11px; padding: 0 6px; }
  body.stu #toast { bottom: calc(92px + env(safe-area-inset-bottom)); width: max-content; max-width: 90vw; text-align: center; }
  body.stu .chat { max-height: calc(100vh - 290px); max-height: calc(100dvh - 290px); }
  body.stu .login { margin-top: 6vh; }
}
@media (max-width: 760px) { .pair .qr { width: 100%; max-width: 240px; margin: 0 auto; } }
@media (min-width: 761px) {
  body.stu main.wrap { max-width: 860px; }
}
@media (max-width: 640px) {
  .edit-ex { grid-template-columns: 1fr 90px; }
  .edit-ex .h { grid-column: 1 / -1; }
  .msg { max-width: 90%; }
}
