/* Shopee VIP counter app. One bold thing: the code is a yellow voucher stub
   that gets a rubber stamp (ใช้ได้ / ใช้แล้ว). Everything around it stays quiet
   so staff read the stamp first during a rush. */

:root {
  color-scheme: light;
  --brand: #2c86e6;        /* Bara Blue */
  --brand-deep: #1d6cc2;
  --brand-soft: #e3effd;
  --ink: #0f2742;
  --ink-2: #4a6280;
  --ink-3: #7d93ad;
  --bg: #f4f8fe;
  --paper: #ffffff;
  --line: #dde8f6;
  --line-strong: #c4d7ee;
  --sticker: #f6df72;
  --sticker-ink: #2b2510;
  --ok: #127a4a;
  --ok-soft: #e2f3e8;
  --bad: #c8382e;
  --bad-soft: #fde9e7;
  --display: "Fraunces", "IBM Plex Sans Thai", Georgia, serif;
  --sans: "IBM Plex Sans Thai", -apple-system, "Segoe UI", system-ui, sans-serif;
  --r-lg: 22px;
  --r: 14px;
}
:root[data-brand="haab"] {
  --brand: #ca232b;
  --brand-deep: #a11b22;
  --brand-soft: #fbe3e3;
  --ink: #2a1416;
  --ink-2: #6b4a4c;
  --ink-3: #9b7d7f;
  --bg: #fff8f7;
  --line: #f1dedd;
  --line-strong: #e4c5c3;
  --sticker: #fff1da;
  --sticker-ink: #5a1a1d;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }

/* ── header band ─────────────────────────────────────────────────────── */
.band {
  display: flex;
  align-items: center;
  gap: 12px;
  /* lines the logo up with the 520px column below on tablets and laptops */
  padding: calc(env(safe-area-inset-top) + 14px) max(16px, calc(50% - 244px)) 16px;
  background: var(--brand);
  color: #fff;
}
.mascot {
  width: 48px;
  height: 48px;
  flex: none;
  border-radius: 14px;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, .35);
}
.band-text { min-width: 0; }
.band-title {
  margin: 0;
  font-family: var(--display);
  font-weight: 800;
  font-size: 20px;
  line-height: 1.2;
}
.branch-chip {
  margin-top: 4px;
  padding: 2px 12px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, .2);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
}
.branch-chip small { font-weight: 400; opacity: .85; margin-left: 6px; text-decoration: underline; }

main {
  max-width: 520px;
  margin: 0 auto;
  padding: 16px 16px calc(36px + env(safe-area-inset-bottom));
}

/* ── setup ───────────────────────────────────────────────────────────── */
.setup h1 { margin: 8px 0 0; font-size: 26px; line-height: 1.25; }
.lede { margin: 2px 0 20px; color: var(--ink-2); }
.field { display: block; margin: 0 0 18px; padding: 0; border: 0; }
.field > span, .field > legend { display: block; margin-bottom: 6px; padding: 0; font-weight: 600; }
.field input {
  width: 100%;
  padding: 13px 16px;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--r);
  background: var(--paper);
  font-size: 20px;
}
.field input:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px var(--brand-soft); }
.pin-input { font-family: var(--display); letter-spacing: .3em; }
.branch-options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.branch-options label {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 64px;
  padding: 8px 12px;
  border: 2px solid var(--line-strong);
  border-radius: var(--r);
  background: var(--paper);
  font-weight: 600;
  text-align: center;
  line-height: 1.3;
}
.branch-options input { position: absolute; top: 0; left: 0; width: 1px; height: 1px; margin: 0; opacity: 0; pointer-events: none; }
.branch-options label:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-deep); }
.branch-options label:has(input:focus-visible) { outline: 3px solid var(--brand); outline-offset: 2px; }
.form-error { min-height: 1.5em; margin: 0 0 10px; color: var(--bad); font-weight: 600; }

/* ── buttons ─────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 56px;
  padding: 10px 18px;
  border: 0;
  border-radius: 16px;
  font-size: 18px;
  font-weight: 700;
}
.btn.primary { background: var(--brand); color: #fff; box-shadow: 0 10px 22px -14px var(--brand-deep); }
.btn.primary:active { background: var(--brand-deep); }
.btn.big { min-height: 66px; font-size: 21px; border-radius: 18px; }
.btn:disabled { background: #c9d6e8; color: #fff; box-shadow: none; cursor: not-allowed; }
.btn .n { background: #fff; color: var(--brand); }
.btn:disabled .n { color: #9fb2cc; }
.link { padding: 4px 0; border: 0; background: none; color: var(--ink-2); text-decoration: underline; font-size: 14px; }

/* ── practice + tally ────────────────────────────────────────────────── */
.practice {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 10px;
  margin-bottom: 12px;
  padding: 10px 14px;
  border-radius: var(--r);
  background: repeating-linear-gradient(-45deg, rgba(43, 37, 16, .06) 0 8px, transparent 8px 16px), var(--sticker);
  color: var(--sticker-ink);
  font-size: 15px;
}
.practice[data-kind="test"] {
  background: repeating-linear-gradient(-45deg, rgba(200, 56, 46, .1) 0 8px, transparent 8px 16px), var(--bad-soft);
  color: var(--bad);
}
.tally {
  padding: 14px 18px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--paper);
}
.tally-line { display: flex; align-items: baseline; flex-wrap: wrap; gap: 0 8px; margin: 0; }
.tally-label { color: var(--ink-2); }
.tally-used {
  font-family: var(--display);
  font-weight: 800;
  font-size: 40px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums lining-nums;
}
.tally-cap { color: var(--ink-2); }
.bar { height: 10px; margin: 8px 0 8px; border-radius: 999px; background: var(--brand-soft); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--brand); transition: width .4s ease; }
.tally-note { margin: 0; color: var(--ink-2); font-size: 15px; white-space: pre-line; }
.tally[data-state="full"] { border-color: var(--bad); background: var(--bad-soft); }
.tally[data-state="full"] .bar i { background: var(--bad); }
.tally[data-state="full"] .tally-note { color: var(--bad); font-weight: 600; }
.offer { margin: 12px 2px 0; color: var(--brand-deep); font-weight: 600; }

/* ── steps ───────────────────────────────────────────────────────────── */
.steps { margin: 0; padding: 0; list-style: none; }
.step { margin-top: 22px; }
.step h2 { display: flex; align-items: center; gap: 10px; margin: 0 0 10px; font-size: 17px; font-weight: 600; }
.n {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  font-family: var(--display);
  font-weight: 800;
  font-size: 15px;
}

/* the voucher stub: notched on both sides */
.ticket {
  position: relative;
  display: block;
  padding: 14px 24px 8px;
  border-radius: 18px;
  background: var(--sticker);
  color: var(--sticker-ink);
  cursor: text;
  -webkit-mask:
    radial-gradient(circle 12px at 0 50%, #0000 97%, #000) left / 51% 100% no-repeat,
    radial-gradient(circle 12px at 100% 50%, #0000 97%, #000) right / 51% 100% no-repeat;
          mask:
    radial-gradient(circle 12px at 0 50%, #0000 97%, #000) left / 51% 100% no-repeat,
    radial-gradient(circle 12px at 100% 50%, #0000 97%, #000) right / 51% 100% no-repeat;
  transition: background-color .2s ease;
}
.ticket-prefix {
  display: block;
  padding-bottom: 6px;
  border-bottom: 2px dashed rgba(43, 37, 16, .25);
  font-family: var(--display);
  font-weight: 800;
  font-size: 15px;
  letter-spacing: .08em;
}
.ticket-num {
  display: block;
  width: 100%;
  padding: 2px 0 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  caret-color: var(--brand);
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(52px, 17vw, 76px);
  line-height: 1.15;
  letter-spacing: .02em;
  font-variant-numeric: tabular-nums lining-nums;
  outline: none;
}
.ticket-num::placeholder { color: rgba(43, 37, 16, .2); }
.ticket[data-state="ok"] { background: #d8f0df; }
.ticket[data-state="used"],
.ticket[data-state="invalid"] { background: var(--bad-soft); }

.stamp {
  position: absolute;
  right: 22px;
  bottom: 18px;
  padding: 2px 12px;
  border: 3px solid currentColor;
  border-radius: 10px;
  font-weight: 700;
  font-size: 20px;
  line-height: 1.3;
  transform: rotate(-9deg);
  opacity: 0;
  pointer-events: none;
}
.ticket[data-state="ok"] .stamp,
.ticket[data-state="used"] .stamp { opacity: .92; animation: stamp .18s ease-out; }
.ticket[data-state="ok"] .stamp { color: var(--ok); }
.ticket[data-state="used"] .stamp { color: var(--bad); }
@keyframes stamp { from { transform: rotate(-9deg) scale(1.6); opacity: 0; } }

.check { min-height: 1.5em; margin: 8px 2px 0; color: var(--ink-2); font-size: 15px; white-space: pre-line; }
.check[data-state="ok"] { color: var(--ok); font-weight: 600; }
.check[data-state="used"], .check[data-state="invalid"] { color: var(--bad); font-weight: 600; }

/* camera */
.camera {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 116px;
  overflow: hidden;
  border: 2px dashed var(--line-strong);
  border-radius: var(--r-lg);
  background: var(--paper);
  color: var(--brand-deep);
  font-weight: 600;
  font-size: 18px;
}
.camera input { position: absolute; top: 0; left: 0; width: 1px; height: 1px; margin: 0; opacity: 0; }
.camera:has(input:focus-visible) { outline: 3px solid var(--brand); outline-offset: 2px; }
.camera-label { display: inline-flex; align-items: center; gap: 10px; }
.camera img { display: block; width: 100%; max-height: 240px; object-fit: cover; }
.camera[data-has-photo="yes"] { border-style: solid; border-color: var(--line); }
.camera[data-has-photo="yes"] .camera-label {
  position: absolute;
  right: 10px;
  bottom: 10px;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(15, 39, 66, .78);
  color: #fff;
  font-size: 15px;
}
.camera[data-has-photo="yes"] .camera-label svg { width: 18px; height: 18px; }

.confirm-hint { min-height: 1.5em; margin: 8px 0 0; color: var(--ink-2); font-size: 15px; text-align: center; }
.confirm-hint[data-state="bad"] { color: var(--bad); font-weight: 600; }

.photo-queue {
  margin: 14px 0 0;
  padding: 8px 14px;
  border-radius: 12px;
  background: var(--brand-soft);
  color: var(--brand-deep);
  font-size: 14px;
  font-weight: 500;
}

/* ── recent + footer ─────────────────────────────────────────────────── */
.recent { margin-top: 30px; }
.recent h2 { margin: 0 0 4px; color: var(--ink-2); font-size: 15px; font-weight: 600; }
.recent ul { margin: 0; padding: 0; list-style: none; }
.recent li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}
.recent .code { font-family: var(--display); font-weight: 600; font-size: 17px; font-variant-numeric: tabular-nums; }
.recent .meta { color: var(--ink-2); font-size: 14px; text-align: right; }
.recent .empty { color: var(--ink-3); border: 0; }
.foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 24px; color: var(--ink-3); font-size: 14px; }

/* ── result sheet ────────────────────────────────────────────────────── */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(15, 39, 66, .5);
}
.sheet-card {
  width: 100%;
  max-width: 520px;
  max-height: 100%;
  overflow-y: auto;
  padding: 26px 22px calc(22px + env(safe-area-inset-bottom));
  border-radius: 26px 26px 0 0;
  background: var(--paper);
  animation: rise .22s ease-out;
}
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
.sheet[data-kind="ok"] .sheet-card { background: var(--ok); color: #fff; }
.sheet[data-kind="bad"] .sheet-card { background: var(--bad); color: #fff; }
.sheet h2 { margin: 0; font-size: 26px; line-height: 1.25; }
.sheet-flag {
  display: inline-block;
  margin: 0 0 10px;
  padding: 2px 12px;
  border-radius: 999px;
  background: var(--sticker);
  color: var(--sticker-ink);
  font-size: 14px;
  font-weight: 700;
}
.sheet-code {
  margin: 10px 0 0;
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(30px, 11vw, 56px);   /* YOGURBARA20000 stays on one line down to 320px */
  line-height: 1.05;
  font-variant-numeric: tabular-nums lining-nums;
  white-space: nowrap;
}
.sheet-code small { margin-right: .12em; font-size: .5em; letter-spacing: .04em; }
.sheet-code:empty { display: none; }
.sheet-body { margin: 12px 0 0; font-size: 17px; white-space: pre-line; }
.sheet-actions { display: grid; gap: 10px; margin-top: 22px; }
.sheet .btn { background: #fff; color: var(--ink); }
.sheet[data-kind="ok"] .btn:not(.ghost) { color: var(--ok); }
.sheet[data-kind="bad"] .btn:not(.ghost) { color: var(--bad); }
.sheet[data-kind="info"] .btn:not(.ghost) { background: var(--brand); color: #fff; }
.sheet .btn.ghost { background: transparent; color: inherit; border: 2px solid currentColor; font-size: 16px; min-height: 50px; opacity: .9; }

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