:root {
  --bg: #120f1f;
  --surface: #1e1a31;
  --surface-2: #2a2444;
  --text: #f5f3ff;
  --muted: #a49fbf;
  --accent: #ff3d7f;
  --accent-2: #7c4dff;
  --error: #ff8a8a;
  --radius: 16px;
  --gradient: linear-gradient(135deg, var(--accent), var(--accent-2));
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button,
input {
  font: inherit;
  color: inherit;
}

h1,
h2,
h3 {
  margin: 0;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.85rem;
}

.error {
  color: var(--error);
  margin: 8px 0 0;
}

.error:empty {
  display: none;
}

/* ---------- layout ---------- */

.screen {
  min-height: 100dvh;
  padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  max-width: 520px;
  margin: 0 auto;
}

.center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  text-align: center;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 320px;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  min-height: 44px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.card h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 12px;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 20px;
  border: 0;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.2s;
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.btn.primary {
  background: var(--gradient);
  color: #fff;
}

.btn.big {
  min-height: 56px;
  font-size: 1.1rem;
  width: 100%;
}

.btn.small {
  min-height: 40px;
  padding: 0 16px;
  font-size: 0.9rem;
}

.btn.active {
  outline: 2px solid var(--accent);
}

.btn.ghost {
  background: transparent;
  border: 1px solid var(--surface-2);
  color: var(--muted);
}

.icon-btn {
  width: 44px;
  height: 44px;
  flex: none;
  border: 0;
  border-radius: 50%;
  background: var(--surface-2);
  font-size: 1.2rem;
  cursor: pointer;
}

.icon-btn:disabled {
  opacity: 0.3;
}

.link {
  background: none;
  border: 0;
  color: var(--muted);
  text-decoration: underline;
  cursor: pointer;
}

.input {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: var(--surface-2);
  outline: none;
}

.input:focus {
  border-color: var(--accent);
}

/* ---------- start ---------- */

.logo {
  font-size: clamp(2.6rem, 12vw, 4rem);
  font-weight: 900;
  letter-spacing: -0.03em;
}

.logo span {
  background: var(--gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ---------- settings ---------- */

.players {
  list-style: none;
  padding: 0;
  margin: 0 0 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.players li {
  display: flex;
  gap: 8px;
}

.stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
}

.stepper output {
  font-size: 2.2rem;
  font-weight: 800;
  min-width: 2ch;
  text-align: center;
}

.source {
  font-weight: 600;
  margin: 0 0 12px;
}

#panel:not(:empty) {
  margin-top: 12px;
}

.playlist-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 300px;
  overflow-y: auto;
}

.playlist-list button {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 12px 8px;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--surface-2);
  text-align: left;
  cursor: pointer;
}

.paste {
  display: flex;
  gap: 8px;
}

.device-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.device {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 2px solid transparent;
  background: var(--surface-2);
  text-align: left;
  cursor: pointer;
}

.device.selected {
  border-color: var(--accent);
}

.device.unavailable {
  opacity: 0.6;
  cursor: default;
}

.steps {
  text-align: left;
  margin: 0;
  padding-left: 20px;
  line-height: 1.6;
}

.devices-box {
  text-align: left;
}

.devices-box h3 {
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.debug {
  width: 100%;
  text-align: left;
  color: var(--muted);
  font-size: 0.8rem;
}

.debug pre {
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--surface);
  border-radius: 12px;
  padding: 12px;
}

/* ---------- loading ---------- */

.spinner {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 4px solid var(--surface-2);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

.spinner.small {
  width: 24px;
  height: 24px;
  border-width: 3px;
  margin: 8px auto;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- playing ---------- */

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

.playing .bar {
  width: 100%;
  justify-content: space-between;
}

.round {
  font-weight: 700;
  color: var(--muted);
}

.pulse {
  position: relative;
  width: 260px;
  height: 260px;
  margin: auto 0 24px;
  display: grid;
  place-items: center;
}

.playing > .muted {
  margin: 0 0 auto;
}

.ring {
  position: absolute;
  inset: 50px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  opacity: 0;
  animation: ripple 3s ease-out infinite;
}

.ring:nth-child(2) {
  animation-delay: 1s;
}

.ring:nth-child(3) {
  animation-delay: 2s;
}

@keyframes ripple {
  0% {
    transform: scale(0.85);
    opacity: 0.7;
  }
  100% {
    transform: scale(1.6);
    opacity: 0;
  }
}

.orbit {
  position: absolute;
  inset: 34px;
  border-radius: 50%;
  background: conic-gradient(from 0deg, transparent 0 60%, var(--accent-2) 85%, var(--accent));
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3px));
  animation: spin 2.4s linear infinite;
}

.stop-btn {
  position: relative;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  border: 0;
  background: var(--gradient);
  box-shadow: 0 10px 40px rgba(255, 61, 127, 0.35);
  display: grid;
  place-items: center;
  cursor: pointer;
  animation: breathe 2s ease-in-out infinite;
}

.stop-btn:active {
  transform: scale(0.95);
}

.stop-icon {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: #fff;
}

@keyframes breathe {
  50% {
    transform: scale(1.04);
  }
}

/* ---------- reveal ---------- */

.reveal {
  position: relative;
  height: 100dvh;
  overflow: hidden;
  padding: 0;
}

.answer {
  position: absolute;
  left: 16px;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  text-align: center;
  transition: top 0.6s ease, transform 0.6s ease;
  animation: pop 0.5s ease-out;
}

.answer .year {
  font-size: clamp(5rem, 30vw, 10rem);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.04em;
  background: var(--gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  transition: font-size 0.6s ease;
}

.answer .title {
  font-size: clamp(1.6rem, 7vw, 2.4rem);
  font-weight: 800;
  margin-top: 16px;
  transition: font-size 0.6s ease, margin 0.6s ease;
}

.answer .artist {
  font-size: clamp(1.2rem, 5vw, 1.6rem);
  color: var(--muted);
  margin-top: 8px;
  transition: font-size 0.6s ease, margin 0.6s ease;
}

.compact .answer {
  top: max(16px, env(safe-area-inset-top));
  transform: translateY(0);
}

.compact .answer .year {
  font-size: 3.5rem;
}

.compact .answer .title {
  font-size: 1.25rem;
  margin-top: 4px;
}

.compact .answer .artist {
  font-size: 1rem;
  margin-top: 2px;
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(-50%) scale(0.9);
  }
}

.pick {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  top: 100%;
  overflow-y: auto;
  padding: 0 16px max(24px, env(safe-area-inset-bottom));
  opacity: 0;
  transform: translateY(16px);
  pointer-events: none;
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.pick.show {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.pick h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 12px;
  text-align: center;
}

.pick-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 10px;
}

.btn.player {
  justify-content: space-between;
  border-radius: var(--radius);
  min-height: 60px;
  font-size: 1.1rem;
  background: var(--surface);
}

.btn.player .score {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.95rem;
}

.pick .btn.ghost {
  width: 100%;
}

/* ---------- victory ---------- */

.victory {
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.podium {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 8px;
  position: relative;
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
  font-weight: 700;
  font-size: 0.85rem;
}

.trophy {
  font-size: 4.5rem;
  animation: pop 0.6s ease-out;
}

.winner {
  font-size: clamp(2.2rem, 11vw, 3.5rem);
  font-weight: 900;
  word-break: break-word;
}

.maniac-line {
  margin: 4px 0 0;
  font-size: 1.2rem;
  font-weight: 700;
}

.maniac {
  display: block;
  margin-top: 6px;
  font-family: 'Bangers', 'Impact', system-ui, sans-serif;
  font-size: clamp(2.8rem, 14vw, 4.5rem);
  font-weight: 400;
  letter-spacing: 0.04em;
  line-height: 1.05;
  transform: rotate(-4deg);
}

.maniac span {
  display: inline-block;
  background: linear-gradient(90deg, #ff3d7f, #ffb300, #2ee59d, #3dc2ff, #a64dff, #ff3d7f);
  background-size: 600% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 3px 0 rgba(0, 0, 0, 0.55));
  animation:
    rainbow 2.5s linear infinite,
    wobble 1.1s ease-in-out infinite;
  animation-delay: calc(var(--i) * -0.18s), calc(var(--i) * 0.08s);
}

@keyframes rainbow {
  to {
    background-position: 600% 0;
  }
}

@keyframes wobble {
  0%,
  100% {
    transform: translateY(0) rotate(0deg);
  }
  25% {
    transform: translateY(-8px) rotate(-6deg);
  }
  75% {
    transform: translateY(4px) rotate(6deg);
  }
}

.places {
  list-style: none;
  padding: 0;
  margin: 24px 0 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.places li {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  text-align: left;
}

.places .place {
  width: 36px;
  height: 36px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface-2);
  font-weight: 800;
}

.places .names {
  flex: 1;
  font-weight: 700;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
}

.confetti i {
  position: absolute;
  top: -12px;
  width: 8px;
  height: 14px;
  border-radius: 2px;
  background: hsl(var(--hue) 90% 65%);
  animation: fall linear infinite;
}

@keyframes fall {
  to {
    transform: translateY(105dvh) rotate(540deg);
  }
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: max(24px, env(safe-area-inset-bottom));
  max-width: 480px;
  margin: 0 auto;
  padding: 14px 18px;
  border-radius: 12px;
  background: var(--surface-2);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
  z-index: 10;
  transition: opacity 0.4s;
}

.toast.hide {
  opacity: 0;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
