@property --ring-rotation {
  syntax: '<angle>';
  inherits: true;
  initial-value: 0deg;
}

:root {
  --bg: #1a0b2e;
  --bg-deep: #0f0620;
  --magenta: #ff2e9a;
  --cyan: #00e5ff;
  --gold: #ffc700;
  --violet: #7b2ff7;
  --ink: #fdf6ff;
  --ink-dim: #c9b8e8;

  --ring-radius: clamp(112px, 30vw, 200px);
  --head-size: clamp(60px, 15vw, 92px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
}

body {
  color: var(--ink);
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100svh;
  padding: env(safe-area-inset-top, 0px) 16px calc(env(safe-area-inset-bottom, 0px) + 24px);
  position: relative;
}

.sky {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(60% 45% at 50% 18%, rgba(255, 199, 0, 0.16), transparent 70%),
    radial-gradient(80% 60% at 15% 85%, rgba(123, 47, 247, 0.35), transparent 65%),
    radial-gradient(80% 60% at 85% 85%, rgba(0, 229, 255, 0.18), transparent 65%),
    linear-gradient(180deg, var(--bg-deep), var(--bg) 55%, var(--bg-deep));
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- stage ---------- */

.stage {
  position: relative;
  width: 100%;
  max-width: 560px;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.figure {
  --figure-width: min(50vw, 220px);
  position: relative;
  width: var(--figure-width);
  aspect-ratio: 1024 / 1536;
  /* The ring's bottom slot is pinned to 8.85% down the figure (the body
     photo's socket) and the halo extends 2*radius + head-size above the
     ring's own center — so the figure needs that much headroom above its
     own top edge, minus the slice of figure height already below 8.85%.
     1024/1536 is the body photo's aspect ratio; 8.85% * 1.5 (height/width)
     converts that vertical offset into a fraction of figure WIDTH so it
     can combine with the radius/head-size terms (also width-based). */
  margin-top: calc(2 * var(--ring-radius) + var(--head-size) / 2 - 0.1328 * var(--figure-width) + 12px);
}

.body-silhouette, .body-img {
  display: block;
  width: 100%;
  height: auto;
}

.figure:has(.body-img[data-loaded="true"]) .body-silhouette {
  display: none;
}

.body-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: none;
}

.body-img[data-loaded="true"] {
  display: block;
}

.socket {
  position: absolute;
  left: 50%;
  top: 8.85%;
  translate: -50% -50%;
  width: 25%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(255, 243, 207, 0.55), rgba(255, 199, 0, 0.25) 60%, transparent 100%);
  pointer-events: none;
}

.halo {
  position: absolute;
  left: 50%;
  top: calc(8.85% - 2 * var(--ring-radius) - var(--head-size) / 2);
  translate: -50% 0;
  width: calc(var(--ring-radius) * 2 + var(--head-size));
  aspect-ratio: 1;
}

.spotlight {
  position: absolute;
  inset: -18%;
  background: radial-gradient(closest-side, rgba(255, 255, 255, 0.10), rgba(255, 255, 255, 0) 72%);
  pointer-events: none;
}

.ring {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 1px;
  height: 1px;
  transform: translate(-50%, -50%);
}

.ring-head {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--head-size);
  height: var(--head-size);
  margin: calc(var(--head-size) / -2);
  transform:
    rotate(calc(var(--i) * (360deg / var(--count)) + var(--ring-rotation)))
    translateY(calc(-1 * var(--ring-radius)))
    rotate(calc((var(--i) * (360deg / var(--count)) + var(--ring-rotation)) * -1));
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--head-size) * 0.52);
  background: linear-gradient(160deg, rgba(255,255,255,0.14), rgba(255,255,255,0.02));
  border: 2px solid rgba(253, 246, 255, 0.25);
  box-shadow: 0 4px 18px rgba(0,0,0,0.35);
  transition: box-shadow 0.35s ease, border-color 0.35s ease;
}

.ring-head.is-active {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(255, 199, 0, 0.35), 0 0 22px rgba(255, 199, 0, 0.55);
  z-index: 1;
}

.ring-head .head-img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: none;
}

.ring-head .head-img[data-loaded="true"] {
  display: block;
}

.ring-head.is-active .head-emoji {
  transform: scale(1.12);
}

.ring-head[data-has-img="true"] .head-emoji {
  display: none;
}

.hub {
  position: absolute;
  top: 50%;
  left: 50%;
  translate: -50% -50%;
  width: calc(var(--ring-radius) * 1.05);
  aspect-ratio: 1;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  pointer-events: none;
}

.wordmark {
  margin: 0;
  font-family: "Bungee", "Space Grotesk", sans-serif;
  font-size: clamp(1.1rem, 5.2vw, 1.9rem);
  line-height: 1.08;
  letter-spacing: 0.02em;
  background: linear-gradient(180deg, var(--gold), var(--magenta) 55%, var(--cyan));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 28px rgba(255, 46, 154, 0.35);
}

/* ---------- controls ---------- */

.controls {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(14px, 4vw, 28px);
  padding-top: clamp(20px, 5vh, 36px);
  width: 100%;
}

.rotate-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid rgba(253, 246, 255, 0.35);
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease, border-color 0.2s ease;
}

.rotate-btn:hover { background: rgba(255, 255, 255, 0.14); border-color: var(--cyan); }
.rotate-btn:active { transform: scale(0.92); }

.wheel-btn {
  --size: clamp(104px, 24vw, 136px);
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  position: relative;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: transparent;
  overflow: hidden;
}

.wheel-dial {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(
    var(--magenta) 0deg 60deg,
    var(--gold) 60deg 120deg,
    var(--cyan) 120deg 180deg,
    var(--violet) 180deg 240deg,
    var(--magenta) 240deg 300deg,
    var(--gold) 300deg 360deg
  );
  box-shadow:
    0 0 0 4px var(--bg-deep),
    0 0 0 7px rgba(253, 246, 255, 0.5),
    0 8px 24px rgba(0,0,0,0.45);
  transition: transform 0.15s ease;
}

.wheel-btn:hover .wheel-dial { transform: scale(1.03); }
.wheel-btn:active .wheel-dial { transform: scale(0.97); }

.wheel-btn.is-spinning .wheel-dial {
  animation: wheel-spin 2.4s cubic-bezier(.12, .78, .14, 1) 1;
}

@keyframes wheel-spin {
  to { transform: rotate(1256deg); }
}

.wheel-label {
  position: relative;
  z-index: 1;
  font-size: clamp(0.62rem, 2.1vw, 0.78rem);
  font-weight: 500;
  line-height: 1.3;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--bg-deep);
  background: rgba(253, 246, 255, 0.92);
  border-radius: 50%;
  width: 66%;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  text-align: center;
  overflow: hidden;
  padding: 4%;
}

.wheel-label strong {
  font-weight: 700;
  color: var(--magenta);
}

/* ---------- motion & accessibility ---------- */

@media (prefers-reduced-motion: reduce) {
  #ring,
  .ring-head,
  .wheel-btn.is-spinning .wheel-dial {
    animation: none !important;
    transition: none !important;
  }
}

:focus-visible {
  outline: 3px solid var(--cyan);
  outline-offset: 3px;
}
