:root {
  font-family: 'Nunito', sans-serif;
  color: #663a20;
  background: #fff8df;
  font-synthesis: none;
  --qa-border: #c87a21;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(ellipse at 12% 10%, #fffdf1 0, transparent 38%),
    radial-gradient(ellipse at 88% 92%, #e5f6ff 0, transparent 37%), #fff8df;
}
.companion-shell { max-width: 1180px; margin: auto; padding: 18px 24px 14px; }
.topbar { height: 54px; display: flex; align-items: center; justify-content: space-between; }
.back-link, .level-pill { border-radius: 999px; background: #fff; padding: 9px 15px; text-decoration: none; color: #8a4b24; font-weight: 900; box-shadow: 0 4px 12px #70432212; }
.brand img { height: 42px; max-width: 150px; object-fit: contain; }
.level-pill { font-size: .7rem; letter-spacing: .08em; color: #875100; background: #ffe8a2; }
.companion-card { margin-top: 9px; padding: 23px 32px 26px; border: 1px solid #f1dfa5; border-radius: 30px; background: #ffffffed; box-shadow: 0 20px 55px #80652b18; }
.intro { text-align: center; margin-bottom: 13px; }
.eyebrow { margin: 0; color: #e58429; font-weight: 1000; font-size: .7rem; letter-spacing: .16em; }
.intro h1 { margin: 2px 0; font: 700 clamp(1.8rem, 3vw, 2.6rem)/1.1 'Fredoka', sans-serif; color: #874718; }
.intro-copy { margin: 6px 0 0; color: #8d765b; font-weight: 700; }
.conversation-layout { display: grid; grid-template-columns: minmax(360px, 1fr) minmax(360px, .92fr); gap: 30px; align-items: stretch; }
.character-column { min-width: 0; display: flex; flex-direction: column; align-items: center; }
.speech-card { position: relative; width: min(100%, 470px); min-height: 76px; margin: 0 auto 5px; padding: 15px 52px 14px 19px; border: 2px solid #ffe5a0; border-radius: 22px; background: #fffdf7; box-shadow: 0 8px 18px #9b6e2720; }
.speech-card:after { content: ''; position: absolute; left: 50%; bottom: -10px; width: 18px; height: 18px; transform: translateX(-50%) rotate(45deg); background: #fffdf7; border-right: 2px solid #ffe5a0; border-bottom: 2px solid #ffe5a0; }
.speech-card p { margin: 0; font: 700 1.05rem/1.35 'Fredoka', sans-serif; color: #633e26; }
.speech-stars { position: absolute; left: 10px; top: -13px; color: #ffc34e; font-size: 1.3rem; }
.replay-button { position: absolute; right: 9px; top: 50%; transform: translateY(-50%); width: 38px; height: 38px; border: 0; border-radius: 50%; background: #fff1c4; font-size: 1.05rem; cursor: pointer; }
.replay-button:disabled { opacity: .4; cursor: default; }
.bili-stage { position: relative; width: min(100%, 480px); height: 360px; margin: 0 auto; overflow: hidden; border-radius: 48% 48% 32px 32px; background: radial-gradient(ellipse at 50% 87%, #fff0c9 0, #fff8e6 48%, transparent 49%); }
.bili-canvas { position: absolute; inset: 0; display: grid; place-items: center; }
.bili-pixel-sprite {
  width: 100%;
  height: 100%;
  background: url('assets/mascot/bili_pixel_idle.png') center bottom 5% / auto 94% no-repeat;
  image-rendering: pixelated;
}
.bili-stage[data-state="idle"] .bili-pixel-sprite { animation: bili-idle 1.8s ease-in-out infinite; }
.bili-stage[data-state="greeting"] .bili-pixel-sprite,
.bili-stage[data-state="talking"] .bili-pixel-sprite { animation: bili-talk .55s steps(2) infinite; }
.bili-stage[data-state="listening"] .bili-pixel-sprite { animation: bili-listen .9s ease-in-out infinite; }
.bili-stage[data-state="celebrate"] .bili-pixel-sprite {
  background-image: url('assets/mascot/bili_pixel_celebrate.png');
  animation: bili-jump .55s steps(2) infinite;
}
.bili-stage[data-state="retry"] .bili-pixel-sprite {
  background-image: url('assets/mascot/bili_pixel_walk_strip.png');
  background-size: 400% 100%;
  background-position: 0 100%;
  animation: bili-walk .68s steps(4) infinite;
}
@keyframes bili-idle { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes bili-talk { 0%, 100% { transform: translateY(0) rotate(-1deg); } 50% { transform: translateY(-7px) rotate(1deg); } }
@keyframes bili-listen { 0%, 100% { transform: translateY(0) scale(1); } 50% { transform: translateY(-4px) scale(1.025); } }
@keyframes bili-jump { 0%, 100% { transform: translateY(0) scale(1, 1); } 10% { transform: translateY(2px) scale(1.07, .9); } 44% { transform: translateY(-34px) scale(.96, 1.08); } 72% { transform: translateY(-13px) scale(1.02, .98); } 86% { transform: translateY(1px) scale(1.04, .92); } }
@keyframes bili-walk { from { background-position-x: 0%; } to { background-position-x: 100%; } }
.stage-sparkle { position: absolute; z-index: 2; opacity: 0; pointer-events: none; color: #ffbf3f; font-size: 1.8rem; animation: sparkle 1.1s ease-in-out infinite alternate; }
.sparkle-one { left: 13%; top: 28%; }
.sparkle-two { right: 12%; top: 39%; animation-delay: .25s; }
.character-caption { margin: -1px 0 0; color: #8293a4; font-size: .82rem; font-weight: 900; }
.bili-stage[data-state="celebrate"] .stage-sparkle { opacity: 1; }
.bili-stage[data-state="thinking"] .stage-sparkle { opacity: .7; }
.chat-column { padding: 24px 24px 20px; border-radius: 24px; background: #fffaf0; border: 1px solid #f6e5b7; display: flex; flex-direction: column; justify-content: center; }
.conversation-heading { display: flex; gap: 13px; align-items: center; }
.conversation-icon { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 16px; background: #fff0c4; font-size: 1.55rem; }
.conversation-heading h2 { margin: 0; font: 700 1.3rem 'Fredoka', sans-serif; color: #75451f; }
.conversation-heading p { margin: 2px 0 0; font-size: .83rem; color: #9b8467; font-weight: 700; }
.progress-track { height: 9px; margin: 20px 0 13px; border-radius: 99px; background: #eee5d1; overflow: hidden; }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #f9bd43, #ff8a36); transition: width .4s ease; }
.round-dots { display: flex; gap: 8px; margin-bottom: 13px; }
.round-dots span { width: 12px; height: 12px; border: 2px solid #e5d8be; border-radius: 50%; background: white; }
.round-dots span.done { border-color: #45b68a; background: #45b68a; box-shadow: 0 0 0 3px #45b68a22; }
.round-dots span.current { border-color: #f4ae37; background: #ffe3a0; }
.reply-hint { margin: 4px 0 14px; color: #80674c; font-weight: 900; font-size: 1.02rem; line-height: 1.45; min-height: 45px; }
.start-button, .mic-button, .next-button { display: flex; justify-content: center; align-items: center; gap: 10px; width: 100%; min-height: 58px; margin-top: 4px; border: 0; border-radius: 18px; color: white; font: 900 1.05rem 'Nunito', sans-serif; cursor: pointer; transition: transform .15s, filter .15s; }
.start-button, .next-button { background: linear-gradient(100deg, #f5a51b, #e87919); box-shadow: 0 6px 0 #bc5d12; }
.mic-button { background: linear-gradient(100deg, #35b990, #2296a8); box-shadow: 0 6px 0 #167b78; }
.mic-button.listening { background: linear-gradient(100deg, #e45555, #bf3b61); box-shadow: 0 6px 0 #972a48; animation: pulse 1s ease-in-out infinite; }
.start-button:hover, .mic-button:hover, .next-button:hover { filter: brightness(1.04); transform: translateY(-2px); }
.start-button:active, .mic-button:active, .next-button:active { transform: translateY(4px); box-shadow: 0 2px 0 #824312; }
.start-button[hidden], .mic-button[hidden], .next-button[hidden] { display: none; }
.feedback { min-height: 24px; margin: 11px 0 0; text-align: center; font-weight: 900; color: #5b9778; }
.feedback.error { color: #bd673d; }
.privacy-note { margin: 16px 0 0; color: #968a77; font-size: .72rem; line-height: 1.45; font-weight: 700; text-align: center; }
.companion-shell footer { padding: 11px 0 0; color: #9b8e77; text-align: center; font-size: .76rem; font-weight: 800; }
.qa-panel { margin-top: 14px; padding: 11px; border: 1px dashed var(--qa-border); border-radius: 12px; background: #fff4d8; color: #6e451f; font-size: .76rem; line-height: 1.5; }
.qa-panel strong { display: block; }
.qa-panel button { margin: 6px 8px 4px 0; padding: 7px 10px; border: 0; border-radius: 9px; background: #875100; color: #fff; font: 800 .75rem 'Nunito', sans-serif; cursor: pointer; }
.qa-panel [role="status"] { display: block; }
.qa-panel .qa-failed { color: #bd3030; font-weight: 900; }
@keyframes sparkle { from { transform: scale(.8) rotate(-10deg); } to { transform: scale(1.18) rotate(12deg); } }
@keyframes pulse { 50% { filter: brightness(1.14); transform: scale(1.015); } }
@media (max-width: 820px) {
  .companion-shell { padding: 12px 14px; }
  .companion-card { padding: 20px; }
  .conversation-layout { grid-template-columns: 1fr; gap: 8px; }
  .character-column { display: grid; grid-template-columns: minmax(240px, .85fr) minmax(220px, 1.15fr); grid-template-areas: 'model bubble' 'caption bubble'; align-items: center; }
  .speech-card { grid-area: bubble; margin: 0; max-width: none; }
  .bili-stage { grid-area: model; width: 100%; height: 285px; }
  .character-caption { grid-area: caption; text-align: center; }
  .chat-column { padding: 20px; min-height: 330px; }
}
@media (max-width: 520px) {
  .companion-shell { padding: 8px; }
  .topbar { height: 44px; }
  .brand img { height: 33px; max-width: 112px; }
  .level-pill { padding: 8px 10px; font-size: .59rem; }
  .companion-card { margin-top: 7px; padding: 16px 12px 17px; border-radius: 23px; }
  .intro { margin-bottom: 10px; }
  .intro-copy { font-size: .84rem; }
  .conversation-layout { gap: 8px; }
  .character-column { grid-template-columns: minmax(128px, .78fr) minmax(0, 1.22fr); gap: 8px; }
  .bili-stage { height: 205px; }
  .speech-card { padding: 11px 40px 11px 12px; min-height: 76px; border-radius: 17px; }
  .speech-card p { font-size: .92rem; }
  .speech-card:after { left: 25%; }
  .replay-button { right: 5px; width: 30px; height: 30px; }
  .stage-sparkle { font-size: 1.3rem; }
  .chat-column { padding: 16px 13px; min-height: unset; }
  .conversation-heading h2 { font-size: 1.1rem; }
  .reply-hint { min-height: 40px; font-size: .96rem; }
  .start-button, .mic-button, .next-button { min-height: 52px; font-size: .95rem; }
  .privacy-note { font-size: .68rem; margin-top: 13px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: .01ms !important; }
}

/* Full-screen classroom entrance shown from the home card. */
html, body { width: 100%; min-width: 0; height: 100%; overflow: hidden; background: #f8d8a5; }
.companion-shell, .companion-card, .conversation-layout, .character-column { display: contents; }
.companion-shell footer, .stage-sparkle { display: none !important; }
.topbar { position: fixed; z-index: 5; top: 14px; left: 14px; display: block; width: auto; height: auto; }
.topbar .brand, .topbar .level-pill { display: none !important; }
.topbar .back-link { display: inline-flex; align-items: center; gap: 6px; padding: 9px 14px; border: 1px solid #ffffffb8; border-radius: 999px; background: #fffaf0e8; color: #774317; font: 900 14px/1 'Nunito', sans-serif; text-decoration: none; box-shadow: 0 3px 12px #68401c28; backdrop-filter: blur(5px); }
.intro, .chat-column, .character-caption {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  clip-path: inset(50%) !important;
  white-space: nowrap !important;
  border: 0 !important;
}
.speech-card { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.bili-stage {
  position: fixed;
  z-index: 1;
  inset: 50% auto auto 50%;
  width: min(100vw, 177.7778dvh);
  height: auto;
  aspect-ratio: 16 / 9;
  margin: 0;
  overflow: hidden;
  border-radius: 0;
  background: transparent;
  transform: translate(-50%, -50%);
}
.classroom-background { position: absolute; inset: 0; display: block; width: 100%; height: 100%; object-fit: contain; }
.bili-canvas { position: absolute; inset: 0; display: block; }
.bili-pixel-sprite {
  position: absolute;
  left: 50%;
  top: 45%;
  width: 15%;
  height: 39%;
  background-position: center bottom;
  background-size: auto 100%;
  margin-left: -7.5%;
  image-rendering: pixelated;
}
.bili-stage[data-state="idle"] .bili-pixel-sprite,
.bili-stage[data-state="listening"] .bili-pixel-sprite {
  background-image: url('assets/mascot/bili_pixel_idle.png');
  background-size: auto 100%;
  animation: none;
}
.bili-stage[data-state="welcome"] .bili-pixel-sprite,
.bili-stage[data-state="talking"] .bili-pixel-sprite { background-image: url('assets/mascot/bili_pixel_idle.png'); background-size: auto 100%; animation: none; }
.bili-stage[data-state="celebrate"] .bili-pixel-sprite { animation: bili-jump .78s cubic-bezier(.32,.02,.55,1) 2; }
.bili-stage[data-state="retry"] .bili-pixel-sprite { background-image: url('assets/mascot/bili_pixel_walk_strip.png'); background-size: 400% 100%; animation: bili-walk .68s steps(4, end) infinite; }
.bili-blink { position: absolute; inset: 0; pointer-events: none; opacity: 0; background: linear-gradient(#6b3215 0 0) 35% 39% / 10% 1.8% no-repeat, linear-gradient(#6b3215 0 0) 74% 39% / 10% 1.8% no-repeat; animation: bili-blink 4.2s steps(1, end) infinite; }
@keyframes bili-breathe { 0%, 100% { transform: translateY(0) scale(1); } 48% { transform: translateY(-5px) scale(1.012, 1.018); } 56% { transform: translateY(-4px) scale(1.008, .99); } }
@keyframes bili-blink { 0%, 89%, 93%, 100% { opacity: 0; } 90%, 92% { opacity: 1; } }
.chat-column button, .speech-card button { display: none !important; }
@media (max-aspect-ratio: 4 / 5) {
  .bili-stage { width: 100vw; }
  .bili-pixel-sprite { width: 15%; height: 39%; top: 45%; margin-left: -7.5%; }
}
