/* ── AI Teacher Studio ── */
:root {
  --bg: #0e0a12;
  --surface: rgba(34, 24, 30, 0.85);
  --border: rgba(255, 168, 140, 0.12);
  --text: #f7f1ee;
  --muted: #a99a93;
  --accent: #fb7a5a;
  --accent-glow: rgba(251, 122, 90, 0.35);
  --cyan: #ffb84c;
  --pink: #ff7a6b;
  --radius: 16px;
  /* Chat rail width — scales up on wider screens so the conversation (the
     primary interaction before the tutor draws) isn't a cramped column. */
  --rail-w: clamp(360px, 30vw, 460px);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: Inter, system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* ── Layout: full-viewport app ── */
.app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  max-width: 100vw;
}

/* ── Top bar ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 1.2rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 10;
  overflow: hidden;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-shrink: 0;
}

.topbar-icon {
  width: 26px;
  height: 26px;
  color: var(--accent);
}

.topbar-title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.topbar-session {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.18rem;
  padding: 0 1rem;
}

.topbar-session-eyebrow {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--cyan);
}

.topbar-session-title {
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-session-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  font-size: 0.74rem;
  color: #c4d4ff;
}

.topbar-session-goal {
  font-size: 0.76rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-session-lesson {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem;
  font-size: 0.74rem;
  margin-top: 0.1rem;
}
.lesson-position {
  color: var(--cyan);
  font-weight: 600;
  white-space: nowrap;
}
.lesson-objectives {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-status {
  font-size: 0.8rem;
  color: var(--muted);
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  background: rgba(251, 122, 90, 0.1);
  border: 1px solid rgba(251, 122, 90, 0.2);
  white-space: nowrap;
}
.topbar-mobile-menu-toggle,
.topbar-mobile-menu {
  display: none;
}
/* Attention pulse for actionable errors (mic/STT). */
.topbar-status.status-alert {
  color: #ffd7cc;
  background: rgba(255, 80, 110, 0.18);
  border-color: var(--pink);
  animation: status-alert-pulse 0.9s ease-in-out 2;
}
@keyframes status-alert-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 80, 110, 0); }
  50% { box-shadow: 0 0 0 4px rgba(255, 80, 110, 0.28); }
}

/* ── Stage: split canvas + whiteboard ── */
.stage {
  position: relative;
  overflow: hidden;
  display: flex;
  background: radial-gradient(ellipse at 50% 40%, #141e40 0%, #090c18 70%);
}

/* Friendly placeholder shown in the empty stage before the tutor draws, so the
   large canvas area reads as "the whiteboard" rather than a void. Hidden by JS
   (appendChatRailTurn / canvas show) once real content appears. */
.stage-welcome {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 0.6rem;
  padding: 2rem;
  pointer-events: none;
  animation: chatIntroIn 0.5s ease both;
}
.stage-welcome[hidden] { display: none; }

/* Board focus mode: a single dock control collapses both teaching surfaces
   (animation canvas + whiteboard) so the conversation gets full width. The
   board auto-restores when the tutor produces a visual (revealBoard()).
   The rail drops from its fixed right-column overlay into the in-flow stage row
   so the topbar and dock (which holds the board toggle) stay visible. */
body.board-hidden .stage-welcome,
body.board-hidden .stage-canvas-wrap,
body.board-hidden .stage-whiteboard { display: none; }
body.board-hidden.chat-rail-enabled .app { padding-right: 0; }
body.board-hidden.chat-rail-enabled .chat-rail {
  position: static;
  flex: 1 1 auto;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

/* Animation takeover: the whiteboard is the lesson home; an illustration is an
   occasional full-screen moment laid over it. While active, the animation fills
   the stage (whiteboard hidden behind it) and a slim chat rail stays for the
   tutor to keep narrating — the student can hide it for full focus, and "Back
   to whiteboard" dismisses the takeover with the lesson exactly as it was. */
body.anim-takeover .stage-welcome,
body.anim-takeover .stage-whiteboard { display: none; }
body.anim-takeover.chat-rail-enabled .stage-canvas-wrap { flex: 1; max-height: none; }
body.anim-takeover.anim-chat-hidden .chat-rail { display: none; }
body.anim-takeover.anim-chat-hidden.chat-rail-enabled .app { padding-right: 0; }

.stage-welcome-icon {
  font-size: 2.4rem;
  filter: drop-shadow(0 0 18px rgba(251, 122, 90, 0.45));
  opacity: 0.9;
}
.stage-welcome-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
  opacity: 0.92;
}
.stage-welcome-text {
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--muted);
  max-width: 30rem;
}

.stage-canvas-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  transition: flex 0.35s ease;
}
/* The canvas + its overlays live in their own relative stage below the bar. */
.canvas-stage { position: relative; flex: 1; min-height: 0; }

/* Animation takeover bar (only meaningful while body.anim-takeover). */
.anim-takeover-bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.8rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.anim-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: var(--accent);
  color: #1a0f0c;
  border: none;
  border-radius: 9px;
  padding: 0.5rem 0.85rem;
  font-weight: 700;
  font-size: 0.82rem;
  cursor: pointer;
}
.anim-back-btn:hover { filter: brightness(1.06); }
.anim-bar-label { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.anim-bar-eyebrow { font-size: 0.6rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--gold); font-weight: 700; }
.anim-bar-title { font-size: 0.92rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.anim-bar-actions { margin-left: auto; display: flex; gap: 0.4rem; }
.anim-bar-ghost {
  background: var(--surface-2, rgba(255,255,255,0.05));
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 9px;
  padding: 0.45rem 0.7rem;
  font-size: 0.78rem;
  cursor: pointer;
}
.anim-bar-ghost:hover { border-color: var(--accent); color: var(--accent); }

.stage-canvas-wrap[hidden] { display: none; }

/* When canvas is hidden, whiteboard takes full width */
.stage-whiteboard:only-child,
.stage-canvas-wrap[hidden] ~ .stage-whiteboard {
  width: 100% !important;
  max-width: 100% !important;
  border-left: none;
}

.canvas {
  display: block;
  width: 100%;
  height: 100%;
  position: absolute;
  inset: 0;
}

.canvas-status {
  position: absolute;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.82rem;
  color: var(--muted);
  background: rgba(9, 12, 24, 0.7);
  backdrop-filter: blur(6px);
  padding: 0.35rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  pointer-events: none;
  z-index: 5;
  transition: opacity 0.3s;
}

.scene-controls {
  position: absolute;
  top: 3.7rem;
  right: 1rem;
  width: min(260px, calc(100% - 2rem));
  max-height: calc(100% - 5rem);
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
  border-radius: 16px;
  background: rgba(9, 12, 24, 0.62);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 168, 140, 0.22);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  z-index: 5;
  overflow: hidden;
}

.scene-controls[hidden] {
  display: none;
}

/* Header: title + collapse toggle (always visible). */
.scene-controls-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.7rem 0.9rem;
  cursor: grab;
  touch-action: none;
  flex: 0 0 auto;
}
.scene-controls-header-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-left: auto;
}
.scene-controls-header-actions:empty { display: none; }
.scene-controls-header-actions .scene-control-btn {
  width: auto;
  margin: 0;
  padding: 0.38rem 0.65rem;
  white-space: nowrap;
}
.scene-controls.dragging { cursor: grabbing; user-select: none; box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45); }
.scene-controls.dragging .scene-controls-header { cursor: grabbing; }
.scene-controls-toggle {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  color: #dfe8ff;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.scene-controls-toggle:hover { background: rgba(255, 255, 255, 0.12); }

/* Scrollable body — capped height so the panel never covers the whole scene. */
.scene-controls-body {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0 0.9rem 0.9rem;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* Collapsed: shrink to a compact "⚙ Parameters" pill so the sim is fully visible. */
.scene-controls.collapsed {
  width: auto;
  max-height: none;
  background: rgba(9, 12, 24, 0.72);
}
.scene-controls.collapsed .scene-controls-header { cursor: pointer; }
.scene-controls.collapsed .scene-controls-body { display: none; }

.scene-controls-title {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 700;
  color: #dfe8ff;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

/* On narrow screens, dock the panel to the bottom as a sheet. */
@media (max-width: 720px) {
  .scene-controls {
    top: auto;
    bottom: 0.75rem;
    left: 0.75rem;
    right: 0.75rem;
    width: auto;
    max-height: 40%;
  }
  .scene-controls.collapsed { left: auto; }
  .scene-controls-header { cursor: default; }
  .scene-controls-title { text-transform: none; }
}

.scene-control {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.scene-control-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.scene-control-label {
  font-size: 0.88rem;
  color: #eef3ff;
  font-weight: 600;
}

.scene-control-value {
  font-size: 0.8rem;
  color: #9fdfff;
  font-variant-numeric: tabular-nums;
}

.scene-control-slider {
  width: 100%;
  accent-color: #7f8dff;
}

.scene-control-btn {
  padding: 0.45rem 1rem;
  border: 1px solid rgba(251, 122, 90, 0.35);
  border-radius: 8px;
  background: rgba(251, 122, 90, 0.15);
  color: #dfe8ff;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.scene-control-btn:hover {
  background: rgba(251, 122, 90, 0.3);
  transform: translateY(-1px);
}
.scene-control-btn:active {
  transform: translateY(0);
}

.scene-control-select {
  width: 100%;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(251, 122, 90, 0.3);
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.82rem;
  padding: 0.35rem 0.5rem;
  outline: none;
  cursor: pointer;
}
.scene-control-select:focus {
  border-color: var(--accent);
}
.scene-control-select option {
  background: #0f1430;
  color: var(--text);
}

.scene-control-radio-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-top: 0.2rem;
}
.scene-control-radio-label,
.scene-control-checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  color: #c4d4ff;
  cursor: pointer;
}
.scene-control-radio-label input,
.scene-control-checkbox-label input {
  accent-color: #7f8dff;
  cursor: pointer;
}

.metrics-bar {
  position: absolute;
  bottom: 0.75rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  justify-content: center;
  z-index: 5;
  pointer-events: none;
}

.dynamic-metric-chip {
  padding: 0.28rem 0.6rem;
  border-radius: 999px;
  background: rgba(9, 12, 24, 0.65);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 168, 140, 0.2);
  color: #d4dfff;
  font-size: 0.78rem;
  font-weight: 500;
}

/* ── Dock: bottom controls ── */
.dock {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  padding: 0.75rem 1.2rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 10;
}

.dock-voice-select {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.4rem 0.5rem;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s, color 0.15s;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238a96c0'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
  padding-right: 1.4rem;
}
.dock-voice-select:hover {
  border-color: rgba(251, 122, 90, 0.4);
  color: var(--text);
}
.dock-voice-select:focus {
  border-color: var(--accent);
}
.dock-voice-select option {
  background: #0f1430;
  color: var(--text);
}

.dock-btn {
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: transform 0.15s, box-shadow 0.2s, background 0.2s;
}

.dock-btn:active { transform: scale(0.92); }
.dock-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.dock-btn svg {
  width: 22px;
  height: 22px;
}

/* Start button */
.start-btn {
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, var(--accent), var(--cyan));
  color: #fff;
  box-shadow: 0 4px 18px var(--accent-glow);
}

.start-btn:hover:not(:disabled) {
  box-shadow: 0 6px 28px var(--accent-glow);
  transform: scale(1.06);
}

/* Mic button */
.mic-btn {
  width: 60px;
  height: 60px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
  border: 2px solid rgba(255, 255, 255, 0.12);
  flex-direction: column;
  gap: 0.15rem;
}

.mic-btn .mic-label {
  font-size: 0.55rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.mic-btn .mic-icon {
  width: 24px;
  height: 24px;
}

.mic-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.22);
}

/* Connected state — recording indicator with audio-level glow */
.mic-btn.connected {
  background: rgba(255, 80, 110, 0.15);
  border-color: var(--pink);
  color: #fff;
  box-shadow:
    0 0 0 calc(4px + 12px * var(--mic-level, 0)) rgba(255, 80, 110, calc(0.12 + 0.2 * var(--mic-level, 0))),
    0 0 calc(20px + 30px * var(--mic-level, 0)) rgba(255, 80, 110, calc(0.15 + 0.25 * var(--mic-level, 0)));
  transition: box-shadow 0.08s ease-out, background 0.2s, border-color 0.2s;
}

.mic-btn.connected .mic-icon { display: none; }
.mic-btn.connected::before {
  content: "";
  width: 18px;
  height: 18px;
  border-radius: 3px;
  background: var(--pink);
}

.mic-btn.connected .mic-label { color: var(--pink); }

/* Tutor is speaking (TTS): the mic pulses amber to signal "tap to interrupt". */
body.tutor-speaking .mic-btn:not(.connected) {
  border-color: var(--accent, #fb7a5a);
  color: #fff;
  animation: mic-interrupt-pulse 1.3s ease-in-out infinite;
}
body.tutor-speaking .mic-btn:not(.connected) .mic-label { color: var(--accent, #fb7a5a); }
@keyframes mic-interrupt-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(251, 122, 90, 0.0); }
  50% { box-shadow: 0 0 0 6px rgba(251, 122, 90, 0.28); }
}

/* Live transcript overlay */
.dock-transcript {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  max-width: 680px;
  width: min(92vw, 680px);
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  padding-bottom: 0.45rem;
}

.dock-transcript[hidden] {
  display: none;
}

.dock-transcript-history {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: stretch;
}

.dock-turn {
  max-width: min(100%, 560px);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.7rem 0.85rem;
  border-radius: 16px;
  border: 1px solid rgba(255, 168, 140, 0.14);
  background: rgba(9, 12, 24, 0.84);
  backdrop-filter: blur(10px);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.22);
}

.dock-turn.student {
  align-self: flex-end;
  background: rgba(255, 184, 76, 0.1);
  border-color: rgba(255, 184, 76, 0.22);
}

.dock-turn.teacher {
  align-self: flex-start;
}

.dock-turn-role {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.dock-turn.student .dock-turn-role {
  color: var(--cyan);
}

.dock-turn-text {
  font-size: 0.88rem;
  line-height: 1.45;
  color: rgba(238, 243, 255, 0.92);
  white-space: pre-wrap;
  word-break: break-word;
}

.dock-turn-attachment {
  align-self: flex-start;
  font-size: 0.72rem;
  font-weight: 600;
  color: #d9e5ff;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  padding: 0.18rem 0.5rem;
}

.wb-clear-btn.has-pending {
  background: rgba(251, 122, 90, 0.16);
  color: var(--accent);
  border: 1px solid rgba(251, 122, 90, 0.28);
}

.wb-clear-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ── Whiteboard side panel ── */
.stage-whiteboard {
  width: 40%;
  max-width: 70%;
  min-width: 220px;
  display: flex;
  flex-direction: column;
  background: rgba(12, 16, 38, 0.96);
  border-left: 1px solid rgba(251, 122, 90, 0.18);
  box-shadow: -8px 0 30px rgba(0, 0, 0, 0.35);
  animation: wb-slide-in 0.3s ease-out;
  z-index: 6;
  position: relative;
}
.stage-whiteboard[hidden] { display: none; }

/* Drag handle for resizing */
.wb-drag-handle {
  position: absolute;
  left: -4px;
  top: 0;
  bottom: 0;
  width: 8px;
  cursor: col-resize;
  z-index: 10;
  background: transparent;
  transition: background 0.15s;
}
.wb-drag-handle:hover,
.wb-drag-handle.dragging {
  background: rgba(251, 122, 90, 0.35);
}

/* Toggle button in dock */
.wb-toggle-btn {
  width: 42px;
  height: 42px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  border: 1px solid rgba(255, 255, 255, 0.1);
}
.wb-toggle-btn svg { width: 18px; height: 18px; }
.wb-toggle-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
}
.wb-toggle-btn.active {
  background: rgba(251, 122, 90, 0.15);
  border-color: rgba(251, 122, 90, 0.35);
  color: var(--accent);
}

/* Mode toggle — a labeled pill so the current conversation mode is always
   visible (Text vs Live), not a mystery icon. */
.mode-toggle-btn {
  height: 42px;
  padding: 0 12px 0 10px;
  gap: 6px;
  border-radius: 21px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  border: 1px solid rgba(255, 255, 255, 0.1);
}
.mode-toggle-btn svg { width: 18px; height: 18px; }
.mode-toggle-btn .mode-label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.mode-toggle-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
}
/* Active = Text mode; inactive (live voice) uses a distinct accent so the two
   states read differently at a glance. */
.mode-toggle-btn.active {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.16);
  color: var(--text);
}
.mode-toggle-btn:not(.active) {
  background: rgba(251, 122, 90, 0.16);
  border-color: rgba(251, 122, 90, 0.4);
  color: var(--accent);
}

@keyframes wb-slide-in {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.wb-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid rgba(251, 122, 90, 0.12);
  flex-shrink: 0;
}
.wb-title {
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.whiteboard-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.2rem 1.4rem;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 1.05rem;
  line-height: 1.75;
  color: #e8efff;
}
.whiteboard-content .wb-heading {
  display: block;
  font-size: 1.3rem;
  font-weight: 700;
  color: #fb7a5a;
  margin: 0.9rem 0 0.35rem;
}
.whiteboard-content .wb-heading:first-child { margin-top: 0; }
.whiteboard-content .wb-hr {
  border: none;
  border-top: 1px solid rgba(255, 255, 255, 0.18);
  margin: 0.8rem 0;
}
.whiteboard-content .wb-bullet {
  display: block;
  padding-left: 1.2rem;
  position: relative;
  margin: 0.15rem 0;
}
.whiteboard-content .wb-bullet::before {
  content: '\2022';
  position: absolute;
  left: 0;
  color: #ffb84c;
  font-weight: 700;
}
.whiteboard-content .wb-math-block {
  display: block;
  text-align: center;
  margin: 0.6rem 0;
  padding: 0.5rem 0;
}
.whiteboard-content .wb-math-inline { display: inline; }
.whiteboard-content strong {
  font-weight: 700;
  color: #a8bfff;
}
.whiteboard-content em {
  font-style: italic;
  color: #c4d4ff;
}
.whiteboard-content .wb-text-line {
  display: block;
  margin: 0.1rem 0;
}
.whiteboard-content .katex { color: #ffb84c; font-size: 1.2em; }
.whiteboard-content .wb-math-block .katex { font-size: 1.45em; }

.whiteboard-content .wb-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.6rem 0;
  font-size: 0.95rem;
}
.whiteboard-content .wb-table td,
.whiteboard-content .wb-table th {
  padding: 0.4rem 0.75rem;
  border: 1px solid rgba(251, 122, 90, 0.25);
  color: #dfe8ff;
}
.whiteboard-content .wb-table tr:first-child td {
  font-weight: 700;
  color: #a8bfff;
  background: rgba(251, 122, 90, 0.1);
  border-bottom: 2px solid rgba(251, 122, 90, 0.35);
}
.whiteboard-content .wb-table tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.03);
}

.wb-cursor {
  display: inline-block;
  width: 2px;
  height: 1.1em;
  background: #fb7a5a;
  vertical-align: text-bottom;
  margin-left: 2px;
  animation: wb-blink 0.7s step-end infinite;
}
@keyframes wb-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* ── Student input area ── */
.wb-student-input {
  flex-shrink: 0;
  border-top: 1px solid rgba(251, 122, 90, 0.15);
  background: rgba(8, 12, 30, 0.6);
  padding: 0.6rem 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.wb-student-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.wb-student-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.wb-student-actions {
  display: flex;
  gap: 0.3rem;
}
.wb-upload-btn, .wb-clear-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: none;
  background: rgba(255,255,255,0.06);
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.wb-upload-btn svg, .wb-clear-btn svg { width: 15px; height: 15px; }
.wb-upload-btn:hover, .wb-clear-btn:hover {
  background: rgba(255,255,255,0.12);
  color: var(--text);
}
.wb-student-textarea {
  width: 100%;
  min-height: 50px;
  max-height: 140px;
  resize: vertical;
  border-radius: 8px;
  border: 1px solid rgba(255, 168, 140, 0.15);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  padding: 0.5rem 0.6rem;
  font-size: 0.88rem;
  font-family: inherit;
  line-height: 1.5;
  outline: none;
  transition: border-color 0.2s;
}
.wb-student-textarea::placeholder { color: rgba(255, 168, 140,0.35); }
.wb-student-textarea:focus { border-color: rgba(251, 122, 90, 0.45); }

.wb-image-preview {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid rgba(255, 168, 140, 0.15);
  max-height: 150px;
}
.wb-image-preview[hidden] { display: none; }
.wb-image-preview img {
  display: block;
  width: 100%;
  max-height: 150px;
  object-fit: contain;
  background: rgba(0,0,0,0.3);
}
.wb-image-preview .wb-img-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 0.8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.wb-image-preview::after {
  content: 'Attachment ready';
  position: absolute;
  left: 0.5rem;
  bottom: 0.5rem;
  padding: 0.18rem 0.45rem;
  border-radius: 999px;
  background: rgba(9, 12, 24, 0.82);
  border: 1px solid rgba(255, 168, 140, 0.16);
  color: #dfe8ff;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.03em;
}

/* ── Responsive ── */
@media (max-width: 640px) {
  .topbar {
    align-items: flex-start;
    gap: 0.5rem;
    flex-wrap: wrap;
    padding: 0.5rem 0.8rem;
  }
  .topbar-title { font-size: 0.92rem; }
  .topbar-session {
    order: 3;
    width: 100%;
    padding: 0;
  }
  /* Trim the verbose session block on phones so the topbar stays short and the
     stage gets the height. Keep the lesson title; drop meta + goal (the chat
     empty state already prompts the student). */
  .topbar-session-meta,
  .topbar-session-goal { display: none; }
  .topbar-session-eyebrow { font-size: 0.58rem; }
  .topbar-session-title { font-size: 0.98rem; line-height: 1.2; }
  .topbar-session-lesson { white-space: normal; }
  .lesson-objectives { white-space: normal; }
  .mic-btn { width: 52px; height: 52px; }
  .start-btn { width: 42px; height: 42px; }
  .stage { flex-direction: column; }
  .stage-whiteboard {
    width: 100%; max-width: 100%; max-height: 45%;
    border-left: none;
    border-top: 1px solid rgba(251, 122, 90, 0.18);
  }
  .whiteboard-content { padding: 0.8rem 1rem; font-size: 0.95rem; }
  /* Dock: let the controls wrap and shrink the voice picker so nothing is
     clipped or overlapped on a narrow screen. */
  .dock { gap: 0.45rem; padding: 0.55rem 0.7rem; flex-wrap: wrap; }
  .dock-voice-select { max-width: 92px; }
}

/* ── Whiteboard Quiz / Interactive HTML ── */
.wb-quiz {
  background: rgba(251, 122, 90, 0.06);
  border: 1px solid rgba(251, 122, 90, 0.2);
  border-radius: 10px;
  padding: 1rem 1.2rem;
  margin: 0.6rem 0;
}
.wb-quiz p { margin: 0.4rem 0; line-height: 1.6; }
.wb-quiz-title {
  font-size: 1rem;
  color: var(--cyan);
  margin-bottom: 0.5rem;
}
.whiteboard-content .wb-h2 {
  font-size: 1.05rem;
  font-weight: 700;
  opacity: 0.9;
}
.whiteboard-content .wb-h3 {
  font-size: 0.95rem;
  font-weight: 600;
  opacity: 0.85;
}
.whiteboard-content .wb-num {
  color: var(--accent);
  font-weight: 700;
}
.wb-quiz label {
  display: block;
  padding: 0.4rem 0.6rem;
  margin: 0.25rem 0;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
  line-height: 1.5;
}
.wb-quiz label:hover { background: rgba(251, 122, 90, 0.1); }
.wb-quiz input[type="radio"],
.wb-quiz input[type="checkbox"] {
  accent-color: var(--accent);
  margin-right: 0.5rem;
  transform: scale(1.15);
  vertical-align: middle;
}
.wb-input, .wb-select {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(251, 122, 90, 0.3);
  border-radius: 6px;
  color: var(--text);
  padding: 0.35rem 0.5rem;
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
  min-width: 80px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.wb-input:focus, .wb-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}
.wb-input::placeholder { color: rgba(255, 168, 140, 0.4); }
.wb-select option { background: #0f1430; color: var(--text); }
.wb-submit {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.6rem;
  padding: 0.5rem 1.2rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.wb-submit:hover { background: #5a78ff; transform: translateY(-1px); }
.wb-submit:active { transform: translateY(0); }
.wb-submit:disabled {
  background: rgba(251, 122, 90, 0.3);
  color: rgba(255, 255, 255, 0.6);
  cursor: default;
  transform: none;
}

/* ── Assessment panel ── */
.assessment-panel {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 26, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 1.5rem;
}
.assessment-panel[hidden] { display: none; }

.assessment-card {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 760px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 64px rgba(0,0,0,0.4);
  display: flex;
  flex-direction: column;
}

.assessment-header {
  padding: 1.75rem 2rem 1.25rem;
  border-bottom: 1px solid #e8eaed;
}

.assessment-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.assessment-eyebrow {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #7c3aed;
}

.assessment-timer {
  font-size: 0.875rem;
  font-weight: 700;
  color: #dc2626;
  font-variant-numeric: tabular-nums;
  background: #fef2f2;
  padding: 0.25rem 0.65rem;
  border-radius: 6px;
}

.assessment-lesson-title {
  font-size: 1.35rem;
  font-weight: 700;
  color: #111827;
  margin: 0 0 0.75rem;
}

.assessment-progress-bar {
  height: 6px;
  background: #e5e7eb;
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}
.assessment-progress-bar::after {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: #7c3aed;
  border-radius: 3px;
  width: var(--progress, 0%);
  transition: width 0.3s ease;
}

.assessment-progress-text {
  position: absolute;
  right: 0; top: -20px;
  font-size: 0.72rem;
  color: #6b7280;
}

.assessment-body {
  padding: 2rem;
  flex: 1;
}

.assessment-question {
  margin-bottom: 1.5rem;
}

.assessment-question-text {
  font-size: 1.1rem;
  font-weight: 600;
  color: #111827;
  margin-bottom: 1.25rem;
  line-height: 1.5;
}

.assessment-choices {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.assessment-choice-label {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  border: 2px solid #e5e7eb;
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  font-size: 0.95rem;
  color: #374151;
}

.assessment-choice-label:hover {
  border-color: #c4b5fd;
  background: #f5f3ff;
}

.assessment-choice-label input[type="radio"] {
  accent-color: #7c3aed;
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
}

.assessment-choice-label input[type="radio"]:checked + span {
  color: #5b21b6;
  font-weight: 600;
}

.assessment-choice-label:has(input:checked) {
  border-color: #7c3aed;
  background: #f5f3ff;
}

.assessment-short-answer {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 2px solid #e5e7eb;
  border-radius: 10px;
  font-size: 0.95rem;
  resize: vertical;
  min-height: 100px;
  font-family: inherit;
  color: #111827;
  transition: border-color 0.15s;
}

.assessment-short-answer:focus {
  outline: none;
  border-color: #7c3aed;
}

.assessment-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 2rem;
  border-top: 1px solid #e8eaed;
  gap: 1rem;
}
.assessment-nav[hidden] { display: none; }

.assessment-item-indicator {
  font-size: 0.875rem;
  color: #6b7280;
  font-weight: 500;
}

.assessment-btn {
  padding: 0.625rem 1.25rem;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  border: none;
  transition: opacity 0.15s, transform 0.1s;
  font-family: inherit;
}

.assessment-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none !important;
}

.assessment-btn:not(:disabled):active { transform: scale(0.97); }

.assessment-btn-primary {
  background: #7c3aed;
  color: #fff;
}
.assessment-btn-primary:not(:disabled):hover { background: #6d28d9; }

.assessment-btn-secondary {
  background: #f3f4f6;
  color: #374151;
}
.assessment-btn-secondary:not(:disabled):hover { background: #e5e7eb; }

.assessment-btn-submit {
  background: #059669;
  color: #fff;
}
.assessment-btn-submit:not(:disabled):hover { background: #047857; }

.assessment-result {
  padding: 2.5rem 2rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
}
.assessment-result[hidden] { display: none; }

.assessment-result-badge {
  font-size: 2.5rem;
  font-weight: 800;
  padding: 0.5rem 1.5rem;
  border-radius: 12px;
}

.assessment-result-badge.pass {
  background: #d1fae5;
  color: #065f46;
}

.assessment-result-badge.fail {
  background: #fee2e2;
  color: #7f1d1d;
}

.assessment-result-score {
  font-size: 1.5rem;
  font-weight: 700;
  color: #111827;
}

.assessment-result-feedback {
  width: 100%;
  text-align: left;
}

.assessment-feedback-item {
  padding: 0.875rem 1rem;
  border-radius: 8px;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

.assessment-feedback-item.correct {
  background: #d1fae5;
  color: #065f46;
}

.assessment-feedback-item.incorrect {
  background: #fee2e2;
  color: #7f1d1d;
}

.assessment-feedback-item-text {
  font-weight: 600;
  margin-bottom: 0.25rem;
}

/* ── Assignment panel ── */
.assignment-panel {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 26, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 1.5rem;
}
.assignment-panel[hidden] { display: none; }

.assignment-card {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 900px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.4);
}

.assignment-header {
  padding: 1.75rem 2rem 1.25rem;
  border-bottom: 1px solid #e8eaed;
}

.assignment-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.assignment-eyebrow {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #2563eb;
}

.assignment-timer {
  font-size: 0.875rem;
  font-weight: 700;
  color: #dc2626;
  font-variant-numeric: tabular-nums;
  background: #fef2f2;
  padding: 0.25rem 0.65rem;
  border-radius: 6px;
}

.assignment-title {
  font-size: 1.35rem;
  font-weight: 700;
  color: #111827;
  margin: 0 0 0.5rem;
}

.assignment-objectives {
  color: #6b7280;
  font-size: 0.95rem;
}

.assignment-body {
  padding: 2rem;
}

.assignment-prompt-text {
  background: #f8fafc;
  padding: 1rem;
  border-radius: 10px;
  margin-bottom: 1rem;
  line-height: 1.6;
  white-space: pre-wrap;
  color: #111827;
}

.assignment-reference {
  margin-bottom: 1rem;
  color: #111827;
}

.assignment-reference details,
.assignment-rubric-preview details {
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 0.85rem 1rem;
}

.assignment-reference .ref-text,
.assignment-reference .ref-material {
  padding: 0.75rem;
  background: #fff;
  border-left: 3px solid #4f46e5;
  margin-top: 0.75rem;
  color: #1f2937;
}

.assignment-response-area {
  margin: 1rem 0;
  color: #111827;
}

.assignment-response-area label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

#assignment-text-input {
  width: 100%;
  min-height: 220px;
  padding: 0.75rem;
  font-size: 1rem;
  line-height: 1.6;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  resize: vertical;
  color: #111827;
}

.assignment-actions {
  margin-bottom: 1rem;
}

.rubric-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  color: #111827;
  margin-top: 0.75rem;
}

.rubric-table th,
.rubric-table td {
  padding: 0.5rem;
  border: 1px solid #d1d5db;
  text-align: left;
}

.rubric-table th {
  background: #f3f4f6;
}

.assignment-result {
  color: #111827;
}

.result-pass h3 { color: #16a34a; }
.result-fail h3 { color: #dc2626; }
.result-narrative { margin: 1rem 0; }
.result-criteria,
.result-strengths,
.result-areas,
.result-suggestions { margin-top: 1rem; }
.spinner-text { text-align: center; padding: 2rem; font-size: 1.1rem; color: #111827; }
.result-pending { text-align: center; padding: 1rem; color: #d97706; }
#assignment-word-count { margin-top: 0.25rem; font-size: 0.85rem; color: #6b7280; }

/* ── Assignment file upload zone ── */
.assignment-file-zone { margin-bottom: 1rem; }
.file-drop-area {
  border: 2px dashed #d1d5db;
  border-radius: 0.75rem;
  padding: 1.5rem;
  text-align: center;
  transition: border-color 0.2s, background 0.2s;
  cursor: pointer;
}
.file-drop-area.drag-over {
  border-color: #6366f1;
  background: #eef2ff;
}
.file-drop-icon { font-size: 1.5rem; margin-bottom: 0.25rem; }
.file-drop-text { font-size: 0.95rem; color: #374151; }
.file-browse-btn {
  background: none;
  border: none;
  color: #4f46e5;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  font-size: 0.95rem;
  padding: 0;
}
.file-drop-hint { font-size: 0.8rem; color: #9ca3af; margin-top: 0.25rem; }
.assignment-file-list { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.75rem; }
.assignment-file-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid #e5e7eb;
  border-radius: 0.5rem;
  background: #f9fafb;
  font-size: 0.9rem;
}
.assignment-file-item .file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.assignment-file-item .file-status { font-size: 0.8rem; color: #6b7280; }
.assignment-file-item .file-status.ready { color: #059669; }
.assignment-file-item .file-status.failed { color: #dc2626; }
.assignment-file-item .file-remove-btn {
  background: none;
  border: none;
  color: #9ca3af;
  cursor: pointer;
  font-size: 1rem;
  padding: 0 0.25rem;
  line-height: 1;
}
.assignment-file-item .file-remove-btn:hover { color: #dc2626; }
.file-error { color: #dc2626; font-size: 0.85rem; margin-top: 0.5rem; }

/* Lesson navigation drawer */
.topbar-drawer-toggle {
  background: none;
  border: none;
  color: var(--text, #fff);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  line-height: 1;
}
.topbar-drawer-toggle:hover { background: rgba(255,255,255,0.1); }

.lesson-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 340px;
  max-width: 90vw;
  height: 100vh;
  background: var(--bg, #fff);
  color: var(--text, #222);
  box-shadow: -4px 0 20px rgba(0,0,0,0.15);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s ease;
}
.lesson-drawer.open { transform: translateX(0); }
.lesson-drawer[hidden] { display: none; }

.lesson-drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 999;
}
.lesson-drawer-overlay[hidden] { display: none; }

.lesson-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border, #ddd);
}
.lesson-drawer-header h3 { margin: 0; font-size: 1rem; }
.lesson-drawer-close {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  color: var(--text-secondary, #666);
}
.lesson-drawer-close:hover { background: var(--hover-bg, #f0f0f0); }

.lesson-drawer-progress {
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  color: var(--text-secondary, #666);
  border-bottom: 1px solid var(--border, #eee);
}
.lesson-drawer-progress-bar {
  height: 4px;
  background: var(--border, #ddd);
  border-radius: 2px;
  margin-top: 0.4rem;
  overflow: hidden;
}
.lesson-drawer-progress-fill {
  height: 100%;
  background: var(--accent, #4f6df5);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.lesson-drawer-list {
  list-style: none;
  padding: 0;
  margin: 0;
  flex: 1;
  overflow-y: auto;
}
.lesson-drawer-item {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border, #f0f0f0);
  cursor: pointer;
  transition: background 0.15s;
}
.lesson-drawer-item:hover { background: var(--hover-bg, #f5f5ff); }
.lesson-drawer-item.current { background: var(--accent-bg, #eef); border-left: 3px solid var(--accent, #4f6df5); }
.lesson-drawer-item.locked { opacity: 0.5; cursor: not-allowed; }
.lesson-drawer-item.locked:hover { background: none; }
.lesson-drawer-item.completed .drawer-item-icon { color: #22c55e; }

.drawer-item-icon { font-size: 1.1rem; min-width: 1.4rem; text-align: center; padding-top: 0.1rem; }
.drawer-item-body { flex: 1; min-width: 0; }
.drawer-item-title { font-size: 0.9rem; font-weight: 500; }
.drawer-item-meta {
  font-size: 0.75rem;
  color: var(--text-secondary, #888);
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-top: 0.15rem;
}
.drawer-item-badge {
  font-size: 0.7rem;
  padding: 0.05rem 0.35rem;
  border-radius: 3px;
  background: var(--accent-bg, #eef);
  color: var(--accent, #4f6df5);
}
.drawer-item-lock {
  font-size: 0.75rem;
  color: var(--warning, #e6a817);
  margin-top: 0.15rem;
}
.drawer-item-score {
  font-size: 0.75rem;
  color: #22c55e;
  font-weight: 500;
}

.lesson-drawer-footer {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border, #ddd);
}

@media (max-width: 600px) {
  .lesson-drawer { width: 100vw; max-width: 100vw; }
}

/* ── Chat rail (Phase 2 hybrid chat/voice runtime) ────────────────────────
   Hidden unless body.chat-rail-enabled (feature flag via localStorage).
   When enabled, replaces the legacy .wb-student-input composer inside the
   whiteboard panel. */
/* Layout: when chat rail is enabled, dock rail to the right edge as a fixed
   full-height column (top to bottom of viewport). The .app grid (header /
   stage / dock) gets padding-right so its content no longer extends under
   the rail — eliminating the dead strip below the composer. Also remove the
   duplicate footer SPEAK button and footer transcript bubble. */
body.chat-rail-enabled .app {
  padding-right: var(--rail-w);
  position: relative;
}
body.chat-rail-enabled .stage-canvas-wrap[hidden] ~ .stage-whiteboard {
  width: auto !important;
  max-width: none !important;
  flex: 1 1 auto;
  border-left: 1px solid rgba(251, 122, 90, 0.18);
}
body.chat-rail-enabled #aiRealtimeBtn { display: none !important; }
body.chat-rail-enabled #aiTranscript { display: none !important; }
body.chat-rail-enabled #transcriptToggle { display: none !important; }
body.chat-rail-enabled #modeToggle { display: none !important; }

.chat-rail {
  flex: 0 0 var(--rail-w);
  max-width: var(--rail-w);
  min-width: 320px;
  display: none;
  flex-direction: column;
  background: rgba(8, 12, 30, 0.72);
  border-left: 1px solid rgba(251, 122, 90, 0.18);
  min-height: 0;
  color: var(--text);
}
body.chat-rail-enabled .chat-rail {
  display: flex;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--rail-w);
  z-index: 40;
}
body.chat-rail-enabled .wb-student-input { display: none !important; }
body.chat-rail-enabled .chat-rail.collapsed {
  flex: 0 0 42px;
  min-width: 42px;
  max-width: 42px;
}
body.chat-rail-enabled .chat-rail.collapsed .chat-rail-transcript,
body.chat-rail-enabled .chat-rail.collapsed .chat-rail-composer,
body.chat-rail-enabled .chat-rail.collapsed .chat-rail-title,
body.chat-rail-enabled .chat-rail.collapsed .chat-rail-mode,
body.chat-rail-enabled .chat-rail.collapsed .chat-rail-voice-pill { display: none; }
/* Collapsed = a 42px strip with just the expand button; center it and make the
   whole header an easy target. */
body.chat-rail-enabled .chat-rail.collapsed .chat-rail-header {
  justify-content: center;
  padding: 0.55rem 0;
  cursor: pointer;
}
body.chat-rail-enabled .chat-rail.collapsed .chat-rail-collapse { transform: rotate(180deg); }

.chat-rail-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid rgba(251, 122, 90, 0.15);
  background: rgba(255, 255, 255, 0.02);
}
.chat-rail-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}
.chat-rail-mode {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  flex: 1;
  font-size: 0.7rem;
  color: var(--muted);
}
.chat-rail-mode-label { letter-spacing: 0.02em; }
.chat-rail-mode-select {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border: 1px solid rgba(255, 168, 140, 0.18);
  border-radius: 6px;
  font-size: 0.72rem;
  padding: 0.15rem 0.3rem;
  cursor: pointer;
  outline: none;
}
.chat-rail-mode-select:focus { border-color: rgba(251, 122, 90, 0.5); }
.chat-rail-voice-pill {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
}
.chat-rail-voice-pill[data-state="connecting"] { background: rgba(255, 209, 102, 0.18); color: #ffd166; }
.chat-rail-voice-pill[data-state="on"] { background: rgba(251, 122, 90, 0.22); color: #fb7a5a; }
.chat-rail-voice-pill[data-state="ptt"] { background: rgba(162, 111, 255, 0.22); color: #a26fff; }
.chat-rail-voice-pill[data-state="muted"] { background: rgba(255, 107, 138, 0.18); color: #ff8aa3; }
.chat-rail-collapse {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 0.25rem 0.4rem;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s, transform 0.25s;
}
.chat-rail-collapse:hover { background: rgba(255, 255, 255, 0.08); color: var(--text); }

.chat-rail-transcript {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0.6rem 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.chat-rail-empty {
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
  margin-top: 1rem;
  font-style: italic;
}

/* ── Lesson intro (rich not-started state inside the chat) ── */
.chat-intro {
  font-style: normal;
  text-align: left;
  margin: 0.25rem 0.1rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  animation: chatIntroIn 0.4s ease both;
}
/* The [hidden] attribute must still win over the flex display above. */
.chat-intro[hidden] { display: none; }
@keyframes chatIntroIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.chat-intro-eyebrow {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--accent);
}
.chat-intro-title {
  font-size: 1.18rem;
  font-weight: 700;
  line-height: 1.25;
  color: var(--text);
  font-style: normal;
}
.chat-intro-objectives {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.chat-intro-objectives li {
  position: relative;
  padding-left: 1.3rem;
  font-size: 0.84rem;
  line-height: 1.45;
  color: var(--text);
  opacity: 0.86;
}
.chat-intro-objectives li::before {
  content: "";
  position: absolute;
  left: 0.15rem;
  top: 0.5em;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 8px rgba(255, 184, 76, 0.5);
}
.chat-intro-starters { display: flex; flex-direction: column; gap: 0.5rem; }
.chat-intro-starters-label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.chat-intro-starter-list { display: flex; flex-direction: column; gap: 0.5rem; }
.chat-intro-starter {
  text-align: left;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text);
  background: rgba(251, 122, 90, 0.10);
  border: 1px solid rgba(251, 122, 90, 0.28);
  border-radius: 12px;
  padding: 0.6rem 0.8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.chat-intro-starter:hover {
  background: rgba(251, 122, 90, 0.18);
  border-color: var(--accent);
}
.chat-intro-starter:active { transform: scale(0.98); }
.chat-intro-starter .chat-intro-starter-emoji { font-size: 1.05rem; flex: none; }
.chat-intro-hint {
  font-size: 0.76rem;
  color: var(--muted);
  font-style: italic;
}
.chat-rail-turn {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  max-width: 92%;
}
.chat-rail-turn.student { align-self: flex-end; }
.chat-rail-turn.teacher { align-self: flex-start; }
.chat-rail-turn-bubble {
  padding: 0.5rem 0.7rem;
  border-radius: 10px;
  font-size: 0.88rem;
  line-height: 1.45;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
/* "Tutor is thinking" indicator (animated dots) shown before the first token. */
.chat-rail-thinking .chat-rail-turn-bubble { padding: 0.6rem 0.85rem; }
.thinking-dots { display: inline-flex; gap: 4px; align-items: center; height: 0.9rem; }
.thinking-dots i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--muted, #9aa3b5);
  animation: thinking-bounce 1.2s infinite ease-in-out;
}
.thinking-dots i:nth-child(2) { animation-delay: 0.15s; }
.thinking-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes thinking-bounce {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}
/* Rendered-markdown elements inside chat bubbles stay compact. */
.chat-rail-turn-bubble p { margin: 0; }
.chat-rail-turn-bubble p + p { margin-top: 0.5rem; }
.chat-rail-turn-bubble ul,
.chat-rail-turn-bubble ol { margin: 0.35rem 0; padding-left: 1.2rem; }
.chat-rail-turn-bubble li { margin: 0.15rem 0; }
.chat-rail-turn-bubble h2,
.chat-rail-turn-bubble h3,
.chat-rail-turn-bubble h4 { margin: 0.4rem 0 0.2rem; font-size: 0.95rem; line-height: 1.3; }
.chat-rail-turn-bubble h2:first-child,
.chat-rail-turn-bubble h3:first-child,
.chat-rail-turn-bubble h4:first-child { margin-top: 0; }
.chat-rail-turn-bubble hr {
  border: none;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
  margin: 0.55rem 0;
}
/* KaTeX math inside chat bubbles: keep display math tidy and scrollable. */
.chat-rail-turn-bubble .katex { font-size: 1em; }
.chat-rail-turn-bubble .katex-display {
  margin: 0.4rem 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.1rem 0;
}
.chat-rail-turn-bubble code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82em;
  background: rgba(255, 255, 255, 0.08);
  padding: 0.1em 0.35em;
  border-radius: 5px;
}
.chat-rail-turn-bubble a { color: var(--cyan); text-decoration: underline; }
.chat-rail-turn-bubble blockquote {
  margin: 0.35rem 0;
  padding-left: 0.6rem;
  border-left: 2px solid rgba(255, 255, 255, 0.2);
  color: var(--muted);
}
.chat-rail-turn-bubble table {
  border-collapse: collapse;
  margin: 0.35rem 0;
  font-size: 0.82rem;
}
.chat-rail-turn-bubble th,
.chat-rail-turn-bubble td {
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 0.2rem 0.4rem;
  text-align: left;
}
.chat-rail-turn.student .chat-rail-turn-bubble {
  background: rgba(251, 122, 90, 0.2);
  border: 1px solid rgba(251, 122, 90, 0.3);
  color: var(--text);
}
.chat-rail-turn.teacher .chat-rail-turn-bubble {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text);
}
.chat-rail-turn-attachment {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  color: var(--muted);
  padding: 0.15rem 0.45rem;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  margin-top: 0.25rem;
}
.chat-rail-turn-attachment img {
  max-width: 100%;
  max-height: 110px;
  border-radius: 6px;
  display: block;
}
.chat-rail-system-chip {
  align-self: center;
  font-size: 0.72rem;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
  cursor: default;
}
.chat-rail-system-chip.clickable { cursor: pointer; }
.chat-rail-system-chip.clickable:hover { background: rgba(251, 122, 90, 0.12); color: var(--text); }

.chat-rail-earlier-banner {
  align-self: center;
  font-size: 0.7rem;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.03);
  border: 1px dashed rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  padding: 0.25rem 0.55rem;
  margin: 0.25rem 0;
}

.chat-rail-composer {
  border-top: 1px solid rgba(251, 122, 90, 0.15);
  background: rgba(8, 12, 30, 0.7);
  padding: 0.55rem 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex-shrink: 0;
}
.chat-rail-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.chat-rail-attachments[hidden] { display: none; }
.chat-rail-attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  padding: 0.2rem 0.4rem;
  background: rgba(251, 122, 90, 0.14);
  border: 1px solid rgba(251, 122, 90, 0.25);
  color: var(--text);
  border-radius: 999px;
}
.chat-rail-attachment-chip img {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  object-fit: cover;
}
.chat-rail-attachment-chip button {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.75rem;
  padding: 0 0.15rem;
}
.chat-rail-composer-row {
  display: flex;
  align-items: flex-end;
  gap: 0.35rem;
}
.chat-rail-textarea {
  flex: 1;
  min-height: 72px;
  max-height: 200px;
  resize: none;
  border-radius: 10px;
  border: 1px solid rgba(255, 168, 140, 0.18);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  padding: 0.6rem 0.7rem;
  font-size: 0.92rem;
  font-family: inherit;
  line-height: 1.45;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.chat-rail-textarea:focus {
  border-color: rgba(251, 122, 90, 0.5);
  background: rgba(255, 255, 255, 0.06);
}
.chat-rail-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.chat-rail-btn svg { width: 16px; height: 16px; }
.chat-rail-btn:hover { background: rgba(255, 255, 255, 0.1); color: var(--text); }
.chat-rail-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.chat-rail-mic.active {
  background: rgba(251, 122, 90, 0.25);
  border-color: rgba(251, 122, 90, 0.4);
  color: #fb7a5a;
}
.chat-rail-mic.ptt {
  background: rgba(162, 111, 255, 0.28);
  border-color: rgba(162, 111, 255, 0.5);
  color: #a26fff;
}
.chat-rail-send.ready {
  background: rgba(251, 122, 90, 0.22);
  border-color: rgba(251, 122, 90, 0.4);
  color: #c1ccff;
}
.chat-rail-hint {
  font-size: 0.72rem;
  color: var(--muted);
  min-height: 0.9rem;
}
.chat-rail-hint.has-message {
  color: #dfe8ff;
}
.chat-rail-hint.has-message.error {
  color: #ff9aac;
}

/* Mobile lesson layout: one primary surface at a time. Conversation owns the
   stage until the tutor creates a visual; board/animation then take over while
   the composer and a compact current-turn caption remain available. */
.mobile-tutor-caption,
.mobile-chat-backdrop {
  display: none;
}

@media (max-width: 900px), (max-height: 560px) and (pointer: coarse) {
  body.chat-rail-enabled {
    --mobile-composer-height: 70px;
  }

  body.chat-rail-enabled .app { padding-right: 0; }
  body.chat-rail-enabled .app {
    grid-template-rows: auto minmax(0, 1fr);
  }
  body.chat-rail-enabled .dock { display: none; }

  .topbar {
    min-height: 52px;
    align-items: center;
    flex-wrap: nowrap;
    gap: 0.4rem;
    padding: 0.45rem 0.55rem;
  }
  .topbar-brand { flex: 0 0 36px; }
  .topbar-brand a { justify-content: center; }
  .topbar-icon { width: 26px; height: 26px; }
  .topbar-title,
  .topbar-session-eyebrow,
  .topbar-session-meta,
  .topbar-session-lesson,
  .topbar-session-goal,
  .topbar-status { display: none !important; }
  .topbar-session {
    order: initial;
    width: auto;
    padding: 0 0.25rem;
    gap: 0;
  }
  .topbar-session-title {
    font-size: 0.9rem;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .topbar-drawer-toggle,
  .topbar-mobile-menu-toggle {
    flex: 0 0 40px;
    width: 40px;
    height: 40px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
    font-size: 1.2rem;
  }
  .topbar-drawer-toggle[hidden] { display: none; }
  .topbar-mobile-menu {
    position: fixed;
    top: 50px;
    right: 8px;
    z-index: 80;
    min-width: 180px;
    padding: 0.35rem;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(12, 16, 38, 0.98);
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.45);
  }
  .topbar-mobile-menu:not([hidden]) {
    display: flex;
    flex-direction: column;
  }
  .topbar-mobile-menu button {
    border: none;
    border-radius: 9px;
    background: transparent;
    color: var(--text);
    padding: 0.7rem 0.8rem;
    text-align: left;
    font-weight: 600;
  }
  .topbar-mobile-menu button:hover,
  .topbar-mobile-menu button:focus-visible { background: rgba(255, 255, 255, 0.08); }
  .topbar-mobile-menu button.danger { color: #ff8aa3; }

  body.chat-rail-enabled .stage {
    display: block;
    position: relative;
    min-height: 0;
  }
  .stage-welcome { display: none !important; }

  body.chat-rail-enabled .chat-rail {
    position: absolute;
    inset: 0;
    display: flex;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    border-left: none;
    border-top: none;
    z-index: 30;
  }
  body.chat-rail-enabled .chat-rail.collapsed {
    flex: none;
    max-width: 100%;
    min-width: 0;
  }

  body.mobile-lesson-layout.mobile-surface-board .stage-whiteboard {
    display: flex;
    position: absolute;
    inset: 0 0 var(--mobile-composer-height) 0;
    width: 100%;
    max-width: none;
    min-width: 0;
    max-height: none;
    border: none;
    box-shadow: none;
    animation: none;
  }
  body.mobile-lesson-layout.mobile-surface-conversation .stage-whiteboard,
  body.mobile-lesson-layout.mobile-surface-animation .stage-whiteboard {
    display: none;
  }
  body.mobile-lesson-layout .stage-whiteboard .wb-header,
  body.mobile-lesson-layout .stage-whiteboard .wb-drag-handle {
    display: none;
  }
  body.mobile-lesson-layout .whiteboard-content {
    padding: 1rem;
    font-size: 0.96rem;
    line-height: 1.6;
    overscroll-behavior: contain;
  }

  body.mobile-lesson-layout.mobile-surface-animation .stage-canvas-wrap {
    display: flex;
    position: absolute;
    inset: 0 0 var(--mobile-composer-height) 0;
    max-height: none;
    width: 100%;
  }
  body.mobile-lesson-layout.mobile-surface-conversation .stage-canvas-wrap,
  body.mobile-lesson-layout.mobile-surface-board .stage-canvas-wrap {
    display: none;
  }
  body.mobile-lesson-layout .anim-takeover-bar {
    min-height: 48px;
    gap: 0.5rem;
    padding: 0.35rem 0.5rem;
  }
  body.mobile-lesson-layout .anim-back-btn {
    width: 40px;
    height: 40px;
    padding: 0;
    justify-content: center;
    font-size: 0;
  }
  body.mobile-lesson-layout .anim-back-btn svg { width: 18px; height: 18px; }
  body.mobile-lesson-layout .anim-bar-eyebrow,
  body.mobile-lesson-layout #animHideChatBtn { display: none; }
  body.mobile-lesson-layout .anim-bar-title { font-size: 0.82rem; }
  body.mobile-lesson-layout .anim-bar-ghost {
    min-height: 40px;
    padding: 0.35rem 0.55rem;
  }
  body.mobile-lesson-layout .metrics-bar {
    bottom: 0.5rem;
    max-width: calc(100% - 1rem);
  }

  /* Visual mode keeps only the composer from the chat rail. */
  body.mobile-lesson-layout:is(.mobile-surface-board, .mobile-surface-animation):not(.mobile-chat-sheet-open) .chat-rail {
    inset: auto 0 0;
    height: auto;
    min-height: 0;
    background: transparent;
    border: none;
    pointer-events: none;
  }
  body.mobile-lesson-layout:is(.mobile-surface-board, .mobile-surface-animation):not(.mobile-chat-sheet-open) .chat-rail-header,
  body.mobile-lesson-layout:is(.mobile-surface-board, .mobile-surface-animation):not(.mobile-chat-sheet-open) .chat-rail-transcript {
    display: none;
  }
  body.mobile-lesson-layout:is(.mobile-surface-board, .mobile-surface-animation):not(.mobile-chat-sheet-open) .chat-rail-composer {
    pointer-events: auto;
  }

  .chat-rail-header {
    min-height: 44px;
    padding: 0.4rem 0.55rem;
  }
  .chat-rail-composer {
    padding: 0.45rem 0.5rem calc(0.45rem + env(safe-area-inset-bottom));
    gap: 0.25rem;
    background: rgba(8, 12, 30, 0.94);
  }
  .chat-rail-composer-row {
    align-items: center;
    gap: 0.3rem;
  }
  .chat-rail-btn {
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    border-radius: 12px;
  }
  .chat-rail-textarea {
    min-width: 0;
    min-height: 44px;
    max-height: 120px;
    padding: 0.65rem 0.7rem;
    font-size: 16px;
    line-height: 1.35;
  }
  .chat-rail-hint { display: none; }
  .chat-rail-hint.has-message {
    display: block;
    padding: 0.2rem 0.25rem 0;
    min-height: 0;
  }
  .chat-rail-attachments { padding: 0 0.15rem; }

  .mobile-tutor-caption {
    position: absolute;
    left: 0.55rem;
    right: 0.55rem;
    bottom: calc(var(--mobile-composer-height) + 0.5rem + env(safe-area-inset-bottom));
    z-index: 26;
  }
  .mobile-tutor-caption[hidden] { display: none; }
  body.mobile-lesson-layout:is(.mobile-surface-board, .mobile-surface-animation):not(.mobile-chat-sheet-open) .mobile-tutor-caption:not([hidden]) {
    display: block;
  }
  .mobile-tutor-caption-open {
    width: 100%;
    min-height: 48px;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.55rem;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 14px;
    padding: 0.55rem 0.65rem;
    background: rgba(9, 12, 24, 0.88);
    color: var(--text);
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.32);
    backdrop-filter: blur(12px);
    text-align: left;
  }
  .mobile-tutor-caption-label,
  .mobile-tutor-caption-action {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--accent);
  }
  .mobile-tutor-caption-text {
    min-width: 0;
    display: -webkit-box;
    overflow: hidden;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    font-size: 0.82rem;
    line-height: 1.35;
  }

  /* Full conversation is an on-demand sheet over the visual. */
  body.mobile-lesson-layout.mobile-chat-sheet-open .chat-rail {
    inset: max(56px, 8vh) 0 0;
    height: auto;
    min-height: 0;
    display: flex;
    border-top: 1px solid rgba(251, 122, 90, 0.28);
    border-radius: 18px 18px 0 0;
    background: rgba(8, 12, 30, 0.98);
    box-shadow: 0 -18px 48px rgba(0, 0, 0, 0.48);
    pointer-events: auto;
    z-index: 42;
  }
  body.mobile-lesson-layout.mobile-chat-sheet-open .chat-rail-header,
  body.mobile-lesson-layout.mobile-chat-sheet-open .chat-rail-transcript,
  body.mobile-lesson-layout.mobile-chat-sheet-open .chat-rail-composer {
    display: flex;
  }
  body.mobile-lesson-layout.mobile-chat-sheet-open .chat-rail-transcript {
    flex-direction: column;
  }
  body.mobile-lesson-layout.mobile-chat-sheet-open .mobile-tutor-caption { display: none; }
  body.mobile-lesson-layout.mobile-chat-sheet-open .mobile-chat-backdrop:not([hidden]) {
    display: block;
    position: absolute;
    inset: 0;
    z-index: 41;
    border: none;
    border-radius: 0;
    background: rgba(0, 0, 0, 0.5);
  }
  body.mobile-lesson-layout.mobile-surface-conversation .chat-rail-collapse {
    display: none;
  }
  body.mobile-lesson-layout.mobile-keyboard-open .app {
    position: fixed;
    top: var(--mobile-visual-viewport-offset-top, 0);
    right: 0;
    left: 0;
    height: var(--mobile-visual-viewport-height, 100dvh);
  }
  body.mobile-lesson-layout.mobile-keyboard-open .topbar {
    display: none;
  }
  body.mobile-lesson-layout.mobile-keyboard-open.mobile-chat-sheet-open .chat-rail {
    inset: 0;
    border-radius: 0;
  }
}

@media (max-height: 560px) and (max-width: 900px),
       (max-height: 560px) and (pointer: coarse) {
  body.chat-rail-enabled { --mobile-composer-height: 62px; }
  .topbar { min-height: 46px; padding-block: 0.25rem; }
  .topbar-drawer-toggle,
  .topbar-mobile-menu-toggle { width: 38px; height: 38px; flex-basis: 38px; }
  body.mobile-lesson-layout .anim-takeover-bar { min-height: 42px; }
  body.mobile-lesson-layout .chat-rail-composer { padding-block: 0.3rem; }
  body.mobile-lesson-layout .mobile-tutor-caption { bottom: calc(var(--mobile-composer-height) + 0.25rem); }
  body.mobile-lesson-layout.mobile-chat-sheet-open .chat-rail { inset: 46px 0 0; border-radius: 0; }
}

/* Image source and preview sheets. */
.attachment-menu-overlay,
.image-preview-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 1rem;
  background: rgba(4, 6, 14, 0.7);
  backdrop-filter: blur(4px);
}
.attachment-menu-overlay[hidden],
.image-preview-overlay[hidden] { display: none; }
.attachment-menu-card,
.image-preview-card {
  width: min(520px, 100%);
  max-height: min(88vh, 760px);
  overflow: auto;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 18px;
  background: #10141f;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.52);
}
.attachment-menu-head,
.image-preview-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1rem 0.75rem;
}
.attachment-menu-head h2,
.image-preview-head h2 {
  margin: 0.15rem 0 0;
  font-size: 1.05rem;
}
.attachment-menu-eyebrow,
.image-preview-eyebrow {
  color: var(--accent);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.attachment-menu-close,
.image-preview-close {
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-size: 1rem;
}
.attachment-menu-actions {
  display: grid;
  gap: 0.55rem;
  padding: 0.25rem 1rem;
}
.attachment-menu-actions button {
  min-height: 64px;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 0.7rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 13px;
  padding: 0.75rem;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  text-align: left;
}
.attachment-menu-actions button:hover,
.attachment-menu-actions button:focus-visible {
  border-color: rgba(251, 122, 90, 0.5);
  background: rgba(251, 122, 90, 0.1);
}
.attachment-menu-actions button > span:first-child { font-size: 1.35rem; text-align: center; }
.attachment-menu-actions strong,
.attachment-menu-actions small { display: block; }
.attachment-menu-actions small { margin-top: 0.1rem; color: var(--muted); line-height: 1.35; }
.attachment-menu-hint {
  padding: 0.75rem 1rem 1rem;
  color: var(--muted);
  font-size: 0.78rem;
}
.image-preview-stage {
  position: relative;
  min-height: 220px;
  max-height: 58vh;
  margin: 0 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 14px;
  background: #070a12;
}
.image-preview-stage img {
  display: block;
  max-width: 100%;
  max-height: 58vh;
  object-fit: contain;
}
.image-preview-processing {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(7, 10, 18, 0.78);
  color: var(--text);
  font-weight: 600;
}
.image-preview-processing[hidden] { display: none; }
.image-preview-meta {
  min-height: 1.4rem;
  padding: 0.65rem 1rem 0;
  color: var(--muted);
  font-size: 0.76rem;
}
.image-preview-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.8rem 1rem calc(1rem + env(safe-area-inset-bottom));
}
.image-preview-actions button {
  min-height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 0.55rem 0.8rem;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-weight: 600;
}
.image-preview-actions button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #1a0f0c;
}

@media (max-width: 640px) {
  .attachment-menu-overlay,
  .image-preview-overlay { padding: 0; }
  .attachment-menu-card,
  .image-preview-card {
    width: 100%;
    max-height: 92dvh;
    border-radius: 18px 18px 0 0;
  }
  .image-preview-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
  .image-preview-actions .primary { grid-column: 1 / -1; }
}

/* ─────────────────────────────────────────────────────────────────────── *
 * Stylus / ink sketch pad (draw or write → tutor image input)
 * ─────────────────────────────────────────────────────────────────────── */
.ink-pad-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(4, 6, 14, 0.66);
  backdrop-filter: blur(4px);
}
.ink-pad-overlay[hidden] { display: none; }
.ink-pad-card {
  width: min(880px, 96vw);
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  background: #10141f;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}
.ink-pad-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.ink-pad-title { font-weight: 600; font-size: 0.95rem; color: var(--text); }
.ink-pad-close {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
}
.ink-pad-close:hover { color: var(--text); background: rgba(255, 255, 255, 0.08); }
.ink-pad-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  flex-wrap: wrap;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.ink-toolbar-spacer { flex: 1 1 auto; }
.ink-tool {
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.ink-tool:hover { background: rgba(255, 255, 255, 0.1); }
.ink-tool.active {
  background: rgba(38, 214, 255, 0.18);
  border-color: rgba(38, 214, 255, 0.45);
  color: #26d6ff;
}
.ink-swatches { display: inline-flex; gap: 6px; align-items: center; margin-left: 4px; }
.ink-swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.2);
  cursor: pointer;
  padding: 0;
}
.ink-swatch.active { border-color: #fff; box-shadow: 0 0 0 2px rgba(38, 214, 255, 0.5); }
.ink-pad-canvas-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 260px;
  margin: 12px 16px;
  border-radius: 12px;
  overflow: hidden;
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.15);
}
#inkCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}
.ink-pad-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  color: #9aa3b5;
  font-size: 0.95rem;
  padding: 0 24px;
  text-align: center;
}
.ink-pad-canvas-wrap.has-ink .ink-pad-placeholder { display: none; }
.ink-pad-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 16px 16px;
}
.ink-action {
  border-radius: 9px;
  padding: 9px 18px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
}
.ink-action-ghost {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.14);
  color: var(--text);
}
.ink-action-ghost:hover { background: rgba(255, 255, 255, 0.08); }
.ink-action-primary {
  background: #fb7a5a;
  color: #14060a;
  border-color: #fb7a5a;
}
.ink-action-primary:hover { filter: brightness(1.05); }
.ink-action-primary:disabled { opacity: 0.45; cursor: not-allowed; filter: none; }
@media (max-width: 640px) {
  .ink-pad-overlay { padding: 0; }
  .ink-pad-card { width: 100vw; height: 100vh; max-height: 100vh; border-radius: 0; }
}
/* Short / landscape screens: shrink the canvas so the action row stays reachable. */
@media (max-height: 560px) {
  .ink-pad-canvas-wrap { min-height: 120px; }
  .ink-pad-actions { padding: 8px 16px 10px; }
}
