.back-link {
  display: inline-block;
  color: var(--gold);
  text-decoration: none;
  margin-bottom: 1.5rem;
  opacity: 0.7;
  transition: opacity 0.3s;
}

.back-link:hover {
  opacity: 1;
}

.screen {
  animation: fadeIn 0.5s ease-in;
}

.hidden {
  display: none !important;
}

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

/* ===== Sorting Hat SVG ===== */

.hat-wrapper {
  position: relative;
  display: inline-block;
}

.intro-hat {
  margin: 1.5rem 0;
}

.intro-hat .sorting-hat-svg {
  width: 220px;
  height: auto;
  animation: float 3s ease-in-out infinite;
  filter: drop-shadow(0 5px 25px rgba(212, 168, 67, 0.3));
}

.quiz-hat .sorting-hat-svg {
  width: 140px;
  height: auto;
  filter: drop-shadow(0 3px 15px rgba(212, 168, 67, 0.3));
}

@keyframes float {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-12px) rotate(2deg); }
}

/* Hat face animations */
.hat-eye {
  animation: blink 4s ease-in-out infinite;
}

.right-eye {
  animation-delay: 0.2s;
}

@keyframes blink {
  0%, 42%, 46%, 100% { transform: scaleY(1); }
  44% { transform: scaleY(0.1); }
}

.eye-glow {
  animation: glowPulse 2s ease-in-out infinite alternate;
}

@keyframes glowPulse {
  0% { opacity: 0.3; r: 2; }
  100% { opacity: 0.8; r: 4; }
}

.hat-mouth.speaking {
  animation: speak 0.4s ease-in-out infinite alternate;
}

.hat-mouth.silent {
  animation: none;
}

@keyframes speak {
  0% { d: path("M75 128 Q95 136 125 128"); }
  100% { d: path("M75 128 Q95 145 125 128"); }
}

.magic-aura {
  animation: auraPulse 3s ease-in-out infinite alternate;
}

@keyframes auraPulse {
  0% { opacity: 0.08; }
  100% { opacity: 0.25; }
}

/* ===== Sparkles ===== */

.sparkles {
  position: absolute;
  inset: -20px;
  pointer-events: none;
  z-index: 1;
}

.sparkle {
  position: absolute;
  width: 6px;
  height: 6px;
  background: var(--gold);
  border-radius: 50%;
  box-shadow: 0 0 6px var(--gold), 0 0 12px var(--gold);
  animation: sparkleFloat 3s ease-in-out infinite;
}

.sparkle:nth-child(1) { top: 20%; left: 5%; animation-delay: 0s; animation-duration: 2.5s; }
.sparkle:nth-child(2) { top: 10%; right: 10%; animation-delay: 0.5s; animation-duration: 3.2s; }
.sparkle:nth-child(3) { top: 50%; left: -5%; animation-delay: 1s; animation-duration: 2.8s; }
.sparkle:nth-child(4) { top: 40%; right: 0%; animation-delay: 1.5s; animation-duration: 3.5s; }
.sparkle:nth-child(5) { top: 70%; left: 10%; animation-delay: 0.7s; animation-duration: 2.2s; }
.sparkle:nth-child(6) { top: 60%; right: 5%; animation-delay: 2s; animation-duration: 3s; }

@keyframes sparkleFloat {
  0% { opacity: 0; transform: translateY(0) scale(0); }
  30% { opacity: 1; transform: translateY(-10px) scale(1); }
  70% { opacity: 1; transform: translateY(-25px) scale(0.8); }
  100% { opacity: 0; transform: translateY(-40px) scale(0); }
}

/* ===== Hat Speaking Layout ===== */

.hat-speaks {
  display: flex;
  align-items: flex-start;
  gap: 1.5rem;
  margin-bottom: 2rem;
  justify-content: center;
  flex-wrap: wrap;
}

.speech-bubble {
  position: relative;
  background: rgba(212, 168, 67, 0.08);
  border: 1px solid rgba(212, 168, 67, 0.25);
  border-radius: 16px;
  padding: 1.2rem 1.5rem;
  max-width: 400px;
  min-height: 80px;
  display: flex;
  align-items: center;
  flex: 1;
}

.speech-bubble::before {
  content: '';
  position: absolute;
  left: -12px;
  top: 30px;
  width: 0;
  height: 0;
  border-top: 10px solid transparent;
  border-bottom: 10px solid transparent;
  border-right: 12px solid rgba(212, 168, 67, 0.25);
}

.speech-bubble::after {
  content: '';
  position: absolute;
  left: -10px;
  top: 31px;
  width: 0;
  height: 0;
  border-top: 9px solid transparent;
  border-bottom: 9px solid transparent;
  border-right: 11px solid rgba(212, 168, 67, 0.08);
}

/* ===== Buttons ===== */

.magic-btn {
  font-family: 'Cinzel Decorative', cursive;
  font-size: 1.1rem;
  padding: 0.8rem 2rem;
  background: linear-gradient(135deg, var(--gold), #b8942e);
  color: var(--darker-bg);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  text-decoration: none;
  display: inline-block;
}

.magic-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 20px rgba(212, 168, 67, 0.5);
}

.magic-btn.secondary {
  background: transparent;
  color: var(--gold);
  border: 2px solid var(--gold);
}

/* ===== Progress ===== */

.progress-bar {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  margin-bottom: 2rem;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--gold);
  border-radius: 3px;
  transition: width 0.4s ease;
  width: 0%;
}

/* ===== Question Text (typewriter) ===== */

#question-text {
  font-family: 'Cinzel Decorative', cursive;
  color: var(--gold);
  font-size: 1.15rem;
  line-height: 1.6;
  margin: 0;
  text-align: left;
  min-height: 2em;
}

#question-text .word {
  display: inline-block;
  opacity: 0;
  transform: translateY(5px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  margin-right: 0.3em;
}

#question-text .word.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Cursor blink after last visible word */
#question-text .word.cursor::after {
  content: '|';
  color: var(--gold);
  animation: cursorBlink 0.7s step-end infinite;
  margin-left: 2px;
}

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

/* ===== Answers ===== */

.answers {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  max-width: 500px;
  margin: 0 auto;
}

.answer-btn {
  font-family: 'Lora', serif;
  font-size: 0.95rem;
  padding: 0.75rem 1.2rem;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-light);
  border: 1px solid rgba(212, 168, 67, 0.3);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s;
  text-align: left;
  opacity: 0;
  transform: translateY(10px);
}

.answer-btn.visible {
  opacity: 1;
  transform: translateY(0);
}

.answer-btn:hover {
  background: rgba(212, 168, 67, 0.15);
  border-color: var(--gold);
  transform: translateX(5px);
}

/* ===== Result ===== */

.house-crest {
  font-size: 5rem;
  margin: 1.5rem 0;
}

.house-title {
  font-family: 'Cinzel Decorative', cursive;
  font-size: 2rem;
  margin-bottom: 1rem;
}

.house-desc {
  font-size: 1.05rem;
  line-height: 1.7;
  max-width: 500px;
  margin: 0 auto 2rem;
  opacity: 0.85;
}

.result-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
}

/* House colors */
.gryffindor .house-title { color: #ae0001; text-shadow: 0 0 20px rgba(174, 0, 1, 0.4); }
.hufflepuff .house-title { color: #ecb939; text-shadow: 0 0 20px rgba(236, 185, 57, 0.4); }
.ravenclaw .house-title { color: #222f5b; text-shadow: 0 0 20px rgba(34, 47, 91, 0.4); }
.slytherin .house-title { color: #2a623d; text-shadow: 0 0 20px rgba(42, 98, 61, 0.4); }

.gryffindor { border-color: #ae0001; }
.hufflepuff { border-color: #ecb939; }
.ravenclaw { border-color: #222f5b; }
.slytherin { border-color: #2a623d; }

/* ===== Responsive ===== */

@media (max-width: 600px) {
  .hat-speaks {
    flex-direction: column;
    align-items: center;
    gap: 0.8rem;
    margin-bottom: 1rem;
  }

  .quiz-hat .sorting-hat-svg {
    width: 90px;
  }

  .speech-bubble {
    text-align: center;
    padding: 0.8rem 1rem;
    min-height: 50px;
  }

  .speech-bubble::before,
  .speech-bubble::after {
    display: none;
  }

  #question-text {
    text-align: center;
    font-size: 1rem;
  }

  .answers {
    gap: 0.5rem;
  }

  .answer-btn {
    padding: 0.6rem 1rem;
    font-size: 0.9rem;
  }

  .progress-bar {
    margin-bottom: 1rem;
  }
}
