:root {
  --bg-color: #0b0f19;
  --card-bg: linear-gradient(145deg, #182032 0%, #111726 100%);
  --card-border: rgba(255, 255, 255, 0.08);
  --accent-gold: #f59e0b;
  --accent-gold-glow: rgba(245, 158, 11, 0.25);
  --accent-amber: #d97706;
  --ink-red: #e11d48;
  --ink-red-dark: #be123c;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --slot-bg: rgba(255, 255, 255, 0.04);
  --slot-border: rgba(255, 255, 255, 0.12);
  --radius-card: 24px;
  --radius-slot: 50%;
  --font-sans: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  --font-display: 'Space Grotesk', system-ui, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-color);
  color: var(--text-main);
  font-family: var(--font-sans);
  touch-action: none; /* Crucial: prevent browser gesture zoom/pan so multi-touch goes to app */
}

/* Canvas layers */
#touchCanvas, #confettiCanvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 50;
}
#confettiCanvas {
  z-index: 100;
}

/* App Container */
.app-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 16px 20px 24px;
  position: relative;
  z-index: 10;
  justify-content: space-between;
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.brand-logo-wrap {
  display: flex;
  align-items: center;
}

.meatworld-logo-header {
  height: 42px;
  width: auto;
  object-fit: contain;
  filter: drop-shadow(0 2px 8px rgba(200, 16, 46, 0.35));
}

.branch-selector-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-main);
  margin-top: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.branch-selector-pill:hover {
  background: rgba(200, 16, 46, 0.2);
  border-color: var(--accent-gold);
}

.branch-pin {
  font-size: 11px;
}

.pill-arrow {
  font-size: 9px;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-main);
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  transform: translateY(-1px);
}

/* Main Card */
.card-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 16px;
  position: relative;
}

.loyalty-card {
  position: relative;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-card);
  padding: 24px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4), 0 0 40px var(--accent-gold-glow);
  overflow: hidden;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.loyalty-card.active-touch {
  transform: scale(0.99);
  box-shadow: 0 15px 30px rgba(0, 0, 0, 0.5), 0 0 60px rgba(225, 29, 72, 0.35);
}

.card-grain {
  position: absolute;
  inset: 0;
  opacity: 0.03;
  pointer-events: none;
  background-image: radial-gradient(#fff 1px, transparent 1px);
  background-size: 8px 8px;
}

.card-glow {
  position: absolute;
  top: -50px;
  right: -50px;
  width: 160px;
  height: 160px;
  background: radial-gradient(circle, var(--accent-gold-glow) 0%, transparent 70%);
  pointer-events: none;
}

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 22px;
}

.cafe-tag {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--accent-gold);
}

.cafe-name {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 700;
  color: #fff;
  margin: 2px 0 4px;
}

.card-subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

.card-stamp-badge {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 8px 12px;
  border-radius: 14px;
  display: flex;
  align-items: baseline;
  gap: 2px;
}

.stamp-count-num {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  color: var(--accent-gold);
}

.stamp-count-max {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 600;
}

/* Stamp Grid */
.stamp-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin: 10px 0 24px;
}

.stamp-slot {
  aspect-ratio: 1;
  background: var(--slot-bg);
  border: 2px dashed var(--slot-border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.stamp-slot.free-reward-slot {
  border-color: rgba(245, 158, 11, 0.4);
  background: rgba(245, 158, 11, 0.05);
}

.slot-number {
  font-size: 13px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.25);
  transition: opacity 0.2s;
}

.stamp-slot.stamped .slot-number {
  opacity: 0;
}

/* The Stamp Imprint */
.stamp-imprint {
  position: absolute;
  inset: -2px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(225, 29, 72, 0.15) 0%, transparent 80%);
  opacity: 0;
  transform: scale(1.6) rotate(-20deg);
  transition: all 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.stamp-slot.stamped .stamp-imprint {
  opacity: 1;
  transform: scale(1) rotate(var(--stamp-rot, 0deg));
}

.ink-svg {
  width: 90%;
  height: 90%;
  color: var(--ink-red);
  filter: drop-shadow(0 2px 4px rgba(225, 29, 72, 0.4));
}

/* Card Footer */
.card-footer {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 16px;
}

.reward-info {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  margin-bottom: 8px;
}

.reward-label {
  color: var(--text-muted);
}

.reward-info strong {
  color: var(--text-main);
  font-weight: 600;
}

.progress-bar-container {
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-amber), var(--accent-gold));
  border-radius: 999px;
  transition: width 0.4s ease;
}

/* Hint Zone */
.stamp-zone-hint {
  margin-top: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.4);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.touch-ring {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1.5px solid var(--accent-gold);
  animation: ringAnim 2s infinite;
}

@keyframes ringAnim {
  0% { transform: scale(0.8); opacity: 0.4; }
  50% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(0.8); opacity: 0.4; }
}

/* Reward Banner */
.reward-banner {
  background: linear-gradient(135deg, #059669 0%, #047857 100%);
  border-radius: 18px;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 10px 25px rgba(5, 150, 105, 0.4);
  animation: slideUp 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.reward-banner.hidden {
  display: none;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.reward-icon {
  font-size: 28px;
}

.reward-text h3 {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
}

.reward-text p {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.85);
}

/* Simulator Dock */
.simulation-dock {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 18px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dock-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.dock-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-main);
}

.dock-hint {
  font-size: 11px;
  color: var(--text-muted);
}

.dock-buttons {
  display: flex;
  gap: 10px;
}

.btn-dock {
  flex: 1;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-gold), var(--accent-amber));
  color: #111;
  font-weight: 700;
  box-shadow: 0 4px 15px rgba(245, 158, 11, 0.3);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(245, 158, 11, 0.4);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.14);
}

.live-touch-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
  color: var(--text-muted);
}

.status-indicator {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #3b82f6;
  flex-shrink: 0;
}

.status-indicator.touching {
  background: #10b981;
  box-shadow: 0 0 8px #10b981;
}

.status-indicator.stamped {
  background: var(--ink-red);
  box-shadow: 0 0 10px var(--ink-red);
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(10px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.hidden {
  display: none;
}

.modal-content {
  background: #151b28;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  width: 100%;
  max-width: 440px;
  padding: 24px;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
  animation: modalIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.modal-header h2 {
  font-size: 18px;
  font-weight: 700;
}

.close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
}

.modal-desc {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 16px;
}

.custom-select {
  width: 100%;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  color: var(--text-main);
  font-family: inherit;
  font-size: 13px;
  margin-bottom: 16px;
}

.calibration-box {
  background: rgba(255, 255, 255, 0.03);
  border: 2px dashed rgba(245, 158, 11, 0.4);
  border-radius: 14px;
  padding: 24px 16px;
  text-align: center;
  margin-bottom: 16px;
  cursor: crosshair;
  transition: all 0.2s;
}

.calibration-box.active-capturing {
  border-color: #10b981;
  background: rgba(16, 185, 129, 0.06);
}

.cal-icon {
  font-size: 32px;
  margin-bottom: 6px;
}

.cal-instructions {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
}

.cal-instructions strong {
  font-size: 14px;
  color: var(--text-main);
}

.cal-feedback {
  margin-top: 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-gold);
}

.cal-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.metric-card {
  background: rgba(255, 255, 255, 0.04);
  border-radius: 10px;
  padding: 10px 8px;
  text-align: center;
}

.metric-label {
  display: block;
  font-size: 10.5px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.metric-val {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
}

.slider-group {
  margin-bottom: 20px;
}

.slider-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 8px;
}

.slider-group input[type="range"] {
  width: 100%;
  accent-color: var(--accent-gold);
}

.slider-hints {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
}

.modal-actions {
  display: flex;
  gap: 10px;
}

.modal-actions button {
  flex: 1;
}

/* QR Modal Specific */
.text-center {
  text-align: center;
}

.url-switcher {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 12px;
}

.url-tab-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.url-tab-btn.active {
  background: rgba(245, 158, 11, 0.15);
  border-color: var(--accent-gold);
  color: var(--accent-gold);
}

.network-badge {
  background: rgba(255, 255, 255, 0.06);
  padding: 10px 14px;
  border-radius: 12px;
  display: inline-block;
  margin-bottom: 16px;
}

.network-badge code {
  font-size: 14px;
  color: var(--accent-gold);
  font-weight: 700;
}

.qr-container {
  display: flex;
  justify-content: center;
  margin: 12px 0 16px;
}

#qrCanvas {
  background: #fff;
  padding: 12px;
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.qr-hint {
  font-size: 12px;
  color: var(--text-muted);
}

/* 3D Visual Physical Stamper Pressing Down Animation */
.physical-stamp-fx {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(2.5);
  opacity: 0;
  pointer-events: none;
  z-index: 150;
  transition: transform 0.15s cubic-bezier(0.12, 0.8, 0.32, 1), opacity 0.15s ease;
}

.physical-stamp-fx.stamping {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.stamp-face-icon {
  width: 120px;
  height: 120px;
  color: var(--ink-red);
  filter: drop-shadow(0 15px 30px rgba(225, 29, 72, 0.5));
}

/* Meat World Stores Modal */
.modal-wide {
  max-width: 500px;
}

.stores-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 380px;
  overflow-y: auto;
  padding-right: 4px;
}

.store-card {
  background: rgba(255, 255, 255, 0.04);
  border: 1.5px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.25s ease;
}

.store-card:hover {
  border-color: rgba(200, 16, 46, 0.5);
  transform: translateY(-2px);
}

.store-card.active {
  border-color: #c8102e;
  background: rgba(200, 16, 46, 0.08);
  box-shadow: 0 4px 15px rgba(200, 16, 46, 0.25);
}

.store-img-wrap {
  position: relative;
  width: 100%;
  height: 120px;
  overflow: hidden;
}

.store-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.store-card:hover .store-img {
  transform: scale(1.04);
}

.store-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: #c8102e;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 6px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}

.store-card-info {
  padding: 10px 14px 12px;
}

.store-card-info h3 {
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 2px;
}

.store-card-info p {
  font-size: 11.5px;
  color: var(--text-muted);
}

