:root {
  --ink: #2a2440;
  --aqua: #5cc9f5;
  --sun: #ffd25e;
  --rest: #8fe870;
  --bubble: #ff7ad9;
  --grape: #a98bff;
  --coral: #ff5a6e;
  --gold: #ffe45e;
  --paper: #fff7ef;
  --radius-s: 8px;
  --radius-m: 14px;
  --radius-l: 22px;
  --shadow-toy: 0 6px 0 rgba(42, 36, 64, 0.28);
  --shadow-panel: 0 12px 40px rgba(42, 36, 64, 0.22);
  --font: "Baloo 2", "Nunito", ui-rounded, system-ui, -apple-system, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: linear-gradient(180deg, #7fa8ff 0%, #ffe0c0 100%);
  font-family: var(--font);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
}

#stage {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.screen {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  pointer-events: none;
}

.screen[hidden] {
  display: none;
}

.screen--start,
.screen--lobby,
.screen--finish,
.screen--error {
  background: radial-gradient(
    120% 90% at 50% 0%,
    rgba(127, 168, 255, 0.55),
    rgba(42, 36, 64, 0.55)
  );
  backdrop-filter: blur(3px);
  pointer-events: auto;
}

.panel {
  width: min(520px, 100%);
  color: var(--ink);
  padding: 30px 32px 26px;
  border-radius: var(--radius-l);
  background: var(--paper);
  border: 3px solid var(--ink);
  box-shadow: var(--shadow-panel), var(--shadow-toy);
  animation: panel-in 260ms cubic-bezier(0.2, 0.9, 0.25, 1) both;
}

@keyframes panel-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
}

.logo {
  margin: 0 0 4px;
  font-size: clamp(38px, 7vw, 58px);
  line-height: 0.94;
  letter-spacing: -0.02em;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px;
}

.logo__wobble {
  color: var(--coral);
  transform: rotate(-4deg);
  display: inline-block;
  text-shadow: 0 4px 0 var(--ink);
}

.logo__rush {
  color: var(--aqua);
  transform: rotate(2deg);
  display: inline-block;
  text-shadow: 0 4px 0 var(--ink);
}

.logo__three {
  font-size: 0.5em;
  color: var(--paper);
  background: var(--ink);
  padding: 2px 10px;
  border-radius: var(--radius-s);
  transform: rotate(-2deg);
}

.tagline {
  margin: 2px 0 18px;
  font-size: 16px;
  opacity: 0.78;
}

.panel__title {
  margin: 0 0 10px;
  font-size: 30px;
}

.panel__hint {
  margin: 6px 0 14px;
  font-size: 14px;
  opacity: 0.7;
}

.field {
  display: block;
  margin-bottom: 14px;
}

.field--inline {
  margin-top: 12px;
}

.field__label {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.65;
  margin-bottom: 6px;
}

.field__input {
  width: 100%;
  padding: 12px 14px;
  font: inherit;
  font-size: 17px;
  color: var(--ink);
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: var(--radius-m);
  outline: none;
}

.field__input:focus-visible {
  box-shadow: 0 0 0 4px rgba(92, 201, 245, 0.55);
}

.field__input--code {
  text-transform: uppercase;
  letter-spacing: 0.4em;
  font-weight: 700;
}

.colors {
  border: 0;
  padding: 0;
  margin: 0 0 18px;
}

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

.swatch {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid var(--ink);
  background: var(--swatch);
  cursor: pointer;
  padding: 0;
  transition: transform 140ms cubic-bezier(0.2, 0.9, 0.25, 1);
}

.swatch[aria-pressed="true"] {
  transform: scale(1.18);
  box-shadow:
    0 0 0 3px var(--paper),
    0 0 0 6px var(--ink);
}

.actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.btn {
  flex: 1 1 auto;
  min-width: 140px;
  padding: 14px 20px;
  font: inherit;
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
  border: 3px solid var(--ink);
  border-radius: var(--radius-m);
  cursor: pointer;
  box-shadow: var(--shadow-toy);
  transform: translateY(0);
  transition:
    transform 90ms ease,
    box-shadow 90ms ease;
}

.btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 rgba(42, 36, 64, 0.28);
}

.btn:focus-visible {
  outline: 4px solid rgba(92, 201, 245, 0.7);
  outline-offset: 2px;
}

.btn--primary {
  background: var(--sun);
}

.btn--secondary {
  background: var(--aqua);
}

.btn--ghost {
  background: var(--paper);
}

.hint {
  margin: 16px 0 0;
  font-size: 13px;
  opacity: 0.72;
}

kbd {
  font: inherit;
  font-size: 0.92em;
  background: var(--ink);
  color: var(--paper);
  border-radius: 6px;
  padding: 1px 7px;
}

.sound {
  position: absolute;
  top: 18px;
  right: 18px;
  padding: 9px 14px;
  font: inherit;
  font-weight: 700;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 999px;
  cursor: pointer;
  box-shadow: var(--shadow-toy);
}

.roomcode {
  margin: 0 0 4px;
  font-size: 15px;
}

.roomcode strong {
  font-size: 34px;
  letter-spacing: 0.28em;
  display: block;
  color: var(--coral);
}

.players {
  list-style: none;
  margin: 0 0 18px;
  padding: 0;
  display: grid;
  gap: 8px;
}

.player {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 3px solid var(--ink);
  border-radius: var(--radius-m);
  background: #fff;
}

.player--ready {
  background: rgba(143, 232, 112, 0.35);
}

.player__dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--dot);
  border: 2px solid var(--ink);
}

.player__name {
  flex: 1;
  font-weight: 700;
}

.player__state {
  font-size: 13px;
  opacity: 0.7;
}

/* ---------- HUD ---------- */

.screen--hud {
  place-items: start center;
  pointer-events: none;
}

.hud {
  position: absolute;
  inset: 14px 14px auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 12px;
}

.hud__timer {
  grid-column: 2;
  font-size: clamp(30px, 5vw, 46px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #fff;
  padding: 6px 20px;
  background: rgba(42, 36, 64, 0.72);
  border-radius: var(--radius-l);
  border: 3px solid rgba(255, 255, 255, 0.22);
}

.hud__pips {
  grid-column: 1;
  grid-row: 1;
  display: flex;
  gap: 6px;
  align-self: center;
}

.pip {
  width: 26px;
  height: 10px;
  border-radius: 999px;
  background: rgba(42, 36, 64, 0.45);
  border: 2px solid rgba(255, 255, 255, 0.5);
  transition:
    background 220ms ease,
    transform 220ms cubic-bezier(0.2, 0.9, 0.25, 1);
}

.pip--on {
  background: var(--rest);
  transform: scaleX(1.12);
}

.hud__place {
  grid-column: 3;
  grid-row: 1;
  justify-self: end;
  align-self: center;
  padding: 6px 14px;
  background: rgba(42, 36, 64, 0.55);
  border-radius: 999px;
  font-size: 20px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 3px 0 rgba(42, 36, 64, 0.7);
}

.controls-hint {
  position: absolute;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 16px;
  background: rgba(42, 36, 64, 0.6);
  color: #fff;
  border-radius: 999px;
  font-size: 14px;
  transition: opacity 600ms ease;
}

.controls-hint--faded {
  opacity: 0;
}

.countdown[hidden] {
  display: none;
}

.countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: clamp(90px, 22vw, 220px);
  font-weight: 800;
  color: #fff;
  text-shadow: 0 10px 0 rgba(42, 36, 64, 0.55);
}

.countdown--pop {
  animation: pop 400ms cubic-bezier(0.2, 1.4, 0.3, 1) both;
}

@keyframes pop {
  from {
    transform: scale(1.6);
    opacity: 0;
  }
}

/* ---------- finish ---------- */

.finish-time {
  margin: 0;
  font-size: clamp(42px, 9vw, 66px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--coral);
  text-shadow: 0 5px 0 var(--ink);
}

.finish-note {
  margin: 4px 0 14px;
  font-size: 15px;
  opacity: 0.78;
}

.results {
  list-style: none;
  margin: 0 0 18px;
  padding: 0;
  display: grid;
  gap: 6px;
  max-height: 34vh;
  overflow: auto;
}

.results__row {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px 12px;
  border: 3px solid var(--ink);
  border-radius: var(--radius-m);
  background: #fff;
  font-variant-numeric: tabular-nums;
}

.results__place {
  font-weight: 800;
  color: var(--coral);
}

.panel--error {
  background: #fff2f2;
}

.error-message {
  font-size: 16px;
  padding: 12px 14px;
  background: #fff;
  border: 3px solid var(--coral);
  border-radius: var(--radius-m);
  word-break: break-word;
}

.live {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

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