:root {
  --bg: #fbf6ee;
  --panel: #fffdf9;
  --ink: #2a1d17;
  --muted: #7a6a5f;
  --line: #efe2d2;
  --chip: #f6ece0;
  --red: #c8102e;
  --red-deep: #8e0b20;
  --red-soft: #fde8e8;
  --gold: #b7791f;
  --gold-soft: #fbefd5;
  --good: #1d7a46;
  --good-soft: #e3f4ea;
  --warn: #a15c00;
  --warn-soft: #fdf0dc;
  --shadow: 0 1px 2px rgba(80, 30, 10, .05), 0 10px 28px rgba(80, 30, 10, .07);
  --font: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Heiti TC", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17110e; --panel: #221915; --ink: #f6ece2; --muted: #b3a194; --line: #3a2c25; --chip: #2e221d;
    --red: #ff5a6e; --red-deep: #ff8a96; --red-soft: #3c1a1f; --gold: #f0b54a; --gold-soft: #3a2b14;
    --good: #5fd38f; --good-soft: #15301f; --warn: #f2b25c; --warn-soft: #3a2a12;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 28px rgba(0, 0, 0, .3);
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); line-height: 1.65; -webkit-font-smoothing: antialiased; }
a { color: var(--red); }
button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.3; letter-spacing: .01em; }
.sr { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* ---------- 版面 ---------- */
.wrap { max-width: 760px; margin: 0 auto; padding: 0 16px; }
.top { background: #c8102e; color: #fff7e6; }
.top .wrap { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 56px; }
.brand { display: flex; align-items: center; gap: 8px; color: inherit; text-decoration: none; font-weight: 800; font-size: 18px; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: #f4c76b; color: #8e0b20; display: grid; place-items: center; font-size: 15px; font-weight: 900; }
.nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { color: #fff7e6; text-decoration: none; padding: 6px 10px; border-radius: 999px; font-size: 14px; white-space: nowrap; opacity: .9; }
.nav a:hover, .nav a[aria-current] { background: rgba(255, 255, 255, .16); opacity: 1; }
@media (max-width: 560px) {
  .top .wrap { flex-direction: column; align-items: stretch; gap: 0; padding-top: 8px; }
  .nav { margin: 0 -16px; padding: 4px 12px 8px; }
}

.hero { background: linear-gradient(180deg, #c8102e 0%, #8e0b20 100%); color: #fff7e6; padding: 28px 0 36px; }
.hero h1 { font-size: clamp(26px, 6vw, 38px); margin: 0 0 8px; }
.hero p { margin: 0; opacity: .92; font-size: 16px; max-width: 34em; }
.crumbs { font-size: 13px; opacity: .8; margin-bottom: 10px; }
.crumbs a { color: inherit; }
main { padding: 0 0 48px; }
main .wrap > :first-child { margin-top: -18px; }

/* ---------- 卡片與表單 ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 18px; margin: 0 0 14px; box-shadow: var(--shadow); }
.card h2 { font-size: 20px; margin: 0 0 12px; }
.card h3 { font-size: 16px; margin: 18px 0 8px; }
.step { display: flex; align-items: center; gap: 10px; }
.num { width: 28px; height: 28px; border-radius: 50%; background: var(--red); color: #fff; display: grid; place-items: center; font-size: 15px; flex: none; }
.field { margin: 14px 0; }
.field-label { font-weight: 700; font-size: 15px; margin-bottom: 8px; }
.hint { color: var(--muted); font-size: 14px; margin: 8px 0 0; }
.empty { color: var(--muted); text-align: center; padding: 18px 0; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
input[type=text], input[type=number], input[type=date], input[type=search], select {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); font-size: 16px;
}
.money-input { display: flex; align-items: center; gap: 8px; border: 2px solid var(--line); border-radius: 14px; padding: 4px 14px; background: var(--bg); margin-bottom: 12px; }
.money-input:focus-within { border-color: var(--red); }
.money-input span { font-weight: 700; color: var(--muted); }
.money-input input { border: 0; background: transparent; font-size: 26px; font-weight: 800; padding: 6px 0; min-height: 0; }
.money-input input:focus { outline: none; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: var(--chip); padding: 8px 14px; border-radius: 999px; cursor: pointer; font-size: 15px; min-height: 40px; }
.chip.on { background: var(--red); border-color: var(--red); color: #fff; font-weight: 700; }
.tabs-card { padding: 14px 18px; }
.tabs { gap: 6px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 10px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; text-decoration: none; color: var(--ink); font-weight: 600; font-size: 15px; }
.btn:hover { border-color: var(--red); }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.link { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 13px; padding: 4px 6px; text-decoration: underline; }
.link.danger { color: var(--red); }

/* ---------- 分配器 ---------- */
.add-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin: 12px 0 16px; }
.add-btn { display: flex; align-items: center; gap: 6px; padding: 10px 12px; border-radius: 12px; border: 1px dashed var(--line); background: var(--bg); cursor: pointer; font-size: 14px; text-align: left; min-height: 46px; }
.add-btn:hover { border-color: var(--red); border-style: solid; }
.emoji { font-size: 22px; line-height: 1; }
.rows { display: grid; gap: 10px; }
.row { border: 1px solid var(--line); border-radius: 14px; padding: 12px; background: var(--bg); }
.row-head { display: flex; align-items: center; gap: 8px; }
.row-head strong { flex: 1; font-size: 15px; }
.row-opts { display: grid; gap: 8px; margin-top: 10px; }
.row-opts .chip { padding: 5px 11px; min-height: 34px; font-size: 14px; }
.names { min-height: 40px !important; font-size: 15px !important; }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button { width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-size: 18px; }
.stepper .count { min-width: 28px; text-align: center; font-weight: 800; }
.stepper.big button { width: 44px; height: 44px; }
.stepper .unit { color: var(--muted); margin-right: 6px; }
.del { width: 32px; height: 32px; border: 0; background: none; color: var(--muted); font-size: 22px; cursor: pointer; border-radius: 8px; }
.del:hover { color: var(--red); }

.result { border: 2px solid var(--gold); }
.alloc { display: grid; gap: 8px; }
.alloc-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; padding: 12px; border-radius: 14px; background: var(--gold-soft); position: relative; }
.alloc-row.locked { outline: 2px solid var(--gold); }
.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.who-name { font-weight: 700; font-size: 15px; }
.who-sub { font-size: 13px; color: var(--muted); }
.amt { text-align: right; }
.amt-big { font-size: 24px; font-weight: 800; color: var(--red); font-variant-numeric: tabular-nums; }
.amt-sub { font-size: 13px; color: var(--muted); }
.amt-edit { grid-column: 1 / -1; }
.amt-select { min-height: 38px !important; font-size: 14px !important; padding: 6px 10px !important; background: var(--panel) !important; }
.sum { margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--line); display: grid; gap: 8px; }
.sum strong { font-size: 26px; color: var(--red); }
.bar { height: 10px; border-radius: 6px; background: var(--chip); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--good); border-radius: 6px; }
.bar.over i { background: var(--red); }
.good { color: var(--good); font-weight: 700; }
.bad { color: var(--red); font-weight: 700; }
.tips { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 8px; }
.tips li { padding: 10px 12px; border-radius: 12px; font-size: 14px; }
.tips .ok { background: var(--good-soft); }
.tips .info { background: var(--chip); }
.tips .warn { background: var(--warn-soft); }
.tips .bad { background: var(--red-soft); font-weight: 600; }
.balance { margin-top: 12px; }
.balance-labels { display: flex; justify-content: space-between; font-size: 14px; font-weight: 600; }
.balance-bar { height: 14px; border-radius: 8px; background: #4a7bd0; overflow: hidden; margin-top: 4px; }
.balance-bar i { display: block; height: 100%; background: var(--red); }
.bills { margin-top: 18px; padding-top: 4px; border-top: 1px dashed var(--line); }
.bill-list { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 6px; }
.bill-list li { display: flex; justify-content: space-between; padding: 8px 12px; background: var(--bg); border-radius: 10px; }

/* ---------- 單包建議 ---------- */
.verdict { text-align: center; padding: 8px 0 4px; }
.verdict-label { color: var(--muted); font-weight: 600; }
.verdict-amt { font-size: clamp(44px, 12vw, 60px); font-weight: 900; color: var(--red); line-height: 1.1; font-variant-numeric: tabular-nums; }
.verdict-range { color: var(--muted); margin-top: 4px; }
.why { padding-left: 20px; margin: 0; }
.why li { margin: 4px 0; }
.options { display: grid; gap: 8px; margin-top: 12px; }
.option { padding: 12px 14px; border: 1px solid var(--line); border-radius: 14px; position: relative; }
.option.best { border: 2px solid var(--red); background: var(--red-soft); }
.option-amt { font-weight: 800; font-size: 18px; }
.badge { position: absolute; top: 10px; right: 12px; background: var(--red); color: #fff; font-size: 12px; padding: 2px 8px; border-radius: 999px; }

/* ---------- 需要包嗎 ---------- */
.need-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.need-list li { padding: 12px 14px; border-radius: 14px; background: var(--bg); border: 1px solid var(--line); }
.need-list p { margin: 4px 0 0; font-size: 15px; }
.need-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tag { font-size: 13px; font-weight: 700; padding: 2px 10px; border-radius: 999px; white-space: nowrap; }
.tag.must { background: var(--red); color: #fff; }
.tag.should { background: var(--red-soft); color: var(--red); }
.tag.maybe { background: var(--warn-soft); color: var(--warn); }
.tag.no { background: var(--good-soft); color: var(--good); }

/* ---------- 賀詞 ---------- */
.words { display: flex; flex-wrap: wrap; gap: 8px; }
.word { font-size: 20px; font-weight: 700; padding: 10px 16px; border-radius: 12px; border: 2px solid var(--red); color: var(--red); background: var(--red-soft); cursor: pointer; letter-spacing: .12em; }
.msg { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; padding: 12px 0; border-top: 1px solid var(--line); }
.msg p { margin: 0; }

/* ---------- 帳本 ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stats > div { background: var(--bg); border-radius: 12px; padding: 10px; text-align: center; }
.stat-label { font-size: 13px; color: var(--muted); }
.stat-num { font-size: 20px; font-weight: 800; }
.blur { filter: blur(7px); user-select: none; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 480px) { .grid2 { grid-template-columns: 1fr; } }
.advice { color: var(--warn); font-size: 14px; }
.advice p { background: var(--warn-soft); padding: 10px 12px; border-radius: 12px; margin: 8px 0 0; color: var(--ink); }
.list-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.list-head h2 { margin: 0; }
.item { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.item-main { display: flex; gap: 10px; align-items: flex-start; min-width: 0; }
.item-side { text-align: right; white-space: nowrap; font-weight: 700; }
.item-side .link { display: inline; }
.dir { flex: none; width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; font-size: 13px; font-weight: 800; color: #fff; background: var(--red); }
.item.receive .dir { background: var(--good); }
.person { border: 1px solid var(--line); border-radius: 14px; padding: 12px; margin: 10px 0; }
.person-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }

/* ---------- 提示、彈窗、吐司 ---------- */
.notice { display: flex; gap: 10px; align-items: flex-start; background: var(--warn-soft); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin: 0 0 14px; font-size: 14px; }
.notice p { margin: 0; flex: 1; }
.notice.soft { background: var(--gold-soft); }
.notice-x { border: 0; background: none; font-size: 20px; cursor: pointer; color: var(--muted); line-height: 1; }
main > .notice { max-width: 728px; margin: 12px auto; }
.modal { position: fixed; inset: 0; background: rgba(20, 8, 4, .6); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-box { background: var(--panel); border-radius: 20px; padding: 18px; width: min(460px, 100%); max-height: 92vh; overflow: auto; position: relative; }
.modal-box h2 { margin: 0 0 12px; font-size: 19px; }
.modal-x { position: absolute; top: 8px; right: 10px; border: 0; background: none; font-size: 26px; cursor: pointer; color: var(--muted); }
.share-canvas { width: 100%; height: auto; border-radius: 14px; margin-top: 12px; display: block; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 30px); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: 14px; opacity: 0; transition: .25s; pointer-events: none; z-index: 60; max-width: 90vw; }
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 內容區塊 ---------- */
.prose { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 6px 18px 12px; margin: 0 0 14px; }
.prose h2 { font-size: 20px; margin: 20px 0 8px; }
.prose p, .prose li { font-size: 16px; }
.prose table { width: 100%; border-collapse: collapse; font-size: 15px; margin: 8px 0 12px; }
.prose th, .prose td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.prose th { background: var(--chip); font-weight: 700; }
.prose td.n { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.table-wrap { overflow-x: auto; }
.faq details { border-bottom: 1px solid var(--line); padding: 12px 0; }
.faq summary { font-weight: 700; cursor: pointer; font-size: 16px; }
.faq details p { margin: 8px 0 0; }
.related { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; margin: 8px 0 14px; }
.related a { display: block; padding: 12px 14px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); text-decoration: none; color: var(--ink); font-weight: 600; }
.related a:hover { border-color: var(--red); }
.related small { display: block; color: var(--muted); font-weight: 400; }
.section-title { font-size: 18px; margin: 24px 0 8px; }

/* 首頁 */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.tile { display: block; padding: 18px; border-radius: 18px; background: var(--panel); border: 1px solid var(--line); text-decoration: none; color: var(--ink); box-shadow: var(--shadow); }
.tile:hover { border-color: var(--red); }
.tile.feature { background: linear-gradient(135deg, #f4c76b, #f9dca0); color: #5a1206; border: 0; grid-column: 1 / -1; }
.tile .t-emoji { font-size: 30px; }
.tile strong { display: block; font-size: 18px; margin: 6px 0 2px; }
.tile span { color: inherit; opacity: .8; font-size: 14px; }
.foot { color: var(--muted); font-size: 13px; padding: 24px 0 40px; border-top: 1px solid var(--line); }
.foot a { color: var(--muted); }

/* ---------- 分配器：選取按鈕與年齡人數 ---------- */
.add-group-label { font-size: 13px; font-weight: 700; color: var(--muted); margin: 14px 0 6px; letter-spacing: .05em; }
.add-grid { margin: 0 0 4px; }
.add-btn { justify-content: flex-start; }
.add-btn .add-label { flex: 1; }
.add-btn .check { font-weight: 800; color: var(--muted); }
.add-btn.on { background: var(--red); border: 1px solid var(--red); color: #fff; font-weight: 700; }
.add-btn.on .check { color: #fff; }
.rows-title { font-size: 15px; margin: 18px 0 8px; }
.ages { display: grid; gap: 6px; margin-top: 10px; }
.age-line { display: grid; grid-template-columns: 64px auto 1fr; align-items: center; gap: 8px; }
.age-line .age-label { font-weight: 700; font-size: 14px; }
.age-line.zero .age-label { color: var(--muted); font-weight: 500; }
.age-line .names { min-height: 36px !important; font-size: 14px !important; padding: 6px 10px !important; }
@media (max-width: 420px) { .age-line { grid-template-columns: 56px auto; } .age-line .names { grid-column: 1 / -1; } }
.row-total { margin-left: auto; font-size: 14px; font-weight: 700; color: var(--red); white-space: nowrap; }
.row-total.zero { color: var(--muted); font-weight: 500; }
