/* ==============================
   CSS Custom Properties
   ============================== */
:root {
  --bg-gradient: linear-gradient(135deg, #FFD1DC 0%, #E8D5F5 25%, #D4E5F7 50%, #F5E6CC 75%, #FFD1DC 100%);
  --bg-size: 400% 400%;
  --card-bg: rgba(255, 255, 255, 0.88);
  --card-blur: 20px;
  --card-border: rgba(255, 255, 255, 0.6);
  --card-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
  --text-primary: #2D2B3A;
  --text-secondary: #6B6880;
  --text-muted: #9E9BB0;
  --radius-sm: 12px;
  --radius-md: 18px;
  --radius-lg: 24px;
  --radius-xl: 32px;
  --font-stack: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Noto Sans SC', sans-serif;
  --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 0.6s cubic-bezier(0.4, 0, 0.2, 1);

  /* Animal Colors */
  --color-cat: #9B7ED8;
  --color-cat-light: #E8DEFF;
  --color-cat-gradient: linear-gradient(135deg, #B08BEB, #7B68EE);
  --color-dog: #FF9A56;
  --color-dog-light: #FFE8D5;
  --color-dog-gradient: linear-gradient(135deg, #FFB347, #FF6B35);
  --color-rabbit: #F472B6;
  --color-rabbit-light: #FDE2F0;
  --color-rabbit-gradient: linear-gradient(135deg, #FF8DC7, #E91E8C);
  --color-fox: #F59E0B;
  --color-fox-light: #FEF3C7;
  --color-fox-gradient: linear-gradient(135deg, #FBBF24, #F97316);
  --color-panda: #34D399;
  --color-panda-light: #D1FAE5;
  --color-panda-gradient: linear-gradient(135deg, #6EE7B7, #10B981);
  --color-deer: #2DD4BF;
  --color-deer-light: #CCFBF1;
  --color-deer-gradient: linear-gradient(135deg, #5EEAD4, #0D9488);
}

/* ==============================
   CSS Reset & Base
   ============================== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-stack);
  color: var(--text-primary);
  background: var(--bg-gradient);
  background-size: var(--bg-size);
  animation: gradientShift 15s ease infinite;
  min-height: 100dvh;
  overflow-x: hidden;
  line-height: 1.6;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

/* ==============================
   App Container
   ============================== */
#app {
  position: relative;
  width: 100%;
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  overflow: hidden;
}

/* ==============================
   Screen System
   ============================== */
.screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 20px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity var(--transition-normal), transform var(--transition-normal);
  z-index: 0;
}

.screen.active {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
  z-index: 1;
}

/* ==============================
   Landing Screen
   ============================== */
.floating-emojis {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.floater {
  position: absolute;
  left: var(--x);
  top: var(--y);
  font-size: 28px;
  opacity: 0.35;
  animation: float var(--dur) ease-in-out var(--delay) infinite;
  filter: blur(0.5px);
}

.landing-content {
  position: relative;
  z-index: 1;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  animation: fadeInUp 0.8s ease-out;
}

.landing-badge {
  display: inline-block;
  padding: 6px 20px;
  background: rgba(255, 255, 255, 0.65);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 100px;
  font-size: 13px;
  color: var(--text-secondary);
  letter-spacing: 2px;
  border: 1px solid rgba(255, 255, 255, 0.5);
}

.landing-title {
  font-size: 42px;
  font-weight: 800;
  line-height: 1.2;
  margin: 8px 0;
  display: flex;
  flex-direction: column;
}

.landing-title span:first-child {
  font-size: 32px;
  font-weight: 600;
  background: linear-gradient(135deg, #6B6880, #2D2B3A);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.title-highlight {
  background: linear-gradient(135deg, #FF6B9D, #C084FC, #60A5FA);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-size: 48px !important;
  font-weight: 900 !important;
  letter-spacing: 4px;
}

.landing-subtitle {
  font-size: 17px;
  color: var(--text-secondary);
  font-weight: 500;
}

.landing-info {
  font-size: 13px;
  color: var(--text-muted);
  letter-spacing: 1px;
}

.animal-preview {
  font-size: 28px;
  letter-spacing: 8px;
  margin: 8px 0;
  animation: pulse 3s ease-in-out infinite;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 16px 48px;
  background: linear-gradient(135deg, #FF6B9D, #C084FC);
  color: white;
  font-size: 17px;
  font-weight: 700;
  border-radius: 100px;
  box-shadow: 0 6px 24px rgba(255, 107, 157, 0.4);
  transition: all var(--transition-fast);
  margin-top: 8px;
  position: relative;
  overflow: hidden;
}

.btn-primary::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
  animation: shimmer 3s ease-in-out infinite;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(255, 107, 157, 0.5);
}

.btn-primary:active {
  transform: translateY(0) scale(0.97);
}

.landing-note {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ==============================
   Quiz Screen
   ============================== */
#screen-quiz {
  justify-content: flex-start;
  padding-top: 20px;
}

.quiz-header {
  width: 100%;
  margin-bottom: 20px;
}

.progress-bar {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 100px;
  overflow: hidden;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.progress-fill {
  height: 100%;
  width: 10%;
  background: linear-gradient(90deg, #FF6B9D, #C084FC);
  border-radius: 100px;
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.question-counter {
  text-align: center;
  margin-top: 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 2px;
}

.quiz-body {
  width: 100%;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: fadeIn 0.3s ease-out;
}

.question-card {
  background: var(--card-bg);
  backdrop-filter: blur(var(--card-blur));
  -webkit-backdrop-filter: blur(var(--card-blur));
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  box-shadow: var(--card-shadow);
  text-align: center;
}

.question-emoji {
  font-size: 44px;
  margin-bottom: 12px;
  display: block;
}

.question-text {
  font-size: 19px;
  font-weight: 700;
  line-height: 1.5;
  color: var(--text-primary);
}

.options {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.option-btn {
  width: 100%;
  padding: 18px 20px;
  background: var(--card-bg);
  backdrop-filter: blur(var(--card-blur));
  -webkit-backdrop-filter: blur(var(--card-blur));
  border: 2px solid rgba(255, 255, 255, 0.6);
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 500;
  color: var(--text-primary);
  text-align: left;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  gap: 12px;
  line-height: 1.5;
}

.option-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  min-width: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(255,107,157,0.15), rgba(192,132,252,0.15));
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
}

.option-btn:hover {
  transform: translateX(4px);
  border-color: rgba(192, 132, 252, 0.4);
  box-shadow: 0 4px 20px rgba(192, 132, 252, 0.15);
}

.option-btn:active {
  transform: scale(0.98);
}

.option-btn.selected {
  background: linear-gradient(135deg, rgba(255,107,157,0.15), rgba(192,132,252,0.15));
  border-color: rgba(192, 132, 252, 0.6);
  transform: scale(0.98);
}

.option-btn.selected .option-label {
  background: linear-gradient(135deg, #FF6B9D, #C084FC);
  color: white;
}

.quiz-body.fade-out {
  opacity: 0;
  transform: translateX(-20px);
  transition: all 0.25s ease-in;
}

.quiz-body.fade-in {
  animation: slideInRight 0.35s ease-out;
}

/* ==============================
   Loading Screen
   ============================== */
.loading-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.loading-orb {
  position: relative;
  width: 120px;
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.loading-emoji {
  font-size: 56px;
  animation: bounce 1.5s ease-in-out infinite;
  position: relative;
  z-index: 2;
}

.loading-ring {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 3px solid transparent;
  border-top-color: #C084FC;
  border-right-color: #FF6B9D;
  animation: spin 1.2s linear infinite;
}

.loading-ring.ring-2 {
  width: 85%;
  height: 85%;
  border-top-color: #60A5FA;
  border-right-color: #C084FC;
  animation-direction: reverse;
  animation-duration: 1.8s;
}

.loading-text {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-secondary);
}

.dots::after {
  content: '';
  animation: dots 1.5s steps(4, end) infinite;
}

.loading-bar-wrap {
  width: 200px;
  height: 6px;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 100px;
  overflow: hidden;
}

.loading-bar {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #FF6B9D, #C084FC, #60A5FA);
  border-radius: 100px;
  transition: width 0.3s ease;
}

.loading-percent {
  font-size: 14px;
  color: var(--text-muted);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ==============================
   Result Screen
   ============================== */
#screen-result {
  justify-content: flex-start;
  padding-top: 24px;
  padding-bottom: 40px;
}

.result-card {
  width: 100%;
  border-radius: var(--radius-xl);
  overflow: hidden;
  background: white;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.12);
  animation: scaleIn 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.result-header {
  padding: 32px 24px 28px;
  text-align: center;
  color: white;
  position: relative;
  overflow: hidden;
}

.result-header::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, rgba(255,255,255,0.15) 0%, transparent 60%);
  animation: rotateGlow 10s linear infinite;
}

.result-label {
  font-size: 13px;
  font-weight: 500;
  opacity: 0.85;
  letter-spacing: 3px;
  margin-bottom: 8px;
  position: relative;
}

.result-emoji {
  font-size: 72px;
  margin: 8px 0;
  position: relative;
  animation: bounceIn 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) 0.2s both;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.15));
}

.result-title {
  font-size: 36px;
  font-weight: 900;
  letter-spacing: 4px;
  position: relative;
  text-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.result-subtitle {
  font-size: 16px;
  font-weight: 500;
  opacity: 0.9;
  margin-top: 6px;
  position: relative;
  letter-spacing: 2px;
}

.result-body {
  padding: 24px;
}

.result-traits {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-bottom: 20px;
}

.trait-pill {
  padding: 6px 16px;
  border-radius: 100px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 1px;
}

.result-desc {
  font-size: 14.5px;
  line-height: 1.8;
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: 20px;
  padding: 0 4px;
}

.result-match {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 20px;
  background: linear-gradient(135deg, #FFF0F5, #FFF5EE);
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
}

.match-icon {
  font-size: 20px;
}

.match-text {
  font-size: 14px;
  color: var(--text-secondary);
}

.match-text strong {
  color: var(--text-primary);
  font-weight: 700;
}

.result-scores {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.score-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: #F9FAFB;
  font-size: 12px;
}

.score-emoji {
  font-size: 18px;
}

.score-name {
  font-weight: 600;
  color: var(--text-primary);
  flex: 1;
}

.score-bar-wrap {
  flex: 1;
  height: 4px;
  background: #E5E7EB;
  border-radius: 100px;
  overflow: hidden;
}

.score-bar-fill {
  height: 100%;
  border-radius: 100px;
  transition: width 1s cubic-bezier(0.4, 0, 0.2, 1);
}

.result-footer {
  padding: 16px 24px;
  text-align: center;
  border-top: 1px solid #F3F4F6;
  background: #FAFAFA;
}

.result-watermark {
  font-size: 14px;
  font-weight: 700;
  background: linear-gradient(135deg, #FF6B9D, #C084FC);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 2px;
}

.result-qr-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

.result-actions {
  margin-top: 24px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.btn-retry {
  padding: 14px 40px;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 2px solid rgba(192, 132, 252, 0.3);
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 600;
  border-radius: 100px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all var(--transition-fast);
}

.btn-retry:hover {
  background: rgba(255, 255, 255, 0.95);
  border-color: rgba(192, 132, 252, 0.6);
  transform: translateY(-1px);
}

.share-hint {
  font-size: 13px;
  color: var(--text-muted);
  animation: pulse 2s ease-in-out infinite;
}

/* ==============================
   Animal Theme Colors
   ============================== */
.theme-cat .result-header { background: var(--color-cat-gradient); }
.theme-cat .trait-pill { background: var(--color-cat-light); color: var(--color-cat); }
.theme-cat .score-bar-fill { background: var(--color-cat-gradient); }

.theme-dog .result-header { background: var(--color-dog-gradient); }
.theme-dog .trait-pill { background: var(--color-dog-light); color: #E06520; }
.theme-dog .score-bar-fill { background: var(--color-dog-gradient); }

.theme-rabbit .result-header { background: var(--color-rabbit-gradient); }
.theme-rabbit .trait-pill { background: var(--color-rabbit-light); color: #D63384; }
.theme-rabbit .score-bar-fill { background: var(--color-rabbit-gradient); }

.theme-fox .result-header { background: var(--color-fox-gradient); }
.theme-fox .trait-pill { background: var(--color-fox-light); color: #D97706; }
.theme-fox .score-bar-fill { background: var(--color-fox-gradient); }

.theme-panda .result-header { background: var(--color-panda-gradient); }
.theme-panda .trait-pill { background: var(--color-panda-light); color: #059669; }
.theme-panda .score-bar-fill { background: var(--color-panda-gradient); }

.theme-deer .result-header { background: var(--color-deer-gradient); }
.theme-deer .trait-pill { background: var(--color-deer-light); color: #0D9488; }
.theme-deer .score-bar-fill { background: var(--color-deer-gradient); }

/* ==============================
   Keyframe Animations
   ============================== */
@keyframes gradientShift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

@keyframes float {
  0%, 100% { transform: translate(0, 0) rotate(0deg); }
  25% { transform: translate(10px, -20px) rotate(5deg); }
  50% { transform: translate(-5px, -35px) rotate(-3deg); }
  75% { transform: translate(15px, -15px) rotate(4deg); }
}

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

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

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(30px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes shimmer {
  0% { left: -100%; }
  50%, 100% { left: 100%; }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

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

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}

@keyframes bounceIn {
  0% { opacity: 0; transform: scale(0.3); }
  50% { transform: scale(1.05); }
  70% { transform: scale(0.95); }
  100% { opacity: 1; transform: scale(1); }
}

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

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

@keyframes dots {
  0% { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
}

@keyframes barGrow {
  from { width: 0%; }
}

/* ==============================
   Responsive Adjustments
   ============================== */
@media (max-width: 380px) {
  .landing-title span:first-child { font-size: 26px; }
  .title-highlight { font-size: 40px !important; }
  .question-text { font-size: 17px; }
  .option-btn { padding: 14px 16px; font-size: 14px; }
  .result-emoji { font-size: 60px; }
  .result-title { font-size: 30px; }
}

@media (min-width: 481px) {
  #app {
    margin-top: 20px;
  }
  .screen {
    min-height: calc(100dvh - 40px);
  }
}

/* ==============================
   Utility
   ============================== */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Smooth scroll behavior */
html {
  scroll-behavior: smooth;
}

/* Disable selection on interactive elements */
button, .option-btn {
  user-select: none;
  -webkit-user-select: none;
}

/* Safe area padding for notched phones */
@supports (padding-top: env(safe-area-inset-top)) {
  .screen {
    padding-top: calc(24px + env(safe-area-inset-top));
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
  }
}
