:root {
  --bg: #EDF0F5;
  --surface: #FFFFFF;
  --surface-2: #F5F7FB;
  --ink: #1B2440;
  --muted: #5C6680;
  --line: #D8DEE8;
  --brand: #2B3F86;
  --brand-ink: #FFFFFF;
  --brand-soft: #DFE5F6;
  --stub: #F2C14E;
  --stub-ink: #3A2A00;
  --pos: #1B7F5A;
  --neg: #B83A31;
  --num: "Barlow Condensed", "Arial Narrow", "PingFang TC", sans-serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Heiti TC", sans-serif;
  --r-lg: 20px;
  --r-md: 12px;
  --nav-h: 64px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F1422;
    --surface: #182036;
    --surface-2: #1E2742;
    --ink: #E7EAF3;
    --muted: #9AA4BF;
    --line: #2A3450;
    --brand: #93A9F2;
    --brand-ink: #0F1422;
    --brand-soft: #25315A;
    --stub: #E8B93F;
    --stub-ink: #2A1E00;
    --pos: #4CC495;
    --neg: #F07A70;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
body.locked { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
:focus-visible { outline: 2.5px solid var(--brand); outline-offset: 2px; border-radius: 6px; }
.num { font-family: var(--num); font-variant-numeric: tabular-nums; letter-spacing: .01em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; justify-content: center; }
.fine { color: var(--muted); font-size: 13px; line-height: 1.5; margin: 10px 2px 0; }

.center-msg { padding: 30vh 24px; text-align: center; color: var(--muted); }
.fatal { padding: calc(var(--safe-t) + 48px) 24px; max-width: 520px; margin: 0 auto; }

.demo-banner {
  background: var(--stub); color: var(--stub-ink);
  font-size: 13px; text-align: center;
  padding: calc(var(--safe-t) + 6px) 16px 6px;
}
.demo-banner + .top, .demo-banner + .login { padding-top: 12px; }

/* ---------- 頂部 ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(var(--safe-t) + 12px) 16px 12px;
  background: var(--bg);
}
.title { font-size: 28px; font-weight: 800; margin: 0; flex: 1; letter-spacing: .02em; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; font-size: 22px; color: var(--ink);
  background: var(--surface); flex: none; overflow: hidden;
}
.icon-btn img { width: 100%; height: 100%; object-fit: cover; }
.trip-top .icon-btn { font-size: 28px; line-height: 1; padding-bottom: 3px; }
.trip-title { flex: 1; min-width: 0; }
.trip-title h1 { margin: 0; font-size: 22px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trip-title span { color: var(--muted); font-size: 13px; }

.page { max-width: 640px; margin: 0 auto; padding: 4px 16px 32px; }
.page.with-nav { padding-bottom: calc(var(--nav-h) + var(--safe-b) + 96px); }
section { margin-top: 20px; }
.sec-h { font-size: 15px; font-weight: 700; margin: 0 2px 10px; color: var(--muted); }

/* ---------- 登入 ---------- */
.login { max-width: 420px; margin: 0 auto; padding: calc(var(--safe-t) + 14vh) 24px 40px; text-align: center; }
.login-mark { display: inline-block; transform: rotate(-4deg); margin-bottom: 12px; }
.login h1 { font-size: 34px; margin: 0 0 8px; letter-spacing: .04em; }
.lede { color: var(--muted); margin: 0 0 32px; }
.hint { color: var(--muted); font-size: 14px; }
.warn { text-align: left; background: var(--surface); border-left: 4px solid var(--stub); border-radius: 8px; padding: 12px 14px; margin-bottom: 20px; font-size: 14px; }
.warn strong { display: block; margin-bottom: 2px; }

/* ---------- 按鈕 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 18px; border-radius: var(--r-md);
  background: var(--surface); color: var(--ink); font-weight: 600;
  border: 1px solid var(--line);
}
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.big { min-height: 54px; width: 100%; font-size: 17px; }
.btn.block { display: flex; width: 100%; margin-top: 12px; }
.btn.danger-outline { color: var(--neg); border-color: color-mix(in srgb, var(--neg) 40%, transparent); background: transparent; }
.btn:active { transform: scale(.98); }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }
.link-btn { color: var(--brand); font-size: 14px; font-weight: 600; padding: 8px 2px; }
.link-btn.danger { color: var(--neg); }
.link-btn.inline { padding: 0 0 0 8px; font-size: 13px; }

/* ---------- 旅行列表 ---------- */
.trip-list { display: grid; gap: 10px; margin-bottom: 16px; }
.trip-list.dim { opacity: .7; }
.trip-card {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  background: var(--surface); border-radius: 16px; padding: 14px 16px;
}
.trip-cur {
  width: 52px; height: 52px; border-radius: 14px; flex: none;
  display: grid; place-items: center;
  background: var(--brand); color: var(--brand-ink);
  font: 700 22px var(--num);
}
.trip-body { flex: 1; min-width: 0; display: grid; }
.trip-name { font-size: 18px; font-weight: 700; }
.trip-meta { color: var(--muted); font-size: 13px; }
.chev { color: var(--muted); font-size: 22px; flex: none; }
.empty { text-align: center; color: var(--muted); padding: 48px 12px 24px; }

/* ---------- 帳目 ---------- */
.summary {
  display: flex; align-items: stretch; gap: 16px;
  background: var(--brand); color: var(--brand-ink);
  border-radius: var(--r-lg); padding: 18px 18px 16px; margin-top: 8px;
}
.summary .lbl { display: block; font-size: 12px; opacity: .8; }
.sum-main { flex: 1; min-width: 0; }
.sum-main .big { font-size: clamp(28px, 10vw, 40px); font-weight: 700; line-height: 1.05; display: block; }
.sum-main .sub { font-size: 13px; opacity: .85; }
.sum-side { flex: none; display: grid; gap: 8px; padding-left: 16px; border-left: 1px dashed color-mix(in srgb, var(--brand-ink) 40%, transparent); }
.sum-side .num { font-size: 20px; font-weight: 600; }

.day { margin-top: 22px; }
.day-h { display: flex; justify-content: space-between; font-size: 14px; font-weight: 700; margin: 0 4px 8px; color: var(--muted); }
.day-h span { font: 600 15px var(--num); }
.rows { background: var(--surface); border-radius: 16px; overflow: hidden; }
.rows > * + * { border-top: 1px solid var(--line); }
.ex-row, .bal-row, .set-row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 12px 14px; min-height: 60px;
}
.ex-row:active, .bal-row:active, .set-row:active, .trip-card:active { background: var(--surface-2); }
.ex-cat { font-size: 22px; width: 36px; height: 36px; display: grid; place-items: center; background: var(--surface-2); border-radius: 10px; flex: none; }
.ex-main { flex: 1; min-width: 0; display: grid; }
.ex-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ex-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ex-amt { display: grid; text-align: right; flex: none; }
.ex-amt .num { font-size: 20px; font-weight: 600; line-height: 1.15; }
.ex-amt .twd { font: 500 14px var(--num); color: var(--muted); }

.fab {
  position: fixed; z-index: 6; right: 16px;
  bottom: calc(var(--nav-h) + var(--safe-b) + 16px);
  background: var(--stub); color: var(--stub-ink);
  font-weight: 800; font-size: 17px;
  padding: 14px 22px; border-radius: 999px;
  box-shadow: 0 6px 20px color-mix(in srgb, var(--stub) 45%, transparent);
}
.fab:active { transform: scale(.96); }

/* ---------- 底部分頁 ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 7;
  display: flex; background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tabbar button {
  flex: 1; height: var(--nav-h); display: grid; place-items: center; align-content: center; gap: 2px;
  font-size: 12px; color: var(--muted);
}
.tabbar button.on { color: var(--brand); font-weight: 700; }

/* ---------- 頭像 ---------- */
.av {
  width: 36px; height: 36px; border-radius: 50%; flex: none;
  display: inline-grid; place-items: center; font-size: 19px; line-height: 1;
}
.av.sm { width: 24px; height: 24px; font-size: 14px; }
.av.lg { width: 56px; height: 56px; font-size: 30px; }
.c0 { background: #FFE3C2; } .c1 { background: #D6E8FF; } .c2 { background: #FFD9E4; } .c3 { background: #DDF3D5; }
.c4 { background: #EADFFF; } .c5 { background: #FFF1B8; } .c6 { background: #CFF2EE; } .c7 { background: #E5E7EB; }
@media (prefers-color-scheme: dark) {
  .c0 { background: #5A4128; } .c1 { background: #26405E; } .c2 { background: #5A2E3C; } .c3 { background: #2E4A2A; }
  .c4 { background: #3F3460; } .c5 { background: #544A1E; } .c6 { background: #1F4A46; } .c7 { background: #3A3F4B; }
}
.tag { font-style: normal; font-size: 11px; font-weight: 700; margin-left: 6px; padding: 1px 7px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); vertical-align: 2px; }
.tag.ghost { background: transparent; border: 1px dashed var(--muted); color: var(--muted); }

/* ---------- 結算：車票存根 ---------- */
.ticket {
  --notch: 11px;
  display: flex; margin-bottom: 12px;
  filter: drop-shadow(0 2px 0 color-mix(in srgb, var(--ink) 8%, transparent));
}
.tk-main, .tk-stub { background: var(--surface); }
.tk-main {
  flex: 1; min-width: 0; padding: 14px 16px 14px 18px;
  border-radius: 14px 0 0 14px;
  -webkit-mask: radial-gradient(circle var(--notch) at 100% 0, #0000 98%, #000) top/100% 51% no-repeat,
                radial-gradient(circle var(--notch) at 100% 100%, #0000 98%, #000) bottom/100% 51% no-repeat;
          mask: radial-gradient(circle var(--notch) at 100% 0, #0000 98%, #000) top/100% 51% no-repeat,
                radial-gradient(circle var(--notch) at 100% 100%, #0000 98%, #000) bottom/100% 51% no-repeat;
}
.tk-stub {
  flex: none; width: 104px; display: grid; place-items: center;
  background: var(--stub);
  border-radius: 0 14px 14px 0;
  border-left: 2px dashed color-mix(in srgb, var(--stub-ink) 30%, transparent);
  -webkit-mask: radial-gradient(circle var(--notch) at 0 0, #0000 98%, #000) top/100% 51% no-repeat,
                radial-gradient(circle var(--notch) at 0 100%, #0000 98%, #000) bottom/100% 51% no-repeat;
          mask: radial-gradient(circle var(--notch) at 0 0, #0000 98%, #000) top/100% 51% no-repeat,
                radial-gradient(circle var(--notch) at 0 100%, #0000 98%, #000) bottom/100% 51% no-repeat;
}
.tk-who { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tk-p { display: inline-flex; align-items: center; gap: 6px; }
.tk-p b { font-weight: 700; }
.tk-p .av { width: 28px; height: 28px; font-size: 15px; }
.tk-arrow { color: var(--muted); font-weight: 700; }
.tk-amt { font-size: clamp(30px, 9vw, 38px); font-weight: 700; line-height: 1.1; margin-top: 6px; color: var(--ink); }
.tk-sub { font-size: 12px; color: var(--muted); }
.stub-btn { background: transparent; border: 0; color: var(--stub-ink); font-weight: 800; min-height: 100%; width: 100%; font-size: 15px; }
.settled { background: var(--surface); border-radius: 16px; padding: 22px; text-align: center; font-size: 18px; font-weight: 700; }
.bal-main { flex: 1; min-width: 0; display: grid; }
.bal-name { font-weight: 600; }
.bal-sub { font-size: 13px; color: var(--muted); }
.bal-net { font-size: 17px; font-weight: 600; text-align: right; flex: none; color: var(--muted); }
.pos { color: var(--pos) !important; }
.neg { color: var(--neg) !important; }
.pay-row { display: grid; grid-template-columns: 1fr auto; gap: 0 12px; padding: 10px 14px; align-items: center; }
.pay-row .num { font-size: 18px; font-weight: 600; text-align: right; }
.pay-row .link-btn { justify-self: end; padding: 0; font-size: 13px; }

/* ---------- 分段選擇 ---------- */
.seg { display: flex; background: var(--surface); border-radius: 12px; padding: 4px; gap: 4px; margin: 14px 0 0; }
.seg.center { max-width: 280px; margin: 12px auto 0; }
.seg button { flex: 1; min-height: 38px; border-radius: 9px; font-weight: 600; color: var(--muted); font-size: 15px; }
.seg button.on { background: var(--brand); color: var(--brand-ink); }
.sheet .seg { background: var(--surface-2); }

/* ---------- 換算 ---------- */
.conv-box { background: var(--surface); border-radius: var(--r-lg); padding: 6px 16px; margin-top: 8px; }
.conv-field { display: grid; gap: 2px; padding: 14px 0; }
.conv-field + .conv-mid + .conv-field { border-top: 1px dashed var(--line); }
.conv-field select { font-size: 14px; color: var(--muted); border: 0; background: transparent; padding: 0; font-weight: 600; justify-self: start; }
.conv-field input { border: 0; background: transparent; font-size: 48px; font-weight: 700; width: 100%; padding: 0; line-height: 1.1; }
.conv-field input:focus { outline: none; }
.conv .chips { margin-top: 12px; }
.rate-line { text-align: center; margin: 18px 0 0; color: var(--muted); font-size: 14px; }
.rate-line b { color: var(--ink); font-size: 22px; }

/* ---------- 成員 ---------- */
.invite { background: var(--surface); border-radius: var(--r-lg); padding: 16px; }
.invite .sec-h { color: var(--ink); font-size: 17px; margin-bottom: 4px; }
.invite p { margin: 0 0 14px; font-size: 14px; }
.mem-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; min-height: 58px; }
.mem-name { flex: 1; font-weight: 600; min-width: 0; }
.set-row { justify-content: space-between; font-weight: 600; min-height: 52px; }
.set-row.danger { color: var(--neg); }

/* ---------- 面板 ---------- */
.scrim { position: fixed; inset: 0; background: rgba(8, 12, 28, .45); z-index: 20; }
.sheet {
  position: fixed; z-index: 21; left: 0; right: 0; bottom: 0;
  max-width: 640px; margin: 0 auto;
  max-height: calc(100dvh - var(--safe-t) - 24px);
  display: flex; flex-direction: column;
  background: var(--surface); border-radius: var(--r-lg) var(--r-lg) 0 0;
}
.sheet.enter { animation: up .24s cubic-bezier(.2, .8, .2, 1); }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .sheet.enter { animation: none; } }
.sheet-head { display: flex; align-items: center; padding: 16px 16px 4px 20px; }
.sheet-head h2 { flex: 1; margin: 0; font-size: 20px; }
.sheet-head .icon-btn { background: var(--surface-2); font-size: 16px; width: 34px; height: 34px; }
.sheet-body { overflow-y: auto; padding: 8px 20px calc(var(--safe-b) + 24px); overscroll-behavior: contain; }

.field { display: grid; gap: 6px; margin-top: 14px; }
.field > span { font-size: 14px; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%; min-height: 46px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2);
  font-size: 16px;
}
.field textarea { resize: vertical; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.two .field { min-width: 0; }
.amt-row { display: flex; gap: 10px; align-items: end; }
.amt-row .grow { flex: 1; min-width: 0; }
.amt-row select { width: auto; }
.amt-input { font-size: 30px !important; font-weight: 700; }
.rate-box { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; margin-top: 10px; padding: 10px 12px; background: var(--surface-2); border-radius: 10px; font-size: 14px; align-items: center; }
.rate-box label { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.rate-input { width: 88px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); font-size: 18px; font-weight: 600; }
.rate-src { grid-column: 1; font-size: 12px; color: var(--muted); }
.rate-twd { grid-column: 2; grid-row: 1 / span 2; font-size: 22px; font-weight: 700; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 38px; padding: 0 14px; border-radius: 999px;
  background: var(--surface); border: 1.5px solid var(--line); font-weight: 600; font-size: 15px;
}
.sheet .chip { background: var(--surface-2); }
.chip.person { padding-left: 6px; }
.chip.on { border-color: var(--brand); background: var(--brand-soft) !important; color: var(--brand); }
.chip.check.on::after { content: "✓"; font-weight: 800; }
.split-note { margin: 10px 2px 0; font-size: 14px; color: var(--muted); }
.split-note b { color: var(--ink); font-size: 18px; }
.ok { color: var(--pos); font-weight: 600; }
.warn-text { color: var(--neg); font-weight: 600; font-size: 14px; }
.custom-list { margin-top: 10px; display: grid; gap: 6px; }
.custom-row { display: flex; align-items: center; gap: 8px; background: var(--surface-2); padding: 6px 8px 6px 10px; border-radius: 10px; }
.custom-row span { flex: 1; font-weight: 600; }
.custom-row input { width: 120px; text-align: right; font-size: 20px; font-weight: 600; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }

.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.emoji { aspect-ratio: 1; font-size: 24px; border-radius: 12px; background: var(--surface-2); border: 2px solid transparent; }
.emoji.on { border-color: var(--brand); background: var(--brand-soft); }
.claim { margin-top: 24px; padding-top: 12px; border-top: 1px dashed var(--line); }
.claim p { margin: 0; }
.claim-btn { justify-content: flex-start; }

.pay-who { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: 8px; font-size: 22px; }
.det-sum { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; }
.det-sum > div { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; display: grid; }
.det-sum .lbl { font-size: 12px; color: var(--muted); }
.det-sum .num { font-size: 22px; font-weight: 700; }
.det-sum .det-net { grid-column: 1 / -1; }
.det-h { font-size: 15px; margin: 20px 0 6px; }
.det-row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.det-row small { display: block; color: var(--muted); font-size: 12px; }
.det-row .num { font-size: 18px; font-weight: 600; }

/* ---------- 提示 ---------- */
.toast {
  position: fixed; z-index: 40; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + var(--safe-b) + 80px);
  background: var(--ink); color: var(--bg);
  padding: 10px 18px; border-radius: 12px; font-size: 15px; font-weight: 600;
  max-width: calc(100% - 32px); width: max-content; text-align: center;
  transition: opacity .3s;
}
.toast.err { background: var(--neg); color: #fff; }
.toast.out { opacity: 0; }

/* ---------- 多幣別 ---------- */
.summary.multi .sum-main .big { font-size: clamp(24px, 7.5vw, 32px); }
.summary.multi .sum-side .num { font-size: 17px; }
.sum-side > div { display: grid; }
.sum-main .big + .big { margin-top: 2px; }
.settle-block { margin-top: 18px; }
.settle-block + .settle-block { margin-top: 32px; padding-top: 20px; border-top: 2px dashed var(--line); }
.settle-block .sec-h { margin-top: 14px; }
.cur-h { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 0 2px 4px; font-size: 20px; }
.cur-h small { font-size: 13px; color: var(--muted); font-weight: 600; }
.conv-mid { display: block; margin: 0 auto; width: 36px; height: 36px; border-radius: 50%; background: var(--surface-2); color: var(--brand); font-size: 18px; position: relative; top: 0; }
.conv-field + .conv-mid { margin-top: -18px; margin-bottom: -18px; z-index: 1; }
.conv-field + .conv-mid + .conv-field { border-top: 1px dashed var(--line); }

.notice { margin: 14px 2px 0; padding: 10px 12px; border-left: 4px solid var(--stub); border-radius: 8px; background: var(--surface); font-size: 14px; font-weight: 500; color: var(--ink); }
.fine a { color: var(--brand); }
