:root {
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: #090d11;
  color: #d8dde1;
}

.game-page {
  min-height: 100vh;
  display: grid;
  justify-items: center;
  align-content: start;
  padding: 1rem 1rem 1.25rem;
}

.game-presentation {
  width: 100%;
  display: grid;
  justify-items: center;
  gap: 0.5rem;
}

.game-presentation h1 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: #c6cbd0;
  font-family: monospace;
}

.subtitle {
  margin: 0;
  color: #9ca5ad;
  font: 12px/1.3 monospace;
}

.wait-hint {
  margin: 0;
  color: #7f8b96;
  font: 11px/1.25 monospace;
}

#game-canvas {
  border: 1px solid #2a323a;
  max-width: 100%;
  height: auto;
  image-rendering: pixelated;
  touch-action: none;
}

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

.game-stage #game-canvas {
  width: 100%;
  display: block;
}

.game-over-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 0.6rem;
  border: 0;
  background: rgba(6, 9, 12, 0.94);
  color: #d9dee3;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  text-align: center;
  transition: opacity 120ms linear;
}

.game-over-overlay.is-active {
  pointer-events: auto;
}

.game-over-overlay .game-over-title {
  font: 600 1.7rem/1.1 monospace;
  letter-spacing: 0.04em;
}

.game-over-overlay .game-over-hint {
  font: 500 0.85rem/1.25 monospace;
  color: #9ca5ad;
  opacity: 0;
}

.game-over-overlay.is-ready .game-over-hint {
  opacity: 1;
}

.game-layout {
  display: grid;
  gap: 1rem;
  align-items: start;
  width: min(1280px, 100%);
}

.debug-panel {
  width: 100%;
  border: 1px solid #334155;
  background: #0b1220;
  padding: 0.75rem;
}

.debug-panel.is-hidden {
  display: none;
}

.debug-panel h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}

.debug-section + .debug-section {
  margin-top: 0.75rem;
}

.debug-section summary {
  cursor: pointer;
  font-weight: 700;
  color: #93c5fd;
  font-size: 0.95rem;
  list-style: none;
}

.debug-section summary::-webkit-details-marker {
  display: none;
}

.debug-section summary::before {
  content: '▸';
  display: inline-block;
  margin-right: 0.4rem;
  transition: transform 120ms ease;
}

.debug-section[open] summary::before {
  transform: rotate(90deg);
}

.debug-panel pre {
  margin: 0.35rem 0 0;
  padding: 0.5rem;
  border: 1px solid #334155;
  background: #020617;
  color: #e2e8f0;
  font: 12px/1.35 monospace;
  white-space: pre-wrap;
}

.settings-modal {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  overflow: auto;
  overscroll-behavior: contain;
  padding: clamp(0.65rem, 3%, 1.25rem);
  border: 1px solid rgba(154, 167, 179, 0.28);
  background:
    radial-gradient(circle at center, rgba(28, 37, 45, 0.42), rgba(5, 8, 11, 0.88) 68%),
    rgba(2, 6, 23, 0.78);
  color: #d9dee3;
  font-family: monospace;
  pointer-events: auto;
}

.settings-modal.is-hidden {
  display: none;
}

.settings-card {
  position: relative;
  width: min(380px, 100%);
  max-height: 100%;
  overflow: auto;
  padding: clamp(0.85rem, 3%, 1.15rem);
  border: 1px solid rgba(154, 167, 179, 0.78);
  background:
    linear-gradient(180deg, rgba(17, 23, 29, 0.96), rgba(7, 10, 14, 0.96)),
    #0b1220;
  box-shadow:
    0 0 0 1px rgba(2, 6, 10, 0.9),
    0 18px 48px rgba(0, 0, 0, 0.5);
}

.settings-card::before {
  content: '';
  position: absolute;
  inset: 0.35rem;
  border: 1px solid rgba(154, 167, 179, 0.18);
  pointer-events: none;
}

.settings-card h2 {
  margin: 0 0 0.9rem;
  color: #eef2f5;
  font: 700 1.25rem/1.1 monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.settings-toggle {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-height: 2.25rem;
  margin-bottom: 0.8rem;
  color: #cfd6dc;
  font: 600 0.9rem/1.35 monospace;
  cursor: pointer;
}

.settings-toggle input {
  width: 1.05rem;
  height: 1.05rem;
  margin: 0;
  accent-color: #d9dee3;
  cursor: pointer;
}

.settings-toggle span {
  display: inline-block;
}

.settings-group {
  margin: 0 0 1rem;
  padding: 0.75rem;
  border: 1px solid rgba(154, 167, 179, 0.38);
  background: rgba(2, 6, 10, 0.48);
}

.settings-group h3 {
  margin: 0 0 0.65rem;
  color: #aeb8c2;
  font: 700 0.78rem/1.2 monospace;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.settings-group .settings-toggle {
  margin-bottom: 0;
}

.settings-close-button {
  width: 100%;
  border: 1px solid rgba(154, 167, 179, 0.72);
  background: rgba(17, 24, 31, 0.78);
  color: #f2f5f7;
  padding: 0.55rem 0.8rem;
  font: 700 0.82rem/1.2 monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}

.settings-close-button:hover,
.settings-close-button:focus-visible {
  background: rgba(38, 49, 59, 0.9);
}

.settings-toggle:focus-within,
.settings-close-button:focus-visible {
  outline: 2px solid rgba(217, 222, 227, 0.86);
  outline-offset: 3px;
}

@media (max-width: 420px) {
  .settings-modal {
    align-items: start;
    padding: 0.55rem;
  }

  .settings-card {
    width: min(340px, 100%);
  }

  .settings-card h2 {
    font-size: 1.1rem;
  }

  .settings-toggle {
    align-items: flex-start;
    font-size: 0.84rem;
  }
}

@media (min-width: 1080px) {
  /*
    Default to the centered single-column layout for first paint. JavaScript
    explicitly opts into the debug column only while the panel is visible.
  */
  .game-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .game-layout.debug-visible {
    grid-template-columns: minmax(0, 1fr) minmax(320px, 360px);
  }

  .game-stage {
    width: min(920px, 100%);
  }

  .debug-panel:not(.is-hidden) {
    overflow: auto;
    max-height: 78vh;
  }
}
/*
  Mobile is an immersive game surface: browser scrolling is unavailable while
  the canvas owns touch gestures. Intentional UI layers (settings/debug) retain
  their own overflow behavior above the canvas.
*/
@media (hover: none) and (pointer: coarse) {
  html,
  body {
    width: 100%;
    min-width: 100%;
    height: 100%;
    min-height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
  }

  body {
    position: fixed;
    inset: 0;
  }

  .game-page {
    width: 100vw;
    min-height: 100vh;
    height: 100vh;
    min-height: 100dvh;
    height: 100dvh;
    display: block;
    overflow: hidden;
    padding: 0;
  }

  .game-layout,
  .game-presentation,
  .game-stage {
    width: 100%;
    min-width: 0;
    height: 100%;
    min-height: 0;
  }

  .game-layout,
  .game-presentation {
    display: block;
  }

  .game-presentation h1,
  .game-presentation .subtitle,
  .game-presentation .wait-hint {
    display: none;
  }

  .game-stage #game-canvas {
    display: block;
    width: 100%;
    max-width: none;
    height: 100%;
    border: 0;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
  }

  .debug-panel:not(.is-hidden) {
    position: fixed;
    inset: 0.5rem;
    z-index: 40;
    max-height: calc(100dvh - 1rem);
    overflow: auto;
  }
}
