:root {
  --bg: #F4EEE3;
  --surface: #FBF8F2;
  --ink: #1F1C19;
  --ink2: #6B645B;
  --ink3: #9C948A;
  --line: #E4DBCC;
  --accent: #C2412D;
  --accent-ink: #FFFFFF;
  --accent-soft: rgba(194, 65, 45, .10);
  --ok: #3F7D58;
  --warn: #A8641A;
  --warn-soft: rgba(168, 100, 26, .12);
  --shadow: 0 8px 28px rgba(31, 28, 25, .12);
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1A1816;
    --surface: #24211E;
    --ink: #F1EBE0;
    --ink2: #B0A796;
    --ink3: #7D7569;
    --line: #38332D;
    --accent: #C9A35C;
    --accent-ink: #1A1816;
    --accent-soft: rgba(201, 163, 92, .14);
    --ok: #74B48D;
    --warn: #E0B04F;
    --warn-soft: rgba(224, 176, 79, .14);
    --shadow: 0 8px 28px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body {
  font-family: -apple-system, "PingFang TC", "Hiragino Sans", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  font-size: 16px; line-height: 1.5;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
img { display: block; }
[hidden] { display: none !important; }

#app { position: fixed; inset: 0; overflow: hidden; }
.view { position: absolute; inset: 0; display: flex; flex-direction: column; background: var(--bg); }

/* ---------- common ---------- */
.header {
  display: flex; align-items: center; gap: 8px;
  padding: calc(var(--safe-top) + 10px) 16px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.header h1 { flex: 1; margin: 0; font-size: 18px; font-weight: 600; letter-spacing: .02em; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.icon-btn svg { width: 22px; height: 22px; }
.text-btn { color: var(--accent); font-size: 15px; padding: 8px 6px; }
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.footer {
  padding: 12px 16px calc(var(--safe-bottom) + 12px);
  border-top: 1px solid var(--line);
  background: var(--bg);
}
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 52px; border-radius: 14px;
  font-size: 17px; font-weight: 600;
  background: var(--accent); color: var(--accent-ink);
}
.btn:active { opacity: .85; }
.btn.secondary { background: transparent; color: var(--ink); border: 1px solid var(--line); font-weight: 500; }
.btn.small { min-height: 40px; font-size: 15px; border-radius: 12px; width: auto; padding: 0 16px; }
.btn-row { display: flex; gap: 10px; }
.btn-row > * { flex: 1; }
.muted { color: var(--ink2); }
.tiny { font-size: 13px; color: var(--ink3); }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface);
  font-size: 14px; white-space: nowrap;
}
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.warn-box {
  display: flex; gap: 8px; align-items: flex-start;
  background: var(--warn-soft); color: var(--warn);
  padding: 10px 12px; border-radius: 12px; font-size: 14px;
}
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 999px; }
.stepper button { width: 38px; height: 36px; font-size: 20px; color: var(--ink2); }
.stepper span { min-width: 26px; text-align: center; font-weight: 600; }
.empty { text-align: center; padding: 64px 24px; color: var(--ink2); }
.empty svg { width: 48px; height: 48px; opacity: .4; margin-bottom: 12px; }
.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2.5px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- scan ---------- */
.scan-top {
  position: relative; flex: 0 0 56%;
  background: #000; overflow: hidden; touch-action: none;
}
.scan-top video, .scan-top #freeze { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scan-top #stillImg { position: absolute; left: 0; top: 0; transform-origin: 0 0; max-width: none; user-select: none; -webkit-user-drag: none; }
.aim {
  position: absolute; left: 50%; top: 52%;
  transform: translate(-50%, -50%);
  border: 2.5px solid #C2412D; border-radius: 12px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .38);
  transition: width .25s, height .25s, border-color .2s;
  pointer-events: none;
}
.aim.h { width: 86%; height: 16%; }
.aim.v { width: 22%; height: 74%; }
.aim .progress {
  position: absolute; left: 0; bottom: -2px; height: 3px; background: #fff;
  width: calc(var(--p, 0) * 100%); border-radius: 2px; transition: width .12s linear;
}
.aim.busy { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { border-color: #fff; } }
.aim.done { border-color: transparent; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .15); }
.hit {
  position: absolute; border: 3px solid #4CC27A; border-radius: 8px;
  box-shadow: 0 0 0 3px rgba(76, 194, 122, .25);
  pointer-events: none;
}
.scan-bar {
  position: absolute; left: 0; right: 0; top: 0;
  display: flex; align-items: center; gap: 8px;
  padding: calc(var(--safe-top) + 8px) 12px 8px;
  background: linear-gradient(rgba(0,0,0,.45), transparent);
  color: #fff;
}
.scan-bar .icon-btn { background: rgba(0,0,0,.32); color: #fff; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.scan-bar .spacer { flex: 1; }
.glass-chip {
  height: 36px; padding: 0 12px; border-radius: 999px;
  background: rgba(0,0,0,.32); color: #fff; font-size: 14px;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  display: inline-flex; align-items: center; gap: 6px;
}
.badge-wrap { position: relative; }
.badge {
  position: absolute; top: -2px; right: -2px;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: #C2412D; color: #fff; font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.scan-hint {
  position: absolute; left: 0; right: 0; bottom: 12px; text-align: center;
  color: rgba(255,255,255,.9); font-size: 14px; text-shadow: 0 1px 4px rgba(0,0,0,.6);
  pointer-events: none;
}
.scan-tools { position: absolute; right: 12px; bottom: 10px; display: flex; gap: 8px; }
.scan-tools .icon-btn { background: rgba(0,0,0,.4); color: #fff; }
.cam-error {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 24px; text-align: center; color: #eee; font-size: 15px;
}

.scan-bottom {
  flex: 1; overflow-y: auto; padding: 16px 20px calc(var(--safe-bottom) + 16px);
  display: flex; flex-direction: column;
}
.result-orig { font-size: 15px; color: var(--ink2); }
.result-orig .pron { font-size: 13px; color: var(--ink3); margin-left: 6px; }
.result-tr { font-size: 26px; font-weight: 700; line-height: 1.25; margin: 2px 0 6px; letter-spacing: .01em; }
.result-price { font-size: 17px; font-weight: 600; }
.result-sizes { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 15px; }
.result-desc { margin: 8px 0 12px; color: var(--ink2); font-size: 15px; }
.result-actions { margin-top: auto; display: flex; gap: 10px; padding-top: 8px; }
.result-actions .btn.secondary { flex: 0 0 34%; }
.placeholder { margin: auto; text-align: center; color: var(--ink3); font-size: 15px; }
.placeholder .big { font-size: 34px; margin-bottom: 4px; opacity: .7; }

/* ---------- bottom sheet / modal ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  background: var(--surface); border-radius: 22px 22px 0 0;
  padding: 10px 20px calc(var(--safe-bottom) + 18px);
  box-shadow: var(--shadow); animation: up .25s ease-out;
  max-height: 88dvh; overflow-y: auto;
}
.sheet::before { content: ""; display: block; width: 36px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 14px; }
@keyframes up { from { transform: translateY(100%); } }
.sheet h3 { margin: 0 0 2px; font-size: 20px; }
.sheet .sec { margin-top: 18px; }
.sheet .sec-label { font-size: 13px; color: var(--ink2); margin-bottom: 8px; }
.check { color: var(--ok); font-weight: 600; font-size: 14px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 90px); transform: translateX(-50%);
  z-index: 40; background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 12px; font-size: 14px;
  display: flex; gap: 14px; align-items: center; max-width: 90vw;
  box-shadow: var(--shadow); animation: fade .2s;
}
.toast button { color: var(--accent); font-weight: 600; }
@media (prefers-color-scheme: dark) { .toast button { color: #8a6a2c; } }

/* ---------- cart ---------- */
.cart-actions { display: flex; gap: 8px; padding: 12px 16px 4px; }
.cart-actions .chip { padding: 8px 14px; font-size: 14px; }
.cat-title { padding: 18px 20px 6px; font-size: 13px; color: var(--ink2); letter-spacing: .08em; }
.item {
  display: flex; gap: 12px; padding: 12px 16px; margin: 0 12px 8px;
  background: var(--surface); border-radius: var(--radius);
  user-select: none; -webkit-user-select: none;
}
.item .thumb { width: 52px; height: 52px; border-radius: 10px; object-fit: cover; background: var(--line); flex-shrink: 0; }
.item .main { flex: 1; min-width: 0; }
.item .tr { font-weight: 600; font-size: 16px; }
.item .orig { font-size: 14px; color: var(--ink2); }
.item .row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.item .price { margin-left: auto; font-weight: 600; }
.item .sizes { margin-top: 8px; }
.item .sizes .chip { padding: 4px 10px; font-size: 13px; }
.item .tools { display: flex; gap: 4px; margin-top: 6px; }
.item .tools button { font-size: 13px; color: var(--ink2); padding: 4px 8px; border-radius: 8px; }
.item .tools button.on { color: var(--accent); }
.pending-tag { font-size: 11px; color: var(--warn); background: var(--warn-soft); padding: 2px 6px; border-radius: 6px; margin-left: 6px; vertical-align: 2px; }
.note-panel { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); }
.note-panel textarea {
  width: 100%; min-height: 44px; margin-top: 10px; padding: 10px 12px; resize: none;
  border: 1px solid var(--line); border-radius: 12px; background: var(--bg); font-size: 16px;
}
.note-out { margin-top: 8px; font-size: 15px; }
.note-out .lbl { font-size: 12px; color: var(--ink3); }
.note-mini { font-size: 13px; color: var(--accent); margin-top: 4px; }
.total-line { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.total-line b { font-size: 22px; }

/* ---------- waiter cards ---------- */
#v-cards { background: var(--surface); }
.cards-bar { display: flex; align-items: center; gap: 8px; padding: calc(var(--safe-top) + 8px) 12px 4px; }
.cards-bar .spacer { flex: 1; }
.cards {
  flex: 1; display: flex; overflow-x: auto; scroll-snap-type: x mandatory;
  scrollbar-width: none;
}
.cards::-webkit-scrollbar { display: none; }
.card {
  flex: 0 0 100%; scroll-snap-align: center;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 16px 28px 24px; text-align: center; gap: 14px; overflow-y: auto;
}
.card .crop { max-width: 100%; max-height: 26dvh; border-radius: 12px; box-shadow: var(--shadow); }
.card .big { font-size: clamp(32px, 10vw, 46px); font-weight: 700; line-height: 1.2; }
.card .size { font-size: 26px; font-weight: 600; color: var(--accent); }
.card .qty { font-size: 44px; font-weight: 700; }
.card .note { font-size: 22px; background: var(--accent-soft); padding: 10px 16px; border-radius: 12px; }
.card .mine { font-size: 14px; color: var(--ink3); margin-top: 6px; }
.card .idx { font-size: 14px; color: var(--ink3); }
.card .allergy { font-size: 22px; color: var(--warn); background: var(--warn-soft); padding: 12px 16px; border-radius: 14px; }
.cards-dots { display: flex; justify-content: center; gap: 6px; padding: 6px 0 calc(var(--safe-bottom) + 14px); }
.cards-dots i { width: 6px; height: 6px; border-radius: 3px; background: var(--line); transition: width .2s; }
.cards-dots i.on { width: 18px; background: var(--accent); }
.list-mode { flex: 1; overflow-y: auto; padding: 8px 20px calc(var(--safe-bottom) + 20px); }
.list-mode .lrow { display: flex; gap: 12px; align-items: center; padding: 14px 0; border-bottom: 1px solid var(--line); }
.list-mode .lrow img { width: 72px; height: 48px; object-fit: cover; border-radius: 8px; }
.list-mode .lname { flex: 1; font-size: 22px; font-weight: 700; }
.list-mode .lname small { display: block; font-size: 16px; font-weight: 500; color: var(--ink2); }
.list-mode .lqty { font-size: 26px; font-weight: 700; }
.fullcard {
  position: fixed; inset: 0; z-index: 30; background: var(--surface);
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  padding: 24px; gap: 18px; animation: fade .2s;
}
.fullcard .big { font-size: clamp(36px, 11vw, 56px); font-weight: 700; line-height: 1.25; }

/* ---------- receipt ---------- */
.receipt-img { width: 100%; max-height: 30dvh; object-fit: contain; border-radius: 12px; background: var(--surface); }
.rline { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); align-items: flex-start; }
.rline .st { width: 22px; flex-shrink: 0; text-align: center; }
.rline .nm { flex: 1; }
.rline .nm small { display: block; color: var(--ink2); font-size: 13px; }
.rline .amt { font-weight: 600; white-space: nowrap; }
.rline .why { font-size: 13px; color: var(--warn); }
.summary-box { background: var(--surface); padding: 14px 16px; border-radius: var(--radius); margin: 12px 0; }
.fees { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 15px; }
.fees dt { color: var(--ink2); }
.fees dd { margin: 0; text-align: right; font-weight: 600; }

/* ---------- history / settings ---------- */
.list-row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 14px 16px; margin: 0 12px 8px; width: calc(100% - 24px);
  background: var(--surface); border-radius: var(--radius);
}
.list-row .meta { flex: 1; min-width: 0; }
.list-row .t { font-weight: 600; }
.list-row .s { font-size: 13px; color: var(--ink2); }
.pad { padding: 16px; }
.field { margin-bottom: 22px; }
.field label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.field .help { font-size: 13px; color: var(--ink2); margin-top: 6px; }
.input, select.input, textarea.input {
  width: 100%; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); font-size: 16px;
}
.input-row { display: flex; gap: 8px; }
.input-row .input { flex: 1; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.switch input { width: 46px; height: 28px; accent-color: var(--accent); }
.onboard { background: var(--accent-soft); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 22px; font-size: 15px; }
.onboard ol { margin: 8px 0 0; padding-left: 20px; }
.onboard a { color: var(--accent); }
.section-title { font-size: 13px; color: var(--ink2); letter-spacing: .08em; margin: 28px 0 10px; }
