:root {
  color-scheme: dark;
  --bg: #0e1116;
  --bg-glow: #17202c;
  --panel: rgba(20, 25, 33, 0.92);
  --border: #2a3340;
  --text: #e6ebf2;
  --muted: #8b97a8;
  --accent: #6fcf6a;
  --accent-2: #4aa3df;
  --danger: #ff7a6b;
  --header-h: 64px;
  --footer-h: 40px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: radial-gradient(ellipse at 50% 30%, var(--bg-glow), var(--bg) 70%) fixed;
  background-color: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

.page {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
}

.masthead {
  height: var(--header-h);
  width: var(--frame-w);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.logo-mark {
  width: 26px;
  height: 26px;
  border-radius: 4px;
  background:
    linear-gradient(var(--accent) 0 35%, transparent 35%),
    linear-gradient(135deg, #8a5a35, #6b4426);
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.25);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #1a212b;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: #222b37; border-color: #3a4656; }
.btn:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }

/* The game keeps a 16:9 aspect ratio and scales to fit the window. */
.page {
  --frame-w: min(100vw - 32px, (100vh - var(--header-h) - var(--footer-h) - 16px) * 16 / 9);
}

.game-frame {
  position: relative;
  width: var(--frame-w);
  aspect-ratio: 16 / 9;
  border-radius: 10px;
  overflow: hidden;
  background: #000;
  border: 1px solid var(--border);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
}

.game-frame:fullscreen {
  width: 100vw;
  height: 100vh;
  aspect-ratio: auto;
  border: 0;
  border-radius: 0;
}

#canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
}

/* Developer readout (F3), drawn over the canvas. */
.debug-overlay {
  position: absolute;
  top: 10px;
  left: 10px;
  margin: 0;
  padding: 8px 10px;
  border-radius: 6px;
  background: rgba(8, 10, 14, 0.62);
  color: #e6ebf2;
  font: 12px/1.45 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  white-space: pre;
  pointer-events: none;
}
.debug-overlay[hidden] { display: none; }

.footer {
  height: var(--footer-h);
  display: flex;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #121821, #0b0e13);
  transition: opacity 0.4s;
}
.overlay[hidden] { display: none; }
.overlay.fade-out { opacity: 0; pointer-events: none; }

.overlay-card {
  width: min(460px, 90%);
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  text-align: center;
}

.overlay-title { margin: 0 0 14px; font-size: 18px; font-weight: 600; }
.overlay-detail { margin: 10px 0 0; color: var(--muted); font-size: 13px; min-height: 1.5em; word-break: break-word; }
.overlay-error .overlay-title { color: var(--danger); }

.progress {
  height: 8px;
  border-radius: 4px;
  background: #222a35;
  overflow: hidden;
}
.progress-bar {
  width: 0%;
  height: 100%;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.2s;
}

.spinner {
  width: 28px;
  height: 28px;
  margin: 0 auto 14px;
  border: 3px solid #2a3340;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.browsers { margin-top: 18px; text-align: left; font-size: 13px; color: var(--text); }
.browsers ul { margin: 6px 0 10px; padding-left: 20px; color: var(--muted); }
.browsers code { color: var(--accent-2); }

@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; }
  .overlay, .progress-bar { transition: none; }
}
