:root {
  --cream: #f3e7d8;
  --cream-deep: #e8d6c1;
  --paper: #fffaf3;
  --coffee: #3b2a21;
  --coffee-soft: #5a4235;
  --coffee-faint: #8b7365;
  --gold: #c9a227;
  --green: #2e7d5b;
  --red: #b3402f;
  --radius: 18px;
  --shadow: 0 12px 32px rgba(59, 42, 33, 0.14);
  --font: 'Segoe UI', system-ui, -apple-system, 'Noto Naskh Arabic', 'Tahoma', sans-serif;
}

* { box-sizing: border-box; }

/* The hidden attribute has to beat any display rule set by a class, otherwise
   an element marked hidden stays visible in whatever half-built state it was
   left in -- a button with no href, a confirmation form nobody asked for. */
[hidden] { display: none !important; }


body {
  margin: 0;
  font-family: var(--font);
  background: var(--cream);
  color: var(--coffee);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: 480px;
  margin: 0 auto;
  padding: 24px 18px 56px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
  margin-bottom: 22px;
}

.brand img { width: 52px; height: 52px; border-radius: 50%; }

.brand h1 {
  font-size: 20px;
  letter-spacing: 3px;
  margin: 0;
  font-weight: 700;
}

.brand small {
  display: block;
  letter-spacing: 2px;
  font-size: 10px;
  color: var(--coffee-faint);
  font-weight: 600;
}

.card {
  background: var(--paper);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 18px;
}

h2 { margin: 0 0 6px; font-size: 19px; }
.sub { margin: 0 0 18px; color: var(--coffee-faint); font-size: 14px; line-height: 1.55; }

label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--coffee-faint);
  margin: 14px 0 6px;
}

input, textarea, select {
  width: 100%;
  padding: 13px 14px;
  font: inherit;
  color: var(--coffee);
  background: #fff;
  border: 1.5px solid var(--cream-deep);
  border-radius: 12px;
  outline: none;
  transition: border-color 0.15s;
}

input:focus, textarea:focus, select:focus { border-color: var(--coffee-soft); }

button {
  width: 100%;
  padding: 15px;
  font: inherit;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--cream);
  background: var(--coffee);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  margin-top: 18px;
  transition: transform 0.08s, opacity 0.15s;
}

button:active { transform: scale(0.985); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.ghost { background: transparent; color: var(--coffee); border: 1.5px solid var(--cream-deep); }
button.gold { background: var(--gold); color: #2a1d12; }
button.danger { background: var(--red); }
button.slim { padding: 11px; font-size: 14px; margin-top: 10px; }

.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

/* ---- loyalty card ---- */

.stampcard {
  background: linear-gradient(160deg, var(--paper), var(--cream));
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 18px;
}

.stampcard header {
  background: var(--coffee);
  color: var(--cream);
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.stampcard header .name { font-weight: 700; font-size: 16px; }
.stampcard header .serial { font-size: 11px; letter-spacing: 2px; opacity: 0.7; }
.stampcard header .free {
  text-align: right;
  font-size: 11px;
  letter-spacing: 1px;
  opacity: 0.75;
}
.stampcard header .free b { display: block; font-size: 22px; letter-spacing: 0; opacity: 1; }

.stamps {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  padding: 22px 20px;
  justify-items: center;
}

.stamp {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 2px solid var(--coffee-faint);
  display: grid;
  place-items: center;
  font-size: 18px;
  color: transparent;
  transition: background 0.25s, transform 0.25s;
}

.stamp.on {
  background: var(--coffee);
  border-color: var(--coffee);
  color: var(--cream);
  transform: scale(1.04);
}

.progress {
  padding: 0 20px 20px;
  text-align: center;
  font-size: 14px;
  color: var(--coffee-soft);
}

.progress b { font-size: 18px; }

.reward-banner {
  margin: 0 20px 20px;
  padding: 13px;
  border-radius: 12px;
  background: var(--gold);
  color: #2a1d12;
  font-weight: 700;
  text-align: center;
}

/* ---- wallet buttons ---- */

.wallet-btns { display: grid; gap: 10px; }

.wallet-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 15px;
  border-radius: 12px;
  background: #000;
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  font-size: 15px;
}

.wallet-btn.google { background: #fff; color: #202124; border: 1.5px solid #dadce0; }
.wallet-btn[aria-disabled='true'] { opacity: 0.4; pointer-events: none; }

/* The Apple mark used to be U+F8FF, Apple's private-use glyph -- it only draws
   on Apple devices and shows as an empty box everywhere else. An inline SVG
   renders the same on every phone and desktop. */
.wallet-btn svg { width: 20px; height: 20px; flex: none; }
.wallet-btn.google svg { width: 22px; height: 22px; }
.wallet-btn:active { transform: scale(0.985); }

.qr-box { text-align: center; padding: 8px 0 0; }
.qr-box img {
  width: 220px;
  height: 220px;
  border-radius: 14px;
  background: #fff;
  padding: 10px;
  box-shadow: var(--shadow);
}
.qr-box p { font-size: 13px; color: var(--coffee-faint); margin: 12px 0 0; letter-spacing: 3px; }

/* ---- feedback ---- */

.msg {
  padding: 13px 15px;
  border-radius: 12px;
  font-size: 14px;
  margin-top: 14px;
  line-height: 1.5;
}
.msg.ok { background: #e2f1ea; color: var(--green); }
.msg.err { background: #fbe6e2; color: var(--red); }
.msg.info { background: var(--cream-deep); color: var(--coffee-soft); }
.msg:empty { display: none; }

.note { font-size: 12px; color: var(--coffee-faint); text-align: center; margin-top: 16px; line-height: 1.6; }
.note a { color: var(--coffee-soft); }

/* ---- scanner ---- */

#viewfinder {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: var(--radius);
  overflow: hidden;
  background: #1b120d;
  display: none;
}
#viewfinder.live { display: block; }
#viewfinder video { width: 100%; height: 100%; object-fit: cover; }
#viewfinder .reticle {
  position: absolute;
  inset: 18%;
  border: 3px solid rgba(243, 231, 216, 0.85);
  border-radius: 16px;
  box-shadow: 0 0 0 999px rgba(27, 18, 13, 0.45);
}

.history { list-style: none; padding: 0; margin: 14px 0 0; font-size: 13px; }
.history li {
  display: flex;
  justify-content: space-between;
  padding: 9px 0;
  border-bottom: 1px solid var(--cream-deep);
  color: var(--coffee-soft);
}
.history li:last-child { border-bottom: none; }

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.badge.active { background: #e2f1ea; color: var(--green); }
.badge.redeemed { background: var(--cream-deep); color: var(--coffee-faint); }
.badge.void { background: #fbe6e2; color: var(--red); }

[dir='rtl'] { text-align: right; }
.ar { font-size: 13px; color: var(--coffee-faint); direction: rtl; }
