:root {
  --bg: #fff7ef;
  --card: #ffffff;
  --text: #4a3426;
  --muted: #9a8576;
  --line: #f1e4d8;
  --primary: #ff8a3d;
  --primary-soft: #ffeedd;
  --primary-text: #ffffff;
  --danger: #ef5b5b;
  --danger-soft: #fde8e8;
  --ok: #4cb782;
  --warn-bg: #fff3d6;
  --warn-text: #8a5a00;
  --shadow: 0 6px 20px rgba(150, 90, 40, .08);
  --radius: 22px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1612;
    --card: #2a211b;
    --text: #f6ebe1;
    --muted: #b39f90;
    --line: #3d3128;
    --primary: #ff9a52;
    --primary-soft: #4a3020;
    --primary-text: #2a1608;
    --danger: #ff7b7b;
    --danger-soft: #4a2424;
    --ok: #63cf98;
    --warn-bg: #4a3a14;
    --warn-text: #ffd98a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", sans-serif;
}

main {
  max-width: 520px;
  margin: 0 auto;
  padding: 4px 16px calc(96px + env(safe-area-inset-bottom, 0px));
}

h1 { margin: 0; font-size: 20px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; margin: 4px 0 10px; }
.center { text-align: center; }

/* 顶栏 */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  max-width: 520px; margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 18px 10px;
  background: var(--bg);
}
.pill { font-size: 12px; padding: 3px 10px; border-radius: 99px; background: var(--line); color: var(--muted); }
.pill.ok { background: rgba(76, 183, 130, .15); color: var(--ok); }
.pill.ok::before { content: "● "; }
.pill.bad { background: var(--danger-soft); color: var(--danger); }

/* 卡片 */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  margin: 12px 0;
}
.card-title { font-weight: 600; margin-bottom: 8px; }
details.card summary { cursor: pointer; list-style: none; margin: 0; }
details.card summary::after { content: "›"; float: right; transition: transform .2s; color: var(--muted); }
details[open].card summary::after { transform: rotate(90deg); }
details[open].card summary { margin-bottom: 8px; }

/* 首页大圆环 */
.hero { text-align: center; padding-top: 22px; }
.ring-wrap { position: relative; width: 190px; height: 190px; margin: 0 auto; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 11; }
.ring-bg { stroke: var(--primary-soft); }
.ring-fg {
  stroke: var(--primary); stroke-linecap: round;
  stroke-dasharray: 326.7; stroke-dashoffset: 326.7;
  transition: stroke-dashoffset .6s ease;
}
.ring-text { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.weight { font-size: 40px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.weight small { font-size: 18px; font-weight: 600; margin-left: 2px; }

.mood { margin: 12px 0 4px; font-size: 16px; }
.mood span:first-child { margin-right: 6px; font-size: 20px; }

.alert {
  background: var(--warn-bg); color: var(--warn-text);
  border-radius: 14px; padding: 10px 12px; margin: 10px 0 0;
  font-size: 14px; text-align: left;
}
.alert.danger { background: var(--danger-soft); color: var(--danger); }

/* 按钮 */
button, input, select { font: inherit; color: inherit; }
.btn {
  border: none; border-radius: 16px; padding: 10px 16px;
  background: var(--primary-soft); color: var(--primary);
  cursor: pointer; font-weight: 600;
  transition: transform .1s, opacity .2s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--primary); color: var(--primary-text); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.soft { background: var(--primary-soft); color: var(--primary); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.big { padding: 15px; font-size: 18px; border-radius: 18px; }
.btn.block { display: block; width: 100%; margin-top: 12px; }

.chips { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.chip {
  border: 2px solid var(--line); background: var(--card);
  border-radius: 14px; padding: 9px 0; cursor: pointer; font-weight: 600;
}
.chip.active { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }

.custom-row { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
input[type=number], input[type=text], input[type=password], input[type=time], select {
  border: 2px solid var(--line); border-radius: 14px; background: var(--card);
  padding: 9px 12px; min-width: 0; outline: none;
}
input:focus, select:focus { border-color: var(--primary); }
.custom-row input { flex: 1; }
select { width: 100%; }

/* 两格小卡片 */
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row2 .card { margin: 0; }
.tile {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  border: none; font-size: 14px; cursor: default; text-align: center;
}
button.tile { cursor: pointer; }
.tile-icon { font-size: 26px; }

/* 定时 */
.slot {
  display: grid; grid-template-columns: auto 1fr auto auto; gap: 8px; align-items: center;
  padding: 10px 0; border-bottom: 1px dashed var(--line);
}
.slot:last-of-type { border-bottom: none; }
.slot .amount { display: flex; align-items: center; gap: 4px; font-size: 14px; }
.slot .amount input { width: 64px; }
.slot .del { background: none; border: none; color: var(--muted); font-size: 18px; cursor: pointer; padding: 4px; }
.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 99px; transition: .2s; cursor: pointer; }
.switch span::before {
  content: ""; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::before { transform: translateX(18px); }

/* 记录 */
.day { color: var(--muted); font-size: 13px; margin: 18px 6px 6px; }
.rec { display: flex; align-items: center; gap: 12px; padding: 12px 16px; margin: 8px 0; }
.rec-icon {
  width: 38px; height: 38px; border-radius: 12px; flex: none;
  display: flex; align-items: center; justify-content: center; font-size: 18px;
  background: var(--primary-soft);
}
.rec-icon.bad { background: var(--danger-soft); }
.rec-main { flex: 1; min-width: 0; }
.rec-main .sub { font-size: 12px; color: var(--muted); }
.rec-time { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* 设置 */
.step { display: flex; gap: 12px; margin: 14px 0; }
.step-no {
  width: 26px; height: 26px; flex: none; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary);
  display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 700;
}
.step-body { flex: 1; }
.check { display: flex; align-items: center; gap: 6px; margin: 6px 0 10px; font-size: 14px; }
.kv { display: flex; justify-content: space-between; }

/* 底部标签栏 */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom, 0px));
}
.tabbar button {
  background: none; border: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 12px; color: var(--muted); padding: 4px 0;
}
.tabbar button span { font-size: 20px; filter: grayscale(1); opacity: .6; transition: .2s; }
.tabbar button.active { color: var(--primary); font-weight: 600; }
.tabbar button.active span { filter: none; opacity: 1; }

/* 画面弹层 */
.sheet {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(0, 0, 0, .45);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet-card {
  width: 100%; max-width: 520px; background: var(--card);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 14px 16px calc(20px + env(safe-area-inset-bottom, 0px));
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.frame-box {
  aspect-ratio: 4 / 3; border-radius: 16px; background: #000; overflow: hidden;
  display: flex; align-items: center; justify-content: center; margin-top: 8px;
}
.frame-box img { width: 100%; height: 100%; object-fit: contain; }
.frame-box .muted { color: #bbb; }

/* 提示条 */
.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom, 0px)); z-index: 20;
  transform: translateX(-50%);
  max-width: calc(100% - 40px); width: max-content;
  background: rgba(60, 40, 28, .92); color: #fff;
  padding: 10px 16px; border-radius: 14px; font-size: 14px; text-align: center;
}

/* 登录 */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 360px; text-align: center; }
.login-logo { font-size: 56px; }
.login-card h1 { font-size: 24px; margin: 6px 0; }
.login-card input { width: 100%; margin-top: 18px; padding: 13px 14px; }
