:root {
  --pink: #f071b5;
  --pink-soft: #ffe0f1;
  --purple: #7657d8;
  --purple-dark: #4e368f;
  --purple-soft: #eee8ff;
  --blue: #4eb9e8;
  --blue-soft: #dff6ff;
  --ink: #2e2545;
  --white: #ffffff;
  --shadow: 0 18px 50px rgba(78, 54, 143, 0.18);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: #f9f5ff;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: "Trebuchet MS", "Avenir Next", system-ui, sans-serif;
  background:
    radial-gradient(circle at 12% 8%, rgba(240, 113, 181, 0.24), transparent 23rem),
    radial-gradient(circle at 88% 18%, rgba(78, 185, 232, 0.26), transparent 25rem),
    linear-gradient(145deg, #fff9fd 0%, #f1edff 50%, #e9f9ff 100%);
}

button {
  font: inherit;
}

button:focus-visible {
  outline: 4px solid rgba(78, 185, 232, 0.48);
  outline-offset: 3px;
}

.page-shell {
  width: min(1120px, calc(100% - 24px));
  margin: 0 auto;
  padding: 18px 0 28px;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 14px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--purple);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 3.2rem);
  line-height: 0.95;
}

.subtitle {
  margin: 7px 0 0;
  color: #695c82;
  font-weight: 700;
}

.sound-button {
  width: 50px;
  height: 50px;
  border: 1px solid rgba(118, 87, 216, 0.18);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 8px 24px rgba(78, 54, 143, 0.12);
  cursor: pointer;
}

.hud {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 10px;
}

.hud-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 54px;
  padding: 10px 14px;
  border: 1px solid rgba(118, 87, 216, 0.13);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.83);
  box-shadow: 0 8px 24px rgba(78, 54, 143, 0.09);
}

.hud-label {
  color: #786d8d;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.praga-card.ready {
  border-color: rgba(78, 185, 232, 0.5);
  background: var(--blue-soft);
}

.praga-card.used {
  opacity: 0.68;
}

.journey {
  position: relative;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin: 3px 18px 12px;
}

.journey-line {
  position: absolute;
  top: 17px;
  right: 8%;
  left: 8%;
  z-index: 0;
  height: 4px;
  border-radius: 999px;
  background: rgba(118, 87, 216, 0.18);
}

.journey-node {
  position: relative;
  z-index: 1;
  display: grid;
  justify-items: center;
  gap: 3px;
  color: #807490;
  font-size: 0.72rem;
  font-weight: 900;
}

.journey-node span {
  display: grid;
  place-items: center;
  width: 37px;
  height: 37px;
  border: 3px solid white;
  border-radius: 50%;
  background: #ddd5ed;
  box-shadow: 0 4px 12px rgba(78, 54, 143, 0.14);
}

.journey-node.active span {
  color: white;
  background: linear-gradient(135deg, var(--pink), var(--purple));
  transform: scale(1.08);
}

.journey-node.completed span {
  color: white;
  background: var(--blue);
}

.game-stage {
  position: relative;
  height: min(65vh, 650px);
  min-height: 430px;
  overflow: hidden;
  border: 3px solid rgba(255, 255, 255, 0.88);
  border-radius: 32px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(118, 87, 216, 0.08)),
    linear-gradient(180deg, #c9f0ff 0%, #ebe6ff 52%, #fce7f4 100%);
  box-shadow: var(--shadow);
  touch-action: pan-y;
  isolation: isolate;
}

.game-stage.world-1 {
  background:
    radial-gradient(circle at 14% 88%, rgba(126, 221, 165, 0.52), transparent 24%),
    linear-gradient(180deg, #c9f0ff 0%, #ebe6ff 52%, #fce7f4 100%);
}

.game-stage.world-2 {
  background:
    radial-gradient(circle at 18% 70%, rgba(77, 196, 144, 0.55), transparent 26%),
    radial-gradient(circle at 82% 35%, rgba(171, 117, 224, 0.45), transparent 27%),
    linear-gradient(180deg, #77cae6 0%, #8169c5 55%, #315f69 100%);
}

.game-stage.world-3 {
  background:
    repeating-linear-gradient(90deg, transparent 0 54px, rgba(255, 255, 255, 0.09) 55px 58px),
    repeating-linear-gradient(0deg, transparent 0 54px, rgba(255, 255, 255, 0.08) 55px 58px),
    linear-gradient(160deg, #263c75, #7b4bb5 54%, #db64a5);
}

.game-stage.world-4 {
  background:
    radial-gradient(circle at 50% 42%, rgba(99, 207, 236, 0.35), transparent 24%),
    radial-gradient(circle at 18% 82%, rgba(170, 103, 223, 0.35), transparent 23%),
    linear-gradient(180deg, #172549 0%, #352b60 56%, #17253a 100%);
}

.game-stage.world-5 {
  background:
    radial-gradient(circle at 50% 30%, rgba(255, 143, 213, 0.48), transparent 18%),
    radial-gradient(circle at 15% 55%, rgba(82, 206, 238, 0.42), transparent 22%),
    radial-gradient(circle at 84% 65%, rgba(136, 92, 231, 0.52), transparent 24%),
    linear-gradient(165deg, #111b45, #432573 55%, #151639);
}

.world-label {
  position: absolute;
  top: 13px;
  left: 14px;
  z-index: 11;
  max-width: calc(100% - 28px);
  padding: 7px 11px;
  border: 1px solid rgba(255, 255, 255, 0.64);
  border-radius: 999px;
  color: var(--purple-dark);
  font-size: 0.78rem;
  font-weight: 900;
  background: rgba(255, 255, 255, 0.84);
  box-shadow: 0 5px 16px rgba(34, 24, 78, 0.14);
}

.game-stage::after {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: -1;
  height: 18%;
  content: "";
  background:
    radial-gradient(ellipse at 50% 0%, rgba(255, 255, 255, 0.95), transparent 66%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.74), #d4c9ff);
}

.cloud {
  position: absolute;
  width: 140px;
  height: 44px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.62);
  filter: blur(1px);
}

.cloud::before,
.cloud::after {
  position: absolute;
  bottom: 12px;
  content: "";
  border-radius: 50%;
  background: inherit;
}

.cloud::before {
  left: 23px;
  width: 58px;
  height: 58px;
}

.cloud::after {
  right: 21px;
  width: 74px;
  height: 74px;
}

.cloud-one {
  top: 18%;
  left: 8%;
}

.cloud-two {
  top: 10%;
  right: 10%;
  transform: scale(0.78);
}

.player {
  position: absolute;
  bottom: 1.5%;
  left: 50%;
  z-index: 5;
  width: clamp(145px, 22vw, 235px);
  height: auto;
  user-select: none;
  transform: translateX(-50%);
  transform-origin: center bottom;
  filter: drop-shadow(0 12px 11px rgba(61, 38, 112, 0.22));
  will-change: left, transform;
}

.game-stage.running .player {
  animation: run-bob 420ms ease-in-out infinite alternate;
}

.game-stage.hit .player {
  animation: hit-shake 440ms ease-out;
}

.game-stage.won .player {
  animation: victory 650ms ease-in-out infinite alternate;
}

.game-stage.celebrating .player {
  z-index: 16;
  animation: celebration-dance 360ms ease-in-out infinite alternate;
  filter:
    drop-shadow(0 0 12px rgba(255, 255, 255, 0.96))
    drop-shadow(0 15px 16px rgba(91, 46, 153, 0.36));
}

.confetti-piece {
  position: absolute;
  top: -22px;
  z-index: 14;
  width: 11px;
  height: 18px;
  border: 1px solid rgba(255, 255, 255, 0.62);
  border-radius: 4px;
  pointer-events: none;
  animation: confetti-fall 1.45s ease-in var(--confetti-delay) forwards;
}

.collectible {
  position: absolute;
  z-index: 3;
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  pointer-events: none;
  will-change: transform, top;
}

.collectible.heart {
  filter: drop-shadow(0 7px 8px rgba(240, 68, 154, 0.3));
}

.heart-shape {
  position: relative;
  width: 33px;
  height: 33px;
  border-radius: 7px 4px 7px 4px;
  background: linear-gradient(135deg, #ffb8dd 0%, #fa66b0 48%, #d92d88 100%);
  transform: rotate(-45deg);
}

.heart-shape::before,
.heart-shape::after {
  position: absolute;
  width: 33px;
  height: 33px;
  content: "";
  border-radius: 50%;
  background: inherit;
}

.heart-shape::before {
  top: -17px;
  left: 0;
}

.heart-shape::after {
  top: 0;
  left: 17px;
}

.collectible.potion {
  border: 3px solid rgba(255, 255, 255, 0.88);
  border-radius: 17px;
  color: white;
  font-size: 1.7rem;
  background: linear-gradient(145deg, #53c7ef, #7760ed 56%, #b45de1);
  box-shadow: inset 0 0 14px rgba(255, 255, 255, 0.42), 0 8px 16px rgba(74, 68, 191, 0.26);
  animation: cube-spin 1.2s ease-in-out infinite alternate;
}

.collectible.glitch {
  filter: drop-shadow(0 7px 8px rgba(30, 19, 52, 0.42));
  animation: glitch-jitter 320ms steps(2, end) infinite;
}

.collectible.glitch .heart-shape {
  background: linear-gradient(135deg, #d6d1df 0%, #766987 48%, #2d2538 100%);
}

.collectible.glitch::after {
  position: absolute;
  z-index: 2;
  color: #fff;
  content: "⚡";
  font-size: 1.15rem;
  text-shadow: 0 2px 5px #241c32;
}

.collectible.obstacle {
  border: 3px solid rgba(255, 255, 255, 0.82);
  border-radius: 50%;
  color: white;
  font-size: 1.75rem;
  font-weight: 900;
  background: radial-gradient(circle at 35% 28%, #a796c8, #49375f 58%, #21192d);
  box-shadow: inset 0 0 14px rgba(255, 255, 255, 0.28), 0 9px 18px rgba(31, 19, 48, 0.38);
  animation: obstacle-sway 650ms ease-in-out infinite alternate;
}

.world-1 .collectible.obstacle {
  background: radial-gradient(circle at 35% 28%, #d28de0, #70408a 58%, #342040);
}

.world-2 .collectible.obstacle {
  background: radial-gradient(circle at 35% 28%, #b4ebee, #4f8fa8 58%, #285263);
}

.world-3 .collectible.obstacle {
  border-radius: 12px;
  background: linear-gradient(135deg, #b55bd7, #563172 54%, #1f1932);
}

.world-4 .collectible.obstacle {
  background: radial-gradient(circle at 35% 28%, #ffe59d, #987053 58%, #3b2b36);
}

.world-5 .collectible.obstacle {
  background: radial-gradient(circle at 35% 28%, #fff6a7, #e05cae 48%, #482675);
}

.collectible.collected {
  opacity: 0;
  transform: scale(1.65) rotate(14deg);
  transition: 180ms ease-out;
}

.status-pill {
  position: absolute;
  top: 14px;
  left: 50%;
  z-index: 10;
  padding: 9px 15px;
  border: 2px solid rgba(255, 255, 255, 0.78);
  border-radius: 999px;
  color: white;
  font-weight: 900;
  background: linear-gradient(90deg, #4eb9e8, #7657d8);
  box-shadow: 0 8px 22px rgba(78, 54, 143, 0.24);
  transform: translateX(-50%);
}

.speed-lines {
  position: absolute;
  inset: 0;
  z-index: 1;
  opacity: 0;
  background: repeating-linear-gradient(105deg, transparent 0 45px, rgba(255, 255, 255, 0.45) 46px 49px, transparent 50px 90px);
  transform: translateX(30%);
  transition: opacity 200ms ease;
}

.speed-lines.active {
  opacity: 0.55;
  animation: speed-sweep 600ms linear infinite;
}

.announcement {
  position: absolute;
  top: 70px;
  left: 50%;
  z-index: 20;
  width: max-content;
  max-width: 80%;
  margin: 0;
  padding: 8px 13px;
  border-radius: 13px;
  color: var(--purple-dark);
  font-weight: 900;
  text-align: center;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 6px 18px rgba(78, 54, 143, 0.15);
  opacity: 0;
  transform: translate(-50%, -6px);
  transition: 200ms ease;
  pointer-events: none;
}

.announcement.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.game-overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
  overflow-y: auto;
  background: rgba(52, 36, 91, 0.45);
  backdrop-filter: blur(6px);
  overscroll-behavior: contain;
}

.game-overlay[hidden] {
  display: none;
}

.overlay-card {
  display: flex;
  flex-direction: column;
  width: min(520px, 100%);
  max-height: 100%;
  padding: clamp(22px, 5vw, 38px);
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 28px;
  text-align: center;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 24px 60px rgba(38, 25, 78, 0.32);
}

.overlay-copy {
  min-height: 0;
  padding: 0 3px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.overlay-icon {
  display: block;
  margin-bottom: 8px;
  font-size: 2.4rem;
}

.overlay-card h2 {
  margin: 0 0 10px;
  color: var(--purple-dark);
  font-size: clamp(1.55rem, 4vw, 2.45rem);
}

.overlay-card p {
  margin: 0 auto;
  max-width: 42ch;
  color: #665b79;
  line-height: 1.5;
}

.overlay-card .overlay-chapter {
  margin-bottom: 7px;
  color: var(--purple);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.overlay-card .story-clue {
  margin-top: 13px;
  padding: 10px 12px;
  border-radius: 13px;
  color: #55426f;
  font-weight: 800;
  background: var(--purple-soft);
}

.instructions {
  margin: 18px auto;
  padding-left: 1.2rem;
  max-width: 410px;
  color: #554966;
  line-height: 1.45;
  text-align: left;
}

.primary-button {
  flex: 0 0 auto;
  min-height: 50px;
  margin-top: 14px;
  padding: 12px 24px;
  border: 0;
  border-radius: 16px;
  color: white;
  font-weight: 900;
  background: linear-gradient(135deg, var(--pink), var(--purple));
  box-shadow: 0 10px 24px rgba(118, 87, 216, 0.28);
  cursor: pointer;
}

.touch-controls {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin: 14px 0 4px;
}

.touch-controls button {
  width: min(180px, 42vw);
  min-height: 58px;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 18px;
  color: white;
  font-size: 1.55rem;
  background: linear-gradient(145deg, #5cc8ee, #7657d8);
  box-shadow: 0 9px 22px rgba(78, 54, 143, 0.21);
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
}

.touch-controls button:active,
.touch-controls button.active {
  transform: translateY(2px) scale(0.98);
  filter: brightness(1.1);
}

.game-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 12px;
  color: #746985;
  font-size: 0.88rem;
}

.game-footer p {
  margin: 0;
}

.text-button {
  border: 0;
  color: var(--purple-dark);
  font-weight: 900;
  background: transparent;
  cursor: pointer;
}

@keyframes run-bob {
  from { transform: translateX(-50%) translateY(0) rotate(-1deg); }
  to { transform: translateX(-50%) translateY(-6px) rotate(1deg); }
}

@keyframes hit-shake {
  0%, 100% { transform: translateX(-50%); }
  25% { transform: translateX(calc(-50% - 14px)) rotate(-3deg); }
  50% { transform: translateX(calc(-50% + 13px)) rotate(3deg); }
  75% { transform: translateX(calc(-50% - 7px)); }
}

@keyframes victory {
  from { transform: translateX(-50%) translateY(0) rotate(-2deg); }
  to { transform: translateX(-50%) translateY(-18px) rotate(2deg); }
}

@keyframes celebration-dance {
  from {
    transform: translateX(-50%) translateY(0) rotate(-5deg) scale(1);
  }
  to {
    transform: translateX(-50%) translateY(-24px) rotate(5deg) scale(1.08);
  }
}

@keyframes confetti-fall {
  0% {
    top: -22px;
    opacity: 0;
    transform: translateX(0) rotate(0deg);
  }
  12% {
    opacity: 1;
  }
  100% {
    top: 108%;
    opacity: 0.95;
    transform: translateX(var(--confetti-drift)) rotate(720deg);
  }
}

@keyframes cube-spin {
  from { transform: rotate(-8deg) scale(0.92); }
  to { transform: rotate(8deg) scale(1.04); }
}

@keyframes speed-sweep {
  from { transform: translateX(30%); }
  to { transform: translateX(-30%); }
}

@keyframes glitch-jitter {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(4px); }
}

@keyframes obstacle-sway {
  from { transform: rotate(-9deg) scale(0.94); }
  to { transform: rotate(9deg) scale(1.04); }
}

@media (min-width: 761px) and (max-height: 850px) {
  .page-shell {
    padding-top: 8px;
  }

  .game-header {
    margin-bottom: 8px;
  }

  h1 {
    font-size: clamp(1.8rem, 3vw, 2.45rem);
  }

  .subtitle {
    margin-top: 4px;
  }

  .hud {
    margin-bottom: 6px;
  }

  .hud-card {
    min-height: 46px;
    padding-top: 7px;
    padding-bottom: 7px;
  }

  .journey {
    margin-bottom: 6px;
  }

  .journey-line {
    top: 14px;
  }

  .journey-node span {
    width: 31px;
    height: 31px;
  }

  .game-stage {
    height: calc(100vh - 245px);
    min-height: 360px;
    border-radius: 24px;
  }

  .game-overlay {
    padding: 8px;
  }

  .overlay-card {
    max-height: calc(100% - 4px);
    padding: 14px 24px 16px;
  }

  .overlay-icon {
    margin-bottom: 2px;
    font-size: 1.65rem;
  }

  .overlay-card h2 {
    margin-bottom: 6px;
    font-size: clamp(1.35rem, 3vw, 2rem);
  }

  .overlay-card p {
    line-height: 1.35;
  }

  .overlay-card .story-clue {
    margin-top: 7px;
    padding: 7px 10px;
  }

  .instructions {
    margin: 8px auto;
    font-size: 0.84rem;
    line-height: 1.3;
  }

  .primary-button {
    min-height: 43px;
    margin-top: 8px;
    padding: 9px 20px;
  }
}

@media (min-width: 761px) and (max-height: 650px) {
  .overlay-icon {
    display: none;
  }

  .instructions {
    margin: 6px auto;
  }

  .game-stage {
    min-height: 330px;
  }

  .game-overlay {
    padding: 8px;
  }

  .overlay-card {
    max-height: calc(100% - 2px);
    padding: 15px 14px 12px;
    border-radius: 20px;
  }

  .overlay-icon {
    margin-bottom: 2px;
    font-size: 1.65rem;
  }

  .overlay-card h2 {
    margin-bottom: 6px;
    font-size: clamp(1.35rem, 7vw, 1.8rem);
  }

  .overlay-card p {
    line-height: 1.35;
  }

  .overlay-card .story-clue {
    margin-top: 8px;
    padding: 7px 9px;
  }

  .instructions {
    margin: 8px auto 0;
    font-size: 0.83rem;
    line-height: 1.3;
  }

  .primary-button {
    width: 100%;
    min-height: 46px;
    margin-top: 8px;
  }
}

@media (max-width: 760px) {
  .page-shell {
    width: min(100% - 14px, 680px);
    padding-top: 10px;
  }

  .hud {
    grid-template-columns: repeat(2, 1fr);
  }

  .hud-card {
    min-height: 48px;
    padding: 8px 11px;
  }

  .journey {
    margin-right: 5px;
    margin-left: 5px;
  }

  .journey-node small {
    font-size: 0.62rem;
  }

  .world-label {
    top: 9px;
    font-size: 0.68rem;
  }

  .game-stage {
    height: 58vh;
    min-height: 390px;
    border-radius: 24px;
  }

  .game-overlay {
    padding: 8px;
  }

  .overlay-card {
    max-height: calc(100% - 2px);
    padding: 15px 14px 12px;
    border-radius: 20px;
  }

  .overlay-icon {
    margin-bottom: 2px;
    font-size: 1.65rem;
  }

  .overlay-card h2 {
    margin-bottom: 6px;
    font-size: clamp(1.35rem, 7vw, 1.8rem);
  }

  .overlay-card p {
    line-height: 1.35;
  }

  .overlay-card .story-clue {
    margin-top: 8px;
    padding: 7px 9px;
  }

  .instructions {
    margin: 8px auto 0;
    font-size: 0.83rem;
    line-height: 1.3;
  }

  .primary-button {
    width: 100%;
    min-height: 46px;
    margin-top: 8px;
  }

  .player {
    width: clamp(132px, 36vw, 190px);
  }

  .collectible {
    width: 51px;
    height: 51px;
  }

  .game-footer {
    align-items: flex-start;
    flex-direction: column;
  }
}

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