:root {
  --bg: #FAF6F0;
  --card: #FFFFFF;
  --ink: #2B2622;
  --muted: #74685E;
  --line: #E8DFD4;
  --accent: #A8492A;
  --accent-ink: #FFFFFF;
  --accent-soft: #F4E4D9;
  --same: #3B6B4E;
  --same-soft: #E4EFE7;
  --diff: #8A5A1C;
  --diff-soft: #F6EBD8;
  --danger: #B3261E;
  --radius: 16px;
  --serif: 'Noto Serif TC', 'Songti TC', serif;
  --sans: 'Noto Sans TC', 'PingFang TC', -apple-system, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--sans); font-size: 16px; line-height: 1.6; -webkit-text-size-adjust: 100%; }
body { min-height: 100dvh; }
#app { max-width: 520px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
h1, h2, h3 { font-family: var(--serif); font-weight: 700; margin: 0; line-height: 1.35; }
h1 { font-size: 30px; } h2 { font-size: 22px; } h3 { font-size: 17px; }
p { margin: 0; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; }

.page { flex: 1; padding: 20px 16px calc(96px + env(safe-area-inset-bottom)); }
.page.no-tab { padding-bottom: calc(32px + env(safe-area-inset-bottom)); }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px; padding: calc(10px + env(safe-area-inset-top)) 12px 10px; background: rgba(250, 246, 240, .94); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.topbar h2 { flex: 1; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border: 0; background: transparent; border-radius: 50%; color: var(--ink); }
.icon-btn:active { background: var(--accent-soft); }
svg.i { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 20px; border-radius: 999px; border: 1px solid var(--ink); background: transparent; font-weight: 500; transition: transform .12s ease, background .15s ease; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.dark { background: var(--ink); color: #fff; }
.btn.block { width: 100%; }
.btn.ghost { border-color: var(--line); background: var(--card); }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; }
.stack > * + * { margin-top: 16px; }
.stack-sm > * + * { margin-top: 8px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }

/* 首頁 */
.landing { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 32px 24px calc(32px + env(safe-area-inset-bottom)); }
.landing .mark { font-family: var(--serif); font-size: 44px; font-weight: 900; letter-spacing: .08em; }
.landing .mark span { color: var(--accent); }
.landing .mark small { font-family: var(--sans); font-size: 15px; font-weight: 500; letter-spacing: .2em; color: var(--muted); margin-left: 12px; }
.landing ol { margin: 24px 0; padding: 0; list-style: none; counter-reset: s; }
.landing li { counter-increment: s; display: flex; gap: 14px; padding: 14px 0; border-top: 1px solid var(--line); }
.landing li::before { content: counter(s); font-family: var(--serif); font-size: 22px; font-weight: 700; color: var(--accent); width: 20px; }

/* 表單 */
label.f { display: block; }
label.f > span { display: block; font-weight: 500; margin-bottom: 6px; }
label.f small { display: block; color: var(--muted); margin-top: 4px; }
input[type=text], input[type=date], select, textarea { width: 100%; min-height: 48px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
textarea { min-height: 110px; resize: vertical; }
.seg { display: flex; gap: 8px; flex-wrap: wrap; }
.seg label { flex: 1; min-width: 88px; }
.seg input { position: absolute; opacity: 0; }
.seg span { display: block; text-align: center; padding: 11px 8px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
.seg input:checked + span { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.seg input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
.check { display: flex; gap: 10px; align-items: flex-start; }
.check input { width: 22px; height: 22px; margin-top: 2px; accent-color: var(--accent); flex: none; }
.err { color: var(--danger); font-size: 14px; min-height: 20px; }
.steps { display: flex; gap: 6px; margin-bottom: 20px; }
.steps i { flex: 1; height: 4px; border-radius: 4px; background: var(--line); }
.steps i.on { background: var(--accent); }

/* 照片格 */
.photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.ph { position: relative; aspect-ratio: 3 / 4; border-radius: 12px; overflow: hidden; background: #EFE7DC; border: 1px solid var(--line); display: grid; place-items: center; color: var(--muted); }
.ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ph .tag { position: absolute; left: 6px; bottom: 6px; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: rgba(43, 38, 34, .78); color: #fff; }
.ph .tag.ok { background: var(--same); }
.ph .tag.no { background: var(--danger); }
.ph .x { position: absolute; right: 2px; top: 2px; width: 36px; height: 36px; border-radius: 50%; border: 0; background: rgba(43, 38, 34, .6); color: #fff; display: grid; place-items: center; }
.ph.add { border-style: dashed; background: var(--card); }
.ph.add input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* 情境題 */
.q-cat { display: inline-block; font-size: 13px; padding: 3px 12px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.q-text { font-family: var(--serif); font-size: 23px; font-weight: 700; margin: 14px 0 20px; }
.opt { display: block; width: 100%; text-align: left; padding: 15px 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); min-height: 56px; }
.opt.on { border-color: var(--accent); background: var(--accent-soft); font-weight: 500; }
.bar { height: 6px; border-radius: 6px; background: var(--line); overflow: hidden; }
.bar b { display: block; height: 100%; background: var(--accent); transition: width .25s ease; }

/* 推薦卡 */
.person { display: flex; gap: 14px; align-items: center; width: 100%; text-align: left; padding: 12px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.avatar { width: 72px; height: 92px; border-radius: 12px; background: #EFE7DC; overflow: hidden; flex: none; display: grid; place-items: center; font-family: var(--serif); font-size: 28px; color: var(--muted); }
.avatar.round { width: 52px; height: 52px; border-radius: 50%; font-size: 20px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.person .info { flex: 1; min-width: 0; }
.person .name { font-weight: 700; font-size: 17px; }
.person .sub { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pct { flex: none; text-align: center; }
.pct b { display: block; font-family: var(--serif); font-size: 26px; line-height: 1; color: var(--accent); }
.pct small { font-size: 12px; color: var(--muted); }
.badge { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--same-soft); color: var(--same); margin-left: 6px; vertical-align: 2px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); margin-left: 6px; }

/* 個人頁 */
.gallery { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; margin: 0 -16px; padding: 0 16px; }
.gallery .g { flex: none; width: 78%; aspect-ratio: 3 / 4; border-radius: var(--radius); overflow: hidden; background: #EFE7DC; scroll-snap-align: center; display: grid; place-items: center; color: var(--muted); }
.gallery .g:only-child { width: 100%; }
.gallery img { width: 100%; height: 100%; object-fit: cover; }
.score { display: flex; align-items: center; gap: 16px; }
.score .num { font-family: var(--serif); font-size: 52px; font-weight: 900; line-height: 1; color: var(--accent); }
.score .num small { font-size: 22px; }
.cmp { border-radius: 12px; padding: 12px 14px; }
.cmp.same { background: var(--same-soft); }
.cmp.diff { background: var(--diff-soft); }
.cmp .q { font-weight: 500; }
.cmp .a { font-size: 14px; margin-top: 4px; }
.cmp .a b { font-weight: 500; }
.sec-title { display: flex; align-items: center; gap: 8px; margin: 24px 0 10px; }
.sec-title .n { font-size: 14px; color: var(--muted); }
.actionbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: rgba(250, 246, 240, .96); border-top: 1px solid var(--line); }
.actionbar .row { max-width: 488px; margin: 0 auto; }

/* 分頁列 */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; background: rgba(255, 255, 255, .97); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs div { max-width: 520px; margin: 0 auto; display: flex; }
.tabs button { flex: 1; min-height: 60px; border: 0; background: transparent; color: var(--muted); font-size: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; position: relative; }
.tabs button.on { color: var(--accent); font-weight: 700; }
.tabs .n { position: absolute; top: 6px; left: 50%; margin-left: 8px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: #fff; font-size: 11px; line-height: 18px; }

/* 聊天 */
.chat { flex: 1; padding: 16px 12px 96px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 78%; padding: 9px 14px; border-radius: 18px; background: var(--card); border: 1px solid var(--line); align-self: flex-start; white-space: pre-wrap; word-break: break-word; }
.msg.me { align-self: flex-end; background: var(--accent); border-color: var(--accent); color: #fff; }
.composer { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; background: #fff; border-top: 1px solid var(--line); padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
.composer form { max-width: 496px; margin: 0 auto; display: flex; gap: 8px; }
.composer input[type=text] { flex: 1; border-radius: 999px; }
.composer form { align-items: center; }
.composer .go { width: 48px; height: 48px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; display: grid; place-items: center; flex: none; }
.composer .cbtn { width: 40px; height: 44px; border: 0; background: transparent; color: var(--muted); display: grid; place-items: center; flex: none; position: relative; border-radius: 10px; cursor: pointer; }
.composer .cbtn input { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; }
.composer .cbtn:focus-within, .composer .cbtn:focus-visible { outline: 3px solid var(--accent); }
.emojis { max-width: 496px; margin: 0 auto 8px; display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; }
[hidden] { display: none !important; }
.msg.aud { min-width: 200px; }
.msg.aud audio { display: block; width: 220px; max-width: 100%; height: 40px; }
.playbtn { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px 0 8px; border-radius: 999px; border: 1px solid currentColor; background: transparent; color: inherit; }
.unsend { display: block; margin: 4px 0 0 auto; border: 0; background: transparent; color: inherit; opacity: .8; font-size: 12px; text-decoration: underline; min-height: 28px; }
.recbar { max-width: 496px; margin: 0 auto; display: flex; align-items: center; gap: 8px; min-height: 48px; }
.recbar > span:nth-child(2) { flex: 1; }
.recbar .btn { min-height: 44px; padding: 0 16px; }
.recdot { width: 12px; height: 12px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .25; } }
.msg.img .t { padding: 0 6px 2px; }
.emojis button { height: 44px; border: 0; background: transparent; font-size: 24px; border-radius: 10px; }
.emojis button:active { background: var(--accent-soft); }
.msg .t { display: block; font-size: 11px; opacity: .65; margin-top: 2px; text-align: right; }
.msg.big { font-size: 44px; line-height: 1.2; background: transparent; border-color: transparent; padding: 0 4px; color: var(--ink); }
.msg.big .t { font-size: 11px; color: var(--muted); }
.msg.img { padding: 4px; position: relative; min-width: 180px; min-height: 120px; overflow: hidden; }
.msg.img img { display: block; max-width: 220px; max-height: 300px; border-radius: 14px; }
.msg.img img:not([src]) { width: 200px; height: 140px; }
.msg.img .cover { position: absolute; inset: 4px 4px 22px; border: 0; border-radius: 14px; background: #D9CFC3; color: var(--ink); font-size: 14px; padding: 12px; }
.msg.me[role=button] { cursor: pointer; }
.day { align-self: center; font-size: 12px; color: var(--muted); margin: 6px 0 2px; }
.seen { align-self: flex-end; font-size: 12px; color: var(--muted); margin-top: -4px; }
.sbar { display: flex; gap: 8px; padding: 10px 12px 0; }

.chat-tabs { display: flex; border-bottom: 1px solid var(--line); background: var(--bg); }
.chat-tabs button { flex: 1; min-height: 48px; border: 0; background: transparent; color: var(--muted); border-bottom: 3px solid transparent; }
.chat-tabs button.on { color: var(--ink); font-weight: 700; border-bottom-color: var(--accent); }
.reveal { align-self: center; font-size: 14px; padding: 6px 14px; border-radius: 999px; background: var(--same-soft); color: var(--same); font-weight: 500; }
.wish { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 60px; text-align: left; padding: 12px 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); }
.wish .wl { flex: 1; font-weight: 500; }
.wish small { display: block; font-weight: 400; font-size: 13px; color: var(--muted); }
.wish i { width: 26px; height: 26px; border-radius: 50%; border: 2px solid #B9AEA2; flex: none; position: relative; }
.wish.on { border-color: var(--accent); background: var(--accent-soft); }
.wish.on i { border-color: var(--accent); background: var(--accent); }
.wish.on i::after { content: ''; position: absolute; left: 7px; top: 3px; width: 6px; height: 11px; border: solid #fff; border-width: 0 2.5px 2.5px 0; transform: rotate(45deg); }
.wish.done { border-color: var(--same); background: var(--same-soft); opacity: 1; }
.wish.done i { border-color: var(--same); background: var(--same); }
.wish.done small { color: var(--same); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 6px 14px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.sw-row { display: grid; grid-template-columns: 7.5em 1fr; align-items: center; gap: 12px; }
.sw-row .bar { height: 10px; }
.care { margin: 12px 12px 0; padding: 12px 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); }
.care summary { font-weight: 700; cursor: pointer; min-height: 28px; }
.care p { margin-top: 8px; }

.goals { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.goal { font-size: 12px; line-height: 1.5; padding: 2px 9px; border-radius: 999px; border: 1px solid #CFC4B8; color: var(--muted); background: transparent; white-space: nowrap; }
.goal.same { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 500; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.warn { align-self: flex-start; max-width: 86%; font-size: 13px; line-height: 1.5; padding: 6px 12px; border-radius: 10px; background: var(--diff-soft); color: #6B4410; border: 1px solid #E6CFA4; }

.pick { display: flex; flex-wrap: wrap; gap: 8px; }
.pick label { position: relative; }
.pick input { position: absolute; opacity: 0; }
.pick span { display: block; padding: 9px 14px; min-height: 44px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); }
.pick input:checked + span { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.pick input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
.chip.soft { background: transparent; border: 1px solid #CFC4B8; color: var(--muted); font-weight: 400; }
.badge.v { background: #E3EDF7; color: #1F4E79; }
.say { display: block; margin-top: 10px; min-height: 40px; padding: 6px 14px; border-radius: 999px; border: 1px solid rgba(43, 38, 34, .25); background: rgba(255, 255, 255, .7); font-size: 14px; }
.said { margin-top: 8px; padding: 8px 10px; border-radius: 10px; background: var(--accent-soft); color: var(--ink); font-size: 14px; white-space: normal; }
.said small { display: block; color: var(--muted); font-size: 12px; }
.pin { align-self: stretch; padding: 10px 14px; border-radius: 12px; background: var(--accent-soft); border: 1px dashed #D9B9A4; }
.pin small { color: var(--muted); font-size: 12px; }
.openers { align-self: stretch; display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.openers button { text-align: left; min-height: 44px; padding: 10px 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); }

/* 彈窗 */
.sheet-bg { position: fixed; inset: 0; z-index: 20; background: rgba(43, 38, 34, .5); display: flex; align-items: flex-end; justify-content: center; animation: fade .18s ease; }
.sheet { width: 100%; max-width: 520px; background: var(--bg); border-radius: 22px 22px 0 0; padding: 22px 18px calc(22px + env(safe-area-inset-bottom)); animation: up .22s ease; max-height: 88dvh; overflow: auto; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(24px); opacity: 0; } }
.toast { position: fixed; left: 50%; bottom: calc(110px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30; background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 14px; max-width: 86vw; }
.empty { text-align: center; padding: 56px 20px; color: var(--muted); }
.empty h3 { color: var(--ink); margin-bottom: 6px; }
.localnote { font-size: 12px; text-align: center; color: var(--muted); padding: 6px; background: var(--diff-soft); }
table.adm { width: 100%; border-collapse: collapse; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
