:root {
  --bg: #0b0718;
  --ink: #f7f3ff;
  --muted: #c2b9de;
  --gold: #ffd166;
  --pink: #ff4d8d;
  --line: rgba(255, 255, 255, 0.14);
  --card: rgba(16, 12, 36, 0.72);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: Nunito, "Segoe UI", sans-serif;
}

body {
  position: fixed;
  inset: 0;
  width: 100%;
  overflow: hidden;
  user-select: none;
  touch-action: manipulation;
  background:
    radial-gradient(900px 520px at 50% -10%, rgba(124, 78, 255, 0.38), transparent 60%),
    radial-gradient(700px 480px at 110% 110%, rgba(255, 61, 134, 0.22), transparent 55%),
    var(--bg);
}

button {
  font-family: inherit;
  color: inherit;
  cursor: pointer;
  border: 0;
  background: none;
}

button:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

button:disabled { cursor: default; }

.bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}

.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(28px);
  opacity: 0.75;
}

.b1 {
  width: 280px;
  height: 280px;
  background: #ff3d86;
  top: -80px;
  left: -70px;
  animation: float 16s ease-in-out infinite;
}

.b2 {
  width: 340px;
  height: 340px;
  background: #6d4dff;
  right: -90px;
  bottom: -110px;
  animation: float 20s ease-in-out infinite reverse;
}

.b3 {
  width: 180px;
  height: 180px;
  background: #ffb703;
  top: 42%;
  left: 68%;
  opacity: 0.35;
  animation: float 13s ease-in-out infinite;
}

@keyframes float {
  50% { transform: translate(24px, 28px) scale(1.08); }
}

#app { position: relative; z-index: 1; height: 100%; }

.screen { position: absolute; inset: 0; }

.hidden { display: none !important; }

#screen-menu,
#screen-result { overflow-y: auto; -webkit-overflow-scrolling: touch; }

.wrap {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding: calc(16px + var(--safe-t)) 16px calc(20px + var(--safe-b));
}

.menu-card {
  width: min(460px, 100%);
  margin: auto;
  padding: 22px 16px 16px;
  border-radius: 28px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.05));
  border: 1px solid var(--line);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.28);
  backdrop-filter: blur(16px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}

.logo {
  width: 132px;
  height: 150px;
  margin: 0 auto;
  position: relative;
}

.logo-base {
  position: absolute;
  left: 50%;
  bottom: 4px;
  width: 108px;
  height: 18px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, #ffe7c4, #d09a52 62%, #6a3e16);
  box-shadow: 0 10px 16px rgba(0, 0, 0, 0.28);
}

.logo-pole {
  position: absolute;
  left: 50%;
  bottom: 14px;
  width: 12px;
  height: 120px;
  transform: translateX(-50%);
  border-radius: 8px;
  background: linear-gradient(90deg, #6b3d16, #fff4de 46%, #e8b56a 72%, #5a3414);
  z-index: 0;
}

.logo-pole::after {
  content: "";
  position: absolute;
  left: -2px;
  right: -2px;
  top: 42px;
  height: 4px;
  border-radius: 4px;
  background: var(--gold);
}

.logo-ring {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  justify-content: space-between;
  z-index: 1;
  filter: drop-shadow(0 4px 0 rgba(0, 0, 0, 0.18));
  animation: ringIn 0.7s ease both;
}

.logo-ring i {
  display: block;
  height: 16px;
  border-radius: 999px;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.55);
}

.logo-ring.c { bottom: 96px; width: 74px; animation-delay: 0.05s; }
.logo-ring.c i { width: 26px; background: #4cc9f0; }
.logo-ring.b { bottom: 70px; width: 98px; animation-delay: 0.15s; }
.logo-ring.b i { width: 36px; background: #ffd166; }
.logo-ring.a { bottom: 44px; width: 120px; animation-delay: 0.25s; }
.logo-ring.a i { width: 46px; background: #ff4d8d; }

@keyframes ringIn {
  from { transform: translateX(-50%) translateY(-16px); opacity: 0; }
  to { transform: translateX(-50%) translateY(0); opacity: 1; }
}

.titles h1 {
  margin: 0;
  font-size: clamp(2.15rem, 8vw, 3rem);
  line-height: 0.95;
  letter-spacing: -0.04em;
}

.tagline {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.eyebrow {
  margin: 0;
  color: #ffd4e6;
  font-weight: 800;
  letter-spacing: 0.04em;
  font-size: 0.82rem;
}

h2 { margin: 0; font-size: clamp(1.7rem, 6vw, 2.2rem); }

.group { text-align: left; }

.level-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.level-head .label { margin-bottom: 0; }

#level-progress {
  color: var(--gold);
  font-size: 0.75rem;
  font-weight: 800;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.lvl {
  min-height: 58px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 2px;
}

.lvl b { font-size: 1rem; line-height: 1; }

.lvl small {
  min-height: 0.85em;
  font-size: 0.62rem;
  letter-spacing: 0.06em;
  color: var(--gold);
  font-weight: 800;
}

.lvl.active {
  border-color: transparent;
  background: linear-gradient(180deg, #9b86ff, #6848e6);
  box-shadow: 0 8px 18px rgba(104, 72, 230, 0.35);
}

.lvl.locked { opacity: 0.42; }

.lvl:active:not(:disabled) { transform: scale(0.96); }

.level-brief {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.star-row {
  font-size: 1.7rem;
  letter-spacing: 0.14em;
  color: var(--gold);
  font-weight: 900;
  line-height: 1;
}

.label {
  margin-bottom: 8px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.seg, .levels {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.seg {
  padding: 6px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.06);
}

.seg button, .levels button {
  border-radius: 12px;
  padding: 10px 4px;
  font-weight: 800;
  line-height: 1.15;
}

.seg button {
  color: #f4efff;
}

.seg button small, .levels button small {
  display: block;
  margin-top: 2px;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--muted);
}

.seg button.active {
  background: linear-gradient(180deg, #ff8eb8, #ff3d82);
  color: white;
  box-shadow: 0 8px 18px rgba(255, 61, 130, 0.35);
}

.seg button.active small { color: rgba(255, 255, 255, 0.86); }

.levels button {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
}

.levels button.active {
  border-color: transparent;
  background: linear-gradient(180deg, #9b86ff, #6848e6);
  box-shadow: 0 8px 18px rgba(104, 72, 230, 0.35);
}

.levels button.active small { color: rgba(255, 255, 255, 0.86); }

.seg button:active, .levels button:active, .play:active, .ghost:active {
  transform: scale(0.98);
}

.best-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-radius: 14px;
  background: rgba(255, 209, 102, 0.12);
  border: 1px solid rgba(255, 209, 102, 0.32);
  color: var(--gold);
  font-weight: 800;
}

.best-pill strong {
  color: white;
  font-size: 1.35rem;
  font-variant-numeric: tabular-nums;
}

.play, .ghost, .text-btn { width: 100%; }

.play {
  padding: 15px 16px;
  border-radius: 16px;
  font-size: 1.15rem;
  font-weight: 900;
  color: white;
  background: linear-gradient(180deg, #ff9abb, #ff3d7f 58%, #e21668);
  box-shadow: 0 12px 26px rgba(255, 61, 127, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

.ghost {
  padding: 13px 16px;
  border-radius: 16px;
  font-weight: 800;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
}

.text-btn {
  padding: 8px;
  color: var(--muted);
  font-weight: 800;
}

.howto {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
  text-align: left;
}

.howto li {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.92rem;
}

.howto span {
  width: 26px;
  height: 26px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  color: white;
  font-weight: 800;
}

#screen-game {
  display: flex;
  flex-direction: column;
  background: #120c22;
}

.hud {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto 44px;
  gap: 8px;
  align-items: center;
  padding: calc(8px + var(--safe-t)) 12px 8px;
  background: linear-gradient(180deg, rgba(10, 8, 22, 0.92), rgba(10, 8, 22, 0));
  z-index: 2;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
  font-size: 1.05rem;
}

.hud-mid { min-width: 0; }

.score-line {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-weight: 800;
}

.score-line span, .sub-line { color: var(--muted); font-size: 0.78rem; }

#hud-score {
  display: inline-block;
  font-size: 1.45rem;
  line-height: 1;
  color: white;
  font-variant-numeric: tabular-nums;
}

#hud-score.hot, #hud-best.hot { color: var(--gold); }

#hud-score.pop { animation: pop 0.28s ease; }

.sub-line {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 2px;
  font-weight: 700;
}

.sub-line b { color: white; font-variant-numeric: tabular-nums; }

.time-badge {
  min-width: 68px;
  text-align: center;
  padding: 8px 8px;
  border-radius: 14px;
  font-weight: 900;
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
}

.time-badge.warn {
  color: white;
  background: #ff2d55;
  border-color: transparent;
  animation: pulse 0.55s ease-in-out infinite;
}

@keyframes pop { 40% { transform: scale(1.2); } }
@keyframes pulse { 50% { transform: scale(1.06); } }

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  touch-action: none;
}

canvas { width: 100%; height: 100%; display: block; }

.stage-top {
  position: absolute;
  top: 8px;
  left: 12px;
  right: 12px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  z-index: 2;
}

.lives { display: flex; gap: 3px; font-size: 1.15rem; min-width: 64px; }
.lives .on { color: #ff4d6d; }
.lives .off { color: #ff4d6d; opacity: 0.28; filter: grayscale(1); }

.ring-count {
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.38);
  font-weight: 800;
  font-size: 0.82rem;
}

.combo {
  justify-self: end;
  padding: 5px 10px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffe08a, #ff8a3d);
  color: #3d2400;
  font-weight: 900;
  font-size: 0.85rem;
}

.hint {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  text-align: center;
  top: 52px;
  width: max-content;
  max-width: 92%;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.42);
  font-weight: 800;
  font-size: 0.88rem;
  z-index: 2;
}

.keys-help { display: none; }

.count-pop {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  font-weight: 900;
  letter-spacing: -0.04em;
  color: white;
  text-shadow: 0 10px 0 rgba(0, 0, 0, 0.12), 0 18px 40px rgba(0, 0, 0, 0.4);
}

.count-pop.go { animation: countIn 0.55s ease; }

@keyframes countIn {
  0% { transform: scale(0.6); opacity: 0; }
  35% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.drop-btn {
  position: absolute;
  left: 50%;
  bottom: calc(14px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 3;
  width: min(46vw, 210px);
  height: 64px;
  border-radius: 999px;
  color: white;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1;
  background: linear-gradient(180deg, #ff97be, #ff3b7c 60%, #e01566);
  box-shadow: 0 12px 28px rgba(255, 59, 124, 0.42), inset 0 2px 0 rgba(255, 255, 255, 0.4);
  animation: cta 1.6s ease-in-out infinite;
}

.drop-kn { font-size: 1.35rem; font-weight: 900; }
.drop-en { margin-top: 3px; font-size: 0.68rem; letter-spacing: 0.12em; opacity: 0.85; font-weight: 800; }

.drop-btn.pressed {
  animation: none;
  transform: translateX(-50%) scale(0.96);
  filter: brightness(1.06);
}

.drop-btn:disabled {
  animation: none;
  opacity: 0.42;
  filter: grayscale(0.35);
}

@keyframes cta {
  50% { transform: translateX(-50%) scale(1.04); }
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(6, 5, 16, 0.62);
  backdrop-filter: blur(8px);
}

.pause-card {
  width: min(340px, 100%);
  padding: 22px 16px 16px;
  border-radius: 24px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: rgba(18, 12, 36, 0.94);
  border: 1px solid var(--line);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
}

.pause-score { margin: 0; color: var(--muted); font-weight: 800; }
.pause-score strong { color: white; font-size: 1.4rem; }

.score-hero span {
  color: var(--muted);
  font-weight: 800;
  font-size: 0.85rem;
}

.score-hero strong {
  display: block;
  font-size: clamp(3rem, 14vw, 4.6rem);
  line-height: 0.95;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(180deg, #fff 20%, #ffd166);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.record {
  align-self: center;
  padding: 6px 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, #ffd166, #ff8a3d);
  color: #3d2400;
  font-weight: 900;
  animation: pop 0.6s ease;
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stats div {
  padding: 10px 6px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
}

.stats b {
  display: block;
  font-size: 1.3rem;
  font-variant-numeric: tabular-nums;
}

.stats span { color: var(--muted); font-size: 0.78rem; font-weight: 700; }

.mini-stack {
  position: relative;
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  gap: 3px;
  min-height: 40px;
  margin: 2px auto;
  padding: 8px 0 12px;
  width: 140px;
}

.mini-pole {
  position: absolute;
  left: 50%;
  top: 2px;
  bottom: 4px;
  width: 8px;
  transform: translateX(-50%);
  border-radius: 8px;
  background: linear-gradient(90deg, #7a4a22, #fff6e4 50%, #5e3816);
}

.mini-ring {
  width: 118px;
  display: flex;
  justify-content: space-between;
  z-index: 1;
}

.mini-ring i {
  width: 50px;
  height: 11px;
  border-radius: 999px;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.5);
}

.mini-ring.perfect i {
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.65), 0 0 0 1px rgba(255, 255, 255, 0.45);
}

.confetti { position: fixed; inset: 0; z-index: 4; pointer-events: none; overflow: hidden; }

.confetti i {
  position: absolute;
  top: -16px;
  width: 8px;
  height: 14px;
  border-radius: 2px;
  animation-name: confettiFall;
  animation-timing-function: linear;
  animation-fill-mode: forwards;
}

@keyframes confettiFall {
  to { transform: translateY(105vh) rotate(420deg); opacity: 0.15; }
}

@media (hover: hover) and (pointer: fine) {
  .keys-help { display: flex; }
}

@media (max-width: 380px) {
  .hud {
    grid-template-columns: 40px minmax(0, 1fr) auto 40px;
    gap: 6px;
    padding-left: 8px;
    padding-right: 8px;
  }
  .icon-btn { width: 40px; height: 40px; }
  #hud-score { font-size: 1.15rem; }
  .time-badge { min-width: 56px; font-size: 0.95rem; padding: 6px 4px; }
  .sub-line { font-size: 0.7rem; }
}

@media (max-height: 520px) {
  .hud { padding-top: calc(4px + var(--safe-t)); }
  .icon-btn { width: 38px; height: 38px; }
  .time-badge { padding: 4px 6px; font-size: 1rem; min-width: 58px; }
  .drop-btn { height: 48px; width: min(40vw, 160px); }
  .drop-kn { font-size: 1.05rem; }
  .logo { height: 120px; transform: scale(0.86); transform-origin: top center; }
}

@media (min-width: 800px) {
  .menu-card { padding: 26px 22px 18px; }
}

@media (prefers-reduced-motion: reduce) {
  .blob, .logo-ring, .drop-btn, .time-badge.warn, .count-pop.go, #hud-score.pop, .record {
    animation: none;
  }
}
