:root {
  --bg: #120c24;
  --panel: #21173d;
  --panel-2: #2d2152;
  --line: #43357a;
  --text: #f4efff;
  --muted: #b3a8d6;
  --accent: #ffcf6b;
  --accent-2: #ff7ab8;
  --good: #5fe08a;
  --bad: #ff6070;
  --radius: 12px;
  --header-h: 48px;
  --hud-h: 64px;
  --bottom-h: 58px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Ubuntu, sans-serif;
  -webkit-text-size-adjust: 100%;
}

a {
  color: var(--accent);
}

button {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.site-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
}

.site-logo {
  font-weight: 800;
  font-size: 20px;
  text-decoration: none;
  color: var(--text);
  letter-spacing: 0.5px;
}

.site-logo span {
  color: var(--accent);
  font-weight: 600;
  font-size: 13px;
  margin-left: 6px;
  text-transform: uppercase;
  letter-spacing: 2px;
}

.site-header nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
}

.page {
  padding: 8px 8px 40px;
}

/* ---------- Game layout ---------- */

.game-root {
  position: relative;
  margin: 0 auto;
  width: 100%;
  max-width: 560px;
  background: #0b0718;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  flex-direction: column;
}

.stage {
  position: relative;
  width: 100%;
  aspect-ratio: var(--board-ar, 1);
  max-height: calc(100vh - var(--header-h) - var(--hud-h) - var(--bottom-h) - 26px);
  max-height: calc(100dvh - var(--header-h) - var(--hud-h) - var(--bottom-h) - 26px);
  min-height: 300px;
}

.stage.menu {
  aspect-ratio: auto;
  height: min(calc(100dvh - var(--header-h) - 26px), 760px);
}

.stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  outline: none;
}

.hud-top {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  min-height: var(--hud-h);
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.hud-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
}

.hud-moves {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 58px;
  padding: 2px 6px;
  background: var(--panel-2);
  border-radius: 10px;
  border: 1px solid var(--line);
}

.hud-big {
  font-size: 26px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1.05;
}

.hud-moves.low .hud-big {
  color: var(--bad);
  animation: throb 0.9s ease-in-out infinite;
}

@keyframes throb {
  50% {
    transform: scale(1.15);
  }
}

.hud-goals {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  flex: 1 1 auto;
  justify-content: center;
}

.goal {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px 3px 4px;
  background: var(--panel-2);
  border-radius: 999px;
  border: 1px solid var(--line);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  font-size: 16px;
}

.goal.done {
  border-color: var(--good);
  color: var(--good);
}

.goal.bump {
  animation: bump 0.25s ease-out;
}

@keyframes bump {
  0% {
    transform: scale(1.2);
  }
}

.hud-score {
  min-width: 110px;
  flex: 0 1 150px;
}

.score-line {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px;
}

#score {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.star-bar {
  position: relative;
  height: 10px;
  margin-top: 4px;
  background: #0d0920;
  border-radius: 6px;
  border: 1px solid var(--line);
}

.star-fill {
  height: 100%;
  width: 0;
  border-radius: 6px;
  background: linear-gradient(90deg, #ffb347, #ffe98a);
  transition: width 0.25s ease-out;
}

.star-tick {
  position: absolute;
  top: -5px;
  width: 16px;
  height: 16px;
  margin-left: -8px;
  clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
  background: #4a3f78;
}

.star-tick.lit {
  background: #ffd23a;
}

.btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 10px;
  padding: 8px 14px;
  font-weight: 700;
}

.btn:hover {
  border-color: var(--muted);
}

.btn:focus-visible,
.booster:focus-visible,
.lvl:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-icon {
  min-width: 42px;
  height: 42px;
  padding: 0 8px;
}

.btn-primary {
  background: linear-gradient(180deg, #ffd978, #ffae3a);
  color: #3a1d00;
  border-color: #ffcf6b;
  font-size: 18px;
  padding: 12px 26px;
  box-shadow: 0 4px 0 #b36a00;
}

.btn-primary:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #b36a00;
}

.btn:disabled,
.booster:disabled {
  opacity: 0.45;
  cursor: default;
}

.hud-bottom {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 6px;
  min-height: var(--bottom-h);
  background: var(--panel);
  border-top: 1px solid var(--line);
}

.booster {
  position: relative;
  width: 52px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  display: flex;
  align-items: center;
  justify-content: center;
}

.booster.active {
  border-color: var(--bad);
  box-shadow: 0 0 0 2px var(--bad) inset;
}

.b-count {
  position: absolute;
  right: -4px;
  top: -6px;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  background: var(--accent-2);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* ---------- Overlay screens ---------- */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: rgba(10, 6, 24, 0.68);
  overflow-y: auto;
  z-index: 5;
}

.overlay:empty {
  display: none;
}

.overlay.clear {
  background: transparent;
}

.card {
  width: 100%;
  max-width: 440px;
  max-height: 100%;
  overflow-y: auto;
  background: linear-gradient(180deg, #2c2056, #1d1438);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  text-align: center;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
  animation: pop 0.22s ease-out;
}

@keyframes pop {
  0% {
    transform: scale(0.9);
    opacity: 0;
  }
}

.card h2 {
  margin: 0 0 6px;
  font-size: 26px;
}

.card p {
  color: var(--muted);
  margin: 6px 0;
  line-height: 1.45;
}

.row-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 14px;
}

.logo {
  font-size: 40px;
  font-weight: 900;
  letter-spacing: 2px;
  line-height: 1;
  margin: 4px 0 2px;
  background: linear-gradient(90deg, #ff6b8b, #ffcf6b, #6bffb0, #6bc8ff, #c58bff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.title-menu {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: stretch;
  max-width: 260px;
  margin: 16px auto 0;
}

.streak {
  color: var(--accent);
  font-weight: 700;
}

/* Map */
.map {
  width: 100%;
  max-width: 520px;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #221842, #140d2a);
  border-radius: 14px;
  border: 1px solid var(--line);
  overflow: hidden;
}

.map-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.map-stars {
  font-weight: 800;
  font-size: 18px;
}

.chest {
  flex: 1 1 150px;
  font-size: 12px;
  color: var(--muted);
}

.chest .bar {
  height: 10px;
  background: #0d0920;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--line);
  margin-top: 3px;
}

.chest .bar > div {
  height: 100%;
  background: linear-gradient(90deg, #ff7ab8, #ffcf6b);
}

.inventory {
  display: flex;
  gap: 8px;
  width: 100%;
  justify-content: center;
  font-size: 13px;
  color: var(--muted);
}

.inventory span {
  display: flex;
  align-items: center;
  gap: 3px;
}

.map-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
}

.episode {
  margin-bottom: 14px;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
}

.episode h3 {
  margin: 0 0 8px;
  font-size: 15px;
  display: flex;
  justify-content: space-between;
}

.episode h3 small {
  color: var(--muted);
  font-weight: 600;
}

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

.lvl {
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.08);
  font-weight: 800;
  font-size: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0;
  position: relative;
}

.lvl .st {
  font-size: 10px;
  letter-spacing: -1px;
  color: #ffd23a;
  line-height: 1;
}

.lvl.locked {
  opacity: 0.35;
}

.lvl.hard {
  border-color: #ff6070;
}

.lvl.current {
  background: linear-gradient(180deg, #ffd978, #ffae3a);
  color: #3a1d00;
  border-color: #fff;
  animation: glow 1.2s ease-in-out infinite;
}

@keyframes glow {
  50% {
    box-shadow: 0 0 14px 4px rgba(255, 207, 107, 0.8);
  }
}

/* Intro / results */
.goal-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin: 10px 0;
}

.tip {
  background: rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  padding: 8px 10px;
  color: var(--text) !important;
}

.big-stars {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 8px 0;
}

.big-star {
  width: 54px;
  height: 54px;
  clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
  background: #3d335f;
  transition: background 0.2s;
}

.big-star.lit {
  background: #ffd23a;
  animation: pop 0.3s ease-out;
}

.big-star:nth-child(2) {
  transform: translateY(-10px) scale(1.15);
}

.result-score {
  font-size: 30px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.rewards {
  text-align: left;
  font-size: 14px;
  margin: 8px 0;
  padding: 0;
  list-style: none;
}

.rewards li {
  padding: 6px 8px;
  border-radius: 8px;
  background: rgba(255, 207, 107, 0.1);
  margin-bottom: 4px;
}

.progress-list {
  margin: 8px 0;
}

.progress-list .bar {
  height: 10px;
  background: #0d0920;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--line);
  margin: 2px 0 8px;
}

.progress-list .bar > div {
  height: 100%;
  background: linear-gradient(90deg, #5fe08a, #c7ff8a);
}

.ach-list {
  list-style: none;
  padding: 0;
  margin: 8px 0;
  text-align: left;
}

.ach-list li {
  padding: 8px;
  border-radius: 8px;
  margin-bottom: 4px;
  background: rgba(255, 255, 255, 0.04);
  opacity: 0.55;
}

.ach-list li.got {
  opacity: 1;
  background: rgba(95, 224, 138, 0.1);
}

.ach-list small {
  display: block;
  color: var(--muted);
}

.toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 8px 0;
  color: var(--text);
}

/* ---------- Ads & page ---------- */

.ad-slot {
  max-width: 970px;
  margin: 12px auto 0;
  min-height: 0;
}

.ad-slot[data-filled='true'] {
  min-height: 90px;
}

.about {
  max-width: 820px;
  margin: 24px auto 0;
  color: var(--muted);
  line-height: 1.55;
  font-size: 15px;
}

.about h1,
.about h2 {
  color: var(--text);
}

kbd {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 5px;
  font-size: 12px;
  color: var(--text);
}

@media (max-width: 520px) {
  .page {
    padding: 0 0 32px;
  }
  .game-root {
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }
  .hud-top {
    gap: 6px;
    padding: 6px;
  }
  .hud-score {
    min-width: 84px;
    flex: 0 1 104px;
  }
  .hud-goals {
    gap: 4px;
  }
  .goal {
    padding: 2px 6px 2px 3px;
  }
  .hud-big {
    font-size: 22px;
  }
  .goal {
    font-size: 14px;
  }
  .about {
    padding: 0 12px;
  }
}

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