:root {
  --bg: #050711;
  --surface: rgba(12, 18, 37, 0.84);
  --surface-strong: #0e162d;
  --surface-soft: rgba(23, 32, 60, 0.58);
  --line: rgba(143, 187, 255, 0.16);
  --line-strong: rgba(143, 187, 255, 0.32);
  --text: #f4f8ff;
  --muted: #95a4c4;
  --cyan: #39f7e5;
  --cyan-strong: #00d9ff;
  --violet: #a770ff;
  --pink: #ff4fd8;
  --danger: #ff4d7d;
  --success: #6dffb3;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.46);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --focus-ring: 0 0 0 3px rgba(57, 247, 229, 0.38);
  --transition: 180ms ease;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  min-height: 100svh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 18% 14%, rgba(0, 217, 255, 0.12), transparent 30rem),
    radial-gradient(circle at 84% 86%, rgba(167, 112, 255, 0.14), transparent 34rem),
    linear-gradient(145deg, #050711 0%, #080d1d 48%, #070a17 100%);
}

button,
input {
  font: inherit;
}

button {
  border: 0;
}

[hidden] {
  display: none !important;
}

::selection {
  color: #061216;
  background: var(--cyan);
}

.ambient {
  position: fixed;
  z-index: -1;
  width: 26rem;
  height: 26rem;
  border-radius: 50%;
  filter: blur(96px);
  opacity: 0.15;
  pointer-events: none;
}

.ambient--one {
  top: -8rem;
  right: -8rem;
  background: var(--cyan-strong);
}

.ambient--two {
  bottom: -10rem;
  left: -8rem;
  background: var(--violet);
}

.app-shell {
  width: min(1120px, calc(100% - 32px));
  min-height: 100vh;
  min-height: 100svh;
  margin: 0 auto;
  padding: clamp(32px, 6vw, 72px) 0;
  display: grid;
  place-items: center;
}

.screen {
  width: 100%;
}

.menu-screen {
  position: relative;
  padding-top: clamp(74px, 8vw, 96px);
  animation: screen-enter 500ms ease both;
}

.menu-logo {
  position: absolute;
  top: 0;
  left: 0;
  width: clamp(138px, 18vw, 220px);
  height: clamp(52px, 7vw, 80px);
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

.menu-logo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: left center;
  filter: drop-shadow(0 0 18px rgba(57, 247, 229, 0.16));
}

.brand-block {
  max-width: 780px;
  margin: 0 auto clamp(28px, 5vw, 52px);
  text-align: center;
}

.eyebrow,
.panel-kicker {
  margin: 0;
  color: var(--cyan);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.game-title {
  margin: 10px 0 12px;
  font-size: clamp(3rem, 9vw, 6.8rem);
  line-height: 0.92;
  letter-spacing: -0.065em;
  text-wrap: balance;
  background: linear-gradient(120deg, #ffffff 8%, var(--cyan) 43%, #76a7ff 72%, var(--violet));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 28px rgba(57, 247, 229, 0.2));
}

.subtitle {
  max-width: 650px;
  margin: 0 auto;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.13rem);
  line-height: 1.65;
}

.menu-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(300px, 0.9fr);
  gap: 22px;
  align-items: stretch;
}

.panel {
  padding: clamp(22px, 4vw, 34px);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.035), transparent 44%),
    var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.panel-heading {
  margin-bottom: 24px;
}

.panel-heading--row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.panel-heading h2,
.overlay-card h2 {
  margin: 7px 0 0;
  font-size: clamp(1.55rem, 4vw, 2.35rem);
  letter-spacing: -0.035em;
}

.field-group {
  display: grid;
  gap: 8px;
}

.field-group label {
  font-size: 0.92rem;
  font-weight: 750;
}

.field-group input {
  width: 100%;
  height: 52px;
  padding: 0 16px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  outline: 0;
  color: var(--text);
  background: rgba(5, 10, 24, 0.74);
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

.field-group input::placeholder {
  color: #657492;
}

.field-group input:hover {
  border-color: rgba(57, 247, 229, 0.42);
}

.field-group input:focus-visible {
  border-color: var(--cyan);
  box-shadow: var(--focus-ring);
  background: rgba(7, 15, 31, 0.96);
}

.field-group input[aria-invalid="true"] {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(255, 77, 125, 0.2);
}

.field-hint,
.field-error {
  min-height: 1.1em;
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.45;
}

.field-hint {
  color: var(--muted);
}

.field-error {
  color: #ff91ae;
}

.button {
  min-height: 52px;
  padding: 0 20px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-weight: 800;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition), background var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.button:hover:not(:disabled) {
  transform: translateY(-2px);
}

.button:active:not(:disabled) {
  transform: translateY(0) scale(0.98);
}

.button:focus-visible,
.touch-button:focus-visible,
#game-canvas:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.button--primary {
  color: #041315;
  background: linear-gradient(115deg, var(--cyan), #78ffd7 46%, #7fe7ff);
  box-shadow: 0 10px 34px rgba(57, 247, 229, 0.22);
}

.button--primary:hover:not(:disabled) {
  box-shadow: 0 14px 42px rgba(57, 247, 229, 0.34);
}

.button--secondary {
  color: var(--text);
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, 0.045);
}

.button--secondary:hover:not(:disabled) {
  border-color: rgba(57, 247, 229, 0.48);
  background: rgba(57, 247, 229, 0.08);
}

.start-panel > .button {
  width: 100%;
  margin-top: 20px;
}

.controls-card {
  margin-top: 24px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--muted);
  background: var(--surface-soft);
}

.controls-card strong {
  color: var(--text);
}

.controls-card p {
  margin: 4px 0 0;
  font-size: 0.86rem;
  line-height: 1.45;
}

.key-cluster {
  flex: 0 0 auto;
  display: grid;
  justify-items: center;
  gap: 4px;
}

.key-cluster div {
  display: flex;
  gap: 4px;
}

kbd {
  min-width: 26px;
  height: 25px;
  padding: 0 6px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-bottom-color: rgba(255, 255, 255, 0.08);
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #dffeff;
  background: rgba(255, 255, 255, 0.07);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.22);
  font: 700 0.76rem/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 18px var(--cyan);
}

.leaderboard-list {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: rank;
  display: grid;
  gap: 10px;
}

.leaderboard-entry {
  min-height: 56px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 13px;
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.035);
}

.leaderboard-entry:first-child {
  border-color: rgba(57, 247, 229, 0.26);
  background: linear-gradient(90deg, rgba(57, 247, 229, 0.11), rgba(255, 255, 255, 0.035));
}

.leaderboard-rank {
  color: var(--cyan);
  font: 800 0.82rem/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.leaderboard-name {
  overflow: hidden;
  color: var(--text);
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-score {
  color: #dcfbff;
  font: 800 0.95rem/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.empty-state {
  margin: 0;
  padding: 30px 16px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-md);
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
}

.game-screen {
  max-width: 820px;
  animation: screen-enter 420ms ease both;
}

.game-hud {
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.hud-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 900;
  letter-spacing: 0.07em;
}

.hud-brand__mark {
  width: 12px;
  height: 12px;
  border-radius: 4px;
  background: var(--cyan);
  box-shadow: 0 0 20px rgba(57, 247, 229, 0.7);
  transform: rotate(45deg);
}

.hud-stats {
  display: flex;
  gap: 10px;
}

.stat-card {
  min-width: 112px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  display: grid;
  gap: 3px;
  text-align: right;
  background: rgba(10, 16, 34, 0.82);
  backdrop-filter: blur(12px);
}

.stat-card strong {
  font: 900 1.25rem/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.stat-label {
  color: var(--muted);
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.stat-card.is-pulsing {
  animation: score-pulse 300ms ease;
}

.game-stage {
  position: relative;
  overflow: hidden;
  width: min(100%, 76vh);
  width: min(100%, 76svh);
  margin: 0 auto;
  border: 1px solid rgba(95, 240, 235, 0.27);
  border-radius: clamp(16px, 3vw, 26px);
  background: #071021;
  box-shadow:
    0 0 0 1px rgba(111, 255, 236, 0.04),
    0 30px 90px rgba(0, 0, 0, 0.52),
    0 0 54px rgba(0, 217, 255, 0.10);
  aspect-ratio: 1;
}

.game-stage::before {
  position: absolute;
  inset: 0;
  z-index: 2;
  border-radius: inherit;
  box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.42);
  content: "";
  pointer-events: none;
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.impact-flash {
  position: absolute;
  inset: 0;
  z-index: 3;
  background: rgba(255, 51, 112, 0.2);
  opacity: 0;
  pointer-events: none;
}

.game-stage.is-crashing {
  animation: crash-shake 420ms ease;
}

.game-stage.is-crashing .impact-flash {
  animation: impact-flash 420ms ease;
}

.game-help {
  margin-top: 14px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.78rem;
}

.game-help span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.touch-controls {
  display: none;
  grid-template-columns: repeat(3, 58px);
  grid-template-rows: repeat(2, 54px);
  justify-content: center;
  gap: 8px;
  margin-top: 18px;
}

.touch-button {
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  color: var(--text);
  background: rgba(15, 25, 48, 0.9);
  font-size: 1.2rem;
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.touch-button:active {
  border-color: var(--cyan);
  background: rgba(57, 247, 229, 0.13);
  transform: scale(0.96);
}

.touch-button--up {
  grid-column: 2;
  grid-row: 1;
}

.touch-button--left {
  grid-column: 1;
  grid-row: 2;
}

.touch-button--down {
  grid-column: 2;
  grid-row: 2;
}

.touch-button--right {
  grid-column: 3;
  grid-row: 2;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  padding: 20px;
  display: grid;
  place-items: center;
  background: rgba(2, 5, 13, 0.72);
  backdrop-filter: blur(14px);
  animation: overlay-enter 260ms ease both;
}

.overlay-card {
  width: min(470px, 100%);
  padding: clamp(26px, 6vw, 42px);
  border: 1px solid rgba(255, 86, 137, 0.25);
  border-radius: var(--radius-xl);
  text-align: center;
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 77, 125, 0.12), transparent 52%),
    rgba(11, 16, 33, 0.96);
  box-shadow: 0 30px 100px rgba(0, 0, 0, 0.62);
  animation: modal-enter 340ms cubic-bezier(0.2, 0.85, 0.25, 1.15) both;
}

.game-over-icon {
  width: 62px;
  height: 62px;
  margin: 0 auto 18px;
  border: 1px solid rgba(255, 77, 125, 0.38);
  border-radius: 20px;
  display: grid;
  place-items: center;
  color: #ffd7e2;
  background: rgba(255, 77, 125, 0.12);
  box-shadow: 0 0 34px rgba(255, 77, 125, 0.16);
  font-size: 2rem;
  font-weight: 300;
}

.result-grid {
  margin: 28px 0;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.result-grid > div {
  padding: 17px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  display: grid;
  gap: 7px;
  background: rgba(255, 255, 255, 0.035);
}

.result-grid span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.result-grid strong {
  font: 900 1.7rem/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.overlay-actions {
  display: grid;
  gap: 10px;
}

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

@keyframes screen-enter {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes score-pulse {
  0%, 100% { transform: scale(1); }
  45% { transform: scale(1.07); border-color: rgba(57, 247, 229, 0.55); }
}

@keyframes crash-shake {
  0%, 100% { transform: translate3d(0, 0, 0); }
  20% { transform: translate3d(-7px, 2px, 0); }
  40% { transform: translate3d(6px, -2px, 0); }
  60% { transform: translate3d(-4px, 1px, 0); }
  80% { transform: translate3d(3px, 0, 0); }
}

@keyframes impact-flash {
  0%, 100% { opacity: 0; }
  18% { opacity: 1; }
}

@keyframes overlay-enter {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modal-enter {
  from { opacity: 0; transform: translateY(18px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 780px) {
  .app-shell {
    width: min(100% - 22px, 680px);
    padding: 24px 0 30px;
  }

  .menu-grid {
    grid-template-columns: 1fr;
  }

  .leaderboard-panel {
    order: 2;
  }

  .game-hud {
    align-items: flex-start;
  }

  .hud-brand {
    padding-top: 9px;
    font-size: 0.82rem;
  }

  .stat-card {
    min-width: 92px;
    padding: 9px 10px;
  }

  .game-help {
    justify-content: center;
  }

  .game-help span:last-child {
    display: none;
  }
}

@media (max-width: 520px) {
  .menu-screen {
    padding-top: 70px;
  }

  .menu-logo {
    width: 142px;
    height: 52px;
  }

  .brand-block {
    margin-bottom: 26px;
  }

  .panel {
    border-radius: 22px;
  }

  .controls-card {
    align-items: flex-start;
  }

  .game-hud {
    display: grid;
  }

  .hud-stats {
    width: 100%;
  }

  .stat-card {
    flex: 1;
    text-align: left;
  }

  .game-help {
    display: none;
  }

  .touch-controls {
    display: grid;
  }
}

@media (pointer: coarse) {
  .touch-controls {
    display: grid;
  }
}

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

  .ambient {
    display: none;
  }
}
