:root {
  --red: #e23d3d;
  --blue: #2b6fd6;
  --yellow: #f6c21c;
  --green: #2fa457;
  --ink: #1d1b26;
  --white: #fff;

  /* The whole page takes on the colour of the latest spin (set from app.js). */
  --page: var(--white);
  --on-page: var(--ink);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--on-page);
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-weight: 700;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.35s, color 0.35s;
}

.app {
  min-height: 100dvh;
  max-width: 28rem;
  margin: 0 auto;
  padding: max(1.25rem, env(safe-area-inset-top)) 1.25rem max(1.5rem, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

h1 {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  opacity: 0.75;
}

/* ---------- Wheel ---------- */

.wheel {
  width: min(100%, 50dvh);
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
}

.wheel:focus-visible,
.spin:focus-visible,
input:focus-visible {
  outline: 3px solid var(--on-page);
  outline-offset: 3px;
}

.wheel svg {
  display: block;
  width: 100%;
  height: 100%;
}

.plate {
  fill: var(--white);
}

.wedge {
  stroke: var(--white);
  stroke-width: 1.5;
  transition: opacity 0.3s;
}

.has-result .wedge:not(.win) {
  opacity: 0.25;
}

.divider {
  stroke: #e6e4ea;
  stroke-width: 1;
}

.limb {
  color: var(--ink);
  transition: opacity 0.3s;
}

.has-result .limb:not(.win) {
  opacity: 0.25;
}

.limb-icon {
  fill: currentColor;
}

.limb-icon .strokes {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
}

.limb-label {
  fill: currentColor;
  font-size: 5.5px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-anchor: middle;
}

.needle {
  transform-origin: 0 0;
  transition: transform 3s cubic-bezier(0.12, 0.7, 0.1, 1);
}

.needle polygon,
.needle circle {
  fill: var(--ink);
  stroke: var(--white);
  stroke-width: 1.25;
  stroke-linejoin: round;
}

/* Ring around the wheel that drains until the next auto-spin. */
.countdown {
  fill: none;
  stroke: var(--ink);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-dasharray: 100;
  stroke-dashoffset: 100;
  transform: rotate(-90deg);
  opacity: 0;
  transition: opacity 0.2s;
}

.is-auto .countdown {
  opacity: 1;
}

/* ---------- Result ---------- */

.result {
  margin: 0;
  min-height: 5.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  text-transform: uppercase;
  line-height: 1;
}

.result .hint {
  font-size: 1rem;
  letter-spacing: 0.1em;
  opacity: 0.6;
}

.result .limb {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: 0.1em;
}

.result .color {
  font-size: clamp(3rem, 16vw, 4rem);
  font-weight: 900;
  letter-spacing: 0.02em;
}

.result.pop {
  animation: pop 0.35s cubic-bezier(0.2, 1.6, 0.4, 1);
}

@keyframes pop {
  from {
    transform: scale(0.85);
    opacity: 0.4;
  }
}

/* ---------- Spin button ---------- */

.spin {
  width: 100%;
  padding: 0.95rem 1rem;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: var(--white);
  font: inherit;
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.1s, opacity 0.2s;
}

.spin:active:not(:disabled) {
  transform: scale(0.97);
}

.spin:disabled {
  opacity: 0.5;
  cursor: default;
}

/* ---------- Controls ---------- */

.controls {
  width: 100%;
  border-radius: 1.25rem;
  background: var(--white);
  color: var(--ink);
  box-shadow: 0 0 0 1px rgb(29 27 38 / 0.08);
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  cursor: pointer;
}

.row + .row {
  border-top: 1px solid #eeecf1;
}

.row-range span {
  flex: none;
  min-width: 5.5rem;
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  flex: 1;
  min-width: 0;
  margin: 0;
  accent-color: var(--ink);
}

input[role="switch"] {
  appearance: none;
  flex: none;
  width: 3rem;
  height: 1.75rem;
  margin: 0;
  border-radius: 999px;
  background: #d9d6e0;
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
}

input[role="switch"]::after {
  content: "";
  position: absolute;
  top: 0.2rem;
  left: 0.2rem;
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 50%;
  background: var(--white);
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.3);
  transition: transform 0.2s;
}

input[role="switch"]:checked {
  background: var(--green);
}

input[role="switch"]:checked::after {
  transform: translateX(1.25rem);
}

input[role="switch"]:disabled {
  opacity: 0.5;
  cursor: default;
}

@media (prefers-reduced-motion: reduce) {
  body {
    transition: none;
  }

  .result.pop {
    animation: none;
  }
}
