:root {
  --bg: #f6f6f3; --card: #ffffff; --ink: #2b2f2c; --muted: #7a817c; --line: #e3e6e3;
  --accent: #5f7f72; --accent-ink: #ffffff; --accent-soft: #e3ece7; --warn: #b5574b; --pro: #4f7f66; --con: #a8574b;
  --d-bg: #171b1a; --d-card: #232927; --d-line: #343c39; --d-ink: #e8ece9; --d-muted: #9aa49f;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171b1a; --card: #222826; --ink: #e6eae7; --muted: #949c97; --line: #333a37;
    --accent: #8fb3a3; --accent-ink: #14201b; --accent-soft: #2c3a34; --warn: #e08a7e; --pro: #8fc2a6; --con: #e09a8e;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  font-size: 16px; line-height: 1.6;
}
a { color: var(--accent); text-decoration: none; }
h1, h3, h4, p { margin: 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.warn { color: var(--warn); }
.row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.row.gap { justify-content: flex-start; }
.row.ends { font-size: 11px; color: var(--muted); }

/* ---------- shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center;
  padding: calc(10px + var(--safe-top)) 16px 10px; background: var(--bg);
}
.topbar-title { font-size: 15px; font-weight: 600; }
.sos {
  border: 1px solid var(--warn); color: var(--warn); background: transparent; border-radius: 20px;
  padding: 6px 14px; font: inherit; font-size: 14px; cursor: pointer;
}
.app { max-width: 560px; margin: 0 auto; padding: 0 16px calc(90px + var(--safe-bottom)); }
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: flex; background: var(--bg);
  border-top: 1px solid var(--line); padding-bottom: var(--safe-bottom);
}
.tabs a { flex: 1; text-align: center; font-size: 12px; padding: 9px 0 10px; color: var(--muted); }
.tabs a i { display: block; width: 6px; height: 6px; border-radius: 3px; margin: 0 auto 4px; background: currentColor; opacity: .45; }
.tabs a.on { color: var(--accent); font-weight: 600; }
.tabs a.on i { opacity: 1; }

.page-head { margin: 4px 0 14px; }
.page-head small { display: block; color: var(--muted); font-size: 13px; }
.page-head h1 { font-size: 24px; font-weight: 600; line-height: 1.35; }
.back { display: inline-block; font-size: 14px; margin: 2px 0 8px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.card h3 { font-size: 15px; font-weight: 600; margin-bottom: 8px; }
.card h3:not(:first-child) { margin-top: 14px; }
.card p + p { margin-top: 8px; }
.card ul, .card ol { margin: 6px 0 0; padding-left: 22px; }
.card li { margin: 4px 0; }
.quote { text-align: center; font-size: 17px; color: var(--accent); padding: 6px 4px; line-height: 1.7; }
.note { font-size: 13px; color: var(--muted); margin-top: 10px; }
.group-title { font-size: 13px; color: var(--muted); font-weight: 600; margin: 12px 0 2px; }
.pro { color: var(--pro); }
.con { color: var(--con); }

.rowlink { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; color: var(--ink); border-bottom: 1px solid var(--line); }
.rowlink:last-child { border-bottom: none; }
.rowlink b { font-weight: 600; display: block; }
.rowlink small { color: var(--muted); font-size: 13px; display: block; }
.rowlink .chev { color: var(--muted); white-space: nowrap; }
.badge { min-width: 24px; text-align: center; font-size: 13px; background: var(--accent-soft); color: var(--accent); border-radius: 12px; padding: 1px 8px; }

/* ---------- buttons & fields ---------- */
.btn {
  display: inline-block; border: none; border-radius: 14px; padding: 12px 18px; font: inherit; font-size: 16px;
  background: var(--accent); color: var(--accent-ink); cursor: pointer; text-align: center;
}
.btn.block { display: block; width: 100%; margin-bottom: 12px; }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
.btn.danger { background: var(--warn); color: #fff; }
.btn.small { padding: 8px 14px; font-size: 14px; }
.field { display: block; margin-bottom: 12px; }
.field span, .field-label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
input[type=text], input[type=search], textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
  font: inherit; font-size: 16px; background: transparent; color: inherit; resize: vertical;
}
.search { background: var(--card); margin-bottom: 12px; }
label.check { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
label.check:last-child { border-bottom: none; }
label.check input { flex: none; width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--accent); }
label.check span { flex: 1; }
.x { border: none; background: transparent; color: var(--muted); font-size: 20px; line-height: 1; padding: 0 4px; cursor: pointer; }
.addrow { display: flex; gap: 8px; margin-top: 10px; }
.addrow input { flex: 1; }
.slider { margin: 6px 0 4px; }
.slider .num { font-size: 18px; }
input[type=range] { width: 100%; accent-color: var(--accent); margin: 6px 0 0; }
.rating { display: flex; gap: 6px; }
.rating button {
  flex: 1; border: 1px solid var(--line); background: transparent; color: var(--ink); border-radius: 12px;
  padding: 10px 0; font: inherit; cursor: pointer;
}
.rating button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.anchor { font-size: 13px; color: var(--accent); min-height: 20px; margin-top: 6px; }
.confirm { background: var(--card); border: 1px solid var(--warn); border-radius: var(--radius); padding: 14px; margin: 4px 0 12px; }
.confirm p { margin-bottom: 10px; }

/* urge card items */
.items .item { display: flex; gap: 6px; align-items: center; margin-bottom: 8px; }
.items .item input { flex: 1; min-width: 0; }
.seg { display: flex; gap: 6px; margin: 10px 0 0; }
.seg button {
  flex: 1; border: 1px solid var(--d-line); background: transparent; color: inherit; border-radius: 10px; padding: 8px 0; font: inherit; font-size: 14px; cursor: pointer;
}
.seg button.on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.seg.mini { margin: 0; gap: 2px; flex: none; }
.seg.mini button { flex: none; padding: 6px 7px; font-size: 12px; border-color: var(--line); }

/* handouts */
details.unit { border-bottom: 1px solid var(--line); }
details.unit:last-child { border-bottom: none; }
details.unit summary { list-style: none; cursor: pointer; padding: 12px 0; display: flex; justify-content: space-between; font-weight: 600; }
details.unit summary::-webkit-details-marker { display: none; }
details.unit summary small { font-weight: 400; color: var(--muted); }
details.unit ol { list-style: none; padding: 0; margin: 0 0 10px; }
details.unit li a { display: flex; gap: 10px; padding: 7px 0; color: var(--ink); align-items: baseline; }
details.unit li em { font-style: normal; color: var(--muted); font-size: 12px; min-width: 28px; }
details.unit li span { flex: 1; }
.tag { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 8px; padding: 0 6px; margin-left: 6px; white-space: nowrap; }
.acro { display: flex; gap: 12px; padding: 8px 0; }
.acro .letter {
  flex: none; width: 36px; height: 36px; border-radius: 10px; background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 18px;
}
.acro b { display: block; }
.acro small { display: block; color: var(--muted); font-size: 12px; }
.acro p { margin-top: 4px; }
.trow + .trow { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.trow h4 { margin-bottom: 6px; }
.trow p { font-size: 14px; }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom)); transform: translate(-50%, 20px); opacity: 0;
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 20px; font-size: 14px; transition: .25s; z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- crisis mode (always dark) ---------- */
body.dark { background: var(--d-bg); color: var(--d-ink); }
body.dark .topbar, body.dark .tabs { display: none; }
body.dark .app { padding-top: calc(12px + var(--safe-top)); padding-bottom: calc(30px + var(--safe-bottom)); }
.crisis a { color: var(--d-ink); }
.crisis-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.crisis-label { color: var(--d-muted) !important; font-size: 14px; }
.crisis-end { border: 1px solid var(--d-line); border-radius: 18px; padding: 5px 14px; font-size: 14px; }
.crisis-back { display: inline-block; color: var(--d-muted) !important; font-size: 14px; margin-bottom: 8px; }
.crisis-lead { font-size: 24px; font-weight: 600; line-height: 1.5; margin: 10px 0 22px; }
.crisis-lead.small { font-size: 18px; margin-bottom: 14px; }
.crisis .muted { color: var(--d-muted); font-size: 14px; font-weight: 400; }
.big-btn {
  display: block; width: 100%; text-align: left; border: none; border-radius: 18px; padding: 20px 18px; margin-bottom: 14px;
  font: inherit; font-size: 18px; font-weight: 600; background: var(--d-card); color: var(--d-ink); cursor: pointer;
}
.big-btn small { display: block; font-weight: 400; font-size: 13px; color: var(--d-muted); margin-top: 6px; }
.big-btn.quiet { background: transparent; border: 1px solid var(--d-line); font-size: 16px; }
.dcard { background: var(--d-card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.dcard h3 { font-size: 16px; margin-bottom: 6px; }
.dcard ul { margin: 6px 0 0; padding-left: 20px; }
.dcard li { margin: 5px 0; }
.dcard .tag { color: var(--d-muted); border-color: var(--d-line); }
.dcard .acro .letter { background: #33403b; color: var(--d-ink); }
.dcard .acro small { color: var(--d-muted); }
.dcard .group-title { color: var(--d-muted); }
.dtext { color: var(--d-muted); margin-bottom: 16px; }
.dnote { color: var(--d-muted); font-size: 13px; margin-top: 10px; }
.dcard .seg button.on, .crisis .seg button.on { background: #33403b; color: var(--d-ink); border-color: #4d5c56; }
.crisis .pro { color: #8fc2a6; }
.crisis .con { color: #e09a8e; }
.ask { font-size: 19px; font-weight: 600; text-align: center; line-height: 1.6; margin: 18px 0; }
.pill {
  display: inline-block; border: none; border-radius: 24px; padding: 12px 26px; font: inherit; font-size: 16px;
  background: var(--d-ink); color: var(--d-bg) !important; cursor: pointer; margin-top: 12px;
}
.pill.ghost { background: transparent; color: var(--d-ink) !important; border: 1px solid var(--d-line); }
.pick {
  display: block; width: 100%; text-align: left; border: 1px solid var(--d-line); background: transparent; color: var(--d-ink);
  border-radius: 12px; padding: 12px 14px; margin: 8px 0; font: inherit; font-size: 15px; cursor: pointer;
}
.pick.on { background: #33403b; border-color: #6f8a7f; }
.pick.on::before { content: '✓ '; color: #9cc7b4; }

/* STOP */
.octagon {
  width: 150px; height: 150px; margin: 14px auto 16px; background: #a8473c; color: #fff;
  clip-path: polygon(30% 0, 70% 0, 100% 30%, 100% 70%, 70% 100%, 30% 100%, 0 70%, 0 30%);
  display: flex; align-items: center; justify-content: center; font-size: 60px; font-weight: 700; transition: background .4s;
}
.octagon.go { background: #5f7f72; }
.dots { display: flex; justify-content: center; gap: 8px; margin-bottom: 16px; }
.dots b { width: 30px; height: 30px; border-radius: 15px; border: 1px solid var(--d-line); display: flex; align-items: center; justify-content: center; font-size: 13px; color: var(--d-muted); }
.dots b.on { background: var(--d-ink); color: var(--d-bg); border-color: var(--d-ink); }
.step-name { font-size: 24px; font-weight: 600; }
.step-en { color: var(--d-muted); font-size: 13px; margin-bottom: 10px; }
.step-text { color: var(--d-muted); line-height: 1.8; min-height: 96px; margin: 0 6px; }
.after { margin-top: 18px; }

/* timers */
.timer { text-align: center; margin-top: 12px; }
.timer-face { font-size: 46px; font-weight: 300; font-variant-numeric: tabular-nums; letter-spacing: 1px; }
.timer .pill { margin-top: 6px; }
.timer-msg { color: #9cc7b4; min-height: 24px; margin-top: 8px; }

/* guided practice */
.guide { text-align: center; padding-top: 10px; }
.guide-title { color: var(--d-muted); font-size: 14px; margin-bottom: 14px; }
.guide-bar { height: 4px; background: var(--d-line); border-radius: 2px; overflow: hidden; margin-bottom: 28px; }
.guide-bar i { display: block; height: 100%; width: 0; background: #8fb3a3; transition: width .4s; }
.guide-sub { color: var(--d-muted); font-size: 14px; min-height: 22px; }
.guide-text { font-size: 22px; line-height: 1.7; min-height: 190px; margin: 18px 4px 10px; display: flex; align-items: center; justify-content: center; }
.guide-ctrl { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
