:root {
  --black: #08080c;
  --paper: #0e0e14;
  --ink: #f2f2f7;
  --muted: #8b8ba3;
  --blue: #3ec8ff;
  --violet: #8b5cff;
  --grad: linear-gradient(90deg, #3ec8ff 0%, #6a7dff 50%, #a35cff 100%);
  --grad-loop: linear-gradient(90deg, #3ec8ff 0%, #8b5cff 25%, #a35cff 50%, #8b5cff 75%, #3ec8ff 100%);
  --red: #ff4d6a;
  --yellow: #ffd23f;
  --pixel: 'Press Start 2P', monospace;
  --text: 'Rubik', system-ui, sans-serif;
  --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(--black); color: var(--ink);
  font-family: var(--text); overflow: hidden; overscroll-behavior: none;
  user-select: none; -webkit-user-select: none; touch-action: none;
}

#app {
  position: relative; margin: 0 auto; height: 100%; width: 100%; max-width: 480px;
  overflow: hidden; background: var(--paper);
  box-shadow: 0 0 0 1px #1c1c28, 0 0 80px rgba(110, 90, 255, .15);
}
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; image-rendering: auto; }
.hidden { display: none !important; }

/* ---------- кнопки ---------- */
.btn {
  display: block; width: 100%; border: 0; cursor: pointer; text-align: center; text-decoration: none;
  font-family: var(--pixel); font-size: 14px; letter-spacing: 1px; padding: 18px 12px;
  color: var(--black); background: var(--grad);
  clip-path: polygon(0 6px, 6px 6px, 6px 0, calc(100% - 6px) 0, calc(100% - 6px) 6px, 100% 6px,
    100% calc(100% - 6px), calc(100% - 6px) calc(100% - 6px), calc(100% - 6px) 100%, 6px 100%, 6px calc(100% - 6px), 0 calc(100% - 6px));
  transition: transform .08s, filter .2s;
}
.btn:active { transform: translateY(3px) scale(.98); }
.btn-primary { background: var(--grad-loop); background-size: 200% 100%; animation: shine 3s linear infinite; }
.btn-ghost {
  background: transparent; color: var(--ink); font-size: 11px; padding: 14px 10px;
  box-shadow: inset 0 0 0 2px #2a2a3c; clip-path: none;
}
.btn-ghost:active { box-shadow: inset 0 0 0 2px var(--violet); }
.btn-icon { width: 56px; flex: none; font-family: var(--text); font-size: 18px; padding: 10px; }
.btn-icon.off { color: var(--muted); text-decoration: line-through; }
.btn-link { background: none; border: 0; color: var(--muted); font-family: var(--text); font-size: 13px; padding: 10px; cursor: pointer; }
.row { display: flex; gap: 10px; width: 100%; }
@keyframes shine { 0% { background-position: 0 0; } 100% { background-position: 200% 0; } }

/* ---------- экраны ---------- */
.screen {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center;
  padding: 24px 24px calc(24px + var(--safe-b));
}

/* меню */
#menu { justify-content: space-between; }
.menu-top { margin-top: 9vh; text-align: center; }
.logo { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.logo-line {
  font-family: var(--pixel); font-size: 42px; line-height: 1; letter-spacing: 2px;
  background: var(--grad-loop); background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(4px 4px 0 #000) drop-shadow(0 0 18px rgba(110, 120, 255, .35));
  animation: shine 4s linear infinite, bob 2.4s ease-in-out infinite;
}
.logo-line.l2 { font-size: 56px; animation-delay: 0s, .3s; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
.tagline { margin-top: 18px; font-size: 13px; color: var(--muted); letter-spacing: 3px; text-transform: uppercase; }

.menu-bottom { width: 100%; display: flex; flex-direction: column; gap: 12px; align-items: center; animation: rise .6s cubic-bezier(.2, 1.4, .4, 1) both; }
@keyframes rise { from { opacity: 0; transform: translateY(30px); } }
.record-chip {
  font-family: var(--pixel); font-size: 9px; line-height: 1.6; padding: 8px 12px; color: var(--ink);
  background: rgba(139, 92, 255, .14); box-shadow: inset 0 0 0 1px rgba(139, 92, 255, .5); text-align: center;
}
.nick { width: 100%; display: flex; align-items: center; gap: 10px; background: rgba(255, 255, 255, .04); box-shadow: inset 0 0 0 2px #2a2a3c; padding: 0 14px; }
.nick span { font-family: var(--pixel); font-size: 9px; color: var(--muted); }
.nick input {
  flex: 1; min-width: 0; background: none; border: 0; outline: none; color: var(--ink);
  font-family: var(--text); font-size: 16px; padding: 14px 0; user-select: text; -webkit-user-select: text;
}
.best-line { font-size: 12px; color: var(--muted); }
.best-line b { color: var(--ink); font-family: var(--pixel); font-size: 10px; }

/* панели */
.panel {
  margin: auto 0; width: 100%; display: flex; flex-direction: column; gap: 12px; align-items: center;
  padding: 24px 20px; background: rgba(8, 8, 12, .92); box-shadow: inset 0 0 0 2px #23233a, 8px 8px 0 rgba(0, 0, 0, .6);
  animation: pop .35s cubic-bezier(.2, 1.5, .4, 1) both; max-height: 100%;
}
.panel.small { max-width: 320px; }
@keyframes pop { from { opacity: 0; transform: scale(.85); } }
.panel-title {
  font-family: var(--pixel); font-size: 16px; text-align: center; line-height: 1.4;
  background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent;
}
#pause, #over, #board { background: rgba(8, 8, 12, .55); backdrop-filter: blur(3px); }

/* рекорды */
.board-sub { font-size: 12px; color: var(--muted); }
.board-list { list-style: none; margin: 0; padding: 0; width: 100%; overflow-y: auto; flex: 1 1 auto; min-height: 120px; max-height: 52vh; }
.board-list li { display: flex; align-items: center; gap: 10px; padding: 10px 8px; border-bottom: 1px solid #1b1b28; font-size: 14px; }
.board-list li .r { font-family: var(--pixel); font-size: 10px; width: 34px; color: var(--muted); }
.board-list li .n { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-list li .s { font-family: var(--pixel); font-size: 10px; }
.board-list li.top1 .r, .board-list li.top1 .s { color: var(--yellow); }
.board-list li.top2 .r { color: #cfd6e6; }
.board-list li.top3 .r { color: #e39b5b; }
.board-list li.me { background: rgba(62, 200, 255, .1); box-shadow: inset 3px 0 0 var(--blue); }
.board-list .empty { justify-content: center; color: var(--muted); border: 0; padding: 30px 0; }
.board-me { font-size: 12px; color: var(--muted); }

/* конец игры */
.over-score {
  font-family: var(--pixel); font-size: 44px; line-height: 1.2;
  background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.over-badge { font-family: var(--pixel); font-size: 9px; color: var(--black); background: var(--yellow); padding: 6px 8px; animation: blink .8s steps(2) infinite; }
@keyframes blink { 50% { opacity: .55; } }
.over-stats { display: flex; width: 100%; gap: 8px; }
.over-stats div { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 4px; background: rgba(255, 255, 255, .03); box-shadow: inset 0 0 0 1px #23233a; }
.over-stats span { font-size: 11px; color: var(--muted); }
.over-stats b { font-family: var(--pixel); font-size: 11px; }
.over-hint { font-size: 13px; color: var(--muted); text-align: center; min-height: 1em; }
.over-hint b { color: var(--blue); }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0 0 auto 0; pointer-events: none; padding: 14px 16px; display: flex; align-items: flex-start; gap: 10px; }
.hud-score { font-family: var(--pixel); font-size: 22px; text-shadow: 3px 3px 0 #000; }
.hud-target { flex: 1; font-size: 11px; color: var(--muted); padding-top: 4px; line-height: 1.4; }
.hud-target b { color: var(--yellow); font-family: var(--pixel); font-size: 9px; }
.hud-pause {
  pointer-events: auto; width: 40px; height: 40px; border: 0; cursor: pointer;
  font-family: var(--pixel); font-size: 12px; color: var(--ink); background: rgba(255, 255, 255, .06); box-shadow: inset 0 0 0 2px #2a2a3c;
}

.hud-sound { font-family: var(--text); font-size: 18px; }
.hud-sound.off, .btn-ghost.off { color: var(--muted); }
.hud-sound.off::after { content: ''; position: absolute; left: 8px; right: 8px; top: 50%; height: 2px; background: var(--red); transform: rotate(-35deg); }
.hud-sound { position: relative; }

/* ---------- кнопки управления ---------- */
#controls {
  position: absolute; left: 0; right: 0; bottom: 0; display: flex; gap: 10px;
  padding: 10px 12px calc(12px + var(--safe-b));
  background: linear-gradient(to top, rgba(8, 8, 12, .9), rgba(8, 8, 12, 0));
}
.ctl {
  flex: 1; height: 72px; border: 0; cursor: pointer; color: var(--ink); font-size: 26px;
  background: rgba(255, 255, 255, .05); box-shadow: inset 0 0 0 2px #2a2a3c;
  touch-action: none; transition: transform .06s;
}
.ctl span { pointer-events: none; }
.ctl-fire { flex: .8; color: var(--black); background: var(--grad); box-shadow: none; font-size: 22px; }
.ctl.down { transform: scale(.94); box-shadow: inset 0 0 0 2px var(--blue); background: rgba(62, 200, 255, .15); }
.ctl-fire.down { background: var(--grad); filter: brightness(1.25); }

/* ---------- праздник ---------- */
#celebrate { position: absolute; inset: 0; z-index: 20; background: rgba(5, 5, 10, .78); display: flex; align-items: center; justify-content: center; overflow: hidden; animation: fade .3s both; }
@keyframes fade { from { opacity: 0; } }
#confetti { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.garland { position: absolute; left: 0; right: 0; top: 0; height: 140px; pointer-events: none; }
.garland svg { position: absolute; left: 0; top: 0; width: 100%; overflow: visible; }
.garland .wire { fill: none; stroke: #7a7aa8; stroke-width: 2; stroke-dasharray: 2000; stroke-dashoffset: 2000; animation: draw .9s ease-out forwards; }
.garland .bulb { opacity: 0; transform-box: fill-box; transform-origin: 50% 0; animation: drop .5s cubic-bezier(.2, 1.6, .4, 1) forwards, glow 1s steps(2) infinite; }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes drop { from { opacity: 0; transform: translateY(-30px) rotate(-30deg); } to { opacity: 1; transform: none; } }
@keyframes glow { 50% { filter: brightness(.45); } }

.sticker {
  position: relative; width: min(84%, 340px); padding: 30px 22px 16px; display: flex; flex-direction: column; align-items: center; gap: 12px;
  background: #fbfbff; color: var(--black); text-align: center;
  box-shadow: 0 0 0 4px var(--black), 0 0 0 8px #fff, 10px 14px 0 8px rgba(0, 0, 0, .5), 0 0 60px 10px rgba(110, 120, 255, .45);
  animation: sticker .8s .5s cubic-bezier(.2, 1.5, .4, 1) both;
}
@keyframes sticker { from { opacity: 0; transform: translateY(120%) rotate(18deg) scale(.6); } to { transform: rotate(-3deg); } }
.sticker-star {
  position: absolute; top: -34px; width: 64px; height: 64px; display: grid; place-items: center; font-size: 34px; color: var(--black);
  background: var(--grad); border-radius: 50%; box-shadow: 0 0 0 4px var(--black); animation: spin 4s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.sticker-title { font-family: var(--pixel); font-size: 18px; margin-top: 10px; }
.sticker-text { font-size: 15px; line-height: 1.5; }
.sticker-text b { font-family: var(--pixel); font-size: 22px; display: inline-block; margin-top: 6px; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.sticker .btn { font-size: 12px; }
.sticker .btn-link { color: #77778a; }

@media (max-height: 640px) {
  .menu-top { margin-top: 4vh; }
  .logo-line { font-size: 34px; } .logo-line.l2 { font-size: 44px; }
  .ctl { height: 60px; }
}
