:root {
  color-scheme: dark;
  --bg: #07090d;
  --panel: #111720;
  --line: #273344;
  --text: #f3f7fb;
  --muted: #92a2b4;
  --hot: #ff4f7b;
  --gold: #ffc857;
  --blue: #59d7ff;
  --green: #57e39f;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 0%, rgba(89, 215, 255, 0.18), transparent 34%),
    radial-gradient(circle at 18% 80%, rgba(255, 79, 123, 0.16), transparent 32%),
    var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Arial, sans-serif;
}

.app {
  width: 100vw;
  height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px;
  padding: 10px;
}

.hud {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
}

.hud div,
.bar {
  background: rgba(12, 17, 24, 0.9);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.hud div {
  min-height: 58px;
  padding: 9px 12px;
}

.hud span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.hud strong {
  font-size: clamp(19px, 2vw, 26px);
}

.play-layout {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
}

.ad-slot {
  display: none;
  align-items: center;
  justify-content: center;
  min-width: 0;
  border: 1px dashed rgba(137, 210, 255, 0.22);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(12, 17, 24, 0.72), rgba(5, 9, 15, 0.62));
  color: rgba(184, 199, 216, 0.72);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.ad-slot span {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
}

.stage {
  position: relative;
  grid-column: 1;
  min-width: 0;
  min-height: 0;
  height: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #05070a;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background:
    linear-gradient(180deg, rgba(4, 6, 9, 0.38), rgba(4, 6, 9, 0.82)),
    radial-gradient(circle at 30% 20%, rgba(89, 215, 255, 0.18), transparent 38%),
    rgba(4, 6, 9, 0.55);
}

.overlay.hidden { display: none; }

.panel {
  width: min(940px, calc(100% - 28px));
  max-height: calc(100% - 28px);
  overflow-y: auto;
  background:
    linear-gradient(180deg, rgba(20, 29, 42, 0.97), rgba(10, 15, 23, 0.97));
  border: 1px solid rgba(137, 210, 255, 0.22);
  border-radius: 8px;
  padding: 18px;
  box-shadow: 0 24px 90px rgba(0, 0, 0, 0.62), 0 0 42px rgba(89, 215, 255, 0.12);
  scrollbar-color: rgba(89, 215, 255, 0.45) rgba(255, 255, 255, 0.06);
}

.menu-panel {
  position: relative;
  width: calc(100% - 24px);
  height: calc(100% - 24px);
  max-height: calc(100% - 24px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding-bottom: 78px;
}

.menu-head {
  position: relative;
  padding: 18px 20px;
  margin-bottom: 12px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 8px;
  background:
    radial-gradient(circle at 18% 18%, rgba(255, 200, 87, 0.16), transparent 32%),
    linear-gradient(135deg, rgba(89, 215, 255, 0.16), rgba(255, 95, 147, 0.08));
}

.menu-head::after {
  content: "";
  position: absolute;
  right: 18px;
  top: 18px;
  width: 82px;
  height: 82px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 36% 32%, #ffffff 0 8%, #59d7ff 9% 34%, #1f6aff 35% 68%, #07111a 69% 100%);
  box-shadow: 0 0 32px rgba(89, 215, 255, 0.32);
  opacity: 0.72;
}

.menu-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(340px, 1.1fr);
  gap: 10px;
  min-height: 0;
  overflow-y: auto;
  padding: 0 4px 84px 0;
}

.menu-section {
  min-width: 0;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: rgba(6, 11, 18, 0.42);
}

.menu-section.wide {
  grid-column: 1 / -1;
}

.online-tools,
.music-tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 180px;
  gap: 8px;
  align-items: center;
  margin-top: 7px;
}

.music-tools {
  grid-template-columns: minmax(0, 1fr) 104px 150px;
}

.online-tools button,
.music-tools button {
  margin-top: 0;
  min-height: 42px;
  padding: 10px 12px;
  background: #172233;
  color: var(--text);
  border: 1px solid rgba(137, 210, 255, 0.24);
}

.online-board {
  display: grid;
  gap: 5px;
  min-height: 74px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}

.online-board li {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 7px 9px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 6px;
  background: rgba(10, 16, 24, 0.62);
  color: var(--muted);
  font-size: 12px;
}

.online-board b {
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.online-board strong {
  color: var(--gold);
}

.prestige-panel {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr) 190px;
  gap: 12px;
  align-items: center;
  margin-top: 8px;
}

.prestige-badge {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 1px solid rgba(137, 210, 255, 0.25);
  background: rgba(5, 9, 15, 0.62);
  box-shadow: 0 0 22px rgba(89, 215, 255, 0.14);
  overflow: hidden;
}

.prestige-badge img {
  width: 68px;
  height: 68px;
  object-fit: contain;
}

.prestige-badge.empty {
  color: var(--muted);
  font-size: 24px;
  font-weight: 900;
}

.prestige-info b,
.prestige-info span {
  display: block;
}

.prestige-info b {
  font-size: 15px;
}

.prestige-info span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  margin-top: 4px;
}

.prestige-meter {
  height: 9px;
  margin-top: 9px;
  border: 1px solid rgba(137, 210, 255, 0.22);
  border-radius: 999px;
  background: rgba(5, 9, 15, 0.7);
  overflow: hidden;
}

.prestige-meter i {
  display: block;
  height: 100%;
  width: var(--progress);
  background: linear-gradient(90deg, #59d7ff, #ffc857);
}

.prestige-panel button {
  margin-top: 0;
  min-height: 52px;
  background: linear-gradient(135deg, #ffc857, #ff5f93);
  color: #13080d;
}

.prestige-panel button.locked {
  background: #172233;
  color: var(--muted);
  border: 1px solid rgba(137, 210, 255, 0.18);
}

.panel button#start {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 18px;
  z-index: 5;
  width: auto;
  min-height: 50px;
  margin-top: 14px;
  border: 0;
  background: linear-gradient(135deg, #59d7ff, #57e39f);
  box-shadow: 0 -18px 28px rgba(10, 15, 23, 0.94), 0 0 24px rgba(89, 215, 255, 0.28);
}

.tag {
  margin: 0 0 8px;
  color: var(--blue);
  font-weight: 800;
  font-size: 12px;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

h1 {
  margin: 0 0 12px;
  font-size: 30px;
  line-height: 1.05;
}

p {
  color: var(--muted);
  line-height: 1.5;
}

button {
  width: 100%;
  border: 0;
  border-radius: 6px;
  padding: 13px 14px;
  margin-top: 10px;
  background: var(--blue);
  color: #041018;
  font: inherit;
  font-weight: 900;
  cursor: pointer;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid rgba(137, 210, 255, 0.24);
  border-radius: 6px;
  padding: 10px 12px;
  background: rgba(5, 9, 15, 0.72);
  color: var(--text);
  font: inherit;
  font-weight: 700;
}

select {
  cursor: pointer;
}

.choices {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 7px;
  margin: 7px 0 10px;
}

.choices.modes {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.choices.abilities {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.choices.upgrades {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.choices.meta-upgrades {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.chapter-panel {
  display: grid;
  gap: 8px;
  margin: 7px 0 10px;
}

.chapter-row,
.milestone-row {
  display: grid;
  gap: 7px;
}

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

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

.chapter-card,
.milestone {
  min-height: 58px;
  padding: 8px;
  border: 1px solid rgba(87, 117, 153, 0.6);
  border-radius: 7px;
  background:
    linear-gradient(180deg, rgba(24, 35, 50, 0.86), rgba(9, 15, 23, 0.9));
}

.chapter-card.active {
  border-color: rgba(89, 215, 255, 0.8);
  box-shadow: 0 0 18px rgba(89, 215, 255, 0.12);
}

.chapter-card.done,
.milestone.done {
  border-color: rgba(87, 227, 159, 0.55);
  background:
    linear-gradient(180deg, rgba(26, 58, 45, 0.72), rgba(10, 20, 18, 0.92));
}

.chapter-card b,
.chapter-card span,
.milestone b,
.milestone span {
  display: block;
}

.chapter-card b,
.milestone b {
  color: var(--text);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.chapter-card span,
.milestone span {
  color: var(--muted);
  font-size: 10px;
  line-height: 1.25;
  margin-top: 4px;
}

.milestone b {
  color: var(--gold);
}

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

.choices.skins {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

#colorChoices,
.choices.markings {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.choice-label {
  color: #b8c7d8;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  margin: 6px 0 0;
  text-transform: uppercase;
}

.pick {
  border: 1px solid rgba(87, 117, 153, 0.75);
  background: linear-gradient(180deg, rgba(25, 36, 50, 0.96), rgba(15, 23, 34, 0.96));
  border-radius: 7px;
  min-height: 62px;
  padding: 8px 7px;
  color: var(--text);
  cursor: pointer;
  text-align: center;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.18);
  transition: border-color 0.12s ease, transform 0.12s ease, box-shadow 0.12s ease;
}

.pick:hover {
  transform: translateY(-1px);
  border-color: rgba(89, 215, 255, 0.85);
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.26), 0 0 16px rgba(89, 215, 255, 0.14);
}

.pick.active {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(89, 215, 255, 0.2) inset, 0 0 18px rgba(89, 215, 255, 0.18);
}

.pick.locked,
.swatch.locked {
  border-color: #3b2d36;
  opacity: 0.58;
  filter: saturate(0.72);
}

.pick b {
  display: block;
  font-size: 12px;
  margin-top: 3px;
  overflow-wrap: anywhere;
}

.pick span {
  color: var(--muted);
  display: block;
  font-size: 11px;
  margin-top: 2px;
  line-height: 1.2;
}

.pick em {
  color: var(--gold);
  display: block;
  font-size: 10px;
  font-style: normal;
  margin-top: 4px;
}

.choices.markings .pick {
  min-height: 54px;
}

.skin-pick {
  min-height: 84px;
  padding: 5px;
}

.skin-pick img {
  display: block;
  width: 54px;
  height: 54px;
  object-fit: contain;
  margin: 0 auto 3px;
}

.skin-pick b {
  font-size: 10px;
  line-height: 1.05;
}

.swatch {
  position: relative;
  height: 42px;
  min-height: 42px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: radial-gradient(circle at 35% 30%, #ffffff 0 8%, var(--a) 9% 46%, var(--b) 47% 100%);
  cursor: pointer;
  color: transparent;
}

.swatch.locked::after {
  content: attr(data-cost);
  position: absolute;
  inset: auto 6px 5px;
  color: #fff2b8;
  font-size: 10px;
  font-weight: 900;
  text-align: center;
  text-shadow: 0 1px 3px #000;
}

.swatch.active {
  border-color: #ffffff;
  box-shadow: 0 0 0 2px rgba(89, 215, 255, 0.24), 0 0 18px var(--a);
}

button.upgrade {
  display: block;
  text-align: left;
  background: #1b2634;
  color: var(--text);
  border: 1px solid #334458;
}

button.upgrade span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-weight: 500;
}

.menu-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.menu-actions button {
  margin-top: 0;
}

.menu-actions button:nth-child(2),
.menu-actions button:nth-child(3) {
  background: #172233;
  color: var(--text);
  border: 1px solid rgba(137, 210, 255, 0.24);
}

.pause-panel,
.result-panel {
  width: min(560px, calc(100% - 28px));
}

.reward-line {
  margin: 8px 0 0;
  padding: 9px 11px;
  border: 1px solid rgba(255, 200, 87, 0.3);
  border-radius: 7px;
  background: rgba(255, 200, 87, 0.08);
  color: #ffe5a3;
  font-weight: 800;
}

.reward-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.reward-actions button {
  margin-top: 0;
  min-height: 48px;
}

.reward-ad {
  background: linear-gradient(135deg, #ffc857, #57e39f);
  color: #06100b;
  box-shadow: 0 0 22px rgba(255, 200, 87, 0.18);
}

.reward-ad.secondary {
  background: linear-gradient(135deg, #59d7ff, #a879ff);
  color: #041018;
}

.reward-ad:disabled {
  opacity: 0.68;
  cursor: default;
}

.ad-note {
  margin: 8px 0 0;
  color: rgba(184, 199, 216, 0.78);
  font-size: 12px;
}

.bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 16px;
  min-height: 42px;
  margin: 0;
  padding: 9px 12px;
  color: var(--muted);
}

#message {
  flex: 1 1 220px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.legal-links {
  display: inline-flex;
  gap: 10px;
  flex-wrap: wrap;
}

.legal-links a {
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
}

.legal-links a:hover {
  color: var(--blue);
}

.mobile-controls {
  display: none;
}

@media (max-width: 760px) {
  body { overflow: auto; }
  .app {
    min-height: 100vh;
    height: auto;
    padding: 8px;
    gap: 7px;
  }
  .stage {
    height: min(64vh, 680px);
    min-height: 360px;
  }
  .hud { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .hud div {
    min-height: 48px;
    padding: 7px 9px;
  }
  .hud strong { font-size: 19px; }
  h1 { font-size: 27px; }
  .menu-head {
    padding: 14px 16px;
  }
  .menu-head::after {
    width: 60px;
    height: 60px;
  }
  .menu-grid { grid-template-columns: 1fr; }
  .menu-panel {
    width: calc(100% - 16px);
    height: calc(100% - 16px);
    max-height: calc(100% - 16px);
  }
  .choices.skins,
  .choices.meta-upgrades,
  .chapter-row,
  .milestone-row,
  .choices.stages { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .online-tools,
  .music-tools,
  .prestige-panel { grid-template-columns: 1fr; }
  .prestige-badge { margin: 0 auto; }
  .menu-actions { grid-template-columns: 1fr; }
  .reward-actions { grid-template-columns: 1fr; }
  .bar { align-items: flex-start; flex-direction: column; gap: 6px; }
  .bar > span:not(#message) {
    display: none;
  }
  #message { flex: 0 1 auto; white-space: normal; }
  .mobile-controls {
    display: none;
    width: 100%;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
  }
  body.mobile-playing {
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: none;
  }
  body.mobile-playing .app {
    height: 100dvh;
    min-height: 0;
    grid-template-rows: minmax(0, 1fr) auto;
    padding: 0;
    gap: 0;
    overflow: hidden;
  }
  body.mobile-playing .hud,
  body.mobile-playing .ad-slot,
  body.mobile-playing .legal-links,
  body.mobile-playing #message,
  body.mobile-playing .bar > span:not(#message) {
    display: none;
  }
  body.mobile-playing .play-layout {
    height: 100%;
    min-height: 0;
    gap: 0;
  }
  body.mobile-playing .stage {
    height: 100%;
    min-height: 0;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }
  body.mobile-playing .bar {
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    padding: 8px;
    background: rgba(5, 8, 13, 0.96);
  }
  body.mobile-playing .mobile-controls {
    display: grid;
  }
  .mobile-controls button {
    min-height: 48px;
    margin: 0;
    border: 1px solid rgba(137, 210, 255, 0.28);
    background: linear-gradient(180deg, #172233, #0c121b);
    color: var(--text);
    box-shadow: none;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
  }
  .mobile-controls button.mobile-held {
    border-color: rgba(86, 232, 176, 0.8);
    background: linear-gradient(135deg, #55d5f2, #56e8b0);
    color: #031018;
  }
}

@media (max-width: 360px) {
  .hud { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) and (orientation: landscape) {
  .app {
    grid-template-rows: auto minmax(0, 1fr) auto;
    height: 100vh;
    min-height: 0;
    overflow: hidden;
  }
  .hud {
    grid-template-columns: repeat(7, minmax(0, 1fr));
  }
  .hud div {
    min-height: 42px;
    padding: 5px 7px;
  }
  .hud span {
    font-size: 9px;
  }
  .hud strong {
    font-size: 16px;
  }
  .stage {
    height: 100%;
    min-height: 0;
  }
  .bar {
    flex-direction: row;
    align-items: center;
  }
  .legal-links {
    display: none;
  }
  .mobile-controls {
    max-width: 460px;
    margin-left: auto;
  }
  body.mobile-playing .app {
    grid-template-rows: minmax(0, 1fr) auto;
  }
  body.mobile-playing .bar {
    padding: 6px 8px;
  }
  body.mobile-playing .mobile-controls {
    max-width: none;
  }
  body.mobile-playing .mobile-controls button {
    min-height: 42px;
  }
}

@media (min-width: 1500px) and (min-height: 760px) {
  .play-layout {
    grid-template-columns: minmax(120px, 160px) minmax(0, 1fr) minmax(120px, 160px);
  }

  .ad-slot {
    display: flex;
  }

  .ad-left { grid-column: 1; }
  .stage { grid-column: 2; }
  .ad-right { grid-column: 3; }
}
