* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  width: 100%;
  height: 100%;
  background: #050510;
  overflow: hidden;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0)
    env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
}
/* Wave 25 — dyslexia-friendly spacing (no external font dep) */
body.dyslexia {
  letter-spacing: 0.06em;
  word-spacing: 0.12em;
  line-height: 1.55;
  font-family: Verdana, "Segoe UI", Tahoma, system-ui, sans-serif;
}
body.dyslexia #stage canvas {
  /* canvas text still uses canvas fonts; CSS helps DOM chrome */
}
/* Wave 30/33 — flash-safe + safe-area stage pad */
body.flash-safe #stage {
  filter: saturate(0.85) contrast(0.95);
}
#wrap {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, #0a0a2e 0%, #050510 70%);
  padding-top: env(safe-area-inset-top, 0);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
/* Wave 16.0.2 — dual-layer stage (world + HUD) */
#stage {
  position: relative;
  width: min(100vw, calc(100vh * 400 / 700));
  height: min(100vh, calc(100vw * 700 / 400));
  max-width: 400px;
  max-height: 700px;
  box-shadow: 0 0 40px rgba(60, 120, 255, 0.35), 0 0 2px #3cf;
  border-radius: 8px;
  overflow: hidden;
  background: #000;
}
#stage canvas {
  display: block;
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  image-rendering: auto;
}
#game {
  z-index: 1;
  background: #000;
}
#hud {
  z-index: 2;
  pointer-events: none;
  background: transparent;
}

/* Wave 18 — high-contrast accessibility theme */
body.hc {
  background: #000;
}
body.hc #wrap {
  background: #000;
}
body.hc #stage {
  box-shadow: 0 0 0 3px #fff, 0 0 24px #ff0;
  border-radius: 0;
}
body.hc #game {
  background: #000;
  filter: contrast(1.35) saturate(1.25);
}

/* Wave 19 — colorblind canvas filters */
body.cb-protan #game {
  filter: url('#cb-protan') contrast(1.08);
}
body.cb-deutan #game {
  filter: url('#cb-deutan') contrast(1.08);
}
body.cb-tritan #game {
  filter: hue-rotate(25deg) saturate(1.15);
}
/* Fallback when SVG filters unavailable — approximate matrices via CSS */
@supports not (filter: url('#x')) {
  body.cb-protan #game { filter: saturate(0.85) hue-rotate(-12deg) contrast(1.1); }
  body.cb-deutan #game { filter: saturate(0.8) hue-rotate(18deg) contrast(1.1); }
}

/* Screen-reader live region (created by game.js if missing) */
#a11y-live {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* Wave 22 — WCAG reduced-motion route */
@media (prefers-reduced-motion: reduce) {
  #stage {
    box-shadow: 0 0 8px rgba(60, 120, 255, 0.25);
  }
  body.hc #stage {
    box-shadow: 0 0 0 3px #fff;
  }
}

/* Ensure focusable stage for keyboard users */
#stage:focus-within {
  outline: 2px solid #ff0;
  outline-offset: 2px;
}

/* Skip link for screen readers (optional HTML injection) */
.skip-a11y {
  position: absolute;
  left: -9999px;
}
.skip-a11y:focus {
  left: 8px;
  top: 8px;
  z-index: 99;
  background: #ff0;
  color: #000;
  padding: 8px 12px;
}

/* Wave 23 — RTL scaffold (canvas game; flips page chrome only) */
body.rtl #wrap {
  direction: rtl;
}
body.rtl #a11y-live {
  /* keep SR region off-screen */
  left: auto;
  right: -9999px;
}
