/* --- Base Reset & Typography --- */
:root {
  /* System Theme Defaults (Dark by default if unset) */
  --bg-dark: #0a0a0f;
  --bg-card: #161623;
  --bg-glass: rgba(255, 255, 255, 0.04);
  --accent-primary: #f59e0b;
  /* Amber */
  --text-main: #f0f0f5;
  --text-vendor: #ffffff;
  --text-muted: rgba(240, 240, 245, 0.5);
  --radius-lg: 24px;

  /* Dynamic Category Colors - initialized to neutral */
  --cat-overlay: rgba(255, 255, 255, 0);
}

/* Light Mode System Preference */
@media (prefers-color-scheme: light) {
  :root {
    --bg-dark: #f0f2f5;
    --bg-card: #ffffff;
    --bg-glass: rgba(0, 0, 0, 0.05);
    --accent-primary: #d97706;
    /* Darker Amber */
    --text-main: #1e293b;
    --text-vendor: #0f172a;
    --text-muted: rgba(15, 23, 42, 0.5);
  }
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg-dark);
  color: var(--text-main);
  overflow: hidden;
  height: 100vh;
  transition: background 0.3s ease;
  touch-action: none;
  /* Crucial for preventing pointercancel on mobile swipes */
}

.screen {
  display: none;
  height: 100%;
  width: 100%;
  flex-direction: column;
}

.screen.active {
  display: flex;
  animation: fade 0.3s;
}

@keyframes fade {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

/* --- Loading Overlay --- */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.4s ease;
}

.loading-overlay.active {
  opacity: 1;
  visibility: visible;
}

.loader-content {
  text-align: center;
  padding: 24px;
}

.logo-text {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 48px;
  font-weight: 700;
  margin-bottom: 24px;
}

.logo-accent {
  color: var(--accent-primary);
}

#loading-status {
  color: var(--text-muted);
  margin-bottom: 24px;
  font-size: 16px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(139, 92, 246, 0.1);
  /* mapped roughly to accent */
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto;
}

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

.btn-primary {
  background: var(--text-main);
  border: none;
  padding: 16px 32px;
  border-radius: 30px;
  color: var(--bg-dark);
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  margin-top: 24px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.btn-primary:active {
  transform: scale(0.98);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.onboarding-links {
  margin-top: 24px;
  display: flex;
  gap: 16px;
  justify-content: center;
}

.btn-secondary-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: 20px;
  background: var(--bg-glass);
  transition: color 0.2s ease, background 0.2s ease;
}

.btn-secondary-link:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.1);
}

/* --- Category Background Patterns & Theming --- */
.split-flap-container {
  /* Default fallbacks if no cat class */
  --bg-card-top: var(--bg-card);
  --bg-card-bottom: var(--bg-card);
  --text-active-vendor: var(--text-vendor);
  --text-active-user: var(--text-main);
  --text-active-muted: var(--text-muted);
}

.bg-pattern {
  position: absolute;
  inset: 0;
  opacity: 0.15;
  /* Increased for gradient blend */
  pointer-events: none;
  background-size: 100px 100px;
}

/* Category Specific Vibrant Gradients */
.split-flap-container.dining {
  --bg-card-top: linear-gradient(135deg, #ff7e5f, #feb47b);
  --bg-card-bottom: linear-gradient(135deg, #feb47b, #f953c6);
  --text-active-vendor: #ffffff;
  --text-active-user: #ffffff;
  --text-active-muted: rgba(255, 255, 255, 0.8);
}

.bg-pattern.dining {
  background-image: url('data:image/svg+xml;utf8,<svg width="40" height="40" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2" xmlns="http://www.w3.org/2000/svg"><path d="M12 2v20M8 2v8a4 4 0 008 0V2"/></svg>');
}

.split-flap-container.shopping {
  --bg-card-top: linear-gradient(135deg, #FFB75E, #ED8F03);
  --bg-card-bottom: linear-gradient(135deg, #ED8F03, #FFB75E);
  --text-active-vendor: #ffffff;
  --text-active-user: #ffffff;
  --text-active-muted: rgba(255, 255, 255, 0.8);
}

.bg-pattern.shopping {
  background-image: url('data:image/svg+xml;utf8,<svg width="40" height="40" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2" xmlns="http://www.w3.org/2000/svg"><path d="M6 2L3 6v14a2 2 0 002 2h14a2 2 0 002-2V6l-3-4z"/><path d="M3 6h18M16 10a4 4 0 01-8 0"/></svg>');
}

.split-flap-container.transport {
  --bg-card-top: linear-gradient(135deg, #001510, #00bf8f);
  --bg-card-bottom: linear-gradient(135deg, #00bf8f, #001510);
  --text-active-vendor: #ffffff;
  --text-active-user: #ffffff;
  --text-active-muted: rgba(255, 255, 255, 0.8);
}

.bg-pattern.transport {
  background-image: url('data:image/svg+xml;utf8,<svg width="40" height="40" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2" xmlns="http://www.w3.org/2000/svg"><rect x="3" y="10" width="18" height="10" rx="2"/><path d="M5 10l2-6h10l2 6M8 15h.01M16 15h.01"/></svg>');
}

.split-flap-container.emergency {
  --bg-card-top: linear-gradient(135deg, #eb3349, #f45c43);
  --bg-card-bottom: linear-gradient(135deg, #f45c43, #eb3349);
  --text-active-vendor: #ffffff;
  --text-active-user: #ffffff;
  --text-active-muted: rgba(255, 255, 255, 0.8);
}

.bg-pattern.emergency {
  background-image: url('data:image/svg+xml;utf8,<svg width="40" height="40" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2" xmlns="http://www.w3.org/2000/svg"><path d="M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0zM12 9v4M12 17h.01"/></svg>');
}

/* --- SPLIT FLAP UI (The Core Requirement) --- */
.card-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0;
  position: relative;
  height: 100vh;
}

.split-flap-container {
  width: 100vw;
  max-width: none;
  height: 100vh;
  position: relative;
  display: flex;
  flex-direction: column;
  perspective: 1200px;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
}

.flap {
  width: 100%;
  height: 50%;
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.top-flap {
  border-radius: 0;
  transform: rotate(180deg);
  align-items: center;
  justify-content: center;
  border-bottom: 2px solid rgba(0, 0, 0, 0.15);
  background: var(--bg-card-top);
}

.bottom-flap {
  border-radius: 0;
  align-items: center;
  justify-content: center;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  background: var(--bg-card-bottom);
}

.flap-hinge {
  position: absolute;
  top: 50%;
  left: 0;
  width: 100%;
  height: 2px;
  background: rgba(0, 0, 0, 0.4);
  margin-top: -1px;
  z-index: 9;
  box-shadow: 0 1px 1px rgba(255, 255, 255, 0.2);
}

/* Typography on Flaps */
.phrase-vendor {
  font-family: 'Space Grotesk', sans-serif;
  font-size: clamp(32px, 8vw, 64px);
  font-weight: 800;
  text-align: center;
  color: var(--text-active-vendor);
  line-height: 1.1;
  text-transform: uppercase;
  z-index: 2;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.phrase-user {
  font-size: clamp(24px, 6vw, 36px);
  font-weight: 600;
  text-align: center;
  color: var(--text-active-user);
  line-height: 1.3;
  margin-bottom: 8px;
  z-index: 2;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.card-counter {
  font-family: 'Space Grotesk', sans-serif;
  color: var(--text-muted);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 2px;
  background: var(--bg-glass);
  padding: 4px 16px;
  border-radius: 20px;
  z-index: 2;
}

/* Horizontal Swipe Hint for Languages */
.lang-switcher {
  position: absolute;
  bottom: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--text-active-muted);
  opacity: 0.8;
}

.flag-indicator-inline {
  font-size: 32px;
  background: rgba(0, 0, 0, 0.3);
  padding: 6px 12px;
  border-radius: 16px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
}

.left-arrow {
  animation: bounceLeft 1.5s infinite ease-in-out;
}

.right-arrow {
  animation: bounceRight 1.5s infinite ease-in-out;
}

@keyframes bounceLeft {

  0%,
  100% {
    transform: translateX(0);
  }

  50% {
    transform: translateX(-4px);
  }
}

@keyframes bounceRight {

  0%,
  100% {
    transform: translateX(0);
  }

  50% {
    transform: translateX(4px);
  }
}

/* 3D Flip Anim - Realistic Book/Flap Fold */
.split-flap-container {
  perspective: 2500px;
  transform-style: preserve-3d;
}

.flap {
  transform-style: preserve-3d;
  backface-visibility: hidden;
  position: relative;
}

/* Shadow Layer - Refined for depth */
.flap::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.8) 100%);
  opacity: 0;
  pointer-events: none;
  z-index: 20;
}

/* NEXT Animation: Bottom folds up to the top */
.flip-animate-next .bottom-flap {
  animation: bookFlipUp 0.6s cubic-bezier(0.645, 0.045, 0.355, 1) forwards;
  transform-origin: top;
  z-index: 100;
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.3);
}

.flip-animate-next .bottom-flap::after {
  animation: shadowFadeIn 0.6s ease forwards;
}

/* PREV Animation: Top folds down to the bottom */
.flip-animate-prev .top-flap {
  animation: bookFlipDown 0.6s cubic-bezier(0.645, 0.045, 0.355, 1) forwards;
  transform-origin: bottom;
  z-index: 100;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.flip-animate-prev .top-flap::after {
  animation: shadowFadeIn 0.6s ease forwards;
}

@keyframes bookFlipUp {
  0% {
    transform: rotateX(0deg) translateY(0);
  }

  50% {
    transform: rotateX(-90deg) translateY(-10px) scale(1.05);
  }

  50.1% {
    transform: rotateX(-90deg);
    opacity: 0;
  }

  100% {
    transform: rotateX(0deg);
    opacity: 0;
  }
}

@keyframes bookFlipDown {
  0% {
    transform: rotate(180deg) rotateX(0deg) translateY(0);
  }

  50% {
    transform: rotate(180deg) rotateX(90deg) translateY(10px) scale(1.05);
  }

  50.1% {
    transform: rotate(180deg) rotateX(90deg);
    opacity: 0;
  }

  100% {
    transform: rotate(180deg) rotateX(0deg);
    opacity: 0;
  }
}

@keyframes shadowFadeIn {
  0% {
    opacity: 0;
  }

  45% {
    opacity: 0.9;
  }

  50% {
    opacity: 1;
  }

  100% {
    opacity: 0;
  }
}

/* Give the static halves some subtle depth shadow when the other half is flipping */
.flip-animate-next .top-flap::after {
  animation: staticShadow 0.6s ease forwards;
}

.flip-animate-prev .bottom-flap::after {
  animation: staticShadow 0.6s ease forwards;
}

@keyframes staticShadow {
  0% {
    opacity: 0;
  }

  50% {
    opacity: 0.3;
  }

  100% {
    opacity: 0;
  }
}

/* --- END SPLIT FLAP UI --- */


/* --- END SPLIT FLAP UI --- */

/* --- END SPLIT FLAP UI --- */

/* --- Onboarding Screens Additions --- */
.onboarding-header {
  text-align: center;
  padding: 40px 24px 20px;
}

.subtitle-hint {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 8px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.tinder-deck {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 20px;
}

.tinder-card {
  position: absolute;
  width: 280px;
  height: 400px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transform-origin: 50% 100%;
  will-change: transform;
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.tinder-card:active {
  cursor: grabbing;
}

.card-flag {
  font-size: 100px;
  margin-bottom: 24px;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.2));
}

.card-country-name {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-main);
  text-align: center;
}

.card-badge {
  position: absolute;
  top: 20px;
  padding: 8px 16px;
  border-radius: 20px;
  font-weight: 800;
  font-size: 24px;
  text-transform: uppercase;
  border: 4px solid;
  opacity: 0;
  transform: scale(0.8);
  pointer-events: none;
}

.badge-nope {
  right: 20px;
  color: #ef4444;
  border-color: #ef4444;
}

.badge-yep {
  left: 20px;
  color: #10b981;
  border-color: #10b981;
}

/* Location Persuasion Screen */
.persuasion-content {
  text-align: center;
  padding: 20px 24px;
  max-width: 500px;
  margin: auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  height: 100%;
}

.title-bold {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 32px;
  font-weight: 800;
  margin-bottom: 16px;
  background: linear-gradient(135deg, var(--text-main), var(--text-muted));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.body-text {
  font-size: 16px;
  line-height: 1.6;
  color: var(--text-muted);
  margin-bottom: 32px;
}

.benefit-icons {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 40px;
}

.emoji-benefit {
  background: var(--bg-card);
  padding: 16px;
  border-radius: 16px;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Flags on Main Cards */
.flag-indicator {
  position: absolute;
  font-size: 32px;
  z-index: 10;
  background: rgba(0, 0, 0, 0.3);
  padding: 6px 10px;
  border-radius: 16px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

/* Vendor views the top-flap essentially upside down, so the UI puts it near bottom physically (but it acts top for them) */
#flag-vendor {
  bottom: 24px;
  right: 24px;
}

/* User sees bottom flap normally */
#flag-user {
  top: 24px;
  left: 24px;
}

/* Privacy Banner */
.privacy-banner {
  position: fixed;
  bottom: -100px;
  left: 0;
  width: 100%;
  padding: 16px 24px;
  background: rgba(10, 10, 15, 0.95);
  backdrop-filter: blur(10px);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  z-index: 200;
  transition: bottom 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.5);
}

@media (prefers-color-scheme: light) {
  .privacy-banner {
    background: rgba(255, 255, 255, 0.95);
    border-top: 1px solid rgba(0, 0, 0, 0.1);
  }
}

.privacy-banner p {
  font-size: 13px;
  color: var(--text-muted);
  flex: 1;
  line-height: 1.4;
}

.btn-privacy {
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--text-main);
  padding: 8px 16px;
  border-radius: 20px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

.privacy-banner.show {
  bottom: 0px;
}