:root {
  color-scheme: dark;
  --cyan: #55f4ff;
  --pink: #ff5fd2;
  --lime: #b8ff6a;
  --ink: #070817;
  --panel: rgba(8, 11, 31, 0.72);
  --panel-strong: rgba(10, 15, 38, 0.88);
  --text: #f7fbff;
  --muted: #b9c7e9;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 12%, rgba(85, 244, 255, 0.28), transparent 30%),
    radial-gradient(circle at 78% 18%, rgba(255, 95, 210, 0.26), transparent 28%),
    linear-gradient(180deg, #27247f 0%, #3a2b9b 42%, #10142d 100%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

body.telegram-miniapp {
  background:
    linear-gradient(90deg, rgba(5, 6, 20, 0.78), rgba(5, 6, 20, 0.18) 48%, rgba(5, 6, 20, 0.68)),
    var(--tg-theme-bg-color, #070817);
}

button,
input {
  font: inherit;
}

#game-root,
#canvas-stage {
  position: fixed;
  inset: 0;
}

#canvas-stage canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.hidden {
  display: none !important;
}

.screen {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 18px;
  padding: clamp(22px, 4vw, 56px);
  text-align: center;
  background:
    linear-gradient(90deg, rgba(5, 6, 20, 0.78), rgba(5, 6, 20, 0.22) 42%, rgba(5, 6, 20, 0.72)),
    linear-gradient(180deg, rgba(5, 7, 19, 0.1), rgba(5, 7, 19, 0.6));
  z-index: 20;
}

.screen-active {
  display: flex;
}

.brand-mark {
  width: 78px;
  height: 78px;
  display: grid;
  place-items: center;
  border: 2px solid rgba(85, 244, 255, 0.75);
  border-radius: 18px;
  background:
    linear-gradient(135deg, rgba(85, 244, 255, 0.18), rgba(255, 95, 210, 0.2)),
    rgba(7, 8, 23, 0.7);
  box-shadow: 0 0 28px rgba(85, 244, 255, 0.36), inset 0 0 24px rgba(255, 255, 255, 0.08);
  color: var(--lime);
  font-size: 30px;
  font-weight: 900;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  max-width: min(820px, 92vw);
  font-size: clamp(44px, 9vw, 108px);
  line-height: 0.92;
  font-weight: 950;
  text-transform: uppercase;
  text-shadow: 0 7px 0 rgba(0, 0, 0, 0.24), 0 0 42px rgba(85, 244, 255, 0.42);
}

h2 {
  font-size: clamp(36px, 6vw, 72px);
  line-height: 0.95;
  font-weight: 930;
  text-transform: uppercase;
  text-shadow: 0 0 30px rgba(255, 95, 210, 0.34);
}

.menu-subtitle,
#loading-text,
.game-over-reason {
  max-width: 620px;
  color: var(--muted);
  font-size: clamp(16px, 2vw, 22px);
}

.menu-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: min(620px, 100%);
}

.menu-actions.compact {
  width: min(520px, 100%);
}

button {
  min-width: 154px;
  min-height: 48px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  padding: 12px 18px;
  color: var(--text);
  background: rgba(13, 18, 45, 0.74);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06), 0 13px 30px rgba(0, 0, 0, 0.24);
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease, box-shadow 120ms ease;
}

button:hover,
button:focus-visible {
  transform: translateY(-2px);
  border-color: rgba(85, 244, 255, 0.78);
  background: rgba(20, 33, 76, 0.86);
  box-shadow: 0 0 24px rgba(85, 244, 255, 0.2), 0 16px 34px rgba(0, 0, 0, 0.28);
  outline: none;
}

.primary-button {
  color: #06101b;
  border-color: rgba(255, 255, 255, 0.34);
  background: linear-gradient(135deg, var(--lime), var(--cyan));
  font-weight: 900;
}

.primary-button:hover,
.primary-button:focus-visible {
  background: linear-gradient(135deg, #dbff70, #6cf8ff);
  box-shadow: 0 0 28px rgba(184, 255, 106, 0.36), 0 16px 34px rgba(0, 0, 0, 0.3);
}

.hud {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: 50%;
  z-index: 10;
  width: min(760px, calc(100vw - 24px));
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  transform: translateX(-50%);
  pointer-events: none;
}

.hud-effects {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 34px;
  pointer-events: none;
}

.effect-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 6px 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(4, 7, 21, 0.62);
  color: var(--text);
  box-shadow: 0 0 18px rgba(85, 244, 255, 0.13);
  font-size: 12px;
  font-weight: 900;
  backdrop-filter: blur(10px);
}

.effect-chip.magnet {
  color: var(--cyan);
}

.effect-chip.boots {
  color: #fff46a;
}

.effect-chip.multiplier {
  color: var(--lime);
}

.hud-pill {
  min-width: 0;
  min-height: 58px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  padding: 9px 14px;
  border: 1px solid rgba(85, 244, 255, 0.26);
  border-radius: 8px;
  background: rgba(4, 7, 21, 0.58);
  box-shadow: inset 0 0 20px rgba(85, 244, 255, 0.06), 0 10px 24px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(10px);
}

.hud-center {
  text-align: center;
}

.hud-pill:last-child {
  text-align: right;
}

.hud-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.hud strong {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: clamp(18px, 3.4vw, 29px);
  line-height: 1;
  text-overflow: ellipsis;
}

.final-score {
  width: min(380px, 100%);
  padding: 18px;
  border: 1px solid rgba(184, 255, 106, 0.32);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: inset 0 0 28px rgba(184, 255, 106, 0.08);
}

.final-score span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.final-score strong {
  display: block;
  margin-top: 4px;
  color: var(--lime);
  font-size: clamp(42px, 7vw, 74px);
  line-height: 0.95;
}

.record-label {
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(184, 255, 106, 0.16);
  color: var(--lime);
  font-weight: 900;
  text-transform: uppercase;
  box-shadow: 0 0 22px rgba(184, 255, 106, 0.25);
}

.name-field {
  width: min(380px, 100%);
  display: grid;
  gap: 7px;
  color: var(--muted);
  text-align: left;
  font-weight: 800;
}

.name-field input {
  width: 100%;
  min-height: 48px;
  border: 1px solid rgba(85, 244, 255, 0.32);
  border-radius: 8px;
  padding: 11px 13px;
  color: var(--text);
  background: rgba(3, 7, 22, 0.76);
  outline: none;
}

.name-field input:focus {
  border-color: rgba(85, 244, 255, 0.9);
  box-shadow: 0 0 20px rgba(85, 244, 255, 0.2);
}

body.telegram-miniapp .name-field {
  display: none;
}

.leaderboard-table,
.mini-board {
  width: min(660px, 100%);
  max-height: min(58vh, 520px);
  overflow: auto;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: var(--panel-strong);
  box-shadow: inset 0 0 32px rgba(85, 244, 255, 0.06), 0 18px 42px rgba(0, 0, 0, 0.28);
}

.mini-board {
  max-height: 170px;
  width: min(460px, 100%);
}

.leader-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 116px 108px;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 9px 13px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  text-align: left;
}

.mini-board .leader-row {
  grid-template-columns: 36px minmax(0, 1fr) 92px;
}

.leader-row:last-child {
  border-bottom: 0;
}

.leader-row.header {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.leader-row.highlight {
  background: linear-gradient(90deg, rgba(184, 255, 106, 0.18), rgba(85, 244, 255, 0.08));
  color: var(--lime);
}

.leader-row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-board {
  padding: 22px;
  color: var(--muted);
}

.how-grid {
  width: min(720px, 100%);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.onboarding-grid {
  width: min(640px, 100%);
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.onboarding-grid div {
  min-height: 82px;
  display: grid;
  align-content: center;
  gap: 6px;
  padding: 13px;
  border: 1px solid rgba(85, 244, 255, 0.18);
  border-radius: 8px;
  background: rgba(4, 7, 21, 0.54);
  text-align: left;
  backdrop-filter: blur(10px);
}

.onboarding-grid strong {
  color: var(--lime);
  font-size: 18px;
}

.onboarding-grid span {
  color: var(--muted);
  font-size: 14px;
}

.how-grid div {
  min-height: 74px;
  display: grid;
  align-content: center;
  gap: 6px;
  padding: 13px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: var(--panel);
  text-align: left;
}

.how-grid strong {
  color: var(--cyan);
  font-size: 19px;
}

.how-grid span {
  color: var(--muted);
}

@media (max-width: 640px) {
  .screen {
    gap: 14px;
    justify-content: center;
  }

  .brand-mark {
    width: 60px;
    height: 60px;
    border-radius: 14px;
    font-size: 24px;
  }

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

  button {
    width: 100%;
  }

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

  .hud-pill {
    min-height: 50px;
    padding: 7px 8px;
  }

  .hud-label {
    font-size: 9px;
  }

  .leader-row {
    grid-template-columns: 34px minmax(0, 1fr) 82px;
  }

  .leader-row .leader-date,
  .leader-row.header .leader-date {
    display: none;
  }

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

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

  .onboarding-grid div {
    min-height: 76px;
  }
}
