/* ==================== RESET & BASE ==================== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #ffffff;
  --bg-secondary: #f5f5f7;
  --bg-card: #ffffff;
  --text-primary: #1d1d1f;
  --text-secondary: #86868b;
  --accent: #1d1d1f;
  --accent-hover: #424245;
  --gold: #a08060;
  --gold-light: #c4a882;
  --gold-bg: rgba(160, 128, 96, 0.08);
  --border: rgba(0, 0, 0, 0.06);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 2px 12px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 4px 24px rgba(0, 0, 0, 0.08);
  --radius: 20px;
  --radius-sm: 14px;
  --transition: 0.3s cubic-bezier(0.25, 0.1, 0.25, 1);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
}

/* ==================== SCREENS ==================== */
.screen {
  display: none;
  opacity: 0;
  transition: opacity 0.5s ease;
}

.screen.active {
  display: flex;
  flex-direction: column;
  opacity: 1;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ==================== WELCOME SCREEN ==================== */
#welcome {
  justify-content: center;
  align-items: center;
  padding: 60px 32px;
  text-align: center;
}

.welcome-content {
  animation: fadeInUp 0.8s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.barista-avatar {
  width: 80px;
  height: 80px;
  margin: 0 auto 40px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--bg-secondary);
}

.barista-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.barista-avatar.small {
  width: 64px;
  height: 64px;
  margin-bottom: 28px;
}

.barista-avatar.tiny {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
}

h1 {
  font-size: 2rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 12px;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.subtitle {
  font-size: 1.1rem;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 40px;
  max-width: 340px;
  margin-left: auto;
  margin-right: auto;
  font-weight: 400;
}

.subtitle strong {
  color: var(--text-primary);
  font-weight: 600;
}

/* ==================== REFERRAL GATE ==================== */
.referral-gate {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.referral-gate.hidden {
  display: none;
}

.lock-icon {
  width: 56px;
  height: 56px;
  position: relative;
  margin-bottom: 0;
}

.lock-icon svg {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  transition: all 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.lock-icon .lock-closed rect { fill: var(--text-secondary); }
.lock-icon .lock-closed path { stroke: var(--text-secondary); }
.lock-icon .lock-closed circle { fill: var(--bg); }

.lock-icon .lock-open rect { fill: var(--gold); }
.lock-icon .lock-open path { stroke: var(--gold); }
.lock-icon .lock-open circle { fill: #fff; }

.lock-icon .lock-open {
  opacity: 0;
  transform: scale(0.8);
}

.lock-icon.unlocked .lock-closed {
  opacity: 0;
  transform: scale(0.8) rotate(-15deg);
}

.lock-icon.unlocked .lock-open {
  opacity: 1;
  transform: scale(1);
}

.lock-icon.shake {
  animation: shake 0.4s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

.referral-input-wrapper {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--bg-secondary);
  border: 1.5px solid transparent;
  border-radius: 14px;
  overflow: hidden;
  transition: all var(--transition);
  width: 100%;
  max-width: 300px;
}

.referral-input-wrapper:focus-within {
  border-color: var(--gold-light);
  background: var(--bg);
  box-shadow: 0 0 0 3px rgba(160, 128, 96, 0.12);
}

.referral-input-wrapper.error {
  border-color: #ff3b30;
  background: rgba(255, 59, 48, 0.04);
}

.referral-input {
  flex: 1;
  border: none;
  outline: none;
  padding: 14px 16px;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text-primary);
  background: transparent;
  letter-spacing: 0.02em;
  font-weight: 400;
}

.referral-input::placeholder {
  color: var(--text-secondary);
  opacity: 0.7;
}

.referral-submit {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: var(--accent);
  border: none;
  border-radius: 10px;
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  margin-right: 4px;
  transition: all var(--transition);
}

.referral-submit:hover {
  background: var(--accent-hover);
  transform: scale(1.04);
}

.referral-submit:active {
  transform: scale(0.96);
}

.referral-error {
  font-size: 0.82rem;
  color: #ff3b30;
  opacity: 0;
  transition: opacity 0.3s ease;
  height: 18px;
  font-weight: 500;
}

.referral-error.visible {
  opacity: 1;
}

.referral-success {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  animation: fadeInUp 0.6s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.referral-success.visible {
  display: flex;
}

.success-text {
  font-size: 1.05rem;
  color: var(--gold);
  font-weight: 500;
}

/* Name Gate */
.name-gate {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  animation: fadeInUp 0.5s ease;
}

.name-gate.visible {
  display: flex;
}

.name-prompt {
  font-size: 1.05rem;
  color: var(--text-secondary);
  font-weight: 400;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  50% { transform: translateX(6px); }
  75% { transform: translateX(-4px); }
}

/* ==================== BUTTONS ==================== */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 15px 30px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 100px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  font-family: inherit;
  letter-spacing: -0.01em;
}

.btn-primary:hover {
  background: var(--accent-hover);
  transform: scale(1.02);
}

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

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 0.88rem;
  cursor: pointer;
  padding: 12px 24px;
  font-family: inherit;
  font-weight: 400;
  transition: color var(--transition);
}

.back-btn:hover {
  color: var(--text-primary);
}

#backBtn {
  position: absolute;
  bottom: 24px;
  left: 12px;
}

.restart-link {
  display: inline-block;
  margin-top: 12px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 8px 16px;
  font-family: inherit;
  font-weight: 400;
  transition: color var(--transition);
}

.restart-link:hover {
  color: var(--text-primary);
}

/* ==================== PROGRESS BAR ==================== */
.progress-bar-container {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding: 20px 32px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}

.progress-bar {
  flex: 1;
  height: 3px;
  background: var(--bg-secondary);
  border-radius: 100px;
  position: relative;
  overflow: hidden;
}

.progress-bar::after {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: var(--progress, 0%);
  background: var(--text-primary);
  border-radius: 100px;
  transition: width 0.5s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.progress-text {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 500;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ==================== QUIZ ==================== */
#quiz {
  position: relative;
  padding-bottom: 80px;
}

.quiz-container {
  padding: 24px 32px 24px;
  position: relative;
  overflow: hidden;
}

.question {
  display: none;
  animation: slideIn 0.45s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.question.active {
  display: block;
}

.question.slide-out {
  animation: slideOut 0.3s cubic-bezier(0.25, 0.1, 0.25, 1) forwards;
}

.question-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.question h2 {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 28px;
  line-height: 1.25;
  letter-spacing: -0.02em;
}

.options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.option {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 15px 18px;
  background: var(--bg-secondary);
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
}

.option:hover {
  background: var(--bg);
  border-color: rgba(0, 0, 0, 0.1);
  box-shadow: var(--shadow-md);
}

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

.option.selected {
  border-color: var(--text-primary);
  background: var(--bg);
  box-shadow: var(--shadow-sm);
}

.option-icon {
  font-size: 1.35rem;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border-radius: 10px;
  flex-shrink: 0;
}

.option.selected .option-icon {
  background: var(--text-primary);
  border-radius: 10px;
  filter: grayscale(1) brightness(3);
}

.option-text {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

/* ==================== ANALYSIS ANIMATION ==================== */
#analysis {
  justify-content: center;
  align-items: center;
  padding: 60px 32px;
  text-align: center;
}

.analysis-content {
  animation: fadeInUp 0.6s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.analysis-content h2 {
  font-size: 1.3rem;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 48px;
  line-height: 1.4;
  letter-spacing: -0.01em;
}

.analysis-steps {
  display: flex;
  flex-direction: column;
  gap: 24px;
  margin-bottom: 48px;
  text-align: left;
  max-width: 280px;
  margin-left: auto;
  margin-right: auto;
}

.analysis-step {
  display: flex;
  align-items: center;
  gap: 16px;
  opacity: 0.2;
  transform: translateY(6px);
  transition: all 0.5s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.analysis-step.active {
  opacity: 1;
  transform: translateY(0);
}

.analysis-step.done .step-check {
  background: var(--text-primary);
  border-color: var(--text-primary);
}

.analysis-step.done .step-check svg {
  opacity: 1;
  transform: scale(1);
}

.step-check {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1.5px solid rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.step-check svg {
  width: 14px;
  height: 14px;
  stroke: #fff;
  opacity: 0;
  transform: scale(0.5);
  transition: all 0.3s ease;
}

.analysis-step span {
  font-size: 0.95rem;
  color: var(--text-primary);
  font-weight: 400;
}

.analysis-progress {
  width: 100%;
  max-width: 280px;
  height: 3px;
  background: var(--bg-secondary);
  border-radius: 100px;
  margin: 0 auto;
  overflow: hidden;
}

.analysis-progress-bar {
  height: 100%;
  width: 0%;
  background: var(--text-primary);
  border-radius: 100px;
  transition: width 0.4s ease;
}

/* ==================== RESULT SCREEN ==================== */
#result {
  justify-content: flex-start;
  align-items: center;
  padding: 48px 32px 60px;
}

.result-content {
  text-align: center;
  width: 100%;
  animation: fadeInUp 0.8s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.result-badge {
  display: inline-block;
  padding: 5px 14px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  border-radius: 100px;
  margin-bottom: 28px;
}

.result-image-container {
  width: 180px;
  height: 180px;
  margin: 0 auto 28px;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

.result-image-container img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#result h2 {
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
  letter-spacing: -0.02em;
}

.result-origin {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 20px;
  font-weight: 400;
}

.result-description {
  font-size: 1rem;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 24px;
  max-width: 380px;
  margin-left: auto;
  margin-right: auto;
  font-weight: 400;
}

.result-flavors {
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 32px;
}

.flavor-tag {
  padding: 5px 12px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 500;
  border-radius: 100px;
}

.barista-recommendation {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bg-secondary);
  padding: 18px 20px;
  border-radius: var(--radius-sm);
  margin-bottom: 36px;
  text-align: left;
  max-width: 380px;
  margin-left: auto;
  margin-right: auto;
}

.barista-recommendation p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.5;
  font-style: italic;
  font-weight: 400;
}

/* ==================== RECIPE SECTION ==================== */
.recipe-section {
  width: 100%;
  margin-bottom: 32px;
}

.recipe-section h3 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 20px;
  text-align: center;
  letter-spacing: -0.01em;
}

.recipe-tabs {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 16px;
}

.recipe-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 12px;
  border-radius: 12px;
  border: none;
  background: var(--bg-secondary);
  cursor: pointer;
  transition: all var(--transition);
  opacity: 0.5;
  font-family: inherit;
}

.recipe-tab:hover {
  opacity: 0.75;
}

.recipe-tab.active {
  opacity: 1;
  background: var(--text-primary);
}

.recipe-tab-icon {
  font-size: 1.2rem;
  line-height: 1;
}

.recipe-tab.active .recipe-tab-icon {
  filter: grayscale(1) brightness(3);
}

.recipe-tab-label {
  font-size: 0.6rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  white-space: nowrap;
}

.recipe-tab.active .recipe-tab-label {
  color: #fff;
}

.recipe-card {
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  padding: 20px 24px;
  animation: fadeInUp 0.3s ease;
}

.recipe-info {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.recipe-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.recipe-item-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--text-secondary);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.recipe-item-label svg {
  width: 14px;
  height: 14px;
  stroke: var(--text-secondary);
}

.recipe-item-value {
  font-size: 1.05rem;
  color: var(--text-primary);
  font-weight: 600;
  letter-spacing: -0.01em;
  padding-left: 20px;
}

/* ==================== RADAR CHART ==================== */
.radar-section {
  width: 100%;
  margin-bottom: 32px;
  text-align: center;
}

.radar-section h3 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
  letter-spacing: -0.01em;
}

#radarChart {
  max-width: 260px;
  margin: 0 auto;
  display: block;
}

/* ==================== DISCOUNT ==================== */
.discount-section {
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  padding: 24px;
  margin-bottom: 28px;
  text-align: center;
}

.discount-badge {
  display: inline-block;
  padding: 4px 12px;
  background: var(--text-primary);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  border-radius: 100px;
  margin-bottom: 12px;
}

.discount-text {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
  font-weight: 400;
}

.discount-code {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  background: var(--bg);
  border: 1.5px dashed rgba(0, 0, 0, 0.15);
  border-radius: 10px;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: all var(--transition);
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
}

.discount-code:hover {
  border-color: var(--text-primary);
}

.discount-code svg {
  opacity: 0.4;
}

.discount-copied {
  font-size: 0.8rem;
  color: var(--gold);
  font-weight: 500;
  margin-top: 8px;
  opacity: 0;
  transition: opacity 0.3s ease;
  height: 18px;
}

.discount-copied.visible {
  opacity: 1;
}

/* ==================== SHARE ==================== */
.share-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 28px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: none;
  border-radius: 100px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
  margin-top: 10px;
}

.share-btn:hover {
  background: var(--text-primary);
  color: #fff;
}

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

/* ==================== ANIMATIONS ==================== */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

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

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

/* ==================== RESPONSIVE ==================== */
@media (max-width: 480px) {
  #welcome {
    padding: 48px 24px;
  }

  h1 {
    font-size: 1.7rem;
  }

  .subtitle {
    font-size: 1rem;
  }

  .quiz-container {
    padding: 20px 24px 24px;
  }

  .question h2 {
    font-size: 1.3rem;
  }

  .option {
    padding: 14px 16px;
  }

  .result-image-container {
    width: 160px;
    height: 160px;
  }

  #result h2 {
    font-size: 1.5rem;
  }

  .progress-bar-container {
    padding: 18px 24px 14px;
  }
}
