:root {
  color-scheme: dark;
  --ink: #f8fafc;
  --muted: #cbd5e1;
  --panel: rgba(15, 23, 42, 0.76);
  --panel-solid: #111827;
  --line: rgba(255, 255, 255, 0.18);
  --pink: #ff4d6d;
  --yellow: #ffc857;
  --green: #4dd599;
  --cyan: #4cc9f0;
  --violet: #b517ff;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #070812;
  color: var(--ink);
}

body {
  overflow-x: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

.backdrop {
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(circle at 12% 10%, rgba(255, 77, 109, 0.48), transparent 28rem),
    radial-gradient(circle at 88% 14%, rgba(76, 201, 240, 0.45), transparent 30rem),
    radial-gradient(circle at 30% 90%, rgba(77, 213, 153, 0.32), transparent 28rem),
    linear-gradient(135deg, #17122f 0%, #06101e 50%, #1f1230 100%);
}

.backdrop::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.22;
  background-image:
    linear-gradient(rgba(255,255,255,0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.08) 1px, transparent 1px);
  background-size: 44px 44px;
  animation: drift 18s linear infinite;
}

@keyframes drift {
  from { transform: translate3d(0, 0, 0); }
  to { transform: translate3d(-44px, 44px, 0); }
}

.shell {
  width: min(1180px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 24px 0 42px;
}

.hero {
  min-height: calc(100vh - 48px);
  display: grid;
  align-content: center;
  gap: 24px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  font-weight: 900;
  letter-spacing: 0;
  font-size: clamp(24px, 4vw, 44px);
}

.brand-mark {
  width: 54px;
  height: 54px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--pink), var(--yellow));
  color: #170617;
  font-weight: 1000;
  box-shadow: 0 14px 34px rgba(255, 77, 109, 0.35);
  transform: rotate(-6deg);
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 90px rgba(0, 0, 0, 0.36);
  backdrop-filter: blur(16px);
  padding: 22px;
}

.panel h1,
.panel h2,
.panel h3 {
  margin: 0 0 12px;
  line-height: 1.02;
}

.panel h1 {
  font-size: clamp(40px, 9vw, 96px);
}

.panel h2 {
  font-size: clamp(28px, 5vw, 56px);
}

.panel h3 {
  font-size: 22px;
}

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

.stack {
  display: grid;
  gap: 14px;
}

.row {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.room-code {
  display: inline-grid;
  place-items: center;
  min-width: 190px;
  padding: 12px 22px;
  border-radius: 8px;
  border: 4px solid rgba(255,255,255,0.92);
  background: #f8fafc;
  color: #111827;
  font-size: clamp(48px, 12vw, 112px);
  font-weight: 1000;
  line-height: 1;
  box-shadow: 10px 10px 0 rgba(0,0,0,0.4);
}

.join-link {
  font-size: clamp(18px, 2vw, 26px);
  color: var(--yellow);
  font-weight: 800;
  word-break: break-word;
}

.btn {
  border: 0;
  border-radius: 8px;
  color: #0b1020;
  font-weight: 900;
  padding: 13px 18px;
  min-height: 48px;
  cursor: pointer;
  background: linear-gradient(135deg, var(--yellow), var(--green));
  box-shadow: 0 10px 0 rgba(0,0,0,0.22);
  transition: transform 120ms ease, box-shadow 120ms ease, filter 120ms ease;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 13px 0 rgba(0,0,0,0.22);
}

.btn:active {
  transform: translateY(5px);
  box-shadow: 0 5px 0 rgba(0,0,0,0.22);
}

.btn.secondary {
  background: linear-gradient(135deg, #e9d5ff, #93c5fd);
}

.btn.danger {
  background: linear-gradient(135deg, #fb7185, #f97316);
}

.btn:disabled {
  cursor: not-allowed;
  filter: grayscale(0.9) brightness(0.75);
  transform: none;
}

.field,
.select,
.textarea {
  width: 100%;
  border: 2px solid rgba(255,255,255,0.22);
  border-radius: 8px;
  min-height: 52px;
  padding: 12px 14px;
  background: rgba(2, 6, 23, 0.76);
  color: var(--ink);
  outline: none;
}

.textarea {
  min-height: 118px;
  resize: vertical;
}

.field:focus,
.select:focus,
.textarea:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 4px rgba(76, 201, 240, 0.2);
}

.player-grid,
.game-grid,
.option-grid,
.score-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.player,
.game-card,
.option,
.score-card {
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.08);
  padding: 14px;
}

.game-card {
  display: grid;
  min-height: 150px;
  cursor: pointer;
  transition: transform 150ms ease, background 150ms ease;
}

.game-card:hover,
.game-card.selected {
  transform: translateY(-4px) rotate(-1deg);
  background: rgba(255,255,255,0.16);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  border-radius: 999px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: rgba(255,255,255,0.08);
  font-weight: 800;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  display: inline-block;
  background: var(--green);
}

.prompt {
  padding: clamp(18px, 4vw, 38px);
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(255,77,109,0.92), rgba(181,23,255,0.86));
  color: #fff;
  font-size: clamp(28px, 6vw, 76px);
  font-weight: 1000;
  line-height: 1.03;
  box-shadow: 0 18px 0 rgba(0,0,0,0.28);
}

.big-count {
  font-size: clamp(44px, 9vw, 120px);
  font-weight: 1000;
  line-height: 0.9;
}

.option {
  min-height: 92px;
  display: grid;
  align-content: center;
  gap: 8px;
  cursor: pointer;
  color: var(--ink);
}

.option button {
  width: 100%;
}

.draw-pad {
  width: 100%;
  aspect-ratio: 1 / 1;
  touch-action: none;
  background: #f8fafc;
  border: 4px solid #0f172a;
  border-radius: 8px;
}

.drawing {
  width: 100%;
  background: #f8fafc;
  border-radius: 8px;
  border: 3px solid rgba(255,255,255,0.82);
}

.arcade-stage {
  overflow: hidden;
}

.race-prompt {
  background: linear-gradient(135deg, rgba(255, 200, 87, 0.96), rgba(255, 77, 109, 0.92));
  color: #111827;
}

.race-track {
  position: relative;
  display: grid;
  gap: 12px;
  padding-right: 22px;
}

.race-lane {
  display: grid;
  grid-template-columns: minmax(120px, 190px) 1fr;
  gap: 12px;
  align-items: center;
}

.race-name {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.race-road {
  position: relative;
  height: 58px;
  overflow: hidden;
  border-radius: 8px;
  border: 2px solid rgba(255,255,255,0.2);
  background:
    repeating-linear-gradient(90deg, rgba(255,255,255,0.12) 0 18px, transparent 18px 42px),
    linear-gradient(180deg, rgba(15,23,42,0.96), rgba(30,41,59,0.82));
}

.race-car {
  position: absolute;
  top: 9px;
  width: 72px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  border: 3px solid rgba(255,255,255,0.86);
  background: var(--car-color);
  color: #08111f;
  font-weight: 1000;
  box-shadow: 0 8px 0 rgba(0,0,0,0.28);
  transition: left 100ms linear;
}

.race-car::before,
.race-car::after {
  content: "";
  position: absolute;
  bottom: -8px;
  width: 15px;
  height: 15px;
  border-radius: 999px;
  background: #0f172a;
  border: 3px solid rgba(255,255,255,0.8);
}

.race-car::before {
  left: 9px;
}

.race-car::after {
  right: 9px;
}

.finish-line {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 18px;
  border-radius: 4px;
  background:
    repeating-linear-gradient(45deg, #fff 0 8px, #111827 8px 16px);
  box-shadow: 0 0 22px rgba(255,255,255,0.35);
}

.mini-track {
  width: 100%;
  height: 26px;
  overflow: hidden;
  border-radius: 999px;
  border: 2px solid rgba(255,255,255,0.22);
  background: rgba(2, 6, 23, 0.68);
}

.mini-car {
  width: 0;
  height: 100%;
  min-width: 10px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--car-color), #ffffff);
  transition: width 120ms linear;
}

.controller-stage {
  min-height: calc(100vh - 100px);
  align-content: center;
}

.boost-button {
  min-height: 44vh;
  border: 0;
  border-radius: 8px;
  color: #111827;
  background:
    radial-gradient(circle at 50% 25%, rgba(255,255,255,0.95), transparent 6rem),
    linear-gradient(135deg, var(--yellow), var(--pink));
  font-size: clamp(48px, 15vw, 132px);
  font-weight: 1000;
  cursor: pointer;
  box-shadow: 0 18px 0 rgba(0,0,0,0.34);
  animation: boostPulse 820ms ease-in-out infinite alternate;
  touch-action: manipulation;
}

.boost-button:active {
  transform: translateY(12px) scale(0.985);
  box-shadow: 0 6px 0 rgba(0,0,0,0.34);
}

@keyframes boostPulse {
  from { filter: saturate(1); }
  to { filter: saturate(1.35) brightness(1.08); }
}

.color-stage {
  box-shadow: 0 24px 90px rgba(0, 0, 0, 0.36), 0 0 60px rgba(255, 255, 255, 0.12);
}

.color-target {
  min-height: min(44vh, 420px);
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 50%, rgba(255,255,255,0.45), transparent 12rem),
    var(--target);
  color: #07101d;
  text-transform: uppercase;
  box-shadow: 0 18px 0 rgba(0,0,0,0.28);
  animation: colorPop 520ms ease both;
}

.color-target span {
  font-size: clamp(22px, 3vw, 42px);
  font-weight: 900;
}

.color-target strong {
  font-size: clamp(62px, 13vw, 164px);
  line-height: 0.9;
}

@keyframes colorPop {
  from { transform: scale(0.96); filter: brightness(0.82); }
  to { transform: scale(1); filter: brightness(1); }
}

.color-orbit {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.color-orbit span {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: 3px solid rgba(255,255,255,0.78);
}

.color-pad-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.color-pad {
  min-height: 120px;
  border: 0;
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 18%, rgba(255,255,255,0.5), transparent 5rem),
    var(--pad);
  color: #07101d;
  font-weight: 1000;
  font-size: clamp(22px, 6vw, 44px);
  box-shadow: 0 10px 0 rgba(0,0,0,0.26);
  cursor: pointer;
  touch-action: manipulation;
}

.color-pad:active {
  transform: translateY(8px);
  box-shadow: 0 3px 0 rgba(0,0,0,0.26);
}

.race-result {
  align-content: start;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  width: min(560px, calc(100vw - 32px));
  padding: 12px 16px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.94);
  border: 1px solid var(--line);
  color: var(--ink);
  box-shadow: 0 18px 40px rgba(0,0,0,0.32);
}

.hidden {
  display: none !important;
}

@media (max-width: 760px) {
  .shell {
    width: min(100vw - 18px, 680px);
    padding-top: 12px;
  }

  .grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
  }

  .panel {
    padding: 16px;
  }

  .brand-mark {
    width: 44px;
    height: 44px;
  }

  .race-lane {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .race-road {
    height: 52px;
  }

  .boost-button {
    min-height: 38vh;
  }

  .color-pad-grid {
    grid-template-columns: 1fr;
  }
}
