:root {
  --bg: #f6f4ee;
  --card: #ffffff;
  --ink: #1d1d1b;
  --muted: #55554f;
  --line: #d9d5c9;
  --brand: #0b5d3b;
  --brand-ink: #ffffff;
  --brand-soft: #e3f1ea;
  --minus: #b3261e;
  --minus-soft: #fde8e6;
  --warn: #8a5300;
  --warn-soft: #fff1d6;
  --ok: #0b5d3b;
  --ok-soft: #e3f1ea;
  --key: #ffffff;
  --key-fn: #ece8dc;
}

/* 規則：畫面上所有字 >= 18px（長輩看得清楚），測試會檢查 */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  font-size: 20px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
[hidden] { display: none !important; }

.view { min-height: 100vh; }
.pad { padding: 16px; max-width: 560px; margin: 0 auto; }

/* 標題列 */
.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  background: var(--brand); color: var(--brand-ink);
  padding: 10px 16px; min-height: 60px;
}
.bar h1 { margin: 0; font-size: 24px; }
.back {
  background: rgba(255,255,255,.18); border: 0; color: #fff;
  border-radius: 10px; padding: 6px 12px; font-size: 19px; min-height: 48px;
  white-space: nowrap;
}

/* 大字累計（精簡高度，讓鍵盤和加入鈕擠得進一個畫面） */
.total-bar {
  position: sticky; top: 0; z-index: 5;
  background: var(--brand); color: #fff;
  padding: 6px 16px;
  display: flex; align-items: center; gap: 10px;
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
}
.total-wrap { flex: 1; text-align: right; line-height: 1.1; min-width: 0; }
.total-store { display: block; font-size: 18px; opacity: .95; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.total-label { font-size: 20px; margin-right: 8px; }
.total-num { font-size: 42px; font-weight: 800; font-variant-numeric: tabular-nums; }
.total-unit { font-size: 20px; margin-left: 2px; }
.total-num.neg { color: #ffd2cc; }

.label { font-size: 22px; margin: 18px 0 8px; }
.list-head { display: flex; align-items: baseline; gap: 8px; }
.count { font-size: 19px; color: var(--muted); font-weight: 400; }
.hint { margin: 0 0 10px; color: var(--muted); font-size: 19px; }
.empty { color: var(--muted); text-align: center; padding: 18px 8px; font-size: 19px; }

/* 按鈕 */
.btn {
  display: block; width: 100%;
  border: 2px solid transparent; border-radius: 14px;
  padding: 10px 14px; min-height: 60px;
  font-size: 22px; font-weight: 700;
}
.btn-xl { min-height: 68px; font-size: 24px; margin-top: 14px; }
.btn-primary { background: var(--brand); color: var(--brand-ink); }
.btn-primary:disabled { background: #a9b9b0; color: #f4f4f4; cursor: not-allowed; }
.btn-secondary { background: var(--card); border-color: var(--brand); color: var(--brand); }
.btn-check { background: #1d3f73; color: #fff; }
.btn-danger { background: var(--minus); color: #fff; }
.btn-ghost { background: transparent; color: var(--muted); text-decoration: underline; font-weight: 400; font-size: 19px; min-height: 48px; }
.btn-mic { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); min-height: 72px; font-size: 23px; margin-top: 10px; }
.btn-mic.listening { background: var(--minus); border-color: var(--minus); color: #fff; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .7; } }
.btn:active, .numpad button:active, .store:active, .kind:active, .amount-display:active { transform: scale(.97); }
.mic-status { min-height: 1.5em; margin: 6px 2px 0; font-size: 19px; color: var(--muted); }

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

/* 首頁 */
.resume { border: 2px solid var(--brand); background: var(--brand-soft); }
.resume-title { margin: 0; font-weight: 800; font-size: 22px; }
.resume-info { margin: 4px 0 0; }
.store-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.store {
  min-height: 76px; border-radius: 14px; border: 2px solid var(--line);
  background: var(--card); font-size: 22px; font-weight: 700;
}
.store.on { border-color: var(--brand); background: var(--brand); color: #fff; }
.store.on::before { content: "✔ "; }
.text-in {
  width: 100%; font: inherit; font-size: 22px;
  padding: 10px 14px; min-height: 60px;
  border: 2px solid var(--line); border-radius: 12px; background: #fff;
  margin-top: 10px;
}
.text-in:focus { outline: 3px solid #8cc7a9; border-color: var(--brand); }

/* 購物中 */
.shop-main { padding-top: 12px; padding-bottom: 32px; }
.amount-display {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: #fff; border: 2px solid var(--line); border-radius: 12px;
  padding: 2px 14px; min-height: 66px; text-align: left;
  font-variant-numeric: tabular-nums;
}
.entry-tag { font-size: 19px; color: var(--muted); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-tag b { color: var(--ink); }
.amt { white-space: nowrap; }
.amount-sign { font-size: 26px; font-weight: 800; color: var(--minus); margin-right: 2px; }
.amount-text { font-size: 42px; font-weight: 800; }
.amount-unit { font-size: 20px; margin-left: 4px; }
.amount-display.minus { border-color: var(--minus); background: var(--minus-soft); }
.amount-display.minus .amount-text { color: var(--minus); }

.numpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.numpad button {
  min-height: 60px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--key); font-size: 30px; font-weight: 700;
  box-shadow: 0 2px 0 var(--line);
}
.numpad .k-fn { background: var(--key-fn); font-size: 22px; }
.btn-add { margin-top: 10px; min-height: 64px; font-size: 25px; }
.two-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.two-btns .btn { font-size: 20px; padding: 6px 4px; }

/* 清單 */
.item-list { list-style: none; padding: 0; margin: 0; }
.item-list li {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; margin-bottom: 8px; min-height: 64px;
}
.tap-list li { cursor: pointer; }
.tap-list li::after { content: "›"; font-size: 28px; color: var(--muted); }
.item-list li.minus { background: var(--minus-soft); border-color: #f1b8b2; }
.it-no { color: var(--muted); font-size: 19px; min-width: 1.6em; }
.it-name { flex: 1; word-break: break-all; }
.it-name .noname { color: var(--muted); }
.tag {
  display: inline-block; font-size: 18px; font-weight: 700; line-height: 1.4;
  padding: 0 8px; border-radius: 8px; margin-right: 6px;
  background: var(--minus); color: #fff;
}
.it-amt { font-weight: 800; font-size: 22px; font-variant-numeric: tabular-nums; white-space: nowrap; }
li.minus .it-amt { color: var(--minus); }

.check-list li { cursor: pointer; }
.check-list li .box {
  width: 40px; height: 40px; flex: 0 0 40px; border-radius: 8px;
  border: 3px solid var(--muted); background: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 26px; font-weight: 900;
}
.check-list li.done { background: var(--ok-soft); border-color: #9ccbb3; }
.check-list li.done .box { background: var(--ok); border-color: var(--ok); color: #fff; }
.check-list li.done .box::after { content: "✔"; }

/* 核對 */
.cmp-row { display: flex; justify-content: space-between; align-items: baseline; padding: 6px 0; gap: 8px; }
.cmp-row b { font-size: 26px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.receipt-num.placeholder { font-size: 19px; color: var(--muted); font-weight: 400; }
.diff { margin-top: 8px; border-radius: 10px; padding: 12px; font-size: 22px; font-weight: 800; text-align: center; }
.diff.same { background: var(--ok-soft); color: var(--ok); border: 2px solid var(--ok); }
.diff.off { background: var(--warn-soft); color: var(--warn); border: 2px solid var(--warn); }
.diff small { display: block; font-size: 19px; font-weight: 400; color: var(--ink); margin-top: 4px; }

/* 收據照片 */
.photo-card { margin-top: 12px; }
.photo-thumb { display: block; width: 100%; padding: 0; border: 0; background: none; margin-bottom: 10px; text-align: center; }
.photo-thumb img { display: block; width: 100%; max-height: 240px; object-fit: contain; background: #eee; border-radius: 10px; }
.photo-thumb.card { padding: 10px; }
.photo-cap { display: block; margin-top: 6px; font-size: 19px; color: var(--brand); font-weight: 700; }

/* 歷史 */
.hist-list { list-style: none; padding: 0; margin: 0; }
.hist-list li { margin-bottom: 10px; }
.hist-btn {
  width: 100%; text-align: left; background: var(--card);
  border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px;
  display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; min-height: 72px;
}
.hist-date { font-size: 19px; color: var(--muted); }
.hist-store { font-weight: 800; font-size: 22px; }
.hist-total { grid-row: 1 / span 2; grid-column: 2; align-self: center; font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }
.hist-flag { grid-column: 1 / span 2; font-size: 19px; }
.hist-flag.ok { color: var(--ok); }
.hist-flag.off { color: var(--warn); font-weight: 700; }

/* 底部彈出面板 */
.sheet {
  border: 0; margin: auto 0 0 0; width: 100%; max-width: 100%;
  max-height: 92vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 16px 16px 20px;
  background: var(--bg);
}
.sheet::backdrop, .dlg::backdrop, .viewer::backdrop { background: rgba(0,0,0,.55); }
.sheet-title { font-size: 22px; margin: 4px 0 10px; }
.sheet-title + .kind-row { margin-bottom: 16px; }
.kind-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kind {
  min-height: 64px; border: 2px solid var(--line); border-radius: 12px;
  background: var(--card); font-size: 20px; font-weight: 700; padding: 4px;
}
.kind.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.kind[data-kind="discount"].on, .kind[data-kind="return"].on { background: var(--minus); border-color: var(--minus); }
.kind.on::before { content: "✔"; margin-right: 2px; }
.name-show { background: #fff; border: 2px solid var(--line); border-radius: 12px; padding: 10px 14px; min-height: 56px; font-size: 24px; font-weight: 700; }
.name-show.empty-name { color: var(--muted); font-weight: 400; font-size: 20px; }
.it-info { background: #fff; border: 2px solid var(--line); border-radius: 12px; padding: 12px 14px; font-size: 24px; display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.it-info.minus { background: var(--minus-soft); border-color: #f1b8b2; }
.it-info .it-amt { font-size: 26px; }
#it-del { margin-top: 18px; }

/* 看大圖 */
.viewer { border: 0; padding: 10px; width: 100vw; max-width: 100vw; height: 100vh; max-height: 100vh; margin: 0; background: #111; }
.viewer[open] { display: flex; flex-direction: column; gap: 10px; }
.viewer img { flex: 1; min-height: 0; width: 100%; object-fit: contain; }
.viewer .btn { flex: 0 0 auto; }

/* 確認框、提示 */
.dlg { border: 0; border-radius: 16px; padding: 20px; width: min(92vw, 420px); }
.dlg-msg { font-size: 22px; margin: 0 0 16px; }
.dlg-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.toast {
  /* 放底部：上方是長輩正在看的金額框，不能擋；底部在首屏是「已買清單」標題，空著 */
  position: fixed; left: 50%; bottom: 10px; transform: translateX(-50%);
  pointer-events: none; /* 不擋住底下的按鈕 */
  background: #222; color: #fff; padding: 12px 20px; border-radius: 12px;
  font-size: 21px; z-index: 20; width: max-content; max-width: 90vw; text-align: center;
  box-shadow: 0 4px 12px rgba(0,0,0,.3);
}

/* 首頁標題列：右邊「怎麼用」 */
.bar h1 { font-size: 22px; white-space: nowrap; min-width: 0; }
.howto-btn {
  margin-left: auto; flex: none;
  background: rgba(255,255,255,.2); border: 2px solid rgba(255,255,255,.7); color: #fff;
  border-radius: 12px; padding: 4px 12px; min-height: 48px; font-size: 19px; font-weight: 700; white-space: nowrap;
}

/* 放到手機桌面（綠色大卡片） */
.install-card { background: var(--brand); color: #fff; border-radius: 16px; padding: 14px 16px; margin-bottom: 14px; }
.install-title { margin: 0 0 8px; font-size: 24px; font-weight: 800; }
.install-btn {
  display: block; width: 100%; min-height: 64px; border: 0; border-radius: 14px;
  background: #fff; color: var(--brand); font-size: 24px; font-weight: 800;
}
.install-steps { margin: 0; font-size: 19px; line-height: 1.45; }
.install-steps ol { margin: 0; padding: 0; list-style: none; }
.install-steps li { display: flex; gap: 10px; align-items: flex-start; margin: 4px 0; }
.install-steps .n { flex: none; width: 32px; height: 32px; border-radius: 50%; background: #fff; color: var(--brand); font-weight: 800; text-align: center; line-height: 32px; }
.install-steps .ic { font-size: 22px; }

/* 怎麼用：全螢幕、4 步純 CSS 動畫 */
.howto { position: fixed; inset: 0; z-index: 40; background: var(--bg); overflow-y: auto; padding: 12px 16px 16px; display: flex; flex-direction: column; max-width: 560px; margin: 0 auto; }
.hw-top { display: flex; align-items: center; justify-content: space-between; min-height: 48px; }
.hw-count { font-size: 20px; font-weight: 800; color: var(--brand); }
.hw-skip { background: transparent; border: 0; color: var(--muted); text-decoration: underline; font-size: 20px; min-height: 48px; padding: 0 8px; }
.hw-stage { position: relative; height: 218px; background: #fff; border: 2px solid var(--line); border-radius: 16px; overflow: hidden; margin: 6px 0 10px; }
.hw-step { position: absolute; inset: 0; padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.hw-step[hidden] { display: none; }
.hw-text { margin: 0 0 10px; font-size: 22px; font-weight: 700; line-height: 1.45; min-height: 96px; }
.hw-btns { display: flex; gap: 10px; margin-top: auto; }
.hw-btns .btn { flex: 1; }
.hw-btns .btn[hidden] { display: none; }

.m-row { display: flex; gap: 8px; }
.m-box { flex: 1; text-align: center; min-height: 56px; line-height: 52px; border: 2px solid var(--line); border-radius: 12px; font-size: 18px; font-weight: 700; background: #fff; }
.m-hit { background: var(--brand); border-color: var(--brand); color: #fff; }
.m-btn { display: block; text-align: center; min-height: 56px; line-height: 56px; border-radius: 12px; background: var(--brand); color: #fff; font-size: 20px; font-weight: 700; }
.m-blue { background: #1d3f73; }
.m-amount { min-height: 66px; border: 2px solid var(--brand); border-radius: 12px; text-align: center; font-size: 20px; line-height: 62px; background: var(--brand-soft); }
.m-amount b { font-size: 40px; }
.m-line { min-height: 46px; line-height: 42px; border: 2px solid var(--line); border-radius: 10px; padding: 0 10px; font-size: 19px; font-weight: 700; background: #fff; }
.m-ok { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }
.m-tick { display: inline-block; width: 30px; height: 30px; line-height: 28px; margin-right: 10px; text-align: center; border: 2px solid var(--brand); border-radius: 8px; background: var(--brand); color: #fff; font-size: 19px; }
.finger { position: absolute; font-size: 40px; line-height: 1; pointer-events: none; }
.f1 { left: 42px; top: 46px; }
.f2 { left: 144px; top: 118px; }
.f3 { left: 144px; top: 90px; }
.f4 { left: 20px; top: 32px; }

@media (prefers-reduced-motion: no-preference) {
  .finger { animation: hw-finger 3.2s ease-in-out infinite; }
  .m-hit, .m-hit-tick { animation: hw-hit 3.2s infinite; }
  .m-hit-btn { animation: hw-press 3.2s infinite; }
  .m-after { animation: hw-reveal 3.2s infinite; }
  .m-after2 { animation: hw-reveal 3.2s infinite; }
}
@keyframes hw-finger {
  0% { opacity: 0; transform: translate(50px, 70px); }
  20% { opacity: 1; }
  45% { transform: translate(0, 0) scale(1); }
  55% { transform: translate(0, 6px) scale(.86); }
  65% { transform: translate(0, 0) scale(1); }
  92% { opacity: 1; }
  100% { opacity: 0; transform: translate(0, 0); }
}
@keyframes hw-hit {
  0%, 53% { background: #fff; color: var(--ink); border-color: var(--line); }
  58%, 92% { background: var(--brand); color: #fff; border-color: var(--brand); }
  100% { background: #fff; color: var(--ink); border-color: var(--line); }
}
@keyframes hw-press { 0%, 52% { transform: scale(1); } 57% { transform: scale(.93); } 66%, 100% { transform: scale(1); } }
@keyframes hw-reveal { 0%, 55% { opacity: 0; } 62%, 92% { opacity: 1; } 100% { opacity: 0; } }
@media (prefers-reduced-motion: no-preference) { .m-hit-tick { animation-name: hw-tick; } }
@keyframes hw-tick {
  0%, 53% { background: #fff; color: transparent; }
  58%, 92% { background: var(--brand); color: #fff; }
  100% { background: #fff; color: transparent; }
}
