:root {
  color-scheme: dark;
  --night-0: #050415;
  --night-1: #0d1230;
  --night-2: #221244;
  --ink: #f8f4ff;
  --muted: rgba(248, 244, 255, 0.7);
  --soft: rgba(248, 244, 255, 0.14);
  --line: rgba(248, 244, 255, 0.2);
  --gold: #ffd36a;
  --coral: #ff7c86;
  --mint: #7fffe0;
  --sky: #74d7ff;
  --shadow: rgba(2, 1, 12, 0.56);
  --bottom-chrome-clearance: max(76px, calc(env(safe-area-inset-bottom) + 54px));
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 12%, rgba(255, 124, 134, 0.16), transparent 28rem),
    radial-gradient(circle at 84% 16%, rgba(127, 255, 224, 0.14), transparent 26rem),
    linear-gradient(180deg, var(--night-2), var(--night-1) 44%, var(--night-0));
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  overscroll-behavior: none;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  touch-action: manipulation;
}

.app {
  position: relative;
  width: 100vw;
  height: 100dvh;
  min-height: 100vh;
  overflow: hidden;
}

#game-root {
  position: absolute;
  inset: 0;
  touch-action: none;
}

#game-root canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.story-panel,
.menu-panel,
.hud,
.launch-hint,
.toast {
  position: absolute;
  z-index: 3;
}

.story-panel {
  inset: 0;
  display: grid;
  grid-template-rows: 1fr auto auto;
  gap: 14px;
  padding: max(18px, env(safe-area-inset-top)) 18px var(--bottom-chrome-clearance);
  pointer-events: none;
}

.story-bubble {
  position: relative;
  align-self: end;
  width: min(92vw, 520px);
  min-height: 118px;
  margin: 0 auto;
  padding: 22px 22px 24px;
  color: #21193a;
  background: linear-gradient(180deg, rgba(255, 252, 243, 0.97), rgba(240, 233, 255, 0.96));
  border: 2px solid rgba(255, 255, 255, 0.7);
  border-radius: 20px;
  box-shadow: 0 18px 46px rgba(2, 1, 12, 0.36);
  pointer-events: auto;
}

.story-bubble::before {
  content: attr(data-speaker);
  display: inline-flex;
  margin-bottom: 9px;
  padding: 4px 9px;
  color: #4c2a7a;
  background: rgba(109, 72, 173, 0.12);
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.story-bubble::after {
  content: "";
  position: absolute;
  bottom: -13px;
  left: 42px;
  width: 26px;
  height: 26px;
  background: rgba(240, 233, 255, 0.96);
  border-right: 2px solid rgba(255, 255, 255, 0.7);
  border-bottom: 2px solid rgba(255, 255, 255, 0.7);
  transform: rotate(45deg);
}

.story-bubble p {
  margin: 0;
  font-size: clamp(1.16rem, 4.6vw, 1.58rem);
  font-weight: 780;
  line-height: 1.25;
  letter-spacing: 0;
}

.story-next {
  justify-self: center;
  width: min(92vw, 520px);
  pointer-events: auto;
}

.story-skip {
  align-self: start;
  justify-self: end;
  pointer-events: auto;
}

.menu-panel {
  inset: auto 0 var(--bottom-chrome-clearance);
  display: grid;
  gap: 16px;
  width: min(100%, 680px);
  max-height: min(calc(100dvh - var(--bottom-chrome-clearance) - 14px), 760px);
  margin: 0 auto;
  padding: 18px 16px;
  overflow: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  background:
    linear-gradient(180deg, rgba(19, 26, 69, 0.42), rgba(7, 8, 26, 0.94)),
    rgba(7, 8, 24, 0.72);
  border-top: 1px solid var(--line);
  border-radius: 24px 24px 0 0;
  box-shadow:
    0 -28px 70px rgba(1, 1, 9, 0.5),
    inset 0 1px 0 rgba(127, 255, 224, 0.12);
  backdrop-filter: blur(18px) saturate(1.18);
}

.menu-heading {
  display: grid;
  gap: 7px;
  text-align: center;
}

.eyebrow,
.menu-copy {
  margin: 0;
  color: var(--muted);
}

.eyebrow {
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(3rem, 12vw, 5.8rem);
  line-height: 0.82;
  letter-spacing: 0;
  text-shadow:
    0 0 22px rgba(116, 215, 255, 0.36),
    0 8px 34px rgba(2, 1, 12, 0.62);
}

.menu-copy {
  max-width: 33rem;
  margin: 0 auto;
  font-size: 0.98rem;
  line-height: 1.35;
}

.selector-shell {
  display: grid;
  gap: 12px;
  padding: 2px;
}

.selector-group {
  display: grid;
  gap: 9px;
}

.selector-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.selector-title strong {
  color: var(--ink);
  font-size: 0.76rem;
  font-weight: 850;
}

.option-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.planet-row {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.option-button {
  position: relative;
  min-height: 66px;
  padding: 8px 5px 7px;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.095), rgba(255, 255, 255, 0.052)),
    rgba(255, 255, 255, 0.058);
  border: 1px solid var(--line);
  border-radius: 13px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    0 8px 22px rgba(2, 1, 12, 0.13);
  cursor: pointer;
  transition:
    transform 150ms ease,
    border-color 150ms ease,
    box-shadow 150ms ease,
    background 150ms ease;
}

.option-button span {
  display: block;
  width: min-content;
  min-width: 100%;
  margin: 0 auto;
  overflow: hidden;
  font-size: clamp(0.64rem, 2.7vw, 0.82rem);
  font-weight: 800;
  line-height: 1.05;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.option-button i {
  position: relative;
  display: block;
  width: 34px;
  height: 34px;
  margin: 0 auto 5px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.42);
  box-shadow:
    0 0 18px color-mix(in srgb, var(--swatch, var(--gold)) 46%, transparent),
    inset 0 1px 0 rgba(255, 255, 255, 0.44);
}

.option-button i::before,
.option-button i::after,
.option-button i b {
  content: "";
  position: absolute;
  inset: 0;
  display: block;
}

.option-ball i,
.option-planet i {
  border-radius: 999px;
  background:
    radial-gradient(circle at 32% 26%, rgba(255, 255, 255, 0.9), transparent 18%),
    radial-gradient(circle at 60% 70%, color-mix(in srgb, var(--swatch) 70%, #000 30%), transparent 56%),
    var(--swatch, var(--gold));
}

.option-ground i {
  width: 40px;
  height: 27px;
  margin-top: 3px;
  margin-bottom: 8px;
  border-radius: 6px;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--swatch) 70%, #fff 30%), var(--swatch), color-mix(in srgb, var(--swatch) 70%, #000 30%));
}

.option-ball[data-id="bowling"] i::before {
  background:
    radial-gradient(circle at 38% 34%, rgba(4, 3, 14, 0.96) 0 14%, transparent 15%),
    radial-gradient(circle at 61% 32%, rgba(4, 3, 14, 0.96) 0 13%, transparent 14%),
    radial-gradient(circle at 49% 54%, rgba(4, 3, 14, 0.96) 0 13%, transparent 14%);
}

.option-ball[data-id="bowling"] i::after {
  background:
    linear-gradient(122deg, transparent 0 22%, rgba(200, 176, 255, 0.24) 24% 30%, transparent 33% 100%),
    linear-gradient(36deg, transparent 0 48%, rgba(8, 5, 26, 0.2) 50% 56%, transparent 59% 100%);
}

.option-ball[data-id="tennis"] i::before {
  border: 3px solid rgba(255, 255, 255, 0.9);
  border-right-color: transparent;
  border-left-color: transparent;
  border-radius: 999px;
  transform: scale(1.16) rotate(28deg);
}

.option-ball[data-id="beach"] i {
  background:
    conic-gradient(from -40deg, #fff 0 17%, #ffd36a 18% 34%, #ff7c86 35% 50%, #74d7ff 51% 67%, #fff 68% 84%, #ffd36a 85% 100%);
}

.option-ball[data-id="beach"] i::before {
  background: radial-gradient(circle at center, rgba(255, 255, 255, 0.94) 0 14%, transparent 15%);
}

.option-ball[data-id="slime"] i::after {
  background:
    radial-gradient(circle at 31% 34%, rgba(224, 255, 235, 0.42) 0 8%, transparent 9%),
    radial-gradient(circle at 67% 54%, rgba(224, 255, 235, 0.32) 0 10%, transparent 11%),
    linear-gradient(180deg, transparent 0 62%, rgba(16, 156, 105, 0.28) 63% 100%);
}

.option-ground[data-id="concrete"] i::after {
  background:
    linear-gradient(72deg, transparent 0 30%, rgba(32, 36, 52, 0.35) 31% 33%, transparent 34%),
    radial-gradient(circle at 28% 52%, rgba(255, 255, 255, 0.35) 0 4%, transparent 5%),
    radial-gradient(circle at 68% 36%, rgba(22, 25, 38, 0.28) 0 5%, transparent 6%);
}

.option-ground[data-id="trampoline"] i {
  background:
    linear-gradient(180deg, #7fffe0 0 18%, #061323 19% 82%, #37e6d3 83% 100%);
}

.option-ground[data-id="trampoline"] i::after {
  background:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.24) 0 1px, transparent 1px 7px),
    repeating-linear-gradient(-45deg, rgba(255, 255, 255, 0.16) 0 1px, transparent 1px 7px);
}

.option-ground[data-id="sand"] i::after {
  background:
    radial-gradient(circle at 28% 60%, rgba(255, 248, 209, 0.48) 0 5%, transparent 6%),
    radial-gradient(circle at 72% 35%, rgba(122, 80, 30, 0.28) 0 4%, transparent 5%),
    repeating-linear-gradient(166deg, transparent 0 7px, rgba(122, 80, 30, 0.19) 8px 9px);
}

.option-ground[data-id="grass"] i::after {
  background:
    repeating-linear-gradient(104deg, transparent 0 5px, rgba(235, 255, 210, 0.46) 6px 7px),
    linear-gradient(180deg, transparent 0 32%, rgba(16, 84, 42, 0.34) 33% 100%);
}

.option-ground[data-id="ice"] i::after {
  background:
    linear-gradient(28deg, transparent 0 28%, rgba(255, 255, 255, 0.52) 29% 31%, transparent 32%),
    linear-gradient(156deg, transparent 0 48%, rgba(255, 255, 255, 0.42) 49% 51%, transparent 52%),
    radial-gradient(ellipse at 60% 34%, rgba(255, 255, 255, 0.3), transparent 38%);
}

.option-planet i::after {
  background:
    linear-gradient(16deg, transparent 0 38%, rgba(255, 255, 255, 0.42) 39% 42%, transparent 43% 100%),
    radial-gradient(circle at 74% 29%, rgba(255, 255, 255, 0.32), transparent 13%);
}

.option-planet[data-id="jupiter"] i::after {
  background:
    repeating-linear-gradient(174deg, rgba(89, 44, 24, 0.18) 0 3px, rgba(255, 255, 255, 0.22) 4px 6px, transparent 7px 10px),
    radial-gradient(circle at 72% 58%, rgba(255, 124, 134, 0.55) 0 9%, transparent 10%);
}

.option-planet[data-id="dream"] i::after {
  background:
    conic-gradient(from 60deg, rgba(255, 255, 255, 0.24), transparent, rgba(116, 215, 255, 0.28), transparent, rgba(255, 211, 106, 0.22), transparent);
}

.option-button[data-active="true"] {
  color: #141024;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.58), rgba(255, 255, 255, 0.18)),
    linear-gradient(180deg, #fff2b4, #ffbf68);
  border-color: rgba(255, 255, 255, 0.72);
  box-shadow:
    0 10px 26px rgba(255, 188, 94, 0.24),
    inset 0 1px 0 rgba(255, 255, 255, 0.72),
    inset 0 -1px 0 rgba(109, 72, 173, 0.2);
  transform: translateY(-2px);
}

.menu-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.primary-button,
.ghost-button,
.icon-text-button {
  min-height: 48px;
  border-radius: 13px;
  border: 0;
  cursor: pointer;
}

.primary-button {
  color: #181025;
  background: linear-gradient(180deg, #ffef9c, #ffbc5e 58%, #ff865f);
  font-weight: 950;
  box-shadow:
    0 15px 38px rgba(255, 124, 134, 0.24),
    inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.primary-button:active,
.ghost-button:active,
.icon-text-button:active,
.option-button:active {
  transform: translateY(1px) scale(0.985);
}

button:focus-visible {
  outline: 3px solid var(--mint);
  outline-offset: 3px;
}

.ghost-button,
.icon-text-button {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--line);
  font-weight: 850;
}

.hud {
  top: max(10px, env(safe-area-inset-top));
  right: auto;
  bottom: auto;
  left: 50%;
  display: grid;
  gap: 8px;
  width: min(calc(100vw - 20px), 390px);
  transform: translateX(-50%);
  pointer-events: none;
}

.hud-top {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  align-items: stretch;
}

.hud-top > div,
.combo-pill,
.skill-pill {
  min-width: 0;
  padding: 9px 11px;
  background: rgba(7, 8, 24, 0.56);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(2, 1, 12, 0.22);
  backdrop-filter: blur(10px);
}

.hud span {
  display: block;
  color: var(--muted);
  font-size: 0.64rem;
  font-weight: 850;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.hud strong {
  display: block;
  margin-top: 1px;
  color: var(--ink);
  font-size: clamp(1.02rem, 4.4vw, 1.4rem);
  line-height: 1;
}

.icon-text-button {
  min-width: 68px;
  min-height: 44px;
  padding: 0 12px;
  pointer-events: auto;
}

.combo-pill {
  min-width: 0;
  max-width: min(70vw, 430px);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hud-meta {
  display: grid;
  align-items: center;
  justify-items: start;
  gap: 8px;
  min-width: 0;
}

.skill-pill {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 8px 10px;
  color: var(--ink);
}

.skill-pill i {
  display: block;
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  background: var(--mint);
  border-radius: 50%;
  box-shadow: 0 0 12px color-mix(in srgb, var(--mint) 82%, transparent);
}

.skill-pill span {
  color: var(--ink);
  line-height: 1;
  white-space: nowrap;
}

.skill-pill[data-state="aiming"] i {
  background: var(--sky);
  box-shadow: 0 0 12px color-mix(in srgb, var(--sky) 82%, transparent);
}

.skill-pill[data-state="tap"] {
  border-color: rgba(255, 211, 106, 0.56);
}

.skill-pill[data-state="tap"] i {
  background: var(--gold);
  box-shadow: 0 0 15px color-mix(in srgb, var(--gold) 88%, transparent);
}

.skill-pill[data-state="used"] i,
.skill-pill[data-state="landed"] i {
  background: var(--coral);
  box-shadow: none;
}

.launch-hint {
  top: max(160px, calc(env(safe-area-inset-top) + 144px));
  left: 50%;
  bottom: auto;
  width: min(92vw, 430px);
  padding: 12px 14px;
  color: #1a1430;
  background: rgba(255, 245, 200, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 13px;
  box-shadow: 0 20px 44px rgba(2, 1, 12, 0.32);
  font-size: 0.95rem;
  font-weight: 900;
  text-align: center;
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  top: max(218px, calc(env(safe-area-inset-top) + 204px));
  left: 50%;
  max-width: min(88vw, 360px);
  padding: 10px 13px;
  color: #171127;
  background: linear-gradient(180deg, #c8fff1, #78e6ff);
  border-radius: 13px;
  box-shadow: 0 18px 44px rgba(2, 1, 12, 0.34);
  font-size: 0.88rem;
  font-weight: 950;
  text-align: center;
  transform: translateX(-50%);
}

[hidden] {
  display: none !important;
}

@media (hover: hover) and (pointer: fine) {
  .option-button:hover:not([data-active="true"]),
  .ghost-button:hover,
  .icon-text-button:hover {
    border-color: rgba(127, 255, 224, 0.52);
    background-color: rgba(127, 255, 224, 0.1);
    transform: translateY(-2px);
  }

  .primary-button:hover {
    filter: brightness(1.07) saturate(1.06);
    transform: translateY(-2px);
  }
}

@media (min-width: 1320px) {
  :root {
    --bottom-chrome-clearance: max(28px, env(safe-area-inset-bottom));
  }

  .menu-panel {
    right: 28px;
    bottom: var(--bottom-chrome-clearance);
    left: auto;
    width: 410px;
    max-height: calc(100dvh - 56px);
    border: 1px solid var(--line);
    border-radius: 24px;
  }

  .menu-panel h1 {
    font-size: clamp(3.2rem, 5.8vw, 4.5rem);
    line-height: 0.9;
  }

  .story-panel {
    padding-bottom: 34px;
  }

  .hud-meta {
    display: flex;
  }
}

@media (max-width: 350px) {
  .option-row,
  .planet-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .option-button span {
    font-size: 0.72rem;
  }
}

@media (max-width: 430px) {
  .combo-pill {
    max-width: calc(100vw - 20px);
  }

  .skill-pill {
    padding-inline: 9px;
  }
}

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