:root {
  --bg-a: #030307;
  --bg-b: #090b12;
  --bg-c: #12151f;
  --txt: #e8fbff;
  --muted: #95c7d1;
  --accent: #00f0c0;
  --accent-2: #ff5f9f;
  --panel: rgba(3, 16, 25, 0.84);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Trebuchet MS", "Franklin Gothic Medium", "Arial Narrow", Arial, sans-serif;
  color: var(--txt);
  background:
    radial-gradient(circle at 10% 20%, rgba(0, 240, 192, 0.09), transparent 42%),
    radial-gradient(circle at 85% 8%, rgba(255, 95, 159, 0.08), transparent 38%),
    linear-gradient(150deg, var(--bg-a), var(--bg-b) 54%, var(--bg-c));
}

body {
  overflow: hidden;
  position: relative;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: rgba(0, 0, 0, 0.28);
  z-index: -1;
}

.app {
  width: 100%;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 12px;
}

.app--hidden {
  visibility: hidden;
}

.loader {
  position: fixed;
  inset: 0;
  background: #000000;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  z-index: 1000;
}

.loader--hidden {
  display: none;
}

.loader__head {
  width: min(120px, 32vw);
  aspect-ratio: 1 / 1;
  animation: loader-spin 1s linear infinite;
}

.loader__text {
  margin: 0;
  color: #dffcff;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.85rem;
}

@keyframes loader-spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.menu {
  width: min(680px, 100%);
  position: relative;
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  border: 1px solid rgba(0, 240, 192, 0.35);
  background: var(--panel);
  border-radius: 18px;
  padding: 24px 18px 22px;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.04) inset,
    0 24px 40px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
}

.menu__glow {
  position: absolute;
  inset: -2px;
  border-radius: inherit;
  background: linear-gradient(120deg, rgba(0, 240, 192, 0.35), transparent 30%, rgba(255, 95, 159, 0.35));
  filter: blur(16px);
  opacity: 0.45;
  z-index: -1;
}

.menu__title-art {
  display: block;
  width: min(320px, 68vw);
  margin: 0 auto 8px;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.5));
}

.menu__cover {
  display: block;
  width: 100%;
  margin: 0 auto 20px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  box-shadow: 0 14px 24px rgba(0, 0, 0, 0.38);
}

.menu h1 {
  margin: 0;
  text-align: center;
  font-size: clamp(1.4rem, 2.2vw, 2rem);
  letter-spacing: 0.08em;
}

.menu__tagline {
  margin: 8px auto 0;
  text-align: center;
  color: var(--muted);
  max-width: 52ch;
  font-size: 0.98rem;
}

.menu-best {
  margin: 14px auto 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(166, 236, 229, 0.3);
  background: rgba(0, 0, 0, 0.28);
  display: grid;
  justify-items: center;
  gap: 3px;
}

.menu-best span {
  font-size: 0.82rem;
  color: #b8e8ef;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.menu-best strong {
  font-size: 1.6rem;
  color: #ffffff;
  line-height: 1;
}

.menu-best small {
  font-size: 0.9rem;
  color: #d7f8ff;
}

.menu-deadline {
  margin: 10px auto 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 140, 172, 0.35);
  background: rgba(31, 7, 17, 0.55);
  display: grid;
  justify-items: center;
  gap: 2px;
}

.menu-deadline span {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #ffd4e3;
}

.menu-deadline strong {
  font-size: 1.15rem;
  letter-spacing: 0.04em;
  color: #ffffff;
}

.menu-deadline small {
  font-size: 0.75rem;
  color: #f0b9cd;
}

.menu__actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 20px;
}

.menu-btn {
  border: 0;
  border-radius: 5px;
  padding: 6px 5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-size: 0.5rem;
  color: #001311;
  cursor: pointer;
  background: linear-gradient(135deg, var(--accent), #98ffe6);
  transition: transform 120ms ease, filter 120ms ease;
}

.menu-btn:hover,
.menu-btn:focus-visible {
  transform: translateY(-1px);
  filter: brightness(1.04);
}

.menu-btn:active {
  transform: translateY(0);
}

.menu-btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  filter: grayscale(0.3);
}

#newGameBtn {
  padding-top: 12px;
  padding-bottom: 12px;
  font-size: 1rem;
}

.menu-btn--secondary {
  background: linear-gradient(135deg, #193847, #26576b);
  color: #d4f4ff;
  border: 1px solid rgba(144, 238, 255, 0.18);
}

.panel {
  margin-top: 16px;
  border: 1px solid rgba(177, 226, 235, 0.25);
  border-radius: 12px;
  background: rgba(4, 20, 31, 0.75);
  padding: 14px;
}

.panel--hidden {
  display: none;
}

.panel h2 {
  margin: 0 0 10px;
  font-size: 1.05rem;
  letter-spacing: 0.08em;
}

.panel__meta {
  margin: 14px 0 8px;
  color: #9fd4df;
  font-size: 0.9rem;
}

.panel__subtitle {
  margin: 6px 0 8px;
  font-size: 0.95rem;
  letter-spacing: 0.06em;
}

.leaderboard {
  margin: 0;
  padding-left: 20px;
  color: #dbf8ff;
  display: grid;
  gap: 6px;
}

.leaderboard__row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.stats-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 10px;
}

.stats-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #cbe7ef;
}

.stats-list strong {
  color: #fff;
  font-size: 1.1rem;
}

.panel--alterego p {
  margin: 0 0 12px;
  color: #d3f0f8;
  line-height: 1.45;
}

.panel--alterego p:last-of-type {
  margin-bottom: 0;
}

.panel--alterego {
  max-height: min(54dvh, 420px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.panel--alterego img {
  margin-top: 12px;
  width: min(360px, 100%);
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  display: block;
}

.game-shell {
  width: min(520px, 100%);
  position: relative;
}

.game-shell--hidden {
  display: none;
}

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

.hud__menu {
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(8, 27, 40, 0.8);
  color: #e9fcff;
  border-radius: 5px;
  padding: 4.5px 6px;
  font-weight: 700;
  font-size: 0.5rem;
  cursor: pointer;
}

.hud__score {
  min-width: 50px;
  text-align: center;
  font-size: 1.7rem;
  font-weight: 800;
  text-shadow: 0 3px 8px rgba(0, 0, 0, 0.5);
}

.hud__hint {
  flex: 1;
  text-align: right;
  font-size: 0.9rem;
  color: #c0e1e8;
}

.canvas-wrap {
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid rgba(199, 241, 250, 0.24);
  box-shadow: 0 22px 44px rgba(0, 0, 0, 0.45);
  background: #06131b;
}

#gameCanvas {
  width: 100%;
  max-height: calc(100dvh - 130px);
  aspect-ratio: 288 / 512;
  display: block;
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 44px 10px 10px;
  background: rgba(1, 11, 17, 0.84);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 14px;
  display: grid;
  place-content: center;
  text-align: center;
  padding: 16px;
}

.overlay--hidden {
  display: none;
}

.countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  font-size: clamp(4rem, 18vw, 7rem);
  font-weight: 900;
  color: #ffffff;
  text-shadow:
    0 0 14px rgba(0, 0, 0, 0.65),
    0 0 32px rgba(0, 240, 192, 0.35);
}

.countdown--hidden {
  display: none;
}

.overlay h2 {
  margin: 0 0 8px;
}

.overlay p {
  margin: 4px 0;
}

.overlay__actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.story-overlay {
  inset: 44px 10px 10px;
  align-content: start;
  gap: 10px;
}

.story-overlay h2 {
  margin: 0;
}

.story-overlay__content {
  max-height: min(42dvh, 360px);
  overflow-y: auto;
  border: 1px solid rgba(180, 225, 236, 0.2);
  border-radius: 10px;
  padding: 10px;
  background: rgba(0, 0, 0, 0.22);
  color: #d7f4fb;
  text-align: left;
  line-height: 1.4;
}

.story-overlay__content p {
  margin: 0 0 10px;
}

.story-overlay__content p:last-child {
  margin-bottom: 0;
}

.name-form {
  margin-top: 10px;
  display: grid;
  gap: 8px;
  text-align: left;
}

.profile-fields--hidden {
  display: none;
}

.name-form label {
  font-size: 0.88rem;
  color: #c8e5ed;
}

.name-form input {
  width: 100%;
  border: 1px solid rgba(175, 219, 231, 0.35);
  background: rgba(0, 0, 0, 0.28);
  color: #ffffff;
  border-radius: 8px;
  padding: 10px;
  font: inherit;
}

.name-form__status {
  min-height: 1.2em;
  margin: 0;
  font-size: 0.86rem;
  color: #9fe4cc;
}

@media (max-width: 700px) {
  .app {
    padding: 8px;
  }

  .menu {
    padding: 18px 12px 14px;
  }

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

  .hud {
    margin-bottom: 6px;
  }

  .hud__hint {
    font-size: 0.78rem;
  }
}
