.back-link {
  display: inline-block;
  color: var(--gold);
  text-decoration: none;
  margin-bottom: 1rem;
  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); }
}

/* ===== Mode Select ===== */

.mode-select {
  margin-bottom: 1rem;
}

.mode-buttons {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
}

.mode-btn {
  font-size: 0.9rem;
  padding: 0.5rem 1rem;
  opacity: 0.4;
  border: 2px solid rgba(212, 168, 67, 0.3);
  background: rgba(255, 255, 255, 0.03);
  color: var(--gold);
}

.mode-btn.selected {
  opacity: 1;
  background: linear-gradient(135deg, var(--gold), #b8942e);
  color: var(--darker-bg);
  box-shadow: 0 0 15px rgba(212, 168, 67, 0.4);
}

/* ===== Intro ===== */

.intro-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  margin: 1rem 0;
  flex-wrap: wrap;
}

.preview-player {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
}

.preview-label {
  font-size: 0.75rem;
  color: var(--gold);
  opacity: 0.7;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.broom-preview {
  animation: broomBob 2s ease-in-out infinite;
  filter: drop-shadow(0 3px 10px rgba(0,0,0,0.4));
}

@keyframes broomBob {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50% { transform: translateY(-8px) rotate(3deg); }
}

#broom-preview-p2 {
  animation: broomBob2 2s ease-in-out infinite;
}

@keyframes broomBob2 {
  0%, 100% { transform: scaleX(-1) translateY(0) rotate(-3deg); }
  50% { transform: scaleX(-1) translateY(-8px) rotate(3deg); }
}

.vs-text {
  font-family: 'Cinzel Decorative', cursive;
  font-size: 1rem;
  color: var(--gold);
  opacity: 0.5;
}

.snitch-preview-svg {
  animation: snitchFloat 2s ease-in-out infinite;
  filter: drop-shadow(0 0 15px rgba(212, 168, 67, 0.5));
}

@keyframes snitchFloat {
  0%, 100% { transform: translateY(0) translateX(-5px); }
  25% { transform: translateY(-10px) translateX(5px); }
  50% { transform: translateY(3px) translateX(8px); }
  75% { transform: translateY(-8px) translateX(-3px); }
}

.controls-hint {
  font-size: 0.9rem;
  opacity: 0.5;
  margin-bottom: 1rem;
  font-style: italic;
}

.wing {
  animation: flapWing 0.15s ease-in-out infinite alternate;
  transform-origin: center;
}

.left-wing { animation-name: flapLeft; }
.right-wing { animation-name: flapRight; }

@keyframes flapLeft {
  0% { transform: rotate(0deg) scaleY(1); }
  100% { transform: rotate(-8deg) scaleY(0.7); }
}

@keyframes flapRight {
  0% { transform: rotate(0deg) scaleY(1); }
  100% { transform: rotate(8deg) scaleY(0.7); }
}

/* ===== Player Setup (name + house grouped) ===== */

.player-setup {
  margin-bottom: 0.8rem;
  padding: 0.8rem;
  border: 1px solid rgba(212, 168, 67, 0.15);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
}

.player-setup-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.magic-input {
  font-family: 'Lora', serif;
  font-size: 0.9rem;
  padding: 0.4rem 0.8rem;
  background: rgba(255, 255, 255, 0.08);
  color: var(--gold);
  border: 2px solid rgba(212, 168, 67, 0.3);
  border-radius: 8px;
  text-align: center;
  width: 140px;
  outline: none;
  transition: border-color 0.3s, box-shadow 0.3s;
}

.magic-input::placeholder {
  color: rgba(212, 168, 67, 0.4);
}

.magic-input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 12px rgba(212, 168, 67, 0.2);
}

.select-label {
  font-size: 0.9rem;
  color: var(--text-light);
  white-space: nowrap;
}

.house-buttons {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
}

.house-btn {
  font-family: 'Lora', serif;
  font-size: 0.85rem;
  padding: 0.4rem 0.8rem;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-light);
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  -webkit-tap-highlight-color: transparent;
}

.house-btn:hover { transform: scale(1.05); }
.house-icon { font-size: 1rem; }

.gryffindor-btn { border-color: rgba(174, 0, 1, 0.4); }
.hufflepuff-btn { border-color: rgba(236, 185, 57, 0.4); }
.ravenclaw-btn { border-color: rgba(34, 47, 91, 0.4); }
.slytherin-btn { border-color: rgba(42, 98, 61, 0.4); }

.gryffindor-btn.selected { background: rgba(174, 0, 1, 0.3); border-color: #ae0001; box-shadow: 0 0 12px rgba(174, 0, 1, 0.3); }
.hufflepuff-btn.selected { background: rgba(236, 185, 57, 0.3); border-color: #ecb939; box-shadow: 0 0 12px rgba(236, 185, 57, 0.3); }
.ravenclaw-btn.selected { background: rgba(34, 47, 91, 0.3); border-color: #222f5b; box-shadow: 0 0 12px rgba(34, 47, 91, 0.3); }
.slytherin-btn.selected { background: rgba(42, 98, 61, 0.3); border-color: #2a623d; box-shadow: 0 0 12px rgba(42, 98, 61, 0.3); }

.difficulty-select { margin-top: 0.5rem; }

.diff-buttons {
  display: flex;
  gap: 0.8rem;
  justify-content: center;
  flex-wrap: wrap;
}

.diff-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  min-width: 130px;
}

.diff-desc {
  font-family: 'Lora', serif;
  font-size: 0.75rem;
  opacity: 0.7;
}

/* ===== 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);
}

/* ===== Game HUD ===== */

.game-hud {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-bottom: 0.8rem;
  flex-wrap: wrap;
  align-items: flex-start;
}

.scores-hud {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.hud-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hud-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0.6;
}

.hud-value {
  font-family: 'Cinzel Decorative', cursive;
  font-size: 1.8rem;
  color: var(--gold);
  text-shadow: 0 0 10px rgba(212, 168, 67, 0.4);
}

#timer.warning {
  color: #e74c3c;
  text-shadow: 0 0 10px rgba(231, 76, 60, 0.5);
  animation: pulse 0.5s ease-in-out infinite alternate;
}

@keyframes pulse {
  from { transform: scale(1); }
  to { transform: scale(1.15); }
}

/* ===== Game Field ===== */

.game-field {
  position: relative;
  width: 100%;
  height: 60vh;
  max-height: 500px;
  min-height: 300px;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(100, 160, 220, 0.15) 0%, transparent 60%),
    linear-gradient(180deg, #3a5a3a 0%, #2d4a2d 30%, #264026 60%, #1e3520 100%);
  border: 2px solid rgba(212, 168, 67, 0.3);
  border-radius: 16px;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

/* Quidditch pitch lines */
.game-field::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 50%, rgba(255,255,255,0.04) 0%, transparent 35%),
    linear-gradient(90deg, transparent 49.5%, rgba(255,255,255,0.06) 49.5%, rgba(255,255,255,0.06) 50.5%, transparent 50.5%);
  pointer-events: none;
}

/* ===== Player on broom ===== */

.player {
  position: absolute;
  width: 80px;
  height: 40px;
  z-index: 10;
  filter: drop-shadow(0 3px 8px rgba(0,0,0,0.5));
  pointer-events: none;
}

.player svg {
  width: 100%;
  height: 100%;
}

.player.facing-left {
  transform: scaleX(-1);
}

.scarf {
  animation: scarfBlow 0.4s ease-in-out infinite alternate;
}

@keyframes scarfBlow {
  0% { d: path("M38 24 Q30 28 25 22 Q20 26 15 24"); }
  100% { d: path("M38 24 Q30 22 25 26 Q20 22 15 26"); }
}

/* ===== Snitch ===== */

.snitch {
  position: absolute;
  width: 55px;
  height: 28px;
  z-index: 5;
  filter: drop-shadow(0 0 12px rgba(212, 168, 67, 0.6));
  pointer-events: none;
}

.snitch svg {
  width: 100%;
  height: 100%;
}

.snitch.caught {
  animation: caughtFlash 0.4s ease-out forwards;
}

@keyframes caughtFlash {
  0% { filter: drop-shadow(0 0 30px rgba(255, 230, 100, 1)) brightness(2); transform: scale(1.5); }
  100% { filter: drop-shadow(0 0 0px transparent) brightness(1); transform: scale(0); opacity: 0; }
}

.snitch::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 6px;
  height: 6px;
  background: var(--gold);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow:
    0 0 8px var(--gold),
    -8px 4px 5px rgba(212, 168, 67, 0.3),
    -16px 2px 4px rgba(212, 168, 67, 0.2);
  pointer-events: none;
  opacity: 0.5;
}

/* ===== Catch Effect ===== */

.catch-effect {
  position: absolute;
  font-family: 'Cinzel Decorative', cursive;
  font-size: 2rem;
  color: var(--gold);
  text-shadow: 0 0 15px rgba(212, 168, 67, 0.8);
  pointer-events: none;
  opacity: 0;
  z-index: 20;
}

.catch-effect.show {
  animation: catchPop 0.8s ease-out forwards;
}

@keyframes catchPop {
  0% { opacity: 1; transform: translateY(0) scale(0.5); }
  50% { opacity: 1; transform: translateY(-30px) scale(1.2); }
  100% { opacity: 0; transform: translateY(-60px) scale(0.8); }
}

.spark {
  position: absolute;
  width: 4px;
  height: 4px;
  background: var(--gold);
  border-radius: 50%;
  pointer-events: none;
  z-index: 15;
}

.spark.animate {
  animation: sparkBurst 0.5s ease-out forwards;
}

@keyframes sparkBurst {
  0% { opacity: 1; transform: translate(0, 0) scale(1); }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0); }
}

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

.result-score {
  font-family: 'Cinzel Decorative', cursive;
  font-size: 1.4rem;
  color: var(--gold);
  margin-bottom: 0.5rem;
  line-height: 1.6;
}

.result-msg {
  font-size: 1.05rem;
  line-height: 1.6;
  opacity: 0.85;
  max-width: 400px;
  margin: 0 auto 2rem;
}

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

/* ===== Touch Joysticks (Multi Mobile) ===== */

.joysticks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  justify-items: center;
  padding: 0.5rem;
  gap: 0.5rem;
  max-width: 320px;
  margin: 0 auto;
}

.joystick-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
}

.joy-label {
  font-family: 'Cinzel Decorative', cursive;
  font-size: 0.7rem;
  color: var(--gold);
  opacity: 0.6;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.joysticks.solo {
  grid-template-columns: 1fr;
  max-width: 160px;
}

.joystick {
  position: relative;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid rgba(212, 168, 67, 0.3);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
}

.joystick-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(212, 168, 67, 0.6);
  transform: translate(-50%, -50%);
  pointer-events: none;
  box-shadow: 0 0 10px rgba(212, 168, 67, 0.3);
}

.game-field.with-joysticks {
  height: 40vh;
  min-height: 200px;
}

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

@media (max-width: 1024px) and (min-width: 601px) {
  .player {
    width: 60px;
    height: 30px;
  }

  .snitch {
    width: 42px;
    height: 21px;
  }

  .game-field {
    height: 55vh;
  }
}

@media (max-width: 600px) {
  .game-field {
    height: 55vh;
    min-height: 280px;
    border-radius: 12px;
  }

  .joystick {
    width: 85px;
    height: 85px;
  }

  .joystick-knob {
    width: 34px;
    height: 34px;
  }

  .joysticks {
    max-width: 260px;
    gap: 0.4rem;
  }

  .mode-btn {
    font-size: 0.8rem;
    padding: 0.4rem 0.8rem;
  }

  .player-setup {
    padding: 0.5rem;
  }

  .house-btn {
    font-size: 0.75rem;
    padding: 0.3rem 0.5rem;
  }

  .game-hud {
    gap: 1.2rem;
  }

  .hud-value {
    font-size: 1.4rem;
  }

  .player {
    width: 55px;
    height: 28px;
  }

  .snitch {
    width: 40px;
    height: 20px;
  }

  .diff-btn {
    min-width: 100px;
    padding: 0.5rem 0.8rem;
    font-size: 0.9rem;
  }

  .intro-preview {
    gap: 0.4rem;
  }

  .broom-preview {
    width: 75px;
  }
}
