:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #efede8;
  --text: #1f1e1c;
  --muted: #6b6862;
  --border: #e2dfd8;
  --accent: #3d6b5a;
  --accent-text: #ffffff;
  --bubble-me: #3d6b5a;
  --bubble-me-text: #ffffff;
  --bubble-ai: #ffffff;
  --danger: #b4412f;
  --danger-bg: #fbeae6;
  --warn-bg: #fff6df;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171715;
    --surface: #22211f;
    --surface-2: #2c2b28;
    --text: #ecebe7;
    --muted: #a19e97;
    --border: #3a3935;
    --accent: #6fa892;
    --accent-text: #0f1a16;
    --bubble-me: #4c8572;
    --bubble-me-text: #ffffff;
    --bubble-ai: #2c2b28;
    --danger: #ef8a76;
    --danger-bg: #3b2420;
    --warn-bg: #3a3220;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
button, input, textarea, select { font: inherit; color: inherit; }
button {
  border: 0; border-radius: 10px; padding: 9px 16px; cursor: pointer;
  background: var(--accent); color: var(--accent-text); font-weight: 600;
}
button.secondary { background: var(--surface-2); color: var(--text); font-weight: 500; }
button:disabled { opacity: .5; cursor: default; }
input, textarea, select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
}
textarea { resize: vertical; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label { display: block; font-size: 14px; color: var(--muted); margin: 14px 0 6px; }
.error { color: var(--danger); font-size: 14px; min-height: 20px; margin-top: 10px; }
.muted { color: var(--muted); font-size: 14px; }

/* 登录 / 初始化 */
.auth { max-width: 380px; margin: 12vh auto; padding: 0 16px; }
.auth .card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px 24px; }
.auth h1 { font-size: 22px; margin: 0 0 4px; }
.auth button { width: 100%; margin-top: 20px; }

/* 孩子聊天页 */
.chat { display: flex; flex-direction: column; height: 100dvh; max-width: 760px; margin: 0 auto; }
.chat header {
  display: flex; align-items: center; justify-content: space-between; padding: 12px 16px;
  border-bottom: 1px solid var(--border); background: var(--bg);
}
.chat header h1 { font-size: 17px; margin: 0; }
.notice { font-size: 13px; color: var(--muted); background: var(--surface-2); padding: 6px 16px; text-align: center; }
.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 82%; padding: 10px 14px; border-radius: 18px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--bubble-me); color: var(--bubble-me-text); border-bottom-right-radius: 6px; }
.msg.assistant { align-self: flex-start; background: var(--bubble-ai); border: 1px solid var(--border); border-bottom-left-radius: 6px; }
.header-actions { display: flex; gap: 8px; align-items: center; }
.auto-read { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; font-size: 14px; }
.auto-read[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }
.ai-row { align-self: flex-start; display: flex; align-items: flex-end; gap: 6px; max-width: 88%; }
.ai-row .msg { max-width: none; min-width: 0; }
.speak {
  flex: 0 0 auto; width: 30px; height: 30px; padding: 0; border-radius: 50%;
  display: grid; place-items: center; background: var(--surface-2); color: var(--muted);
}
.speak svg:last-child { display: none; }
.speak.speaking { color: var(--accent); }
.speak.speaking svg:first-child { display: none; }
.speak.speaking svg:last-child { display: block; }
.msg.typing::after { content: "▍"; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.help-card {
  align-self: stretch; background: var(--warn-bg); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; font-size: 14px;
}
.help-card strong { display: block; margin-bottom: 4px; }
.composer {
  display: flex; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border); background: var(--bg);
}
.msg img { display: block; max-width: 100%; max-height: 320px; border-radius: 12px; margin: 2px 0 6px; }
.msg img:last-child { margin-bottom: 2px; }
.composer .attach { border-radius: 50%; width: 42px; height: 42px; padding: 0; display: grid; place-items: center; align-self: flex-end; flex: 0 0 auto; }
.attach-preview { position: relative; padding: 10px 16px 0; border-top: 1px solid var(--border); background: var(--bg); }
.attach-preview img { height: 72px; border-radius: 10px; display: block; }
.attach-preview .remove {
  position: absolute; top: 4px; left: 76px; width: 24px; height: 24px; padding: 0; border-radius: 50%;
  background: var(--text); color: var(--bg); line-height: 24px; font-size: 16px;
}
.attach-preview:not([hidden]) + .composer { border-top: 0; }
.composer textarea { flex: 1; resize: none; max-height: 140px; border-radius: 20px; padding: 10px 16px; }
.composer button { border-radius: 20px; align-self: flex-end; }
.empty { margin: auto; text-align: center; color: var(--muted); }

/* 家长端 */
.parent { max-width: 1100px; margin: 0 auto; padding: 0 16px 40px; }
.parent > header { display: flex; align-items: center; justify-content: space-between; padding: 16px 0; gap: 12px; flex-wrap: wrap; }
.parent > header h1 { font-size: 20px; margin: 0; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { background: none; color: var(--muted); border-radius: 0; padding: 10px 14px; border-bottom: 2px solid transparent; font-weight: 500; white-space: nowrap; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--danger); color: #fff; font-size: 12px; line-height: 20px; text-align: center; margin-left: 4px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.panel h2 { font-size: 16px; margin: 0 0 10px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > * { flex: 0 0 auto; }
.row select { width: auto; min-width: 140px; }
.logs { display: grid; grid-template-columns: 180px 1fr; gap: 16px; }
@media (max-width: 680px) { .logs { grid-template-columns: 1fr; } }
.days { display: flex; flex-direction: column; gap: 4px; max-height: 70vh; overflow-y: auto; }
.days button { background: none; color: var(--text); text-align: left; font-weight: 500; display: flex; justify-content: space-between; }
.days button.active { background: var(--surface-2); }
.transcript { display: flex; flex-direction: column; gap: 10px; }
.transcript .msg { max-width: 90%; }
.msg.flagged { outline: 2px solid var(--danger); }
.meta { font-size: 12px; color: var(--muted); }
.msg-wrap { display: flex; flex-direction: column; }
.msg-wrap.user { align-items: flex-end; }
.flag-tag { font-size: 12px; color: var(--danger); font-weight: 600; }
.flag-item { padding: 12px 0; border-bottom: 1px solid var(--border); }
.flag-item:last-child { border-bottom: 0; }
.flag-item a { color: var(--accent); font-size: 14px; }
.flag-content { margin: 4px 0; white-space: pre-wrap; }
.flag-content img { display: block; max-height: 160px; max-width: 100%; border-radius: 10px; margin-bottom: 4px; }
pre.rules { white-space: pre-wrap; background: var(--surface-2); padding: 12px; border-radius: 10px; font-size: 13px; color: var(--muted); margin: 0; }
.saved { color: var(--accent); font-size: 14px; }
