/* ============ 主题变量 ============ */
:root {
  color-scheme: light;
  --page: #f7f5f1;
  --surface: #ffffff;
  --surface-2: #f0ede7;
  --ink: #2b2a28;
  --ink-2: #6b6a66;
  --ink-3: #979590;
  --line: #e5e2db;
  --accent: #178f6b;
  --accent-soft: #e2f3ec;
  --sos-1: #f2994a;
  --sos-2: #e8643a;
  --shadow: 0 2px 12px rgba(60, 50, 30, 0.08);
  /* 情绪大类颜色（已通过色觉可分性验证） */
  --c-joy: #eda100;
  --c-anger: #e34948;
  --c-sadness: #2a78d6;
  --c-fear: #4a3aa7;
  --c-shame: #eb6834;
  --c-calm: #1baf7a;
  --c-joy-soft: #fdf3dd;
  --c-anger-soft: #fce9e9;
  --c-sadness-soft: #e5effb;
  --c-fear-soft: #eae7f6;
  --c-shame-soft: #fdece4;
  --c-calm-soft: #e0f5ed;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #121211;
    --surface: #1e1e1c;
    --surface-2: #292926;
    --ink: #f0efec;
    --ink-2: #b5b3ac;
    --ink-3: #85837d;
    --line: #34342f;
    --accent: #2cbd90;
    --accent-soft: #1b3229;
    --sos-1: #e08a3f;
    --sos-2: #d95a30;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
    --c-joy: #c98500;
    --c-anger: #e66767;
    --c-sadness: #3987e5;
    --c-fear: #9085e9;
    --c-shame: #d95926;
    --c-calm: #199e70;
    --c-joy-soft: #33290f;
    --c-anger-soft: #362020;
    --c-sadness-soft: #1c2839;
    --c-fear-soft: #262336;
    --c-shame-soft: #34231a;
    --c-calm-soft: #163026;
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--page);
  color: var(--ink);
  line-height: 1.6;
  min-height: 100dvh;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; -webkit-tap-highlight-color: transparent; }
textarea, input { font: inherit; color: inherit; }

#app { max-width: 560px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
#view-root { flex: 1; padding: 20px 20px calc(84px + env(safe-area-inset-bottom)); }

/* ============ 底部导航 ============ */
#tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 560px;
  display: flex; justify-content: space-around;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
  z-index: 50;
}
#tabbar button {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 12px; color: var(--ink-3); padding: 4px 18px; border-radius: 12px;
}
#tabbar button.active { color: var(--accent); font-weight: 600; }
#tabbar .tab-icon { font-size: 20px; }
#tabbar.hidden { display: none; }

/* ============ 通用组件 ============ */
.card {
  background: var(--surface); border-radius: 18px; padding: 18px;
  box-shadow: var(--shadow); margin-bottom: 14px;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: 14px; padding: 13px 22px; font-size: 16px; font-weight: 600;
  transition: transform 0.1s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-ghost { background: var(--surface-2); color: var(--ink); }
.btn-quiet { color: var(--ink-2); font-weight: 500; padding: 10px 16px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn-danger-quiet { color: var(--c-anger); font-weight: 500; }

.view-head { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; min-height: 36px; }
.view-head h1 { font-size: 20px; font-weight: 700; flex: 1; }
.back-btn { font-size: 15px; color: var(--ink-2); padding: 6px 10px 6px 0; }

.fade-in { animation: fadeIn 0.35s ease both; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.muted { color: var(--ink-2); font-size: 14px; }
.tiny { color: var(--ink-3); font-size: 12.5px; }

/* ============ 首页 ============ */
.home-greet { margin: 10px 2px 22px; }
.home-greet-row { display: flex; align-items: center; justify-content: space-between; }
.diary-link {
  font-size: 13px; color: var(--ink-2); text-decoration: none;
  background: var(--surface); border-radius: 999px; padding: 7px 14px;
  box-shadow: var(--shadow);
}
.home-greet h1 { font-size: 24px; font-weight: 700; }
.home-greet p { color: var(--ink-2); font-size: 15px; margin-top: 4px; }

.sos-entry {
  width: 100%; border-radius: 20px; padding: 22px 20px; margin-bottom: 14px;
  background: linear-gradient(135deg, var(--sos-1), var(--sos-2));
  color: #fff; text-align: left; box-shadow: 0 6px 20px rgba(232, 100, 58, 0.35);
  transition: transform 0.1s ease;
}
.sos-entry:active { transform: scale(0.98); }
.sos-entry .big { font-size: 19px; font-weight: 700; display: block; }
.sos-entry .sub { font-size: 13.5px; opacity: 0.92; margin-top: 3px; display: block; }

.record-entry {
  width: 100%; border-radius: 20px; padding: 22px 20px; margin-bottom: 14px;
  background: var(--surface); box-shadow: var(--shadow); text-align: left;
  transition: transform 0.1s ease;
}
.record-entry:active { transform: scale(0.98); }
.record-entry .big { font-size: 18px; font-weight: 700; display: block; }
.record-entry .sub { font-size: 13.5px; color: var(--ink-2); margin-top: 3px; display: block; }

.home-recent h2 { font-size: 15px; color: var(--ink-2); font-weight: 600; margin: 20px 2px 10px; }
.recent-item { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--line); }
.recent-item:last-child { border-bottom: none; }
.recent-emoji { font-size: 24px; width: 36px; text-align: center; flex-shrink: 0; }
.recent-body { flex: 1; min-width: 0; }
.recent-tags { display: block; font-size: 14.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-note { display: block; font-size: 13px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-time { font-size: 12px; color: var(--ink-3); flex-shrink: 0; }

/* ============ 情绪急救 ============ */
.sos-wrap { display: flex; flex-direction: column; min-height: calc(100dvh - 60px); padding-bottom: 10px; }
.sos-body { flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; }

.sos-pick { width: 100%; }
.sos-pick h2 { font-size: 21px; font-weight: 700; margin-bottom: 6px; text-align: center; }
.sos-pick p.lead { text-align: center; color: var(--ink-2); font-size: 14.5px; margin-bottom: 22px; }
.sos-options { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.sos-opt {
  background: var(--surface); border-radius: 18px; padding: 20px 14px;
  box-shadow: var(--shadow); text-align: center;
  transition: transform 0.1s ease;
}
.sos-opt:active { transform: scale(0.96); }
.sos-opt .emo { font-size: 34px; display: block; margin-bottom: 8px; }
.sos-opt .name { font-size: 15.5px; font-weight: 700; display: block; }
.sos-opt .hint { font-size: 12px; color: var(--ink-3); display: block; margin-top: 2px; }

.step-title { font-size: 20px; font-weight: 700; margin-bottom: 8px; }
.step-sub { color: var(--ink-2); font-size: 15px; max-width: 320px; margin: 0 auto 18px; }
.sos-progress { text-align: center; color: var(--ink-3); font-size: 13px; margin-bottom: 8px; }

/* 呼吸练习 */
.breath-stage { position: relative; width: 240px; height: 240px; margin: 24px auto; display: flex; align-items: center; justify-content: center; }
.breath-ring {
  position: absolute; inset: 0; border-radius: 50%;
  border: 2px dashed var(--line);
}
.breath-circle {
  width: 220px; height: 220px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--accent-soft), var(--accent));
  transform: scale(0.55);
  transition: transform 4s cubic-bezier(0.4, 0, 0.4, 1);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 30px rgba(23, 143, 107, 0.3);
}
.breath-inner { text-align: center; color: #fff; }
.breath-phase { font-size: 19px; font-weight: 700; display: block; }
.breath-count { font-size: 34px; font-weight: 700; display: block; line-height: 1.2; }
.breath-cycle { color: var(--ink-3); font-size: 13.5px; margin-top: 4px; }

/* 着陆练习 5-4-3-2-1 */
.ground-icon { font-size: 44px; margin-bottom: 10px; }
.ground-dots { display: flex; gap: 14px; justify-content: center; margin: 26px 0; flex-wrap: wrap; }
.ground-dot {
  width: 52px; height: 52px; border-radius: 50%;
  border: 2px solid var(--line); background: var(--surface);
  font-size: 18px; font-weight: 700; color: var(--ink-3);
  transition: all 0.2s ease;
}
.ground-dot.done { background: var(--accent); border-color: var(--accent); color: #fff; transform: scale(1.05); }
.ground-tip { color: var(--ink-3); font-size: 13px; }

/* 蝴蝶拍 */
.butterfly-stage { display: flex; gap: 34px; justify-content: center; margin: 30px 0 16px; }
.bf-hand {
  width: 88px; height: 88px; border-radius: 50%;
  background: var(--surface-2); display: flex; align-items: center; justify-content: center;
  font-size: 38px; transition: all 0.5s ease; opacity: 0.45;
}
.bf-hand.on { background: var(--accent-soft); opacity: 1; transform: scale(1.12); box-shadow: 0 4px 18px rgba(23, 143, 107, 0.25); }
.bf-timer { font-size: 28px; font-weight: 700; margin-top: 6px; }

/* 冷刺激 / 肌肉放松 */
.method-list { text-align: left; margin: 18px auto; max-width: 360px; }
.method-list li { margin-bottom: 12px; padding-left: 8px; color: var(--ink-2); font-size: 15px; }
.method-list li strong { color: var(--ink); }
.muscle-part { font-size: 40px; margin: 8px 0; }
.muscle-phase { font-size: 22px; font-weight: 700; margin: 10px 0 4px; }
.muscle-phase.tense { color: var(--sos-2); }
.muscle-phase.relax { color: var(--accent); }
.muscle-count { font-size: 40px; font-weight: 700; }

/* 求助卡片 */
.hotline-card {
  background: var(--c-sadness-soft); border-radius: 16px; padding: 16px;
  margin: 16px 0; text-align: left; font-size: 14px;
}
.hotline-card strong { display: block; margin-bottom: 6px; font-size: 15px; }
.hotline-card a { color: var(--c-sadness); font-weight: 700; text-decoration: none; font-size: 17px; }
.hotline-card p { color: var(--ink-2); margin-top: 4px; }

.sos-footer { display: flex; justify-content: center; gap: 10px; padding-top: 14px; flex-wrap: wrap; }

/* 急救结束 */
.sos-done-emoji { font-size: 56px; margin-bottom: 12px; }
.sos-done-actions { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 320px; margin: 20px auto 0; }
.method-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; max-width: 380px; margin: 16px auto 0; }
.method-grid .btn { padding: 14px 10px; font-size: 14.5px; }

/* ============ 记录向导 ============ */
.wizard-progress { display: flex; gap: 6px; justify-content: center; margin-bottom: 22px; }
.wizard-progress i { width: 26px; height: 4px; border-radius: 2px; background: var(--line); }
.wizard-progress i.on { background: var(--accent); }

.wizard h2 { font-size: 20px; font-weight: 700; text-align: center; margin-bottom: 6px; }
.wizard .lead { text-align: center; color: var(--ink-2); font-size: 14px; margin-bottom: 20px; }

.cat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.cat-card {
  border-radius: 18px; padding: 18px 12px; text-align: center;
  background: var(--surface); box-shadow: var(--shadow);
  border: 2px solid transparent; transition: all 0.15s ease;
}
.cat-card:active { transform: scale(0.96); }
.cat-card.sel { border-color: var(--cat-color, var(--accent)); background: var(--cat-soft, var(--accent-soft)); }
.cat-card .emo { font-size: 32px; display: block; margin-bottom: 6px; }
.cat-card .name { font-size: 15px; font-weight: 700; }

.chip-wrap { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.chip {
  border-radius: 999px; padding: 9px 18px; font-size: 15px;
  background: var(--surface); box-shadow: var(--shadow);
  border: 1.5px solid transparent; transition: all 0.15s ease;
}
.chip.sel { border-color: var(--cat-color, var(--accent)); background: var(--cat-soft, var(--accent-soft)); font-weight: 600; }

.intensity-val { text-align: center; margin: 8px 0 18px; }
.intensity-val .num { font-size: 46px; font-weight: 700; line-height: 1.1; }
.intensity-val .word { color: var(--ink-2); font-size: 14.5px; }
input[type="range"] {
  width: 100%; accent-color: var(--accent); height: 32px;
}
.range-marks { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-3); margin-top: 2px; }

.wizard textarea {
  width: 100%; min-height: 110px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--surface); padding: 14px; font-size: 15px; resize: vertical;
  outline: none;
}
.wizard textarea:focus { border-color: var(--accent); }
.deep-q { margin-bottom: 16px; }
.deep-q label { display: block; font-size: 14.5px; font-weight: 600; margin-bottom: 6px; }
.deep-q textarea { min-height: 70px; }

.wizard-nav { display: flex; gap: 10px; margin-top: 24px; }
.wizard-nav .btn { flex: 1; }

.save-done { text-align: center; padding-top: 40px; }
.save-done .emo { font-size: 58px; display: block; margin-bottom: 14px; }
.save-done h2 { font-size: 20px; margin-bottom: 8px; }
.save-done p { color: var(--ink-2); font-size: 15px; max-width: 300px; margin: 0 auto 26px; }

/* ============ 回顾 ============ */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cal-head .m { font-size: 16px; font-weight: 700; }
.cal-head button { font-size: 18px; padding: 4px 14px; color: var(--ink-2); border-radius: 10px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-wd { text-align: center; font-size: 11.5px; color: var(--ink-3); padding: 2px 0; }
.cal-day {
  aspect-ratio: 1; border-radius: 10px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; font-size: 13px; color: var(--ink-2);
  background: var(--surface-2); position: relative; border: 2px solid transparent;
}
.cal-day.empty { background: transparent; }
.cal-day.has { color: #fff; font-weight: 600; }
.cal-day.today { border-color: var(--accent); }
.cal-day.sel { outline: 2.5px solid var(--ink); outline-offset: 1px; }
.cal-day .d-emo { font-size: 10px; line-height: 1; position: absolute; bottom: 3px; }

.stats-row { display: flex; gap: 12px; margin-bottom: 14px; }
.stat-tile { flex: 1; background: var(--surface); border-radius: 16px; padding: 14px; box-shadow: var(--shadow); text-align: center; }
.stat-tile .v { font-size: 26px; font-weight: 700; line-height: 1.2; }
.stat-tile .k { font-size: 12.5px; color: var(--ink-2); }

.dist-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.dist-label { width: 118px; font-size: 13.5px; flex-shrink: 0; display: flex; align-items: center; gap: 5px; }
.dist-track { flex: 1; height: 18px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.dist-bar { height: 100%; border-radius: 4px 5px 5px 4px; min-width: 2px; transition: width 0.4s ease; }
.dist-num { width: 30px; text-align: right; font-size: 13px; color: var(--ink-2); flex-shrink: 0; font-variant-numeric: tabular-nums; }

.entry-card { background: var(--surface); border-radius: 16px; padding: 14px 16px; box-shadow: var(--shadow); margin-bottom: 12px; }
.entry-top { display: flex; align-items: center; gap: 10px; }
.entry-emoji { font-size: 26px; }
.entry-meta { flex: 1; min-width: 0; }
.entry-tags { font-size: 15px; font-weight: 700; }
.entry-date { font-size: 12px; color: var(--ink-3); }
.entry-intensity {
  font-size: 12px; font-weight: 700; color: #fff; border-radius: 999px;
  padding: 3px 10px; flex-shrink: 0;
}
.entry-note { font-size: 14px; color: var(--ink-2); margin-top: 8px; white-space: pre-wrap; overflow-wrap: break-word; }
.entry-note.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.entry-deep { margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 10px; font-size: 13.5px; }
.entry-deep p { margin-bottom: 6px; color: var(--ink-2); }
.entry-deep strong { color: var(--ink); }
.entry-actions { display: flex; justify-content: flex-end; gap: 4px; margin-top: 6px; }
.entry-actions button { font-size: 13px; color: var(--ink-3); padding: 4px 10px; }

.empty-state { text-align: center; padding: 46px 20px; color: var(--ink-3); }
.empty-state .emo { font-size: 44px; display: block; margin-bottom: 10px; }

.data-tools { display: flex; gap: 10px; justify-content: center; margin: 18px 0 8px; }
.data-tools button { font-size: 13px; color: var(--ink-3); text-decoration: underline; }

/* ============ AI 聊天与设置 ============ */
.chat-wrap { display: flex; flex-direction: column; min-height: calc(100dvh - 60px); }
.chat-list { flex: 1; display: flex; flex-direction: column; gap: 10px; padding: 6px 2px 16px; }
.chat-msg {
  max-width: 84%; padding: 10px 14px; border-radius: 16px; font-size: 15px;
  white-space: pre-wrap; overflow-wrap: break-word; line-height: 1.55;
}
.chat-msg.assistant { background: var(--surface); box-shadow: var(--shadow); border-top-left-radius: 6px; align-self: flex-start; }
.chat-msg.user { background: var(--accent); color: #fff; border-top-right-radius: 6px; align-self: flex-end; }
.chat-msg.typing { color: var(--ink-3); }
.chat-msg.error { color: var(--c-anger); }
.chat-input-row { display: flex; gap: 8px; align-items: flex-end; position: sticky; bottom: calc(10px + env(safe-area-inset-bottom)); }
.chat-input-row textarea {
  flex: 1; border-radius: 14px; border: 1px solid var(--line); background: var(--surface);
  padding: 12px; font-size: 15px; resize: none; min-height: 46px; max-height: 120px; outline: none;
}
.chat-input-row textarea:focus { border-color: var(--accent); }
.set-input {
  width: 100%; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  padding: 12px; font-size: 15px; outline: none; color: var(--ink);
}
.set-input:focus { border-color: var(--accent); }

@media (max-width: 380px) {
  .breath-stage { width: 200px; height: 200px; }
  .breath-circle { width: 184px; height: 184px; }
}
