/* 小苏学数学 —— 样式（孩子页面 + 家长页面共用） */
:root {
  --bg: #fff8ec;
  --card: #ffffff;
  --text: #3b2f2a;
  --muted: #8a7b72;
  --orange: #ff8a3d;
  --orange-dark: #e9701f;
  --blue: #4da3ff;
  --green: #39b97a;
  --red: #e5534b;
  --line: #f0e3d0;
  --child: #dff0ff;
  --radius: 18px;
  --shadow: 0 4px 14px rgba(120, 80, 30, 0.1);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  font-size: 18px;
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
  overflow-x: clip;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--orange-dark); }
[hidden] { display: none !important; }

#app { width: 100%; max-width: 760px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; }

.view { display: none; min-height: 100vh; min-height: 100dvh; }
.view.active { display: block; }
.view.center.active { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; }

.muted { color: var(--muted); }
.small { font-size: 14px; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 2px solid var(--line); background: var(--card);
  border-radius: 14px; padding: 10px 18px; min-height: 48px;
  text-decoration: none; color: var(--text); font-weight: 600;
  transition: transform .1s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--orange); border-color: var(--orange); color: #fff; }
.btn.primary:disabled { opacity: .6; }
.btn.danger { color: var(--red); border-color: #f5c6c3; }
.btn.small { min-height: 36px; padding: 4px 12px; font-size: 15px; border-radius: 10px; }
.grow { flex: 1; }
.row { display: flex; gap: 10px; margin-top: 12px; }

/* ---------- 小苏 ---------- */
.owl { font-size: 72px; line-height: 1; }
.bounce { animation: bounce 1s ease-in-out infinite; }
.wave { animation: wave 2.4s ease-in-out infinite; transform-origin: 50% 90%; display: inline-block; }
@keyframes bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-12px); } }
@keyframes wave { 0%, 100% { transform: rotate(0); } 10% { transform: rotate(-10deg); } 20% { transform: rotate(8deg); } 30% { transform: rotate(0); } }

/* ---------- 首页 ---------- */
.home { padding: 28px 20px 40px; display: flex; flex-direction: column; gap: 16px; }
.home-head { text-align: center; }
.home-head h1 { margin: 8px 0 0; font-size: 30px; }
.home-head p { margin: 4px 0 0; color: var(--muted); }
.stars {
  align-self: center; background: #fff3c4; border-radius: 999px; padding: 6px 18px;
  font-size: 16px; color: #8a6200;
}
.big-card {
  display: flex; align-items: center; gap: 16px; text-align: left;
  border: none; border-radius: var(--radius); padding: 20px 22px;
  background: var(--card); box-shadow: var(--shadow); min-height: 88px;
  border-left: 8px solid var(--blue);
  transition: transform .1s;
}
.big-card:active { transform: scale(.98); }
.big-card.orange { border-left-color: var(--orange); }
.big-card.green { border-left-color: var(--green); }
.big-card.purple { border-left-color: #9b6bff; }
.big-card .emoji { font-size: 36px; }
.big-card b { display: block; font-size: 22px; }
.big-card small { display: block; color: var(--muted); font-size: 15px; margin-top: 2px; }
.tip { text-align: center; color: var(--muted); font-size: 16px; margin: 8px 0 0; }
.parent-link { align-self: center; color: var(--muted); font-size: 14px; margin-top: 12px; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.topbar .title { flex: 1; text-align: center; font-weight: 700; }
.topbar .spacer { width: 72px; }
.back { border: none; background: none; font-size: 20px; padding: 6px 10px; min-width: 48px; min-height: 44px; color: var(--orange-dark); font-weight: 700; }

/* ---------- 输入页 ---------- */
.page { padding: 16px; }
.problem-input {
  width: 100%; min-height: 200px; resize: vertical;
  border: 2px solid var(--line); border-radius: var(--radius); padding: 14px;
  background: var(--card); font-size: 19px; line-height: 1.6;
}
.problem-input:focus, #msg:focus { outline: none; border-color: var(--orange); }
.notice { background: #fff3c4; border-radius: 14px; padding: 12px 14px; margin-bottom: 12px; }
.choose-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.choice {
  text-align: left; border: 2px solid var(--line); background: var(--card);
  border-radius: 14px; padding: 12px 14px; min-height: 48px;
}
.choice:active { border-color: var(--orange); }

.symbols { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.sym {
  min-width: 44px; height: 40px; border: 1px solid var(--line); background: var(--card);
  border-radius: 10px; font-size: 20px; font-weight: 600; padding: 0 8px;
}
.sym:active { background: #ffe7d4; }

/* ---------- 对话页 ---------- */
.chat-view.active { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.problem-card {
  flex-shrink: 0; margin: 10px 12px 0; padding: 12px 14px; background: #fff3c4; border-radius: 14px;
  white-space: pre-wrap; max-height: 26vh; overflow: auto; font-size: 17px;
}
.problem-card.collapsed { display: none; }
.messages { flex: 1; overflow-y: auto; padding: 14px 12px 8px; -webkit-overflow-scrolling: touch; }
.msg { display: flex; gap: 8px; margin-bottom: 14px; align-items: flex-end; }
.msg.child { justify-content: flex-end; }
.msg .avatar { font-size: 30px; line-height: 1; flex-shrink: 0; }
.msg .bubble {
  position: relative; max-width: 80%; min-width: 0; padding: 12px 16px; border-radius: 18px;
  white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere; box-shadow: 0 2px 6px rgba(0,0,0,.05);
}
.msg.tutor .bubble { background: var(--card); border-bottom-left-radius: 6px; padding-right: 44px; }
.msg.tutor .bubble.has-diagram { max-width: 88%; padding-right: 16px; }
.msg.tutor .bubble.has-diagram .bubble-text { padding-right: 28px; }
.msg.child .bubble { background: var(--child); border-bottom-right-radius: 6px; }
.speak {
  position: absolute; right: 6px; top: 8px; border: none; background: none;
  font-size: 18px; padding: 4px; opacity: .65;
}
.diagram-card {
  margin-top: 10px; background: #fffdf8; border: 1.5px solid var(--line);
  border-radius: 12px; padding: 8px 10px 6px;
}
.diagram-title { font-size: 13px; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.diagram-card svg { display: block; width: 100%; height: auto; max-width: 340px; margin: 0 auto; }
.chat-img {
  display: block; width: 100%; max-width: 360px; height: auto; margin-top: 10px;
  border-radius: 12px; border: 1.5px solid var(--line); background: #fffdf8; cursor: zoom-in;
}
.tb-page-box { margin-top: 10px; }
.unit-banner {
  flex-shrink: 0; margin: 8px 12px 0; padding: 6px 12px; border-radius: 10px;
  background: #f0e8ff; color: #5b2ea6; font-size: 14px; font-weight: 600;
}
.pill-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.pill {
  border: 2px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 6px 14px; font-size: 15px; font-weight: 600; min-height: 40px;
}
.pill.active { background: var(--orange); border-color: var(--orange); color: #fff; }
.rec-panel { margin-top: 0; margin-bottom: 14px; background: #fffdf5; border: 2px solid #ffe4a3; }
.rec-head { font-weight: 700; margin-bottom: 8px; }
.rec-item {
  display: block; width: 100%; text-align: left; border: 1.5px solid var(--line);
  background: #fff; border-radius: 12px; padding: 10px 12px; margin-top: 8px;
}
.rec-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 2px; }
.unit-card {
  background: var(--card); border-radius: 16px; padding: 14px; margin-bottom: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,.05);
}
.unit-card .btn.small { font-size: 14px; padding: 6px 10px; white-space: nowrap; }
.unit-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.lightbox {
  position: fixed; inset: 0; z-index: 80; background: rgba(25, 20, 15, .92);
  display: flex; flex-direction: column; padding: 12px;
}
.lightbox-bar { display: flex; justify-content: space-between; align-items: center; color: #fff; gap: 10px; margin-bottom: 8px; }
.lightbox-bar .btn { white-space: nowrap; flex-shrink: 0; }
.lightbox-body { flex: 1; overflow: auto; display: flex; align-items: flex-start; justify-content: center; }
.lightbox-body img { max-width: 100%; height: auto; border-radius: 10px; background: #fff; }
.lightbox-nav { display: flex; justify-content: center; align-items: center; gap: 14px; color: #fff; padding-top: 10px; }
.m-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); margin-top: 6px; }
.pop { animation: pop .25s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.typing .bubble { display: flex; gap: 5px; padding: 16px 18px; }
.typing .bubble span { width: 8px; height: 8px; border-radius: 50%; background: #c9b8a8; animation: blink 1.2s infinite; }
.typing .bubble span:nth-child(2) { animation-delay: .2s; }
.typing .bubble span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .3; } 40% { opacity: 1; } }

.done-actions { display: flex; gap: 10px; padding: 10px 12px; flex-wrap: wrap; }
.done-actions .btn { flex: 1; min-width: 148px; white-space: nowrap; font-size: 16px; padding: 10px 12px; }
.composer { border-top: 1px solid var(--line); background: var(--bg); padding: 8px 12px calc(10px + env(safe-area-inset-bottom)); }
.quick { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 2px solid #ffd7b8; background: #fff1e5; color: var(--orange-dark); border-radius: 999px; padding: 6px 14px; font-weight: 600; min-height: 40px; font-size: 15px; }
.chip.blue { border-color: #bfe0ff; background: #edf6ff; color: #246bc2; }
.chip.purple { border-color: #dec8ff; background: #f6efff; color: #7139b8; }
.composer .symbols { margin-top: 8px; }
.composer .sym { height: 36px; min-width: 40px; font-size: 18px; }
.input-row { display: flex; gap: 8px; margin-top: 8px; align-items: flex-end; }
.mic-btn { min-width: 48px; padding: 10px 12px; font-size: 20px; }
.btn.recording {
  background: #fde4e2; border-color: var(--red); color: var(--red);
  animation: pulse-rec 1.1s ease-in-out infinite;
}
@keyframes pulse-rec { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.04); } }
.modal-box p { white-space: pre-line; text-align: left; font-size: 16px; }
#msg {
  flex: 1; resize: none; border: 2px solid var(--line); border-radius: 14px;
  padding: 10px 12px; background: var(--card); max-height: 140px; min-height: 48px; line-height: 1.5;
  overflow-y: hidden;
}

/* ---------- 弹窗/提示 ---------- */
.modal, .overlay {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  background: rgba(60, 40, 20, .35); padding: 20px;
}
.overlay { flex-direction: column; background: rgba(255, 248, 236, .92); text-align: center; }
.modal-box { background: var(--card); border-radius: 22px; padding: 26px; max-width: 360px; text-align: center; box-shadow: var(--shadow); }
.modal-emoji { font-size: 56px; }
.toast {
  position: fixed; left: 50%; bottom: 120px; transform: translateX(-50%); z-index: 60;
  background: rgba(50, 35, 25, .92); color: #fff; padding: 12px 18px; border-radius: 14px;
  max-width: 88vw; text-align: center; font-size: 16px;
}
.confetti {
  position: fixed; top: -40px; z-index: 70; pointer-events: none;
  animation: fall 2.6s ease-in forwards;
}
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); opacity: .8; } }

/* ---------- 家长页面 ---------- */
.parent { padding: 20px 16px 60px; }
.parent h1 { font-size: 24px; margin: 0 0 4px; }
.parent h2 { font-size: 20px; margin: 24px 0 10px; }
.panel { background: var(--card); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-top: 14px; max-width: 100%; overflow-wrap: anywhere; }
.field { display: block; margin-bottom: 14px; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
.field > span { display: block; font-weight: 600; margin-bottom: 4px; font-size: 16px; }
.field input, .field select {
  width: 100%; border: 2px solid var(--line); border-radius: 12px; padding: 10px 12px; background: #fff; min-height: 46px;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--orange); }
.help { font-size: 14px; color: var(--muted); margin-top: 4px; }
.help-box { background: #f3f8ff; border-radius: 12px; padding: 10px 12px; font-size: 15px; margin-bottom: 14px; }
details.adv { margin-bottom: 14px; }
details.adv summary { cursor: pointer; color: var(--muted); margin-bottom: 10px; }
.tabs { display: flex; gap: 8px; margin-top: 14px; margin-bottom: 14px; }
.tab { flex: 1; border: 2px solid var(--line); background: var(--card); border-radius: 12px; padding: 8px 4px; font-weight: 600; min-height: 44px; font-size: 15px; white-space: nowrap; }
.tab.active { background: var(--orange); border-color: var(--orange); color: #fff; }
.rec {
  display: block; width: 100%; text-align: left; border: none; background: var(--card);
  border-radius: 14px; padding: 12px 14px; margin-bottom: 10px; box-shadow: 0 2px 8px rgba(0,0,0,.05);
}
.rec .meta { display: flex; gap: 8px; flex-wrap: wrap; font-size: 14px; color: var(--muted); margin-bottom: 4px; }
.rec .prob { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.badge { display: inline-block; border-radius: 999px; padding: 0 10px; font-size: 13px; font-weight: 600; white-space: nowrap; flex-shrink: 0; }
.badge.ok { background: #dff5ea; color: #1d7a4c; }
.badge.hint { background: #fff1e0; color: #a85a00; }
.badge.todo { background: #eee; color: #666; }
.badge.warn { background: #fde4e2; color: #b4322a; }
.badge.lv { background: #eef3ff; color: #3a5bb0; }
.summary dl { margin: 0; }
.summary dt { font-weight: 700; margin-top: 8px; font-size: 15px; color: var(--muted); }
.summary dd { margin: 2px 0 0; }
.transcript .msg .bubble { max-width: 88%; font-size: 16px; }
.transcript .msg.tutor .bubble { padding-right: 16px; }
.flag-box { background: #fde4e2; border-radius: 12px; padding: 10px 12px; margin-top: 10px; }
.ok-text { color: var(--green); font-weight: 600; }
.err-text { color: var(--red); }
.url { font-family: Consolas, monospace; background: #fff3c4; padding: 2px 8px; border-radius: 6px; font-size: 18px; }
