:root {
  --bg: #0b1020;
  --panel: rgba(255, 255, 255, 0.06);
  --border: rgba(255, 255, 255, 0.12);
  --text: rgba(255, 255, 255, 0.92);
  --muted: rgba(255, 255, 255, 0.70);
  --primary: #7c3aed;
  --primary2: #22c55e;
  --bad: #ef4444;
  --good: #22c55e;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.25);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  background: radial-gradient(1200px 600px at 20% 10%, rgba(124, 58, 237, 0.25), transparent),
              radial-gradient(900px 500px at 90% 20%, rgba(34, 197, 94, 0.18), transparent),
              var(--bg);
  color: var(--text);
}

a { color: inherit; text-decoration: none; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; }

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 18px;
}

.topbar {
  position: sticky;
  top: 0;
  backdrop-filter: blur(14px);
  background: rgba(11, 16, 32, 0.75);
  border-bottom: 1px solid var(--border);
  z-index: 50;
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}

.brand {
  font-weight: 700;
  letter-spacing: 0.2px;
}

.nav { display: flex; gap: 14px; }
.nav a {
  padding: 8px 10px;
  border-radius: 10px;
  color: var(--muted);
}
.nav a:hover { background: rgba(255, 255, 255, 0.06); color: var(--text); }

.content { padding: 26px 18px 44px; }

.footer {
  border-top: 1px solid var(--border);
  padding: 20px 0;
  color: var(--muted);
}
.footer-inner { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }

.hero {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 18px;
  align-items: start;
  margin: 10px 0 22px;
}

@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr; }
}

h1 { margin: 0 0 10px; font-size: 42px; line-height: 1.08; }
h2 { margin: 0 0 10px; }
.h3 { margin: 0 0 8px; font-size: 18px; }
.lead { color: var(--muted); font-size: 18px; line-height: 1.5; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 14px;
}
@media (max-width: 900px) {
  .grid { grid-template-columns: 1fr; }
}

.split {
  display: grid;
  grid-template-columns: 1.8fr 1fr;
  gap: 14px;
  align-items: start;
}
@media (max-width: 900px) {
  .split { grid-template-columns: 1fr; }
}

.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
  font-weight: 600;
}
.btn[hidden] {
  display: none !important;
}
.btn:hover { background: rgba(255, 255, 255, 0.10); }
.btn.primary {
  border-color: rgba(124, 58, 237, 0.5);
  background: linear-gradient(135deg, rgba(124, 58, 237, 0.95), rgba(34, 197, 94, 0.55));
}
.btn.primary:hover { filter: brightness(1.05); }

.link { color: rgba(255,255,255,0.86); }
.link:hover { text-decoration: underline; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
}
.badge.subtle { background: rgba(255, 255, 255, 0.05); }
.badge.good { border-color: rgba(34,197,94,0.6); color: rgba(34,197,94,0.95); }
.badge.bad { border-color: rgba(239,68,68,0.6); color: rgba(239,68,68,0.95); }

.meta { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.form .label { display: block; margin: 10px 0 6px; color: var(--muted); }
.label.inline { margin: 0 8px 0 0; display: inline; }
.input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.22);
  color: var(--text);
}
textarea.input {
  min-height: 110px;
  resize: vertical;
  font: inherit;
}

.stack { display: flex; flex-direction: column; gap: 14px; margin-top: 14px; }

.question .prompt { color: rgba(255,255,255,0.88); white-space: pre-wrap; }
.choices { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.choice {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.15);
}
.choice:hover { background: rgba(0, 0, 0, 0.22); }
.choice input { accent-color: var(--primary); }
.choice.readonly { cursor: default; }
.choice.readonly:hover { background: rgba(0, 0, 0, 0.15); }
.choice.correct { border-color: rgba(34,197,94,0.55); }
.choice.chosen { outline: 2px solid rgba(124,58,237,0.45); }

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.06);
  color: rgba(255,255,255,0.9);
}
.pill.small { padding: 2px 7px; font-size: 12px; color: var(--muted); }

.topic-list { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.topic-pill { margin: 0; }
.topic-pill button { cursor: pointer; }
.btn:disabled,
.pill:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.player {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 10px;
}
.quality-select {
  width: auto;
  min-width: 96px;
}

.avatar-shell {
  margin-top: 10px;
}

.audio {
  width: 100%;
  margin-top: 10px;
}

.video {
  width: 100%;
  margin-top: 10px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.55);
}

.avatar-stage {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.35);
  aspect-ratio: 16 / 9;
}

.graph-hud {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 3;
  width: min(300px, calc(100% - 32px));
  padding: 14px 14px 12px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background:
    linear-gradient(140deg, rgba(15, 23, 42, 0.84), rgba(30, 41, 59, 0.72)),
    rgba(15, 23, 42, 0.7);
  color: rgba(248, 250, 252, 0.96);
  backdrop-filter: blur(12px);
  box-shadow: 0 16px 44px rgba(2, 6, 23, 0.28);
  pointer-events: none;
}

.graph-hud[hidden] {
  display: none !important;
}

.graph-hud.active {
  border-color: rgba(34, 197, 94, 0.24);
}

.graph-hud-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(191, 219, 254, 0.88);
}

.graph-hud-pulse {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: rgba(34, 197, 94, 0.96);
  box-shadow: 0 0 0 6px rgba(34, 197, 94, 0.16);
  animation: graph-pulse 1.8s ease-in-out infinite;
}

.graph-hud-title {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.2;
}

.graph-hud-detail {
  margin-top: 6px;
  font-size: 13px;
  line-height: 1.45;
  color: rgba(226, 232, 240, 0.88);
}

.graph-hud-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.graph-hud-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  background: rgba(255, 255, 255, 0.08);
  color: rgba(248, 250, 252, 0.95);
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
}

#avatar-canvas,
.whiteboard-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

#avatar-canvas:focus-visible,
.whiteboard-canvas:focus-visible {
  outline: 2px solid rgba(124, 58, 237, 0.8);
  outline-offset: -2px;
}

.avatar-stage:fullscreen {
  margin-top: 0;
  width: 100vw;
  height: 100vh;
  border: none;
  border-radius: 0;
  background: #020617;
}

.avatar-shell:fullscreen {
  margin: 0;
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px;
  background: #020617;
}

.avatar-shell:fullscreen .avatar-stage {
  flex: 1 1 auto;
  min-height: 0;
}

.avatar-shell:fullscreen .graph-hud {
  top: 18px;
  right: 18px;
  width: min(340px, calc(100% - 36px));
}

.avatar-shell:fullscreen .player {
  margin-top: 0;
  flex: 0 0 auto;
  padding: 8px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.32);
}

.avatar-shell:fullscreen .audio {
  margin-top: 0;
}

.script {
  white-space: pre-wrap;
  line-height: 1.55;
  color: rgba(255,255,255,0.88);
}

.board-timing-plan {
  margin: 12px 0 0;
  padding-left: 24px;
  display: grid;
  gap: 8px;
}

.board-timing-plan li {
  color: rgba(255, 255, 255, 0.9);
}

.board-timing-stamp {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-weight: 700;
  color: rgba(34, 197, 94, 0.95);
  margin-right: 8px;
}

.score { display: flex; gap: 16px; align-items: baseline; margin-top: 10px; }
.score-big { font-size: 38px; font-weight: 800; }

.explanation pre {
  margin: 12px 0 0;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(11, 16, 32, 0.65);
  backdrop-filter: blur(10px);
  z-index: 1000;
}

.loading-overlay[hidden] {
  display: none !important;
}

.qa-modal {
  width: min(760px, 100%);
  max-height: 85vh;
  overflow: auto;
}

.qa-board-modal {
  width: min(1320px, 100%);
}

.qa-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.qa-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.qa-error {
  margin-top: 10px;
  color: rgba(239, 68, 68, 0.95);
}

.qa-answer {
  margin-top: 12px;
  white-space: pre-wrap;
  line-height: 1.55;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.22);
  padding: 12px;
}

.qa-board-layout {
  display: grid;
  grid-template-columns: minmax(320px, 0.92fr) minmax(0, 1.08fr);
  gap: 16px;
  margin-top: 14px;
}

.qa-board-compose,
.qa-board-preview-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.qa-board-text {
  min-height: 180px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(244, 247, 250, 0.96)),
    linear-gradient(180deg, rgba(148, 163, 184, 0.10), rgba(148, 163, 184, 0));
  color: #0f172a;
  font: 22px/1.45 "Bradley Hand", "Segoe Print", "Comic Sans MS", ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial;
}

.qa-board-builder,
.qa-board-drawing-stack {
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  padding: 14px;
}

.qa-board-builder-head,
.qa-board-preview-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.qa-board-kind-select {
  width: min(260px, 100%);
}

.qa-board-fields {
  margin-top: 14px;
}

.qa-board-field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.qa-board-field-grid[hidden] {
  display: none !important;
}

.qa-board-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.qa-board-field-help {
  margin: 0 0 2px;
}

.qa-board-field-full {
  grid-column: 1 / -1;
}

.qa-board-command-shell {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.qa-board-command-shell code {
  display: block;
  overflow-x: auto;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  background: rgba(15, 23, 42, 0.56);
  color: rgba(248, 250, 252, 0.98);
  padding: 10px 12px;
}

.qa-board-builder-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.qa-board-drawing-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.qa-board-drawing-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  background: rgba(15, 23, 42, 0.36);
}

.qa-board-drawing-copy {
  min-width: 0;
}

.qa-board-drawing-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(148, 163, 184, 0.92);
}

.qa-board-drawing-command {
  display: block;
  margin-top: 6px;
  color: rgba(226, 232, 240, 0.98);
  word-break: break-word;
}

.qa-board-drawing-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.qa-board-preview-stage {
  min-height: 420px;
  background:
    radial-gradient(circle at top left, rgba(34, 197, 94, 0.10), transparent 32%),
    radial-gradient(circle at 80% 10%, rgba(124, 58, 237, 0.12), transparent 30%),
    rgba(2, 6, 23, 0.94);
}

@media (max-width: 1100px) {
  .qa-board-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .qa-board-field-grid {
    grid-template-columns: 1fr;
  }

  .qa-board-builder-head,
  .qa-board-preview-head {
    flex-direction: column;
  }

  .qa-board-kind-select {
    width: 100%;
  }

  .qa-board-drawing-item {
    flex-direction: column;
  }

  .qa-board-drawing-actions {
    justify-content: flex-start;
  }

  .qa-board-preview-stage {
    min-height: 320px;
  }
}

.loading-card {
  display: flex;
  align-items: center;
  gap: 12px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.35);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  max-width: 520px;
}

.loading-title {
  font-weight: 700;
}

.spinner {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.22);
  border-top-color: rgba(255, 255, 255, 0.92);
  animation: spin 0.9s linear infinite;
  flex: 0 0 auto;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes graph-pulse {
  0%, 100% {
    transform: scale(0.94);
    opacity: 0.78;
  }

  50% {
    transform: scale(1.08);
    opacity: 1;
  }
}

.realtime-page {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.realtime-primary {
  padding: 18px;
}

.realtime-primary-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.realtime-primary-copy {
  min-width: 0;
}

.realtime-status-row {
  gap: 8px;
  margin-bottom: 10px;
}

.realtime-lead {
  margin: 0;
  max-width: 62ch;
}

.realtime-availability {
  margin: 6px 0 0;
  max-width: 30ch;
  text-align: right;
}

.realtime-board-shell {
  margin-top: 0;
}

.realtime-lesson-stage {
  background:
    radial-gradient(circle at top left, rgba(34, 197, 94, 0.10), transparent 32%),
    radial-gradient(circle at 80% 10%, rgba(124, 58, 237, 0.12), transparent 30%),
    rgba(2, 6, 23, 0.94);
}

.realtime-player {
  margin-top: 12px;
}

.realtime-captions-shell {
  position: absolute;
  inset: auto 0 0 0;
  display: flex;
  justify-content: center;
  padding: 20px clamp(16px, 3.8vw, 44px) 28px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 140ms ease;
  background: linear-gradient(180deg, rgba(2, 6, 23, 0), rgba(2, 6, 23, 0.52));
}

.avatar-shell:fullscreen .realtime-captions-shell {
  opacity: 1;
}

.realtime-captions {
  max-width: min(82vw, 900px);
  padding: 10px 18px;
  border-radius: 18px;
  background: rgba(2, 6, 23, 0.34);
  backdrop-filter: blur(8px);
  color: rgba(248, 250, 252, 0.98);
  font-size: clamp(21px, 2.35vw, 36px);
  font-weight: 700;
  line-height: 1.28;
  letter-spacing: 0.01em;
  text-align: center;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.92);
  word-break: break-word;
}

.realtime-captions[hidden] {
  display: none !important;
}

.realtime-dashboard {
  display: grid;
  grid-template-columns: minmax(280px, 0.95fr) minmax(0, 1.3fr);
  gap: 14px;
  align-items: start;
}

.realtime-controls-stack,
.realtime-side {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.realtime-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.realtime-topic-card {
  min-height: 0;
}

.realtime-topic-note {
  margin: 12px 0 0;
}

@media (max-width: 960px) {
  .realtime-primary-head {
    flex-direction: column;
  }

  .realtime-availability {
    max-width: none;
    text-align: left;
    margin-top: 0;
  }

  .realtime-dashboard {
    grid-template-columns: 1fr;
  }
}

.realtime-thread {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 520px;
  overflow-y: auto;
  padding-right: 4px;
}

.realtime-thread-empty {
  color: var(--muted);
  line-height: 1.6;
}

.realtime-turn {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.04);
}

.realtime-turn.user {
  background: rgba(34, 197, 94, 0.08);
  border-color: rgba(34, 197, 94, 0.18);
}

.realtime-turn.assistant {
  background: rgba(124, 58, 237, 0.1);
  border-color: rgba(124, 58, 237, 0.22);
}

.realtime-turn-role {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 6px;
}

.realtime-turn-text {
  white-space: pre-wrap;
  line-height: 1.55;
  color: rgba(255, 255, 255, 0.92);
}

.realtime-error {
  margin: 10px 0 0;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(239, 68, 68, 0.28);
  background: rgba(127, 29, 29, 0.22);
  color: rgba(254, 226, 226, 0.98);
}

.debug-panel { margin-top: 14px; }
.debug-panel > summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--muted);
}
.debug-panel > summary:hover { color: var(--text); }
.debug-panel[open] > summary { margin-bottom: 6px; color: var(--text); }
.debug-section { margin-top: 12px; }
.debug-beats { margin: 8px 0 0; padding-left: 20px; }
.debug-beats li { margin-bottom: 8px; }
.debug-table-wrap { overflow-x: auto; }
.debug-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.debug-table th,
.debug-table td {
  text-align: left;
  vertical-align: top;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}
.debug-table th { color: var(--muted); font-weight: 600; }
.debug-table td:first-child { color: var(--muted); white-space: nowrap; }
