:root {
  /* palette */
  --paper: #FAF6EF;
  --surface: #FFFFFF;
  --ink: #2B2118;
  --muted: #8A7A66;
  --espresso: #4A2E1F;
  --espresso-dark: #331F15;
  --gold: #C89B5C;
  --gold-deep: #A97C3E;
  --gold-bg: #FBF1DE;
  --gold-line: #EEDBAE;
  --sage: #5B7A4D;
  --sage-bg: #EAF0E4;
  --rust: #B5482E;
  --rust-bg: #F6E7E2;
  --line: #E7DFD1;
  --line-soft: #F0E9DC;

  /* spacing scale */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 20px;
  --s6: 28px;

  /* radii */
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 18px;
  --r-pill: 999px;

  /* warm-tinted elevation, never neutral grey */
  --shadow-sm: 0 1px 2px rgba(74, 46, 31, 0.05);
  --shadow-md: 0 2px 8px rgba(74, 46, 31, 0.07);
  --shadow-bar: 0 -2px 14px rgba(74, 46, 31, 0.10);
}

/* Thai baht sign. Several common UI fonts ship the glyph with an advance
   narrower than its ink, so it overlaps the digit that follows; sourcing just
   this one character from a Thai-capable face fixes the collision without
   changing how the digits look. */
.baht {
  font-family: "Thonburi", "Leelawadee UI", "Noto Sans Thai", "Sarabun", sans-serif;
  margin-right: 0.04em;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.hidden { display: none !important; }

button { font-family: inherit; }

:focus-visible {
  outline: 2px solid var(--espresso);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* ---------- header ---------- */

.app-header {
  display: flex;
  align-items: flex-start;
  gap: var(--s2);
  padding: var(--s6) var(--s5) var(--s3);
  flex: none;
}
.app-header .mark {
  width: 24px;
  height: 24px;
  flex: none;
  margin-top: 2px;
  color: var(--espresso);
}
.app-header .brand { display: flex; flex-direction: column; gap: 1px; }
.app-header .brand-tag {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--gold-deep);
  letter-spacing: 0.08em;
}
.app-header h1 {
  font-size: 19px;
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.015em;
  line-height: 1.15;
}

.icon-btn {
  margin-left: auto;
  width: 36px;
  height: 36px;
  flex: none;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  box-shadow: var(--shadow-sm);
  transition: color .15s ease, border-color .15s ease;
}
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn:hover { border-color: var(--espresso); color: var(--espresso); }
.icon-btn:active { background: var(--gold-bg); }

/* ---------- layout ---------- */

.scroll { flex: 1; padding: 0 var(--s4) var(--s4); }

.section-label {
  font-size: 12.5px;
  color: var(--muted);
  margin: var(--s4) var(--s1) var(--s3);
  font-weight: 600;
  letter-spacing: 0.01em;
}

.section-label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s3);
  margin: var(--s4) var(--s1) var(--s3);
}
.section-label-row .section-label { margin: 0; }

.text-btn {
  background: none;
  border: 0;
  padding: 0;
  color: var(--espresso);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.text-btn:hover { color: var(--espresso-dark); text-decoration: underline; }
.text-btn:disabled { color: var(--muted); cursor: not-allowed; text-decoration: none; }
.text-btn-quiet { color: var(--muted); }
.text-btn-quiet:hover { color: var(--rust); }

.label-actions { display: flex; align-items: baseline; gap: var(--s4); }
.logout-form { margin: 0; display: inline; }

/* ---------- menu ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: var(--s3);
}

button.product {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 10px var(--s3);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  text-align: left;
  box-shadow: var(--shadow-sm);
  transition: border-color .15s ease, transform .08s ease, box-shadow .15s ease;
}
button.product:hover { border-color: var(--gold); }
button.product:active {
  transform: scale(0.975);
  box-shadow: none;
  background: var(--gold-bg);
}
button.product .name {
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.3;
  padding-right: var(--s5);
}
button.product .price {
  color: var(--gold-deep);
  font-weight: 700;
  font-size: 13px;
}

/* count badge on items already in the cart. The hover rule above has equal
   specificity, so this must not silently swallow hover feedback — in-cart
   cards get their own hover colour. */
button.product.in-cart { border-color: var(--espresso); }
button.product.in-cart:hover { border-color: var(--gold-deep); }
/* author `display` beats the hidden attribute's UA rule, so restore it */
.product-qty[hidden] { display: none; }
.product-qty {
  position: absolute;
  top: var(--s2);
  right: var(--s2);
  min-width: 21px;
  height: 21px;
  padding: 0 5px;
  border-radius: var(--r-pill);
  background: var(--espresso);
  color: #fff;
  font-size: 11.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- cart ---------- */

.cart-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 0 var(--s4);
  margin: 0 0 var(--s3);
  box-shadow: var(--shadow-sm);
}

.cart { list-style: none; padding: 0; margin: 0; }
.cart li {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s3) 0;
  border-bottom: 1px solid var(--line-soft);
  font-size: 14px;
}
.cart li:last-child { border-bottom: none; }

.cart-name {
  flex: 1;
  min-width: 0;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cart-line {
  font-weight: 700;
  font-size: 13.5px;
  min-width: 68px;
  text-align: right;
}

.qty {
  display: flex;
  align-items: center;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  padding: 2px;
  flex: none;
}
.qty-btn {
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--espresso);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.qty-btn:hover { background: var(--gold-bg); }
.qty-btn:active { background: var(--gold-line); }
.qty-num {
  min-width: 20px;
  text-align: center;
  font-size: 13.5px;
  font-weight: 700;
}

.empty-cart {
  padding: var(--s6) var(--s1);
  text-align: center;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.5;
  margin: 0;
}

/* ---------- sticky pay bar ---------- */

.sticky-bar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  background: var(--espresso);
  color: #fff;
  padding: var(--s4) var(--s5);
  padding-bottom: calc(var(--s4) + env(safe-area-inset-bottom));
  position: sticky;
  bottom: 0;
  box-shadow: var(--shadow-bar);
}
.sticky-bar-total { display: flex; flex-direction: column; gap: 1px; }
.sticky-bar .count {
  font-size: 11.5px;
  opacity: 0.7;
  letter-spacing: 0.02em;
}
.sticky-bar .total {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.015em;
}

button.primary {
  background: var(--gold);
  color: var(--espresso-dark);
  border: 0;
  border-radius: var(--r-sm);
  padding: var(--s3) var(--s5);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s ease, transform .08s ease;
}
button.primary:hover:not(:disabled) { background: #d4a969; }
button.primary:active:not(:disabled) { transform: scale(0.97); }
button.primary:disabled {
  background: rgba(255, 255, 255, 0.16);
  color: rgba(255, 255, 255, 0.45);
  cursor: not-allowed;
}

#screen-pay button.primary,
#screen-result button.primary {
  width: 100%;
  background: var(--espresso);
  color: #fff;
  padding: var(--s4);
}
#screen-pay button.primary:hover:not(:disabled),
#screen-result button.primary:hover:not(:disabled) { background: var(--espresso-dark); }
#screen-pay button.primary:disabled,
#screen-result button.primary:disabled { background: #cfc2ae; color: #fff; }

/* ---------- pay screen ---------- */

.pay-body {
  flex: 1;
  padding: 0 var(--s5) var(--s6);
  display: flex;
  flex-direction: column;
}

.chip-row {
  display: flex;
  gap: var(--s2);
  margin-bottom: var(--s5);
}
.chip {
  flex: 1;
  text-align: center;
  padding: var(--s3) var(--s1);
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface);
  cursor: pointer;
  text-transform: capitalize;
  transition: border-color .15s ease, background .15s ease, color .15s ease;
}
/* Menu groups: unlike the fixed set of chains, there can be more groups than
   fit the width, so these size to their label and scroll sideways instead of
   squeezing. */
.chip-row-scroll {
  overflow-x: auto;
  scrollbar-width: none;
  /* let chips reach the screen edges while scrolling, but stay aligned with
     the grid at rest */
  margin: 0 calc(-1 * var(--s4)) var(--s4);
  padding: 2px var(--s4);
}
.chip-row-scroll::-webkit-scrollbar { display: none; }
.chip-row-scroll .chip {
  flex: 0 0 auto;
  padding-left: var(--s4);
  padding-right: var(--s4);
}

/* Hover must exclude the active chip: the plain hover rule outranks
   `.chip.active` on specificity, so without this it would repaint the label
   espresso on an espresso background and make it unreadable. The active chip
   gets its own hover instead. */
.chip:hover:not(:disabled):not(.active) {
  border-color: var(--gold);
  color: var(--espresso);
}
.chip.active {
  border-color: var(--espresso);
  background: var(--espresso);
  color: #fff;
}
.chip.active:hover:not(:disabled) {
  background: var(--espresso-dark);
  border-color: var(--espresso-dark);
}
.chip:disabled { cursor: not-allowed; opacity: 0.55; }

.details {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--s4);
  display: grid;
  grid-template-columns: 1fr auto;
  row-gap: var(--s3);
  column-gap: var(--s4);
  font-size: 13.5px;
  margin: 0 0 var(--s5);
  box-shadow: var(--shadow-sm);
}
.details dt { margin: 0; color: var(--muted); }
.details dd { margin: 0; font-weight: 700; text-align: right; }
.details dd:last-of-type {
  font-size: 16px;
  color: var(--espresso);
  letter-spacing: -0.01em;
}

.qr-wrap { display: flex; justify-content: center; margin-bottom: var(--s4); }
#qr {
  display: block;
  width: 216px;
  height: 216px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  padding: var(--s2);
  box-shadow: var(--shadow-md);
}

.countdown-row {
  text-align: center;
  color: var(--muted);
  font-size: 12.5px;
  margin: 0 0 var(--s3);
}
.countdown-row b {
  font-size: 17px;
  color: var(--ink);
  font-weight: 700;
  letter-spacing: -0.01em;
}

.status-pill {
  text-align: center;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--espresso);
  background: var(--gold-bg);
  border: 1px solid var(--gold-line);
  border-radius: var(--r-sm);
  padding: var(--s3);
  margin-bottom: var(--s4);
}

.btn-outline {
  width: 100%;
  background: none;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: var(--r-sm);
  padding: var(--s4);
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .15s ease, color .15s ease;
}
.btn-outline:hover { border-color: var(--espresso); color: var(--espresso); }

/* ---------- result screen ---------- */

.result-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--s5) var(--s5) var(--s6);
  text-align: center;
}

.badge {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--s5);
  flex: none;
}
.badge.paid { background: var(--sage-bg); color: var(--sage); }
.badge.warn { background: var(--rust-bg); color: var(--rust); }

.result-title {
  font-size: 23px;
  font-weight: 700;
  margin: 0 0 var(--s1);
  letter-spacing: -0.02em;
}
.result-title.paid { color: var(--sage); }
.result-title.warn { color: var(--rust); }

.result-sub {
  font-size: 13.5px;
  color: var(--muted);
  margin: 0 0 var(--s5);
  line-height: 1.5;
  max-width: 32ch;
}

.result-details {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 0 var(--s4);
  margin-bottom: var(--s5);
  text-align: left;
  box-shadow: var(--shadow-sm);
}
.result-details .row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--s4);
  padding: var(--s3) 0;
  border-bottom: 1px solid var(--line-soft);
  font-size: 13.5px;
}
.result-details .row:last-child { border-bottom: none; }
.result-details dt { margin: 0; color: var(--muted); flex: none; }
.result-details dd {
  margin: 0;
  font-weight: 700;
  text-align: right;
  min-width: 0;
}
.result-details dd.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.result-body button.primary { margin-top: auto; }

/* ---------- order history ---------- */

.history-list {
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  padding-bottom: var(--s4);
}
.history-item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--s3) var(--s4);
  box-shadow: var(--shadow-sm);
}
.history-item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--s3);
  margin-bottom: var(--s1);
}
.history-order { font-weight: 700; font-size: 14.5px; letter-spacing: -0.01em; }
.history-status {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: var(--r-pill);
  letter-spacing: 0.02em;
  flex: none;
}
.history-status.pending { background: var(--gold-bg); color: var(--gold-deep); }
.history-status.paid { background: var(--sage-bg); color: var(--sage); }
.history-status.warn { background: var(--rust-bg); color: var(--rust); }
.history-item-bottom {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--s3);
  font-size: 12.5px;
  color: var(--muted);
}
.history-total { font-weight: 700; color: var(--ink); font-size: 14px; }
.history-chain { text-transform: capitalize; }

/* payer wallet, captured from the transfer */
.history-payer {
  display: flex;
  align-items: baseline;
  gap: var(--s2);
  margin-top: var(--s2);
  padding-top: var(--s2);
  border-top: 1px solid var(--line-soft);
  font-size: 11.5px;
  color: var(--muted);
}
.addr {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px;
  color: var(--ink);
  font-weight: 600;
}

.recheck-status {
  font-size: 12.5px;
  color: var(--muted);
  margin: 0 var(--s1) var(--s3);
  line-height: 1.5;
}
.recheck-status.ok { color: var(--sage); }

/* ---------- login ---------- */

.login-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--s6) var(--s5);
  text-align: center;
}
.login-mark { width: 42px; height: 42px; color: var(--espresso); margin-bottom: var(--s4); }
.login-title {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: var(--s1) 0 var(--s2);
}
.login-sub { font-size: 13.5px; color: var(--muted); margin: 0 0 var(--s6); }

.login-form {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  text-align: left;
}
.login-label { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.login-input {
  width: 100%;
  padding: var(--s3) var(--s4);
  font-size: 16px; /* 16px stops iOS Safari zooming the page on focus */
  font-family: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-sm);
}
.login-input:focus-visible { outline: 2px solid var(--espresso); outline-offset: 1px; }
.login-error { margin: var(--s1) 0 0; }
.login-submit { width: 100%; margin-top: var(--s3); padding: var(--s4); }

/* ---------- misc ---------- */

.error {
  color: var(--rust);
  font-weight: 600;
  margin: 0 0 var(--s3);
  font-size: 13.5px;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

@media (prefers-reduced-motion: no-preference) {
  .screen:not(.hidden) { animation: fade-in .2s ease-out; }
}
@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
