/**
 * Hogwarts Sorting Hat 2026
 * Created / made by Billy Hawkins
 * Contact: billy@soniq.org
 * https://soniq.org · https://soniqdesigns.com
 *
 * Copyright (c) 2026 Billy Hawkins / Soniq. All rights reserved.
 */
:root {
  --bg: #050308;
  --accent: #d4af37;
  --parchment: #f4e4b0;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--parchment);
}
html, body.hall-body {
  height: 100dvh;
  height: 100svh;
  overflow: hidden;
}
body.hall-body {
  overflow: hidden;
  background:
    radial-gradient(ellipse at 50% 110%, rgba(212, 175, 55, 0.08), transparent 45%),
    radial-gradient(circle at 20% 10%, rgba(90, 20, 80, 0.18), transparent 30%),
    radial-gradient(circle at 80% 20%, rgba(20, 40, 90, 0.18), transparent 28%),
    var(--bg);
}

.hall {
  height: 100dvh;
  height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(0.35rem, 1.4vh, 1rem);
  padding:
    max(0.45rem, env(safe-area-inset-top))
    max(0.7rem, env(safe-area-inset-right))
    max(0.45rem, env(safe-area-inset-bottom))
    max(0.7rem, env(safe-area-inset-left));
  text-align: center;
  overflow: hidden;
}

.copy {
  max-width: 42rem;
  margin: 0;
  line-height: 1.35;
  letter-spacing: 0.02em;
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.65);
}
.copy.header { font-weight: 700; }
.copy.subheader { opacity: 0.95; }
.copy.footer { opacity: 0.88; }

.hero-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(0.45rem, 1.4vh, 1rem);
  width: min(92vw, 520px);
  flex: 1 1 auto;
  min-height: 0;
}

.hat-hero {
  position: relative;
  width: min(52vw, 36vh, 280px);
  margin: 0;
  filter: drop-shadow(0 18px 36px rgba(0, 0, 0, 0.55));
}

.hat-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 525 / 700;
  z-index: 3;
  transform-origin: 50% 60%;
  animation: hat-breathe 8s ease-in-out infinite;
}

.hat-photo,
.hat-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  pointer-events: none;
}

.hat-photo.is-puppeted {
  opacity: 0;
}

.talking-hat.is-casting {
  width: min(48vw, 32vh, 240px);
}

.talking-hat.is-casting .hat-stage {
  animation-duration: 5s;
}

.hat-glow {
  position: absolute;
  left: 12%;
  right: 12%;
  top: 8%;
  bottom: 18%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(90, 140, 255, 0.28), rgba(212, 175, 55, 0.08) 42%, transparent 70%);
  filter: blur(18px);
  z-index: 1;
  animation: glow-pulse 4.5s ease-in-out infinite;
}

.talking-hat.is-casting .hat-glow {
  animation-duration: 2.2s;
  background: radial-gradient(circle, rgba(120, 170, 255, 0.45), rgba(212, 175, 55, 0.16) 40%, transparent 70%);
}

.talking-hat.is-talking .hat-glow {
  opacity: 1;
  transform: scale(1.06);
}

.qr-wrap {
  position: relative;
  z-index: 4;
  padding: 10px;
  background: #f7f1de;
  border-radius: 10px;
  box-shadow:
    0 0 0 3px rgba(212, 175, 55, 0.35),
    0 10px 30px rgba(0, 0, 0, 0.45);
}
.qr-wrap svg,
.qr-wrap img,
.qr-wrap table {
  display: block;
  width: var(--qr-size, 168px);
  height: var(--qr-size, 168px);
}

.smoke {
  position: absolute;
  left: 50%;
  bottom: 38%;
  width: 72%;
  height: 48%;
  transform: translateX(-50%);
  z-index: 2;
  pointer-events: none;
}
.smoke span {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 70px;
  height: 70px;
  margin-left: -35px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(90, 140, 255, 0.85), rgba(40, 20, 90, 0.05) 70%);
  filter: blur(10px);
  animation: rise 4.8s ease-in infinite;
  opacity: 0.7;
}
.smoke span:nth-child(2) { animation-delay: 0.8s; width: 90px; margin-left: -20px; }
.smoke span:nth-child(3) { animation-delay: 1.6s; width: 60px; margin-left: -50px; }
.smoke span:nth-child(4) { animation-delay: 2.4s; width: 80px; margin-left: -10px; }
.smoke span:nth-child(5) { animation-delay: 3.2s; width: 50px; margin-left: -40px; }

@keyframes rise {
  0% { transform: translateY(10px) scale(0.6); opacity: 0; }
  25% { opacity: 0.8; }
  100% { transform: translateY(-180px) scale(1.4); opacity: 0; }
}

.sparkles {
  position: absolute;
  inset: 4% 10% 30%;
  z-index: 4;
  pointer-events: none;
}
.sparkles i {
  position: absolute;
  width: 6px;
  height: 6px;
  background: #f4e4b0;
  border-radius: 50%;
  box-shadow: 0 0 10px #d4af37;
  opacity: 0;
  animation: twinkle 3.6s ease-in-out infinite;
}
.sparkles i:nth-child(1) { left: 18%; top: 22%; animation-delay: 0.2s; }
.sparkles i:nth-child(2) { left: 72%; top: 16%; animation-delay: 0.8s; }
.sparkles i:nth-child(3) { left: 12%; top: 48%; animation-delay: 1.3s; }
.sparkles i:nth-child(4) { left: 84%; top: 40%; animation-delay: 1.8s; }
.sparkles i:nth-child(5) { left: 30%; top: 8%; animation-delay: 2.2s; width: 4px; height: 4px; }
.sparkles i:nth-child(6) { left: 60%; top: 52%; animation-delay: 2.7s; }
.sparkles i:nth-child(7) { left: 48%; top: 4%; animation-delay: 0.5s; width: 5px; height: 5px; }
.sparkles i:nth-child(8) { left: 78%; top: 28%; animation-delay: 3.1s; }

@keyframes hat-breathe {
  0%, 100% { transform: perspective(900px) rotateX(2deg) rotateY(-2.2deg) translateY(0); }
  50% { transform: perspective(900px) rotateX(-1.4deg) rotateY(2deg) translateY(-6px); }
}
@keyframes glow-pulse {
  0%, 100% { opacity: 0.55; transform: scale(0.96); }
  50% { opacity: 0.95; transform: scale(1.05); }
}
@keyframes twinkle {
  0%, 100% { opacity: 0; transform: scale(0.4); }
  40% { opacity: 0.95; transform: scale(1); }
  70% { opacity: 0.2; }
}

.construction {
  height: 100dvh;
  height: 100svh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 2rem 1.2rem;
  text-align: center;
}
.construction > img {
  max-width: min(90vw, 520px);
  max-height: 42vh;
  object-fit: contain;
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.sort-stage {
  height: 100dvh;
  height: 100svh;
  display: grid;
  place-items: center;
  padding:
    max(0.5rem, env(safe-area-inset-top))
    max(0.7rem, env(safe-area-inset-right))
    max(0.5rem, env(safe-area-inset-bottom))
    max(0.7rem, env(safe-area-inset-left));
  text-align: center;
  overflow: hidden;
  position: relative;
}
.sort-stage .whisper {
  max-width: 28rem;
  z-index: 2;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.45s ease, transform 0.45s ease;
}
.sort-stage .whisper.is-on {
  opacity: 1;
  transform: none;
}
.sort-stage .burst {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, rgba(244, 228, 176, 0.9), transparent 55%);
  opacity: 0;
  animation: burst 16s ease forwards;
}
.sort-cast {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.8rem;
  z-index: 2;
}

@keyframes burst {
  0%, 82% { opacity: 0; }
  92% { opacity: 1; }
  100% { opacity: 0.35; }
}

.empty-links {
  max-width: 28rem;
  padding: 2rem;
}

.already-sorted {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
  z-index: 2;
  max-width: 36rem;
  max-height: 100%;
  padding: 0 0.6rem;
  overflow: hidden;
}
.already-sorted[hidden],
.sort-cast[hidden] {
  display: none !important;
}
.already-sorted .hat-hero {
  width: min(42vw, 24vh, 180px);
}
.hall-btn {
  appearance: none;
  display: inline-block;
  border: 0;
  background: #d4af37;
  color: #12080a;
  padding: 0.7rem 1.1rem;
  border-radius: 999px;
  font: 0.95rem/1.2 Cinzel, serif;
  text-decoration: none;
  cursor: pointer;
}
.hall-btn.ghost {
  background: transparent;
  color: #f4e4b0;
  border: 1px solid rgba(212, 175, 55, 0.45);
}
.reset-help {
  max-width: 28rem;
  opacity: 0.85;
}

@media (max-width: 640px), (max-height: 900px) {
  .copy { max-width: 94vw; }
  .copy.header { font-size: min(var(--copy-size, 28px), 5.6vw) !important; line-height: 1.15; }
  .copy.subheader { font-size: min(var(--copy-size, 16px), 3.5vw) !important; line-height: 1.25; }
  .copy.footer, .reset-help { font-size: min(var(--copy-size, 14px), 3.2vw) !important; }
  .hat-hero { width: min(48vw, 34vh, 210px); }
  .qr-wrap { padding: 6px; }
  .qr-wrap svg,
  .qr-wrap img,
  .qr-wrap table {
    width: min(var(--qr-size, 168px), 22vw, 96px);
    height: min(var(--qr-size, 168px), 22vw, 96px);
  }
  .hall-btn { padding: 0.5rem 0.8rem; font-size: 0.82rem; }
}

@media (orientation: landscape) and (max-height: 700px) {
  .hall { flex-direction: row; flex-wrap: wrap; justify-content: center; }
  .hero-stage { flex-direction: row; width: auto; max-width: 92vw; flex: 0 1 auto; }
  .hat-hero { width: min(28vw, 46vh, 200px); }
  .copy { max-width: 46vw; }
}
