:root {
  color-scheme: dark;
  --surface: #09051d;
  --surface-soft: rgba(17, 11, 44, 0.82);
  --surface-raised: rgba(27, 17, 63, 0.92);
  --text: #ffffff;
  --text-muted: #c9c1e3;
  --line: rgba(255, 255, 255, 0.16);
  --violet: #7c3cff;
  --pink: #ff4fb8;
  --cyan: #32dcff;
  --lime: #c8ff5c;
  --focus: #b9f3ff;
  --radius-lg: 2rem;
  --radius-md: 1.25rem;
  --shadow-panel: 0 2rem 6rem rgba(4, 1, 18, 0.55);
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-width: 20rem;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--surface);
}

body {
  color: var(--text);
  font-size: 1rem;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  user-select: none;
}

button,
select,
input {
  font: inherit;
}

button,
select,
label {
  touch-action: manipulation;
}

button {
  color: inherit;
}

button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 0.2rem solid var(--focus);
  outline-offset: 0.2rem;
}

[hidden] {
  display: none !important;
}

#stage {
  position: fixed;
  inset: 0;
  z-index: 0;
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

.ambient {
  position: fixed;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  pointer-events: none;
  opacity: 0.8;
  transition: opacity 300ms ease;
}

body.is-playing .ambient {
  opacity: 0;
}

.ambient__orb {
  position: absolute;
  width: min(90vw, 42rem);
  aspect-ratio: 1;
  border-radius: 50%;
  filter: blur(5rem);
  opacity: 0.34;
  animation: drift 9s ease-in-out infinite alternate;
}

.ambient__orb--violet {
  top: -30%;
  left: -15%;
  background: var(--violet);
}

.ambient__orb--pink {
  right: -22%;
  bottom: -36%;
  background: var(--pink);
  animation-delay: -3s;
}

.ambient__orb--cyan {
  top: 20%;
  right: 15%;
  width: min(60vw, 28rem);
  background: var(--cyan);
  opacity: 0.2;
  animation-delay: -6s;
}

.welcome {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
  overflow-y: auto;
  background: linear-gradient(160deg, rgba(5, 3, 19, 0.16), rgba(5, 3, 19, 0.58));
  transition: opacity 240ms ease, visibility 240ms ease;
}

.welcome.is-leaving {
  opacity: 0;
  visibility: hidden;
}

.welcome__card {
  width: min(100%, 43rem);
  padding: clamp(1.4rem, 4vw, 3rem);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.035)),
    rgba(8, 4, 28, 0.78);
  box-shadow: var(--shadow-panel), inset 0 1px 0 rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(1.5rem) saturate(140%);
  -webkit-backdrop-filter: blur(1.5rem) saturate(140%);
  text-align: center;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.85rem;
}

.brand__mark {
  display: grid;
  place-items: center;
  width: clamp(3.2rem, 12vw, 4.4rem);
  aspect-ratio: 1;
  border-radius: 1.25rem;
  color: #fff;
  background: linear-gradient(135deg, var(--violet), var(--pink) 55%, var(--cyan));
  box-shadow: 0 0 2.5rem rgba(124, 60, 255, 0.48);
  transform: rotate(-5deg);
}

.brand__mark svg {
  width: 72%;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(3rem, 12vw, 6.5rem);
  font-weight: 900;
  line-height: 0.92;
  letter-spacing: -0.075em;
  background: linear-gradient(100deg, #ffffff 18%, #d9c6ff 55%, #84efff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 2.5rem rgba(105, 214, 255, 0.2);
}

.welcome__lead {
  max-width: 34rem;
  margin: clamp(1.4rem, 4vw, 2rem) auto 0;
  color: #f5f1ff;
  font-size: clamp(1.05rem, 3vw, 1.3rem);
  font-weight: 600;
}

.features {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.55rem;
  margin: 1.4rem 0 0;
  padding: 0;
  list-style: none;
}

.features li {
  padding: 0.55rem 0.85rem;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 700;
}

.theme-picker {
  margin-top: 1rem;
  padding: 0.75rem;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 1rem;
  background: rgba(255, 255, 255, 0.055);
}

.theme-picker__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.6rem;
  text-align: left;
}

.theme-picker__header > strong {
  font-size: 0.86rem;
}

.theme-picker__settings {
  min-height: 2.75rem;
  padding: 0.45rem 0.7rem;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 0.7rem;
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
  color: #bcefff;
  font-size: 0.76rem;
  font-weight: 800;
}

.theme-picker__options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
}

.theme-picker__options button {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
  min-height: 2.75rem;
  padding: 0.5rem 0.65rem;
  border: 1px solid transparent;
  border-radius: 0.75rem;
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
  font-size: 0.76rem;
  font-weight: 750;
  transition: border-color 180ms ease, background 180ms ease, transform 180ms ease;
}

.theme-picker__options button:hover {
  background: rgba(255, 255, 255, 0.11);
}

.theme-picker__options button.is-active {
  border-color: rgba(142, 238, 255, 0.7);
  background: rgba(114, 210, 255, 0.15);
}

.theme-picker__options button:active {
  transform: scale(0.97);
}

.theme-swatch {
  flex: 0 0 0.8rem;
  width: 0.8rem;
  height: 0.8rem;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 50%;
  box-shadow: 0 0 0.7rem currentColor;
}

.theme-swatch--confetti { background: #ff7b9f; color: #ff7b9f; }
.theme-swatch--bubbles { background: #71d6ff; color: #71d6ff; }
.theme-swatch--space { background: #a89cff; color: #a89cff; }
.theme-swatch--underwater { background: #70e7d4; color: #70e7d4; }

.game-controls {
  position: fixed;
  left: max(0.75rem, env(safe-area-inset-left));
  bottom: max(5.25rem, calc(env(safe-area-inset-bottom) + 5.25rem));
  z-index: 8;
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.quick-theme,
.quick-finish {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.8rem;
  padding: 0.55rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(7, 4, 24, 0.72);
  box-shadow: 0 0.7rem 2rem rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(1rem);
  -webkit-backdrop-filter: blur(1rem);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 800;
  transition: background 180ms ease, border-color 180ms ease, transform 180ms ease;
}

.quick-theme:hover {
  background: rgba(27, 17, 63, 0.88);
}

.quick-finish {
  border-color: rgba(255, 126, 155, 0.42);
  background: rgba(106, 20, 49, 0.78);
  color: #fff3f6;
}

.quick-finish:hover {
  border-color: rgba(255, 158, 181, 0.72);
  background: rgba(144, 25, 62, 0.92);
}

.quick-theme:active,
.quick-finish:active {
  transform: scale(0.96);
}

.quick-theme svg,
.quick-finish svg {
  width: 1.25rem;
  color: var(--cyan);
}

.quick-finish svg {
  color: #ff9eb5;
}

.start-button {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  width: 100%;
  min-height: 4rem;
  margin-top: clamp(1.5rem, 5vw, 2.4rem);
  padding: 1rem 1.5rem;
  overflow: hidden;
  border: 0;
  border-radius: 1.2rem;
  background: linear-gradient(100deg, var(--violet), #a63ff2 45%, var(--pink));
  box-shadow: 0 1rem 3rem rgba(124, 60, 255, 0.34), inset 0 1px 0 rgba(255, 255, 255, 0.34);
  cursor: pointer;
  font-size: clamp(1.1rem, 3vw, 1.35rem);
  font-weight: 800;
  transition: transform 180ms ease, filter 180ms ease, box-shadow 180ms ease;
}

.start-button::before {
  content: "";
  position: absolute;
  inset: -100% 45%;
  width: 18%;
  background: rgba(255, 255, 255, 0.3);
  transform: rotate(22deg);
  transition: transform 400ms ease;
}

.start-button:hover {
  filter: saturate(118%) brightness(1.08);
  box-shadow: 0 1.2rem 3.5rem rgba(124, 60, 255, 0.46), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.start-button:hover::before {
  transform: translateX(16rem) rotate(22deg);
}

.start-button:active {
  transform: scale(0.975);
}

.start-button svg {
  width: 1.5rem;
  height: 1.5rem;
}

.welcome__hint {
  margin: 1rem 0 0;
  color: #aaa0ca;
  font-size: 0.875rem;
}

.welcome__hint strong {
  color: #ffffff;
}

.hud {
  position: fixed;
  top: max(0.75rem, env(safe-area-inset-top));
  right: max(0.75rem, env(safe-area-inset-right));
  z-index: 8;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.8rem;
  padding: 0.45rem 0.55rem 0.45rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(7, 4, 24, 0.64);
  box-shadow: 0 0.7rem 2rem rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(1rem);
  -webkit-backdrop-filter: blur(1rem);
  pointer-events: none;
}

.hud.is-pulsing {
  animation: hud-pulse 360ms ease-out;
}

.hud.is-leveling-up {
  animation: hud-level-up 620ms ease-out;
}

body.is-apocalypse-shaking #stage {
  animation: canvas-shake 420ms linear infinite;
}

.hud__label {
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#score {
  min-width: 1.1rem;
  font-variant-numeric: tabular-nums;
}

.hud__pill {
  padding: 0.42rem 0.65rem;
  border-radius: 999px;
  background: linear-gradient(110deg, #c9f7ff, #e3d1ff, #ffe0a3);
  color: #130b2d;
  font-size: 0.72rem;
  font-weight: 900;
}

.parent-hotspot {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 9;
  width: 4rem;
  height: 4rem;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: default;
}

.panel {
  position: fixed;
  z-index: 30;
  inset: max(0.75rem, env(safe-area-inset-top)) max(0.75rem, env(safe-area-inset-right)) max(0.75rem, env(safe-area-inset-bottom)) auto;
  width: min(calc(100% - 1.5rem), 25rem);
  padding: 1.25rem;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 1.5rem;
  background: var(--surface-raised);
  box-shadow: var(--shadow-panel);
  backdrop-filter: blur(1.5rem) saturate(130%);
  -webkit-backdrop-filter: blur(1.5rem) saturate(130%);
  animation: panel-in 220ms ease-out;
  touch-action: pan-y;
  user-select: text;
}

.panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.panel__eyebrow {
  margin-bottom: 0.15rem;
  color: #a895d4;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.panel h2 {
  margin-bottom: 0;
  font-size: 1.6rem;
  line-height: 1.15;
}

.icon-button {
  display: grid;
  place-items: center;
  flex: 0 0 3rem;
  width: 3rem;
  height: 3rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
  transition: background 180ms ease, transform 180ms ease;
}

.icon-button:hover {
  background: rgba(255, 255, 255, 0.15);
}

.icon-button:active {
  transform: scale(0.94);
}

.icon-button svg {
  width: 1.4rem;
}

.field,
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 4rem;
  padding: 0.75rem 0;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.field > span,
.switch-row strong {
  display: block;
  font-size: 0.95rem;
  font-weight: 750;
}

.switch-row small {
  display: block;
  max-width: 15rem;
  margin-top: 0.12rem;
  color: #aaa0c5;
  font-size: 0.78rem;
  line-height: 1.35;
}

select {
  min-width: 7.5rem;
  min-height: 2.75rem;
  padding: 0.55rem 2rem 0.55rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  background: #23164e;
  color: var(--text);
  cursor: pointer;
}

input[type="checkbox"] {
  position: relative;
  flex: 0 0 auto;
  width: 3.2rem;
  height: 1.85rem;
  margin: 0;
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  cursor: pointer;
  transition: background 180ms ease, border-color 180ms ease;
}

input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 0.2rem;
  left: 0.22rem;
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0.15rem 0.4rem rgba(0, 0, 0, 0.28);
  transition: transform 180ms ease;
}

input[type="checkbox"]:checked {
  border-color: transparent;
  background: linear-gradient(100deg, var(--violet), var(--pink));
}

input[type="checkbox"]:checked::after {
  transform: translateX(1.31rem);
}

.panel__actions {
  display: grid;
  gap: 0.65rem;
  margin-top: 1rem;
}

.secondary-button {
  min-height: 3rem;
  padding: 0.75rem 1rem;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 0.9rem;
  background: rgba(124, 60, 255, 0.28);
  cursor: pointer;
  font-weight: 800;
  transition: background 180ms ease, transform 180ms ease;
}

.secondary-button--quiet {
  background: rgba(255, 255, 255, 0.06);
}

.secondary-button:hover {
  background: rgba(124, 60, 255, 0.44);
}

.secondary-button:active {
  transform: scale(0.98);
}

.panel__note {
  margin: 1rem 0 0;
  color: #a99fc5;
  font-size: 0.78rem;
  line-height: 1.45;
}

.toast {
  position: fixed;
  z-index: 40;
  left: 50%;
  bottom: max(1rem, env(safe-area-inset-bottom));
  width: max-content;
  max-width: calc(100% - 2rem);
  padding: 0.8rem 1rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(10, 5, 31, 0.88);
  box-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(1rem);
  -webkit-backdrop-filter: blur(1rem);
  transform: translateX(-50%);
  text-align: center;
  font-size: 0.875rem;
  font-weight: 700;
  animation: toast-in 220ms ease-out;
}


.summary {
  position: fixed;
  inset: 0;
  z-index: 35;
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
  overflow-y: auto;
  background: rgba(3, 1, 15, 0.74);
  backdrop-filter: blur(1.1rem);
  -webkit-backdrop-filter: blur(1.1rem);
  animation: summary-in 260ms ease-out;
  touch-action: pan-y;
}

.summary__card {
  width: min(100%, 32rem);
  padding: clamp(1.5rem, 5vw, 2.5rem);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.035)),
    rgba(12, 6, 38, 0.94);
  box-shadow: var(--shadow-panel), inset 0 1px 0 rgba(255, 255, 255, 0.14);
  text-align: center;
}

.summary__eyebrow {
  margin-bottom: 0.35rem;
  color: #baa9e2;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.summary h2 {
  margin-bottom: 1.5rem;
  font-size: clamp(1.8rem, 7vw, 2.7rem);
  line-height: 1.05;
  letter-spacing: -0.04em;
}

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

.summary__stats p {
  display: grid;
  gap: 0.25rem;
  margin: 0;
  padding: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 1rem;
  background: rgba(255, 255, 255, 0.06);
}

.summary__stats span {
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.summary__stats strong {
  font-size: clamp(1.5rem, 8vw, 2.4rem);
  font-variant-numeric: tabular-nums;
}

.summary__chaos {
  margin: 1rem 0;
  font-size: 1.15rem;
  font-weight: 900;
}

.summary__actions {
  display: grid;
  gap: 0.65rem;
}

.summary .start-button {
  min-height: 3.4rem;
  margin-top: 0;
  padding-block: 0.75rem;
  font-size: 1rem;
}

@keyframes summary-in {
  from { opacity: 0; transform: scale(0.985); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes hud-pulse {
  0%, 100% { transform: scale(1); }
  45% { transform: scale(1.08); }
}

@keyframes hud-level-up {
  0%, 100% { transform: scale(1); filter: brightness(1); }
  40% { transform: scale(1.13); filter: brightness(1.3); }
}

@keyframes canvas-shake {
  0%, 100% { transform: translate3d(0, 0, 0); }
  25% { transform: translate3d(-0.2rem, 0.12rem, 0); }
  50% { transform: translate3d(0.18rem, -0.14rem, 0); }
  75% { transform: translate3d(-0.1rem, -0.08rem, 0); }
}
@keyframes drift {
  from { transform: translate3d(-3%, -2%, 0) scale(0.96); }
  to { transform: translate3d(7%, 5%, 0) scale(1.08); }
}

@keyframes panel-in {
  from { opacity: 0; transform: translateX(1rem) scale(0.98); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 0.75rem); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

@media (min-width: 48rem) {
  .welcome {
    padding: 2rem;
  }

  .welcome__card {
    padding: 3.2rem;
  }

  .features {
    gap: 0.7rem;
  }

  .features li {
    padding-inline: 1rem;
  }

  .panel {
    padding: 1.5rem;
  }

  .game-controls {
    bottom: max(0.75rem, env(safe-area-inset-bottom));
  }
}


@media (min-width: 48rem) and (max-height: 50rem) {
  .welcome__card {
    padding: 1.5rem 2rem;
  }

  h1 {
    font-size: 4.5rem;
  }

  .welcome__lead {
    margin-top: 1rem;
    font-size: 1.1rem;
  }

  .features {
    margin-top: 0.8rem;
  }

  .theme-picker {
    margin-top: 0.7rem;
    padding: 0.6rem;
  }

  .start-button {
    margin-top: 1rem;
  }

  .welcome__hint {
    margin-top: 0.6rem;
  }
}
@media (max-height: 42rem) and (orientation: landscape) {
  .welcome {
    place-items: start center;
  }

  .welcome__card {
    margin: auto;
    padding-block: 1.25rem;
  }

  h1 {
    font-size: clamp(2.8rem, 10vh, 4rem);
  }

  .welcome__lead {
    margin-top: 0.85rem;
  }

  .features {
    margin-top: 0.85rem;
  }

  .start-button {
    min-height: 3.25rem;
    margin-top: 1rem;
    padding-block: 0.65rem;
  }

  .welcome__hint {
    margin-top: 0.6rem;
  }
}

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