:root {
  color-scheme: dark;
  background: #03040b;
  --text: #eafcff;
  --muted: rgba(219, 243, 255, 0.72);
  --line: rgba(134, 231, 255, 0.2);
  --cyan: #2af7ff;
  --magenta: #ff38d2;
  --violet: #9d5cff;
  --panel: rgba(6, 9, 26, 0.68);
}

* {
  box-sizing: border-box;
}

/* The `hidden` attribute must always win, even over flex/grid display rules. */
[hidden] {
  display: none !important;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 45%, rgba(39, 14, 82, 0.35), transparent 44%),
    radial-gradient(circle at 20% 15%, rgba(0, 210, 255, 0.13), transparent 31%),
    radial-gradient(circle at 84% 78%, rgba(255, 0, 186, 0.12), transparent 34%),
    #03040b;
}

body {
  position: fixed;
  inset: 0;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

#space,
#sandbox {
  position: fixed;
  inset: 0;
  display: block;
  width: 100vw;
  height: 100vh;
}

#space {
  z-index: 0;
  background: #03040b;
}

#sandbox {
  z-index: 1;
  background: transparent;
  cursor: crosshair;
  touch-action: none;
}

.ui {
  position: fixed;
  inset: 0;
  z-index: 3;
  color: var(--text);
  font: 500 15px/1.35 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  pointer-events: none;
}

/* ---- Relax onboarding hint ---- */
.hint-card {
  position: absolute;
  left: 50%;
  bottom: clamp(2.4rem, 12vh, 7rem);
  transform: translate(-50%, 14px);
  display: grid;
  gap: 0.3rem;
  justify-items: center;
  padding: 0.95rem 1.5rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(6, 9, 26, 0.55);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  box-shadow: 0 0 36px rgba(42, 247, 255, 0.18);
  text-align: center;
  opacity: 0;
  transition: opacity 420ms ease, transform 420ms ease;
  pointer-events: none;
}

.hint-card.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.hint-card strong {
  font-size: 1.12rem;
  letter-spacing: 0.01em;
}

.hint-card span {
  color: var(--muted);
  font-size: 0.92rem;
}

/* ---- Corner buttons (challenge entry, back) ---- */
.corner-button {
  position: absolute;
  top: clamp(0.8rem, 2.5vw, 1.3rem);
  pointer-events: auto;
  padding: 0.7rem 1.1rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(9, 14, 35, 0.66);
  color: var(--text);
  font: inherit;
  font-weight: 800;
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  box-shadow: 0 0 20px rgba(42, 247, 255, 0.14);
  cursor: pointer;
  touch-action: manipulation;
}

.corner-right {
  right: clamp(0.8rem, 2.5vw, 1.3rem);
}

.corner-left {
  left: clamp(0.8rem, 2.5vw, 1.3rem);
}

/* ---- Screens (level select, result) ---- */
.screen {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: clamp(1rem, 3vw, 2rem);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 180ms ease, visibility 180ms ease;
}

.screen.is-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.panel {
  width: min(92vw, 600px);
  border: 1px solid var(--line);
  border-radius: 10px;
  background:
    linear-gradient(135deg, rgba(42, 247, 255, 0.12), transparent 32%),
    linear-gradient(225deg, rgba(255, 56, 210, 0.12), transparent 38%),
    var(--panel);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.45), 0 0 44px rgba(42, 247, 255, 0.11);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}

.levels-panel {
  padding: clamp(1.1rem, 3vw, 1.6rem);
}

.result-panel {
  padding: clamp(1.5rem, 4vw, 2.4rem);
  text-align: center;
}

.eyebrow {
  margin: 0 0 0.45rem;
  color: var(--cyan);
  font-size: 0.77rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h2 {
  margin: 0;
  font-weight: 850;
  font-size: clamp(1.7rem, 4.5vw, 2.9rem);
  line-height: 1;
  text-wrap: balance;
}

.screen-topline {
  display: flex;
  align-items: center;
  gap: 0.95rem;
  margin-bottom: 0.5rem;
}

.levels-howto {
  margin: 0.2rem 0 1.1rem;
  color: var(--muted);
  font-size: 0.95rem;
}

button {
  min-height: 48px;
  border: 0;
  border-radius: 10px;
  color: var(--text);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
}

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

.icon-button {
  flex: 0 0 auto;
  width: 48px;
  padding: 0;
  border: 1px solid var(--line);
  background: rgba(9, 14, 35, 0.72);
  font-size: 2.1rem;
  line-height: 1;
}

.primary-button,
.secondary-button {
  min-width: min(100%, 150px);
  padding: 0.85rem 1.2rem;
}

.primary-button {
  background: linear-gradient(135deg, rgba(32, 230, 255, 0.95), rgba(115, 84, 255, 0.88));
  box-shadow: 0 0 24px rgba(42, 247, 255, 0.28);
}

.primary-button.accent {
  background: linear-gradient(135deg, rgba(255, 56, 210, 0.95), rgba(92, 118, 255, 0.9));
  box-shadow: 0 0 26px rgba(255, 56, 210, 0.28);
}

.secondary-button {
  border: 1px solid var(--line);
  background: rgba(9, 14, 35, 0.72);
}

/* ---- Level cards ---- */
.level-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
}

.level-card {
  display: grid;
  align-content: start;
  gap: 0.3rem;
  min-height: 150px;
  padding: 1.1rem 1rem;
  border: 1px solid rgba(219, 243, 255, 0.16);
  border-radius: 10px;
  background: rgba(4, 8, 24, 0.68);
  color: var(--text);
  text-align: left;
  box-shadow: inset 0 0 24px rgba(42, 247, 255, 0.05);
}

.level-card .card-name {
  font-size: 1.35rem;
  font-weight: 850;
}

.level-card .card-goal {
  margin-top: 0.15rem;
  font-size: 1.02rem;
  color: var(--text);
}

.level-card .card-goal strong {
  color: var(--cyan);
}

.level-card .card-sub {
  color: var(--muted);
  font-size: 0.85rem;
}

.level-card .card-best {
  align-self: end;
  margin-top: 0.7rem;
  color: #fff3a0;
  font-size: 0.92rem;
  font-weight: 800;
  text-shadow: 0 0 14px rgba(255, 223, 93, 0.32);
}

/* ---- In-round HUD ---- */
.game-ui {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.goal {
  position: absolute;
  top: clamp(1rem, 4vh, 2.2rem);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  white-space: nowrap;
}

.goal-label {
  color: var(--muted);
  font-size: clamp(0.85rem, 2.2vw, 1.05rem);
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.goal strong {
  color: var(--text);
  font-size: clamp(1.8rem, 5vw, 2.6rem);
  font-weight: 850;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 22px rgba(42, 247, 255, 0.5), 0 0 40px rgba(255, 56, 210, 0.3);
}

.live-counter {
  position: absolute;
  top: clamp(3.6rem, 13vh, 6.4rem);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 0.9;
}

.live-counter strong {
  font-size: clamp(3.4rem, 14vw, 6.4rem);
  font-weight: 850;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 30px rgba(42, 247, 255, 0.45), 0 0 60px rgba(157, 92, 255, 0.3);
}

.live-counter span {
  margin-top: 0.1rem;
  color: var(--muted);
  font-size: clamp(0.78rem, 2.2vw, 0.95rem);
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.live-counter.tick strong {
  animation: counter-pop 220ms ease;
}

@keyframes counter-pop {
  0% { transform: scale(1.28); color: #fff; }
  100% { transform: scale(1); }
}

.game-hint {
  position: absolute;
  left: 50%;
  bottom: clamp(2rem, 10vh, 5rem);
  transform: translateX(-50%);
  margin: 0;
  padding: 0.6rem 1.1rem;
  border-radius: 999px;
  background: rgba(6, 9, 26, 0.5);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: var(--muted);
  white-space: nowrap;
  opacity: 1;
  transition: opacity 360ms ease;
}

.game-hint.faded {
  opacity: 0;
}

/* ---- Result readout ---- */
.result-readout {
  display: grid;
  justify-items: center;
  gap: 0.35rem;
  margin-top: 1.2rem;
}

.readout-main {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.readout-main strong {
  font-size: clamp(3rem, 12vw, 5rem);
  font-weight: 850;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 30px rgba(42, 247, 255, 0.4);
}

.readout-main span {
  color: var(--muted);
  font-size: 1rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.readout-sub {
  color: var(--muted);
  font-size: 0.98rem;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.7rem;
  margin-top: clamp(1.4rem, 4vw, 2rem);
}

noscript {
  position: fixed;
  inset: auto 1rem 1rem 1rem;
  z-index: 4;
  color: #d8f7ff;
  font: 14px/1.4 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  text-align: center;
}

@media (max-width: 720px) {
  .level-grid {
    grid-template-columns: 1fr;
    gap: 0.6rem;
  }

  .level-card {
    min-height: 0;
    grid-template-columns: 1fr auto;
    align-items: center;
  }

  .level-card .card-best {
    grid-column: 1 / -1;
    margin-top: 0.2rem;
  }

  .panel {
    width: min(94vw, 520px);
  }
}
