/* =============================================
   TOKENS & RESET
   ============================================= */
:root {
  --clr-bg: #0f0f1a;
  --clr-surface: rgba(255, 255, 255, 0.05);
  --clr-surface-hover: rgba(255, 255, 255, 0.09);
  --clr-border: rgba(255, 255, 255, 0.1);
  --clr-border-glow: rgba(99, 102, 241, 0.45);

  --clr-primary: #6366f1;
  --clr-primary-light: #818cf8;
  --clr-accent: #06b6d4;
  --clr-success: #10b981;
  --clr-warning: #f59e0b;

  --clr-text: #f1f5f9;
  --clr-text-muted: #94a3b8;
  --clr-text-dim: #64748b;

  --clr-card-front: linear-gradient(145deg, #1e1b4b 0%, #1e1e3f 60%, #0f0f1a 100%);
  --clr-card-back: linear-gradient(145deg, #064e3b 0%, #065f46 50%, #0f0f1a 100%);

  --radius-card: 28px;
  --radius-btn: 16px;
  --radius-chip: 999px;

  --shadow-card: 0 40px 80px rgba(0, 0, 0, 0.6), 0 8px 32px rgba(99, 102, 241, 0.15);
  --shadow-card-hover: 0 50px 100px rgba(0, 0, 0, 0.7), 0 12px 48px rgba(99, 102, 241, 0.25);

  --transition-flip: 0.65s cubic-bezier(0.34, 1.3, 0.64, 1);
  --transition-snap: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-bounce: 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);

  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --header-h: 68px;
  --progress-h: 4px;
}

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

html, body {
  height: 100%;
  width: 100%;
  overflow-x: hidden;
}

body {
  font-family: var(--font);
  background-color: var(--clr-bg);
  color: var(--clr-text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  position: relative;
}

/* =============================================
   ANIMATED BACKGROUND BLOBS
   ============================================= */
.bg-blob {
  position: fixed;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.18;
  pointer-events: none;
  z-index: 0;
  animation: blob-drift 18s ease-in-out infinite alternate;
}

.blob-1 {
  width: 520px;
  height: 520px;
  background: radial-gradient(circle, #6366f1, transparent);
  top: -120px;
  left: -120px;
  animation-delay: 0s;
}

.blob-2 {
  width: 420px;
  height: 420px;
  background: radial-gradient(circle, #06b6d4, transparent);
  bottom: -80px;
  right: -80px;
  animation-delay: -6s;
}

.blob-3 {
  width: 300px;
  height: 300px;
  background: radial-gradient(circle, #8b5cf6, transparent);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation-delay: -12s;
}

@keyframes blob-drift {
  0%   { transform: translate(0, 0) scale(1); }
  50%  { transform: translate(40px, -30px) scale(1.1); }
  100% { transform: translate(-20px, 40px) scale(0.95); }
}

/* =============================================
   APP LAYOUT
   ============================================= */
#app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* =============================================
   HEADER
   ============================================= */
.header {
  height: var(--header-h);
  background: rgba(15, 15, 26, 0.8);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--clr-border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 680px;
  margin: 0 auto;
  height: 100%;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

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

.logo-icon {
  font-size: 1.4rem;
  line-height: 1;
}

.logo-text {
  font-size: 1rem;
  font-weight: 700;
  background: linear-gradient(90deg, var(--clr-primary-light), var(--clr-accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
}

.stats-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-chip);
  padding: 8px 16px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}

.stat-value {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--clr-text);
  line-height: 1;
  transition: all 0.3s;
}

.stat-label {
  font-size: 0.6rem;
  font-weight: 500;
  color: var(--clr-text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-divider {
  width: 1px;
  height: 24px;
  background: var(--clr-border);
}

/* =============================================
   PROGRESS BAR
   ============================================= */
.progress-track {
  height: var(--progress-h);
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--clr-primary), var(--clr-accent));
  width: 0%;
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 0 var(--radius-chip) var(--radius-chip) 0;
  box-shadow: 0 0 12px rgba(99, 102, 241, 0.6);
}

/* =============================================
   CARD ARENA
   ============================================= */
.card-arena {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px 24px;
  gap: 20px;
}

.card-wrapper {
  width: 100%;
  max-width: 440px;
  perspective: 1200px;
}

/* =============================================
   CARD 3D FLIP
   ============================================= */
.card {
  width: 100%;
  aspect-ratio: 3 / 4;
  cursor: pointer;
  outline: none;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.1s;
  border-radius: var(--radius-card);
  -webkit-tap-highlight-color: transparent;
}

.card:focus-visible {
  outline: 3px solid var(--clr-primary-light);
  outline-offset: 6px;
}

.card:hover:not(.is-flipped) {
  transform: translateY(-6px) rotateX(2deg);
}

.card:active {
  transform: scale(0.97);
}

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

.card-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform var(--transition-flip);
  border-radius: var(--radius-card);
}

.card-face {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-card);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  padding: 28px 28px 24px;
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

/* FRONT */
.card-front {
  background: var(--clr-card-front);
  border: 1px solid rgba(99, 102, 241, 0.25);
}

.card-front::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at top left, rgba(99, 102, 241, 0.15), transparent 60%);
  border-radius: inherit;
  pointer-events: none;
}

/* BACK */
.card-back {
  background: var(--clr-card-back);
  border: 1px solid rgba(16, 185, 129, 0.25);
  transform: rotateY(180deg);
}

.card-back::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at bottom right, rgba(16, 185, 129, 0.15), transparent 60%);
  border-radius: inherit;
  pointer-events: none;
}

/* =============================================
   CARD CONTENT
   ============================================= */
.card-badge {
  display: flex;
  align-items: center;
  gap: 7px;
  align-self: flex-start;
}

.badge-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--clr-primary);
  box-shadow: 0 0 8px var(--clr-primary);
  animation: pulse-dot 2s ease-in-out infinite;
}

.answer-dot {
  background: var(--clr-success);
  box-shadow: 0 0 8px var(--clr-success);
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(0.85); }
}

.badge-text {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--clr-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.card-number-chip {
  align-self: flex-end;
  margin-top: -20px;
  background: var(--clr-primary);
  color: white;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: var(--radius-chip);
  letter-spacing: 0.04em;
}

.card-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px 0;
}

.card-question {
  font-size: clamp(1.1rem, 3.5vw, 1.45rem);
  font-weight: 700;
  line-height: 1.4;
  text-align: center;
  color: var(--clr-text);
  letter-spacing: -0.02em;
}

.card-answer {
  font-size: clamp(0.95rem, 3vw, 1.25rem);
  font-weight: 500;
  line-height: 1.55;
  text-align: center;
  color: var(--clr-text);
}

.card-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--clr-text-dim);
  animation: hint-float 3s ease-in-out infinite;
  padding-top: 8px;
}

.hint-icon { font-size: 1rem; }

@keyframes hint-float {
  0%, 100% { transform: translateY(0); opacity: 0.7; }
  50% { transform: translateY(-4px); opacity: 1; }
}

/* =============================================
   BUTTON
   ============================================= */
.card-actions {
  display: flex;
  justify-content: center;
  padding-top: 8px;
}

.btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 28px;
  border: none;
  border-radius: var(--radius-btn);
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition-bounce);
  position: relative;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0);
  transition: background 0.2s;
}

.btn:hover::after { background: rgba(255, 255, 255, 0.08); }
.btn:active { transform: scale(0.95); }

.btn-next {
  background: linear-gradient(135deg, var(--clr-success), #059669);
  color: white;
  box-shadow: 0 8px 32px rgba(16, 185, 129, 0.4);
  min-width: 160px;
  justify-content: center;
}

.btn-next:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 40px rgba(16, 185, 129, 0.55);
}

.btn-arrow {
  width: 18px;
  height: 18px;
  transition: transform 0.3s;
}

.btn-next:hover .btn-arrow {
  transform: translateX(4px);
}

/* =============================================
   SWIPE HINT
   ============================================= */
.swipe-hint {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--clr-text-dim);
  text-align: center;
  display: none;
}

@media (pointer: coarse) {
  .swipe-hint { display: block; }
}

/* =============================================
   CARD ENTRY / EXIT ANIMATIONS
   ============================================= */
@keyframes card-enter {
  from {
    opacity: 0;
    transform: translateY(40px) scale(0.9) rotateX(-12deg);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1) rotateX(0);
  }
}

@keyframes card-exit-left {
  to {
    opacity: 0;
    transform: translateX(-120%) rotate(-18deg) scale(0.8);
  }
}

@keyframes card-exit-right {
  to {
    opacity: 0;
    transform: translateX(120%) rotate(18deg) scale(0.8);
  }
}

.card-wrapper.entering .card {
  animation: card-enter 0.55s var(--transition-bounce) both;
}

.card-wrapper.exit-left .card {
  animation: card-exit-left 0.4s cubic-bezier(0.4, 0, 1, 1) both;
  pointer-events: none;
}

.card-wrapper.exit-right .card {
  animation: card-exit-right 0.4s cubic-bezier(0.4, 0, 1, 1) both;
  pointer-events: none;
}

/* =============================================
   LOOP COMPLETE BANNER
   ============================================= */
.loop-complete {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(10, 10, 20, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  padding: 32px;
  animation: fade-in 0.4s ease both;
}

.loop-complete[hidden] { display: none; }

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.loop-icon {
  font-size: 4rem;
  animation: pop-in 0.5s var(--transition-bounce) 0.1s both;
}

@keyframes pop-in {
  from { transform: scale(0); }
  to { transform: scale(1); }
}

.loop-title {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  background: linear-gradient(90deg, var(--clr-primary-light), var(--clr-accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: pop-in 0.5s var(--transition-bounce) 0.2s both;
}

.loop-subtitle {
  font-size: 1rem;
  color: var(--clr-text-muted);
  text-align: center;
  animation: pop-in 0.5s var(--transition-bounce) 0.3s both;
}

.loop-progress {
  width: 220px;
  height: 6px;
  background: var(--clr-surface);
  border-radius: var(--radius-chip);
  overflow: hidden;
  animation: pop-in 0.5s var(--transition-bounce) 0.4s both;
}

.loop-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--clr-primary), var(--clr-accent));
  border-radius: var(--radius-chip);
  transition: width 0.05s linear;
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.6);
}

/* =============================================
   RESPONSIVE
   ============================================= */
@media (max-width: 480px) {
  .card-arena { padding: 24px 16px 16px; }
  .card-face { padding: 22px 20px 18px; }
  .header-inner { padding: 0 16px; }
  .logo-text { font-size: 0.88rem; }
  .stats-bar { padding: 6px 12px; gap: 10px; }
}

@media (min-width: 700px) {
  .card-wrapper { max-width: 380px; }
  .card { aspect-ratio: 2.5 / 3.5; }
}

/* =============================================
   INSTALL BANNER
   ============================================= */
.install-banner {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(120px);
  z-index: 300;
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(30, 27, 75, 0.95);
  border: 1px solid var(--clr-border-glow);
  border-radius: 20px;
  padding: 14px 20px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(20px);
  transition: transform 0.5s var(--transition-bounce);
  white-space: nowrap;
}

.install-banner.visible {
  transform: translateX(-50%) translateY(0);
}

.install-text {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--clr-text-muted);
}

.install-btn {
  background: var(--clr-primary);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 0.78rem;
  font-weight: 700;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.2s;
}

.install-btn:hover {
  background: var(--clr-primary-light);
  transform: scale(1.04);
}

.install-dismiss {
  background: none;
  border: none;
  color: var(--clr-text-dim);
  cursor: pointer;
  font-size: 1rem;
  padding: 4px;
  display: flex;
  align-items: center;
  transition: color 0.2s;
}

.install-dismiss:hover { color: var(--clr-text); }
