:root {
  --bg: #f6eedf;
  --paper: #fffdf8;
  --paper-2: #fff9ef;
  --text: #2b1f16;
  --muted: #645143;
  --brown: #4d2d12;
  --brown-2: #7b4309;
  --line: #eadcc7;
  --green: #14922b;
  --green-2: #42b917;
  --gold: #d29b47;
  --soft-gold: #ead8b8;
  --shadow: 0 18px 38px rgba(83, 52, 18, .13), 0 4px 12px rgba(83, 52, 18, .08);
  --radius-xl: 30px;
  --radius-lg: 24px;
  /* Fixed design width: the card is authored at this width and JS scales the
     whole thing to the screen, so it looks identical on every device/zoom. */
  --design-w: 390px;
}

* { box-sizing: border-box; }
/* hidden must win over panes that set an explicit display (flex/grid). */
[hidden] { display: none !important; }
html {
  min-height: 100%;
  background: var(--bg);
  /* Lock text to the CSS px on every device: Android Chrome otherwise scales
     web text by the system "Font size" setting (making it smaller/larger than
     iOS, which ignores it). 100% = render exactly as authored. */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* Kill the iOS rubber-band / overscroll bounce (the card is a single screen). */
  overscroll-behavior: none;
}
body {
  margin: 0;
  min-height: 100svh;
  overflow-x: hidden;
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background:
    radial-gradient(circle at 12% 4%, rgba(255,255,255,.8), transparent 32%),
    radial-gradient(circle at 80% 7%, rgba(255,255,255,.72), transparent 28%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='118' height='118' viewBox='0 0 118 118'%3E%3Cg fill='none' stroke='%23c49b60' stroke-width='1.45' opacity='.22'%3E%3Cellipse cx='22' cy='28' rx='8' ry='16' transform='rotate(32 22 28)'/%3E%3Cpath d='M22 13c4 8 4 21 0 30' transform='rotate(32 22 28)'/%3E%3Cellipse cx='92' cy='91' rx='8' ry='16' transform='rotate(-28 92 91)'/%3E%3Cpath d='M92 76c4 8 4 21 0 30' transform='rotate(-28 92 91)'/%3E%3C/g%3E%3C/svg%3E"),
    linear-gradient(180deg, #fbf3e5 0%, #f5ecdc 52%, #f2e6d4 100%);
  background-size: auto, auto, 118px 118px, auto;
}
button { font: inherit; }

/* Kill iOS double-tap-to-zoom (a fast double tap on a button zoomed the page).
   `manipulation` keeps normal taps and pinch-zoom, drops the double-tap gesture. */
html, body, button, a, .cup-slot, .loyalty-page { touch-action: manipulation; }

/* Installed PWA: pin the viewport so a finger drag can't rubber-band the card.
   The body is a fixed-size box that only scrolls if the card is genuinely taller
   than the screen (tiny/landscape devices) — so nothing gets clipped, and when it
   fits (the normal case) it doesn't move at all. Browser tabs keep normal scroll. */
@media (display-mode: standalone) {
  html {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
  }
  body {
    position: fixed;
    inset: 0;
    width: 100%;
    overflow: hidden;               /* locked — the touchmove guard enforces it too */
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
  }
}

.loyalty-page {
  position: relative;
  width: var(--design-w);
  left: calc(50% - var(--design-w) / 2);
  min-height: 100svh;
  transform-origin: top center;
  /* transform: scale() is set by fitCard() in app.js so the whole card scales
     uniformly to the viewport width — identical proportions on any device/zoom. */
  padding: max(2px, calc(env(safe-area-inset-top) - 14px)) 16px calc(24px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
}

.topbar {
  position: relative;
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.topbar h1 {
  margin: 2px 14px 0 46px;
  font-size: 15px;
  line-height: 1.05;
  font-weight: 900;
  letter-spacing: -.04em;
  color: var(--text);
  white-space: nowrap;
}
.bean,
.bean-icon {
  display: inline-block;
  width: 24px;
  height: 34px;
  border: 2px solid rgba(188, 139, 72, .42);
  border-radius: 50%;
  transform: rotate(34deg);
}
.bean::after,
.bean-icon::after {
  content: "";
  position: absolute;
  inset: 4px 9px;
  border-left: 2px solid rgba(188, 139, 72, .42);
  border-radius: 50%;
}
.bean { position: absolute; opacity: .75; }
.bean--one { left: 18px; top: 4px; }
.bean--two { right: 126px; top: 2px; width: 20px; height: 28px; opacity: .55; }
.corner-ribbons {
  position: absolute;
  top: -14px;
  right: -78px;
  width: 150px;
  height: 76px;
  transform: rotate(-12deg);
}
.corner-ribbons i {
  position: absolute;
  right: 0;
  width: 145px;
  height: 34px;
  border-radius: 7px;
  background: linear-gradient(110deg, #8a5526, #5c3411);
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.12);
}
.corner-ribbons i:first-child { top: 0; }
.corner-ribbons i:last-child { bottom: 0; right: 24px; }

.card-shell {
  position: relative;
  border: 1px solid rgba(229, 212, 185, .9);
  border-radius: var(--radius-xl);
  background: linear-gradient(145deg, rgba(255,255,255,.97), rgba(255,251,244,.97));
  box-shadow: var(--shadow);
}

.hero-card {
  min-height: 130px;
  padding: 14px 16px;
  overflow: visible;
  display: grid;
  grid-template-columns: 45% 55%;
  align-items: center;
}
/* Clips the green background to the rounded card; the cup lives outside it
   so it can rise above the card's top edge without being cut off. */
.hero-clip {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  border-radius: inherit;
}
.hero-clip::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 27% 77%, rgba(49, 160, 31, .18), transparent 33%);
}
.hero-green {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 42%;
  background: #0f7a4f;
  clip-path: polygon(0 0, 100% 0, 79% 100%, 0 100%);
}
.hero-green--stripe {
  width: 54%;
  top: 40px;
  bottom: auto;
  height: 16px;
  left: -32px;
  background: #fff;
  transform: rotate(-22deg);
  clip-path: none;
  border-radius: 999px;
  opacity: .98;
}
.hero-green--stripe2 {
  top: 102px;
  height: 11px;
  width: 50%;
}
.hero-cup {
  position: absolute;
  left: 12px;
  bottom: 3px;
  z-index: 3;
  width: min(29.4%, 124px);
  transform: rotate(-6deg);
  filter: drop-shadow(0 20px 18px rgba(41, 23, 8, .30));
  user-select: none;
}
.hero-badge {
  position: absolute;
  z-index: 5;
  left: 24%;
  top: 64%;
  transform: translateY(-50%);
  width: 100px;
  height: 100px;
  display: grid;
  place-items: center;
}
/* drop-shadow lives on the img, NOT the badge container: iOS/WebKit drops
   absolutely-positioned children of a filtered box (the disc vanished on iPhone
   while the number, an in-flow grid item, stayed). */
.hero-badge img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 14px 18px rgba(51, 28, 6, .32)); }
.hero-badge span {
  position: relative;
  z-index: 1;
  margin-top: -2px;
  color: #fff;
  font-size: 32px;
  line-height: 1;
  font-weight: 950;
  text-shadow: 0 3px 4px rgba(0,0,0,.18);
}
.hero-gift {
  position: absolute;
  z-index: 6;
  left: calc(24% + 61px);
  top: calc(64% + 11px);
  width: 28px;
  /* No drop-shadow filter here: on iOS, absolute + filter + pulse-animation
     together make the badge vanish (the number disc — filtered but not animated —
     and the cups — animated but not absolute — both render fine). */
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}
.hero-copy {
  position: relative;
  z-index: 4;
  grid-column: 2;
  align-self: start;
  padding-top: 4px;
  padding-left: 16px;
  min-width: 0;
}
.hello,
.lead { margin: 0; }
.hello {
  font-size: 15px;
  font-weight: 900;
  letter-spacing: -.025em;
}
.hello b { color: var(--green); }
.lead {
  margin-top: 2px;
  font-size: 13.5px;
  color: #4a3b30;
  line-height: 1.2;
}
.free-count {
  margin: 24px 0 0;
  font-size: 15.6px;
  line-height: 1.1;
  font-weight: 900;
  letter-spacing: -.02em;
  color: #2b1a0f;
  white-space: nowrap;
}
.claim-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  max-width: none;
  border: 0;
  border-radius: 20px;
  min-height: 66px;
  padding: 0 22px;
  color: #fff;
  cursor: pointer;
  background: linear-gradient(180deg, #119326, #087c1e);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.32), 0 10px 18px rgba(0, 110, 29, .20);
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
}
.gift-line {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 12 20 22 4 22 4 12'/%3E%3Crect x='2' y='7' width='20' height='5'/%3E%3Cline x1='12' y1='22' x2='12' y2='7'/%3E%3Cpath d='M12 7H7.5a2.5 2.5 0 0 1 0-5C11 2 12 7 12 7z'/%3E%3Cpath d='M12 7h4.5a2.5 2.5 0 0 0 0-5C13 2 12 7 12 7z'/%3E%3C/g%3E%3C/svg%3E") center/contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 12 20 22 4 22 4 12'/%3E%3Crect x='2' y='7' width='20' height='5'/%3E%3Cline x1='12' y1='22' x2='12' y2='7'/%3E%3Cpath d='M12 7H7.5a2.5 2.5 0 0 1 0-5C11 2 12 7 12 7z'/%3E%3Cpath d='M12 7h4.5a2.5 2.5 0 0 0 0-5C13 2 12 7 12 7z'/%3E%3C/g%3E%3C/svg%3E") center/contain no-repeat;
}

.cycle-card { padding: 12px 22px 12px; }
.cycle-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 9px;
}
.cycle-head h2 {
  margin: 0;
  display: inline-flex;
  align-items: center;
  font-size: 12.2px;
  line-height: 1;
  font-weight: 900;
  letter-spacing: -.03em;
  white-space: nowrap;
}
/* keep the pills together and right-aligned, even when they wrap to a 2nd line */
.cycle-actions { margin-left: auto; }
.bean-icon {
  position: relative;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #784412, #321706 70%);
  box-shadow: inset 2px 2px 0 rgba(255,255,255,.25);
}
.bean-icon::after {
  inset: 4px 12px;
  border-left: 2px solid rgba(255,255,255,.8);
}
.cycle-pill {
  flex: 0 0 auto;
  padding: 6px 10px;
  border-radius: 999px;
  background: #f0dfc4;
  color: #291b11;
  font-weight: 900;
  font-size: 11px;
  letter-spacing: -.035em;
}
.cups-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  align-items: end;
  gap: 12.2px;
  padding: 4px 8px 0;
}
.cup-slot {
  position: relative;
  min-width: 0;
  aspect-ratio: 1 / 1.22;
  display: grid;
  place-items: end center;
}
.cup-slot img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center bottom;
  filter: drop-shadow(0 8px 8px rgba(55, 28, 5, .17));
}
.cup-slot.is-empty img { filter: none; opacity: .92; }
.progress {
  height: 18px;
  margin-top: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #ead9b9;
  box-shadow: inset 0 1px 1px rgba(255,255,255,.7);
}
.progress span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #0a5238, #0e7a52);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.28);
  transition: width 1.5s cubic-bezier(.22, .61, .36, 1);
}

.qr-card {
  padding: 12px 30px 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 100; /* confetti must fall behind this block */
}
.qr-card::before,
.qr-card::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 46%;
  opacity: .44;
  background-image: radial-gradient(circle, rgba(209, 180, 134, .38) 1.8px, transparent 2px);
  background-size: 16px 16px;
  mask-image: linear-gradient(90deg, black, transparent);
}
.qr-card::after {
  left: auto;
  right: 0;
  mask-image: linear-gradient(-90deg, black, transparent);
}
.decor {
  position: absolute;
  z-index: 1;
  pointer-events: none;
  user-select: none;
}
.decor--left {
  left: -18px;
  top: 50px;
  width: min(50%, 250px);
  filter: drop-shadow(0 8px 9px rgba(60, 42, 14, .14));
}
.decor--right {
  right: -12px;
  top: 24px;
  width: min(50%, 244px);
  filter: drop-shadow(0 8px 9px rgba(60, 42, 14, .15));
}
.qr-wrap {
  position: relative;
  z-index: 2;
  width: min(100%, 211px);
  max-width: 211px;
  margin: 0 auto 6px;
  padding: 10px;
  border-radius: 26px;
  background: #fff;
  box-shadow: 0 16px 24px rgba(58, 34, 8, .12);
}
.qr-wrap img { display: block; width: 100%; height: auto; image-rendering: pixelated; }
/* Fills the QR square while the code is loading or after it failed, so the panel
   keeps its size instead of collapsing under the caption. */
.qr-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  aspect-ratio: 1 / 1;
  min-height: 150px;
  padding: 12px;
  text-align: center;
}
.qr-error-text { margin: 0; font-size: 14px; font-weight: 600; color: #6b5636; line-height: 1.35; }
.qr-retry {
  border: 0;
  border-radius: 12px;
  padding: 10px 20px;
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(180deg, #119326, #087c1e);
  cursor: pointer;
}
.qr-caption {
  position: relative;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 0 0 8px;
  color: #271d17;
  font-size: 12.2px;
  line-height: 1.2;
  text-align: center;
  white-space: nowrap;
}
.mini-cup {
  width: 34px;
  height: 46px;
  flex: 0 0 34px;
  background: url('assets/cup-filled.webp') center/contain no-repeat;
}
/* Refresh as a small pill next to "N из M", same plaque background. */
.cycle-actions { display: inline-flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.cycle-refresh {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  border: 0;
  border-radius: 999px;
  background: #f0dfc4;
  color: #291b11;
  font-weight: 900;
  font-size: 11px;
  letter-spacing: -.035em;
  white-space: nowrap;
  cursor: pointer;
}
.cycle-refresh:active { background: #e7d2b0; }
.refresh-icon { font-size: 1.15em; line-height: 1; transform-origin: 50% 53%; }
.cycle-refresh.is-refreshing .refresh-icon { animation: spin .65s linear infinite; }

.install-card {
  position: relative;
  z-index: 100;
  display: block;
  text-align: center;
  padding: 12px 18px;
  border-radius: var(--radius-lg);
  border: 2px solid #118d34;
  background: linear-gradient(145deg, rgba(255,255,255,.92), rgba(255,252,246,.92));
  box-shadow: 0 12px 24px rgba(45, 83, 33, .08);
}
.install-card img {
  width: 52px;
  height: 52px;
  object-fit: contain;
  filter: drop-shadow(0 4px 7px rgba(40, 19, 5, .13));
}
.install-card p {
  margin: 0;
  font-size: 12.2px;
  line-height: 1.3;
  letter-spacing: -.02em;
}
.install-card b { color: #0b5e40; font-weight: 950; }

@keyframes spin { to { transform: rotate(360deg); } }

/* Card design — applied unconditionally: the whole card is rendered at the fixed
   design width and uniformly scaled by JS, so there is no per-viewport reflow. */
  .loyalty-page { padding-left: 16px; padding-right: 16px; gap: 12px; }
  .hero-card { min-height: 130px; padding: 14px 14px; grid-template-columns: 45% 55%; }
  .hero-cup { left: 6px; width: min(29.4%, 124px); }
  .hero-badge { width: 100px; height: 100px; left: 24%; top: 64%; transform: translateY(-50%); }
  .hero-badge span { font-size: 34px; }
  .hero-gift { width: 28px; left: calc(24% + 61px); top: calc(64% + 11px); }
  .hero-copy { padding-left: 16px; }
  .claim-button { min-height: 54px; padding: 0 14px; gap: 8px; }
  .gift-line { width: 25px; height: 25px; flex-basis: 25px; }
  .cycle-card { padding: 12px 18px 12px; }
  .progress { height: 15px; margin-top: 10px; }
  .qr-card { padding: 12px 22px 12px; }
  .decor--left { top: 54px; width: min(50%, 232px); left: -18px; }
  .decor--right { top: 28px; width: min(50%, 228px); right: -12px; }
  .install-card { padding: 10px 10px; }
  .install-card img { width: 48px; height: 48px; }

/* --- Boot / loading / fatal --- */
.boot {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60svh;
  margin: 0;
  padding: 24px;
  text-align: center;
  color: var(--muted);
  font-size: 18px;
  font-weight: 600;
}
#fatal { color: #b3261e; }

/* --- Registration screen --- */
.reg-screen {
  width: min(100%, var(--max));
  min-height: 100svh;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 18px calc(28px + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
}
.reg-card {
  width: 100%;
  padding: 30px 26px 28px;
}
.reg-brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-weight: 900;
  letter-spacing: -.03em;
  color: var(--green);
  font-size: 20px;
}
.reg-title {
  margin: 16px 0 6px;
  font-size: 28px;
  font-weight: 950;
  letter-spacing: -.04em;
  color: var(--text);
}
.reg-sub {
  margin: 0 0 22px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.4;
}
.reg-form { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 8px; }
.field > span { font-weight: 700; font-size: 15px; color: var(--text); }
.field small { color: var(--muted); font-weight: 500; }
.field input {
  width: 100%;
  height: 56px;
  padding: 0 16px;
  border: 1.5px solid var(--line);
  border-radius: 16px;
  background: #fff;
  font-size: 18px;
  color: var(--text);
}
.field input:focus { outline: none; border-color: var(--green); }
.phone-input {
  display: flex;
  align-items: stretch;
  border: 1.5px solid var(--line);
  border-radius: 16px;
  background: #fff;
  overflow: hidden;
}
.phone-input:focus-within { border-color: var(--green); }
.phone-prefix {
  display: flex;
  align-items: center;
  padding: 0 14px;
  font-size: 18px;
  font-weight: 800;
  color: var(--text);
  background: var(--soft-gold);
}
.phone-input input { border: 0; border-radius: 0; height: 56px; }
.reg-submit {
  margin-top: 6px;
  width: 100%;
  min-height: 60px;
  border: 0;
  border-radius: 18px;
  color: #fff;
  font-size: 20px;
  font-weight: 800;
  background: linear-gradient(180deg, #119326, #087c1e);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.3), 0 10px 18px rgba(0,110,29,.2);
}
.reg-submit:disabled { opacity: .7; }
.reg-error {
  margin: 4px 0 0;
  color: #b3261e;
  font-size: 15px;
  font-weight: 600;
}

/* --- SMS code step --- */
.code-step { display: flex; flex-direction: column; gap: 14px; }
.otp-row { display: flex; gap: 12px; justify-content: center; margin-top: 4px; }
.otp-box {
  width: 62px;
  height: 72px;
  border: 1.5px solid var(--line);
  border-radius: 16px;
  background: #fff;
  text-align: center;
  font-size: 30px;
  font-weight: 800;
  color: var(--text);
  caret-color: var(--green);
}
.otp-box:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px rgba(17,147,38,.15); }
.otp-box.is-filled { border-color: var(--green); background: var(--soft-gold); }
.code-actions { display: flex; justify-content: space-between; gap: 12px; margin-top: 2px; }
.code-link {
  border: 0;
  background: none;
  padding: 6px 2px;
  font-size: 15px;
  font-weight: 700;
  color: var(--brown-2);
  cursor: pointer;
}
.code-link:disabled { color: var(--muted); cursor: default; }

/* --- Notify (push) button --- */
.notify-button {
  position: relative;
  z-index: 2;
  margin-top: 10px;
  width: auto;
  padding: 0 22px;
  min-height: 46px;
  border: none;
  border-radius: 999px;
  background: var(--green);
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: -.03em;
  cursor: pointer;
  /* Raised look + gentle attention pulse so it reads as a tappable button. */
  box-shadow: 0 6px 16px rgba(20, 146, 43, .38);
  transition: transform .12s ease, box-shadow .12s ease;
  animation: notify-pulse 2.4s ease-in-out infinite;
}
.notify-button::after {
  content: "›";
  margin-left: 8px;
  font-weight: 700;
}
.notify-button:active {
  transform: scale(.96);
  box-shadow: 0 3px 10px rgba(20, 146, 43, .32);
}
.notify-button:disabled { opacity: .6; animation: none; }
@keyframes notify-pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 6px 16px rgba(20, 146, 43, .38); }
  50% { transform: scale(1.045); box-shadow: 0 9px 24px rgba(20, 146, 43, .52); }
}
@media (prefers-reduced-motion: reduce) {
  .notify-button { animation: none; }
}
.cycle-card .notify-button { display: block; width: fit-content; margin: 12px auto 2px; }

/* QR fade-in on (re)render */
#qrImage { opacity: 1; }
#qrImage.qr-in { animation: qrIn 1.2s ease-out both; }
@keyframes qrIn { from { opacity: 0; transform: scale(.985); } to { opacity: 1; transform: none; } }

/* --- Pulsing accents --- */
@keyframes giftPulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.18); } }
@keyframes heroRingPulse {
  0%, 100% { box-shadow: var(--shadow), 0 0 0 0 rgba(20, 146, 43, 0); }
  50%      { box-shadow: var(--shadow), 0 0 0 4px rgba(20, 146, 43, .20); }
}
@media (prefers-reduced-motion: no-preference) {
  .hero-gift { animation: giftPulse 1.5s ease-in-out infinite; transform-origin: center; }
  .hero-card { animation: heroRingPulse 2.6s ease-in-out infinite; }
}

/* --- Confetti burst (fired from the gift icon when a free coffee is earned) --- */
/* Lives INSIDE .loyalty-page (which is transform-scaled): absolute positioning
   keeps it in the card's coordinate space and inside its stacking context, so
   z-index 50 stays behind the QR card (100) yet above the hero & cycle cards. */
.confetti { position: absolute; inset: 0; pointer-events: none; z-index: 50; overflow: hidden; }
.confetti i {
  position: absolute;
  display: block;
  opacity: 0;
  will-change: transform, opacity;
  animation: confettiFly var(--d, 5s) cubic-bezier(.2, .6, .3, 1) var(--delay, 0s) forwards;
}
@keyframes confettiFly {
  0%   { transform: translate(0, 0) rotate(0deg); opacity: 0; }
  8%   { opacity: 1; }
  35%  { transform: translate(var(--bx), var(--by)) rotate(calc(var(--rot) * .4)); opacity: 1; }
  100% { transform: translate(var(--ex), var(--ey)) rotate(var(--rot)); opacity: 0; }
}

/* Cups fade/scale in one-by-one (staggered by --i) on each render */
@keyframes cupIn { from { opacity: 0; transform: translateY(9px) scale(.82); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: no-preference) {
  .cup-slot { animation: cupIn .65s cubic-bezier(.22,.61,.36,1) both; animation-delay: calc(var(--i, 0) * .28s); }
}

/* Inline iOS-style share glyph in the install hint */
.share-ico {
  display: inline-block;
  width: 1.15em;
  height: 1.15em;
  vertical-align: -.24em;
  background: #0b5e40;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 15V3'/%3E%3Cpath d='M8 7l4-4 4 4'/%3E%3Cpath d='M5 12v7a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-7'/%3E%3C/svg%3E") center/contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 15V3'/%3E%3Cpath d='M8 7l4-4 4 4'/%3E%3Cpath d='M5 12v7a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-7'/%3E%3C/svg%3E") center/contain no-repeat;
}

/* When launched as an installed PWA: hide the install hint and keep the content
   top-aligned so it sits near the top edge (centering left a big gap up top). */
@media (display-mode: standalone) {
  .install-card { display: none !important; }
  /* Top-aligned, but with a modest gap below the status bar so it isn't slammed
     to the very edge (centering left too much space; flex-start alone too little). */
  .loyalty-page { justify-content: flex-start; padding-top: calc(env(safe-area-inset-top) + 40px); }
  .quick-links { display: flex; }
}

/* Android/desktop install button */
.install-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 28px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #15a06a, #0b6e47);
  color: #fff;
  font-weight: 800;
  font-size: 14.4px;
  letter-spacing: -.02em;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.25), 0 8px 16px rgba(11,94,64,.22);
}
.install-hint-sub { color: var(--muted); }

.install-card .install-caption { margin-bottom: 8px; color: var(--muted); font-size: 10.3px; letter-spacing: -.015em; white-space: nowrap; }

/* Subtle quick-links row under the QR block: transparent (shows the page
   background through), darker brown border + text. */
/* Only shown inside the installed PWA (standalone), not in the browser link.
   Default hidden; revealed by the standalone media query and the JS is-standalone
   flag (iOS reports standalone via navigator.standalone, not always the media). */
.quick-links {
  display: none;
  gap: 8px;
  margin-top: 2px;
}
.is-standalone .quick-links { display: flex; }

/* Tiny build stamp — lets us tell at a glance which version a device is on
   (iOS PWAs cache aggressively). */
.build-tag { margin: 8px auto 0; text-align: center; font-size: 9px; letter-spacing: .06em; color: rgba(43, 31, 22, .3); }

/* Offline hint under the QR (shown when the balance couldn't be refreshed). */
.offline-note {
  position: relative;
  z-index: 2;
  margin: 0 0 8px;
  padding: 5px 12px;
  border-radius: 999px;
  background: #f6e4c4;
  color: #7a4a06;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}
.quick-link {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  text-align: center;
  padding: 10px 6px;
  border-radius: 14px;
  border: 1.5px solid rgba(77, 45, 18, .38);
  background: transparent;
  color: #4d2d12;
  font-weight: 800;
  font-size: 11px;
  letter-spacing: -.02em;
  text-decoration: none;
  white-space: nowrap;
  transition: background .15s ease;
}
.quick-link:active { background: rgba(77, 45, 18, .08); }
/* "Something new here" dot, pinned to the button's top-right corner. Sits outside
   the outline (negative offsets) so it reads as a badge on the button, not as part
   of the label — the same idiom as an app icon badge. */
.quick-badge {
  position: absolute;
  top: -8px;
  right: -7px;
  min-width: 21px;
  height: 21px;
  padding: 0 5px;
  border-radius: 999px;
  border: 2px solid var(--bg);
  background: #e5352b;
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  line-height: 17px;
  text-align: center;
  box-shadow: 0 2px 5px rgba(160, 24, 18, .35);
}
/* Расходящееся кольцо вокруг значка, чтобы «тут новое» замечали не вглядываясь.
   Ни одного фильтра: выше в этом файле записано, чем такое кончается на iOS —
   абсолютный элемент с фильтром и анимацией там просто пропадает с экрана.
   Здесь только transform и opacity, они безопасны. */
.quick-badge::after {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: 999px;
  border: 3px solid #ff4a3d;
  /* box-shadow, а не filter: сияние вокруг кольца, но без того, от чего
     абсолютные элементы пропадают на iOS. */
  box-shadow: 0 0 10px 2px rgba(255, 74, 61, .75);
  animation: quickBadgePulse 1.6s ease-out infinite;
  pointer-events: none;
}
@keyframes quickBadgePulse {
  0%   { transform: scale(.85); opacity: 1; }
  55%  { transform: scale(1.55); opacity: .45; }
  100% { transform: scale(2); opacity: 0; }
}
/* У кого анимации отключены в системе — значок просто крупнее, без пульсации. */
@media (prefers-reduced-motion: reduce) {
  .quick-badge::after { animation: none; opacity: 0; }
}

/* Square icon button at the end of the row. Fixed width so the three text links
   simply share what is left, and a 1:1 box so it reads as a square next to them. */
.quick-link--icon {
  flex: 0 0 auto;
  width: 38px;
  padding: 0;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.quick-link--icon svg {
  width: 19px;
  height: 19px;
  /* Outline drawing: the gear body is a stroked path, the hub a stroked circle. */
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ─── Settings page ──────────────────────────────────────────────────────── */
.settings-card { padding: 20px 18px; text-align: left; }
.settings-card h1 { margin: 0 0 4px; font-size: 24px; font-weight: 900; letter-spacing: -.03em; color: var(--text); }
.settings-empty { margin: 12px 0 0; color: var(--muted); font-size: 15px; }
.settings-empty a { color: #087c1e; font-weight: 700; }
.settings-field { display: block; margin-top: 16px; }
.settings-label { display: block; margin-bottom: 6px; font-size: 12px; font-weight: 700; color: #6b5636; }
.name-row { display: flex; align-items: center; gap: 10px; }
/* Pencil: opens editing. Square, same rounded outline as the card's other controls. */
.name-edit {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1.5px solid rgba(77, 45, 18, .22);
  border-radius: 14px;
  background: #fffdf9;
  color: #6b5636;
  cursor: pointer;
}
.name-edit svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.name-edit:active { background: #f6eedf; }
.name-edit[hidden] { display: none; }
.name-row input {
  flex: 1 1 auto;
  min-width: 0;
  box-sizing: border-box;
  height: 46px;
  padding: 0 14px;
  border: 1.5px solid rgba(77, 45, 18, .22);
  border-radius: 14px;
  background: #fffdf9;
  font: inherit;
  font-size: 16px; /* keeps iOS from zooming the page on focus */
  color: #2b1f16;
}
.name-row input:focus { outline: none; border-color: #119326; }
/* Locked state: reads as a value, not an empty box waiting for input. */
.name-row input:disabled {
  border-color: transparent;
  background: #f6eedf;
  color: #2b1f16;
  -webkit-text-fill-color: #2b1f16; /* iOS greys disabled text out otherwise */
  opacity: 1;
}
/* Read-only value row (phone): looks like the locked name, minus the control. */
.settings-value {
  margin: 0;
  height: 46px;
  display: flex;
  align-items: center;
  padding: 0 14px;
  border-radius: 14px;
  background: #f6eedf;
  font-size: 16px;
  color: #2b1f16;
  letter-spacing: .02em;
}
.settings-save {
  width: 100%;
  margin-top: 12px;
  border: 0;
  border-radius: 14px;
  padding: 13px;
  font: inherit;
  font-size: 15px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(180deg, #119326, #087c1e);
  cursor: pointer;
}
.settings-save:disabled { opacity: .55; }
.settings-msg { margin: 10px 0 0; font-size: 13px; font-weight: 700; color: #119326; }
.settings-msg.is-error { color: #b3261e; }
.settings-sep { margin: 20px 0 0; border: 0; border-top: 1px solid rgba(77, 45, 18, .12); }
.settings-exit {
  width: 100%;
  margin-top: 18px;
  border: 1.5px solid rgba(179, 38, 30, .35);
  border-radius: 14px;
  padding: 12px;
  font: inherit;
  font-size: 15px;
  font-weight: 800;
  color: #b3261e;
  background: transparent;
  cursor: pointer;
}
.settings-note { margin: 8px 0 0; font-size: 11px; color: var(--muted); text-align: center; line-height: 1.4; }

/* Placeholder pages (Новинки / Акции / Отзыв) */
/* Подстраницы — обычные документы без скрипта, а значит без fitCard(), который
   вписывает главную карту в экран. Поэтому ширина здесь резиновая: с жёсткими
   390 точками страница вылезала вбок на телефонах шириной 360. */
.stub-page {
  justify-content: flex-start;
  gap: 14px;
  width: min(var(--design-w), 100%);
  left: 0;
  margin: 0 auto;
}

/* В установленном приложении тело страницы прибито гвоздями (position: fixed,
   overflow: hidden) — так карта не резинится под пальцем. Но подстраницы могут
   быть длиннее экрана, и на узком телефоне их низ оказывался физически
   недостижим: кнопка есть, доскроллить до неё нельзя. Здесь замок снимаем. */
@media (display-mode: standalone) {
  .stub-body {
    position: static;
    height: 100%;          /* html уже 100% — тело само становится прокруткой */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}
.stub-back {
  align-self: flex-start;
  margin-top: 6px;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1.5px solid rgba(77, 45, 18, .38);
  background: transparent;
  color: #4d2d12;
  font-weight: 800;
  font-size: 15px;
  cursor: pointer;
}
.stub-card {
  margin-top: 18vh;
  text-align: center;
  padding: 30px 24px;
}
.stub-emoji { font-size: 46px; line-height: 1; }
.stub-card h1 { margin: 12px 0 6px; font-size: 24px; font-weight: 900; letter-spacing: -.03em; color: var(--text); }
.stub-card p { margin: 0; color: var(--muted); font-size: 15px; }

/* ─── Review page ────────────────────────────────────────────────────────── */
.review-card {
  margin-top: 3vh;
  padding: 0 22px 26px;
  text-align: center;
  overflow: visible; /* the cup leans out over the top edge */
}
/* The same cup as the card's hero, tilted — ties the page to the brand without
   another asset to download (it is already cached by then). */
.review-cup {
  margin-top: -28px;
  display: flex;
  justify-content: center;
}
.review-cup img {
  width: 74px;
  transform: rotate(-7deg);
  filter: drop-shadow(0 14px 16px rgba(41, 23, 8, .26));
}
.review-card h1 {
  margin: 6px 0 6px;
  font-size: 24px;
  font-weight: 900;
  letter-spacing: -.03em;
  color: var(--text);
}
.review-lead {
  margin: 0 auto 14px;
  max-width: 20em;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}
/* Fixed-size Yandex widget on a soft plate: keeps its own look, but sits on the
   card instead of floating on the page background. min-height reserves the space
   so nothing jumps when the frame loads (or never does). */
.review-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 56px;
  margin: 0 auto 14px;
  padding: 6px 10px;
  width: fit-content;
  border-radius: 16px;
  background: #fffdf8;
  border: 1px solid rgba(229, 212, 185, .9);
  box-shadow: 0 6px 14px rgba(83, 52, 18, .07);
}
.review-badge iframe { display: block; border: 0; }
.review-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 15px 20px;
  border-radius: 16px;
  color: #fff;
  background: linear-gradient(180deg, #14922b, #087c1e);
  box-shadow: 0 10px 20px rgba(0, 110, 29, .22);
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -.01em;
  text-decoration: none;
}
.review-btn:active { transform: translateY(1px); }
.review-btn-star { width: 20px; height: 20px; fill: #ffd54a; stroke: none; }
.review-note { margin: 10px 0 0; font-size: 11px; color: var(--muted); }

/* Разделитель между площадками: без него две одинаковые кнопки подряд читаются
   как «нажми обе», а это выбор — куда пойти. */
.review-or {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 4px 14px;
  color: var(--muted);
  font-size: 11px;
}
.review-or::before,
.review-or::after {
  content: '';
  flex: 1;
  height: 1px;
  background: rgba(160, 132, 96, .25);
}

/* Плашка Google. У Яндекса тут живой виджет, у Google такого не существует —
   поэтому логотип и звёзды нарисованы прямо здесь. Ничего не загружается: карта
   гостя должна открываться без сети, а чужой скрипт на этой странице ещё и
   видел бы данные гостя. */
.review-badge--google { gap: 10px; padding: 10px 14px; }
.review-g { width: 26px; height: 26px; flex: none; }
.review-g-text { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; }
.review-g-stars { color: #f0a500; font-size: 14px; letter-spacing: .5px; }
.review-g-label { color: var(--muted); font-size: 12px; font-weight: 700; }

/* Синий вместо зелёного: две кнопки подряд одного цвета сливаются, а так сразу
   видно, что это разные площадки. */
.review-btn--google {
  background: linear-gradient(180deg, #4285f4, #1a68d1);
  box-shadow: 0 10px 20px rgba(26, 104, 209, .22);
}

/* "Open in Chrome" popup — browsers without WebAPK install (Yandex/Firefox) */
.cm-overlay {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .5); padding: 24px;
}
.cm-box {
  position: relative; width: min(340px, 100%);
  background: #fff; border-radius: 20px; padding: 26px 20px 20px;
  text-align: center; box-shadow: 0 24px 64px rgba(0, 0, 0, .3);
  display: flex; flex-direction: column; gap: 12px;
}
.cm-title { margin: 0; font-size: 18px; font-weight: 800; color: #2a1c0e; }
.cm-sub { margin: 0; font-size: 14px; color: #6b5b45; line-height: 1.4; }
.cm-btn {
  display: block; text-decoration: none;
  min-height: 52px; line-height: 52px; border-radius: 14px;
  background: #119326; color: #fff; font-size: 16px; font-weight: 800;
}
.cm-link { background: none; border: 0; color: #8a6a2a; font-size: 13px; font-weight: 600; cursor: pointer; padding: 4px; }
.cm-close { position: absolute; top: 6px; right: 10px; background: none; border: 0; font-size: 26px; line-height: 1; color: #9a8b76; cursor: pointer; }
