:root {
  color-scheme: dark;
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  background: #111a3b;
  color: #f7fbff;
  --ink: #f7fbff;
  --muted: #b9c7e8;
  --stage-backdrop-image: url("./assets/game-bg.webp");
  --stage-panel-stroke: rgba(138, 231, 255, 0.36);
  --stage-page-tint: rgba(78, 223, 255, 0.36);
  --panel-stroke: var(--stage-panel-stroke);
  --glow: var(--stage-page-tint);
  --danger: #ff7f9f;
  --success: #8fffd7;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100svh;
  background:
    linear-gradient(180deg, rgba(7, 12, 34, 0.08), rgba(7, 12, 34, 0.52)),
    var(--stage-backdrop-image) center / cover no-repeat,
    #111a3b;
  overflow-x: hidden;
}

button,
a {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
a:focus-visible,
canvas:focus-visible {
  outline: 3px solid #fff07a;
  outline-offset: 3px;
}

.lab-app {
  display: grid;
  gap: clamp(0.45rem, 1vw, 0.7rem);
  width: min(100%, 72rem);
  min-height: 100svh;
  margin: 0 auto;
  padding: clamp(0.6rem, 1.4vw, 1rem);
}

.title-screen {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 52% 35%, rgba(143, 255, 215, 0.25), transparent 16rem),
    linear-gradient(180deg, rgba(4, 8, 25, 0.18), rgba(4, 8, 25, 0.78)),
    var(--stage-backdrop-image) center / cover no-repeat,
    #111a3b;
  padding: clamp(1rem, 5vw, 2rem);
}

.title-screen[hidden] {
  display: none;
}

.title-card {
  position: relative;
  display: grid;
  width: min(100%, 34rem);
  min-height: 24rem;
  place-items: center;
  gap: 0.8rem;
  overflow: hidden;
  border: 1px solid rgba(143, 255, 215, 0.34);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(11, 24, 62, 0.82), rgba(5, 10, 32, 0.88)),
    url("./assets/ui-panel.png") center / 100% 100% no-repeat;
  padding: clamp(2.2rem, 7vw, 3.3rem);
  text-align: center;
  box-shadow: 0 1.8rem 4.5rem rgba(0, 0, 0, 0.5), 0 0 3rem rgba(78, 223, 255, 0.3);
  isolation: isolate;
  animation: title-card-rise 420ms ease-out both;
}

.title-card::before,
.title-card::after {
  content: "";
  position: absolute;
  z-index: -1;
  border-radius: 999px;
  pointer-events: none;
}

.title-card::before {
  width: 13rem;
  height: 13rem;
  border: 2px solid rgba(143, 255, 215, 0.18);
  box-shadow: 0 0 2rem rgba(143, 255, 215, 0.28);
  animation: title-orbit 7s linear infinite;
}

.title-card::after {
  inset: 1rem;
  background: radial-gradient(circle at 50% 46%, rgba(255, 240, 122, 0.14), transparent 11rem);
  opacity: 0.82;
}

.title-card h1 {
  font-size: clamp(2rem, 7.4vw, 3.4rem);
}

.title-progress {
  color: var(--muted);
  font-weight: 800;
  line-height: 1.65;
}

.title-progress {
  color: #dffbff;
  font-size: 0.92rem;
}

.title-actions {
  display: grid;
  width: min(100%, 19rem);
  gap: 0.58rem;
}

.hud-panel {
  border: 1px solid var(--panel-stroke);
  background:
    linear-gradient(180deg, rgba(13, 26, 65, 0.78), rgba(7, 13, 36, 0.82)),
    url("./assets/ui-panel.png") center / 100% 100% no-repeat;
  box-shadow: 0 1rem 2.6rem rgba(3, 8, 28, 0.34), 0 0 2rem var(--glow);
  backdrop-filter: blur(12px);
}

.eyebrow {
  margin: 0 0 0.22rem;
  color: #8fffd7;
  font-size: 0.74rem;
  font-weight: 950;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.45rem, 3.2vw, 2.35rem);
  font-weight: 950;
  line-height: 1.08;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.play-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(12rem, 17rem);
  align-items: center;
  gap: clamp(0.65rem, 1.6vw, 0.95rem);
  min-height: 0;
}

.board-wrap {
  display: grid;
  min-width: 0;
  place-items: center;
}

#game-board {
  display: block;
  width: min(100%, 74svh, 43rem);
  max-width: calc(100vw - 1.2rem);
  aspect-ratio: 1 / 1;
  border: 0;
  border-radius: 8px;
  background: rgba(8, 15, 42, 0.7);
  box-shadow: 0 1.15rem 2.8rem rgba(3, 8, 28, 0.48);
  touch-action: none;
}

.hud-panel {
  display: grid;
  align-self: stretch;
  border-radius: 8px;
  padding: clamp(0.75rem, 1.7vw, 1rem);
}

.clear-actions {
  display: grid;
  gap: 0.52rem;
}

.image-button {
  min-height: 2.75rem;
  border: 0;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02)),
    url("./assets/button-normal.png") center / 100% 100% no-repeat;
  color: #f7fbff;
  padding: 0.56rem 0.76rem;
  font-weight: 950;
  line-height: 1.15;
  text-align: center;
  text-decoration: none;
  text-shadow: 0 1px 2px rgba(3, 8, 28, 0.65);
}

.image-button.primary {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0.03)),
    url("./assets/button-primary.png") center / 100% 100% no-repeat;
}

.image-button:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.link-button {
  display: inline-grid;
  place-items: center;
}

.stage-select {
  min-height: 0;
  display: grid;
  align-content: start;
  gap: 0.5rem;
}

.chapter-buttons,
.stage-buttons {
  display: grid;
  gap: 0.42rem;
  overscroll-behavior: contain;
  padding: 0.12rem;
  scrollbar-color: rgba(143, 255, 215, 0.58) rgba(5, 12, 32, 0.48);
}

.chapter-buttons {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.stage-buttons {
  grid-template-columns: repeat(auto-fill, minmax(4.25rem, 1fr));
  max-height: min(31rem, 62svh);
  overflow-y: auto;
}

.chapter-buttons button,
.stage-buttons button {
  position: relative;
  min-height: 2.75rem;
  border: 1px solid rgba(143, 255, 215, 0.26);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(7, 18, 51, 0.75), rgba(9, 10, 37, 0.84)),
    url("./assets/button-normal.png") center / 100% 100% no-repeat;
  color: #eaf8ff;
  font-weight: 950;
}

.chapter-buttons button[aria-current="true"],
.stage-buttons button[aria-current="true"] {
  border-color: rgba(255, 240, 122, 0.82);
  color: #fff7b0;
  box-shadow: 0 0 1.1rem rgba(255, 240, 122, 0.22);
}

.chapter-buttons button.is-cleared::after,
.stage-buttons button.is-cleared::after {
  content: "";
  position: absolute;
  top: 0.36rem;
  right: 0.38rem;
  width: 0.48rem;
  height: 0.48rem;
  border-radius: 999px;
  background: #8fffd7;
  box-shadow: 0 0 0.7rem rgba(143, 255, 215, 0.78);
}

.clear-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(3, 8, 28, 0.7);
  padding: 1rem;
}

.clear-modal[hidden] {
  display: none;
}

.clear-card {
  width: min(100%, 31rem);
  min-height: 16rem;
  display: grid;
  place-items: center;
  gap: 0.7rem;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(9, 20, 55, 0.66), rgba(5, 12, 32, 0.78)),
    url("./assets/clear-modal.png") center / 100% 100% no-repeat;
  padding: clamp(2.1rem, 6vw, 3rem);
  text-align: center;
  box-shadow: 0 1.4rem 4rem rgba(0, 0, 0, 0.45);
  animation: clear-card-pop 300ms ease-out both;
}

.clear-card h2 {
  font-size: clamp(3rem, 12vw, 5.2rem);
  font-weight: 950;
  line-height: 1.1;
}

.clear-card p:not(.eyebrow) {
  color: var(--muted);
  font-weight: 800;
  line-height: 1.6;
}

#clear-message:empty {
  display: none;
}

.clear-actions {
  width: min(100%, 18rem);
}

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

@media (max-width: 880px) {
  .lab-app {
    align-content: start;
  }

  .play-layout {
    grid-template-columns: 1fr;
  }

  #game-board {
    width: min(100%, 58svh, 37rem);
  }

  .hud-panel {
    align-self: stretch;
  }
}

@media (max-width: 560px) {
  .lab-app {
    padding: 0.5rem;
  }

  #game-board {
    width: min(100%, 54svh, calc(100vw - 1rem));
  }

  .hud-panel {
    padding: 0.7rem;
  }

  .title-card {
    min-height: 21rem;
    padding: 1.8rem 1rem;
  }

  .stage-buttons {
    grid-template-columns: repeat(auto-fill, minmax(4.1rem, 1fr));
    max-height: 12rem;
  }
}

@keyframes title-card-rise {
  from {
    opacity: 0;
    transform: translateY(0.65rem) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes title-orbit {
  from {
    transform: rotate(0deg) translateX(1rem) rotate(0deg);
  }
  to {
    transform: rotate(360deg) translateX(1rem) rotate(-360deg);
  }
}

@keyframes clear-card-pop {
  from {
    opacity: 0;
    transform: translateY(0.55rem) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

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