/* ─── Design tokens ─────────────────────────────────────────────────── */
:root {
  --bg:        #0f1117;
  --surface:   #1a1d27;
  --surface2:  #22263a;
  --border:    rgba(255,255,255,.08);
  --ink:       #e8eaf0;
  --muted:     #8b90a8;
  --brand:     #6366f1;
  --brand-h:   #818cf8;
  --danger:    #ef4444;
  --good:      #22c55e;
  --warn:      #f59e0b;

  --hl-yellow: rgba(251,191,36,.45);
  --hl-green:  rgba(52,211,153,.40);
  --hl-pink:   rgba(244,114,182,.38);
  --hl-blue:   rgba(96,165,250,.38);
  --hl-orange: rgba(251,146,60,.40);
  --hl-purple: rgba(167,139,250,.38);

  --radius:   12px;
  --radius-s:  8px;
  --topbar-h: 52px;
  --toolbar-w: 56px;    /* vertical toolbar width on desktop */
  --sidebar-w: 260px;
  --student-bar-h: 44px;

  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { margin: 0; overscroll-behavior: none; }
[hidden] { display: none !important; }
button { -webkit-tap-highlight-color: transparent; }

/* ─── Shared atoms ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  border: 1px solid var(--border); background: var(--surface2);
  color: var(--ink); border-radius: var(--radius-s); padding: .5rem .9rem;
  font: inherit; font-size: .9rem; cursor: pointer; min-height: 44px;
  transition: background .15s, border-color .15s;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover, .btn:focus-visible { background: var(--surface); border-color: rgba(255,255,255,.18); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover, .btn-primary:focus-visible { background: var(--brand-h); border-color: var(--brand-h); }

input, select {
  font: inherit; border: 1px solid var(--border); border-radius: var(--radius-s);
  padding: .55rem .75rem; min-height: 44px; background: var(--surface2);
  color: var(--ink); outline: none; transition: border-color .15s;
  -webkit-appearance: none; appearance: none;
}
input:focus, select:focus { border-color: var(--brand); }
label { display: grid; gap: .3rem; font-size: .9rem; }
.error { color: var(--danger); min-height: 1.2em; font-size: .88rem; padding-top: .2rem; }

/* ─── Dashboard ────────────────────────────────────────────────────── */
.page-dashboard { background: var(--bg); }

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: .75rem 1.25rem; background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar .brand { font-weight: 700; font-size: 1.1rem; color: var(--ink); }
.topbar .brand span { color: var(--brand); }
.topbar-right { display: flex; gap: .6rem; align-items: center; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

.container { max-width: 980px; margin: 1.5rem auto; padding: 0 1.25rem; display: grid; gap: 1.2rem; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem;
}
.card.narrow { max-width: 440px; margin: 2rem auto; width: 100%; }
.card-head {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap;
}
.card-head h2 { font-size: 1rem; font-weight: 600; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .8rem; }
.row input:not([type=file]) { flex: 1 1 220px; }
.list { list-style: none; }
.list li {
  display: flex; justify-content: space-between; align-items: center;
  gap: .8rem; padding: .75rem 0; border-top: 1px solid var(--border); flex-wrap: wrap;
}
.actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.table th, .table td {
  text-align: left; padding: .5rem .4rem;
  border-top: 1px solid var(--border); color: var(--ink);
}
.table th { color: var(--muted); font-weight: 500; }
progress { width: 100%; height: 6px; border-radius: 4px; overflow: hidden; }
progress::-webkit-progress-bar { background: var(--surface2); }
progress::-webkit-progress-value { background: var(--brand); border-radius: 4px; }

/* ─── Join screen ──────────────────────────────────────────────────── */
.page-room { height: 100dvh; overflow: hidden; background: var(--bg); }

.join-screen {
  min-height: 100dvh; display: grid; place-items: center; padding: 1rem;
  background: radial-gradient(ellipse 80% 60% at 50% 0%, rgba(99,102,241,.18), transparent);
}
.join-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: clamp(1.25rem, 5vw, 2rem);
  width: 100%; max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.join-brand {
  display: flex; align-items: center; gap: .6rem; font-weight: 700;
  font-size: 1.15rem; margin-bottom: 1.4rem;
}
.join-card h1 { font-size: clamp(1.3rem, 5vw, 1.6rem); margin-bottom: .3rem; }
.join-sub { color: var(--muted); font-size: .9rem; margin-bottom: 1.4rem; }
.field { margin-bottom: 1rem; }
.field label { font-size: .85rem; color: var(--muted); margin-bottom: .3rem; display: block; }
.field input { width: 100%; }
.btn-join {
  display: flex; align-items: center; justify-content: center; gap: .5rem;
  width: 100%; padding: .85rem; background: var(--brand); border: none;
  border-radius: var(--radius-s); color: #fff; font-size: 1rem; font-weight: 600;
  cursor: pointer; min-height: 50px;
  transition: background .15s;
  -webkit-tap-highlight-color: transparent;
}
.btn-join:hover, .btn-join:focus-visible { background: var(--brand-h); }

/* ─── Classroom shell ─────────────────────────────────────────────── */
.classroom {
  display: flex; flex-direction: column;
  height: 100dvh; width: 100vw; overflow: hidden;
}

/* ─── Top bar ─────────────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: .6rem;
  padding: 0 .75rem; height: var(--topbar-h); flex: none;
  position: relative; z-index: 20;
  background: rgba(18,20,32,.92);
  border-bottom: 1px solid rgba(255,255,255,.07);
  backdrop-filter: blur(16px) saturate(160%);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  box-shadow: 0 1px 0 rgba(255,255,255,.04), 0 2px 12px rgba(0,0,0,.35);
}
.topbar-left {
  display: flex; align-items: center; gap: .5rem;
  min-width: 0; flex: 1; overflow: hidden;
}
/* Centre pill on tablet+ */
.topbar-center {
  display: none; /* hidden on mobile, shown when doc open */
  align-items: center; gap: .4rem;
  position: absolute; left: 50%; transform: translateX(-50%);
}
.topbar-center:not([hidden]) { display: flex; }

.topbar-right { display: flex; align-items: center; gap: .4rem; margin-left: auto; flex-shrink: 0; position: relative; }

.class-info { min-width: 0; overflow: hidden; }
.class-name {
  font-size: .9rem; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block;
}
.class-doc {
  font-size: .75rem; color: var(--muted); display: block;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Net dot */
.net-dot {
  width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; background: var(--muted);
  transition: background .3s; box-shadow: 0 0 0 2px rgba(0,0,0,.3);
}
.net-dot.good { background: var(--good); box-shadow: 0 0 6px var(--good); }
.net-dot.ok   { background: var(--warn); }
.net-dot.bad  { background: var(--danger); }
.net-dot.off  { background: var(--muted); }

/* Page nav */
.nav-btn {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface2); color: var(--ink); cursor: pointer; display: grid;
  place-items: center; transition: background .15s; flex-shrink: 0;
  min-width: 36px; /* prevent squeeze */
  -webkit-tap-highlight-color: transparent;
}
.nav-btn:hover, .nav-btn:focus-visible { background: var(--surface); }
.page-pill {
  display: flex; align-items: center; gap: .3rem;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 20px; padding: .2rem .65rem;
}
.page-pill input {
  width: 3rem; border: none; background: none; color: var(--ink);
  text-align: center; font-size: .88rem; padding: .1rem 0;
  min-height: unset; min-width: 0;
}
.page-total { font-size: .82rem; color: var(--muted); white-space: nowrap; }

/* Badges */
.stars-badge, .people-badge {
  display: flex; align-items: center; gap: .3rem; font-size: .82rem; font-weight: 600;
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.1);
  border-radius: 20px; padding: .22rem .6rem;
  color: var(--warn); flex-shrink: 0;
  transition: background .15s;
}
.people-badge { color: var(--muted); cursor: pointer; }
.people-badge:hover, .people-badge:focus-visible { background: rgba(255,255,255,.12); color: var(--ink); }

/* People panel */
.people-panel {
  position: absolute; top: calc(100% + 8px); right: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .6rem 0;
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
  z-index: 40; min-width: 240px; max-width: 300px;
}
.people-panel-title {
  font-size: .68rem; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em;
  padding: 0 .85rem .4rem; margin: 0;
}
.people-list { list-style: none; margin: 0; padding: 0; }
.people-item {
  display: flex; align-items: center; gap: .55rem;
  padding: .42rem .85rem;
  transition: background .12s;
}
.people-item:hover { background: var(--surface2); }
.people-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .72rem; font-weight: 700; flex-shrink: 0;
}
.people-avatar-tutor { background: rgba(99,102,241,.25); color: var(--brand-h); }
.people-avatar-student { background: rgba(16,185,129,.18); color: #34d399; }
.people-info { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.people-name { font-size: .82rem; font-weight: 500; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.people-role { font-size: .68rem; color: var(--muted); text-transform: capitalize; }
.people-actions { display: flex; gap: .3rem; flex-shrink: 0; }
.people-action-btn {
  font-size: .68rem; font-weight: 600; padding: .18rem .5rem;
  border-radius: 999px; cursor: pointer; transition: background .15s;
  border: 1px solid;
}
.people-kick {
  background: rgba(245,158,11,.12); border-color: rgba(245,158,11,.35);
  color: #f59e0b;
}
.people-kick:hover { background: rgba(245,158,11,.25); }
.people-block {
  background: rgba(239,68,68,.12); border-color: rgba(239,68,68,.35);
  color: #ef4444;
}
.people-block:hover { background: rgba(239,68,68,.25); }
.people-empty { font-size: .8rem; color: var(--muted); padding: .4rem .85rem; }

@keyframes pop { 0%,100%{transform:scale(1)} 45%{transform:scale(1.45)} }
.stars-badge.pop { animation: pop .5s ease; }

/* ─── Chat button & unread badge ─────────────────────────────────── */
.chat-btn { position: relative; }
.chat-btn.open {
  background: rgba(99,102,241,.22); color: var(--brand-h);
  border: 1px solid rgba(99,102,241,.45);
}
.chat-unread {
  position: absolute; top: 2px; right: 2px;
  background: #ef4444; color: #fff;
  font-size: .58rem; font-weight: 700; line-height: 1;
  min-width: 14px; height: 14px; padding: 0 3px;
  border-radius: 999px; display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}

/* ─── Chat panel (compact floating popup) ───────────────────────── */
.chat-panel {
  position: fixed;
  bottom: calc(var(--student-bar-h) + 10px);
  right: 14px;
  width: min(320px, calc(100vw - 28px));
  max-height: min(400px, calc(100dvh - var(--topbar-h) - var(--student-bar-h) - 30px));
  z-index: 50;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px;
  display: flex; flex-direction: column;
  box-shadow: 0 8px 40px rgba(0,0,0,.55), 0 2px 8px rgba(0,0,0,.3);
  animation: chatPopIn .18s cubic-bezier(.34,1.56,.64,1);
  overflow: hidden;
}
.chat-panel[hidden] { display: none; }

@keyframes chatPopIn {
  from { transform: scale(.88) translateY(16px); opacity: 0; }
  to   { transform: scale(1)   translateY(0);    opacity: 1; }
}

.chat-panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: .65rem .9rem; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.chat-panel-title {
  font-size: .88rem; font-weight: 600; color: var(--ink);
}

.chat-messages {
  flex: 1; overflow-y: auto; padding: .6rem .75rem;
  display: flex; flex-direction: column; gap: .45rem;
  -webkit-overflow-scrolling: touch;
}
.chat-msg {
  display: flex; flex-direction: column; gap: .1rem;
  max-width: 86%;
}
.chat-msg.me { align-self: flex-end; align-items: flex-end; }
.chat-msg.other { align-self: flex-start; align-items: flex-start; }

.chat-msg-meta {
  font-size: .64rem; color: var(--muted); display: flex; gap: .35rem; align-items: baseline;
}
.chat-msg-name { font-weight: 600; }
.chat-msg-name.tutor { color: hsl(var(--brand-h),80%,65%); }
.chat-msg-name.student { color: #34d399; }
.chat-msg-time { opacity: .7; }

.chat-msg-bubble {
  font-size: .84rem; line-height: 1.4;
  padding: .4rem .65rem; border-radius: 14px;
  word-break: break-word; white-space: pre-wrap;
}
.chat-msg.me .chat-msg-bubble {
  background: hsl(var(--brand-h),55%,40%); color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-msg.other .chat-msg-bubble {
  background: var(--surface2); color: var(--ink);
  border-bottom-left-radius: 4px;
}

.chat-day-sep {
  align-self: center; font-size: .66rem; color: var(--muted);
  background: var(--surface2); border-radius: 999px;
  padding: .15rem .6rem; flex-shrink: 0; margin: .3rem 0;
}

.chat-empty {
  flex: 1; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: .82rem; text-align: center; padding: 1.5rem;
}

.chat-input-row {
  display: flex; gap: .4rem; padding: .55rem .7rem;
  border-top: 1px solid var(--border); flex-shrink: 0; align-items: center;
}
.chat-input {
  flex: 1; background: var(--surface2); border: 1px solid var(--border);
  border-radius: 20px; padding: .4rem .75rem; font-size: .84rem; color: var(--ink);
  outline: none; min-width: 0;
  transition: border-color .15s;
}
.chat-input:focus { border-color: hsl(var(--brand-h),70%,55%); }
.chat-input::placeholder { color: var(--muted); }
.chat-send-btn {
  width: 34px; height: 34px; border-radius: 50%; border: none; cursor: pointer; flex-shrink: 0;
  background: hsl(var(--brand-h),55%,40%); color: #fff;
  display: grid; place-items: center;
  transition: background .15s, transform .1s;
}
.chat-send-btn:hover { background: hsl(var(--brand-h),60%,50%); }
.chat-send-btn:active { transform: scale(.93); }

/* ─── Text-selection highlight overlay ──────────────────────────── */
.text-sel-hl {
  position: absolute; pointer-events: none; z-index: 4;
  background: rgba(251,191,36,.38);
  border-radius: 2px;
  mix-blend-mode: multiply;
  animation: textHlFadeIn .15s ease;
}
@keyframes textHlFadeIn {
  from { opacity: 0; transform: scaleY(.85); }
  to   { opacity: 1; transform: scaleY(1); }
}
/* Tutor-only: cursor crosshair when text-select tool active */
.page-wrap.text-select-mode { cursor: text; user-select: text; }
.page-wrap.text-select-mode canvas { pointer-events: none; }
.page-wrap.text-select-mode img  { pointer-events: none; }

/* ─── Room body ──────────────────────────────────────────────────── */
.room-body { flex: 1; display: flex; min-height: 0; position: relative; overflow: hidden; }

/* ─── Library Sidebar ────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w); flex: none;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden; z-index: 15;
  /* animate open/close */
  transition: width .2s ease;
}
.sidebar[hidden] { width: 0; display: flex !important; overflow: hidden; }

.sidebar-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: .7rem .9rem; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.sidebar-title { font-weight: 600; font-size: .9rem; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 6px; border: 1px solid var(--border);
  background: transparent; color: var(--muted); cursor: pointer; display: grid;
  place-items: center; transition: background .15s, color .15s; flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover, .icon-btn:focus-visible { background: var(--surface2); color: var(--ink); }

.upload-area {
  display: flex; flex-direction: column; align-items: center; gap: .4rem;
  margin: .65rem; padding: .9rem; border: 2px dashed var(--border);
  border-radius: var(--radius-s); cursor: pointer; color: var(--muted);
  font-size: .82rem; text-align: center; transition: border-color .15s, color .15s;
  flex-shrink: 0;
}
.upload-area:hover { border-color: var(--brand); color: var(--brand); }

.upload-bar { height: 4px; background: var(--surface2); margin: 0 .65rem .4rem; border-radius: 4px; overflow: hidden; flex-shrink: 0; }
.upload-bar-fill { height: 100%; background: var(--brand); border-radius: 4px; width: 0; transition: width .2s; }

.docs-list { flex: 1; overflow-y: auto; padding: .4rem; -webkit-overflow-scrolling: touch; }
.docs-empty { color: var(--muted); font-size: .82rem; text-align: center; padding: 1.5rem .5rem; }
.doc-item {
  display: flex; align-items: center; gap: .5rem;
  padding: .6rem; border-radius: var(--radius-s); cursor: pointer;
  transition: background .15s; border: 1px solid transparent;
  -webkit-tap-highlight-color: transparent;
}
.doc-item:hover, .doc-item:focus-visible { background: var(--surface2); }
.doc-item.active { background: rgba(99,102,241,.18); border-color: rgba(99,102,241,.4); }
.doc-icon {
  width: 32px; height: 36px; background: var(--surface2); border-radius: 4px;
  display: grid; place-items: center; flex-shrink: 0; font-size: .6rem;
  color: var(--muted); border: 1px solid var(--border); font-weight: 700;
}
.doc-info { min-width: 0; flex: 1; }
.doc-name { font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.doc-meta { font-size: .72rem; color: var(--muted); }

/* ─── Viewer ────────────────────────────────────────────────────── */
.viewer {
  flex: 1; overflow: auto; padding: 12px;
  background: #12141c;
  -webkit-overflow-scrolling: touch;
  position: relative;
}

.empty-state {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 1rem;
  color: var(--muted); padding: 2rem;
}
.empty-state svg { opacity: .3; flex-shrink: 0; }
.empty-state p { font-size: .92rem; text-align: center; }

.page-wrap {
  position: relative; background: #fff;
  box-shadow: 0 4px 32px rgba(0,0,0,.55);
  border-radius: 2px; margin: 0 auto;
}
.page-wrap canvas, .page-wrap img { display: block; }

/* ─── Marks layer ───────────────────────────────────────────────── */
.marks { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.marks.tool-laser { pointer-events: auto; touch-action: none; cursor: none; }
.marks.tool-hl, .marks.tool-star, .marks.tool-erase, .marks.tool-pen {
  pointer-events: auto; touch-action: none; cursor: crosshair;
}
/* text-sel: marks layer is transparent so text under PDF canvas is selectable */
.marks.tool-text-sel { pointer-events: none; }

.mark { position: absolute; }
.hl { border-radius: 2px; mix-blend-mode: multiply; }
.hl-yellow { background: var(--hl-yellow); } .hl-green { background: var(--hl-green); }
.hl-pink   { background: var(--hl-pink);   } .hl-blue  { background: var(--hl-blue);  }
.hl-orange { background: var(--hl-orange); } .hl-purple{ background: var(--hl-purple);}
.hl.ghost  { outline: 1.5px dashed rgba(0,0,0,.35); }

.ink-layer { position: absolute; inset: 0; pointer-events: none; }
.marks.tool-line, .marks.tool-arrow, .marks.tool-rect, .marks.tool-ellipse {
  pointer-events: auto; touch-action: none; cursor: crosshair;
}
.marks.tool-text { pointer-events: auto; cursor: text; }

/* Whiteboard page: white with a faint dot grid */
.page-wrap.board {
  background: #fff radial-gradient(circle, #d7dbe2 1px, transparent 1.2px) 0 0 / 4% 5.333%;
}
.ink-text-input {
  position: absolute; z-index: 5; margin: 0; padding: 0 2px;
  border: 1px dashed #6366f1; border-radius: 2px; outline: none;
  background: rgba(255,255,255,.85); line-height: 1.2;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Naskh Arabic", sans-serif;
  max-width: 100%; transform: translate(-3px, -1px);
}
.ink-text-input::placeholder { color: #9ca3af; font-size: 14px; }

.star-mark {
  transform: translate(-50%, -50%);
  font-size: clamp(24px, 5vw, 44px);
  filter: drop-shadow(0 2px 4px rgba(0,0,0,.3));
  animation: starpop .55s cubic-bezier(.17,.89,.32,1.28);
  cursor: default; user-select: none;
}
@keyframes starpop {
  0%   { transform: translate(-50%,-50%) scale(.2) rotate(-20deg); opacity: 0; }
  60%  { transform: translate(-50%,-50%) scale(1.3) rotate(5deg); opacity: 1; }
  100% { transform: translate(-50%,-50%) scale(1) rotate(0deg); }
}
.marks.tool-erase .mark { cursor: pointer; outline: 2px dashed rgba(239,68,68,.7); outline-offset: 1px; }

.laser {
  position: absolute; width: 22px; height: 22px; border-radius: 50%;
  background: rgba(239,68,68,.9);
  box-shadow: 0 0 0 4px rgba(239,68,68,.25), 0 0 16px 6px rgba(239,68,68,.35);
  transform: translate(-50%, -50%); pointer-events: none;
  transition: left 70ms linear, top 70ms linear;
}

/* ─── Floating toolbar — DESKTOP (left side, vertical) ─────────── */
.float-toolbar {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; align-items: center; gap: .2rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: .45rem .35rem;
  box-shadow: 0 8px 32px rgba(0,0,0,.45);
  z-index: 10;
}

.tb-btn {
  width: 44px; height: 44px; border-radius: 10px; border: 1px solid transparent;
  background: transparent; color: var(--muted); cursor: pointer; display: grid;
  place-items: center; transition: background .15s, color .15s, border-color .15s;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.tb-btn:hover, .tb-btn:focus-visible { background: var(--surface2); color: var(--ink); }
.tb-btn.tool.active {
  background: rgba(99,102,241,.22); color: var(--brand-h);
  border-color: rgba(99,102,241,.45);
}
.tb-btn.tool[data-tool="star"] { color: var(--warn); }
.tb-btn.tool[data-tool="star"].active { background: rgba(245,158,11,.18); border-color: rgba(245,158,11,.45); }
.tb-btn-lib { color: var(--brand); }
.tb-btn-lib:hover, .tb-btn-lib:focus-visible { background: rgba(99,102,241,.15); color: var(--brand-h); }
.tb-btn-danger:hover, .tb-btn-danger:focus-visible { background: rgba(239,68,68,.15); color: var(--danger); }
.tb-sep { width: 24px; height: 1px; background: var(--border); margin: .1rem 0; flex-shrink: 0; }

/* Colour swatches — vertical strip on desktop */
.tb-colors { display: flex; flex-direction: column; gap: .28rem; padding: .05rem 0; }
.swatch {
  width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--surface);
  background: var(--c, #fff); cursor: pointer; outline: 2px solid transparent;
  outline-offset: 1px; transition: outline-color .12s, transform .12s;
  -webkit-tap-highlight-color: transparent;
}
.swatch:hover { transform: scale(1.18); }
.swatch.active { outline-color: var(--c, #fff); }

/* ─── Student bar ───────────────────────────────────────────────── */
.student-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 .9rem; background: var(--surface); border-top: 1px solid var(--border);
  flex: none; height: var(--student-bar-h); min-height: var(--student-bar-h);
}
.page-label { font-size: .8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-follow {
  display: flex; align-items: center; gap: .4rem; flex-shrink: 0;
  background: var(--brand); border: none; border-radius: 6px;
  color: #fff; font-size: .82rem; font-weight: 600; padding: .35rem .75rem;
  cursor: pointer; min-height: 34px;
  transition: background .15s;
  -webkit-tap-highlight-color: transparent;
}
.btn-follow:hover { background: var(--brand-h); }

/* ─── Waiting-for-teacher screen (student) ───────────────────────── */
.waiting-screen {
  position: fixed; inset: 0; z-index: 50;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
}
.waiting-card {
  display: flex; flex-direction: column; align-items: center; gap: 1rem;
  text-align: center; padding: 2.5rem 2rem; max-width: 320px;
}
.waiting-pulse {
  width: 80px; height: 80px; border-radius: 50%;
  background: var(--surface2);
  display: grid; place-items: center;
  color: var(--brand-h);
  position: relative;
}
.waiting-pulse::before {
  content: ''; position: absolute; inset: -6px; border-radius: 50%;
  border: 2px solid rgba(99,102,241,.35);
  animation: waiting-ring 1.8s ease-out infinite;
}
.waiting-pulse::after {
  content: ''; position: absolute; inset: -14px; border-radius: 50%;
  border: 2px solid rgba(99,102,241,.15);
  animation: waiting-ring 1.8s ease-out 0.5s infinite;
}
@keyframes waiting-ring {
  0%   { transform: scale(.85); opacity: 1; }
  100% { transform: scale(1.3); opacity: 0; }
}
.waiting-title {
  font-size: 1.1rem; font-weight: 600; color: var(--ink); margin: 0;
}
.waiting-sub {
  font-size: .84rem; color: var(--muted); margin: 0; line-height: 1.5;
}

/* ─── "Teacher not here yet" badge (past lesson) ─────────────────── */
.no-tutor-badge {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  background: rgba(245,158,11,.18); color: #d97706;
  border: 1px solid rgba(245,158,11,.35);
  border-radius: 20px; padding: .3rem .85rem;
  font-size: .78rem; font-weight: 600; white-space: nowrap;
  z-index: 10; pointer-events: none;
}

/* ─── Permission panel (teacher) ─────────────────────────────────── */
.tb-btn-perm { color: var(--muted); }
.tb-btn-perm:hover, .tb-btn-perm:focus-visible { background: rgba(34,197,94,.12); color: var(--good); }

/* ─── Share / invite link button & popup (topbar, tutor only) ─────────── */
.tb-btn-share { color: var(--muted); position: relative; }
.tb-btn-share:hover, .tb-btn-share:focus-visible { background: rgba(99,102,241,.12); color: var(--brand-h); }
.share-panel {
  position: absolute; top: calc(100% + 8px); right: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .75rem;
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
  z-index: 40; min-width: 280px; max-width: 340px;
}
.share-label { font-size: .72rem; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em; margin: 0 0 .4rem; }
.share-row { display: flex; gap: .4rem; align-items: center; }
.share-input {
  flex: 1; min-width: 0;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-s); padding: .35rem .55rem;
  font-size: .78rem; color: var(--ink); outline: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.share-copy-btn {
  display: flex; align-items: center; gap: .3rem;
  background: rgba(99,102,241,.18); border: 1px solid rgba(99,102,241,.35);
  border-radius: var(--radius-s); padding: .35rem .65rem;
  font-size: .78rem; font-weight: 600; color: var(--brand-h);
  cursor: pointer; white-space: nowrap; transition: background .15s;
  flex-shrink: 0;
}
.share-copy-btn:hover { background: rgba(99,102,241,.28); }
.share-copy-btn.copied { background: rgba(34,197,94,.18); border-color: rgba(34,197,94,.35); color: var(--good); }

.perm-panel {
  position: fixed; bottom: 70px; right: 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .6rem .6rem .5rem;
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
  z-index: 30; min-width: 170px;
}
.perm-panel-title {
  font-size: .72rem; font-weight: 600; color: var(--muted); text-transform: uppercase;
  letter-spacing: .06em; padding: 0 .4rem .4rem; margin-bottom: .2rem;
  border-bottom: 1px solid var(--border);
}
.perm-toggle {
  display: flex; align-items: center; gap: .55rem; width: 100%;
  background: transparent; border: 1px solid var(--border); border-radius: var(--radius-s);
  color: var(--muted); font: inherit; font-size: .84rem; cursor: pointer;
  padding: .45rem .6rem; margin-top: .35rem;
  transition: background .12s, color .12s, border-color .12s;
  -webkit-tap-highlight-color: transparent;
}
.perm-toggle:hover { background: var(--surface2); color: var(--ink); }
.perm-toggle.on {
  background: rgba(34,197,94,.12); color: var(--good);
  border-color: rgba(34,197,94,.35);
}
.perm-toggle .perm-status {
  margin-left: auto; font-size: .72rem; font-weight: 700;
  color: var(--muted); letter-spacing: .03em;
}
.perm-toggle.on .perm-status::after { content: 'ON'; color: var(--good); }
.perm-toggle:not(.on) .perm-status::after { content: 'OFF'; color: var(--muted); }

/* ─── Permission badges (student bar) ────────────────────────────── */
.perm-badges { display: flex; align-items: center; gap: .3rem; }
.perm-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 50%;
  background: rgba(34,197,94,.18); color: var(--good);
  border: 1px solid rgba(34,197,94,.35);
}

/* ─── Student mini toolbar ────────────────────────────────────────── */
.student-toolbar {
  position: fixed; bottom: calc(var(--student-bar-h) + 6px); left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: .2rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: .35rem .4rem;
  box-shadow: 0 4px 20px rgba(0,0,0,.4);
  z-index: 20;
}
.stu-btn {
  width: 38px; height: 38px; border-radius: 8px; border: 1px solid transparent;
  background: transparent; color: var(--muted); cursor: pointer;
  display: grid; place-items: center;
  transition: background .15s, color .15s, border-color .15s;
  -webkit-tap-highlight-color: transparent;
}
.stu-btn:hover { background: var(--surface2); color: var(--ink); }
.stu-btn.tool.active {
  background: rgba(99,102,241,.22); color: var(--brand-h);
  border-color: rgba(99,102,241,.45);
}
.stu-sep { width: 1px; height: 24px; background: var(--border); margin: 0 .1rem; }
.stu-swatch {
  width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--surface);
  background: var(--c, #fff); cursor: pointer; outline: 2px solid transparent;
  outline-offset: 1px; transition: outline-color .12s;
  -webkit-tap-highlight-color: transparent;
}
.stu-swatch.active { outline-color: var(--c, #fff); }

/* ─── Star burst ──────────────────────────────────────────────────── */
.star-burst { position: fixed; inset: 0; pointer-events: none; z-index: 100; overflow: hidden; }
.burst-star {
  position: absolute; opacity: 0;
  animation: burstAnim 1.4s cubic-bezier(.17,.89,.32,1.28) forwards;
  user-select: none;
}
@keyframes burstAnim {
  0%   { opacity: 1; transform: translate(-50%,-50%) scale(0) rotate(0deg); }
  60%  { opacity: 1; transform: translate(-50%, calc(-50% - 60px)) scale(1.4) rotate(20deg); }
  100% { opacity: 0; transform: translate(-50%, calc(-50% - 120px)) scale(.8) rotate(35deg); }
}

/* ─── Toast ────────────────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%);
  background: rgba(26,29,39,.95); color: var(--ink);
  padding: .65rem 1.1rem; border-radius: 10px; max-width: min(90vw, 380px);
  font-size: .88rem; border: 1px solid var(--border);
  box-shadow: 0 8px 24px rgba(0,0,0,.4); backdrop-filter: blur(8px);
  z-index: 200; text-align: center;
}

/* ─────────────────────────────────────────────────────────────────────
   RESPONSIVE BREAKPOINTS
   Mobile-first: styles above handle the full layout where possible.
   Breakpoints override for progressively larger viewports.
───────────────────────────────────────────────────────────────────── */

/* ── xs: very small phones (< 400px) ──────────────────────────────── */
@media (max-width: 399px) {
  :root { --topbar-h: 48px; }

  .topbar-center { display: none !important; } /* page nav moves to student/tutor bar */

  /* Badges become icon-only */
  .stars-badge .star-num, .people-badge #people-count, #people-btn #people-count { display: none; }
  .stars-badge, .people-badge, #people-btn { padding: .2rem .4rem; }

  .class-name { font-size: .82rem; }

  /* Toolbar: bottom strip, full width, horizontal scroll */
  .float-toolbar {
    position: fixed; left: 0; right: 0; bottom: calc(var(--student-bar-h) + 2px);
    top: unset; transform: none; border-radius: 0;
    flex-direction: row; flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden;
    padding: .3rem .5rem; gap: .2rem;
    border-left: none; border-right: none; border-bottom: none;
    max-width: 100%;
  }
  .tb-sep { width: 1px; height: 32px; margin: 0; }
  .tb-colors { flex-direction: row; gap: .22rem; }
  .tb-btn { width: 40px; height: 40px; flex-shrink: 0; }
  .swatch { width: 22px; height: 22px; }

  .viewer { padding: 6px; padding-bottom: calc(var(--student-bar-h) + 54px); }

  .student-bar { height: var(--student-bar-h); }

  /* Sidebar: full overlay */
  .sidebar:not([hidden]) {
    position: fixed; inset: var(--topbar-h) 0 0 0;
    width: 100% !important; z-index: 50;
  }
  .sidebar[hidden] { display: none !important; }
}

/* ── sm: phones (400px – 639px) ───────────────────────────────────── */
@media (min-width: 400px) and (max-width: 639px) {
  :root { --topbar-h: 50px; }

  .topbar-center { display: none !important; }

  /* Toolbar: floating bottom-right pill */
  .float-toolbar {
    position: fixed;
    left: unset; right: 10px; bottom: calc(var(--student-bar-h) + 10px);
    top: unset; transform: none; border-radius: 14px;
    flex-direction: row; flex-wrap: wrap; justify-content: center;
    padding: .4rem .45rem; gap: .2rem;
    max-width: calc(100vw - 20px);
  }
  .tb-sep { width: 1px; height: 30px; margin: 0 .05rem; }
  .tb-colors { flex-direction: row; gap: .22rem; }
  .tb-btn { width: 42px; height: 42px; }

  /* viewer padding so toolbar doesn't cover content */
  .viewer { padding: 8px; padding-bottom: calc(var(--student-bar-h) + 110px); }

  /* Sidebar: full overlay */
  .sidebar:not([hidden]) {
    position: fixed; inset: var(--topbar-h) 0 0 0;
    width: 100% !important; z-index: 50;
  }
  .sidebar[hidden] { display: none !important; }

  .class-doc { display: none; } /* save space on small screens */
}

/* ── md: tablets / large phones landscape (640px – 1023px) ────────── */
@media (min-width: 640px) and (max-width: 1023px) {
  :root {
    --topbar-h: 52px;
    --toolbar-w: 54px;
  }

  /* Page nav visible in topbar */
  .topbar-center { display: flex; }

  /* Toolbar: left side vertical, but smaller */
  .float-toolbar {
    left: 8px; top: 50%; transform: translateY(-50%);
    flex-direction: column; flex-wrap: nowrap;
    padding: .4rem .32rem;
  }
  .tb-btn { width: 42px; height: 42px; }

  /* Sidebar: 220px, slides in-flow */
  :root { --sidebar-w: 220px; }
  .sidebar[hidden] { width: 0; display: flex !important; overflow: hidden; }

  .viewer { padding: 10px; padding-left: calc(var(--toolbar-w) + 14px); }
}

/* ── lg: desktop (1024px+) ─────────────────────────────────────────── */
@media (min-width: 1024px) {
  .topbar-center { display: flex; }

  .float-toolbar { left: 10px; }

  .viewer { padding: 16px; padding-left: calc(var(--toolbar-w) + 18px); }

  /* Sidebar slides in-flow, no overlay */
  .sidebar[hidden] { width: 0; display: flex !important; overflow: hidden; }
}

/* ── xl: wide desktop (1400px+) ─────────────────────────────────────── */
@media (min-width: 1400px) {
  :root { --toolbar-w: 60px; }
  .tb-btn { width: 48px; height: 48px; }
  .float-toolbar { left: 12px; }
}

/* ─── Touch: larger tap targets on touch devices ─────────────────── */
@media (hover: none) {
  .tb-btn { min-width: 44px; min-height: 44px; }
  .nav-btn { min-width: 40px; min-height: 40px; }
  .swatch { width: 28px; height: 28px; }
  .doc-item { padding: .75rem .6rem; }
  .btn-join { min-height: 54px; }
}

/* ─── Landscape phones (height-constrained) ──────────────────────── */
@media (max-height: 500px) and (orientation: landscape) {
  :root { --topbar-h: 44px; --student-bar-h: 38px; }

  .float-toolbar {
    max-height: calc(100vh - var(--topbar-h) - var(--student-bar-h) - 20px);
    overflow-y: auto; overflow-x: hidden;
  }
  .tb-btn { width: 36px; height: 36px; }
  .tb-sep { width: 20px; }
}

/* ─── Safe areas (iPhone notch / home bar) ───────────────────────── */
@supports (padding: env(safe-area-inset-bottom)) {
  .student-bar { padding-bottom: max(.0rem, env(safe-area-inset-bottom)); }
  .float-toolbar { margin-bottom: env(safe-area-inset-bottom); }
  .toast { bottom: calc(1.25rem + env(safe-area-inset-bottom)); }
}

/* ─── Whiteboard / drawing panel ──────────────────────────────────── */
.draw-panel { min-width: 232px; }
.draw-panel .perm-panel-title:not(:first-child) { margin-top: .5rem; }
.draw-row { display: flex; align-items: center; gap: .2rem; flex-wrap: wrap; }
.draw-gap { flex: 1; }
.draw-panel .tb-btn { width: 40px; height: 40px; }
.size-btn.active { background: rgba(99,102,241,.22); border-color: rgba(99,102,241,.45); color: var(--brand-h); }
.size-dot { width: var(--d, 8px); height: var(--d, 8px); border-radius: 50%; background: currentColor; display: block; }
.draw-wide-btn {
  flex: 1; height: 40px; border-radius: 10px; cursor: pointer; white-space: nowrap;
  background: rgba(99,102,241,.18); border: 1px solid rgba(99,102,241,.35);
  color: var(--brand-h); font-size: .82rem; font-weight: 600; padding: 0 .7rem;
}
.draw-wide-btn:hover { background: rgba(99,102,241,.28); }
#board-btn.active { background: rgba(99,102,241,.22); border-color: rgba(99,102,241,.45); }
.swatch[data-color="black"], .stu-swatch[data-color="black"] { border-color: #9ca3af; }
.swatch[data-color="black"].active, .stu-swatch[data-color="black"].active { outline-color: #e5e7eb; }

/* Vertical toolbar: colours in two columns so the toolbar stays short */
@media (min-width: 640px) {
  .tb-colors { display: grid; grid-template-columns: repeat(2, 20px); gap: 5px 4px; }
  .tb-colors .swatch { width: 20px; height: 20px; }
  .float-toolbar { max-height: calc(100% - 12px); overflow-y: auto; overflow-x: hidden; scrollbar-width: none; }
}
@media (min-width: 640px) and (max-height: 820px) {
  .float-toolbar > .tb-btn { width: 38px; height: 38px; min-width: 38px; min-height: 38px; }
  .float-toolbar { gap: .1rem; padding-top: .3rem; padding-bottom: .3rem; }
}

/* ─── Audio / video ───────────────────────────────────────────────── */
.av-btn { width: 36px; height: 36px; border-radius: 50%; background: var(--surface2); color: var(--ink); position: relative; }
.av-btn .ico-on { display: none; }
.av-btn.on { background: var(--good, #22c55e); color: #fff; border-color: transparent; }
.av-btn.on .ico-on { display: block; }
.av-btn.on .ico-off { display: none; }
.av-btn.blocked { opacity: .45; }
.av-btn.waiting { opacity: .6; }
.av-speaking { font-size: .76rem; color: var(--good, #22c55e); white-space: nowrap; max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
.av-unlock {
  position: fixed; left: 50%; top: calc(var(--topbar-h, 52px) + 10px); transform: translateX(-50%);
  z-index: 60; border: none; border-radius: 999px; padding: .6rem 1.1rem; cursor: pointer;
  background: var(--brand); color: #fff; font-weight: 600; font-size: .9rem;
  box-shadow: 0 6px 24px rgba(0,0,0,.45);
}
.av-tiles {
  position: fixed; right: 12px; top: calc(var(--topbar-h, 52px) + 10px); z-index: 15;
  display: flex; flex-direction: column; gap: 8px; max-height: 70vh; overflow-y: auto;
}
.av-tile {
  position: relative; width: 168px; aspect-ratio: 4 / 3; border-radius: 10px; overflow: hidden;
  background: #000; border: 2px solid var(--border); box-shadow: 0 4px 18px rgba(0,0,0,.45);
}
.av-tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.av-tile.mine video { transform: scaleX(-1); }
.av-tile.speaking { border-color: var(--good, #22c55e); }
.av-tile-name {
  position: absolute; left: 6px; bottom: 5px; font-size: .7rem; color: #fff;
  background: rgba(0,0,0,.55); border-radius: 6px; padding: 1px 6px; max-width: 90%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.people-item.speaking .people-avatar { box-shadow: 0 0 0 2px var(--good, #22c55e); }
.people-mute-all { width: 100%; margin-bottom: .4rem; }
.join-when { color: var(--brand-h); font-weight: 600; font-size: .9rem; margin: -.2rem 0 .4rem; }
@media (max-width: 639px) {
  .av-tile { width: 104px; }
  .av-tiles { right: 6px; }
  .av-speaking { display: none; }
  .av-btn { width: 34px; height: 34px; }
}

/* ─── Dashboard: schedule and tutors ─────────────────────────────── */
.when { color: var(--brand-h); font-weight: 600; }
.when.past { color: var(--muted); font-weight: 400; }
.inline-form { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; margin-top: .5rem; width: 100%; }
.row input[type=datetime-local], .inline-form input[type=datetime-local] { flex: 0 1 210px; }
.row select, .inline-form select, .inline-form input, .row input[type=datetime-local] {
  background: var(--surface2); border: 1px solid var(--border); color: var(--ink);
  border-radius: var(--radius-s, 8px); padding: .5rem .6rem; font: inherit; color-scheme: dark;
}
.secret-box {
  margin: .2rem 0 .8rem; padding: .7rem .8rem; border-radius: var(--radius-s, 8px);
  background: rgba(34,197,94,.1); border: 1px solid rgba(34,197,94,.35); font-size: .9rem;
}
.secret-box code { font-size: 1rem; user-select: all; background: rgba(0,0,0,.35); padding: .15rem .45rem; border-radius: 6px; }
.tag { font-size: .7rem; border: 1px solid var(--border); border-radius: 999px; padding: 0 .45rem; margin-left: .35rem; color: var(--muted); }
.tag.off { color: var(--danger, #ef4444); border-color: rgba(239,68,68,.4); }
.list li.stack { flex-wrap: wrap; }

/* ─── Student view locked to the tutor ────────────────────────────── */
body.student-locked .viewer { overflow: hidden; touch-action: none; overscroll-behavior: none; }
body.student-locked .page-wrap { pointer-events: none; user-select: none; -webkit-user-select: none; }
body.student-locked .page-wrap .marks[class*="tool-"]:not(.tool-none) { pointer-events: auto; }
.btn-hand {
  display: inline-flex; align-items: center; gap: .3rem; height: 32px; padding: 0 .75rem;
  border-radius: 999px; border: 1px solid var(--border); background: var(--surface2);
  color: var(--ink); font-size: .82rem; font-weight: 600; cursor: pointer; margin-left: auto;
}
.btn-hand:active { transform: scale(.96); }

/* ─── Screen share ────────────────────────────────────────────────── */
.av-screen { position: absolute; inset: 0; z-index: 9; background: #000; display: flex; align-items: center; justify-content: center; }
.av-screen video { width: 100%; height: 100%; object-fit: contain; }
.av-screen-label {
  position: absolute; left: 10px; top: 10px; font-size: .75rem; color: #fff;
  background: rgba(0,0,0,.6); border-radius: 6px; padding: 2px 8px;
}
.av-sharing {
  position: absolute; left: 50%; top: 10px; transform: translateX(-50%); z-index: 12;
  display: flex; align-items: center; gap: .6rem; white-space: nowrap;
  background: var(--good, #22c55e); color: #fff; font-size: .82rem; font-weight: 600;
  border-radius: 999px; padding: .35rem .45rem .35rem .9rem; box-shadow: 0 4px 18px rgba(0,0,0,.4);
}
.av-sharing-stop { border: none; border-radius: 999px; padding: .25rem .7rem; cursor: pointer; background: #fff; color: #166534; font-weight: 700; font-size: .78rem; }

/* Library open on a wide screen: keep the tool bar beside it, not underneath */
@media (min-width: 640px) {
  .sidebar:not([hidden]) ~ .float-toolbar { left: calc(var(--sidebar-w) + 10px); }
}

/* ─── Leave ───────────────────────────────────────────────────────── */
.leave-btn { color: #f87171; }
.leave-btn:hover, .leave-btn:focus-visible { background: rgba(239,68,68,.15); color: #ef4444; }
.leave-bar {
  position: fixed; left: 50%; top: calc(var(--topbar-h, 52px) + 12px); transform: translateX(-50%); z-index: 70;
  display: flex; align-items: center; gap: .6rem; white-space: nowrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: .55rem .7rem .55rem 1rem;
  box-shadow: 0 8px 32px rgba(0,0,0,.55); font-size: .9rem; font-weight: 600;
}
.leave-yes, .leave-no { border: none; border-radius: 10px; padding: .5rem 1rem; font-weight: 700; cursor: pointer; font-size: .88rem; }
.leave-yes { background: #ef4444; color: #fff; }
.leave-no { background: var(--surface2); color: var(--ink); border: 1px solid var(--border); }

/* ─── Connection health (tutor) ───────────────────────────────────── */
.net-dot { cursor: pointer; }
.health-panel {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 80;
  width: min(880px, calc(100vw - 20px)); max-height: calc(100dvh - 40px); display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 16px 60px rgba(0,0,0,.65);
}
.health-head { display: flex; align-items: center; gap: .7rem; padding: .7rem .8rem .5rem 1rem; }
.health-meta { flex: 1; font-size: .72rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.health-scroll { overflow: auto; padding: 0 .6rem; }
.health-table { width: 100%; border-collapse: collapse; font-size: .8rem; }
.health-table th { text-align: left; color: var(--muted); font-weight: 500; padding: .35rem .5rem; white-space: nowrap; }
.health-table td { padding: .45rem .5rem; border-top: 1px solid var(--border); white-space: nowrap; }
.health-table td.h-good { color: #4ade80; } .health-table td.h-ok { color: #fbbf24; } .health-table td.h-bad { color: #f87171; }
.health-hint { font-size: .74rem; color: var(--muted); padding: .5rem 1rem .8rem; }

/* ═══════════════════════════════════════════════════════════════════
   Polish layer: colour, depth and motion. No layout changes.
   ═══════════════════════════════════════════════════════════════════ */
:root {
  --bg: #0b0d14;
  --surface: #151824;
  --surface2: #1f2333;
  --border: rgba(255,255,255,.09);
  --brand: #6d5efc;
  --brand-h: #9488ff;
  --brand-grad: linear-gradient(135deg, #6d5efc 0%, #8b5cf6 55%, #c084fc 100%);
  --glass: rgba(21,24,36,.78);
  --shadow-lg: 0 18px 50px rgba(0,0,0,.55), 0 2px 8px rgba(0,0,0,.35);
  --ease: cubic-bezier(.2,.8,.2,1);
}
body { background: radial-gradient(1200px 600px at 50% -10%, rgba(109,94,252,.10), transparent 60%), var(--bg); }
::selection { background: rgba(109,94,252,.45); }
* { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.18) transparent; }
:focus-visible { outline: 2px solid var(--brand-h); outline-offset: 2px; }

/* buttons */
.btn { border-radius: 10px; transition: background .18s var(--ease), border-color .18s var(--ease), transform .12s var(--ease), box-shadow .18s var(--ease); }
.btn:active, .tb-btn:active, .stu-btn:active, .nav-btn:active { transform: scale(.95); }
.btn-primary, .btn-join, .draw-wide-btn { background: var(--brand-grad); border-color: transparent; color: #fff; box-shadow: 0 6px 20px rgba(109,94,252,.35); }
.btn-primary:hover, .btn-primary:focus-visible, .btn-join:hover, .btn-join:focus-visible { background: var(--brand-grad); filter: brightness(1.1); box-shadow: 0 8px 26px rgba(109,94,252,.5); }
.btn-join { border-radius: 14px; letter-spacing: .01em; }

/* top bar */
.page-room .topbar { background: var(--glass); border-bottom-color: rgba(255,255,255,.06); }
.class-name { letter-spacing: -.01em; }
.live-pill {
  display: inline-flex; align-items: center; gap: .35rem; flex: none;
  font-size: .72rem; font-weight: 700; color: #fecaca; letter-spacing: .02em;
  background: rgba(239,68,68,.14); border: 1px solid rgba(239,68,68,.35); border-radius: 999px; padding: .16rem .5rem .16rem .42rem;
  font-variant-numeric: tabular-nums;
}
.live-pill i { width: 7px; height: 7px; border-radius: 50%; background: #ef4444; animation: livePulse 1.6s ease-in-out infinite; }
.live-pill.paused { color: var(--muted); background: var(--surface2); border-color: var(--border); }
.live-pill.paused i { background: var(--muted); animation: none; }
@keyframes livePulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .45; transform: scale(.8); } }
.page-pill, .nav-btn, .stars-badge, .people-badge { transition: background .18s var(--ease), border-color .18s var(--ease); }

/* call buttons */
.av-btn { transition: background .2s var(--ease), color .2s var(--ease), box-shadow .2s var(--ease), transform .12s var(--ease); border: 1px solid var(--border); }
.av-btn:hover { background: #2a2f45; }
.av-btn.on { background: linear-gradient(135deg, #16a34a, #22c55e); box-shadow: 0 4px 16px rgba(34,197,94,.4); border-color: transparent; }
.av-btn.on:hover { background: linear-gradient(135deg, #16a34a, #22c55e); filter: brightness(1.08); }
#mic-btn.speaking { box-shadow: 0 0 0 3px rgba(34,197,94,.35), 0 0 0 7px rgba(34,197,94,.14), 0 4px 16px rgba(34,197,94,.4); }
.leave-btn { border-radius: 50%; width: 36px; height: 36px; background: rgba(239,68,68,.12); border: 1px solid rgba(239,68,68,.3); }
.leave-btn:hover, .leave-btn:focus-visible { background: #ef4444; color: #fff; }

/* tool bar */
.float-toolbar, .student-toolbar {
  background: var(--glass); border-color: rgba(255,255,255,.1);
  backdrop-filter: blur(18px) saturate(160%); -webkit-backdrop-filter: blur(18px) saturate(160%);
  box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255,255,255,.05);
}
.tb-btn, .stu-btn { transition: background .16s var(--ease), color .16s var(--ease), border-color .16s var(--ease), transform .12s var(--ease), box-shadow .16s var(--ease); }
.tb-btn.tool.active, .stu-btn.tool.active, .size-btn.active, #board-btn.active {
  background: var(--brand-grad); color: #fff; border-color: transparent; box-shadow: 0 4px 14px rgba(109,94,252,.45);
}
.tb-btn.tool[data-tool="star"].active { background: linear-gradient(135deg, #f59e0b, #fbbf24); color: #fff; box-shadow: 0 4px 14px rgba(245,158,11,.45); }
.swatch, .stu-swatch { transition: transform .14s var(--ease), outline-color .14s var(--ease); }
.swatch.active, .stu-swatch.active { transform: scale(1.12); }

/* panels and cards */
.perm-panel, .people-panel, .share-panel, .chat-panel, .health-panel, .leave-bar, .sidebar {
  background: var(--glass); backdrop-filter: blur(20px) saturate(160%); -webkit-backdrop-filter: blur(20px) saturate(160%);
  border-color: rgba(255,255,255,.1); box-shadow: var(--shadow-lg);
}
.perm-panel:not([hidden]), .people-panel:not([hidden]), .share-panel:not([hidden]), .leave-bar:not([hidden]) { animation: panelIn .18s var(--ease); }
.health-panel:not([hidden]) { animation: fadeIn .16s ease; }
@keyframes panelIn { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: none; } }
.leave-bar:not([hidden]) { animation-name: fadeIn; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.perm-toggle { transition: background .16s var(--ease), border-color .16s var(--ease), color .16s var(--ease); border-radius: 10px; }
.card { border-radius: 16px; box-shadow: 0 10px 30px rgba(0,0,0,.25); }
.page-dashboard .topbar .brand span, .join-brand span { background: var(--brand-grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.list li { transition: background .16s var(--ease); border-radius: 8px; }

/* lesson page */
.page-wrap { border-radius: 6px; box-shadow: 0 10px 40px rgba(0,0,0,.6), 0 0 0 1px rgba(255,255,255,.05); }
.empty-state svg { opacity: .22; }
.av-tile { border-radius: 14px; border-color: rgba(255,255,255,.14); transition: border-color .2s var(--ease), box-shadow .2s var(--ease); }
.av-tile.speaking { box-shadow: 0 0 0 3px rgba(34,197,94,.35), 0 4px 18px rgba(0,0,0,.45); }
.av-tile-name { backdrop-filter: blur(6px); }

/* join and waiting screens */
.join-screen { background: radial-gradient(900px 500px at 50% -5%, rgba(109,94,252,.28), transparent 65%), radial-gradient(600px 400px at 85% 100%, rgba(192,132,252,.12), transparent 60%), var(--bg); }
.join-card { border-radius: 20px; border-color: rgba(255,255,255,.1); background: linear-gradient(180deg, rgba(31,35,51,.92), rgba(21,24,36,.96)); box-shadow: 0 30px 80px rgba(0,0,0,.6), inset 0 1px 0 rgba(255,255,255,.06); animation: panelIn .35s var(--ease); }
.join-card input { border-radius: 12px; min-height: 48px; font-size: 1rem; }
.join-card input:focus { border-color: var(--brand-h); box-shadow: 0 0 0 4px rgba(109,94,252,.22); outline: none; }

/* notices */
.toast {
  background: rgba(17,19,30,.94); border: 1px solid rgba(255,255,255,.12); border-radius: 14px;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); box-shadow: var(--shadow-lg);
}
.toast:not([hidden]) { animation: panelIn .22s var(--ease); }
.tip {
  position: fixed; z-index: 200; pointer-events: none; max-width: 260px;
  background: #0a0c12; color: #f1f3f9; border: 1px solid rgba(255,255,255,.14); border-radius: 8px;
  font-size: .74rem; font-weight: 500; line-height: 1.3; padding: .32rem .55rem; box-shadow: 0 8px 24px rgba(0,0,0,.5);
  animation: fadeIn .12s ease;
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* Panels sit on top of white lesson pages: keep them solid enough to read
   (see-through glass let the page's letters show through as dark smudges). */
.perm-panel, .people-panel, .share-panel, .chat-panel, .health-panel, .leave-bar, .sidebar { background: rgba(19,22,33,.975); }
.float-toolbar, .student-toolbar { background: rgba(19,22,33,.93); }
/* Chat bubbles: your own messages in the brand colour, others on a clear grey */
.chat-msg.me .chat-msg-bubble { background: var(--brand-grad); color: #fff; }
.chat-msg.other .chat-msg-bubble { background: #262b3f; color: var(--ink); border: 1px solid rgba(255,255,255,.06); }
.chat-msg-name.tutor { color: var(--brand-h); }
.chat-input:focus { border-color: var(--brand-h); box-shadow: 0 0 0 3px rgba(109,94,252,.22); outline: none; }

.leave-bar { flex-wrap: wrap; justify-content: center; max-width: calc(100vw - 16px); white-space: normal; }

/* recording mark */
.rec-pill {
  display: inline-flex; align-items: center; gap: .3rem; flex: none; font-size: .68rem; font-weight: 800; letter-spacing: .06em;
  color: #fff; background: #dc2626; border-radius: 6px; padding: .16rem .42rem;
}
.rec-pill i { width: 7px; height: 7px; border-radius: 50%; background: #fff; animation: livePulse 1.2s ease-in-out infinite; }

/* ─── Admin panel and reports ─────────────────────────────────────── */
.container.wide { max-width: 1240px; }
.admin-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; }
.admin-head h1 { font-size: 1.5rem; letter-spacing: -.02em; }
.period { font-size: .85rem; color: var(--muted); display: flex; align-items: center; gap: .5rem; }
.period select, .report-search, .small-select, .report select, .admin-panel .row select {
  background: var(--surface2); border: 1px solid var(--border); color: var(--ink);
  border-radius: 10px; padding: .5rem .65rem; font: inherit; font-size: .88rem; color-scheme: dark;
}
.tabs { display: flex; gap: .3rem; overflow-x: auto; padding: .3rem; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; scrollbar-width: none; }
.tab { border: none; background: transparent; color: var(--muted); font: inherit; font-size: .9rem; font-weight: 600; padding: .55rem 1rem; border-radius: 10px; cursor: pointer; white-space: nowrap; transition: background .16s, color .16s; }
.tab:hover { color: var(--ink); background: var(--surface2); }
.tab.active { background: var(--brand-grad); color: #fff; box-shadow: 0 4px 14px rgba(109,94,252,.4); }
.admin-panel { min-height: 320px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .8rem; margin-bottom: 1rem; }
.stat { background: var(--surface2); border: 1px solid var(--border); border-radius: 14px; padding: 1rem 1.1rem; display: flex; flex-direction: column; gap: .15rem; }
.stat b { font-size: 1.9rem; letter-spacing: -.03em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat span { font-size: .86rem; font-weight: 600; }
.stat small { font-size: .74rem; color: var(--muted); min-height: 1em; }
.stat.live { border-color: rgba(34,197,94,.45); background: linear-gradient(180deg, rgba(34,197,94,.14), var(--surface2)); }
.stat.live b { color: #4ade80; }
.report-bar { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin-bottom: .7rem; }
.report-search { flex: 1 1 260px; min-width: 0; }
.table-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; }
.table.report { font-size: .85rem; }
.table.report th { position: sticky; top: 0; background: var(--surface2); white-space: nowrap; font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; padding: .6rem .7rem; }
.table.report td { padding: .6rem .7rem; vertical-align: middle; }
.table.report tbody tr:hover td { background: rgba(255,255,255,.025); }
.table.report tr:first-child td { border-top: none; }
.btn-small { padding: .35rem .7rem; font-size: .8rem; border-radius: 8px; white-space: nowrap; }
.tag { display: inline-block; white-space: nowrap; }
.tag.ok { color: #4ade80; border-color: rgba(34,197,94,.4); }
.tag.live { color: #fff; background: #16a34a; border-color: transparent; }
.tag.role-superadmin { color: #f0abfc; border-color: rgba(240,171,252,.45); }
.tag.role-admin { color: #a5b4fc; border-color: rgba(165,180,252,.45); }
.tag.role-supervisor { color: #fcd34d; border-color: rgba(252,211,77,.45); }
.tag.role-teacher { color: #7dd3fc; border-color: rgba(125,211,252,.4); }
.role-badge { font-size: .72rem; font-weight: 700; border-radius: 999px; padding: .2rem .65rem; border: 1px solid var(--border); white-space: nowrap; }
.role-badge.role-superadmin { color: #f0abfc; border-color: rgba(240,171,252,.5); background: rgba(240,171,252,.1); }
.role-badge.role-admin { color: #a5b4fc; border-color: rgba(165,180,252,.5); background: rgba(165,180,252,.1); }
.role-badge.role-supervisor { color: #fcd34d; border-color: rgba(252,211,77,.5); background: rgba(252,211,77,.08); }
.role-badge.role-teacher { color: #7dd3fc; border-color: rgba(125,211,252,.5); background: rgba(125,211,252,.08); }
.player-row td { background: rgba(109,94,252,.08) !important; }
.player { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.player audio { flex: 1 1 320px; min-width: 240px; height: 40px; color-scheme: dark; }
.page-admin .topbar-right { flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 640px) { .admin-head h1 { font-size: 1.2rem; } .stat b { font-size: 1.5rem; } .page-dashboard .topbar { flex-wrap: wrap; gap: .5rem; } }

/* recording player: whose voice to hear */
.seg { display: inline-flex; border: 1px solid var(--line, rgba(255,255,255,.14)); border-radius: 10px; overflow: hidden; }
.seg-btn { background: transparent; color: inherit; border: 0; padding: .45rem .8rem; font: inherit; font-size: .85rem; cursor: pointer; }
.seg-btn + .seg-btn { border-left: 1px solid var(--line, rgba(255,255,255,.14)); }
.seg-btn.on { background: rgba(109,94,252,.9); color: #fff; }

/* supervision */
.sup-pill { display: inline-flex; align-items: center; padding: .18rem .55rem; border-radius: 999px; font-size: .68rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: #ffd98a; background: rgba(255,186,73,.14); border: 1px solid rgba(255,186,73,.35); white-space: nowrap; }
body.observer #mic-btn, body.observer #cam-btn, body.observer #screen-btn, body.observer #hand-btn, body.observer #chat-input, body.observer #chat-send, body.observer #draw-btn, body.observer .tools, body.observer #toolbar { display: none !important; }
body.observer .sup-pill { color: #9fe6c0; background: rgba(56,201,138,.14); border-color: rgba(56,201,138,.4); }

/* sessions report and lesson film */
.section-title { margin: 1.2rem 0 .6rem; font-size: 1rem; }
.live-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: .8rem; margin-bottom: 1rem; }
.live-card { display: flex; flex-direction: column; gap: .45rem; padding: .9rem 1rem; border-radius: 14px; background: rgba(56,201,138,.07); border: 1px solid rgba(56,201,138,.3); }
.live-head { display: flex; justify-content: space-between; align-items: center; gap: .6rem; }
.live-people { display: flex; flex-direction: column; gap: .2rem; padding: .4rem 0; border-top: 1px solid rgba(255,255,255,.08); }
.live-person { display: flex; justify-content: space-between; gap: .8rem; }
.live-card .btn { align-self: flex-start; text-decoration: none; }
.chips { display: flex; flex-wrap: wrap; gap: .25rem; }
.chip { padding: .1rem .45rem; border-radius: 999px; font-size: .72rem; background: rgba(109,94,252,.18); border: 1px solid rgba(109,94,252,.4); white-space: nowrap; }
.warn { color: #ffb3a8; }
.film { margin-bottom: .8rem; text-align: center; }
.film-img { max-width: 100%; max-height: 62vh; border-radius: 10px; background: #fff; border: 1px solid rgba(255,255,255,.14); }
.film-cap { margin-top: .3rem; }

#panel { overflow-x: auto; }

/* blocked words */
.word-form { display: flex; gap: .6rem; flex-wrap: wrap; margin-bottom: .4rem; }
.word-form .input { flex: 1 1 260px; }
.word-list { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .6rem; }
.word { display: inline-flex; align-items: center; gap: .35rem; padding: .25rem .3rem .25rem .7rem; border-radius: 999px; background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.14); }
.word-off { opacity: .55; text-decoration: line-through; }
.word-x { background: rgba(255,255,255,.08); color: inherit; border: 0; border-radius: 999px; padding: .1rem .5rem; font: inherit; font-size: .75rem; cursor: pointer; }
.word-x:hover { background: rgba(109,94,252,.6); }

/* ─── Light, warm look for the dashboard, login and admin pages ───────────── */
html:not(.dark) body.page-dashboard {
  --bg: #f7f5f0; --surface: #ffffff; --surface2: #f2efe8; --border: rgba(40,32,20,.13);
  --ink: #232830; --muted: #6a6f7b; --brand: #0f766e; --brand-h: #0d9488; --line: rgba(40,32,20,.13);
  background: #f7f5f0; color: var(--ink);
}
html:not(.dark) body.page-dashboard .btn-primary, html:not(.dark) body.page-dashboard .tab.active, html:not(.dark) body.page-dashboard .seg-btn.on { background: #0f766e !important; background-image: none !important; color: #fff !important; box-shadow: 0 1px 2px rgba(15,118,110,.25) !important; border-color: #0f766e !important; }
html:not(.dark) body.page-dashboard .btn-primary:hover { background: #0b5f59 !important; }
html:not(.dark) body.page-dashboard .card, html:not(.dark) body.page-dashboard .panel, html:not(.dark) body.page-dashboard #panel, html:not(.dark) body.page-dashboard .tabs, html:not(.dark) body.page-dashboard .stat, html:not(.dark) body.page-dashboard .topbar, html:not(.dark) body.page-dashboard header {
  background: #fff !important; background-image: none !important; border-color: var(--border) !important; box-shadow: 0 1px 2px rgba(40,32,20,.05), 0 8px 24px rgba(40,32,20,.04) !important; backdrop-filter: none !important; color: var(--ink);
}
html:not(.dark) body.page-dashboard .btn, html:not(.dark) body.page-dashboard .input, html:not(.dark) body.page-dashboard input, html:not(.dark) body.page-dashboard select, html:not(.dark) body.page-dashboard textarea { background: #fff; color: var(--ink); border-color: rgba(40,32,20,.2); }
html:not(.dark) body.page-dashboard input::placeholder { color: #9a9ea8; }
html:not(.dark) body.page-dashboard .tab { color: #4b5160; }
html:not(.dark) body.page-dashboard .table th, html:not(.dark) body.page-dashboard table.report th { background: #f2efe8 !important; color: #5a5f6b !important; }
html:not(.dark) body.page-dashboard .table td, html:not(.dark) body.page-dashboard table.report td { border-color: rgba(40,32,20,.09) !important; color: var(--ink); }
html:not(.dark) body.page-dashboard table.report, html:not(.dark) body.page-dashboard .table { border-color: var(--border) !important; background: #fff; }
html:not(.dark) body.page-dashboard .muted, html:not(.dark) body.page-dashboard .small.muted { color: var(--muted) !important; }
html:not(.dark) body.page-dashboard a { color: #0f766e; }
html:not(.dark) body.page-dashboard .player-row td { background: #f2f7f6 !important; }
html:not(.dark) body.page-dashboard .player audio { color-scheme: light; }
html:not(.dark) body.page-dashboard .live-card { background: #f0f8f5; border-color: rgba(15,118,110,.3); }
html:not(.dark) body.page-dashboard .live-people { border-top-color: rgba(40,32,20,.1); }
html:not(.dark) body.page-dashboard .chip { background: #e6f2f0; border-color: rgba(15,118,110,.3); color: #0b5f59; }
html:not(.dark) body.page-dashboard .word { background: #f2efe8; border-color: var(--border); }
html:not(.dark) body.page-dashboard .word-x { background: rgba(40,32,20,.08); }
html:not(.dark) body.page-dashboard .word-x:hover { background: #0f766e; color: #fff; }
html:not(.dark) body.page-dashboard .warn { color: #b42318; }
html:not(.dark) body.page-dashboard .film-img { border-color: var(--border); }
html:not(.dark) body.page-dashboard h1, html:not(.dark) body.page-dashboard h2, html:not(.dark) body.page-dashboard h3, html:not(.dark) body.page-dashboard strong, html:not(.dark) body.page-dashboard b { color: #1a1e26; }
/* students in the sessions table: one tidy line each */
table.report td .small { line-height: 1.45; }
table.report th, table.report td { vertical-align: top; }
html:not(.dark):has(html:not(.dark) body.page-dashboard) { background: #f7f5f0; }
body.page-dashboard { min-height: 100vh; display: flex; flex-direction: column; }
body.page-dashboard > main { flex: 1 0 auto; width: 100%; }
html:not(.dark) body.page-dashboard .topbar .brand span { background: none; -webkit-background-clip: border-box; background-clip: border-box; color: #0f766e; }
html:not(.dark) body.page-dashboard .role-badge { background: #f2efe8; border-color: rgba(40,32,20,.2); color: #4b5160; }
html:not(.dark) body.page-dashboard .role-badge.role-superadmin { color: #86198f; background: #fbeafd; border-color: #e9b8ef; }
html:not(.dark) body.page-dashboard .role-badge.role-admin { color: #3730a3; background: #eceefd; border-color: #c3c8f5; }
html:not(.dark) body.page-dashboard .role-badge.role-supervisor { color: #92400e; background: #fdf3d9; border-color: #efd28a; }
html:not(.dark) body.page-dashboard .role-badge.role-teacher { color: #075985; background: #e3f3fb; border-color: #a9d6ee; }
html:not(.dark) body.page-dashboard .tab { transition: none; }

/* footer: service status and the light / dark switch */
.site-footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: .4rem 1.2rem; padding: 1rem; margin-top: 1.5rem; font-size: .8rem; color: var(--muted); border-top: 1px solid var(--border); }
.site-footer .st { display: inline-flex; align-items: center; gap: .4rem; }
.site-footer .st i { width: 8px; height: 8px; border-radius: 50%; background: #9aa0aa; }
.site-footer .st.ok i { background: #16a34a; } .site-footer .st.bad i { background: #dc2626; }
.site-footer button { font: inherit; color: inherit; background: transparent; border: 1px solid var(--border); border-radius: 999px; padding: .25rem .8rem; cursor: pointer; }
.site-footer button:hover { color: var(--ink); border-color: var(--muted); }

/* API keys */
.key-new { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; padding: .8rem 1rem; margin: .6rem 0; border-radius: 12px; border: 1px solid rgba(15,118,110,.4); background: rgba(15,118,110,.08); }
.key-new strong { flex: 1 1 100%; }
.key-box { flex: 1 1 320px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85rem; }

.limit-input { width: 7rem; }

/* open classes */
.join-teacher { display: flex; align-items: center; gap: .5rem; margin: .2rem 0 .8rem; font-size: .92rem; cursor: pointer; }
.join-teacher input, .open-opt input { width: 1.05rem; height: 1.05rem; }
.open-opt { display: inline-flex; align-items: center; gap: .4rem; font-size: .88rem; white-space: nowrap; cursor: pointer; }

/* ─── Call bar: bottom centre, round buttons, red means off or leave ───────── */
.call-bar {
  position: fixed; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 40;
  display: flex; align-items: center; gap: .55rem; padding: .5rem .65rem; border-radius: 999px;
  background: #20242c; border: 1px solid rgba(255,255,255,.08); box-shadow: 0 10px 30px rgba(0,0,0,.45);
  max-width: calc(100vw - 16px);
}
.call-bar > button {
  width: 46px; height: 46px; min-width: 46px; padding: 0; margin: 0; border-radius: 50%; border: 0; flex: none;
  display: inline-flex; align-items: center; justify-content: center; position: relative;
  background: #3b414d; color: #fff; cursor: pointer; transition: background .15s, transform .1s; box-shadow: none; opacity: 1;
}
.call-bar > button:hover { background: #4a5160; }
.call-bar > button:active { transform: scale(.95); }
.call-bar > button svg { width: 21px; height: 21px; }
/* microphone and camera: plain when on, red when off */
.call-bar #mic-btn.on, .call-bar #cam-btn.on { background: #3b414d; }
.call-bar #mic-btn:not(.on), .call-bar #cam-btn:not(.on) { background: #d93f3f; }
.call-bar #mic-btn:not(.on):hover, .call-bar #cam-btn:not(.on):hover { background: #e25555; }
.call-bar #screen-btn.on { background: #1a9a8f; }
.call-bar .av-btn.blocked { opacity: .5; }
.call-bar .btn-hand { font-size: 1.25rem; }
.call-bar .btn-hand span { display: none; }
.call-bar #leave-btn { width: 62px; min-width: 62px; border-radius: 999px; background: #d93f3f; margin-left: .35rem; }
.call-bar #leave-btn:hover { background: #e25555; }
.call-bar #people-btn { gap: .2rem; font-size: .8rem; font-weight: 700; }
body.has-call-bar .viewer { padding-bottom: 84px; }
body.has-call-bar:not(.is-tutor) .call-bar { bottom: calc(var(--student-bar-h) + 10px); }
body.has-call-bar:not(.is-tutor) .viewer { padding-bottom: 76px; }
body.observer .call-bar #hand-btn { display: none !important; }
@media (max-width: 700px) {
  .call-bar { gap: .4rem; padding: .4rem .5rem; bottom: 8px; }
  .call-bar > button { width: 42px; height: 42px; min-width: 42px; }
  .call-bar #leave-btn { width: 54px; min-width: 54px; margin-left: .15rem; }
  /* the tutor's drawing tools are a strip along the bottom on a phone: the call bar sits just above it */
  body.has-call-bar.is-tutor .call-bar { bottom: calc(var(--student-bar-h) + 62px); }
  body.has-call-bar.is-tutor .viewer { padding-bottom: calc(var(--student-bar-h) + 120px); }
  body.has-call-bar:not(.is-tutor) .call-bar { bottom: calc(var(--student-bar-h) + 6px); }
}

body.is-tutor .call-bar #hand-btn { display: none !important; }
.btn-listen { display: block; width: 100%; margin-top: .6rem; padding: .7rem 1rem; border-radius: 12px; border: 1px solid var(--border); background: transparent; color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; }
.btn-listen:hover { background: var(--surface2); }

/* ─── Getting ready screen ─────────────────────────────────────────────────── */
.ready-card { max-width: 900px; display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: clamp(1rem, 3vw, 2rem); align-items: center; }
.ready-preview { position: relative; aspect-ratio: 4 / 3; border-radius: 16px; overflow: hidden; background: #12151c; border: 1px solid rgba(255,255,255,.08); }
.ready-preview video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); display: block; }
.ready-novideo { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .5rem; color: #8b93a5; font-size: .92rem; }
.ready-toggles { position: absolute; left: 0; right: 0; bottom: 14px; display: flex; justify-content: center; gap: .8rem; }
.ready-toggle { width: 52px; height: 52px; border-radius: 50%; border: 0; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; background: #d93f3f; color: #fff; transition: background .15s, transform .1s; }
.ready-toggle.on { background: #3b414d; }
.ready-toggle:hover { filter: brightness(1.12); } .ready-toggle:active { transform: scale(.95); }
.ready-level { position: absolute; left: 14px; right: 14px; top: 14px; height: 6px; border-radius: 3px; background: rgba(255,255,255,.14); overflow: hidden; }
.ready-level i { display: block; height: 100%; width: 0; border-radius: 3px; background: #34c98a; transition: width .06s linear; }
.ready-state { margin: .7rem 0 .5rem; font-size: .88rem; color: var(--muted); min-height: 1.3em; }
.ready-state.ok { color: #58d8a0; } .ready-state.bad { color: #ff9a8f; }
.ready-devices { display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-end; }
.ready-dev { display: flex; flex-direction: column; gap: .2rem; flex: 1 1 150px; min-width: 0; font-size: .74rem; color: var(--muted); }
.ready-dev select { width: 100%; min-width: 0; padding: .45rem .6rem; border-radius: 10px; border: 1px solid var(--border); background: var(--surface2); color: var(--ink); font: inherit; font-size: .85rem; text-overflow: ellipsis; }
.ready-test { flex: 0 0 auto; padding: .5rem .8rem; border-radius: 10px; border: 1px solid var(--border); background: transparent; color: var(--ink); font: inherit; font-size: .85rem; cursor: pointer; }
.ready-test:hover { background: var(--surface2); }
.ready-main .join-sub { margin-bottom: 1rem; }
@media (max-width: 760px) {
  .ready-card { grid-template-columns: 1fr; max-width: 440px; gap: 1rem; }
  .ready-main { order: 2; } .ready-side { order: 1; }
  .ready-preview { aspect-ratio: 16 / 10; }
}

.ready-novideo { padding-bottom: 64px; }

/* ─── Light look for the class page and the getting-ready screen (dark stays available) ─── */
html:not(.dark):has(body.page-room) { background: #f4f6f9; }
html:not(.dark) body.page-room {
  --bg: #f4f6f9; --surface: #ffffff; --surface2: #eef1f5; --border: rgba(20,30,50,.14);
  --ink: #1f2430; --muted: #5f6675; --brand: #0f766e; --brand-h: #0d9488;
  background: #f4f6f9; color: var(--ink);
}
html:not(.dark) body.page-room .join-screen { background: #f4f6f9; }
html:not(.dark) body.page-room .join-card { background: #fff; background-image: none; border-color: var(--border); box-shadow: 0 2px 6px rgba(20,30,50,.06), 0 18px 48px rgba(20,30,50,.10); }
html:not(.dark) body.page-room .join-card input, html:not(.dark) body.page-room .ready-dev select { background: #fff; color: var(--ink); border-color: rgba(20,30,50,.22); }
html:not(.dark) body.page-room .join-card input:focus { border-color: #0f766e; box-shadow: 0 0 0 4px rgba(15,118,110,.16); }
html:not(.dark) body.page-room .btn-join { background: #0f766e; background-image: none; color: #fff; box-shadow: 0 2px 6px rgba(15,118,110,.3); }
html:not(.dark) body.page-room .btn-join:hover { background: #0b5f59; }
html:not(.dark) body.page-room .join-brand svg circle { fill: #0f766e; }
html:not(.dark) body.page-room .ready-preview { background: #202631; border-color: transparent; }
html:not(.dark) body.page-room .ready-state.ok { color: #0b7a55; } html:not(.dark) body.page-room .ready-state.bad { color: #b42318; }
html:not(.dark) body.page-room .error { color: #b42318; }
/* inside the class */
html:not(.dark) body.page-room .topbar { background: #fff; border-bottom: 1px solid var(--border); color: var(--ink); box-shadow: none; backdrop-filter: none; }
html:not(.dark) body.page-room .viewer { background: #f4f6f9; }
html:not(.dark) body.page-room .float-toolbar, html:not(.dark) body.page-room .perm-panel, html:not(.dark) body.page-room .people-panel, html:not(.dark) body.page-room .chat-panel,
html:not(.dark) body.page-room .share-panel, html:not(.dark) body.page-room .health-panel, html:not(.dark) body.page-room .library-panel, html:not(.dark) body.page-room .sidebar, html:not(.dark) body.page-room .draw-panel {
  background: #fff !important; background-image: none !important; color: var(--ink); border-color: var(--border) !important; box-shadow: 0 2px 6px rgba(20,30,50,.06), 0 14px 36px rgba(20,30,50,.12) !important; backdrop-filter: none !important;
}
html:not(.dark) body.page-room .tb-btn { color: #3a4150; }
html:not(.dark) body.page-room .tb-btn:hover { background: #eef1f5; }
html:not(.dark) body.page-room .tb-btn.active, html:not(.dark) body.page-room .tb-btn[aria-pressed="true"]:not(.av-btn) { background: #0f766e; background-image: none; color: #fff; box-shadow: none; }
html:not(.dark) body.page-room .nav-btn, html:not(.dark) body.page-room .page-input-wrap, html:not(.dark) body.page-room #page-input { background: #eef1f5; color: var(--ink); border-color: var(--border); }
html:not(.dark) body.page-room .class-name, html:not(.dark) body.page-room .topbar strong { color: #1a1e26; }
html:not(.dark) body.page-room .student-bar { background: #fff; border-top: 1px solid var(--border); color: var(--muted); }
html:not(.dark) body.page-room .page-wrap { box-shadow: 0 1px 3px rgba(20,30,50,.10), 0 10px 30px rgba(20,30,50,.10); }
html:not(.dark) body.page-room .stars-badge { background: #fff7e0; border-color: #f2d48a; color: #8a5a00; }
html:not(.dark) body.page-room .sup-pill { color: #8a5a00; background: #fff4d6; border-color: #efd28a; }
html:not(.dark) body.page-room.observer .sup-pill { color: #0b7a55; background: #e3f6ee; border-color: #9fdcc3; }
html:not(.dark) body.page-room .chat-input, html:not(.dark) body.page-room input, html:not(.dark) body.page-room select { background: #fff; color: var(--ink); border-color: rgba(20,30,50,.2); }
html:not(.dark) body.page-room .empty-state, html:not(.dark) body.page-room .muted { color: var(--muted); }
html:not(.dark) body.page-room .toast { background: #1f2430; color: #fff; }
html:not(.dark) body.page-room .leave-bar { background: #fff; color: var(--ink); border-color: var(--border); box-shadow: 0 14px 36px rgba(20,30,50,.18); }
html:not(.dark) body.page-room .tb-sep { background: var(--border); }
/* the call bar: white, with soft grey buttons; red still means off or leave */
html:not(.dark) body.page-room .call-bar { background: #fff; border-color: var(--border); box-shadow: 0 2px 6px rgba(20,30,50,.08), 0 12px 32px rgba(20,30,50,.16); }
html:not(.dark) body.page-room .call-bar > button { background: #e9edf2; color: #2a303b; }
html:not(.dark) body.page-room .call-bar > button:hover { background: #dde2e9; }
html:not(.dark) body.page-room .call-bar #mic-btn.on, html:not(.dark) body.page-room .call-bar #cam-btn.on { background: #e9edf2; color: #2a303b; }
html:not(.dark) body.page-room .call-bar #mic-btn:not(.on), html:not(.dark) body.page-room .call-bar #cam-btn:not(.on), html:not(.dark) body.page-room .call-bar #leave-btn { background: #d93f3f; color: #fff; }
html:not(.dark) body.page-room .call-bar #screen-btn.on { background: #0f766e; color: #fff; }
html:not(.dark) body.page-room { --brand-grad: linear-gradient(#0f766e, #0f766e); }
html:not(.dark) body.page-room .float-toolbar .tb-btn.active, html:not(.dark) body.page-room .float-toolbar .tb-btn.on { box-shadow: none; }
html:not(.dark) body.page-room .people-panel button, html:not(.dark) body.page-room .perm-panel button { border-color: var(--border); }
html:not(.dark) body.page-room .timer-pill, html:not(.dark) body.page-room #live-timer, html:not(.dark) body.page-room .live-pill { color: #b42318; background: #fdecea; border-color: #f3b8b1; }

/* ─── Dashboard, login and admin: tidy on every screen size ─────────────────── */
body.page-dashboard > main { align-content: start; }
body.page-dashboard .container { width: 100%; margin: clamp(.8rem, 3vw, 1.5rem) auto; padding: 0 clamp(.75rem, 3vw, 1.25rem); }
/* login: a compact card in the middle of the space, never stretched */
.login-card { max-width: 420px; margin: clamp(1rem, 9vh, 5rem) auto 1rem; padding: clamp(1.25rem, 5vw, 2rem); }
.login-card h1 { font-size: clamp(1.4rem, 5vw, 1.75rem); margin-bottom: .3rem; }
.login-sub { font-size: .9rem; margin-bottom: 1.2rem; line-height: 1.45; }
.login-form { display: grid; gap: .9rem; }
.login-form label { display: grid; gap: .3rem; font-size: .88rem; font-weight: 600; }
.login-form input { width: 100%; min-height: 46px; padding: .6rem .8rem; border-radius: 10px; border: 1px solid var(--border); font: inherit; font-size: 1rem; background: var(--surface); color: var(--ink); }
.login-form input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px rgba(15,118,110,.16); }
.login-form .btn { width: 100%; min-height: 46px; justify-content: center; font-size: 1rem; font-weight: 600; }
.login-form .error:empty { display: none; }
/* top bar wraps instead of overflowing */
body.page-dashboard .topbar { flex-wrap: wrap; gap: .4rem .6rem; height: auto; min-height: var(--topbar-h); padding: .45rem clamp(.75rem, 3vw, 1.25rem); }
body.page-dashboard .topbar-right { display: flex; align-items: center; flex-wrap: wrap; gap: .4rem; margin-left: auto; }
body.page-dashboard .topbar .btn { white-space: nowrap; }
/* forms: fields share a row on wide screens and stack on narrow ones */
body.page-dashboard form.row, body.page-dashboard .row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
body.page-dashboard form.row > input:not([type=checkbox]), body.page-dashboard form.row > select { flex: 1 1 180px; min-width: 0; min-height: 42px; }
body.page-dashboard form.row > .btn { flex: 0 0 auto; min-height: 42px; }
body.page-dashboard .card { padding: clamp(.9rem, 3vw, 1.25rem); min-width: 0; }
body.page-dashboard .list li { flex-wrap: wrap; gap: .4rem; }
/* admin: tabs slide sideways, tables scroll inside their own box */
body.page-dashboard .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: thin; }
body.page-dashboard .tab { flex: none; }
body.page-dashboard #panel { min-width: 0; }
body.page-dashboard table.report { min-width: 640px; }
body.page-dashboard .stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: .7rem; }
.site-footer { flex: none; }
@media (max-width: 640px) {
  body.page-dashboard form.row > input:not([type=checkbox]), body.page-dashboard form.row > select, body.page-dashboard form.row > .btn { flex: 1 1 100%; }
  body.page-dashboard .topbar .brand { font-size: 1rem; }
  body.page-dashboard #who { display: none; }
  body.page-dashboard .admin-head, body.page-dashboard .page-head { flex-direction: column; align-items: flex-start; gap: .5rem; }
  .site-footer { font-size: .74rem; gap: .3rem .8rem; padding: .8rem .6rem; }
  .word-form .btn, .word-form .input { flex: 1 1 100%; }
}
body.page-dashboard .container { grid-template-columns: minmax(0, 1fr); }
body.page-dashboard .container > *, body.page-dashboard #app-view { min-width: 0; max-width: 100%; }
body.page-dashboard input[type=checkbox] { width: 1.1rem; height: 1.1rem; min-height: 0; padding: 0; flex: none; border-radius: 4px; accent-color: #0f766e; }
body.page-dashboard input[type=file] { max-width: 100%; min-width: 0; }
body.page-dashboard .open-opt { flex: 1 1 auto; }
