:root {
  --ink: #f7fbff;
  --muted: #aeb8c7;
  --panel: rgba(10, 14, 20, 0.78);
  --panel-strong: rgba(8, 11, 16, 0.92);
  --line: rgba(255, 255, 255, 0.16);
  --line-strong: rgba(255, 255, 255, 0.28);
  --hot: #ff4fd8;
  --cyan: #20f4ff;
  --lime: #9cff4a;
  --amber: #ffca3a;
  --orange: #ff7a30;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  min-height: 100%;
  overflow: hidden;
  background: #07090d;
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button {
  font: inherit;
  cursor: pointer;
}

.game-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  background: #07090d;
}

#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.scanline {
  pointer-events: none;
  position: absolute;
  inset: 0;
  background:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px) 0 0 / 100% 4px,
    radial-gradient(circle at 50% 120%, rgba(255, 255, 255, 0.1), transparent 40%);
  mix-blend-mode: screen;
  opacity: 0.34;
}

.topbar {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top));
  left: calc(14px + env(safe-area-inset-left));
  right: calc(14px + env(safe-area-inset-right));
  z-index: 4;
  display: grid;
  grid-template-columns: minmax(190px, 280px) minmax(180px, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-height: 54px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(7, 9, 13, 0.58);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  position: relative;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border: 1px solid rgba(32, 244, 255, 0.8);
  border-radius: 7px;
  background:
    linear-gradient(135deg, rgba(32, 244, 255, 0.32), rgba(255, 79, 216, 0.2)),
    #0b0f16;
  box-shadow:
    0 0 24px rgba(32, 244, 255, 0.38),
    inset 0 0 18px rgba(255, 255, 255, 0.08);
  transform: rotate(45deg);
}

.brand-mark::after {
  content: "";
  position: absolute;
  inset: 9px;
  border: 2px solid var(--amber);
  border-radius: 4px;
}

.brand strong,
.brand span,
.hud-chip,
.progress-wrap {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand strong {
  display: block;
  font-size: 0.92rem;
  font-weight: 850;
}

.brand span {
  display: block;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
}

.progress-wrap {
  display: grid;
  grid-template-columns: minmax(90px, 1fr) 44px;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.progress-track {
  position: relative;
  height: 10px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
}

#progressBar {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--cyan), var(--lime), var(--amber), var(--hot));
  box-shadow: 0 0 18px rgba(32, 244, 255, 0.72);
}

#progressText {
  color: var(--ink);
  font-size: 0.8rem;
  font-weight: 850;
  text-align: right;
}

.hud-cluster {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hud-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  max-width: 150px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 820;
}

.icon-button,
.primary-button,
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  color: var(--ink);
  font-weight: 840;
  background: rgba(255, 255, 255, 0.1);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  transition:
    transform 150ms ease,
    border-color 150ms ease,
    background 150ms ease,
    box-shadow 150ms ease;
}

.icon-button:hover,
.primary-button:hover,
.ghost-button:hover,
.level-card:hover {
  transform: translateY(-1px);
  border-color: rgba(32, 244, 255, 0.64);
  box-shadow:
    0 0 22px rgba(32, 244, 255, 0.22),
    inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.icon-button:focus-visible,
.primary-button:focus-visible,
.ghost-button:focus-visible,
.level-card:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 3px;
}

.icon-button {
  width: 38px;
  padding: 0;
}

.pause-icon {
  position: relative;
  width: 14px;
  height: 16px;
}

.pause-icon::before,
.pause-icon::after {
  content: "";
  position: absolute;
  top: 1px;
  bottom: 1px;
  width: 4px;
  border-radius: 2px;
  background: currentColor;
}

.pause-icon::before {
  left: 1px;
}

.pause-icon::after {
  right: 1px;
}

.primary-button,
.ghost-button {
  min-width: 126px;
  padding: 0 16px;
}

.primary-button {
  border-color: rgba(156, 255, 74, 0.68);
  background:
    linear-gradient(135deg, rgba(156, 255, 74, 0.32), rgba(32, 244, 255, 0.2)),
    rgba(255, 255, 255, 0.1);
}

.ghost-button.compact {
  min-width: 84px;
  min-height: 34px;
}

.screen,
.overlay {
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  padding: 92px 20px 28px;
  opacity: 0;
  transform: translateY(10px);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.screen.is-active,
.overlay.is-active {
  pointer-events: auto;
  opacity: 1;
  transform: translateY(0);
}

.menu-panel,
.level-panel,
.dialog {
  width: min(680px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px);
}

.menu-panel {
  padding: 30px;
}

.kicker {
  margin: 0 0 10px;
  color: var(--cyan);
  font-size: 0.76rem;
  font-weight: 860;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  max-width: 620px;
  font-size: clamp(2.5rem, 8vw, 5.4rem);
  line-height: 0.94;
}

h1 span {
  display: block;
}

h2 {
  font-size: clamp(1.8rem, 4vw, 3.2rem);
  line-height: 1;
}

.menu-actions,
.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 24px;
}

.menu-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
}

.menu-stats span {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.07);
  font-size: 0.78rem;
  font-weight: 760;
}

.level-panel {
  padding: 18px;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.level-card {
  position: relative;
  min-height: 170px;
  padding: 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  text-align: left;
  background: rgba(255, 255, 255, 0.08);
  transition:
    transform 150ms ease,
    border-color 150ms ease,
    box-shadow 150ms ease;
}

.level-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, var(--card-a), transparent 46%),
    radial-gradient(circle at 82% 18%, var(--card-b), transparent 30%);
  opacity: 0.82;
}

.level-card > * {
  position: relative;
}

.level-card strong {
  display: block;
  margin-bottom: 8px;
  font-size: 1.05rem;
}

.level-card span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 760;
}

.level-meter {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
}

.level-meter i {
  display: block;
  width: var(--best);
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--cyan), var(--lime), var(--amber));
}

.overlay {
  z-index: 5;
  background: rgba(0, 0, 0, 0.22);
}

.dialog {
  width: min(460px, calc(100vw - 32px));
  padding: 24px;
  text-align: center;
}

.dialog .dialog-actions {
  justify-content: center;
}

.result-line {
  margin: 14px 0 0;
  color: var(--muted);
  font-weight: 760;
}

@media (max-width: 760px) {
  .game-shell {
    min-height: 0;
  }

  .topbar {
    top: calc(10px + env(safe-area-inset-top));
    left: calc(10px + env(safe-area-inset-left));
    right: calc(10px + env(safe-area-inset-right));
    grid-template-columns: 1fr auto;
    gap: 8px;
  }

  .progress-wrap {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .hud-chip {
    display: none;
  }

  .screen,
  .overlay {
    padding: 104px 12px 18px;
  }

  .menu-panel,
  .level-panel,
  .dialog {
    width: calc(100vw - 24px);
  }

  .menu-panel {
    padding: 22px;
  }

  h1 {
    font-size: clamp(2.05rem, 8.8vw, 2.45rem);
    line-height: 1.02;
    max-width: 100%;
  }

  .menu-actions,
  .dialog-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .menu-actions .primary-button,
  .menu-actions .ghost-button,
  .dialog-actions .primary-button,
  .dialog-actions .ghost-button {
    width: 100%;
    min-width: 0;
  }

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

  .level-card {
    min-height: 126px;
  }

  .primary-button,
  .ghost-button {
    flex: 1 1 128px;
  }
}

@media (max-height: 620px) and (orientation: landscape) {
  .game-shell {
    min-height: 0;
  }

  .topbar {
    min-height: 46px;
  }

  .screen,
  .overlay {
    padding-top: 74px;
  }

  h1 {
    font-size: clamp(2rem, 7vw, 3.8rem);
  }

  .menu-panel {
    padding: 20px;
  }

  .level-card {
    min-height: 138px;
  }
}
