:root {
  --pink: #ffb5c5;
  --pink-dark: #ff8fab;
  --cream: #fff5f7;
  --text: #4a3f55;
  --text-soft: #8b7f96;
  --board: #2d5a3d;
  --board-light: #3d7a52;
  --chalk: #f5f5dc;
  --shadow: 0 8px 32px rgba(255, 143, 171, 0.25);
  --radius: 24px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  font-family: "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  background: linear-gradient(160deg, #fff5f7 0%, #ffe8ef 45%, #ffd6e7 100%);
  color: var(--text);
  overflow: hidden;
  touch-action: manipulation;
  user-select: none;
}

#app {
  height: 100%;
  height: 100dvh;
  position: relative;
}

.scene {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.scene.active {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.top-bar, .scene-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 8px;
}

.top-bar .logo {
  margin: 0;
  font-size: 2rem;
  font-weight: 800;
  background: linear-gradient(135deg, #ff6b9d, #ff8fab);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.scene-header h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
}

.scene-header.dark {
  color: var(--chalk);
  background: #1e3d2a;
}

.icon-btn {
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.8);
  font-size: 1.4rem;
  box-shadow: var(--shadow);
  cursor: pointer;
}

.back-btn, .save-btn, .tool-btn {
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.back-btn {
  background: rgba(255, 255, 255, 0.85);
  color: var(--text);
}

.save-btn {
  background: var(--pink-dark);
  color: white;
}

.top-actions { display: flex; gap: 8px; }

.home-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 16px 16px;
  gap: 12px;
  min-height: 0;
}

.buddy-mini {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff 0%, #ffe0ea 55%, #ffc8dc 100%);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.buddy-mini.listening { animation: pulse 0.8s ease-in-out infinite; }
.buddy-mini.speaking { animation: bounce 0.5s ease-in-out infinite; }
.chat-bubble.dudu { cursor: pointer; }
.chat-bubble.dudu:active { opacity: 0.85; }
@keyframes bounce {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}
.buddy-mini .buddy-face { font-size: 2.5rem; }

.chat-area {
  flex: 1;
  width: 100%;
  max-width: 520px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 8px 4px;
  min-height: 120px;
}

.chat-bubble {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 1.05rem;
  line-height: 1.55;
  word-break: break-word;
}

.chat-bubble.dudu {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: var(--shadow);
  border-bottom-left-radius: 4px;
}

.chat-bubble.user {
  align-self: flex-end;
  background: linear-gradient(135deg, #ff6b9d, #ff8fab);
  color: white;
  border-bottom-right-radius: 4px;
}

.voice-status {
  margin: 8px 0 0;
  font-size: 0.9rem;
  color: var(--text-soft);
  text-align: center;
  min-height: 1.2em;
}

.loading {
  position: fixed;
  inset: 0;
  background: rgba(255, 245, 247, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.loading.show { opacity: 1; pointer-events: auto; }
.loading span {
  background: white;
  padding: 14px 24px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  font-weight: 600;
}

.settings-dialog {
  border: none;
  border-radius: 20px;
  padding: 24px;
  max-width: 360px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.settings-dialog h3 { margin: 0 0 16px; }
.settings-dialog label { display: block; margin-bottom: 12px; font-weight: 600; }
.settings-dialog input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 14px;
  border: 2px solid #ffe0ea;
  border-radius: 12px;
  font-size: 1rem;
}

.settings-note { font-size: 0.85rem; color: var(--text-soft); line-height: 1.5; }
.settings-actions { display: flex; gap: 10px; margin-top: 16px; }
.settings-actions button {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
}
#settings-save { background: var(--pink-dark); color: white; }
#settings-close { background: #f0f0f0; }

.play-audio {
  margin-top: 8px;
  border: none;
  background: #ffe8ef;
  color: var(--pink-dark);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  cursor: pointer;
}

.buddy-wrap {
  text-align: center;
}

.buddy {
  width: 160px;
  height: 160px;
  margin: 0 auto;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff 0%, #ffe0ea 55%, #ffc8dc 100%);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  animation: float 3s ease-in-out infinite;
}

.buddy.listening {
  animation: pulse 0.8s ease-in-out infinite;
  box-shadow: 0 0 0 8px rgba(255, 143, 171, 0.35), var(--shadow);
}

.buddy-face {
  font-size: 5rem;
  line-height: 1;
}

.buddy-blush {
  position: absolute;
  width: 22px;
  height: 12px;
  background: rgba(255, 120, 150, 0.35);
  border-radius: 50%;
  top: 58%;
}

.buddy-blush.left { left: 18%; }
.buddy-blush.right { right: 18%; }

.buddy-name {
  margin: 12px 0 4px;
  font-size: 1.5rem;
  font-weight: 800;
}

.buddy-hint, .voice-transcript {
  margin: 0;
  color: var(--text-soft);
  font-size: 1rem;
  min-height: 1.5em;
}

.voice-panel {
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.voice-mode-switch {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  margin-bottom: 14px;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(255, 107, 157, 0.18);
}

.voice-mode-btn {
  border: none;
  background: transparent;
  color: var(--text-soft);
  font-size: 0.88rem;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.voice-mode-btn.active {
  background: linear-gradient(145deg, #ff6b9d, #ff8fab);
  color: white;
  box-shadow: 0 4px 12px rgba(255, 107, 157, 0.35);
}

.voice-btn.tap-mode.tap-active {
  background: linear-gradient(145deg, #ff4d88, #ff6b9d);
  box-shadow: 0 0 0 6px rgba(255, 107, 157, 0.28), 0 12px 28px rgba(255, 107, 157, 0.45);
}

.voice-btn {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(145deg, #ff6b9d, #ff8fab);
  color: white;
  box-shadow: 0 12px 28px rgba(255, 107, 157, 0.45);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin: 0 auto;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.voice-btn:active, .voice-btn.recording {
  transform: scale(0.94);
  box-shadow: 0 6px 16px rgba(255, 107, 157, 0.5);
}

.voice-btn.small {
  width: auto;
  height: auto;
  border-radius: 999px;
  padding: 14px 28px;
  flex-direction: row;
  font-size: 1.05rem;
}

.voice-icon { font-size: 2rem; }
.voice-label { font-size: 0.9rem; font-weight: 600; }

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  max-width: 480px;
}

.action-chip {
  border: none;
  border-radius: 999px;
  padding: 14px 22px;
  font-size: 1.05rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
  cursor: pointer;
}

.action-chip:active {
  transform: scale(0.97);
}

/* 黑板 */
.blackboard-main {
  flex: 1;
  padding: 16px 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: #1e3d2a;
}

.chalkboard {
  flex: 1;
  background: linear-gradient(180deg, var(--board) 0%, var(--board-light) 100%);
  border-radius: var(--radius);
  border: 8px solid #5c4033;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.25);
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
}

.chalk-tip, .math-feedback {
  color: rgba(245, 245, 220, 0.85);
  font-size: 1.1rem;
  margin: 0;
  font-family: "Comic Sans MS", "Chalkboard SE", cursive, sans-serif;
}

.math-problem {
  font-size: clamp(2.5rem, 8vw, 4rem);
  color: var(--chalk);
  font-weight: 700;
  font-family: "Comic Sans MS", "Chalkboard SE", cursive, sans-serif;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}

.math-choices {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  width: 100%;
  max-width: 320px;
}

.math-choice {
  border: 3px dashed rgba(245, 245, 220, 0.5);
  background: rgba(255, 255, 255, 0.08);
  color: var(--chalk);
  border-radius: 16px;
  padding: 18px;
  font-size: 1.8rem;
  font-weight: 700;
  cursor: pointer;
}

.math-choice.correct {
  background: rgba(144, 238, 144, 0.35);
  border-color: #90ee90;
}

.math-choice.wrong {
  background: rgba(255, 99, 71, 0.25);
  border-color: #ff6347;
}

.blackboard-tools {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.tool-btn {
  background: var(--chalk);
  color: #2d5a3d;
}

.tool-btn.secondary {
  background: rgba(255, 255, 255, 0.2);
  color: var(--chalk);
}

.score-badge {
  background: rgba(255, 215, 0, 0.25);
  color: #ffd700;
  padding: 6px 14px;
  border-radius: 999px;
  font-weight: 700;
}

/* 画板 */
.draw-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  padding: 0 12px 0;
  gap: 8px;
}

.draw-canvas-wrap {
  flex: 1 1 auto;
  min-height: 140px;
  min-width: 0;
  overflow: hidden;
}

#draw-canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  touch-action: none;
}

.draw-toolbar {
  flex: 0 0 auto;
  max-height: min(42dvh, 300px);
  padding: 10px 4px calc(12px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: rgba(255, 255, 255, 0.96);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: 0 -4px 24px rgba(255, 143, 171, 0.2);
}

.tool-mode-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.tool-mode {
  border: none;
  border-radius: 999px;
  padding: 10px 14px;
  font-size: 0.95rem;
  font-weight: 600;
  background: white;
  box-shadow: var(--shadow);
  cursor: pointer;
}

.tool-mode.active {
  background: var(--pink);
  color: white;
}

.tool-mode.danger {
  background: #ffe8e8;
  color: #c0392b;
}

.color-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
  padding: 0 2px;
}

.color-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.color-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  padding: 0;
}

.color-dot.active {
  border-color: var(--text);
  transform: scale(1.12);
  box-shadow: 0 0 0 2px white, 0 0 0 4px var(--pink-dark);
}

.brush-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px;
}

.brush-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-soft);
  min-width: 72px;
  white-space: nowrap;
}

.brush-slider {
  flex: 1;
  height: 28px;
  accent-color: var(--pink-dark);
}

.size-preset-row, .size-row {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  padding: 0 4px;
}

.size-btn {
  border: none;
  border-radius: 999px;
  padding: 10px 16px;
  background: white;
  font-weight: 600;
  box-shadow: var(--shadow);
  cursor: pointer;
}

.size-btn.active {
  background: var(--pink);
  color: white;
}

.size-btn.danger {
  background: #ffe0e0;
  color: #c0392b;
}

/* 故事 */
.story-main {
  flex: 1;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.story-card {
  flex: 1;
  width: 100%;
  max-width: 560px;
  background: rgba(255, 255, 255, 0.92);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
  overflow-y: auto;
}

.story-text {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.8;
}

/* 时光 */
.memories-main {
  flex: 1;
  padding: 8px 20px 24px;
  overflow-y: auto;
}

.memories-intro {
  text-align: center;
  color: var(--text-soft);
}

.memory-list {
  list-style: none;
  margin: 16px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.memory-item {
  background: rgba(255, 255, 255, 0.92);
  border-radius: 18px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
}

.memory-date {
  font-size: 0.85rem;
  color: var(--pink-dark);
  font-weight: 700;
  margin-bottom: 6px;
}

.memory-text {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.6;
}

.memory-tag {
  display: inline-block;
  margin-top: 8px;
  font-size: 0.8rem;
  background: #ffe8ef;
  color: var(--pink-dark);
  padding: 4px 10px;
  border-radius: 999px;
}

.empty-hint {
  text-align: center;
  color: var(--text-soft);
  padding: 40px 20px;
}

.empty-hint.hidden { display: none; }

.toast {
  position: fixed;
  bottom: calc(24px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: rgba(74, 63, 85, 0.92);
  color: white;
  padding: 12px 22px;
  border-radius: 999px;
  font-size: 0.95rem;
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  z-index: 100;
  pointer-events: none;
  max-width: 90%;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}

@media (min-width: 768px) {
  .home-main { gap: 32px; }
  .buddy { width: 200px; height: 200px; }
  .buddy-face { font-size: 6rem; }
  .voice-btn { width: 140px; height: 140px; }
}
