:root {
  --brand: #c2410c;
  --brand-ink: #fff;
  --bg: #f6f4f1;
  --surface: #fff;
  --ink: #1c1917;
  --muted: #78716c;
  --line: #e7e5e4;
  --danger: #b91c1c;
  --ok: #15803d;
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161412;
    --surface: #221f1c;
    --ink: #f5f5f4;
    --muted: #a8a29e;
    --line: #3a3532;
    --danger: #f87171;
    --ok: #4ade80;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
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;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; }

/* ---------- 頁首與分類 ---------- */
.header {
  background: var(--brand);
  color: var(--brand-ink);
  padding: 18px 16px 14px;
}
.header h1 { margin: 0; font-size: 22px; line-height: 1.3; }
.badge-table {
  display: inline-block;
  margin-top: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,.22);
  font-size: 14px;
  font-weight: 600;
}
.closed-banner {
  background: #fef3c7; color: #78350f;
  padding: 10px 16px; font-size: 14px;
}

.cat-nav {
  position: sticky; top: 0; z-index: 5;
  display: flex; gap: 8px;
  overflow-x: auto; scrollbar-width: none;
  padding: 10px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.cat-nav::-webkit-scrollbar { display: none; }
.cat-nav button {
  flex: none;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 15px;
}
.cat-nav button[aria-current="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* ---------- 菜單 ---------- */
main { padding: 4px 16px calc(110px + var(--safe-bottom)); max-width: 640px; margin: 0 auto; }
.cat-title { font-size: 18px; margin: 22px 0 10px; scroll-margin-top: 64px; }
.item {
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  padding: 14px;
  margin-bottom: 10px;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface);
  text-align: left;
  box-shadow: 0 1px 2px rgba(0,0,0,.05);
}
.item img { width: 64px; height: 64px; border-radius: 10px; object-fit: cover; flex: none; }
.item-body { flex: 1; min-width: 0; }
.item-name { font-weight: 600; }
.item-desc { color: var(--muted); font-size: 14px; margin-top: 2px; }
.item-price { margin-top: 4px; font-weight: 600; color: var(--brand); }
.item-add {
  flex: none;
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--brand); color: var(--brand-ink);
  font-size: 22px; line-height: 1;
}
.item-count {
  flex: none;
  min-width: 26px; height: 26px; padding: 0 8px; border-radius: 13px;
  display: grid; place-items: center;
  background: var(--ink); color: var(--bg);
  font-size: 13px; font-weight: 700;
}
.item.sold-out { opacity: .5; }
.item.sold-out .item-add { background: var(--muted); font-size: 12px; width: auto; padding: 0 10px; border-radius: 18px; }

.privacy { color: var(--muted); font-size: 13px; text-align: center; margin: 28px 0 8px; }

/* ---------- 購物車列 ---------- */
.cart-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  padding: 10px 16px calc(10px + var(--safe-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.cart-bar button { max-width: 608px; margin: 0 auto; display: flex; }
.btn-primary {
  width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 52px;
  border: 0; border-radius: var(--radius);
  background: var(--brand); color: var(--brand-ink);
  font-size: 17px; font-weight: 700;
}
.btn-primary:disabled { opacity: .5; }
.btn-primary .count {
  background: rgba(255,255,255,.25); border-radius: 999px; padding: 0 9px; font-size: 14px;
}
.btn-ghost {
  border: 1px solid var(--line); background: var(--surface);
  border-radius: var(--radius); min-height: 48px; padding: 0 16px; width: 100%;
}

/* ---------- 底部面板 ---------- */
.backdrop {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 40;
  background: rgba(0,0,0,.45);
  touch-action: none; /* 避免在遮罩上滑動時捲到後面的菜單 */
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: flex; flex-direction: column;
  width: 100%; max-width: 640px;
  max-height: 92vh; max-height: 92dvh;
  margin: 0 auto;
  border-radius: 20px 20px 0 0;
  background: var(--surface); color: var(--ink);
  overflow: hidden;
  animation: slide-up .2s ease-out;
}
@keyframes slide-up { from { transform: translateY(40px); opacity: .6; } }
.sheet-form { display: flex; flex-direction: column; flex: 1; min-height: 0; margin: 0; }
.sheet-head {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 18px 16px 12px;
  border-bottom: 1px solid var(--line);
}
.sheet-head h2 { margin: 0; font-size: 20px; flex: 1; }
.sheet-head .sub { color: var(--muted); font-size: 14px; font-weight: 400; margin-top: 2px; }
.btn-close {
  flex: none; width: 36px; height: 36px; border-radius: 50%;
  border: 0; background: var(--bg); font-size: 20px; line-height: 1;
}
.sheet-body { padding: 4px 16px 16px; overflow-y: auto; flex: 1; min-height: 0; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.sheet-foot { padding: 12px 16px calc(12px + var(--safe-bottom)); border-top: 1px solid var(--line); }

/* 選項群組 */
fieldset { border: 0; padding: 0; margin: 16px 0 0; min-width: 0; }
legend { font-weight: 700; padding: 0; margin-bottom: 8px; display: flex; gap: 8px; align-items: baseline; }
legend .hint { font-weight: 400; color: var(--muted); font-size: 13px; }
legend .req { font-size: 12px; font-weight: 600; color: var(--brand); border: 1px solid currentColor; border-radius: 6px; padding: 0 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
/* 整個 label 都是點擊範圍；input 只做視覺隱藏，點擊交給 label 觸發（各家手機瀏覽器都支援） */
.chip { position: relative; display: inline-block; cursor: pointer; -webkit-user-select: none; user-select: none; }
.chip input {
  position: absolute; width: 1px; height: 1px; margin: 0; padding: 0;
  opacity: 0; overflow: hidden; clip: rect(0 0 0 0); pointer-events: none;
}
.chip span {
  display: inline-flex; align-items: center;
  min-height: 44px;
  padding: 8px 14px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font-size: 15px;
}
/* 選到：實心主色，不依賴 color-mix（舊版 iOS 不支援） */
.chip input:checked + span { border-color: var(--brand); background: var(--brand); color: var(--brand-ink); font-weight: 600; }
.chip input:checked + span::before { content: "✓"; margin-right: 4px; }
.chip input:checked + span small { color: inherit; opacity: .85; }
.chip input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }
.chip input:disabled + span { opacity: .4; text-decoration: line-through; }
.chip input:disabled ~ * { cursor: not-allowed; }
.chip small { color: var(--muted); margin-left: 4px; }

/* 必選但還沒選：按「加入」時標紅並晃一下 */
fieldset.missing legend { color: var(--danger); }
fieldset.missing legend .req { color: var(--danger); }
fieldset.missing .chips { animation: shake .35s; }
fieldset.missing .chip span { border-color: var(--danger); }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.btn-primary.pending { background: var(--ink); color: var(--bg); }

.qty-row { display: flex; align-items: center; justify-content: space-between; margin-top: 20px; font-weight: 700; }
.stepper { display: inline-flex; align-items: center; gap: 4px; }
.stepper button {
  width: 36px; height: 36px; border-radius: 50%;
  border: 1.5px solid var(--line); background: var(--surface);
  font-size: 20px; line-height: 1;
}
.stepper output { min-width: 32px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }

/* 購物車內容 */
.cart-line { display: flex; gap: 12px; align-items: center; padding: 14px 0; border-bottom: 1px solid var(--line); }
.cart-line .info { flex: 1; min-width: 0; }
.cart-line .opts { color: var(--muted); font-size: 14px; }
.cart-line .price { font-weight: 600; font-variant-numeric: tabular-nums; }
.cart-line .stepper button { width: 32px; height: 32px; font-size: 18px; }
.note-label { display: block; font-weight: 700; margin-top: 18px; }
.note-label .hint { font-weight: 400; color: var(--muted); font-size: 13px; float: right; }
textarea {
  display: block; width: 100%; margin-top: 8px;
  border: 1.5px solid var(--line); border-radius: 10px;
  padding: 10px 12px; font: inherit; resize: none;
  background: var(--surface); color: var(--ink);
}
textarea:focus { outline: none; border-color: var(--brand); }
.total-row { display: flex; justify-content: space-between; margin-top: 18px; font-size: 18px; font-weight: 700; }
.total-row .muted { color: var(--muted); font-weight: 400; font-size: 14px; }
.cf-turnstile-slot { margin-top: 14px; min-height: 0; display: flex; justify-content: center; }
.form-error { color: var(--danger); font-size: 14px; margin: 10px 0 0; }
.foot-hint { color: var(--muted); font-size: 13px; text-align: center; margin: 8px 0 0; }

/* ---------- 狀態畫面 ---------- */
.state-screen {
  min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 24px; text-align: center;
}
.state-screen h2 { margin: 0; font-size: 22px; }
.state-screen p { margin: 0; color: var(--muted); }
.state-icon { font-size: 52px; line-height: 1; }
.spinner {
  width: 32px; height: 32px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--brand);
  animation: spin .8s linear infinite;
}
.btn-primary .spinner { width: 20px; height: 20px; border-color: rgba(255,255,255,.4); border-top-color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }

.receipt {
  width: 100%; max-width: 420px;
  background: var(--surface); border-radius: var(--radius);
  padding: 16px; text-align: left; margin: 8px 0;
}
.receipt .order-no { font-size: 28px; font-weight: 800; letter-spacing: 1px; text-align: center; }
.receipt .order-meta { text-align: center; color: var(--muted); font-size: 14px; margin-bottom: 10px; }
.receipt ul { list-style: none; padding: 0; margin: 0; border-top: 1px dashed var(--line); }
.receipt li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.receipt li .opts { display: block; color: var(--muted); font-size: 13px; }
.receipt .total { display: flex; justify-content: space-between; font-weight: 700; margin-top: 10px; }
.receipt pre {
  white-space: pre-wrap; font: 13px/1.5 ui-monospace, Menlo, monospace;
  background: var(--bg); padding: 10px; border-radius: 8px; margin: 12px 0 0;
}
.dry-run-tag { display: inline-block; font-size: 12px; background: #fef3c7; color: #78350f; padding: 1px 8px; border-radius: 6px; margin-top: 12px; }
.state-screen .btn-primary, .state-screen .btn-ghost { max-width: 420px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom)); z-index: 30;
  transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg);
  padding: 10px 18px; border-radius: 999px; font-size: 15px;
  opacity: 0; pointer-events: none; transition: .2s;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
