/* Doom-like stage: the engine framebuffer is the visual authority. */
:root {
  color-scheme: dark;
  /* DOOM's own reds and greys: the menu font's 255/139/67 reds, the status bar's stone. */
  --black: #000;
  --panel: #1b0000;
  --line: #6b0000;
  --text: #ff3f3f;
  --muted: #9b3a3a;
  --accent: #cf0000;
  --accent-pressed: #ff3f3f;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --view-width: calc(100vw - env(safe-area-inset-left) - env(safe-area-inset-right));
  --view-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--black);
  color: var(--text);
  font-family: var(--mono);
}

.stage {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--black);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#canvas,
#boot-canvas {
  display: block;
  /* Fill the window: no letterbox or pillarbox bars. The 320x200 frame stretches to the window's
     shape, like a widescreen port's "stretch" mode; pointer mapping reads the canvas rect. */
  width: var(--view-width);
  height: var(--view-height);
  image-rendering: pixelated;
  outline: none;
}

#canvas { position: relative; z-index: 1; }
#boot-canvas { position: absolute; z-index: 2; }
#boot-canvas[hidden] { display: none; }

.touch-controls {
  position: fixed;
  inset: 0;
  z-index: 3;
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: env(safe-area-inset-top) max(1rem, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(1rem, env(safe-area-inset-left));
  pointer-events: none;
}

.touch-controls[hidden] { display: none !important; }
.touch-controls__left,
.touch-controls__right { pointer-events: none; }
.touch-controls__stick,
.touch-controls button { pointer-events: auto; }

.touch-controls button {
  min-width: 3.25rem;
  min-height: 2.75rem;
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 0;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  color: var(--text);
  font: 600 0.62rem/1 var(--mono);
  letter-spacing: 0.08em;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.touch-controls button:focus-visible {
  outline: 2px solid var(--accent-pressed);
  outline-offset: 2px;
}
.touch-controls button:active,
.touch-controls button[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent-pressed);
  color: #fff;
}

.touch-controls__stick {
  position: relative;
  width: clamp(7rem, 18vw, 9rem);
  height: clamp(7rem, 18vw, 9rem);
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 72%, transparent);
  touch-action: none;
  user-select: none;
}
.touch-controls__stick::before,
.touch-controls__stick::after {
  position: absolute;
  content: "";
  background: var(--line);
  opacity: 0.8;
}
.touch-controls__stick::before { inset: 50% 12% auto; height: 1px; }
.touch-controls__stick::after { inset: 12% auto 12% 50%; width: 1px; }
.touch-controls__stick-label {
  position: absolute;
  color: var(--muted);
  font: 500 0.48rem/1 var(--mono);
  letter-spacing: 0.08em;
  pointer-events: none;
}
.touch-controls__stick-label--up { top: 0.55rem; left: 50%; transform: translateX(-50%); }
.touch-controls__stick-label--down { bottom: 0.55rem; left: 50%; transform: translateX(-50%); }
.touch-controls__stick-label--left { top: 50%; left: 0.55rem; transform: translateY(-50%); }
.touch-controls__stick-label--right { top: 50%; right: 0.55rem; transform: translateY(-50%); }
.touch-controls__stick-thumb {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 2.7rem;
  height: 2.7rem;
  transform: translate(calc(-50% + var(--stick-x, 0px)), calc(-50% + var(--stick-y, 0px)));
  border: 1px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 72%, var(--panel));
  pointer-events: none;
}

.touch-controls__right {
  display: grid;
  justify-items: end;
  gap: 0.45rem;
}
.touch-controls__nav,
.touch-controls__utility,
.touch-controls__actions {
  display: flex;
  gap: 0.45rem;
}
.touch-controls__fire { background: color-mix(in srgb, var(--accent) 72%, var(--panel)); }

/* Native site menus are drawn in the framebuffer; only their classic Doom menu
   gets the four small navigation buttons. */
body.is-native-menu .touch-controls { display: none !important; }
body.is-classic-menu .touch-controls__stick,
body.is-classic-menu .touch-controls__utility,
body.is-classic-menu .touch-controls__actions { display: none; }
body.is-classic-menu .touch-controls { justify-content: flex-end; }
body.is-classic-menu .touch-controls__nav { display: flex; }
body:not(.is-classic-menu) .touch-controls__nav { display: none; }

.orientation-hint {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: none;
  place-items: center;
  align-content: center;
  gap: 1rem;
  padding: 2rem;
  background: var(--black);
  color: var(--muted);
  font: 600 0.7rem/1.6 var(--mono);
  letter-spacing: 0.12em;
  text-align: center;
  text-transform: uppercase;
}
.orientation-hint__device {
  width: 2.1rem;
  height: 3.5rem;
  border: 2px solid var(--accent);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

@media (pointer: coarse) and (orientation: landscape) {
  .touch-controls { display: flex; }
}

@media (pointer: coarse) and (orientation: portrait) {
  .orientation-hint { display: grid; }
  .touch-controls { display: none !important; }
}

@media (pointer: fine) {
  .touch-controls { display: none !important; }
}

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

@media (prefers-contrast: more) {
  :root { --line: #8d7768; --muted: #ddd0c6; }
}
