/*
  Spinner Wheel. Loaded only on its project page. Plain CSS, not built by
  Tailwind; colours come from the site's theme tokens, so dark mode just works.
  The slices themselves are drawn on a canvas by app.js.
*/

.wheel {
  --hub: 25%;            /* hub diameter, as a share of the wheel */
  --ring: #d8dbe2;
  --ring-edge: #9aa1ad;
  --ring-shade: rgb(20 26 40 / 0.18);
  --glass: rgb(255 255 255 / 0.95);
}

[data-theme="dark"] .wheel {
  --ring: #333c49;
  --ring-edge: #1c222b;
  --ring-shade: rgb(0 0 0 / 0.5);
  --glass: rgb(24 30 38 / 0.95);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .wheel {
    --ring: #333c49;
    --ring-edge: #1c222b;
    --ring-shade: rgb(0 0 0 / 0.5);
    --glass: rgb(24 30 38 / 0.95);
  }
}

/* ---- Stage --------------------------------------------------------------- */

.wheel-stage {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.wheel-frame {
  position: relative;
  width: 100%;
  max-width: 32rem;
  margin: 0 auto;
  aspect-ratio: 1;
  touch-action: pan-y;            /* flick the wheel sideways; still scroll the page */
  user-select: none;
  -webkit-user-select: none;
}

.wheel-canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  cursor: grab;
  /* box-shadow, not drop-shadow: a filter would re-read the whole canvas on
     every frame of a spin, which is exactly when there is no time for it. */
  box-shadow: 0 10px 26px var(--ring-shade);
}

.wheel-frame.is-dragging .wheel-canvas { cursor: grabbing; }
.wheel-frame.is-spinning .wheel-canvas { cursor: default; }

/* Confetti gets a little room to fly outside the wheel. */
.wheel-confetti {
  position: absolute;
  inset: -12%;
  width: 124%;
  height: 124%;
  pointer-events: none;
  z-index: 3;
}

/* ---- The flapper at the top --------------------------------------------- */

.wheel-pointer {
  position: absolute;
  top: -3%;
  left: 50%;
  width: 10%;
  min-width: 28px;
  transform-origin: 50% 20%;
  transform: translateX(-50%) rotate(0deg);
  z-index: 4;
  pointer-events: none;
  will-change: transform;
}

.wheel-flapper {
  display: block;
  width: 100%;
  height: auto;
  fill: var(--color-base-content);
}

.wheel-flapper path {
  stroke: var(--color-base-100);
  stroke-width: 2.5;
  paint-order: stroke;
}

.wheel-flapper-pin { fill: var(--color-base-100); }

/* ---- The hub, which is also the spin button ----------------------------- */

.wheel-hub {
  position: absolute;
  top: 50%;
  left: 50%;
  width: var(--hub);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border: 0;
  padding: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  z-index: 5;
  -webkit-tap-highlight-color: transparent;
}

.wheel-hub-face {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background:
    radial-gradient(circle at 34% 28%, rgb(255 255 255 / 0.55), transparent 58%),
    linear-gradient(160deg, var(--ring), var(--ring-edge));
  box-shadow:
    0 0 0 2px var(--color-base-100),
    0 0 0 4px var(--ring-shade),
    0 6px 14px var(--ring-shade),
    inset 0 -2px 6px rgb(0 0 0 / 0.22);
  color: var(--color-base-content);
  transition: transform 140ms cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 140ms ease;
}

.wheel-hub-word {
  font-weight: 800;
  font-stretch: 118%;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: clamp(0.8125rem, 3.4cqw, 1.25rem);
}

.wheel-frame { container-type: inline-size; }

.wheel-hub:hover .wheel-hub-face { transform: scale(1.05); }
.wheel-hub:active .wheel-hub-face { transform: scale(0.94); }
.wheel-hub:focus-visible { outline: none; }
.wheel-hub:focus-visible .wheel-hub-face {
  box-shadow:
    0 0 0 2px var(--color-base-100),
    0 0 0 5px var(--color-secondary),
    0 6px 14px var(--ring-shade);
}

/* A slow breath while the wheel is sitting there waiting to be pressed. It's a
   ring of its own fading in and out: opacity and transform stay on the
   compositor, where an animated box-shadow would repaint the hub every frame. */
.wheel-hub-face::after {
  content: "";
  position: absolute;
  inset: -7%;
  border-radius: 50%;
  box-shadow: 0 0 0 3px var(--ring-shade);
  opacity: 0;
  pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
  .wheel:not(.is-spinning) .wheel-hub-face::after { animation: wheel-breathe 3.6s ease-in-out infinite; }
}

@keyframes wheel-breathe {
  0%, 100% { opacity: 0; transform: scale(0.97); }
  50% { opacity: 0.6; transform: scale(1.05); }
}

.wheel.is-spinning .wheel-hub { cursor: default; }
.wheel.is-spinning .wheel-hub-word { opacity: 0.5; }

/* ---- Empty state and the winner ----------------------------------------- */

.wheel-empty {
  position: absolute;
  inset: 12%;
  display: grid;
  place-items: center;
  border-radius: 50%;
  text-align: center;
  color: var(--muted);
  font-size: 0.9375rem;
  padding: 2rem;
  z-index: 2;
}

.wheel-result {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 6;
  padding: 6%;
}

.wheel-result-card {
  width: 100%;
  max-width: 24rem;
  border-radius: 1rem;
  border: 1px solid var(--color-base-300);
  /* Nearly opaque rather than blurred: a backdrop-filter would have to re-blur
     the spinning wheel and the confetti behind it on every frame. */
  background: var(--glass);
  box-shadow: 0 18px 40px var(--ring-shade);
  padding: 1.25rem 1rem;
  text-align: center;
  animation: wheel-pop 420ms cubic-bezier(0.22, 1.4, 0.4, 1) both;
}

@keyframes wheel-pop {
  from { transform: scale(0.72) translateY(10px); opacity: 0; }
  60% { transform: scale(1.04); opacity: 1; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}

.wheel-result-kicker {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.wheel-result-name {
  margin-top: 0.35rem;
  font-weight: 800;
  font-stretch: 118%;
  font-size: clamp(1.5rem, 7cqw, 2.5rem);
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.wheel-result-actions {
  margin-top: 0.9rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4rem;
}

/* ---- Segmented control --------------------------------------------------- */

.wheel-seg {
  display: inline-flex;
  overflow: hidden;
  border: 1px solid var(--color-base-300);
  border-radius: 0.625rem;
  background: var(--color-base-100);
}

.wheel-seg button {
  font: inherit;
  font-size: 0.875rem;
  color: var(--color-base-content);
  background: transparent;
  border-right: 1px solid var(--color-base-300);
  padding: 0.3125rem 0.75rem;
  cursor: pointer;
}

.wheel-seg button:last-child { border-right: 0; }
.wheel-seg button[aria-pressed="true"] {
  background: var(--color-base-content);
  color: var(--color-base-100);
  font-weight: 600;
}
.wheel-seg button:focus-visible { outline-offset: -3px; }

/* ---- Small bits ---------------------------------------------------------- */

[data-sound][aria-pressed="true"] .wheel-sound-off,
[data-sound][aria-pressed="false"] .wheel-sound-on { display: none; }

.wheel [data-history] li {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.25rem 0;
}

.wheel [data-history] li span:first-child { overflow-wrap: anywhere; }
.wheel [data-history] li span:last-child { color: var(--muted); white-space: nowrap; }

.wheel [data-history] li.is-new { animation: wheel-slide-in 320ms ease both; }

@keyframes wheel-slide-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: none; }
}

/* ---- Fullscreen ---------------------------------------------------------- */

.wheel-stage:fullscreen {
  background: var(--color-base-200);
  padding: 2rem;
}

.wheel-stage:fullscreen .wheel-frame {
  max-width: min(92vw, 78vh);
}

@media (prefers-reduced-motion: reduce) {
  .wheel-result-card { animation-duration: 1ms; }
  .wheel [data-history] li.is-new { animation: none; }
}
