:root {
  --bg: #fefdfb;
  --surface: #ffffff;
  --surface-2: #f6f4f1;
  --text: #000000;
  --text-2: #6d6963;
  --text-3: #a5a098;
  --line: #f2eee8;
  --accent: #2f6b58;
  --accent-ink: #ffffff;
  --danger: #c2493c;
  --shadow: 0 2px 8px rgba(70, 58, 40, 0.05);

  --c-steps: #12a06f;
  --c-steps-soft: #e6f6ef;
  --c-sleep: #2f7ed8;
  --c-sleep-soft: #e9f1fc;
  --c-weight: #d1813c;
  --c-weight-soft: #fbf0e5;
  --c-workout: #7a5fd0;
  --c-workout-soft: #f0ecfb;
  --c-mood: #cc4d7b;
  --c-mood-soft: #fbe9f0;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0d0f;
    --surface: #17171a;
    --surface-2: #232326;
    --text: #ffffff;
    --text-2: #a1a1a6;
    --text-3: #737378;
    --line: #262629;
    --accent: #6dbb9a;
    --accent-ink: #10201a;
    --danger: #e0857c;
    --shadow: none;

    --c-steps: #6dbb9a;
    --c-steps-soft: #1a2620;
    --c-sleep: #7aa8dd;
    --c-sleep-soft: #18222e;
    --c-weight: #d6a077;
    --c-weight-soft: #262019;
    --c-workout: #ab93dd;
    --c-workout-soft: #211d2b;
    --c-mood: #d493ae;
    --c-mood-soft: #261c22;

    color-scheme: dark;
  }
}

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

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 17px;
  line-height: 1.6;
  overscroll-behavior-y: none;
}

/* ---------------- 登录 / 注册 ---------------- */

#auth {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}

#auth-form {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

#auth-form h1 {
  margin: 0;
  font-size: 27px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

#auth-form > p {
  margin: 0;
  font-size: 14px;
  line-height: 1.65;
  color: var(--text-2);
}

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.auth-field > span {
  font-size: 13px;
  color: var(--text-2);
}

.auth-field input {
  font: inherit;
  font-size: 16px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}

.auth-field input:focus {
  outline: none;
  border-color: var(--accent);
}

#auth-submit {
  font: inherit;
  font-size: 16px;
  font-weight: 500;
  padding: 13px;
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  transition: transform 0.14s ease;
}

#auth-submit:active {
  transform: scale(0.985);
}

.auth-error {
  margin: 0;
  min-height: 18px;
  font-size: 13px;
  color: var(--danger);
}

.owner-only.hidden {
  display: none !important;
}

.hidden {
  display: none !important;
}

body.no-scroll {
  overflow: hidden;
}

/* ---------------- 口令 ---------------- */

#gate {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}

#gate-form {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#gate-form h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 500;
}

#gate-form p {
  margin: 0;
  font-size: 14px;
  color: var(--text-2);
}

#gate-form input {
  font: inherit;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}

#gate-form button {
  font: inherit;
  padding: 11px 14px;
  border-radius: 12px;
  border: 0;
  background: var(--accent);
  color: var(--accent-ink);
}

.gate-error {
  color: var(--danger) !important;
}

/* ---------------- 骨架 ---------------- */

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  background: var(--bg);
}

#appbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px 10px;
  padding-top: calc(16px + env(safe-area-inset-top));
}

.bar-text {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

#bar-title {
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

#bar-sub {
  font-size: 13px;
  color: var(--text-3);
}

.gear {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-3);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.18s ease, transform 0.12s ease;
}

.gear svg {
  width: 19px;
  height: 19px;
}

.gear:active {
  background: var(--surface-2);
  transform: scale(0.92);
}

#view {
  flex: 1;
  overflow-y: auto;
  padding: 6px 18px 26px;
  -webkit-overflow-scrolling: touch;
}

/* ---------------- 底部导航 ---------------- */

#tabbar {
  display: flex;
  border-top: 1px solid var(--line);
  background: var(--bg);
  padding-bottom: env(safe-area-inset-bottom);
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 0 9px;
  border: 0;
  background: transparent;
  color: var(--text-3);
  font: inherit;
  cursor: pointer;
  transition: color 0.2s ease;
}

.tab .tab-ico {
  display: grid;
  place-items: center;
  height: 24px;
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

.tab .tab-ico svg {
  width: 22px;
  height: 22px;
}

.tab-label {
  font-size: 11px;
  line-height: 1.3;
}

.tab.active {
  color: var(--accent);
}

.tab.active .tab-ico {
  transform: translateY(-1px) scale(1.06);
}

/* ---------------- 问候区（首页主角） ---------------- */

.hello {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 2px 22px;
}

.hello h2 {
  margin: 0 0 4px;
  font-size: 32px;
  font-weight: 600;
  letter-spacing: -0.025em;
}

.hello p {
  margin: 0;
  font-size: 14px;
  color: var(--text-2);
}

.hello p em {
  font-style: normal;
  color: var(--text);
}

.hello-ring {
  position: relative;
  flex: 0 0 auto;
  width: 62px;
  height: 62px;
}

.hello-ring svg {
  width: 100%;
  height: 100%;
}

.hello-ring span {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

/* ---------------- 数据格 ---------------- */

.metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.metric {
  background: var(--tone-soft, var(--surface));
  border-radius: 22px;
  padding: 14px 15px 12px;
  min-width: 0;
}

.metric-head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 7px;
}

.metric-head i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--tone, var(--text-3));
}

.metric-head span {
  font-size: 12px;
  color: var(--text-2);
}

.metric b {
  display: block;
  font-size: 28px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.025em;
  font-variant-numeric: tabular-nums;
}

.metric b small {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-3);
  margin-left: 2px;
}

.metric .spark {
  display: block;
  width: 100%;
  height: 22px;
  margin-top: 6px;
}

.metric.empty b {
  color: var(--text-3);
}

/* ---------------- 它在说话 ---------------- */

.voice {
  margin-top: 4px;
  padding: 16px 18px;
  border-radius: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.voice-head {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--text-3);
}

.voice-head i {
  width: 3px;
  height: 12px;
  border-radius: 2px;
  background: var(--accent);
}

.voice p {
  margin: 0;
  font-size: 15px;
  line-height: 1.7;
  white-space: pre-wrap;
}

/* ---------------- 通用块 ---------------- */

.block {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.block + .block,
.block + .section-title,
.section-title + .block,
.metrics + .voice,
.voice + .block {
  margin-top: 12px;
}

.block-title {
  margin: 0 0 10px;
  font-size: 12.5px;
  color: var(--text-3);
}

.section-title {
  margin: 24px 2px 10px;
  font-size: 12.5px;
  color: var(--text-3);
}

.cta {
  display: block;
  width: 100%;
  margin-top: 14px;
  padding: 15px;
  border: 0;
  border-radius: 16px;
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-size: 15px;
  cursor: pointer;
  transition: transform 0.14s ease, opacity 0.14s ease;
}

.cta:active {
  transform: scale(0.985);
  opacity: 0.92;
}

.cta.ghost {
  margin-top: 12px;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text-2);
}

/* ---------------- 时间线 ---------------- */

.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
}

.timeline li {
  display: flex;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.timeline li:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.timeline .t {
  min-width: 40px;
  padding-top: 2px;
  font-size: 12px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

.timeline .what {
  flex: 1;
  min-width: 0;
}

.timeline .tag {
  display: inline-block;
  margin-right: 6px;
  padding: 1px 7px;
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 11px;
  vertical-align: 1px;
}

.empty-note {
  margin: 0;
  font-size: 14px;
  color: var(--text-3);
  line-height: 1.65;
}

.examples {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.example {
  text-align: left;
  font: inherit;
  font-size: 14px;
  padding: 11px 13px;
  border-radius: 13px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text-2);
  cursor: pointer;
  transition: transform 0.14s ease, border-color 0.18s ease;
}

.example:active {
  transform: scale(0.985);
  border-color: var(--accent);
}

/* ---------------- 记录页 ---------------- */

.thread {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-bottom: 8px;
}

.msg {
  display: flex;
  flex-direction: column;
  max-width: 86%;
}

.msg.user {
  align-self: flex-end;
  align-items: flex-end;
}

.msg.agent {
  align-self: flex-start;
  align-items: flex-start;
}

.msg.fresh {
  animation: bubbleIn 0.3s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes bubbleIn {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to { opacity: 1; transform: none; }
}

.bubble {
  padding: 10px 14px;
  border-radius: 18px;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.user .bubble {
  background: var(--accent);
  color: var(--accent-ink);
  border-bottom-right-radius: 6px;
}

.msg.agent .bubble {
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}

.msg .meta {
  margin-top: 4px;
  padding: 0 4px;
  font-size: 12px;
  color: var(--text-3);
}

.msg.agent.offline .bubble {
  border-style: dashed;
}

.typing .bubble {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 14px;
}

.typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-3);
  animation: blink 1.2s infinite;
}

.typing i:nth-child(2) { animation-delay: 0.2s; }
.typing i:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
  0%, 60%, 100% { opacity: 0.25; }
  30% { opacity: 1; }
}

/* ---------------- 输入区 ---------------- */

#composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 9px 16px;
  border-top: 1px solid var(--line);
  background: var(--bg);
}

#input {
  flex: 1;
  font: inherit;
  font-size: 16px;
  line-height: 1.5;
  resize: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 20px;
  padding: 10px 15px;
  min-height: 42px;
  max-height: 132px;
  transition: border-color 0.18s ease;
}

#input:focus {
  outline: none;
  border-color: var(--accent);
}

.icon-btn {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  transition: transform 0.14s ease;
}

.icon-btn:active {
  transform: scale(0.93);
}

.icon-btn.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

.icon-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.icon-btn svg {
  width: 19px;
  height: 19px;
}

.icon-btn.recording {
  border-color: var(--danger);
  background: var(--danger);
  color: #fff;
  animation: pulse 1.4s infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(180, 69, 59, 0.35); }
  50% { box-shadow: 0 0 0 10px rgba(180, 69, 59, 0); }
}

/* ---------------- 图表 ---------------- */

.chart {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.chart-legend {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-3);
}

.chart-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.chart-head .delta {
  font-size: 13px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}

/* ---------------- 我的 ---------------- */

.me-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
  padding: 13px 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
}

.me-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

a.me-row {
  text-decoration: none;
  color: inherit;
}

.me-row .value {
  flex: 0 0 auto;
  max-width: 62%;
  color: var(--text-3);
  font-size: 14px;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stat {
  text-align: center;
}

.stat b {
  display: block;
  font-size: 23px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.stat span {
  font-size: 12px;
  color: var(--text-3);
}

/* ---------------- 日期条 ---------------- */

.daybar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 10px;
}

.daybar button {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-2);
  font: inherit;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.14s ease, opacity 0.18s ease;
}

.daybar button:active {
  transform: scale(0.92);
}

.daybar button:disabled {
  opacity: 0.3;
  cursor: default;
}

.daybar .day-label {
  font-size: 14px;
  color: var(--text-2);
}

/* ---------------- 进度 ---------------- */

.bar {
  height: 7px;
  margin: 10px 0 8px;
  border-radius: 4px;
  background: var(--surface-2);
  overflow: hidden;
}

.bar i {
  display: block;
  height: 100%;
  border-radius: 4px;
  background: var(--accent);
  transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

.review-text {
  margin: 0;
  font-size: 15px;
  line-height: 1.72;
  white-space: pre-wrap;
}

.mini {
  flex: 0 0 auto;
  padding: 6px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-2);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: transform 0.14s ease;
}

.mini:active {
  transform: scale(0.96);
}

.mini:disabled {
  opacity: 0.5;
  cursor: default;
}

.mini.danger {
  color: var(--danger);
}

/* ---------------- 成员 ---------------- */

.member {
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.member:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.member:first-child {
  padding-top: 0;
}

.member-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 8px;
}

.member-info b {
  font-size: 15px;
  font-weight: 600;
}

.member-info span {
  font-size: 12px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

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

.member-actions .mini {
  padding: 5px 14px;
  font-size: 13px;
}

.mono {
  margin: 0 0 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text-2);
  word-break: break-all;
  background: var(--surface-2);
  border-radius: 12px;
  padding: 11px 13px;
}

/* ---------------- 设置面板 ---------------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(20, 19, 16, 0.42);
  animation: fadeIn 0.2s ease both;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.sheet {
  width: 100%;
  max-width: 520px;
  max-height: 90dvh;
  overflow-y: auto;
  background: var(--bg);
  border-radius: 22px 22px 0 0;
  padding-bottom: env(safe-area-inset-bottom);
  animation: sheetUp 0.3s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes sheetUp {
  from { transform: translateY(24px); opacity: 0.6; }
  to { transform: none; opacity: 1; }
}

@media (min-width: 640px) {
  .sheet-backdrop {
    align-items: center;
  }

  .sheet {
    border-radius: 22px;
  }
}

.sheet-head {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 10px;
  background: var(--bg);
  font-size: 16px;
  font-weight: 500;
}

.sheet-head .close {
  font: inherit;
  font-size: 14px;
  font-weight: 400;
  color: var(--text-2);
  background: transparent;
  border: 0;
  padding: 4px 0;
  cursor: pointer;
}

.sheet-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 4px 20px 24px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field > span {
  font-size: 13px;
  color: var(--text-2);
}

.field input,
.field select {
  font: inherit;
  font-size: 16px;
  padding: 11px 13px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  width: 100%;
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--accent);
}

.field small {
  font-size: 12px;
  color: var(--text-3);
}

.field-row {
  display: flex;
  gap: 10px;
}

.field-row .field {
  flex: 1;
}

.advanced summary {
  font-size: 14px;
  color: var(--text-2);
  cursor: pointer;
  padding: 2px 0;
}

.advanced[open] summary {
  margin-bottom: 12px;
}

.advanced .field + .field {
  margin-top: 12px;
}

.sheet-actions {
  display: flex;
  gap: 10px;
  margin-top: 2px;
}

.sheet-actions button {
  flex: 1;
  font: inherit;
  padding: 12px;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.14s ease;
}

.sheet-actions button:active {
  transform: scale(0.98);
}

.sheet-actions .ghost {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}

.sheet-actions .solid {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

.note {
  margin: 0;
  min-height: 18px;
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.5;
}

/* ---------------- 进场动效 ---------------- */

.page {
  animation: pageIn 0.34s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes pageIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.page > * {
  animation: riseIn 0.36s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.page > *:nth-child(1) { animation-delay: 0.01s; }
.page > *:nth-child(2) { animation-delay: 0.05s; }
.page > *:nth-child(3) { animation-delay: 0.09s; }
.page > *:nth-child(4) { animation-delay: 0.13s; }
.page > *:nth-child(5) { animation-delay: 0.17s; }
.page > *:nth-child(n + 6) { animation-delay: 0.2s; }

@keyframes riseIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 380px) {
  .hello h2 {
    font-size: 24px;
  }

  .metric b {
    font-size: 21px;
  }
}
