/* ==========================================================================
   Taste Match - Mobile-First Restaurant Card Game Styles
   Theme: Warm Artisan Bistro & Gourmet Kitchen + Antigravity Physics
   ========================================================================== */

:root {
  --primary: #be123c;         /* Crimson Bistro */
  --primary-dark: #881337;    /* Deep Wine */
  --primary-light: #fb7185;   /* Soft Coral */
  --accent: #f59e0b;          /* Golden Crust */
  --accent-glow: #fbbf24;     /* Warm Gold */
  --bg-creme: #fdfbf7;        /* Warm Ivory Tablecloth */
  --card-back-bg: #1e293b;    /* Slate Kitchen Chalkboard */
  --card-face-bg: #ffffff;    /* Clean Porcelain Plate */
  --text-dark: #1c1917;       /* Rich Charcoal */
  --text-muted: #78716c;      /* Muted Linen */
  --border-light: #e7e5e4;    /* Light Ceramic Border */
  --success: #16a34a;         /* Fresh Herb Green */
  --shadow-sm: 0 2px 4px rgba(0,0,0,0.06);
  --shadow-md: 0 6px 16px rgba(0,0,0,0.1);
  --shadow-lg: 0 12px 24px -6px rgba(190, 18, 60, 0.25);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
}

/* Reset & Mobile Optimization */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background-color: var(--bg-creme);
  color: var(--text-dark);
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  touch-action: manipulation;
}

/* Container constrained for mobile-first play */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 10px 14px;
  justify-content: space-between;
  position: relative;
}

/* ==========================================================================
   Header & Branding
   ========================================================================== */
.app-header {
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 10;
}

.branding-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 4px;
}

.logo-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  box-shadow: 0 4px 10px rgba(190, 18, 60, 0.3);
}

.logo-icon svg {
  width: 20px;
  height: 20px;
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-name {
  font-family: 'Playfair Display', Georgia, serif;
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: 0.05em;
  color: var(--primary-dark);
  line-height: 1.1;
}

.brand-sub {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
}

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

.tutorial-btn {
  background: #ffffff;
  border: 1px solid var(--border-light);
  height: 38px;
  padding: 0 12px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--primary-dark);
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.tutorial-btn:active {
  transform: scale(0.94);
  background: #fff1f2;
  border-color: #fecdd3;
}

.tutorial-badge {
  width: 18px;
  height: 18px;
  background: #fff1f2;
  color: var(--primary);
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 800;
}

.icon-btn {
  background: #fff;
  border: 1px solid var(--border-light);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dark);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, background 0.15s ease;
}

.icon-btn:active {
  transform: scale(0.92);
  background: #f5f5f4;
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

.hidden {
  display: none !important;
}

/* ==========================================================================
   Live HUD (Moves Left, Score, Restart)
   ========================================================================== */
.hud-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #ffffff;
  border-radius: var(--radius-md);
  padding: 8px 16px;
  box-shadow: var(--shadow-md);
  border: 1px solid rgba(190, 18, 60, 0.08);
}

.hud-stat {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.hud-label {
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.hud-value {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--primary-dark);
  line-height: 1.1;
}

.hud-value.danger {
  color: #dc2626;
  animation: pulseCritical 0.8s infinite alternate;
}

.hud-divider {
  width: 1px;
  height: 28px;
  background-color: var(--border-light);
}

.hud-action-btn {
  background: #fff1f2;
  border: 1px solid rgba(190, 18, 60, 0.2);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease;
}

.hud-action-btn:active {
  transform: rotate(-45deg) scale(0.92);
  background: #ffe4e6;
}

.hud-action-btn svg {
  width: 18px;
  height: 18px;
}

/* ==========================================================================
   Game Main & 3x4 Grid
   ========================================================================== */
.game-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 0;
  position: relative;
}

.cards-grid {
  width: 100%;
  height: 100%;
  max-height: 68vh;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 10px;
  perspective: 1000px;
}

/* 3D Card Structure */
.card {
  position: relative;
  width: 100%;
  height: 100%;
  cursor: pointer;
  perspective: 800px;
  touch-action: manipulation;
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: var(--radius-md);
  transform-style: preserve-3d;
  transition: transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
}

.card.is-flipped .card-inner,
.card.is-matched .card-inner {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-md);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* Card Back (Face Down) */
.card-back {
  background: linear-gradient(145deg, #1e293b, #0f172a);
  border: 2px solid #334155;
  color: var(--accent);
}

.card-back-pattern {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.card-back-icon {
  width: 28px;
  height: 28px;
  opacity: 0.85;
}

.card-back-text {
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  color: #94a3b8;
  text-transform: uppercase;
}

/* Card Front (Face Up - Restaurant Dish) */
.card-front {
  background: var(--card-face-bg);
  transform: rotateY(180deg);
  border: 2px solid #fecdd3;
  padding: 6px;
  text-align: center;
}

.dish-icon-wrapper {
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #fff1f2;
  margin-bottom: 4px;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.04);
}

.dish-icon-wrapper svg {
  width: 34px;
  height: 34px;
}

.dish-title {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-dark);
  text-transform: capitalize;
  white-space: nowrap;
}

/* ==========================================================================
   Animations & Celebratory Effects
   ========================================================================== */
.card.is-matched .card-inner {
  animation: matchCelebration 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.card.is-matched .card-front {
  border-color: #86efac;
  background: #f0fdf4;
}

.card.is-matched .dish-icon-wrapper {
  background: #dcfce7;
}

@keyframes matchCelebration {
  0% { transform: rotateY(180deg) scale(1); }
  40% { transform: rotateY(180deg) scale(1.12); box-shadow: 0 0 20px rgba(34, 197, 94, 0.5); }
  100% { transform: rotateY(180deg) scale(1); }
}

.card.shake .card-inner {
  animation: mismatchShake 0.4s ease;
}

@keyframes mismatchShake {
  0%, 100% { transform: rotateY(180deg) translateX(0); }
  20%, 60% { transform: rotateY(180deg) translateX(-6px); }
  40%, 80% { transform: rotateY(180deg) translateX(6px); }
}

@keyframes pulseCritical {
  from { opacity: 1; transform: scale(1); }
  to { opacity: 0.6; transform: scale(1.08); }
}

/* ==========================================================================
   Antigravity Physics Active Styles
   ========================================================================== */
.physics-body {
  position: fixed !important;
  margin: 0 !important;
  transform-origin: center center !important;
  will-change: transform;
  z-index: 50;
  pointer-events: auto;
  cursor: grab;
  touch-action: none;
}

.physics-body:active {
  cursor: grabbing;
}

.physics-body .card-inner {
  transition: none !important;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2) !important;
}

/* ==========================================================================
   Footer
   ========================================================================== */
.game-footer {
  text-align: center;
  padding: 4px 8px;
  z-index: 10;
}

.table-cue {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
}

.copyright-text {
  font-size: 0.66rem;
  color: #a8a29e;
  margin-top: 3px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.game-footer-links {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin: 6px 0 2px 0;
  font-size: 0.72rem;
  position: relative;
  z-index: 200;
  pointer-events: auto;
}

.game-footer-links a {
  color: var(--text-muted);
  text-decoration: none;
  padding: 4px 6px;
  font-weight: 600;
  cursor: pointer;
  pointer-events: auto;
  transition: color 0.15s ease;
}

.game-footer-links a:hover {
  color: var(--primary);
  text-decoration: underline;
}

/* Tutorial Modal Steps */
.tutorial-steps {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
  width: 100%;
  margin-top: 6px;
  max-height: 48vh;
  overflow-y: auto;
}

.tutorial-step {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: #fdfbf7;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 8px 10px;
}

.step-badge {
  width: 22px;
  height: 22px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #ffffff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 800;
  flex-shrink: 0;
  margin-top: 2px;
}

.step-info strong {
  display: block;
  font-size: 0.8rem;
  color: var(--text-dark);
  margin-bottom: 2px;
}

.step-info p {
  font-size: 0.7rem;
  color: var(--text-muted);
  line-height: 1.35;
}

/* ==========================================================================
   Modals & Voucher Ticket (Floating Cleanly on Top)
   ========================================================================== */
.game-modal {
  border: none;
  border-radius: var(--radius-lg);
  padding: 0;
  background: transparent;
  max-width: 92vw;
  width: 370px;
  margin: auto;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.6);
  z-index: 10000 !important;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: auto !important;
}

.game-modal::backdrop {
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fadeInBackdrop 0.25s ease-out;
}

.modal-card {
  background: #ffffff;
  padding: 20px 18px;
  border-radius: var(--radius-lg);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  overflow: hidden;
  animation: modalScaleUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 20px 40px rgba(0,0,0,0.3);
}

.confetti-burst {
  font-size: 2.2rem;
  margin-bottom: 4px;
  animation: bounceBurst 0.6s infinite alternate ease-in-out;
}

.modal-icon-badge {
  font-size: 2.4rem;
  margin-bottom: 4px;
}

.modal-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--primary-dark);
  margin-bottom: 4px;
}

.modal-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.35;
  margin-bottom: 12px;
}

/* Voucher Ticket Mockup */
.voucher-ticket {
  position: relative;
  background: linear-gradient(135deg, #fff7ed, #ffedd5);
  border: 2px dashed #f97316;
  border-radius: var(--radius-md);
  padding: 12px 14px;
  width: 100%;
  margin-bottom: 12px;
}

.ticket-cutout {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  background: #ffffff;
  border-radius: 50%;
}

.ticket-cutout.left { left: -9px; }
.ticket-cutout.right { right: -9px; }

.voucher-header {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 6px;
}

.voucher-badge {
  font-size: 0.65rem;
  font-weight: 800;
  color: #ea580c;
  letter-spacing: 0.1em;
}

.voucher-discount {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.1rem;
  font-weight: 800;
  color: #c2410c;
}

.voucher-code-box {
  background: #ffffff;
  border-radius: var(--radius-sm);
  padding: 5px 12px;
  display: inline-flex;
  gap: 8px;
  align-items: center;
  border: 1px solid #fed7aa;
  margin-bottom: 10px;
}

.code-label {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 700;
}

.code-value {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--primary-dark);
  letter-spacing: 0.1em;
  font-family: monospace;
}

/* Verification QR Code Wrap */
.voucher-qr-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin: 6px 0 8px 0;
}

.voucher-qrcode {
  width: 100px;
  height: 100px;
  background: #ffffff;
  padding: 6px;
  border-radius: 8px;
  border: 1px solid #fed7aa;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}

.voucher-qrcode img, .voucher-qrcode canvas {
  width: 88px !important;
  height: 88px !important;
  display: block;
}

.qr-label {
  font-size: 0.62rem;
  font-weight: 700;
  color: #c2410c;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Firestore Sync Status Pill */
.voucher-sync-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.64rem;
  color: #15803d;
  background: rgba(34, 197, 94, 0.12);
  padding: 3px 8px;
  border-radius: 12px;
  margin-bottom: 6px;
  font-weight: 600;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: #16a34a;
  animation: pulseDot 1.4s infinite;
}

@keyframes pulseDot {
  0% { transform: scale(0.9); opacity: 0.7; }
  50% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.7; }
}

.voucher-terms {
  font-size: 0.62rem;
  color: #9a3412;
  font-style: italic;
}

/* Modal Stats Pill */
.modal-stats {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

.stat-pill {
  font-size: 0.75rem;
  background: #f5f5f4;
  padding: 4px 10px;
  border-radius: 20px;
  color: var(--text-dark);
}

.antigravity-hint {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 12px;
  animation: pulseGlow 1.5s infinite alternate;
}

@keyframes pulseGlow {
  from { opacity: 0.8; }
  to { opacity: 1; transform: scale(1.02); }
}

/* Receipt CTA for Lose Screen */
.receipt-callout {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  margin-bottom: 16px;
  width: 100%;
}

.receipt-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: #e2e8f0;
  color: #475569;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.receipt-icon svg {
  width: 20px;
  height: 20px;
}

.receipt-text strong {
  display: block;
  font-size: 0.82rem;
  color: var(--text-dark);
}

.receipt-text span {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* Buttons */
.modal-actions {
  display: flex;
  gap: 10px;
  width: 100%;
}

.btn {
  flex: 1;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  border: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.btn:active {
  transform: scale(0.96);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(190, 18, 60, 0.3);
}

.btn-secondary {
  background: #f5f5f4;
  color: var(--text-dark);
}

/* Floating Confetti Particle Overlay */
.particle-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 9999;
}

.confetti-particle {
  position: absolute;
  width: 8px;
  height: 14px;
  opacity: 0.9;
  animation: confettiFall 1.8s ease-out forwards;
}

@keyframes confettiFall {
  0% { transform: translateY(-20px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

@keyframes modalScaleUp {
  from { transform: translate(-50%, -50%) scale(0.85); opacity: 0; }
  to { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

@keyframes fadeInBackdrop {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes bounceBurst {
  from { transform: translateY(0) scale(1); }
  to { transform: translateY(-6px) scale(1.08); }
}

/* ==========================================================================
   Responsive Adaptations for Small & Tall Phones
   ========================================================================== */
@media (max-height: 640px) {
  .app-container {
    padding: 4px 8px;
  }
  .branding-bar {
    padding: 0;
  }
  .hud-card {
    padding: 4px 10px;
  }
  .dish-icon-wrapper {
    width: 38px;
    height: 38px;
    margin-bottom: 2px;
  }
  .dish-icon-wrapper svg {
    width: 24px;
    height: 24px;
  }
  .dish-title {
    font-size: 0.62rem;
  }
  .cards-grid {
    gap: 6px;
  }
  .voucher-qrcode {
    width: 80px;
    height: 80px;
  }
  .voucher-qrcode img, .voucher-qrcode canvas {
    width: 68px !important;
    height: 68px !important;
  }
}
