/* Grow with the window, keeping the 1000:560 stage fully in view. */
.nw-header,
.nw {
  max-width: max(64rem, min(100%, calc((100vh - 9rem) * 1000 / 560 + 2rem)));
}

.nw {
  margin: 0 auto;
  padding: 0 1rem 2rem;
  -webkit-user-select: none;
  user-select: none;
}

.nw-stage {
  position: relative;
  border-radius: 0.75rem;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #000;
}

.nw-stage canvas {
  display: block;
  width: 100%;
  aspect-ratio: 1000 / 560;
  /* The canvas handles its own drags (twin-stick touch controls). */
  touch-action: none;
}

/* Fullscreen: letterbox the canvas at its aspect ratio. */
.nw-stage:fullscreen {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 0;
}

.nw-stage:fullscreen canvas {
  width: min(100vw, 178.57vh);
}

.nw-hint {
  margin: 0.5rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.nw-overlay {
  position: absolute;
  inset: 0;
  display: none;
  padding: 1rem;
  background: rgb(0 0 0 / 0.6);
  color: #fff;
  text-align: center;
  overflow-y: auto;
}

.nw-overlay.open {
  display: flex;
}

/* Centre with auto margins so tall content can still scroll on small screens. */
.nw-overlay > div {
  margin: auto;
  max-width: 44rem;
}

.nw-overlay h2 {
  font-size: clamp(1.5rem, 5vw, 2.5rem);
  margin: 0 0 0.25rem;
}

.nw-overlay p {
  margin: 0.25rem 0 0.75rem;
  color: #e7e5e4;
}

.nw-overlay .row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  margin: 0.5rem 0;
}

.nw-overlay button {
  font: inherit;
  padding: 0.5rem 1.1rem;
  font-weight: 600;
  background: #fff;
  color: #1c1917;
  border: 0;
  border-radius: 0.5rem;
  cursor: pointer;
}

.nw-overlay button.primary {
  background: var(--accent);
  color: #fff;
}

.nw-overlay .help {
  font-size: 0.85rem;
  color: #d6d3d1;
}

.nw-overlay .help b {
  color: #fde047;
}

.nw-overlay .settings {
  margin-top: 0.9rem;
}

.nw-overlay button.toggle {
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
  font-weight: 600;
  background: rgb(255 255 255 / 0.1);
  color: #e7e5e4;
  border: 1px solid rgb(255 255 255 / 0.2);
}

.nw-overlay button.toggle[aria-pressed="true"] {
  background: rgb(103 232 249 / 0.2);
  border-color: rgb(103 232 249 / 0.6);
  color: #ecfeff;
}

/* Phones: the stage is short, so the overlay text shrinks to fit. */
@media (max-width: 600px) {
  .nw-overlay {
    padding: 0.5rem;
    font-size: 0.8rem;
  }

  .nw-overlay h2 {
    font-size: 1.3rem;
  }

  .nw-overlay p {
    margin: 0.15rem 0 0.4rem;
  }

  .nw-overlay button {
    padding: 0.35rem 0.8rem;
  }

  .nw-overlay .help {
    font-size: 0.72rem;
  }

  /* The controls line repeats the hint under the stage. */
  .nw-overlay .help.controls {
    display: none;
  }
}
