:root {
  --bg: #f1f5fe;
  --surface: #ffffff;
  --surface-2: #e9effc;
  --text: #14203a;
  --muted: #56657c;
  --line: #d3def3;
  --accent: #0050e6;
  --accent-text: #ffffff;
  --accent-soft: #e6efff;
  --accent-line: #a9c6fc;
  --hero: #0050e6;
  --hero-soft: rgba(255,255,255,.14);
  --honey: #9a6a10;
  --honey-soft: #fbf1dc;
  --honey-line: #e8c987;
  --danger: #b3403a;
  --shadow: 0 1px 2px rgba(20, 30, 40, .06), 0 2px 8px rgba(20, 30, 40, .05);
  --radius: 14px;
  --tab-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c1322;
    --surface: #141d33;
    --surface-2: #1c2843;
    --text: #e6ecf8;
    --muted: #96a3bd;
    --line: #2a3a5e;
    --accent: #5c94ff;
    --accent-text: #061433;
    --accent-soft: #13264d;
    --accent-line: #28498f;
  --hero: #0b46c9;
  --hero-soft: rgba(255,255,255,.12);
    --honey: #e4b65c;
    --honey-soft: #33291a;
    --honey-line: #6b5427;
    --danger: #e0807a;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0c1322;
  --surface: #141d33;
  --surface-2: #1c2843;
  --text: #e6ecf8;
  --muted: #96a3bd;
  --line: #2a3a5e;
  --accent: #5c94ff;
  --accent-text: #061433;
  --accent-soft: #13264d;
  --accent-line: #28498f;
  --hero: #0b46c9;
  --hero-soft: rgba(255,255,255,.12);
  --honey: #e4b65c;
  --honey-soft: #33291a;
  --honey-line: #6b5427;
  --danger: #e0807a;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom));
  min-height: 100vh;
}
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* Top bar */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) max(16px, calc((100% - 640px) / 2 + 16px)) 10px;
  background: var(--bg);
}
.top h1 { flex: 1; margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 12px;
  border: 1px solid transparent; background: transparent; color: var(--muted);
}
.icon-btn:active { background: var(--surface-2); }
.back { margin-left: -8px; color: var(--text); }

main { padding: 0 16px 24px; max-width: 640px; margin: 0 auto; }

/* Bottom tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; justify-content: space-around;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 600;
}
.tabs a.on { color: var(--accent); }
.tabs a.on svg { stroke-width: 2.2; }

/* Search */
.search {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0 6px 0 12px; box-shadow: var(--shadow);
}
.search:focus-within { border-color: var(--accent); }
.search > svg { color: var(--muted); }
.search input::-webkit-search-cancel-button { display: none; }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; padding: 13px 0; font-size: 17px; }
.search .icon-btn { color: var(--muted); }

.actions { display: flex; gap: 8px; margin: 12px 0 4px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font-size: 14px; font-weight: 600; white-space: nowrap; text-decoration: none;
}
.chip svg { width: 18px; height: 18px; color: var(--accent); }

.section-title { margin: 18px 4px 8px; font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* Lists */
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 12px 14px; border: 0; border-top: 1px solid var(--line);
  background: transparent; text-align: left;
}
.row:first-child { border-top: 0; }
.row:active { background: var(--surface-2); }
.row .main { flex: 1; min-width: 0; }
.row .name { font-weight: 600; line-height: 1.3; }
.row .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.row .sub.serve { color: var(--accent); font-weight: 600; }
.row .val { text-align: right; font-weight: 700; white-space: nowrap; }
.row .val small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; }
.row .x { color: var(--muted); }
.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent-line); margin-right: 4px; vertical-align: 1px; }

.empty { text-align: center; color: var(--muted); padding: 28px 16px; }
.empty b { display: block; color: var(--text); margin-bottom: 4px; }

/* Totals */
.total {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
}
.total .big { font-size: 44px; font-weight: 800; letter-spacing: -.02em; line-height: 1.05; }
.total .big small { font-size: 18px; font-weight: 600; color: var(--muted); margin-left: 4px; }
.total .line { display: flex; gap: 16px; margin-top: 6px; color: var(--muted); font-size: 15px; }
.total .line b { color: var(--text); }
.units {
  display: flex; align-items: center; gap: 12px; margin-top: 14px;
  padding: 12px 14px; border-radius: 12px;
  background: var(--accent-soft); border: 1px solid var(--accent-line);
}
.units .u { font-size: 26px; font-weight: 800; }
.units .why { color: var(--muted); font-size: 13px; line-height: 1.3; }
.units select { margin-left: auto; padding: 6px 8px; border-radius: 10px; border: 1px solid var(--accent-line); background: var(--surface); font-size: 14px; }
.note {
  margin-top: 14px; padding: 12px 14px; border-radius: 12px; font-size: 14px;
  background: var(--honey-soft); border: 1px solid var(--honey-line); color: var(--text);
}
.note b { color: var(--honey); }
.hint { color: var(--muted); font-size: 13px; margin: 10px 4px 0; }

.btns { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.btn {
  flex: 1; min-width: 0; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 13px 14px; border-radius: 12px; font-weight: 700; font-size: 15px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); text-decoration: none;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); }
.btn svg { width: 18px; height: 18px; }
.btn:disabled { opacity: .5; }

/* Segmented */
.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; margin-bottom: 12px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 8px 6px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* Forms */
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 2px 5px; }
.input, .field input, .field select {
  width: 100%; padding: 11px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); font-size: 16px;
}
.input:focus, .field input:focus, .field select:focus { outline: 0; border-color: var(--accent); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.toggle { display: flex; align-items: center; gap: 12px; padding: 12px 14px; }
.toggle .main { flex: 1; }
.switch { position: relative; width: 48px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch i { position: absolute; inset: 0; border-radius: 999px; background: var(--line); transition: .15s; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(20px); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.card + .card { margin-top: 12px; }
.card p { margin: 0 0 8px; }
.card p:last-child { margin-bottom: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Sheet */
.sheet { position: fixed; inset: 0; z-index: 20; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(10, 14, 18, .45); }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-height: 92vh; overflow: auto;
  background: var(--bg); border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(18px + env(safe-area-inset-bottom));
  max-width: 640px; margin: 0 auto;
  animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: .6; } }
.sheet-head { display: flex; align-items: flex-start; gap: 8px; padding: 8px 0 10px; }
.sheet-head h2 { flex: 1; margin: 4px 0 0; font-size: 19px; line-height: 1.3; }
.sheet-head .sub { color: var(--muted); font-size: 13px; margin-top: 3px; font-weight: 400; }
.per100 { display: flex; gap: 8px; margin-bottom: 14px; }
.per100 div { flex: 1; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; }
.per100 b { display: block; font-size: 17px; }
.per100 span { font-size: 12px; color: var(--muted); }
.amount { display: flex; gap: 8px; align-items: stretch; margin-bottom: 12px; }
.stepper { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.stepper button { width: 44px; height: 46px; border: 0; background: transparent; color: var(--accent); }
.stepper input { width: 64px; border: 0; background: transparent; text-align: center; font-size: 18px; font-weight: 700; outline: 0; padding: 0; }
.amount select { flex: 1; min-width: 0; padding: 0 8px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-size: 15px; }
.result { display: flex; align-items: baseline; gap: 14px; padding: 14px; border-radius: 12px; background: var(--accent-soft); border: 1px solid var(--accent-line); }
.result .big { font-size: 32px; font-weight: 800; }
.result .big small { font-size: 15px; font-weight: 600; color: var(--muted); margin-left: 3px; }
.result .rest { color: var(--muted); font-size: 14px; }
.result .rest b { color: var(--text); }

/* Scanner */
.scanner { position: relative; border-radius: var(--radius); overflow: hidden; background: #000; aspect-ratio: 4 / 3; }
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanner .frame { position: absolute; left: 12%; right: 12%; top: 32%; bottom: 32%; border: 2px solid rgba(255,255,255,.85); border-radius: 12px; box-shadow: 0 0 0 999px rgba(0,0,0,.25); }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + 16px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 30; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px;
  max-width: calc(100% - 32px); pointer-events: none; text-align: center;
}
.spin { display: inline-block; width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: r .7s linear infinite; vertical-align: -4px; }
@keyframes r { to { transform: rotate(360deg); } }

/* ---- Blue as the main colour ---- */
.top { background: var(--hero); color: #fff; margin-bottom: 14px; }
.top h1 { color: #fff; }
.top .icon-btn, .top .back { color: #fff; }
.top .icon-btn:active { background: var(--hero-soft); }
.section-title { color: var(--accent); }
.chip { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
.row .val { color: var(--accent); }
.row .val small { color: var(--muted); }
.per100 b { color: var(--accent); }
.seg button.on { background: var(--accent); color: var(--accent-text); }
.tabs a.on { background: var(--accent-soft); border-radius: 14px; margin: 6px 4px; }
.total { background: var(--hero); border-color: var(--hero); color: #fff; }
.total .big small, .total .line { color: rgba(255,255,255,.82); }
.total .line b { color: #fff; }
.total .units { background: var(--hero-soft); border-color: rgba(255,255,255,.3); }
.total .units .why { color: rgba(255,255,255,.82); }
.total .units select { background: #fff; color: #0b1b3f; border-color: transparent; }
.total .note { color: var(--text); }
.result { background: var(--hero); border-color: var(--hero); color: #fff; }
.result .big small, .result .rest { color: rgba(255,255,255,.82); }
.result .rest b { color: #fff; }
.btn.primary, .seg button.on { background: var(--hero); border-color: var(--hero); color: #fff; }

/* ---- Food panel spacing ---- */
.sheet-head { padding: 10px 0 12px; align-items: flex-start; }
.sheet-head h2 { margin: 6px 0 0; font-size: 20px; line-height: 1.25; }
.sheet-head .sub { margin-top: 4px; line-height: 1.35; }
.per100 { gap: 8px; margin-bottom: 14px; }
.per100 div { padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.per100 b { font-size: 18px; line-height: 1.2; }
.per100 span { line-height: 1.2; }
.per-note { margin: 0 2px 6px; font-size: 12px; color: var(--muted); }
.amount { margin-bottom: 14px; }
.amount select { padding: 0 12px; text-overflow: ellipsis; }
.result { display: block; padding: 14px 16px; }
.result .big { line-height: 1.1; }
.result .rest { margin-top: 4px; }
.sheet .btns { margin-top: 14px; }
.sheet .hint { margin: 12px 2px 0; }

/* ---- App frame (same as Magic Herd): top bar and tabs stay still, only the middle scrolls, and only if it needs to ---- */
html { height: 100%; overflow: hidden; -webkit-text-size-adjust: 100%; }
body {
  position: fixed; inset: 0; width: 100%; height: 100%;
  display: flex; flex-direction: column; overflow: hidden; overscroll-behavior: none;
  padding-bottom: 0; min-height: 0;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
input, textarea, select, .selectable { -webkit-user-select: text; user-select: text; -webkit-touch-callout: default; }
img { -webkit-user-drag: none; }
button, a, label, select, input, summary { touch-action: manipulation; }
.top { position: relative; flex: none; margin-bottom: 0; z-index: 5; }
main#view {
  flex: 1; min-height: 0; width: 100%; max-width: none; margin: 0;
  overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  padding: 14px max(16px, calc((100% - 640px) / 2 + 16px)) 20px;
  will-change: transform;
}
.tabs { position: relative; flex: none; height: auto; padding: 6px 4px calc(env(safe-area-inset-bottom) + 6px); }
/* Tabs never move: the highlight is a pill behind the icon; size, weight and spacing stay the same */
.tabs a, .tabs a.on { margin: 0; background: none; border-radius: 0; gap: 2px; padding: 2px 0; font-weight: 600; }
.tabs a .ti { display: grid; place-items: center; width: 56px; height: 30px; border-radius: 15px; transition: background-color .2s ease, color .2s ease; }
.tabs a svg, .tabs a.on svg { width: 24px; height: 24px; stroke-width: 1.9; }
.tabs a.on .ti { background: var(--accent-soft); }
.tabs a .tl { font-size: 12px; line-height: 1.2; white-space: nowrap; }
.toast { bottom: calc(76px + env(safe-area-inset-bottom)); }

/* Sheets slide up, and slide away when closed */
.sheet-backdrop { animation: fade .18s ease-out; }
.sheet.closing { pointer-events: none; }
.sheet.closing .sheet-backdrop { opacity: 0; transition: opacity .18s ease; }
.sheet.closing .sheet-panel { transform: translateY(100%); transition: transform .2s ease-in; }
@keyframes fade { from { opacity: 0; } }
.sheet-panel { overscroll-behavior: contain; }
@media (prefers-reduced-motion: reduce) { .sheet-panel, .sheet-backdrop { animation: none; } }

/* ---- Sign-in screens ---- */
html.gated .top, html.gated #view, html.gated .tabs { display: none; }
#gate {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; display: flex;
  padding: calc(env(safe-area-inset-top) + 24px) 16px calc(env(safe-area-inset-bottom) + 24px);
  background: var(--hero);
}
.gate-card {
  width: 100%; max-width: 420px; margin: auto; background: var(--bg); color: var(--text);
  border-radius: 20px; padding: 22px 18px 18px; box-shadow: 0 10px 30px rgba(0, 20, 70, .25);
}
.gate-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.gate-brand img { border-radius: 14px; flex: none; }
.gate-brand b { display: block; font-size: 18px; }
.gate-brand span { color: var(--muted); font-size: 13px; }
.gate-card h1 { font-size: 22px; margin: 0 0 12px; }
.gate-card > p { margin: 0 0 12px; }
.gate-steps { margin: 0 0 14px; padding-left: 20px; color: var(--muted); font-size: 14px; }
.gate-steps li + li { margin-top: 4px; }
.gate-qr { display: block; width: 200px; height: 200px; margin: 4px auto 12px; background: #fff; padding: 8px; border-radius: 12px; }
.gate-key { word-break: break-all; }
.gate-form .btn, .gate-card > .btn { margin-top: 8px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); margin: -2px 2px 10px; }
.field small { display: block; color: var(--muted); font-size: 12px; margin: 4px 2px 0; }
.form-error { color: var(--danger); font-size: 14px; margin: 4px 2px 8px; }
.btn.block { display: flex; width: 100%; flex: none; }
.btn.link { background: none; border-color: transparent; color: var(--accent); font-weight: 600; }
.btn.busy { opacity: .7; }
.code-input { letter-spacing: .35em; font-size: 22px !important; text-align: center; font-variant-numeric: tabular-nums; }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- Customise (coffees) ---- */
.custom { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin-bottom: 14px; }
.cu-title { margin: 0 0 10px; }
.cu-row { display: flex; align-items: center; gap: 12px; }
.cu-row + .cu-row { margin-top: 10px; }
.cu-row > span { flex: none; width: 84px; font-weight: 600; font-size: 14px; }
.cu-row select { flex: 1; min-width: 0; padding: 9px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-size: 15px; }
.cu-seg { flex: 1; margin: 0; }
.cu-seg button { padding: 7px 2px; font-size: 13px; }
.stepper.small { margin-left: auto; }
.stepper.small button { width: 40px; height: 38px; }
.stepper.small b { min-width: 28px; text-align: center; font-size: 17px; }
.cu-lines { margin-top: 6px; font-size: 13px; line-height: 1.35; }
