:root {
  --bg: #f7f1e8;
  --surface: #fffdf9;
  --surface-2: #f1e8db;
  --ink: #2f3147;
  --ink-2: #6b6d80;
  --line: #e6dccd;
  --accent: #e07a5f;
  --accent-ink: #fff;
  --accent-soft: #fbe3da;
  --sage: #81b29a;
  --radius: 16px;
  --shadow: 0 1px 2px rgb(47 49 71 / 6%), 0 4px 16px rgb(47 49 71 / 6%);
  --tab-h: 64px;

  --green: #3f8a5f;  --green-bg: #e2f1e7;
  --blue: #3b6fa8;   --blue-bg: #e1ebf6;
  --amber: #a86b12;  --amber-bg: #fbedd2;
  --purple: #7a52a3; --purple-bg: #eee5f7;
  --gray: #6b6d80;   --gray-bg: #ebe8e3;
  --pink: #b8466a;   --pink-bg: #f9e0e8;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1d26;
    --surface: #262833;
    --surface-2: #30323f;
    --ink: #f1ede6;
    --ink-2: #a9aab8;
    --line: #3a3c4a;
    --accent: #ec8b70;
    --accent-soft: #4a3029;
    --green: #8fd1a8;  --green-bg: #213a2b;
    --blue: #9cc1ec;   --blue-bg: #1f2f43;
    --amber: #f0c06e;  --amber-bg: #3d3019;
    --purple: #c9a8ec; --purple-bg: #33284a;
    --gray: #b3b3bd;   --gray-bg: #34353f;
    --pink: #f0a0ba;   --pink-bg: #45242f;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 16px);
}
button, input, select, textarea { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }
h1, h2, h3 { margin: 0; line-height: 1.3; }

/* ---------- top & tabs ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
}
.topbar h1 { font-size: 20px; font-weight: 700; letter-spacing: .02em; }
#child-switch select {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 6px 12px; font-size: 14px; max-width: 160px;
}

main { max-width: 860px; margin: 0 auto; padding: 4px 16px 24px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: end;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding: 0 8px env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar button {
  border: 0; background: none; color: var(--ink-2); font-size: 11px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  height: var(--tab-h); justify-content: center; cursor: pointer;
}
.tabbar button span { font-size: 20px; line-height: 1; filter: grayscale(1) opacity(.7); }
.tabbar button.active { color: var(--accent); font-weight: 600; }
.tabbar button.active span { filter: none; }
.tabbar .tab-add span {
  display: grid; place-items: center; filter: none;
  width: 56px; height: 56px; margin-bottom: 14px; border-radius: 50%;
  background: var(--accent); font-size: 24px; box-shadow: 0 6px 16px rgb(224 122 95 / 40%);
}

/* ---------- generic ---------- */
.section { margin-top: 20px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; gap: 8px; }
.section-head h2 { font-size: 17px; }
.muted { color: var(--ink-2); font-size: 14px; }
.small { font-size: 13px; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.stack > * + * { margin-top: 10px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.empty { text-align: center; padding: 32px 16px; color: var(--ink-2); }
.empty .big { font-size: 40px; margin-bottom: 8px; }

.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 12px;
  padding: 10px 16px; cursor: pointer; font-weight: 600; font-size: 15px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.danger { color: #c0392b; border-color: currentColor; background: transparent; }
.btn.sm { padding: 6px 12px; font-size: 13px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; color: var(--accent); font-weight: 600; cursor: pointer; padding: 0; font-size: 14px; }
.icon-btn { border: 0; background: var(--surface-2); width: 34px; height: 34px; border-radius: 50%; cursor: pointer; }

.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.tone-green { color: var(--green); background: var(--green-bg); }
.tone-blue { color: var(--blue); background: var(--blue-bg); }
.tone-amber { color: var(--amber); background: var(--amber-bg); }
.tone-purple { color: var(--purple); background: var(--purple-bg); }
.tone-gray { color: var(--gray); background: var(--gray-bg); }
.tone-pink { color: var(--pink); background: var(--pink-bg); }

/* ---------- forms ---------- */
label.field { display: block; }
label.field > span { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 4px; font-weight: 600; }
input[type=text], input[type=search], input[type=number], input[type=date], input[type=password], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 10px;
  padding: 10px 12px; font-size: 16px; min-height: 44px;
}
textarea { min-height: 72px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

/* ---------- home ---------- */
.hero {
  background: linear-gradient(135deg, var(--accent-soft), var(--surface));
  border-radius: 20px; padding: 20px; box-shadow: var(--shadow);
}
.hero .name { font-size: 24px; font-weight: 800; }
.hero .age { font-size: 15px; color: var(--ink-2); margin-top: 2px; }
.hero .stage { margin-top: 12px; }
.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.progress > i { display: block; height: 100%; background: var(--sage); border-radius: 99px; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 12px; }
.stat { background: var(--surface); border-radius: 14px; padding: 12px 8px; text-align: center; box-shadow: var(--shadow); cursor: pointer; border: 0; }
.stat b { display: block; font-size: 22px; line-height: 1.2; }
.stat span { font-size: 12px; color: var(--ink-2); }

.mini-list { list-style: none; margin: 0; padding: 0; }
.mini-list li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.mini-list li:last-child { border-bottom: 0; }
.thumb { width: 44px; height: 44px; border-radius: 10px; object-fit: cover; background: var(--surface-2); flex: none; display: grid; place-items: center; font-size: 20px; }

/* ---------- items ---------- */
.toolbar { position: sticky; top: 58px; z-index: 5; background: var(--bg); padding: 4px 0 10px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 8px 0 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 6px 12px; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.filters select { min-height: 38px; padding: 6px 10px; font-size: 14px; }

.item-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 640px) { .item-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 820px) { .item-grid { grid-template-columns: repeat(4, 1fr); } }
.item-card { background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); cursor: pointer; border: 0; padding: 0; text-align: left; }
.item-card .ph { aspect-ratio: 1; background: var(--surface-2); display: grid; place-items: center; font-size: 40px; position: relative; }
.item-card .ph img { width: 100%; height: 100%; object-fit: cover; }
.item-card .ph .qty { position: absolute; right: 8px; bottom: 8px; background: rgb(0 0 0 / 55%); color: #fff; font-size: 12px; padding: 1px 8px; border-radius: 99px; }
.item-card .ph .fit { position: absolute; left: 8px; top: 8px; }
.item-card .body { padding: 10px 12px 12px; }
.item-card .nm { font-weight: 700; font-size: 15px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.item-card .meta { font-size: 12px; color: var(--ink-2); margin-top: 4px; }
.item-card .pill { margin-top: 6px; }

/* ---------- checklist ---------- */
.check-row { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--line); }
.check-row:last-child { border-bottom: 0; }
.check-box { width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--line); flex: none; display: grid; place-items: center; font-size: 14px; margin-top: 2px; }
.check-box.have { background: var(--sage); border-color: var(--sage); color: #fff; }
.check-box.skip { background: var(--surface-2); color: var(--ink-2); }
.check-box.want { border-color: var(--pink); color: var(--pink); }
.check-row .nm { font-weight: 600; }
.check-row.done .nm { color: var(--ink-2); }
.check-actions { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }

/* ---------- sheet ---------- */
.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgb(20 20 30 / 45%); animation: fade .2s; }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 94vh; display: flex; flex-direction: column;
  background: var(--bg); border-radius: 22px 22px 0 0; animation: up .25s cubic-bezier(.2,.8,.2,1);
  max-width: 720px; margin: 0 auto;
}
@media (min-width: 760px) {
  .sheet-panel { top: 50%; bottom: auto; transform: translateY(-50%); border-radius: 22px; animation: fade .2s; max-height: 88vh; }
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 8px; }
.sheet-head h2 { font-size: 18px; }
.sheet-body { overflow-y: auto; padding: 8px 16px calc(24px + env(safe-area-inset-bottom)); }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

.photo-preview { width: 100%; max-height: 260px; object-fit: contain; border-radius: 14px; background: var(--surface-2); }
.candidate { background: var(--surface); border-radius: 14px; padding: 12px; box-shadow: var(--shadow); }
.candidate.off { opacity: .5; }
.candidate .head { display: flex; gap: 8px; align-items: center; }
.candidate .head input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); }
.conf { font-size: 12px; color: var(--ink-2); }

.spinner { width: 36px; height: 36px; border: 4px solid var(--surface-2); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 16px); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; z-index: 60; font-size: 14px;
  max-width: calc(100% - 32px); box-shadow: var(--shadow); animation: fade .2s;
}
.notice { border-radius: 12px; padding: 12px; font-size: 14px; background: var(--amber-bg); color: var(--amber); }
.child-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.child-row:last-child { border-bottom: 0; }

/* ---------- 已買清單 ---------- */
.stats-2 { grid-template-columns: 1fr 1fr; }
.stats-2 .stat b { font-size: 20px; }
.mini-list .nm1 { font-weight: 600; line-height: 1.35; }
.price { font-weight: 700; font-size: 14px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.cat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 640px) { .cat-grid { grid-template-columns: repeat(3, 1fr); } }
.cat-tile {
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 10px; align-items: center;
  background: var(--surface); border: 0; border-radius: 14px; padding: 12px; box-shadow: var(--shadow); text-align: left; cursor: pointer;
}
.cat-tile .ic { grid-row: span 2; font-size: 24px; }
.cat-tile b { font-size: 14px; }
.list-summary { margin-bottom: 10px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: none; padding: 5px 10px; border-radius: 8px; font-size: 13px; cursor: pointer; color: var(--ink-2); }
.seg button.on { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }
.group { padding: 12px 16px 4px; margin-bottom: 12px; }
.group-head { display: flex; justify-content: space-between; align-items: baseline; padding-bottom: 4px; border-bottom: 1px solid var(--line); }
.dup { font-size: 13px; color: var(--amber); background: var(--amber-bg); border-radius: 10px; padding: 8px 10px; }
.dup-box:empty { display: none; }

/* ---------- 商品卡 ---------- */
.sheet-head h2:empty + .icon-btn { margin-left: auto; }
.detail > * + * { margin-top: 14px; }
.detail-photo { width: 100%; aspect-ratio: 4 / 3; object-fit: contain; background: var(--surface-2); border-radius: 18px; }
.detail-photo.ph-empty { display: grid; place-items: center; font-size: 64px; }
.detail-head .brand { font-size: 13px; font-weight: 700; color: var(--accent); letter-spacing: .03em; }
.detail-head h2 { font-size: 22px; margin-top: 2px; }
.detail-block { background: var(--surface); border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow); }
.detail-block h3 { font-size: 13px; color: var(--ink-2); margin-bottom: 4px; }
.detail-block p { margin: 0; white-space: pre-wrap; }
.detail-block.tip { background: var(--amber-bg); box-shadow: none; }
.detail-block.tip h3, .detail-block.tip p { color: var(--amber); }
.spec-list { margin: 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 6px; }
.spec-list li { background: var(--surface-2); border-radius: 8px; padding: 3px 10px; font-size: 14px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.kv:last-child { border-bottom: 0; }
.kv span { color: var(--ink-2); }
.kv b { font-weight: 600; text-align: right; }
details summary { cursor: pointer; }

/* ---------- 數量 ---------- */
.row-end { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; flex: none; }
.qty-tag { font-size: 13px; font-weight: 700; color: var(--blue); background: var(--blue-bg); border-radius: 8px; padding: 1px 8px; white-space: nowrap; }
.qty-tag.empty { color: var(--gray); background: var(--gray-bg); }
.size-stats { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 0 4px; }
.size-stats span { background: var(--surface-2); border-radius: 8px; padding: 3px 10px; font-size: 13px; white-space: nowrap; }
.size-stats b { margin-right: 6px; }
.count-row { display: block; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 8px 0; cursor: pointer; }
.count-row:last-of-type { border-bottom: 0; }
.qty-box { display: flex; align-items: center; gap: 12px; }
.qty-main { flex: 1; text-align: center; font-size: 16px; }
.qty-main b { font-size: 28px; }
.step { width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface-2); font-size: 24px; cursor: pointer; flex: none; }
.step:disabled { opacity: .4; cursor: default; }

/* ---------- 待辨識 ---------- */
.thumb-strip { display: flex; gap: 8px; overflow-x: auto; }
.thumb-strip img { width: 72px; height: 72px; object-fit: cover; border-radius: 10px; flex: none; }
.jobs-card { border: 2px solid var(--accent-soft); }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; font-size: .9em; }
