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

:root {
  --blue: #2f9ff0;
  --ink: #1e2b3a;
  --ink2: #5b6b7c;
  --glass: rgba(255, 255, 255, .72);
  --radius: 24px;
}

html, body { height: 100%; }
body {
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  overflow: hidden;
}

/* ============ blurred warm-classroom backdrop ============ */

#backdrop {
  position: fixed; inset: 0;
  background: linear-gradient(120deg, #e9d9bc, #dcc49c 55%, #cfb489);
  z-index: -1;
  overflow: hidden;
}
.blob { position: absolute; border-radius: 50%; filter: blur(70px); opacity: .75; }
.b1 { width: 45vw; height: 45vw; left: -8vw;  top: -12vh; background: #f6e8c9; }
.b2 { width: 34vw; height: 34vw; right: -6vw; top: 6vh;   background: #caa26b; }
.b3 { width: 30vw; height: 30vw; left: 28vw;  bottom: -14vh; background: #b9803f; opacity: .45; }
.b4 { width: 22vw; height: 22vw; right: 22vw; bottom: -6vh; background: #7fae74; opacity: .4; }

/* ============ shared glass card ============ */

.glass {
  background: var(--glass);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid rgba(255,255,255,.65);
  border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(70, 50, 20, .16);
}
.hidden { display: none !important; }

/* ============ sidebar ============ */

#sidebar {
  position: fixed;
  left: 14px; top: 14px; bottom: 14px;
  width: 76px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  z-index: 10;
}
#logo { font-size: 2rem; margin: 6px 0 10px; filter: drop-shadow(0 2px 6px rgba(0,0,0,.25)); }
#sidebar nav { display: flex; flex-direction: column; gap: 10px; }
#sidebar-bottom { margin-top: auto; }
.nav-btn {
  width: 62px;
  padding: 9px 0 7px;
  border: none;
  border-radius: 16px;
  background: rgba(255,255,255,.85);
  box-shadow: 0 4px 14px rgba(70,50,20,.14);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--ink2);
}
.nav-btn span { font-size: 1.15rem; }
.nav-btn small { font-size: .62rem; font-weight: 600; }
.nav-btn.active { background: var(--blue); color: #fff; }

/* ============ layout ============ */

#stage {
  position: fixed;
  left: 106px;
  right: 396px;
  top: 14px;
  bottom: 86px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* dashboard card */
#dashboard {
  padding: 34px 38px;
  overflow-y: auto;
  max-height: 100%;
}
#greeting { font-size: 2.3rem; font-weight: 800; letter-spacing: -.5px; }
.sub { color: var(--ink2); margin: 6px 0 18px; font-size: 1.05rem; }

#chips { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 22px; }
.chip {
  padding: 9px 18px;
  border: none;
  border-radius: 999px;
  background: rgba(255,255,255,.9);
  color: var(--ink);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(70,50,20,.1);
}
.chip.active { background: var(--blue); color: #fff; }

.card {
  background: rgba(255,255,255,.9);
  border-radius: 18px;
  box-shadow: 0 6px 22px rgba(70,50,20,.12);
}

/* subject artwork gradients */
.art-maths   { background: linear-gradient(140deg, #ff9a4d, #f2653c 55%, #7e3fae); }
.art-science { background: linear-gradient(140deg, #37b6ff, #2f7bd8 55%, #144a8f); }
.art-english { background: linear-gradient(140deg, #ff8fb1, #e35183 55%, #7c2450); }
.art-history { background: linear-gradient(140deg, #f5c33b, #cf8a2d 55%, #6e451a); }
.art-geo     { background: linear-gradient(140deg, #5fd38a, #2f9d76 55%, #145a4f); }
.art-agri    { background: linear-gradient(140deg, #cbe25b, #6fae3a 55%, #2f5d1e); }
.art-health  { background: linear-gradient(140deg, #6be5d8, #2fb3c9 55%, #145a8f); }

/* featured lesson */
#featured { display: flex; overflow: hidden; margin-bottom: 20px; }
#featart {
  flex: 0 0 38%;
  min-height: 250px;
  display: flex;
  align-items: center;
  justify-content: center;
}
#featart span {
  font-size: 4.4rem;
  filter: drop-shadow(0 6px 18px rgba(0,0,0,.35));
}
#featbody { padding: 22px 26px; flex: 1; }
#featObjectives {
  margin: 0 0 16px 18px;
  color: var(--ink2);
  font-size: .88rem;
  line-height: 1.6;
}
.badge {
  display: inline-block;
  background: var(--blue);
  color: #fff;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: 1.5px;
  padding: 5px 12px;
  border-radius: 999px;
}
#featTitle { font-size: 1.7rem; font-weight: 800; margin: 10px 0 2px; }
.by { color: var(--ink2); font-size: .85rem; margin-bottom: 8px; }
.desc { color: var(--ink2); font-size: .95rem; line-height: 1.55; margin-bottom: 16px; }
#startBtn {
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 12px 26px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(47,159,240,.45);
  transition: transform .08s;
}
#startBtn:active { transform: scale(.96); }

/* lesson library grid */
#libTitle { font-size: 1.05rem; font-weight: 700; margin: 4px 0 12px; }
#lessonGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
}
.lesson-card {
  border: none;
  padding: 0;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  transition: transform .1s, box-shadow .2s;
  font-family: inherit;
}
.lesson-card:hover { transform: translateY(-3px); box-shadow: 0 12px 28px rgba(70,50,20,.2); }
.lc-art {
  height: 84px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lc-art span { font-size: 2.2rem; filter: drop-shadow(0 4px 10px rgba(0,0,0,.3)); }
.lc-body { display: block; padding: 12px 14px 14px; }
.lc-body small { color: var(--ink2); font-size: .72rem; font-weight: 600; letter-spacing: .3px; }
.lc-body b { display: block; font-size: .95rem; margin: 4px 0 5px; color: var(--ink); }
.lc-body i { font-style: normal; color: var(--ink2); font-size: .78rem; line-height: 1.45; display: block; }

/* lesson header (during class) */
#lessonHeader { padding: 18px 28px; align-self: flex-start; }
#lessonHeader small { color: var(--ink2); letter-spacing: 1px; text-transform: uppercase; font-size: .7rem; }
#lessonHeader h2 { font-size: 1.6rem; font-weight: 800; }

/* caption */
#subtitle {
  margin-top: auto;
  margin-bottom: 12px;
  align-self: center;
  max-width: 92%;
  background: rgba(20, 25, 32, .78);
  color: #fff;
  padding: 12px 22px;
  border-radius: 14px;
  font-size: 1.08rem;
  line-height: 1.55;
  text-align: center;
}
#subtitle:empty { display: none; }

/* ============ tutor panel ============ */

#tutorPanel {
  position: fixed;
  right: 14px;
  top: 14px;
  bottom: 86px;
  width: 368px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-bottom: 18px;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(255,255,255,.5), rgba(255,244,224,.72));
}
#avatar { height: 82%; }
#teacher-name {
  margin-top: 8px;
  padding: 5px 18px;
  background: rgba(30, 43, 58, .85);
  color: #fff;
  border-radius: 999px;
  font-weight: 600;
  font-size: .9rem;
}

/* ---------- avatar animations ----------
   transform-box:fill-box scales SVG parts around their own centre —
   without it the transform happens around the canvas origin. */

/* natural blink: skin-coloured eyelids close over the eyes */
.lid {
  transform-box: fill-box;
  transform-origin: center top;
  transform: scaleY(0);
  animation: blink 4.6s infinite;
}
.eye + .eye .lid { animation-delay: .02s; }
@keyframes blink {
  0%, 93.5%, 100% { transform: scaleY(0); }
  95%, 96.5% { transform: scaleY(1); }
}

/* talking: cycle closed → parted → open (with teeth), like syllables */
#avatar.speaking .mouth-closed { animation: vA .34s steps(1) infinite; }
#avatar.speaking .mouth-mid    { animation: vB .34s steps(1) infinite; }
#avatar.speaking .mouth-wide   { animation: vC .34s steps(1) infinite; }
@keyframes vA { 0% { opacity: 1; } 30% { opacity: 0; } 100% { opacity: 0; } }
@keyframes vB { 0% { opacity: 0; } 30% { opacity: 1; } 68% { opacity: 0; } 100% { opacity: 0; } }
@keyframes vC { 0% { opacity: 0; } 68% { opacity: 1; } 100% { opacity: 1; } }

/* life-like idle: gentle breathing; subtle sway while talking */
.figure {
  transform-box: fill-box;
  transform-origin: center bottom;
  animation: breathe 4.2s ease-in-out infinite;
}
@keyframes breathe { 0%,100% { transform: scaleY(1); } 50% { transform: scaleY(1.008); } }
#avatar.speaking { animation: sway 3.2s ease-in-out infinite; }
@keyframes sway { 0%,100% { transform: rotate(0); } 50% { transform: rotate(.7deg); } }

/* real-human video avatar (fills the tutor panel when enabled) */
#avatarIdle, #avatarTalk {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* 3D teacher canvas (TalkingHead renders into this container) */
#avatar3d {
  position: absolute;
  inset: 0;
}
#avatar3d canvas { width: 100% !important; height: 100% !important; }

/* avatar loading state (shown while the locked mode loads) */
#avatarLoading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--ink2);
  font-size: .95rem;
  font-weight: 600;
}
.spinner {
  width: 42px;
  height: 42px;
  border: 4px solid rgba(47,159,240,.25);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#teacher-name { position: relative; z-index: 2; }

/* audio-driven lip sync: JS picks the mouth state per frame, so the
   generic CSS talking cycle must stand down */
#avatar.lipsync .mouth-closed,
#avatar.lipsync .mouth-mid,
#avatar.lipsync .mouth-wide { animation: none !important; }

#avatarSwitch {
  position: relative;
  z-index: 2;
  margin-top: 8px;
  border: none;
  border-radius: 999px;
  padding: 7px 14px;
  font-size: .78rem;
  font-weight: 600;
  background: rgba(255,255,255,.85);
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(0,0,0,.18);
}

/* ============ status chip ============ */

#status {
  position: fixed;
  top: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(30, 43, 58, .85);
  color: #ffd873;
  padding: 8px 22px;
  border-radius: 999px;
  font-size: .9rem;
  z-index: 12;
  max-width: 60vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============ bottom bar ============ */

#bottomBar {
  position: fixed;
  left: 106px;
  right: 396px;
  bottom: 16px;
  display: flex;
  gap: 12px;
  align-items: center;
  z-index: 11;
}
.round {
  width: 54px;
  height: 54px;
  border-radius: 50% !important;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  flex: 0 0 auto;
}
#queryBar {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px 7px 22px;
  border-radius: 999px;
}
#queryInput {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-size: 1rem;
  color: var(--ink);
}
#queryInput::placeholder { color: var(--ink2); }
#micBtn, #sendBtn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  font-size: 1.05rem;
}
#micBtn { background: transparent; }
#micBtn:disabled { opacity: .35; cursor: not-allowed; }
#micBtn.hot { background: #ffb830; box-shadow: 0 0 0 6px rgba(255,184,48,.3); }
#sendBtn { background: var(--blue); color: #fff; font-weight: 800; }

#mode {
  position: fixed;
  top: 22px;
  left: 106px;
  background: rgba(255, 255, 255, .92);
  border: 1px solid rgba(255,255,255,.7);
  color: var(--ink);
  font-size: .82rem;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(70,50,20,.18);
  z-index: 12;
  max-width: 34vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============ event log drawer ============ */

#logToggle {
  position: fixed;
  top: 20px;
  right: 396px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(30, 43, 58, .8);
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  z-index: 14;
}
#logPanel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(400px, 90vw);
  background: rgba(16, 26, 20, .95);
  color: #cfe3d5;
  z-index: 13;
  display: flex;
  flex-direction: column;
  transition: transform .25s ease;
}
#logPanel.collapsed { transform: translateX(100%); }
#logTitle {
  padding: 14px 16px;
  font-size: .85rem;
  border-bottom: 1px solid #2c4436;
  color: #ffd873;
}
#log {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: .76rem;
  line-height: 1.65;
}
.log-row { display: flex; gap: 8px; align-items: baseline; }
.log-time { color: #6b8577; }
.log-source { font-weight: 700; min-width: 52px; }
.log-type { color: #e8e2d4; }
.log-text { color: #9db8a8; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ============ small screens ============ */

@media (max-width: 1100px) {
  #tutorPanel { width: 280px; }
  #stage, #bottomBar { right: 306px; }
  #logToggle { right: 306px; }
}
@media (max-width: 820px) {
  #sidebar { display: none; }
  #tutorPanel { display: none; }
  #stage, #bottomBar { left: 14px; right: 14px; }
  #logToggle { right: 14px; }
}
