:root {
  color-scheme: light;
  --bg: #f6f5f2;
  --surface: #fcfcfb;
  --surface-2: #efeee9;
  --border: #e2e0d9;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7974;
  --accent: #c2410c;
  --accent-ink: #fff;
  --accent-soft: #fde7da;
  --series: #2a78d6;
  --good: #0f7b3e; --good-soft: #dcf3e4;
  --warn: #a15c00; --warn-soft: #fdf0d6;
  --bad: #b42318; --bad-soft: #fde4e1;
  --radius: 14px;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #242422; --border: #33332f;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e86;
    --accent: #f97316; --accent-ink: #1a0d03; --accent-soft: #3a2113;
    --series: #3987e5;
    --good: #4ade80; --good-soft: #10291a; --warn: #fbbf24; --warn-soft: #2e2410; --bad: #f87171; --bad-soft: #341616;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #242422; --border: #33332f;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e86;
  --accent: #f97316; --accent-ink: #1a0d03; --accent-soft: #3a2113;
  --series: #3987e5;
  --good: #4ade80; --good-soft: #10291a; --warn: #fbbf24; --warn-soft: #2e2410; --bad: #f87171; --bad-soft: #341616;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.45; }
a { color: var(--accent); }
h1 { font-size: 1.6rem; margin: .2rem 0 1rem; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; margin: 2rem 0 .6rem; }
h3 { font-size: .95rem; margin: 0 0 .6rem; color: var(--text-2); font-weight: 600; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .92em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.ok { color: var(--good); }
.warn { color: var(--warn); }

.top { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .8rem 16px;
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 800; text-decoration: none; color: var(--text); font-size: 1.1rem; display: flex; align-items: center; gap: .5rem; }
/* The logo's moon is two alpha masks painted with theme tokens, so it follows light/dark mode. */
.mark { position: relative; width: 1.75rem; aspect-ratio: 300 / 388; flex: none; }
.mark i { position: absolute; inset: 0; -webkit-mask: var(--m) center / contain no-repeat; mask: var(--m) center / contain no-repeat; }
.mark .red { --m: url(/img/mark-red.png); background: var(--accent); }
.mark .ink { --m: url(/img/mark-ink.png); background: var(--text); }
.top nav { display: flex; gap: 1rem; align-items: center; font-size: .95rem; }
.top nav a { text-decoration: none; }
main { max-width: 960px; margin: 0 auto; padding: 1.2rem 16px 9rem; }
main.wide { max-width: 1180px; }
.narrow { max-width: 420px; margin: 0 auto; }

button, .button { font: inherit; border-radius: 10px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); padding: .55rem 1rem; cursor: pointer; text-decoration: none; display: inline-block; }
button:hover, .button:hover { border-color: var(--text-2); }
.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 650; }
.primary:hover { filter: brightness(1.05); border-color: var(--accent); }
.secondary { width: 100%; padding: .8rem; margin-top: .6rem; }
.big { width: 100%; padding: .85rem; font-size: 1.05rem; }
button.small { padding: .25rem .6rem; font-size: .85rem; }
button.link { background: none; border: 0; color: var(--accent); padding: 0; }
button:disabled { opacity: .6; cursor: default; }
form.inline { display: inline; }
input { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .5rem .6rem; }
input:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.field { display: grid; gap: .3rem; font-size: .9rem; color: var(--text-2); }
.field input { width: 100%; }
.stack { display: grid; gap: .9rem; }
.row { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }

.flash { padding: .7rem 1rem; border-radius: 10px; margin-bottom: 1rem; background: var(--surface-2); }
.flash.success { background: var(--good-soft); color: var(--good); }
.flash.error { background: var(--bad-soft); color: var(--bad); }
.flash.info { background: var(--accent-soft); color: var(--text); }

/* Shop */
.grid { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.product { display: flex; flex-direction: column; overflow: hidden; transition: border-color .12s, box-shadow .12s; }
.product.picked { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.tap { all: unset; cursor: pointer; display: grid; gap: .15rem; padding: .9rem .9rem .6rem; text-align: left; flex: 1; }
.tap:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: var(--radius); }
.emoji { font-size: 2rem; line-height: 1.1; }
.name { font-weight: 600; }
.price { font-size: 1.15rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.stock { font-size: .78rem; color: var(--muted); }
.stock.low { color: var(--warn); }
.stepper { display: grid; grid-template-columns: 2.4rem 1fr 2.4rem; border-top: 1px solid var(--border); }
.stepper button { border: 0; border-radius: 0; background: var(--surface-2); font-size: 1.2rem; padding: .35rem 0; }
.stepper input { border: 0; border-radius: 0; text-align: center; width: 100%; -moz-appearance: textfield; font-variant-numeric: tabular-nums; }
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; }

.checkout { position: fixed; inset: auto 0 0 0; background: var(--surface); border-top: 1px solid var(--border);
  box-shadow: 0 -8px 30px rgb(0 0 0 / .12); z-index: 10; padding: .9rem 16px calc(.9rem + env(safe-area-inset-bottom)); }
.checkout-inner { max-width: 560px; margin: 0 auto; display: grid; gap: .7rem; }
.total-row { display: flex; justify-content: space-between; align-items: baseline; font-size: 1.1rem; }
.total-row strong { font-size: 1.4rem; font-variant-numeric: tabular-nums; }
.methods { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: .5rem; }
.methods label { flex: 1 1 140px; display: flex; gap: .45rem; align-items: center; padding: .55rem .7rem;
  border: 1px solid var(--border); border-radius: 10px; cursor: pointer; font-size: .95rem; }
.methods label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.methods label.disabled { opacity: .5; cursor: not-allowed; }
.methods small { color: var(--muted); margin-left: auto; }
.checkout p { margin: 0; }

/* Pay */
.qr-box[hidden] { display: none; }
.pay { max-width: 640px; margin: 0 auto; }
.qr-box { display: grid; grid-template-columns: minmax(0, 220px) 1fr; gap: 1.2rem; align-items: start;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.qr { background: #fff; padding: 8px; border-radius: 8px; }
.qr svg { display: block; width: 100%; height: auto; }
.qr-box p { margin-top: 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: .25rem .8rem; margin: 0 0 1rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; word-break: break-all; }
.pay-tabs { display: inline-flex; gap: 4px; padding: 4px; margin-bottom: .8rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: 999px; }
.pay-tabs button { border: 0; background: none; padding: .4rem 1rem; border-radius: 999px; font: inherit; color: var(--muted); cursor: pointer; }
.pay-tabs button[aria-selected="true"] { background: var(--accent); color: var(--accent-ink, #fff); font-weight: 600; }
@media (max-width: 540px) { .qr-box { grid-template-columns: 1fr; } .qr { max-width: 260px; margin: 0 auto; } }

/* Stats */
.tiles { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); margin-bottom: 1rem; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; display: grid; gap: .1rem; }
.tile-label { font-size: .82rem; color: var(--text-2); }
.tile strong { font-size: 1.5rem; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.tile-sub { font-size: .8rem; color: var(--muted); }
.settle { max-width: 360px; margin: 0 0 1rem; }
.two-col { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.chart { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin: 0 0 .75rem; }
.chart svg { width: 100%; height: 160px; display: block; overflow: visible; }
.chart .axis { stroke: var(--border); stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart .mark { fill: var(--series); }
.chart .hit { fill: transparent; }
.chart .bar:hover .mark { filter: brightness(1.15); }
.xlabels { display: flex; font-size: .72rem; color: var(--muted); margin-top: .3rem; }
.xlabels span { flex: none; text-align: center; overflow: hidden; white-space: nowrap; }
.chart details { margin-top: .5rem; color: var(--text-2); }
.chart details table { margin-top: .4rem; }
.favs { margin: 0; padding-left: 1.2rem; display: grid; gap: .35rem; }
.favs li span:last-child { float: right; }
#tip { position: fixed; left: 0; top: 0; pointer-events: none; background: var(--text); color: var(--bg);
  padding: .3rem .55rem; border-radius: 6px; font-size: .8rem; z-index: 50; white-space: nowrap; }

/* Tables */
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; }
th, td { padding: .5rem .7rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.inactive td { opacity: .45; }
.price-form input { width: 5.2rem; text-align: right; padding: .25rem .4rem; }
.actions { white-space: nowrap; }
.badge { display: inline-block; padding: .05rem .45rem; border-radius: 99px; font-size: .74rem; background: var(--surface-2); color: var(--text-2); vertical-align: middle; }
.badge-paid { background: var(--good-soft); color: var(--good); }
.badge-unpaid { background: var(--warn-soft); color: var(--warn); }
.badge-claimed { background: var(--accent-soft); color: var(--accent); }
.admin-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.admin-head h1 { margin: 0; }
.trip-lines input { padding: .35rem .45rem; }
.trip-lines td:first-child input { width: 100%; min-width: 12rem; }

/* Product photos */
.pic { width: 3rem; height: 3rem; object-fit: contain; border-radius: 8px; background: #fff; }
.emoji.pic { display: block; width: auto; height: auto; background: none; }
.pic-xs { width: 1.6rem; height: 1.6rem; object-fit: contain; border-radius: 4px; background: #fff; vertical-align: middle; }
.emoji.pic-xs { display: inline-block; background: none; font-size: 1.1rem; text-align: center; }
.pic-lg { width: 7rem; height: 7rem; object-fit: contain; border-radius: var(--radius); background: #fff; flex: none; }
.emoji.pic-lg { font-size: 4rem; display: grid; place-items: center; background: var(--surface-2); }
.product-cell { white-space: nowrap; }
.product-cell a { color: var(--text); text-decoration: none; }
.product-cell a:hover { color: var(--accent); text-decoration: underline; }
.product { position: relative; }
.info-btn { position: absolute; top: .5rem; right: .5rem; width: 1.6rem; height: 1.6rem; padding: 0; border-radius: 50%;
  font-size: .8rem; font-weight: 700; font-style: italic; font-family: Georgia, serif; z-index: 1; }
.shop-tools { display: flex; justify-content: flex-end; margin-bottom: .6rem; }

/* Product page */
.product-head { display: flex; gap: 1rem; align-items: center; margin-bottom: 1rem; }
.product-head h1 { margin: 0 0 .2rem; }
.pad { padding: 1rem; margin-bottom: .75rem; }
.codes { list-style: none; padding: 0; margin: 0 0 .8rem; display: grid; gap: .35rem; }
.code-add { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.code-add input[name=code] { flex: 1 1 10rem; }
select { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .5rem .6rem; flex: 1 1 14rem; }
.head-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.cancel-form { text-align: center; margin: .8rem 0; }
tr.scanned td { background: var(--accent-soft); }

/* Scanner and sheets */
dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 1rem;
  width: min(440px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); }
dialog::backdrop { background: rgb(0 0 0 / .55); }
.scanner { display: grid; gap: .7rem; }
.scanner:not([open]) { display: none; }
.scanner-head { display: flex; justify-content: space-between; align-items: center; }
.viewfinder { position: relative; border-radius: 10px; overflow: hidden; background: #000; aspect-ratio: 4 / 3; }
.viewfinder video { width: 100%; height: 100%; object-fit: cover; display: block; }
.aim { position: absolute; inset: 30% 10%; border: 2px solid rgb(255 255 255 / .85); border-radius: 8px; box-shadow: 0 0 0 999px rgb(0 0 0 / .25); }
.scanner-status { margin: 0; }
.scanner-manual { display: flex; gap: .5rem; }
.scanner-manual input { flex: 1; min-width: 0; }
.scanner-log { list-style: none; margin: 0; padding: 0; display: grid; gap: .3rem; max-height: 8.5rem; overflow-y: auto; font-size: .9rem; }
.scanner-log li { padding: .35rem .6rem; border-radius: 8px; }
.scanner-log .good { background: var(--good-soft); color: var(--good); }
.scanner-log .bad { background: var(--bad-soft); color: var(--bad); }
.sheet h2 { margin: .3rem 0 .2rem; }
.sheet-img { display: block; width: 9rem; height: 9rem; object-fit: contain; margin: 0 auto; background: #fff; border-radius: 10px; }
.top nav a.lang { font-size: .78rem; font-weight: 700; letter-spacing: .04em; padding: .15rem .45rem; border: 1px solid var(--border); border-radius: 6px; color: var(--text-2); }
.top nav a.lang:hover { border-color: var(--accent); color: var(--accent); }
#clear-basket { margin-left: .5rem; font-size: .85rem; }

.price .deposit { white-space: nowrap; font-weight: 400; font-size: .7em; color: var(--muted); }
.matches { list-style: none; padding: 0; margin: .8rem 0 0; display: grid; gap: .5rem; }
.matches li { display: grid; grid-template-columns: 2.5rem 1fr auto; gap: .6rem; align-items: center; }
.matches .pic-sm { width: 2.5rem; height: 2.5rem; object-fit: contain; border-radius: 6px; background: #fff; }
.matches .match-text { min-width: 0; overflow-wrap: anywhere; }
.match-row h3 { margin-top: 0; }

/* Flavours */
.picked-list { padding: 0 .9rem .5rem; font-size: .8rem; color: var(--accent); min-height: 0; }
.picked-list:empty { display: none; }
.pick-flavour { border: 0; border-top: 1px solid var(--border); border-radius: 0; background: var(--surface-2); padding: .5rem; font-size: .9rem; }
.flavour-rows { display: grid; gap: .6rem; margin: .8rem 0 1rem; }
.flavour-row { display: grid; grid-template-columns: 1fr 8.5rem; gap: .8rem; align-items: center; }
.flavour-row .stepper { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.flavour-row output { display: grid; place-items: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.flavour-rows + .big { width: 100%; }
.name-cell input { display: block; width: 100%; }
.name-cell input.flavour { margin-top: .25rem; font-size: .85rem; padding: .25rem .5rem; }
.sort-stock { margin: 1rem 0; padding: .8rem; border: 1px dashed var(--accent); border-radius: var(--radius); }
.sort-stock p { margin-top: 0; }
.merge summary { cursor: pointer; font-weight: 600; }
.merge[open] summary { margin-bottom: .5rem; }
button.copy { all: unset; cursor: pointer; font: inherit; font-weight: 600; border-bottom: 1px dashed var(--muted); }
button.copy:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sheet .pay-tabs { display: flex; flex-wrap: wrap; border-radius: 1rem; }
