/* kid-english 全站样式
   约定:角色状态 = SVG 根元素上的 char--<state> class(characters.js 只切 class,动画全在这里)
   舞台 = .stage,恒定 16:9 居中 letterbox,手机横屏与电视镜像观感一致 */

:root {
  --cream: #FFF7EC;
  --ink: #4A4038;
  --ink-soft: #8A7B6E;
  --sun: #FFD9A0;
  --sun-deep: #F5B85C;
  --kitty: #F49BAB;
  --puppy: #F9C97C;
  --bunny: #BFD8F5;
  --panda: #9FD8A9;
  --sky: #CDEBFF;
  --grass: #C8E8B0;
  --card: #FFFFFF;
  --shadow: 0 6px 0 rgba(74, 64, 56, .12);
  --radius: 26px;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: "PingFang SC", "Hiragino Sans GB", "Comic Sans MS", system-ui, sans-serif;
  background: var(--cream);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  position: fixed;
  inset: 0;
}

button {
  font-family: inherit;
  border: none;
  background: none;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

/* ---------- 16:9 舞台 ---------- */

.stage-wrap {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--cream);
}

.stage {
  position: relative;
  width: min(100vw, calc(100dvh * 16 / 9));
  height: min(100dvh, calc(100vw * 9 / 16));
  overflow: hidden;
  background: var(--sky);
}

/* 场景背景(纯 CSS,零图片) */
.bg-meadow { background: linear-gradient(180deg, #BFE5FF 0%, #DDF3FF 52%, #C8E8B0 52%, #B4DE9A 100%); }
.bg-picnic { background: linear-gradient(180deg, #FFE9C9 0%, #FFF4E0 50%, #F7D9A8 50%, #F2C98D 100%); }
.bg-night  { background: linear-gradient(180deg, #2E3A5C 0%, #46527A 70%, #39466B 100%); }
.bg-home   { background: linear-gradient(180deg, #CDEBFF 0%, #EAF7FF 55%, var(--cream) 55%, #FFF1DB 100%); }

.bg-sun {
  position: absolute; top: 6%; right: 7%;
  width: 11%; aspect-ratio: 1; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #FFE9A8, var(--sun-deep));
  box-shadow: 0 0 40px rgba(245, 184, 92, .55);
}
.bg-cloud {
  position: absolute;
  width: 16%; height: 9%;
  background: #FFFFFF; border-radius: 999px; opacity: .9;
}
.bg-cloud::before, .bg-cloud::after {
  content: ""; position: absolute; background: #fff; border-radius: 50%;
  width: 55%; aspect-ratio: 1; top: -46%; left: 12%;
}
.bg-cloud::after { width: 42%; left: 50%; top: -28%; }
.bg-cloud.c2 { animation-delay: -14s; }
@keyframes cloud-drift { from { transform: translateX(-24vw); } to { transform: translateX(110vw); } }
.bg-cloud { animation: cloud-drift 42s linear infinite; }

.bg-moon {
  position: absolute; top: 8%; right: 10%;
  width: 10%; aspect-ratio: 1; border-radius: 50%;
  background: #FFF3C9; box-shadow: 0 0 34px rgba(255, 243, 201, .7);
}
.bg-star { position: absolute; color: #FFF3C9; font-size: clamp(10px, 2.2vw, 22px); animation: star-tw 2.6s ease-in-out infinite; }
.bg-star:nth-child(2n) { animation-delay: -1.3s; }
@keyframes star-tw { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }

/* ---------- 角色与状态机 ---------- */

.char-box {
  position: absolute;
  width: 30%;
  bottom: 4%;
  filter: drop-shadow(0 10px 6px rgba(74, 64, 56, .14));
}
.char-box.pos-left  { left: 8%; }
.char-box.pos-right { right: 8%; }
.char-box.pos-right .char { transform: scaleX(-1); }
.char-box.pos-solo  { left: 50%; transform: translateX(-50%); width: 34%; }

.char { width: 100%; height: auto; display: block; overflow: visible; }
/* 只给做 CSS 动画的分组设 fill-box;不能给所有元素设,否则 SVG 属性 rotate(a x y) 的坐标基准被破坏 */
.char .g-root, .char .g-head,
.char .g-arm-l, .char .g-arm-r,
.char .g-ear-l, .char .g-ear-r {
  transform-box: fill-box;
  transform-origin: center;
}

/* 默认:闭嘴、睁眼 */
.char .g-mouth-open   { opacity: 0; }
.char .g-eyes-closed  { opacity: 0; }

/* idle:呼吸浮动 + 定时眨眼 */
.char .g-root { animation: kid-bob 3.2s ease-in-out infinite; transform-origin: center 80%; }
@keyframes kid-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-2.2%); } }
.char .g-eyes-open   { animation: kid-blink-open 4.4s step-end infinite; }
.char .g-eyes-closed { animation: kid-blink-closed 4.4s step-end infinite; }
@keyframes kid-blink-open   { 0%, 92% { opacity: 1; } 93%, 99% { opacity: 0; } 100% { opacity: 1; } }
@keyframes kid-blink-closed { 0%, 92% { opacity: 0; } 93%, 99% { opacity: 1; } 100% { opacity: 0; } }

/* talking:嘴巴开合(音频播放中一直挂着) */
.char--talking .g-mouth-open   { animation: kid-flap-a 0.34s step-end infinite; }
.char--talking .g-mouth-closed { animation: kid-flap-b 0.34s step-end infinite; }
@keyframes kid-flap-a { 0% { opacity: 1; } 55% { opacity: 0; } 100% { opacity: 1; } }
@keyframes kid-flap-b { 0% { opacity: 0; } 55% { opacity: 1; } 100% { opacity: 0; } }

/* happy:跳一跳 + 双手举起 */
.char--happy .g-root { animation: kid-jump .55s ease-in-out 2; }
@keyframes kid-jump { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-7%); } }
.char--happy .g-arm-l { animation: kid-armup-l .55s ease-in-out 2; transform-origin: 80% 20%; }
.char--happy .g-arm-r { animation: kid-armup-r .55s ease-in-out 2; transform-origin: 20% 20%; }
@keyframes kid-armup-l { 0%, 100% { transform: rotate(0); } 45% { transform: rotate(-52deg); } }
@keyframes kid-armup-r { 0%, 100% { transform: rotate(0); } 45% { transform: rotate(52deg); } }

/* wave:招手(右臂,镜像时视觉是靠里那只) */
.char--wave .g-arm-r { animation: kid-wave .5s ease-in-out 3; transform-origin: 30% 15%; }
@keyframes kid-wave { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(58deg); } }

/* thinking:歪头思考 */
.char--thinking .g-head { animation: kid-tilt 1.6s ease-in-out infinite; transform-origin: center 90%; }
@keyframes kid-tilt { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(-6deg); } }
.char-box .bubble {
  position: absolute; top: -6%; right: -4%;
  background: #fff; border-radius: 18px; padding: .35em .7em;
  font-size: clamp(14px, 2.6vw, 26px); color: var(--ink-soft);
  box-shadow: var(--shadow); opacity: 0; transition: opacity .25s;
}
.char-box.show-bubble .bubble { opacity: 1; }
.char-box .bubble .dots::after { content: "…"; animation: kid-dots 1.2s step-end infinite; }
@keyframes kid-dots { 0% { content: "·"; } 33% { content: "··"; } 66% { content: "···"; } }

/* listening:耳朵动 + 声波圈 */
.char--listening .g-ear-l { animation: kid-ear 0.7s ease-in-out infinite; transform-origin: 70% 90%; }
.char--listening .g-ear-r { animation: kid-ear 0.7s ease-in-out infinite reverse; transform-origin: 30% 90%; }
@keyframes kid-ear { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(7deg); } }

/* sleepy:闭眼慢摇 */
.char--sleepy .g-eyes-open  { opacity: 0 !important; animation: none; }
.char--sleepy .g-eyes-closed { opacity: 1 !important; animation: none; }
.char--sleepy .g-root { animation: kid-bob 5s ease-in-out infinite; }
.char--sleepy .g-mouth-open { opacity: 0 !important; }

/* ---------- 通用 UI ---------- */

.top-bar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 2.2% 3%;
  z-index: 30;
}
.top-title {
  font-size: clamp(16px, 3vw, 30px);
  font-weight: 700;
  color: var(--ink);
  background: rgba(255, 255, 255, .75);
  border-radius: 999px;
  padding: .3em .9em;
  box-shadow: var(--shadow);
}
.btn-home, .btn-gear {
  width: clamp(48px, 7vw, 72px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(255, 255, 255, .85);
  box-shadow: var(--shadow);
  font-size: clamp(22px, 3.4vw, 36px);
  display: grid; place-items: center;
}
.btn-gear { opacity: .65; }

.btn-big {
  min-height: 88px;
  padding: .5em 1.2em;
  border-radius: var(--radius);
  background: var(--sun);
  box-shadow: 0 8px 0 var(--sun-deep);
  font-size: clamp(22px, 4.2vw, 42px);
  font-weight: 700;
  color: var(--ink);
  transition: transform .08s;
}
.btn-big:active { transform: translateY(6px); box-shadow: 0 2px 0 var(--sun-deep); }
.btn-big.secondary { background: #fff; box-shadow: 0 8px 0 #E3D9CC; }

/* 全屏遮罩(开始/结束/晚安/家长门/竖屏提示) */
.overlay {
  position: absolute; inset: 0; z-index: 50;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 4%;
  background: rgba(255, 247, 236, .94);
  text-align: center;
  padding: 4%;
}
.overlay.hidden { display: none; }
.overlay h1 { font-size: clamp(26px, 5vw, 52px); }
.overlay .hint { color: var(--ink-soft); font-size: clamp(15px, 2.4vw, 24px); }
.overlay .emoji-big { font-size: clamp(60px, 12vw, 130px); line-height: 1; }

/* 底部中文小字幕(给家长看) */
.subtitle {
  position: absolute; bottom: 3%; left: 50%;
  transform: translateX(-50%);
  max-width: 64%;
  background: rgba(255, 255, 255, .85);
  color: var(--ink-soft);
  border-radius: 999px;
  padding: .35em 1.1em;
  font-size: clamp(14px, 2.4vw, 24px);
  z-index: 20;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  opacity: 0; transition: opacity .25s;
}
.subtitle.show { opacity: 1; }
.subtitle .en { color: var(--ink); font-weight: 700; margin-right: .6em; }

/* ---------- 首页 ---------- */

.home-panda { position: absolute; left: 4%; bottom: 2%; width: 24%; }
.home-title {
  position: absolute; top: 5%; left: 50%; transform: translateX(-50%);
  font-size: clamp(28px, 5.4vw, 56px); font-weight: 900;
  color: var(--ink); letter-spacing: .06em;
  text-shadow: 0 3px 0 #fff;
  z-index: 5; white-space: nowrap;
}
.home-cards {
  position: absolute; top: 19%; right: 3%; left: 30%;
  bottom: 3%;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: minmax(0, 1fr);
  gap: 2.4%;
  z-index: 10;
  align-content: center;
}
.home-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 2%;
  padding: 3%;
  border-bottom: 8px solid var(--sun);
  min-height: 0;
}
.home-card:active { transform: scale(.96); }
.home-card .icon { font-size: clamp(34px, 7vw, 76px); line-height: 1.15; }
.home-card .name { font-size: clamp(15px, 2.6vw, 26px); font-weight: 700; }
.home-card .name-en { font-size: clamp(11px, 1.8vw, 18px); color: var(--ink-soft); }
.home-card.card-chat { border-bottom-color: var(--panda); }
.home-card.card-scene { border-bottom-color: var(--kitty); }
.home-card.card-vocab { border-bottom-color: var(--bunny); }

/* ---------- 情景剧 / 词卡 ---------- */

.play-center {
  position: absolute; inset: 0; z-index: 40;
  display: grid; place-items: center;
  background: rgba(255, 247, 236, .5);
}
.btn-play {
  width: clamp(110px, 18vw, 190px);
  aspect-ratio: 1; border-radius: 50%;
  background: var(--sun);
  box-shadow: 0 10px 0 var(--sun-deep);
  font-size: clamp(48px, 9vw, 96px);
  display: grid; place-items: center;
}
.btn-play:active { transform: translateY(8px); box-shadow: 0 2px 0 var(--sun-deep); }

.vocab-card {
  position: absolute; top: 12%; left: 50%; transform: translateX(-50%);
  width: 44%; height: 66%;
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2%;
  z-index: 10;
}
.vocab-card .emoji { font-size: clamp(80px, 16vw, 170px); line-height: 1.1; }
.vocab-card .word { font-size: clamp(34px, 6.5vw, 68px); font-weight: 900; letter-spacing: .04em; }
.vocab-card .zh { font-size: clamp(16px, 2.8vw, 28px); color: var(--ink-soft); }
.vocab-host { width: 20%; left: 3%; bottom: 3%; }
.btn-arrow {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: clamp(60px, 9vw, 96px); aspect-ratio: 1; border-radius: 50%;
  background: rgba(255,255,255,.9); box-shadow: var(--shadow);
  font-size: clamp(28px, 4.6vw, 48px);
  z-index: 15;
}
.btn-arrow.prev { left: 2%; }
.btn-arrow.next { right: 2%; }
.btn-sound {
  position: absolute; right: 24%; bottom: 6%;
  width: clamp(64px, 10vw, 104px); aspect-ratio: 1; border-radius: 50%;
  background: var(--sun); box-shadow: 0 7px 0 var(--sun-deep);
  font-size: clamp(30px, 5vw, 52px);
  z-index: 15;
}
.progress-dots {
  position: absolute; top: 4.5%; left: 50%; transform: translateX(-50%);
  display: flex; gap: 10px; z-index: 15;
}
.progress-dots i {
  width: clamp(10px, 1.6vw, 16px); aspect-ratio: 1; border-radius: 50%;
  background: rgba(255,255,255,.85); box-shadow: inset 0 0 0 2px rgba(74,64,56,.15);
}
.progress-dots i.on { background: var(--sun-deep); }

/* 大麦克风(陪聊 & try_it) */
.btn-mic {
  position: absolute; bottom: 9%; right: 4%;
  width: clamp(110px, 17vw, 190px);
  aspect-ratio: 1; border-radius: 50%;
  background: var(--kitty);
  box-shadow: 0 10px 0 #D97B8D;
  font-size: clamp(46px, 8vw, 92px);
  display: grid; place-items: center;
  z-index: 40;
  transition: transform .1s;
}
.btn-mic:active, .btn-mic.recording { transform: scale(1.06); }
.btn-mic.recording { animation: mic-pulse 1s ease-out infinite; }
@keyframes mic-pulse {
  0%   { box-shadow: 0 10px 0 #D97B8D, 0 0 0 0 rgba(244, 155, 171, .6); }
  100% { box-shadow: 0 10px 0 #D97B8D, 0 0 0 34px rgba(244, 155, 171, 0); }
}
.mic-label {
  position: absolute; bottom: 3%; right: 4%;
  width: clamp(110px, 17vw, 190px); text-align: center;
  color: var(--ink-soft); font-size: clamp(13px, 2vw, 20px); z-index: 40;
}
.btn-skip {
  position: absolute; left: 3%; bottom: 4%;
  padding: .4em 1em; border-radius: 999px;
  background: rgba(255,255,255,.8); color: var(--ink-soft);
  font-size: clamp(13px, 2vw, 20px); z-index: 41;
}

/* 彩带 + 星星庆祝 */
.confetti { position: absolute; inset: 0; pointer-events: none; z-index: 45; overflow: hidden; }
.confetti i {
  position: absolute; top: -6%;
  width: 12px; height: 20px; border-radius: 3px;
  animation: conf-fall 1.9s ease-in forwards;
}
.confetti i.star {
  width: auto; height: auto; background: none !important; border-radius: 0;
  font-size: clamp(20px, 3.6vw, 40px); font-style: normal;
  animation: conf-fall 2.3s ease-in forwards;
}
@keyframes conf-fall {
  0%   { transform: translateY(0) rotate(0); opacity: 1; }
  100% { transform: translateY(110vh) rotate(560deg); opacity: .8; }
}

/* 贴纸墙 */
.sticker-wall { display: flex; gap: 4%; font-size: clamp(44px, 9vw, 96px); }
.sticker-wall .got { filter: none; }
.sticker-wall .not { filter: grayscale(1) opacity(.35); }

/* ---------- 陪聊 ---------- */

.chat-panda { width: 32%; left: 50%; transform: translateX(-50%); bottom: 18%; }
.chat-status {
  position: absolute; top: 6%; left: 50%; transform: translateX(-50%);
  font-size: clamp(16px, 2.8vw, 28px); color: var(--ink-soft);
  background: rgba(255,255,255,.8); border-radius: 999px; padding: .3em 1em;
  z-index: 20;
}
.debug-row {
  position: absolute; bottom: 26%; left: 50%; transform: translateX(-50%);
  display: flex; gap: 8px; z-index: 60; width: 60%;
}
.debug-row input {
  flex: 1; font-size: 18px; padding: .5em .8em;
  border-radius: 12px; border: 2px solid var(--sun-deep);
}
.debug-row button { background: var(--sun); border-radius: 12px; padding: 0 1em; font-size: 18px; }

/* ---------- 家长页 ---------- */

.parent-page {
  position: absolute; inset: 0; overflow-y: auto;
  padding: 4% 6%;
  background: var(--cream);
  -webkit-user-select: text; user-select: text;
}
.parent-page h1 { font-size: clamp(22px, 4vw, 36px); margin-bottom: .6em; }
.parent-section {
  background: #fff; border-radius: 18px; box-shadow: var(--shadow);
  padding: 4%; margin-bottom: 4%;
}
.parent-section h2 { font-size: clamp(17px, 2.8vw, 26px); margin-bottom: .6em; }
.chip-row { display: flex; flex-wrap: wrap; gap: 10px; }
.chip {
  padding: .5em 1.1em; border-radius: 999px;
  background: #F3EBDF; font-size: clamp(15px, 2.4vw, 22px);
}
.chip.on { background: var(--sun); font-weight: 700; }
.switch-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: .55em 0; border-bottom: 1px dashed #EADFCE;
  font-size: clamp(15px, 2.4vw, 22px);
}
.switch-row:last-child { border-bottom: none; }
.health-list { font-size: clamp(14px, 2.2vw, 20px); line-height: 1.9; color: var(--ink-soft); }
.parent-note { color: var(--ink-soft); font-size: clamp(13px, 2vw, 18px); line-height: 1.7; }

/* 家长门(算术) */
.gate-q { font-size: clamp(30px, 6vw, 60px); font-weight: 900; letter-spacing: .1em; }
.gate-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: min(58vw, 320px); }
.gate-pad button {
  font-size: clamp(22px, 4vw, 34px); font-weight: 700;
  background: #fff; border-radius: 16px; box-shadow: var(--shadow);
  min-height: 56px;
}
.gate-input { font-size: clamp(26px, 5vw, 48px); letter-spacing: .2em; min-height: 1.3em; }

/* ---------- 晚安收尾 ---------- */
.overlay.sleep { background: rgba(46, 58, 92, .96); color: #FFF3C9; }
.overlay.sleep .hint { color: #C9D4F0; }

/* ---------- 竖屏提示 ---------- */
.rotate-tip { display: none; }
@media (orientation: portrait) {
  .rotate-tip {
    display: flex; position: fixed; inset: 0; z-index: 999;
    flex-direction: column; align-items: center; justify-content: center; gap: 16px;
    background: var(--cream); text-align: center; padding: 8%;
  }
  .rotate-tip .emoji-big { font-size: 17vw; animation: rot-hint 1.6s ease-in-out infinite; }
  @keyframes rot-hint { 0%, 100% { transform: rotate(0); } 55% { transform: rotate(90deg); } }
  .rotate-tip p { font-size: 5.4vw; font-weight: 700; }
  .rotate-tip .hint { font-size: 3.6vw; color: var(--ink-soft); }
}
/* 家长页竖屏可用,不拦 */
body.allow-portrait .rotate-tip { display: none; }

/* ---------- 降噪 ---------- */
@media (prefers-reduced-motion: reduce) {
  .char .g-root, .bg-cloud, .char--thinking .g-head,
  .char--listening .g-ear-l, .char--listening .g-ear-r { animation: none !important; }
}
