/* Live teaching stage: the teacher's whiteboard for GPT-Live voice lessons.
   Active only while body.live-stage is set (Live voice + stage capability).
   The board is the student's focus; chat is an on-demand drawer. */

:root { --teacher-bar-h: 64px; }

.live-stage-panel,
.teacher-bar,
.live-chat-backdrop { display: none; }

/* ── Focus layout ─────────────────────────────────────────────────────── */

body.live-stage .stage {
  display: block;
  position: relative;
  min-height: 0;
}
body.live-stage.chat-rail-enabled .app { padding-right: 0; }
body.live-stage .stage-welcome,
body.live-stage .stage-whiteboard,
body.live-stage .mobile-tutor-caption,
body.live-stage .mobile-chat-backdrop,
body.live-stage #boardToggle,
body.live-stage #animHideChatBtn { display: none !important; }
/* Board focus mode belongs to the classic layout; the stage is already focused. */
body.live-stage.board-hidden .live-stage-panel { display: flex; }

body.live-stage .live-stage-panel {
  display: flex;
  flex-direction: column;
  position: absolute;
  inset: 0 0 var(--teacher-bar-h) 0;
  z-index: 4;
}
/* Legacy takeover (animation choreography off) and the full-screen layout. */
body.live-stage.anim-takeover .live-stage-panel,
body.live-stage.stage-layout-animation .live-stage-panel { display: none; }

body.live-stage .stage-canvas-wrap:not([hidden]) {
  display: flex;
  position: absolute;
  inset: 0 0 var(--teacher-bar-h) 0;
  width: 100%;
  max-height: none;
  z-index: 5;
}
body.live-stage .anim-dock { bottom: calc(var(--teacher-bar-h) + 0.75rem); z-index: 8; }

/* ── Teacher-controlled layouts (animation choreography) ─────────────────
   split: board beside the animation; board_pip: the animation as a small
   picture-in-picture over the board. The teacher chooses; the student can pin. */
body.live-stage.stage-layout-split .live-stage-panel { inset: 0 40% var(--teacher-bar-h) 0; }
body.live-stage.stage-layout-split .stage-canvas-wrap:not([hidden]) {
  inset: 0 0 var(--teacher-bar-h) 60%;
  width: 40%;
  border-left: 1px solid rgba(255, 255, 255, 0.08);
}
body.live-stage.stage-layout-board_pip .stage-canvas-wrap:not([hidden]) {
  inset: auto 1rem calc(var(--teacher-bar-h) + 1rem) auto;
  width: min(36vw, 420px);
  height: auto;
  aspect-ratio: 16 / 10;
  max-height: 40vh;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
  z-index: 7;
}
body.live-stage .stage-canvas-wrap.stage-pip .anim-takeover-bar,
body.live-stage .stage-canvas-wrap.stage-pip .scene-controls,
body.live-stage .stage-canvas-wrap.stage-pip .metrics-bar,
body.live-stage .stage-canvas-wrap.stage-pip .canvas-status { display: none; }
.stage-pip-handle { display: none; }
body.live-stage .stage-canvas-wrap.stage-pip .stage-pip-handle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 28px;
  padding: 0 0.4rem 0 0.6rem;
  z-index: 4;
  cursor: grab;
  background: linear-gradient(rgba(6, 10, 24, 0.85), rgba(6, 10, 24, 0));
  touch-action: none;
}
.stage-pip-grip {
  width: 28px;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.45);
}
.stage-pip-expand {
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(10, 16, 36, 0.7);
  color: #eef2ff;
  border-radius: 7px;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  cursor: pointer;
}
/* In split and pip the bar is a slim strip, not the full takeover chrome. */
body.live-stage.stage-layout-split .anim-takeover-bar { padding: 0.3rem 0.6rem; }
body.live-stage.stage-layout-split #animHideChatBtn { display: none !important; }

.live-board {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
}

/* Chat is a drawer over the board, never a column beside it. */
body.live-stage .chat-rail { display: none !important; }
body.live-stage.live-stage-chat-open .chat-rail {
  display: flex !important;
  flex-direction: column;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: auto;
  inset: 0 0 0 auto;
  width: min(400px, 100vw);
  max-width: 100vw;
  min-width: 0;
  height: auto;
  z-index: 62;
  pointer-events: auto;
  background: rgba(8, 12, 30, 0.98);
  border-left: 1px solid rgba(251, 122, 90, 0.28);
  box-shadow: -18px 0 48px rgba(0, 0, 0, 0.45);
}
body.live-stage.live-stage-chat-open .chat-rail .chat-rail-header,
body.live-stage.live-stage-chat-open .chat-rail .chat-rail-composer { display: flex; }
body.live-stage.live-stage-chat-open .chat-rail .chat-rail-transcript { display: flex; flex-direction: column; }
body.live-stage.live-stage-chat-open .chat-rail .chat-rail-collapse { display: none; }
body.live-stage.live-stage-chat-open .live-chat-backdrop {
  display: block;
  position: fixed;
  inset: 0;
  z-index: 61;
  border: none;
  background: rgba(0, 0, 0, 0.4);
}

/* ── Teacher bar ─────────────────────────────────────────────────────── */

body.live-stage .teacher-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--teacher-bar-h);
  padding: 0 0.9rem calc(env(safe-area-inset-bottom) * 0.5);
  background: rgba(8, 11, 24, 0.94);
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  z-index: 9;
}
.teacher-presence {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
  flex: 1 1 auto;
}
.teacher-orb {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffd2a6, #fb7a5a 60%, #a83a52);
  box-shadow: 0 0 0 0 rgba(251, 122, 90, 0.5);
  opacity: 0.55;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.teacher-orb[data-state="listening"] { opacity: 0.9; }
.teacher-orb[data-state="preparing"] { opacity: 1; animation: teacher-orb-think 1.4s ease-in-out infinite; }
.teacher-orb[data-state="presenting"],
.teacher-orb[data-state="speaking"] { opacity: 1; animation: teacher-orb-speak 1.1s ease-in-out infinite; }
@keyframes teacher-orb-think {
  0%, 100% { transform: scale(0.92); }
  50% { transform: scale(1.04); }
}
@keyframes teacher-orb-speak {
  0%, 100% { box-shadow: 0 0 0 0 rgba(251, 122, 90, 0.45); }
  50% { box-shadow: 0 0 0 9px rgba(251, 122, 90, 0); }
}
.teacher-state-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted, #9aa3b8);
  font-size: 0.86rem;
}
.teacher-bar-actions { display: flex; align-items: center; gap: 0.45rem; flex: none; }
.teacher-bar-btn {
  min-width: 44px;
  height: 44px;
  padding: 0 0.85rem;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text, #ecf0ff);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}
.teacher-bar-btn:hover { border-color: var(--accent, #fb7a5a); }
.teacher-bar-share { display: inline-flex; align-items: center; gap: 0.4rem; }
.teacher-bar-share[hidden] { display: none; }
.teacher-bar-share svg { width: 18px; height: 18px; flex: none; }
.teacher-bar-btn[aria-pressed="true"] { background: rgba(251, 122, 90, 0.16); border-color: var(--accent, #fb7a5a); color: #ffd9cc; }
.teacher-bar-mic {
  background: var(--accent, #fb7a5a);
  border-color: transparent;
  color: #1a0f0c;
  min-width: 112px;
}
.teacher-bar-mic[data-state="connecting"] { opacity: 0.75; }
.teacher-bar-mic[data-state="live"] { background: rgba(123, 227, 164, 0.16); color: #c9f7da; border-color: rgba(123, 227, 164, 0.5); }
.teacher-bar-mic[data-state="muted"] { background: rgba(255, 122, 138, 0.16); color: #ffd0d6; border-color: rgba(255, 122, 138, 0.5); }

/* Optional captions: off by default; the board is the visual channel. */
.live-caption {
  position: absolute;
  left: 50%;
  bottom: 0.75rem;
  transform: translateX(-50%);
  max-width: min(46rem, calc(100% - 2rem));
  padding: 0.45rem 0.8rem;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.66);
  color: #f3efe4;
  font-size: 0.95rem;
  line-height: 1.4;
  text-align: center;
  z-index: 3;
  pointer-events: none;
}
.live-caption[hidden] { display: none; }

/* ── Board engine (.lb-*) ────────────────────────────────────────────── */

.lb-root {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: radial-gradient(ellipse at 50% 30%, #17233f 0%, #0d1428 70%);
  color: #f3efe4;
}
.lb-toolbar {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.3rem 0.5rem;
  flex: none;
}
.lb-root.lb-multi-page .lb-toolbar { display: flex; }
.lb-nav {
  width: 36px;
  height: 32px;
  border-radius: 9px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  color: inherit;
  font-size: 1.1rem;
  cursor: pointer;
}
.lb-nav:disabled { opacity: 0.35; cursor: default; }
.lb-page-label { font-size: 0.78rem; color: #9aa3b8; min-width: 8rem; text-align: center; }
.lb-viewport {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  outline: none;
}
.lb-sizer { position: relative; }
.lb-page {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
}
.lb-page.lb-offstage { visibility: hidden; pointer-events: none; }
.lb-page-title {
  position: absolute;
  left: 40px;
  top: 24px;
  font-size: 30px;
  font-weight: 700;
  color: #ffe066;
  letter-spacing: 0.01em;
}
.lb-under,
.lb-ink {
  position: absolute;
  left: 0;
  top: 0;
  overflow: visible;
  pointer-events: none;
}
.lb-under { z-index: 0; }
.lb-objects { position: absolute; inset: 0; z-index: 1; }
.lb-ink { z-index: 2; }
.lb-highlight { opacity: 0.26; transform-box: fill-box; transform-origin: left center; }
.lb-stroke {
  fill: none;
  stroke-width: 3.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 0;
}
.lb-label {
  font: 600 20px "Caveat", "Segoe Print", "Bradley Hand", "Comic Sans MS", cursive;
}
.lb-obj {
  position: absolute;
  font-size: 26px;
  line-height: 1.4;
}
.lb-obj.lb-size-title { font-size: 34px; font-weight: 700; }
.lb-obj.lb-size-small { font-size: 21px; }
.lb-content { display: inline-block; max-width: 100%; }
.lb-math .lb-content { display: block; }
.lb-work-frame { display: inline-block; margin: 0; padding: 8px 8px 4px; background: #f7f4ec; border-radius: 6px; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35); transform: rotate(-0.6deg); }
.lb-work-img { display: block; max-width: 100%; max-height: 360px; width: auto; height: auto; object-fit: contain; border-radius: 3px; }
.lb-work-caption { font: 600 16px "Caveat", "Segoe Print", "Bradley Hand", cursive; color: #4a4f5c; text-align: center; padding-top: 2px; }
.lb-obj .katex-display { margin: 0; text-align: left; }
.lb-obj .katex-display > .katex { text-align: left; display: inline-block; }
.lb-obj .katex { font-size: 1.12em; }
.lb-line { min-height: 1em; }
.lb-line.lb-h { font-weight: 700; color: #ffe066; }
.lb-line.lb-li { display: flex; gap: 0.5em; }
.lb-bullet { color: #ffad5c; }
.lb-line.lb-gap { min-height: 0.5em; }
.lb-latex { font-family: ui-monospace, monospace; font-size: 0.85em; color: #c9d1e8; }
.lb-focus-pulse { animation: lb-focus-pulse 1.1s ease-out 1; }
@keyframes lb-focus-pulse {
  0% { filter: drop-shadow(0 0 0 rgba(255, 224, 102, 0)); }
  35% { filter: drop-shadow(0 0 10px rgba(255, 224, 102, 0.75)); }
  100% { filter: drop-shadow(0 0 0 rgba(255, 224, 102, 0)); }
}
.lb-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 2rem;
  text-align: center;
  pointer-events: none;
}
.lb-empty[hidden] { display: none; }
.lb-empty-title { font-size: 1.15rem; font-weight: 700; color: #f3efe4; }
.lb-empty-text { max-width: 26rem; color: #9aa3b8; font-size: 0.92rem; }
.lb-edge,
.lb-follow {
  position: absolute;
  right: 0.9rem;
  z-index: 5;
  border-radius: 999px;
  border: 1px solid rgba(255, 224, 102, 0.6);
  background: rgba(20, 24, 44, 0.94);
  color: #ffe066;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.45rem 0.8rem;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
}
.lb-follow { bottom: 0.9rem; }
.lb-edge { top: 3rem; }
.lb-edge[hidden],
.lb-follow[hidden] { display: none; }

/* ── Mobile ──────────────────────────────────────────────────────────── */

@media (max-width: 900px), (max-height: 560px) and (pointer: coarse) {
  :root { --teacher-bar-h: 60px; }
  body.live-stage .teacher-bar { gap: 0.4rem; padding-inline: 0.55rem; }
  body.live-stage .teacher-state-text { font-size: 0.8rem; }
  body.live-stage .teacher-bar-mic { min-width: 88px; }
  body.live-stage .teacher-bar-btn { padding: 0 0.6rem; }
  body.live-stage .teacher-bar-share .teacher-bar-label { display: none; }
  body.live-stage.live-stage-chat-open .chat-rail {
    inset: max(56px, 8vh) 0 0 0;
    width: 100%;
    border-left: none;
    border-top: 1px solid rgba(251, 122, 90, 0.28);
    border-radius: 18px 18px 0 0;
  }
  body.live-stage.mobile-keyboard-open.live-stage-chat-open .chat-rail { inset: 0; border-radius: 0; }
  /* Split stacks: animation on top, board below. Pip docks to the corner. */
  body.live-stage.stage-layout-split .live-stage-panel { inset: 40% 0 var(--teacher-bar-h) 0; }
  body.live-stage.stage-layout-split .stage-canvas-wrap:not([hidden]),
  body.live-stage.mobile-lesson-layout.stage-layout-split .stage-canvas-wrap:not([hidden]) {
    display: flex;
    position: absolute;
    inset: 0 0 60% 0;
    width: 100%;
    max-height: none;
    border-left: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  }
  body.live-stage.stage-layout-board_pip .stage-canvas-wrap:not([hidden]),
  body.live-stage.mobile-lesson-layout.stage-layout-board_pip .stage-canvas-wrap:not([hidden]) {
    display: flex;
    position: absolute;
    inset: auto 0.6rem calc(var(--teacher-bar-h) + 0.6rem) auto;
    width: min(60vw, 280px);
    max-height: 30vh;
  }
}

@media (prefers-reduced-motion: reduce) {
  .teacher-orb { animation: none !important; }
  .lb-focus-pulse { animation: none; }
}
