:root {
  --text: #f4f7ff;
  --muted: rgba(244, 247, 255, 0.55);
  --glass: rgba(255, 255, 255, 0.06);
  --border: rgba(255, 255, 255, 0.12);
  --accent: #8fa8ff;
  --accent-2: #b98cff;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: #070a14;
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

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

/* ---------- HUD ---------- */

.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 15;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding:
    max(18px, env(safe-area-inset-top))
    max(18px, env(safe-area-inset-right))
    0
    max(18px, env(safe-area-inset-left));
  pointer-events: none;
}

.score-box {
  pointer-events: none;
  min-width: 0;
  transition: opacity 0.25s ease;
}

body.overlay-open .score-box {
  opacity: 0;
}

.score {
  font-size: clamp(42px, 10vw, 64px);
  font-weight: 800;
  line-height: 0.9;
  letter-spacing: -0.045em;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 6px 30px rgba(0, 0, 0, 0.35);
  transform-origin: left center;
  transition: transform 0.13s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.score.pop {
  transform: scale(1.14);
}

.best {
  margin-top: 7px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.2em;
  color: var(--muted);
}

.icon-btn {
  pointer-events: auto;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--glass);
  color: var(--text);
  cursor: pointer;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  transition: transform 0.15s ease, background 0.2s ease;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

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

.mute-lines {
  display: none;
}

body.muted .sound-waves {
  display: none;
}

body.muted .mute-lines {
  display: block;
}

/* ---------- Overlays ---------- */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(ellipse at 50% 42%, rgba(10, 14, 30, 0.18), rgba(4, 6, 14, 0.7));
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  opacity: 1;
  transition: opacity 0.32s ease, visibility 0s linear 0s;
  overflow-y: auto;
}

.overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.32s ease, visibility 0s linear 0.32s;
}

.panel {
  width: min(360px, 88vw);
  max-height: 100%;
  padding: 36px 28px 28px;
  text-align: center;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 28px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.035));
  box-shadow:
    0 30px 80px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.09);
  transform: translateY(0) scale(1);
  transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.overlay.hidden .panel {
  transform: translateY(12px) scale(0.97);
}

.logo {
  font-size: clamp(58px, 17vw, 76px);
  font-weight: 900;
  line-height: 0.9;
  letter-spacing: -0.065em;
  background: linear-gradient(180deg, #ffffff 10%, #b8c7ff 62%, #8d7bff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 10px 45px rgba(108, 140, 255, 0.4));
}

.tagline {
  margin: 18px 0 0;
  font-size: 15px;
  line-height: 1.55;
  color: rgba(244, 247, 255, 0.72);
}

.menu-best {
  margin-top: 22px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.22em;
  color: var(--muted);
}

.menu-best span {
  color: var(--text);
}

.play-btn {
  width: 100%;
  margin-top: 20px;
  padding: 16px 20px;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(180deg, #f0f4ff, #b9c8ff);
  color: #0a0e1c;
  font-family: inherit;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow:
    0 12px 32px rgba(108, 140, 255, 0.32),
    inset 0 -2px 0 rgba(0, 0, 0, 0.16);
  transition: transform 0.12s ease, filter 0.2s ease, box-shadow 0.2s ease;
}

.play-btn:hover {
  filter: brightness(1.05);
}

.play-btn:active {
  transform: translateY(2px) scale(0.995);
  box-shadow: 0 5px 16px rgba(108, 140, 255, 0.28);
}

.share-btn {
  width: 100%;
  margin-top: 10px;
  padding: 13px 20px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.12s ease;
}

.share-btn:hover {
  background: rgba(255, 255, 255, 0.09);
}

.share-btn:active {
  transform: scale(0.99);
}

.hint {
  margin: 18px 0 0;
  font-size: 12px;
  line-height: 1.6;
  color: rgba(244, 247, 255, 0.42);
}

.hint span {
  color: var(--accent);
}

.hint.small {
  margin-top: 14px;
  font-size: 11px;
}

.over-title {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.3em;
  color: var(--muted);
}

.final-score {
  margin-top: 8px;
  font-size: clamp(72px, 22vw, 96px);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.06em;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(180deg, #ffffff, #a9bbff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.new-best {
  display: inline-block;
  margin-top: 10px;
  padding: 7px 13px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffe9a8, #ffc53d);
  color: #3a2600;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.16em;
  box-shadow: 0 6px 22px rgba(255, 197, 61, 0.35);
  animation: best-pop 0.5s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}

.new-best.hidden {
  display: none;
}

@keyframes best-pop {
  from {
    opacity: 0;
    transform: scale(0.7) translateY(6px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.final-best {
  margin-top: 14px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.22em;
  color: var(--muted);
}

.final-best span {
  color: var(--text);
}

/* ---------- Boot ---------- */

.boot {
  z-index: 30;
  background:
    radial-gradient(ellipse at 50% 38%, rgba(80, 110, 255, 0.16), transparent 62%),
    #070a14;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.boot-inner {
  display: grid;
  justify-items: center;
  gap: 28px;
}

.boot-logo {
  font-size: clamp(52px, 16vw, 70px);
  animation: boot-breathe 1.8s ease-in-out infinite;
}

.spinner {
  width: 26px;
  height: 26px;
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes boot-breathe {
  0%,
  100% {
    opacity: 0.85;
    transform: scale(1);
  }
  50% {
    opacity: 1;
    transform: scale(1.03);
  }
}

/* ---------- Auth ---------- */

.auth-logo {
  font-size: clamp(46px, 14vw, 58px);
}

#auth .panel {
  padding: 30px 24px 24px;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 20px 0 18px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: rgba(4, 8, 20, 0.4);
}

.tab {
  padding: 10px 8px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.tab:disabled {
  opacity: 0.55;
  cursor: default;
}

.field {
  display: block;
  margin-top: 12px;
  text-align: left;
}

.field.hidden {
  display: none;
}

.field span {
  display: block;
  margin: 0 0 7px 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.field input {
  width: 100%;
  padding: 13px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(4, 8, 20, 0.5);
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.field input:focus {
  border-color: rgba(143, 168, 255, 0.7);
  background: rgba(4, 8, 20, 0.72);
}

.field input:disabled {
  opacity: 0.6;
}

.field input:-webkit-autofill,
.field input:-webkit-autofill:hover,
.field input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text);
  -webkit-box-shadow: 0 0 0 1000px #101528 inset;
  caret-color: var(--text);
}

.form-error {
  min-height: 17px;
  margin: 10px 0 0;
  font-size: 12px;
  line-height: 1.45;
  color: #ff9eae;
}

#authForm .play-btn {
  margin-top: 8px;
}

.play-btn:disabled {
  opacity: 0.65;
  cursor: default;
  transform: none;
}

/* ---------- Account line ---------- */

.user-line {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 20px;
  padding: 9px 13px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  font-size: 12px;
  color: rgba(244, 247, 255, 0.68);
}

.user-line strong {
  color: var(--text);
}

.user-dot {
  flex: 0 0 auto;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #78e3a8;
  box-shadow: 0 0 10px rgba(120, 227, 168, 0.8);
}

.link-btn {
  margin-left: 3px;
  padding: 2px 3px;
  border: 0;
  background: none;
  color: var(--accent);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.link-btn:hover {
  color: #c3d1ff;
}

.link-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

/* ---------- Score status ---------- */

.score-status {
  min-height: 17px;
  margin: 14px 0 0;
  font-size: 12px;
  line-height: 1.45;
  color: rgba(244, 247, 255, 0.55);
}

.score-status.saved {
  color: #8fe6b6;
}

.score-status.error {
  color: #ff9eae;
}

/* ---------- Leaderboard ---------- */

#leaderboard .panel {
  width: min(400px, 90vw);
  padding: 30px 24px 24px;
}

.lb-heading {
  margin-top: 6px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.26em;
  color: rgba(244, 247, 255, 0.34);
}

.lb-status {
  min-height: 16px;
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.lb-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}

.lb-list.hidden,
.lb-empty.hidden,
.lb-me.hidden {
  display: none;
}

.lb-row {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.035);
  font-size: 14px;
  text-align: left;
}

.lb-row.lb-mine {
  border-color: rgba(143, 168, 255, 0.55);
  background: rgba(143, 168, 255, 0.12);
}

.lb-rank {
  font-size: 11px;
  font-weight: 800;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.lb-row:nth-child(1) .lb-rank {
  color: #ffd76a;
}

.lb-row:nth-child(2) .lb-rank {
  color: #d7e0f5;
}

.lb-row:nth-child(3) .lb-rank {
  color: #e0a97a;
}

.lb-name {
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-score {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.lb-empty {
  margin: 18px 0 4px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
}

.lb-me {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid rgba(143, 168, 255, 0.28);
  border-radius: 12px;
  background: rgba(143, 168, 255, 0.1);
  font-size: 12px;
  line-height: 1.5;
  color: rgba(244, 247, 255, 0.78);
}

.lb-me strong {
  color: var(--text);
}

/* ---------- Toast ---------- */

.toast {
  position: absolute;
  left: 50%;
  bottom: max(28px, calc(env(safe-area-inset-bottom) + 20px));
  z-index: 20;
  padding: 11px 18px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(16, 21, 40, 0.85);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, 10px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- Misc ---------- */

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

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

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