/* ============================================================
   TalkMemory · 小葵的记忆
   暖色系（向日葵黄 / 奶油白 / 浅棕），儿童友好但不幼稚
   标题：ZCOOL KuaiLe（index.html 已引入）；正文：系统字体
   ============================================================ */

/* ---------- 设计变量 ---------- */
:root {
  /* 主色：向日葵 */
  --sun: #ffc93c;
  --sun-bright: #ffd86b;
  --sun-soft: #ffe9ad;
  --sun-deep: #e8a416;
  --honey: #f0a32b;

  /* 底色：奶油与纸 */
  --cream: #fff6e3;
  --paper: #fffdf7;
  --paper-2: #fff1cf;
  --paper-3: #fbe6b6;

  /* 文字：暖棕三阶 */
  --ink: #4b3421;
  --ink-2: #7a5c41;
  --ink-3: #a98d6f;

  /* 点缀 */
  --brown: #8a5a33;
  --line: #f0ddbb;
  --leaf: #6fa94f;
  --berry: #e5533d;

  /* 阴影：柔、暖 */
  --shadow-sm: 0 2px 8px rgba(138, 90, 51, 0.08);
  --shadow-md: 0 6px 24px rgba(138, 90, 51, 0.12);
  --shadow-lg: 0 18px 48px rgba(75, 52, 33, 0.22);

  /* 字体 */
  --font-display: "ZCOOL KuaiLe", "YouYuan", "幼圆", "Microsoft YaHei", sans-serif;
  --font-body: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono", Consolas, monospace;

  /* 圆角：刻意做出层次，避免一刀切 */
  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 20px;
}

/* ---------- 基础 ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--cream);
  font-size: 15px;
  line-height: 1.65;
  overflow: hidden;
}

/* 环境背景：左上角一片"阳光"，右下角一抹蜜色，
   再叠一层细细的奶油圆点纹理 —— 静态页面也有呼吸感 */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(880px 620px at 6% -8%, rgba(255, 201, 60, 0.38), transparent 62%),
    radial-gradient(720px 560px at 102% 108%, rgba(240, 163, 43, 0.16), transparent 60%),
    radial-gradient(420px 320px at 70% -6%, rgba(255, 233, 173, 0.5), transparent 70%);
  animation: sunDrift 26s ease-in-out infinite alternate;
}
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image: radial-gradient(rgba(139, 90, 43, 0.055) 1px, transparent 1.4px);
  background-size: 22px 22px;
}
@keyframes sunDrift {
  from { background-position: 0 0, 0 0, 0 0; }
  to   { background-position: 40px 24px, -30px -20px, -20px 16px; }
}

::selection { background: var(--sun-soft); color: var(--ink); }

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
button:focus-visible, input:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid rgba(255, 201, 60, 0.75);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* 全局细滚动条 */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #ecd08d; border-radius: 99px; border: 2px solid var(--cream); }
::-webkit-scrollbar-thumb:hover { background: var(--sun-deep); }

/* ---------- 总布局：左时间线 + 右聊天 ---------- */
.app {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 336px 1fr;
  height: 100vh;
  height: 100dvh;
  max-width: 1240px;
  margin: 0 auto;
  background: var(--paper);
  box-shadow: var(--shadow-lg);
}
@media (min-width: 1300px) {
  .app { border-radius: var(--r-lg); height: calc(100dvh - 32px); margin: 16px auto; }
}

/* ============================================================
   左侧：竖向时间线
   ============================================================ */
.sidebar {
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(180deg, rgba(255, 233, 173, 0.35), transparent 120px),
    var(--paper);
  border-right: 1px solid var(--line);
  min-height: 0;
}

.side-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 20px 18px 14px;
  border-bottom: 2px dashed var(--line);
}
.side-title { display: flex; align-items: center; gap: 12px; }
.sunflower {
  font-size: 34px;
  display: inline-block;
  transform-origin: 50% 80%;
  animation: sway 5s ease-in-out infinite; /* 小葵在风里轻轻摇 */
}
@keyframes sway {
  0%, 100% { transform: rotate(-6deg); }
  50%      { transform: rotate(7deg); }
}
.side-title-text { display: flex; flex-direction: column; line-height: 1.3; }
.side-title-text b {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 400;
  letter-spacing: 1px;
  color: var(--ink);
}
#memStats { font-size: 12px; color: var(--ink-3); font-style: normal; }

/* 时间线滚动区 */
.timeline { flex: 1; overflow-y: auto; padding: 6px 14px 28px 18px; min-height: 0; }
.t-loading { padding: 28px 8px; color: var(--ink-3); font-size: 13.5px; }

/* 月份分组 */
.t-group { margin-top: 18px; }
.t-month-label {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 4px 6px 2px;
  background: linear-gradient(180deg, var(--paper) 72%, rgba(255, 253, 247, 0));
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 17px;
  letter-spacing: 1px;
  color: var(--brown);
}
.t-month-label::after { /* 月份后的虚线尾巴 */
  content: "";
  flex: 1;
  height: 2px;
  border-bottom: 2px dotted var(--line);
  transform: translateY(-4px);
}
.t-count {
  font-family: var(--font-body);
  font-size: 11px;
  color: var(--brown);
  background: var(--paper-2);
  border-radius: 99px;
  padding: 1px 8px;
  white-space: nowrap;
}

/* 竖向轨道 + 节点圆点 */
.t-days {
  position: relative;
  margin-left: 7px;
  padding: 4px 0 2px;
  border-left: 3px dotted #ead4a4;
}
.t-day {
  position: relative;
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 10px 9px 20px;
  border-radius: var(--r-md);
  transition: background 0.2s, transform 0.2s;
  animation: rise 0.45s both; /* 翻页进场 */
  animation-delay: calc(var(--i, 0) * 45ms);
}
@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}
.t-day::before { /* 轨道节点 */
  content: "";
  position: absolute;
  left: -8.5px;
  top: 16px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--paper);
  border: 3px solid var(--sun);
  transition: background 0.2s, transform 0.2s;
}
.t-day:hover { background: var(--paper-2); transform: translateX(4px); }
.t-day:hover::before { background: var(--sun-bright); transform: scale(1.15); }
.t-day.open { background: var(--paper-2); }
.t-day.open::before { background: var(--sun); }

.t-day-main { display: flex; align-items: baseline; gap: 8px; }
.t-date {
  font-family: var(--font-display);
  font-size: 14px;
  color: var(--sun-deep);
  white-space: nowrap;
  min-width: 44px;
}
.t-summary {
  flex: 1;
  font-size: 13.5px;
  color: var(--ink-2);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.t-day.open .t-summary { -webkit-line-clamp: unset; color: var(--ink); }

/* 展开详情：grid-rows 0fr → 1fr 的丝滑动画 */
.t-detail {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.35s ease, margin 0.35s ease;
  margin-top: 0;
}
.t-day.open .t-detail { grid-template-rows: 1fr; margin-top: 10px; }
.t-detail-in { overflow: hidden; }
.t-detail-text {
  font-size: 13px;
  color: var(--ink-2);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 8px 10px;
  margin-bottom: 8px;
}
.t-events { list-style: none; margin-bottom: 10px; }
.t-events li {
  position: relative;
  font-size: 12.5px;
  color: var(--ink-2);
  padding: 2px 0 2px 18px;
}
.t-events li::before {
  content: "🌰";
  position: absolute;
  left: 0;
  font-size: 11px;
}
.t-quiz {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--brown);
  background: linear-gradient(180deg, var(--sun-bright), var(--sun));
  border: 1px solid var(--sun-deep);
  border-radius: 99px;
  padding: 5px 13px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s, box-shadow 0.15s;
}
.t-quiz:hover { transform: translateY(-2px) rotate(-1deg); box-shadow: var(--shadow-md); }
.t-quiz:active { transform: translateY(0) scale(0.97); }

.t-end { padding: 14px 8px 4px; font-size: 12.5px; color: var(--ink-3); text-align: center; }

/* ============================================================
   右侧：聊天区
   ============================================================ */
.chat-area { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.chat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  background: rgba(255, 253, 247, 0.92);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 2px 10px rgba(138, 90, 51, 0.05);
  z-index: 5;
}
.peer { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.peer-ava {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  font-size: 22px;
  border-radius: 50%;
  background: linear-gradient(160deg, var(--sun-bright), var(--honey));
  box-shadow: inset 0 -3px 6px rgba(138, 90, 51, 0.18), var(--shadow-sm);
  animation: breathe 3.6s ease-in-out infinite; /* 小葵在"呼吸" */
}
@keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }
.peer-info { display: flex; align-items: center; gap: 7px; min-width: 0; }
.peer-info b { font-family: var(--font-display); font-weight: 400; font-size: 20px; letter-spacing: 1px; }
.peer-info small { color: var(--ink-3); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* 状态小圆点：ok 绿 / warn 琥珀 / err 莓红 */
.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--ink-3);
  flex: none;
  transition: background 0.3s;
}
.status-dot.warn { background: var(--honey); }
.status-dot.err  { background: var(--berry); }
.status-dot.ok {
  background: var(--leaf);
  animation: pulse 2s ease-out infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(111, 169, 79, 0.55); }
  70%  { box-shadow: 0 0 0 8px rgba(111, 169, 79, 0); }
  100% { box-shadow: 0 0 0 0 rgba(111, 169, 79, 0); }
}

.head-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  font-size: 17px;
  border-radius: 12px;
  transition: background 0.18s, transform 0.18s;
}
.icon-btn:hover { background: var(--paper-2); transform: translateY(-1px); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn.ghost { opacity: 0.85; }
.parent-btn {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--brown);
  border: 1.5px solid #d9b988;
  border-radius: 99px;
  padding: 7px 14px;
  background: var(--paper);
  transition: all 0.18s;
}
.parent-btn:hover { background: var(--paper-2); border-color: var(--honey); transform: translateY(-1px); }

/* 桌面端不需要抽屉开关 */
.drawer-open { display: none; }
.drawer-close { display: grid; }

/* ---------- 消息流 ---------- */
.chat-scroll { flex: 1; overflow-y: auto; min-height: 0; scroll-behavior: smooth; }
.chat-inner {
  max-width: 780px;
  margin: 0 auto;
  padding: 22px 20px 30px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.msg { display: flex; gap: 10px; max-width: 88%; animation: pop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both; }
@keyframes pop {
  from { opacity: 0; transform: translateY(12px) scale(0.9); }
  to   { opacity: 1; transform: none; }
}
.msg.me { align-self: flex-end; flex-direction: row-reverse; }
.msg.bot { align-self: flex-start; }
.msg .ava {
  flex: none;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  font-size: 17px;
  border-radius: 50%;
  align-self: flex-end;
}
.msg.bot .ava { background: linear-gradient(160deg, var(--sun-bright), var(--honey)); box-shadow: var(--shadow-sm); }
.msg.me .ava { background: var(--paper-3); }

.bubble {
  padding: 11px 15px;
  font-size: 14.5px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: var(--shadow-sm);
}
.msg.bot .bubble {
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: 18px 18px 18px 5px; /* 左下角留给"说话的小尾巴" */
}
.msg.me .bubble {
  background: linear-gradient(160deg, var(--sun-bright), var(--sun));
  border-radius: 18px 18px 5px 18px;
  color: #4a3007;
}

/* "🧠 它想起了" —— 折叠的召回记忆 */
.recalled { margin-top: 9px; border-top: 1px dashed var(--line); padding-top: 7px; font-size: 13px; }
.recalled > summary {
  cursor: pointer;
  user-select: none;
  color: var(--brown);
  font-weight: 600;
  font-size: 12.5px;
  transition: color 0.15s;
  list-style: none;
}
.recalled > summary::-webkit-details-marker { display: none; }
.recalled > summary::after { content: " ▾"; font-size: 10px; }
.recalled[open] > summary::after { content: " ▴"; }
.recalled > summary:hover { color: var(--sun-deep); }
.recalled ul { list-style: none; margin-top: 7px; display: flex; flex-direction: column; gap: 7px; }
.recalled li {
  background: var(--paper-2);
  border-left: 4px solid var(--sun);
  border-radius: 4px var(--r-sm) var(--r-sm) 4px;
  padding: 7px 10px;
}
.r-meta { display: flex; gap: 7px; align-items: center; margin-bottom: 3px; }
.r-type {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--paper);
  background: var(--honey);
  border-radius: 4px;
  padding: 1px 6px;
}
.r-date { font-size: 11px; color: var(--ink-3); font-family: var(--font-mono); }
.recalled li p { font-size: 12.5px; color: var(--ink-2); }

/* 快捷提问小圆片（欢迎语下方） */
.quick-chips { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.quick-chip {
  font-size: 12.5px;
  color: var(--brown);
  background: var(--paper);
  border: 1.5px solid #e6c88f;
  border-radius: 99px;
  padding: 5px 12px;
  transition: all 0.16s;
}
.quick-chip:hover { background: var(--sun); border-color: var(--sun-deep); transform: translateY(-2px); }

/* 正在想……的跳动小点 */
.typing { display: inline-flex; gap: 5px; align-items: center; min-height: 22px; }
.typing i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--honey);
  animation: hop 1s infinite ease-in-out;
}
.typing i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes hop { 0%, 80%, 100% { transform: translateY(0); opacity: 0.5; } 40% { transform: translateY(-7px); opacity: 1; } }

/* ---------- 输入区 ---------- */
.composer {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 14px 18px calc(16px + env(safe-area-inset-bottom, 0px));
  background: rgba(255, 246, 227, 0.94);
  border-top: 1px solid var(--line);
}
#chatInput {
  flex: 1;
  min-width: 0;
  font: inherit;
  color: var(--ink);
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: 99px;
  padding: 12px 18px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
#chatInput::placeholder { color: var(--ink-3); }
#chatInput:focus {
  outline: none;
  border-color: var(--sun);
  box-shadow: 0 0 0 4px rgba(255, 201, 60, 0.28);
}
.send-btn {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 15px;
  font-weight: 700;
  color: #4a3007;
  background: linear-gradient(180deg, var(--sun-bright), var(--sun));
  border: 1px solid var(--sun-deep);
  border-radius: 99px;
  padding: 11px 20px;
  box-shadow: 0 3px 10px rgba(232, 164, 22, 0.4);
  transition: transform 0.16s, box-shadow 0.16s, filter 0.2s;
}
.send-emoji { display: inline-block; transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1); }
.send-btn:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(232, 164, 22, 0.5); }
.send-btn:hover:not(:disabled) .send-emoji { transform: rotate(24deg) scale(1.2); }
.send-btn:active:not(:disabled) { transform: scale(0.96); }
.send-btn:disabled { filter: grayscale(0.75) brightness(0.96); box-shadow: none; cursor: not-allowed; }
.send-btn.busy .send-emoji { animation: spinThink 1.1s linear infinite; }
@keyframes spinThink { to { transform: rotate(360deg); } }

/* ============================================================
   家长面板
   ============================================================ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(75, 52, 33, 0.38);
  backdrop-filter: blur(3px);
  animation: fadeIn 0.2s both;
}
.modal[hidden] { display: none; }
@keyframes fadeIn { from { opacity: 0; } }
.modal-card {
  width: min(620px, 100%);
  max-height: min(84dvh, 720px);
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--line);
  overflow: hidden;
  animation: sheetUp 0.32s cubic-bezier(0.34, 1.4, 0.64, 1) both;
}
@keyframes sheetUp { from { opacity: 0; transform: translateY(28px) scale(0.97); } }

.modal-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px 12px;
}
.modal-head h2 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 22px;
  letter-spacing: 1px;
  flex: 1;
}
.chip {
  font-size: 12px;
  font-weight: 700;
  border-radius: 99px;
  padding: 3px 12px;
  background: var(--paper-3);
  color: var(--brown);
  border: 1px solid #e6c88f;
}
.chip.live { background: #e4f1da; color: #4c7a33; border-color: #b5d59d; }

.tabs { display: flex; gap: 4px; padding: 0 14px; border-bottom: 2px solid var(--line); }
.tab {
  position: relative;
  font-family: var(--font-display);
  font-size: 15.5px;
  color: var(--ink-3);
  padding: 9px 14px 11px;
  transition: color 0.18s;
}
.tab::after {
  content: "";
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: -2px;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: var(--sun);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.25s ease;
}
.tab:hover { color: var(--brown); }
.tab.active { color: var(--ink); }
.tab.active::after { transform: scaleX(1); }

.modal-body { flex: 1; overflow: auto; padding: 14px 18px; min-height: 160px; }
.json-view {
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.75;
  color: #f7e7c9;
  background: #3e2c1c;
  border-radius: var(--r-md);
  padding: 16px 18px;
  white-space: pre-wrap;
  word-break: break-word;
}
/* JSON 轻量着色：键蜜色 / 字符串奶油 / 数字数字绿 / 布尔橙 */
.json-view .j-key { color: var(--sun-bright); }
.json-view .j-str { color: #fbe9c3; }
.json-view .j-num { color: #b8dd9a; }
.json-view .j-bool { color: #ffb27a; }
.modal-note {
  padding: 10px 18px 14px;
  font-size: 12px;
  color: var(--ink-3);
  border-top: 1px dashed var(--line);
}

/* ============================================================
   窄屏（≤900px）：时间线变抽屉
   ============================================================ */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 29;
  background: rgba(75, 52, 33, 0.42);
  animation: fadeIn 0.22s both;
}
.drawer-backdrop[hidden] { display: none; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; box-shadow: none; border-radius: 0; height: 100dvh; margin: 0; }

  .drawer-open { display: grid; }
  .drawer-close { display: none; }

  .sidebar {
    position: fixed;
    z-index: 30;
    inset: 0 auto 0 0;
    width: min(84vw, 330px);
    transform: translateX(-105%);
    transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .drawer-close { display: grid; } /* 抽屉里需要关闭按钮 */

  .msg { max-width: 94%; }
  .chat-inner { padding: 16px 12px 24px; }
}

/*  prefers-reduced-motion：尊重系统设置，关掉所有装饰动画  */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .chat-scroll { scroll-behavior: auto; }
}
