* {
  box-sizing: border-box;
}

:root {
  --bg: #0b0d14;
  --surface: #141826;
  --surface-2: #1b2032;
  --line: rgba(255, 255, 255, 0.08);
  --text: #e8eaf0;
  --muted: #8f95ab;
  --accent: #c8ff00;
  --accent-2: #25e8ff;
  --danger: #ff4d6d;
  --cell: clamp(15px, min(8.4vw, 4.1vh), 30px);
  --radius: 16px;
  font-size: 16px;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'SN Pro', system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: radial-gradient(1100px 700px at 50% -10%, #1a2036 0%, var(--bg) 60%);
  -webkit-tap-highlight-color: transparent;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 12px clamp(10px, 2vw, 24px) 20px;
  gap: 14px;
}

/* ---------- шапка ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
}

.logo {
  font-family: 'JetBrains Mono', Menlo, monospace;
  font-weight: 700;
  font-size: clamp(1.1rem, 3.6vw, 1.5rem);
  letter-spacing: 0.12em;
  color: var(--text);
  text-shadow: 0 0 18px rgba(200, 255, 0, 0.35);
  user-select: none;
}

.logo__dot {
  color: var(--accent);
}

.logo__sub {
  color: var(--accent-2);
  font-size: 0.7em;
  letter-spacing: 0.2em;
  margin-left: 2px;
}

.topbar__actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}

.icon-btn:hover {
  background: var(--surface-2);
  border-color: rgba(200, 255, 0, 0.4);
}

.icon-btn:active {
  transform: scale(0.94);
}

.icon-btn[disabled] {
  opacity: 0.4;
  cursor: default;
}

/* ---------- раскладка игры ---------- */
.game {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(150px, 190px) auto minmax(150px, 200px);
  grid-template-areas: 'left stage right';
  justify-content: center;
  align-items: start;
  gap: clamp(10px, 2vw, 20px);
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
}

.panel--left {
  grid-area: left;
}

.panel--right {
  grid-area: right;
}

.stage {
  grid-area: stage;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  background: linear-gradient(180deg, var(--surface) 0%, #111524 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.card__title {
  font-family: 'JetBrains Mono', Menlo, monospace;
  font-size: 0.68rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
  text-align: center;
}

.mini {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.35);
}

.mini--next {
  min-height: 220px;
}

/* ---------- статистика ---------- */
.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stat {
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat__label {
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat__value {
  font-family: 'JetBrains Mono', Menlo, monospace;
  font-weight: 700;
  font-size: clamp(1rem, 2.4vw, 1.3rem);
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.stat__value--accent {
  color: var(--accent);
  text-shadow: 0 0 12px rgba(200, 255, 0, 0.45);
}

.combo {
  grid-column: 1 / -1;
  text-align: center;
  font-family: 'JetBrains Mono', Menlo, monospace;
  font-weight: 700;
  font-size: 0.8rem;
  letter-spacing: 0.16em;
  color: #0b0d14;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 10px;
  padding: 6px 8px;
  animation: pulse 0.6s ease-in-out infinite alternate;
}

.combo[hidden] {
  display: none;
}

@keyframes pulse {
  from {
    transform: scale(1);
  }
  to {
    transform: scale(1.04);
  }
}

/* ---------- клавиши ---------- */
.keys {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.keys li {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: space-between;
}

.keys__btns {
  display: flex;
  gap: 4px;
}

.keys__label {
  font-size: 0.72rem;
  color: var(--muted);
}

kbd {
  font-family: 'JetBrains Mono', Menlo, monospace;
  font-size: 0.68rem;
  min-width: 24px;
  padding: 3px 6px;
  text-align: center;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-bottom-width: 3px;
  border-radius: 7px;
}

/* ---------- поле ---------- */
.board-frame {
  position: relative;
  width: calc(var(--cell) * 10);
  height: calc(var(--cell) * 20);
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid rgba(37, 232, 255, 0.35);
  box-shadow:
    0 0 0 4px rgba(20, 24, 38, 0.9),
    0 0 34px rgba(37, 232, 255, 0.18),
    0 22px 50px rgba(0, 0, 0, 0.55);
  background: #0c0e15;
  touch-action: manipulation;
}

.board {
  display: block;
  width: 100%;
  height: 100%;
}

/* ---------- всплывающая надпись ---------- */
.banner {
  position: absolute;
  top: 16%;
  left: 0;
  right: 0;
  text-align: center;
  font-family: 'JetBrains Mono', Menlo, monospace;
  font-weight: 700;
  font-size: clamp(1.1rem, 5vw, 1.7rem);
  letter-spacing: 0.14em;
  color: var(--accent);
  text-shadow:
    0 0 12px rgba(200, 255, 0, 0.8),
    0 4px 14px rgba(0, 0, 0, 0.7);
  opacity: 0;
  transform: scale(0.7);
  pointer-events: none;
}

.banner.show {
  animation: bannerPop 1s ease forwards;
}

@keyframes bannerPop {
  0% {
    opacity: 0;
    transform: scale(0.6);
  }
  25% {
    opacity: 1;
    transform: scale(1.12);
  }
  70% {
    opacity: 1;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(1.05);
  }
}

/* ---------- оверлей ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: rgba(8, 10, 18, 0.86);
  backdrop-filter: blur(4px);
  z-index: 3;
}

.overlay[hidden] {
  display: none;
}

.overlay__panel {
  width: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.overlay__title {
  font-family: 'JetBrains Mono', Menlo, monospace;
  font-weight: 700;
  font-size: clamp(1.3rem, 7vw, 1.9rem);
  letter-spacing: 0.16em;
  color: var(--accent);
  text-shadow: 0 0 22px rgba(200, 255, 0, 0.6);
}

.overlay__title--over {
  color: var(--danger);
  text-shadow: 0 0 22px rgba(255, 77, 109, 0.6);
}

.overlay__text {
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--muted);
  max-width: 240px;
}

.overlay__stats {
  display: flex;
  gap: 10px;
  justify-content: center;
  width: 100%;
}

.overlay__stats[hidden] {
  display: none;
}

.overlay__stat {
  flex: 1;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.overlay__stat span {
  font-size: 0.6rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.overlay__stat b {
  font-family: 'JetBrains Mono', Menlo, monospace;
  font-size: 1.05rem;
  color: var(--accent);
}

.btn {
  margin-top: 4px;
  padding: 12px 26px;
  border: none;
  border-radius: 999px;
  font-family: 'JetBrains Mono', Menlo, monospace;
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  color: #0b0d14;
  background: linear-gradient(90deg, var(--accent), #8fff4d);
  box-shadow: 0 0 24px rgba(200, 255, 0, 0.45);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 34px rgba(200, 255, 0, 0.65);
}

.btn:active {
  transform: scale(0.96);
}

/* ---------- сенсорное управление ---------- */
.touch {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
  width: calc(var(--cell) * 10);
}

.tbtn {
  height: 48px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  color: var(--text);
  font-size: 1.15rem;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  transition: transform 0.08s ease, border-color 0.12s ease, background 0.12s ease;
}

.tbtn--accent {
  color: #0b0d14;
  background: linear-gradient(180deg, var(--accent), #9fe000);
  border-color: transparent;
  font-weight: 700;
}

.tbtn:hover {
  border-color: rgba(37, 232, 255, 0.5);
}

.tbtn:active,
.tbtn.is-pressed {
  transform: scale(0.93);
  background: #232a42;
}

.tbtn--accent:active,
.tbtn--accent.is-pressed {
  background: var(--accent);
}

/* ---------- адаптив ---------- */
@media (max-width: 760px) {
  .game {
    grid-template-columns: 1fr;
    grid-template-areas:
      'right'
      'stage'
      'left';
  }

  .panel {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .panel > .card {
    flex: 1 1 150px;
  }

  .card--keys {
    display: none;
  }

  .mini--next {
    min-height: 120px;
  }

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

  .tbtn {
    height: 52px;
  }
}

@media (max-width: 400px) {
  .stats {
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
  }

  .stat {
    padding: 6px;
    align-items: center;
    text-align: center;
  }
}

/* ---------- фон с плавающими фигурами ---------- */
.floaters {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

.floaters span {
  position: absolute;
  bottom: -14vh;
  font-family: 'JetBrains Mono', Menlo, monospace;
  font-weight: 700;
  opacity: 0;
  animation: floatUp linear infinite;
  filter: blur(0.4px);
}

@keyframes floatUp {
  0% {
    transform: translateY(0) rotate(0deg);
    opacity: 0;
  }
  12% {
    opacity: 0.1;
  }
  85% {
    opacity: 0.08;
  }
  100% {
    transform: translateY(-125vh) rotate(320deg);
    opacity: 0;
  }
}

/* живое свечение под полем */
@keyframes frameBreathe {
  0%,
  100% {
    box-shadow:
      0 0 0 4px rgba(20, 24, 38, 0.9),
      0 0 30px rgba(37, 232, 255, 0.16),
      0 22px 50px rgba(0, 0, 0, 0.55);
  }
  50% {
    box-shadow:
      0 0 0 4px rgba(20, 24, 38, 0.9),
      0 0 48px rgba(37, 232, 255, 0.34),
      0 22px 50px rgba(0, 0, 0, 0.55);
  }
}

/* прыжок числа в статистике */
@keyframes statPop {
  0% {
    transform: scale(1);
  }
  35% {
    transform: scale(1.22);
    color: var(--accent);
    text-shadow: 0 0 14px rgba(200, 255, 0, 0.65);
  }
  100% {
    transform: scale(1);
  }
}

.stat__value.pop {
  animation: statPop 0.32s ease;
}

/* пульс логотипа */
@keyframes logoPulse {
  0%,
  100% {
    text-shadow: 0 0 14px rgba(200, 255, 0, 0.3);
  }
  50% {
    text-shadow:
      0 0 22px rgba(200, 255, 0, 0.65),
      0 0 44px rgba(37, 232, 255, 0.35);
  }
}

.logo {
  animation: logoPulse 3.2s ease-in-out infinite;
}

/* панели въезжают при загрузке */
.card {
  animation: panelIn 0.45s ease backwards;
}

.panel--left .card:nth-child(1) {
  animation-delay: 0.06s;
}
.panel--left .card:nth-child(2) {
  animation-delay: 0.14s;
}
.panel--right .card:nth-child(1) {
  animation-delay: 0.1s;
}
.panel--right .card:nth-child(2) {
  animation-delay: 0.18s;
}
.panel--right .card:nth-child(3) {
  animation-delay: 0.24s;
}

@keyframes panelIn {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.board-frame {
  animation:
    frameBreathe 4.5s ease-in-out infinite,
    panelIn 0.5s ease backwards;
}

.overlay__panel {
  animation: overlayIn 0.35s cubic-bezier(0.2, 1.4, 0.4, 1);
}

@keyframes overlayIn {
  from {
    opacity: 0;
    transform: scale(0.86) translateY(10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* луч света по кнопке */
.btn {
  position: relative;
  overflow: hidden;
}

.btn::after {
  content: '';
  position: absolute;
  top: 0;
  left: -60%;
  width: 45%;
  height: 100%;
  background: linear-gradient(105deg, transparent, rgba(255, 255, 255, 0.65), transparent);
  transform: skewX(-20deg);
  animation: shine 3.4s ease-in-out infinite;
}

@keyframes shine {
  0%,
  62% {
    left: -60%;
  }
  88%,
  100% {
    left: 130%;
  }
}

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

/* ---------- выбор сложности ---------- */
.diff {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  animation: fadeUp 0.35s ease;
}

.diff[hidden] {
  display: none;
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.diff__label {
  font-family: 'JetBrains Mono', Menlo, monospace;
  font-size: 0.6rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
}

.diff__opts {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.diff__btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 7px 2px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.35);
  color: var(--muted);
  font-family: 'SN Pro', system-ui, sans-serif;
  font-size: clamp(0.6rem, 2.6vw, 0.78rem);
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.diff__btn span {
  font-family: 'JetBrains Mono', Menlo, monospace;
  font-size: 0.62em;
  font-weight: 400;
  opacity: 0.75;
}

.diff__btn:hover {
  border-color: rgba(37, 232, 255, 0.5);
  color: var(--text);
}

.diff__btn:active {
  transform: scale(0.94);
}

.diff__btn.is-active {
  color: #0b0d14;
  background: linear-gradient(180deg, var(--accent), #9fe000);
  border-color: transparent;
  box-shadow: 0 0 16px rgba(200, 255, 0, 0.45);
}

.stat--wide {
  grid-column: 1 / -1;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}

/* компактный переключатель в HUD — работает во время игры */
.diff__opts--hud {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.diff__opts--hud .diff__btn {
  padding: 6px 2px;
  font-size: clamp(0.58rem, 1.8vw, 0.74rem);
}

.diff__opts--hud .diff__btn.is-active {
  animation: diffPop 0.25s ease;
}

@keyframes diffPop {
  0% {
    transform: scale(0.9);
  }
  60% {
    transform: scale(1.06);
  }
  100% {
    transform: scale(1);
  }
}

.stat__value--small {
  font-size: clamp(0.8rem, 1.9vw, 1.05rem);
  color: var(--accent-2);
  text-shadow: 0 0 10px rgba(37, 232, 255, 0.4);
}
