/* ═════════════════ Base (shadcn-style white theme) ═════════════════ */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: "Inter", -apple-system, "SF Pro Text", "Segoe UI", Roboto,
               "Noto Sans Devanagari", sans-serif;
  background: #ffffff;
  color: #09090b;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
}
button { font: inherit; }
h3 {
  margin: 0 0 10px 0;
  font-size: 11px;
  letter-spacing: 1.3px;
  color: #71717a;
  text-transform: uppercase;
  font-weight: 500;
}
.hidden { display: none !important; }

/* ═════════════════ Grid layout ═════════════════ */
#app {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 56px 1fr 80px;
  grid-template-areas:
    "header"
    "board"
    "hud";
  height: 100%;
}
/* Board-primary (T5): hide the left panel (problem + chat); board fills width. */
#left-panel { display: none !important; }

/* ═════════════════ Header ═════════════════ */
#topbar {
  grid-area: header;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  background: #ffffff;
  border-bottom: 1px solid #e4e4e7;
}
#topic-area { display: flex; flex-direction: column; gap: 2px; }
#topic { font-size: 15px; font-weight: 600; color: #09090b; letter-spacing: -0.01em; }
#sub-topic { font-size: 12px; color: #71717a; display: flex; gap: 10px; }
#sub-topic span:empty { display: none; }
#sub-topic #step::before { content: "·"; margin-right: 8px; color: #d4d4d8; }
#sub-topic #step:empty::before { content: ""; }

#status-area { display: flex; align-items: center; gap: 10px; }
#status {
  font-size: 11px; letter-spacing: 0.4px; font-weight: 500;
  padding: 4px 10px; border-radius: 6px;
  background: #fafafa;
  border: 1px solid #e4e4e7;
  color: #71717a;
  text-transform: uppercase;
}
#status.live       { color: #16a34a; border-color: #bbf7d0; background: #f0fdf4; }
#status.listening  { color: #ca8a04; border-color: #fde68a; background: #fefce8; }
#status.error      { color: #dc2626; border-color: #fecaca; background: #fef2f2; }

.lang-btn {
  padding: 5px 11px; font-size: 12px; font-weight: 500;
  background: #ffffff;
  color: #09090b;
  border: 1px solid #e4e4e7; border-radius: 6px;
  cursor: pointer;
  transition: background 140ms, border-color 140ms;
}
.lang-btn:hover { background: #f4f4f5; }

/* ═════════════════ Left panel ═════════════════ */
#left-panel {
  grid-area: left;
  display: flex; flex-direction: column;
  background: #fafafa;
  border-right: 1px solid #e4e4e7;
  min-height: 0;
}

#problem-panel {
  padding: 20px 20px;
  border-bottom: 1px solid #e4e4e7;
  max-height: 42%;
  overflow-y: auto;
  background: #ffffff;
}
#problem-empty { color: #a1a1aa; font-size: 13px; line-height: 1.5; }
#problem-text {
  font-size: 15px; line-height: 1.55; color: #09090b;
  padding: 8px 0;
}
#problem-latex {
  padding: 14px 12px;
  background: #fafafa;
  border-radius: 8px;
  border: 1px solid #e4e4e7;
  text-align: center;
}
#problem-latex .katex { font-size: 1.3em !important; color: #09090b; }

#transcript-panel {
  flex: 1; min-height: 0;
  padding: 18px 20px;
  display: flex; flex-direction: column;
}
#transcript {
  flex: 1; overflow-y: auto;
  display: flex; flex-direction: column; gap: 10px;
  padding-right: 4px;
}
.bubble {
  max-width: 90%;
  padding: 10px 14px; border-radius: 10px;
  font-size: 13.5px; line-height: 1.5;
  word-wrap: break-word;
  animation: bubbleIn 180ms ease-out;
}
.bubble.partial { opacity: 0.7; }
.bubble.user {
  align-self: flex-end;
  background: #18181b;
  color: #fafafa;
  border-bottom-right-radius: 4px;
}
.bubble.assistant {
  align-self: flex-start;
  background: #ffffff;
  color: #09090b;
  border: 1px solid #e4e4e7;
  border-bottom-left-radius: 4px;
}
.bubble .role {
  display: block;
  font-size: 10px; letter-spacing: 0.8px; text-transform: uppercase;
  color: #a1a1aa; margin-bottom: 4px; font-weight: 500;
}
.bubble .photo {
  display: block; max-width: 100%; max-height: 180px;
  border-radius: 8px; margin-top: 2px;
}
.bubble.user .role { color: rgba(250,250,250,0.55); }
@keyframes bubbleIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ═════════════════ Board ═════════════════ */
#board {
  grid-area: board;
  position: relative;
  overflow: hidden;
  padding: 0;
  background: #ffffff;
}
#tutor-board { position: absolute; inset: 0; }
/* Handwritten "marker" font for whiteboard text — the teacher's written style.
   Only affects SVG <text> (draw_svg slides, diagram labels). Math is rendered by
   KaTeX as HTML spans, so equations keep their proper math font. */
#tutor-board text { font-family: "Caveat", "Comic Sans MS", cursive !important; }
/* Mastery panel floats top-right (its old host, the left panel, is hidden). */
#mastery-panel {
  position: fixed; top: 64px; right: 16px; width: 280px; max-height: 72vh;
  overflow: auto; background: #fff; border: 1px solid #e4e4e7; border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.14); padding: 12px 14px; z-index: 50;
}

.eq-card, .diagram-card {
  width: min(820px, 96%);
  padding: 22px 26px;
  background: #ffffff;
  border: 1px solid #e4e4e7;
  border-radius: 10px;
  box-shadow: 0 1px 2px 0 rgba(0,0,0,0.04);
  text-align: center;
  transform: translateY(6px); opacity: 0;
  animation: pop 280ms cubic-bezier(.2,.9,.3,1.1) forwards;
  transition: box-shadow 200ms, border-color 200ms, transform 200ms, opacity 200ms;
}
.eq-card .katex { font-size: 1.75em !important; color: #09090b; }
.eq-card.flash, .diagram-card.flash {
  border-color: #f59e0b;
  box-shadow: 0 0 0 2px rgba(245,158,11,0.25), 0 1px 2px 0 rgba(0,0,0,0.04);
  transform: scale(1.01);
}
.eq-card.focused, .diagram-card.focused {
  border-color: #18181b;
  box-shadow: 0 0 0 2px rgba(24,24,27,0.12), 0 1px 2px 0 rgba(0,0,0,0.04);
}
.eq-card.dimmed, .diagram-card.dimmed { opacity: 0.5; }

.diagram-card {
  width: min(880px, 97%);
  padding: 20px 22px;
  color: #09090b;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.diagram-card .caption {
  font-size: 13px; color: #52525b; font-weight: 400;
  max-width: 80ch; line-height: 1.5;
}
.diagram-card svg {
  max-width: 100%; height: auto; display: block;
  border-radius: 6px;
}
.diagram-card .plot-host { width: 100%; display: flex; justify-content: center; }
.diagram-card .plot-host svg { background: #fafafa; }
.diagram-card .number-line-host { padding: 10px 16px; width: 100%; }

/* Interactive quiz card */
.quiz-card {
  position: fixed;
  left: 50%;
  bottom: 96px;                 /* float over the board, above the footer */
  width: min(560px, 92%);
  z-index: 60;                  /* above the tldraw board + avatar */
  padding: 18px 22px;
  background: #ffffff;
  border: 1px solid #e4e4e7;
  border-radius: 12px;
  box-shadow: 0 14px 36px rgba(0,0,0,0.20);
  text-align: left;
  opacity: 0;
  transform: translateX(-50%) translateY(8px);
  animation: quizpop 240ms cubic-bezier(.2,.9,.3,1.1) forwards;
}
@keyframes quizpop { to { opacity: 1; transform: translateX(-50%) translateY(0); } }
.quiz-card.closing {
  opacity: 0; transform: translateX(-50%) translateY(10px);
  transition: opacity 250ms, transform 250ms; animation: none;
}
.quiz-card.flash {
  border-color: #f59e0b;
  box-shadow: 0 0 0 2px rgba(245,158,11,0.25), 0 1px 2px 0 rgba(0,0,0,0.04);
}
.quiz-card.dimmed { opacity: 0.5; }
.quiz-question {
  font-size: 16px; font-weight: 600; color: #09090b;
  margin-bottom: 14px; line-height: 1.45;
}
.quiz-options { display: grid; gap: 8px; }
.quiz-option {
  text-align: left; padding: 11px 14px;
  font: inherit; font-size: 14.5px; color: #09090b;
  background: #fafafa;
  border: 1px solid #d4d4d8; border-radius: 8px;
  cursor: pointer;
  transition: background 120ms, border-color 120ms;
}
.quiz-option:hover { background: #f4f4f5; border-color: #a1a1aa; }
.quiz-card.answered .quiz-option { cursor: default; opacity: 0.65; }
.quiz-card.answered .quiz-option.correct {
  background: #dcfce7; border-color: #22c55e; opacity: 1;
}
.quiz-card.answered .quiz-option.wrong {
  background: #fee2e2; border-color: #ef4444; opacity: 1;
}

@keyframes pop { to { transform: translateY(0); opacity: 1; } }

/* ═════════════════ HUD footer ═════════════════ */
#hud {
  grid-area: hud;
  display: flex; align-items: center; gap: 14px;
  padding: 0 24px;
  background: #ffffff;
  border-top: 1px solid #e4e4e7;
}

#text-form {
  flex: 1; display: flex; gap: 8px; align-items: center;
}
#text-input {
  flex: 1; padding: 10px 14px; font-size: 14px;
  color: #09090b;
  background: #ffffff;
  border: 1px solid #e4e4e7; border-radius: 8px;
  outline: none;
  transition: border-color 120ms, box-shadow 120ms;
}
#text-input:focus {
  border-color: #18181b;
  box-shadow: 0 0 0 3px rgba(24,24,27,0.08);
}
#text-input::placeholder { color: #a1a1aa; }

#photoBtn {
  padding: 9px 12px; font-size: 16px; line-height: 1;
  background: #ffffff;
  border: 1px solid #e4e4e7; border-radius: 8px;
  cursor: pointer;
  transition: background 120ms, border-color 120ms;
}
#photoBtn:hover { background: #f4f4f5; border-color: #a1a1aa; }

#sendBtn {
  padding: 10px 18px; font-size: 13.5px; font-weight: 500;
  color: #fafafa;
  background: #18181b;
  border: 1px solid #18181b; border-radius: 8px;
  cursor: pointer;
  transition: background 120ms;
}
#sendBtn:hover { background: #27272a; }
#sendBtn:disabled { opacity: 0.5; cursor: not-allowed; }

#ptt-area { display: flex; align-items: center; gap: 10px; }
.hint { color: #71717a; font-size: 12px; }
.hint kbd {
  background: #f4f4f5;
  border: 1px solid #e4e4e7;
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 6px;
  font-family: inherit;
  font-size: 11px;
  color: #18181b;
}
#pttBtn {
  padding: 10px 22px; font-size: 13.5px; font-weight: 500;
  color: #fafafa;
  background: #18181b;
  border: 1px solid #18181b; border-radius: 999px;
  cursor: pointer;
  transition: background 120ms, box-shadow 120ms;
}
#pttBtn:hover { background: #27272a; }
#pttBtn:active, #pttBtn.talking {
  background: #09090b;
  box-shadow: 0 0 0 3px rgba(24,24,27,0.12);
}

/* ═════════════════ Welcome / onboarding ═════════════════ */
#welcome {
  position: fixed; inset: 0; z-index: 50;
  background: #fafafa;
  display: flex; align-items: center; justify-content: center;
  opacity: 1;
  transition: opacity 500ms ease;
}
body:not(.onboarding) #welcome { opacity: 0; pointer-events: none; }
#welcome-card {
  width: 340px;
  margin-left: 360px; /* leaves room for the avatar, which floats to its left */
  background: #ffffff;
  border: 1px solid #e4e4e7; border-radius: 14px;
  padding: 28px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.06);
}
#welcome-card h1 { margin: 0 0 6px; font-size: 24px; color: #09090b; }
#welcome-card p { margin: 0 0 20px; font-size: 14px; color: #71717a; line-height: 1.45; }
#welcome-card label {
  display: block; margin: 12px 0 6px;
  font-size: 12px; font-weight: 600; color: #3f3f46;
  text-transform: uppercase; letter-spacing: 0.4px;
}
#welcome-card input, #welcome-card select {
  width: 100%; box-sizing: border-box;
  padding: 10px 12px;
  font: inherit; font-size: 15px; color: #09090b;
  background: #fff;
  border: 1px solid #d4d4d8; border-radius: 8px;
  outline: none;
}
#welcome-card input:focus, #welcome-card select:focus {
  border-color: #18181b;
  box-shadow: 0 0 0 3px rgba(24,24,27,0.08);
}
#welcome-card button {
  width: 100%; margin-top: 20px;
  padding: 11px 0;
  font: inherit; font-size: 15px; font-weight: 600;
  color: #fafafa; background: #18181b;
  border: none; border-radius: 8px;
  cursor: pointer;
  transition: background 120ms;
}
#welcome-card button:hover { background: #27272a; }

/* ═════════════════ Avatar ═════════════════ */
#avatar-wrap {
  position: fixed;
  left: 24px; right: auto; bottom: 96px;   /* bottom-LEFT, clear of the tldraw watermark */
  width: 180px; height: 180px;
  z-index: 6;
  pointer-events: none;
  transition: bottom 600ms ease, transform 600ms ease;
  transform-origin: bottom left;
}
/* ===== Avatar hidden for now (pending a proper SVG). Hides it in BOTH the
   onboarding welcome screen and the in-lesson corner. Delete this one block
   to restore the avatar. ===== */
#avatar-wrap { display: none !important; }
/* During onboarding the avatar sits enlarged beside the welcome card,
   then glides to its corner when the form is submitted. */
body.onboarding #avatar-wrap {
  left: auto;
  right: calc(50% + 30px);
  bottom: calc(50% - 130px);
  transform: scale(1.5);
  z-index: 60;
}
/* Live2D prototype (?avatar=live2d) — taller frame for the upper-body crop */
#avatar-wrap.live2d { width: 240px; height: 340px; }
/* Cartoon teacher (default) — head+shoulders portrait crop */
#avatar-wrap.cartoon { width: 200px; height: 246px; }
#avatar-wrap.live2d canvas {
  width: 100%; height: 100%; display: block;
  filter: drop-shadow(0 6px 14px rgba(0,0,0,0.18));
}
/* Mastery / progress panel (M2) */
#mastery-content { font-size: 13px; color: #3f3f46; }
.mastery-overall { margin-bottom: 8px; }
.mastery-list { list-style: none; margin: 0; padding: 0; }
.mastery-list li { display: flex; align-items: center; gap: 8px; margin: 5px 0; }
.mastery-topic { flex: 0 0 38%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mastery-bar { flex: 1; height: 8px; background: #e4e4e7; border-radius: 4px; overflow: hidden; }
.mastery-bar > span { display: block; height: 100%; border-radius: 4px; }
.mastery-pct { flex: 0 0 36px; text-align: right; color: #71717a; }
.mastery-empty { color: #a1a1aa; }
.mastery-achievements { margin-top: 8px; font-size: 16px; letter-spacing: 2px; }
@keyframes idleBob {
  0%,100% { transform: translateY(0) rotate(-1deg); }
  50%     { transform: translateY(-3px) rotate(1deg); }
}
/* Owl mascot — full-frame SVG, gentle idle bob */
#avatar {
  width: 100%; height: 100%;
  filter: drop-shadow(0 6px 14px rgba(0,0,0,0.18));
  pointer-events: none;
  animation: idleBob 3.2s ease-in-out infinite;
  transform-origin: 50% 100%;
}
#avatar.talking { animation: idleBob 1.4s ease-in-out infinite; }

/* Emotes — classes toggled by setAvatarEmotion (the model's `emote` tool).
   Kept after .talking so an emote wins the `animation` slot mid-speech. */
#avatar .eye-white, #avatar .ear, #avatar .wing {
  transform-box: fill-box;
  transform-origin: center;
  transition: transform 250ms ease;
}
#avatar .wing { transform-origin: 50% 10%; } /* hinge at the shoulder */
#avatar.emote-surprised .eye-white { transform: scale(1.25); }
#avatar.emote-surprised .ear { transform: translateY(-5px) scale(1.12); }
#avatar.emote-happy .eye-white { transform: scaleY(0.45); } /* squinty smile */
#avatar.emote-thinking { animation: idleBob 4.5s ease-in-out infinite; }
#avatar.emote-encouraging { animation: nod 700ms ease-in-out 2; }
#avatar.emote-celebrating { animation: hop 500ms ease-in-out 3; }
#avatar.emote-celebrating .wing-l { animation: flapL 240ms ease-in-out 6 alternate; }
#avatar.emote-celebrating .wing-r { animation: flapR 240ms ease-in-out 6 alternate; }
@keyframes nod {
  0%,100% { transform: translateY(0) rotate(0deg); }
  35%     { transform: translateY(2px) rotate(4deg); }
  70%     { transform: translateY(0) rotate(-2deg); }
}
@keyframes hop {
  0%,100% { transform: translateY(0); }
  45%     { transform: translateY(-16px); }
}
@keyframes flapL { from { transform: rotate(0deg); } to { transform: rotate(-22deg); } }
@keyframes flapR { from { transform: rotate(0deg); } to { transform: rotate(22deg); } }
#avatar-label {
  position: absolute; bottom: -4px; left: 0; right: 0;
  text-align: center; font-size: 10px; color: #a1a1aa;
  letter-spacing: 0.5px; text-transform: uppercase; font-weight: 500;
}

/* ═════════════════ Responsive (tablet / mobile) ═════════════════ */
@media (max-width: 900px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: 56px 1fr 110px;
    grid-template-areas:
      "header"
      "board"
      "hud";
  }
  #left-panel {
    border-right: none;
    border-bottom: 1px solid #e4e4e7;
    flex-direction: row;
  }
  #problem-panel {
    flex: 1; max-height: none;
    border-right: 1px solid #e4e4e7;
    border-bottom: none;
  }
  #transcript-panel { flex: 1; }
  #board { padding: 20px; }
  #hud { flex-direction: column; gap: 10px; padding: 12px 16px; height: auto; }
  #text-form { width: 100%; }
  #ptt-area { width: 100%; justify-content: space-between; }
  #avatar-wrap { width: 100px; height: 130px; right: 10px; bottom: 160px; }
  /* Onboarding stacks vertically: avatar on top, card below */
  #welcome { align-items: flex-end; padding-bottom: 8vh; }
  #welcome-card { margin-left: 0; }
  body.onboarding #avatar-wrap { right: calc(50% - 60px); bottom: 64%; transform: scale(1.15); }
}
