:root {
  color-scheme: dark;
  font-family: Inter, ui-rounded, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-synthesis: none;
  --ink: #fffaf0;
  --muted: #d1cee9;
  --night: #101023;
  --night-soft: #1b1b36;
  --panel: rgba(25, 24, 52, 0.94);
  --panel-solid: #211f42;
  --line: #9089c8;
  --gold: #ffd678;
  --gold-deep: #3b2a0b;
  --rose: #ff90a8;
  --mint: #8be6cf;
  --focus: #fff29b;
  --shadow: 0 1.25rem 4rem rgba(3, 3, 16, 0.46);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 20rem;
  min-height: 100%;
  background: var(--night);
}

body {
  min-height: 100svh;
  margin: 0;
  padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 4%, rgba(142, 108, 199, 0.32), transparent 30rem),
    radial-gradient(circle at 90% 34%, rgba(219, 91, 143, 0.16), transparent 34rem),
    linear-gradient(160deg, #191835 0%, #101023 54%, #0a1321 100%);
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image: radial-gradient(circle, rgba(255, 250, 240, 0.19) 0 1px, transparent 1.5px);
  background-size: 5rem 5rem;
  content: "";
  opacity: 0.22;
  pointer-events: none;
}

button {
  min-width: 2.75rem;
  min-height: 2.75rem;
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  padding: 0.65rem 0.95rem;
  color: var(--ink);
  background: #29284c;
  box-shadow: 0 0.28rem 0 rgba(7, 7, 24, 0.55);
  font: inherit;
  font-weight: 720;
  line-height: 1.15;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button:hover:not(:disabled) {
  border-color: var(--gold);
  background: #35335e;
}

button:active:not(:disabled),
button.is-held {
  translate: 0 0.2rem;
  box-shadow: 0 0.08rem 0 rgba(7, 7, 24, 0.55);
}

button:focus-visible,
[tabindex]:focus-visible {
  outline: 0.2rem solid var(--focus);
  outline-offset: 0.2rem;
}

button:disabled {
  cursor: wait;
  opacity: 0.72;
}

button.primary {
  border-color: var(--gold);
  color: #211706;
  background: linear-gradient(180deg, #ffe49c, var(--gold));
}

button.primary:hover:not(:disabled) {
  color: #130e03;
  background: #ffedae;
}

[hidden] {
  display: none !important;
}

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

.site-header,
main,
footer {
  width: min(70rem, 100%);
  margin-inline: auto;
}

.site-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 2rem;
  padding: 0.1rem 0.25rem 1rem;
}

.eyebrow,
.chapter,
.overlay-kicker {
  margin: 0 0 0.2rem;
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  font-size: clamp(1.55rem, 5vw, 2.65rem);
  font-weight: 850;
  letter-spacing: -0.055em;
  line-height: 0.95;
}

.tagline {
  max-width: 28rem;
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  text-align: right;
}

.game-shell {
  position: relative;
  display: grid;
  gap: 0.6rem;
  padding: clamp(0.75rem, 2.4vw, 1rem);
  overflow: hidden;
  border: 1px solid rgba(173, 165, 225, 0.7);
  border-radius: 1.5rem;
  background: linear-gradient(150deg, rgba(40, 38, 78, 0.97), rgba(20, 20, 43, 0.98));
  box-shadow: var(--shadow);
}

.game-shell::before {
  position: absolute;
  top: -8rem;
  right: -7rem;
  width: 20rem;
  height: 20rem;
  border-radius: 50%;
  background: rgba(235, 121, 165, 0.1);
  content: "";
  pointer-events: none;
}

.game-heading,
.toolbar,
.lower-controls,
.touch-controls,
.direction-controls,
.settings,
.overlay-actions {
  display: flex;
  align-items: center;
}

.game-heading {
  z-index: 1;
  justify-content: space-between;
  gap: 1rem;
}

.game-heading h2 {
  margin: 0;
  font-size: clamp(1.1rem, 3vw, 1.55rem);
  letter-spacing: -0.025em;
}

.toolbar,
.settings,
.overlay-actions {
  flex-wrap: wrap;
  gap: 0.5rem;
}

.toolbar[inert] {
  opacity: 0.42;
  filter: saturate(0.55);
}

.instructions {
  z-index: 1;
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.fullscreen-help {
  z-index: 1;
  margin: 0;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.35;
}

#fullscreen-button[aria-pressed="true"] {
  border-color: var(--mint);
  color: #061a16;
  background: var(--mint);
}

.hud {
  z-index: 2;
  display: grid;
  grid-template-columns: auto minmax(10rem, 1fr);
  align-items: center;
  gap: 1rem;
  min-height: 3.4rem;
  padding: 0.45rem 0.65rem;
  border: 1px solid rgba(144, 137, 200, 0.65);
  border-radius: 1rem;
  background: rgba(14, 14, 36, 0.72);
}

.hud dl {
  display: flex;
  gap: clamp(1rem, 4vw, 2.4rem);
  margin: 0;
}

.hud dl > div {
  display: grid;
  gap: 0.08rem;
}

.hud dt {
  color: var(--muted);
  font-size: 0.67rem;
  font-weight: 800;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.hud dd {
  margin: 0;
  color: var(--gold);
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  font-weight: 820;
}

.status {
  margin: 0;
  color: var(--ink);
  font-size: 0.84rem;
  line-height: 1.3;
  text-align: right;
}

.playfield {
  position: relative;
  z-index: 1;
  width: 100%;
  height: clamp(15rem, 52vw, 38rem);
  max-height: max(15rem, calc(100svh - 22rem));
  min-height: 15rem;
  overflow: hidden;
  border: 2px solid #a9a3df;
  border-radius: clamp(0.8rem, 2.2vw, 1.35rem);
  background: #12172e;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12), 0 0.8rem 2rem rgba(4, 5, 18, 0.46);
  isolation: isolate;
  user-select: none;
}

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

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: clamp(0.5rem, 2vw, 1rem);
  background: linear-gradient(150deg, rgba(12, 13, 33, 0.65), rgba(23, 17, 42, 0.9));
  backdrop-filter: blur(0.4rem);
}

.overlay[data-overflow="true"] {
  padding-bottom: 2.1rem;
}

.overlay[data-overflow="true"]::after {
  position: absolute;
  bottom: 0.35rem;
  left: 50%;
  z-index: 20;
  max-width: calc(100% - 1rem);
  translate: -50% 0;
  border: 1px solid #6a4a0a;
  border-radius: 999px;
  padding: 0.28rem 0.55rem;
  color: #231805;
  background: var(--gold);
  box-shadow: 0 0.25rem 0.8rem rgba(3, 3, 16, 0.7);
  content: "More options ↓";
  font-size: 0.7rem;
  font-weight: 850;
  line-height: 1.1;
  text-align: center;
  pointer-events: none;
}

.overlay-card {
  width: min(30rem, 100%);
  max-height: 100%;
  padding: clamp(0.75rem, 2vw, 1.15rem);
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-color: var(--gold) var(--panel-solid);
  scrollbar-gutter: stable;
  border: 1px solid var(--line);
  border-radius: 1.25rem;
  background: var(--panel);
  box-shadow: 0 1rem 3rem rgba(2, 2, 14, 0.56);
}

.overlay-card h3 {
  margin: 0;
  font-size: clamp(1.3rem, 4vw, 1.8rem);
  letter-spacing: -0.04em;
  line-height: 1.02;
}

#overlay-message {
  margin: 0.45rem 0 0.75rem;
  color: var(--muted);
  line-height: 1.35;
}

.overlay-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: stretch;
}

.overlay-actions button {
  width: 100%;
}

.lower-controls {
  z-index: 1;
  justify-content: space-between;
  gap: 1rem;
}

.touch-controls {
  flex: 1;
  justify-content: space-between;
  gap: 1rem;
}

.direction-controls {
  gap: 0.55rem;
}

.touch-control {
  display: inline-flex;
  min-width: 4rem;
  min-height: 4rem;
  align-items: center;
  justify-content: center;
  border-color: #aaa4e0;
  border-radius: 50%;
  padding: 0.5rem;
  font-size: 1.55rem;
  touch-action: none;
}

.touch-control.jump {
  flex-direction: column;
  border-color: var(--gold);
  color: var(--gold-deep);
  background: var(--gold);
  font-size: 1.1rem;
  line-height: 1;
}

.touch-control.jump span:last-child {
  font-size: 0.65rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.settings {
  justify-content: end;
}

.overlay-card > .settings {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: stretch;
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px solid rgba(144, 137, 200, 0.55);
}

body[data-game-state="dying"] .playfield::after {
  position: absolute;
  top: clamp(0.55rem, 2vw, 1rem);
  left: 50%;
  z-index: 9;
  width: max-content;
  max-width: calc(100% - 1rem);
  translate: -50% 0;
  border: 2px solid #fff0a8;
  border-radius: 999px;
  padding: 0.45rem 0.8rem;
  color: #2a0b18;
  background: #fff0a8;
  box-shadow: 0 0.45rem 1.2rem rgba(12, 4, 18, 0.75);
  content: "Light faded — returning to beacon…";
  font-size: clamp(0.76rem, 2.7vw, 0.95rem);
  font-weight: 900;
  line-height: 1.15;
  text-align: center;
  pointer-events: none;
}

.settings button[aria-pressed="true"] {
  border-color: var(--mint);
  color: #061a16;
  background: var(--mint);
}

.no-script {
  margin-top: 1rem;
  padding: 1rem;
  border: 2px solid var(--rose);
  border-radius: 1rem;
  background: #331b2a;
}

.no-script h2,
.no-script p {
  margin: 0;
}

.no-script p {
  margin-top: 0.4rem;
}

footer {
  padding: 0.75rem 0.25rem 0;
  color: var(--muted);
  font-size: 0.74rem;
  text-align: center;
}

footer p {
  margin: 0;
}

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

  .lower-controls {
    justify-content: end;
  }
}

@media (max-width: 42rem) {
  body {
    padding: max(0.6rem, env(safe-area-inset-top)) max(0.6rem, env(safe-area-inset-right)) max(0.6rem, env(safe-area-inset-bottom)) max(0.6rem, env(safe-area-inset-left));
  }

  .site-header {
    align-items: start;
  }

  .tagline {
    display: none;
  }

  .game-heading {
    align-items: start;
    flex-direction: column;
  }

  .toolbar {
    width: 100%;
  }

  .toolbar button {
    flex: 1 1 9rem;
  }

  .hud {
    grid-template-columns: 1fr;
    gap: 0.35rem;
  }

  .playfield {
    height: 22rem;
    min-height: 22rem;
    max-height: none;
  }

  .overlay {
    padding: 0.45rem;
  }

  .overlay-card {
    padding: 0.7rem;
  }

  .overlay-kicker {
    display: none;
  }

  .overlay-card h3 {
    font-size: 1.3rem;
  }

  #overlay-message {
    margin: 0.35rem 0 0.55rem;
    font-size: 0.82rem;
    line-height: 1.28;
  }

  .overlay-card > .settings {
    margin-top: 0.45rem;
    padding-top: 0.45rem;
  }

  .status {
    min-height: 1.1rem;
    text-align: left;
  }

  .lower-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .settings {
    justify-content: stretch;
  }

  .settings button {
    flex: 1;
  }

  body[data-game-state="playing"],
  body[data-game-state="dying"] {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    min-height: 100svh;
    overflow: hidden;
    overscroll-behavior: none;
  }

  body[data-game-state="playing"] .site-header,
  body[data-game-state="playing"] footer,
  body[data-game-state="dying"] .site-header,
  body[data-game-state="dying"] footer {
    display: none;
  }

  body[data-game-state="playing"] main,
  body[data-game-state="dying"] main,
  body[data-game-state="playing"] .game-shell,
  body[data-game-state="dying"] .game-shell {
    width: 100%;
    height: 100%;
    min-height: 0;
  }

  body[data-game-state="playing"] .game-shell,
  body[data-game-state="dying"] .game-shell {
    grid-template-rows: auto minmax(0, 1fr);
    gap: 0.25rem;
    padding: max(0.35rem, env(safe-area-inset-top)) max(0.35rem, env(safe-area-inset-right)) max(0.35rem, env(safe-area-inset-bottom)) max(0.35rem, env(safe-area-inset-left));
    border-radius: 0.85rem;
  }

  body[data-game-state="playing"] .game-heading,
  body[data-game-state="dying"] .game-heading {
    display: block;
    min-height: 2.75rem;
  }

  body[data-game-state="playing"] .game-heading > div:first-child,
  body[data-game-state="dying"] .game-heading > div:first-child {
    display: none;
  }

  body[data-game-state="playing"] .toolbar,
  body[data-game-state="dying"] .toolbar {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.3rem;
  }

  body[data-game-state="playing"] .toolbar button,
  body[data-game-state="dying"] .toolbar button {
    min-width: 0;
    min-height: 2.75rem;
    padding: 0.3rem;
    font-size: 0.72rem;
  }

  body[data-game-state="playing"] .instructions,
  body[data-game-state="playing"] .fullscreen-help,
  body[data-game-state="dying"] .instructions,
  body[data-game-state="dying"] .fullscreen-help,
  body[data-game-state="playing"] .status,
  body[data-game-state="dying"] .status {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    border: 0;
    white-space: nowrap;
  }

  body[data-game-state="playing"] .hud,
  body[data-game-state="dying"] .hud {
    position: absolute;
    top: max(3.55rem, calc(env(safe-area-inset-top) + 3rem));
    left: max(0.75rem, calc(env(safe-area-inset-left) + 0.35rem));
    z-index: 5;
    display: block;
    width: auto;
    min-height: 0;
    padding: 0.35rem 0.5rem;
    pointer-events: none;
  }

  body[data-game-state="playing"] .playfield,
  body[data-game-state="dying"] .playfield {
    height: auto;
    min-height: 0;
    max-height: none;
  }

  body[data-game-state="playing"] .lower-controls,
  body[data-game-state="dying"] .lower-controls {
    position: absolute;
    right: max(0.75rem, calc(env(safe-area-inset-right) + 0.35rem));
    bottom: max(0.75rem, calc(env(safe-area-inset-bottom) + 0.35rem));
    left: max(0.75rem, calc(env(safe-area-inset-left) + 0.35rem));
    z-index: 6;
    display: block;
    pointer-events: none;
  }

  body[data-game-state="playing"] .touch-controls,
  body[data-game-state="dying"] .touch-controls {
    display: flex;
    width: 100%;
    pointer-events: none;
  }

  body[data-game-state="playing"] .touch-controls button,
  body[data-game-state="dying"] .touch-controls button {
    pointer-events: auto;
  }

  body[data-game-state="playing"] .lower-controls > .settings,
  body[data-game-state="dying"] .lower-controls > .settings {
    display: none;
  }

  body:is([data-game-state="playing"], [data-game-state="dying"])
    .fullscreen-help[data-fullscreen-support="fallback"] {
    position: absolute;
    top: max(7rem, calc(env(safe-area-inset-top) + 6.5rem));
    right: max(0.75rem, calc(env(safe-area-inset-right) + 0.35rem));
    left: max(0.75rem, calc(env(safe-area-inset-left) + 0.35rem));
    z-index: 8;
    width: auto;
    height: auto;
    max-height: 6.5rem;
    margin: 0;
    padding: 0.4rem 0.55rem;
    overflow: auto;
    clip: auto;
    clip-path: none;
    border: 1px solid var(--line);
    border-radius: 0.75rem;
    color: var(--ink);
    background: var(--panel-solid);
    box-shadow: 0 0.4rem 1rem rgba(3, 3, 16, 0.55);
    line-height: 1.25;
    white-space: normal;
  }
}

@media (orientation: landscape) and (max-height: 32.5rem) {
  body {
    padding: max(0.35rem, env(safe-area-inset-top)) max(0.45rem, env(safe-area-inset-right)) max(0.35rem, env(safe-area-inset-bottom)) max(0.45rem, env(safe-area-inset-left));
  }

  .site-header,
  footer {
    display: none;
  }

  .game-shell {
    min-height: calc(100svh - max(0.7rem, env(safe-area-inset-top) + env(safe-area-inset-bottom)));
    gap: 0.35rem;
    padding: 0.45rem;
    border-radius: 0.9rem;
  }

  .game-heading {
    min-height: 2.75rem;
  }

  .chapter {
    display: none;
  }

  .game-heading h2 {
    font-size: 1rem;
  }

  .instructions,
  .fullscreen-help {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    border: 0;
    white-space: nowrap;
  }

  .hud {
    position: absolute;
    top: max(3.55rem, calc(env(safe-area-inset-top) + 3rem));
    left: max(0.85rem, calc(env(safe-area-inset-left) + 0.45rem));
    z-index: 5;
    display: block;
    min-height: 0;
    padding: 0.35rem 0.5rem;
    pointer-events: none;
  }

  .hud dl {
    gap: 1rem;
  }

  .hud dt {
    font-size: 0.58rem;
  }

  .hud dd {
    font-size: 0.78rem;
  }

  .status {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }

  .playfield {
    height: calc(100svh - 5rem);
    min-height: 12rem;
    max-height: none;
    border-radius: 0.65rem;
  }

  .lower-controls {
    position: absolute;
    right: max(1rem, calc(env(safe-area-inset-right) + 0.45rem));
    bottom: max(0.9rem, calc(env(safe-area-inset-bottom) + 0.35rem));
    left: max(1rem, calc(env(safe-area-inset-left) + 0.45rem));
    z-index: 6;
    pointer-events: none;
  }

  .lower-controls button {
    pointer-events: auto;
  }

  .touch-controls {
    display: flex;
  }

  .touch-control {
    min-width: 3.4rem;
    min-height: 3.4rem;
    background: rgba(41, 40, 76, 0.88);
  }

  .touch-control.jump {
    color: var(--gold-deep);
    background: rgba(255, 214, 120, 0.92);
  }

  .lower-controls > .settings {
    display: none;
  }

  .overlay-card {
    width: min(27rem, calc(100% - 7rem));
    padding: 0.65rem 0.8rem;
  }

  .overlay-card h3 {
    font-size: 1.35rem;
  }

  #overlay-message {
    margin: 0.25rem 0 0.4rem;
    font-size: 0.82rem;
    line-height: 1.2;
  }

  .overlay-actions button {
    min-height: 2.75rem;
    padding: 0.35rem 0.45rem;
    font-size: 0.84rem;
  }

  .overlay-card > .settings {
    margin-top: 0.35rem;
    padding-top: 0.35rem;
  }

  .overlay-card > .settings button {
    padding: 0.35rem 0.45rem;
    font-size: 0.84rem;
  }

  body:is([data-game-state="playing"], [data-game-state="dying"])
    .fullscreen-help[data-fullscreen-support="fallback"] {
    position: absolute;
    top: max(6.2rem, calc(env(safe-area-inset-top) + 5.7rem));
    right: max(0.75rem, calc(env(safe-area-inset-right) + 0.45rem));
    left: auto;
    z-index: 8;
    width: min(18rem, calc(100% - 2rem - env(safe-area-inset-left) - env(safe-area-inset-right)));
    height: auto;
    max-height: none;
    margin: 0;
    padding: 0.4rem 0.55rem;
    overflow: visible;
    clip: auto;
    clip-path: none;
    border: 1px solid var(--line);
    border-radius: 0.75rem;
    color: var(--ink);
    background: var(--panel-solid);
    box-shadow: 0 0.4rem 1rem rgba(3, 3, 16, 0.55);
    line-height: 1.25;
    white-space: normal;
  }
}

@media (max-height: 50rem) {
  footer {
    display: none;
  }
}

/* Fullscreen and installed modes share one whole-shell, safe-area-aware layout. */
.game-shell:fullscreen,
html[data-display-mode="standalone"] .game-shell {
  width: 100%;
  max-width: 100%;
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  min-height: 100dvh;
  grid-template-rows: auto auto 0 auto minmax(0, 1fr) auto;
  gap: clamp(0.35rem, 1.4vmin, 0.6rem);
  padding: max(0.45rem, env(safe-area-inset-top)) max(0.45rem, env(safe-area-inset-right)) max(0.45rem, env(safe-area-inset-bottom)) max(0.45rem, env(safe-area-inset-left));
  overflow: hidden;
  overscroll-behavior: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.game-shell:fullscreen::backdrop {
  background: var(--night);
}

:is(.game-shell:fullscreen, html[data-display-mode="standalone"] .game-shell) > .game-heading {
  grid-row: 1;
}

:is(.game-shell:fullscreen, html[data-display-mode="standalone"] .game-shell) > .instructions {
  grid-row: 2;
}

:is(.game-shell:fullscreen, html[data-display-mode="standalone"] .game-shell) > .fullscreen-help {
  display: none;
  grid-row: 3;
}

:is(.game-shell:fullscreen, html[data-display-mode="standalone"] .game-shell) > .hud {
  grid-row: 4;
}

:is(.game-shell:fullscreen, html[data-display-mode="standalone"] .game-shell) > .playfield {
  height: auto;
  min-height: 0;
  max-height: none;
  grid-row: 5;
}

:is(.game-shell:fullscreen, html[data-display-mode="standalone"] .game-shell) > .lower-controls {
  grid-row: 6;
}

html[data-display-mode="standalone"],
html[data-display-mode="standalone"] body,
html[data-display-mode="standalone"] main {
  width: 100%;
  height: 100%;
  min-height: 100vh;
  min-height: 100dvh;
}

html[data-display-mode="standalone"] body {
  padding: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

html[data-display-mode="standalone"] .site-header,
html[data-display-mode="standalone"] footer {
  display: none;
}

/* At 200% zoom, trade the immersive overlay layout for clear document reflow. */
@media (orientation: landscape) and (max-height: 16rem) {
  .game-shell {
    height: auto;
    min-height: 0;
    gap: 0.5rem;
    padding: 0.5rem;
    overflow: visible;
  }

  body[data-game-state="playing"],
  body[data-game-state="dying"] {
    height: auto;
    overflow: auto;
  }

  body[data-game-state="playing"] main,
  body[data-game-state="dying"] main {
    height: auto;
  }

  .game-heading {
    min-height: 0;
    align-items: stretch;
    flex-direction: column;
    gap: 0.4rem;
  }

  .toolbar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .toolbar button {
    min-width: 0;
  }

  .instructions {
    position: static;
    width: auto;
    height: auto;
    margin: 0;
    padding: 0;
    overflow: visible;
    clip: auto;
    clip-path: none;
    white-space: normal;
  }

  .hud {
    position: static;
    display: grid;
    grid-template-columns: 1fr;
    min-height: 0;
    padding: 0.4rem 0.5rem;
    pointer-events: auto;
  }

  .status {
    position: static;
    width: auto;
    height: auto;
    min-height: 1.1rem;
    overflow: visible;
    clip: auto;
    clip-path: none;
    text-align: left;
  }

  .playfield {
    height: clamp(16rem, 75vw, 20rem);
    min-height: 16rem;
    max-height: none;
  }

  .lower-controls {
    position: static;
    width: 100%;
    align-items: stretch;
    flex-direction: column;
    pointer-events: auto;
  }

  .touch-controls,
  .lower-controls > .settings {
    display: flex;
    width: 100%;
  }

  .lower-controls > .settings {
    justify-content: stretch;
  }

  .lower-controls > .settings button {
    flex: 1;
  }

  .overlay-card {
    width: min(30rem, 100%);
  }

  body::before,
  .game-shell::before {
    display: none;
  }

  .game-shell:fullscreen,
  html[data-display-mode="standalone"] .game-shell {
    width: 100%;
    height: auto;
    min-height: 100dvh;
    grid-template-rows: auto auto 0 auto auto auto;
    overflow: auto;
  }

  body:is([data-game-state="playing"], [data-game-state="dying"]) .game-shell:fullscreen,
  html[data-display-mode="standalone"]
    body:is([data-game-state="playing"], [data-game-state="dying"])
    .game-shell {
    width: 100%;
    height: auto;
    min-height: 100dvh;
    grid-template-rows: auto auto 0 auto auto auto;
    overflow-x: hidden;
    overflow-y: auto;
  }

  :is(.game-shell:fullscreen, html[data-display-mode="standalone"] .game-shell) > .playfield {
    height: clamp(16rem, 75vw, 20rem);
    min-height: 16rem;
    max-height: none;
  }

  :is(.game-shell:fullscreen, html[data-display-mode="standalone"] .game-shell) > .instructions {
    position: static;
    width: auto;
    height: auto;
    min-height: max-content;
    margin: 0;
    overflow: visible;
    clip: auto;
    clip-path: none;
    white-space: normal;
  }

  :is(.game-shell:fullscreen, html[data-display-mode="standalone"] .game-shell) > .hud {
    position: static;
    display: grid;
    width: auto;
    min-height: max-content;
    pointer-events: auto;
  }

  :is(.game-shell:fullscreen, html[data-display-mode="standalone"] .game-shell) > .hud .status {
    position: static;
    width: auto;
    height: auto;
    margin: 0;
    overflow: visible;
    clip: auto;
    clip-path: none;
    white-space: normal;
  }

  :is(.game-shell:fullscreen, html[data-display-mode="standalone"] .game-shell) > .lower-controls {
    position: static;
    display: flex;
    width: 100%;
    align-items: stretch;
    flex-direction: column;
    pointer-events: auto;
  }

  :is(.game-shell:fullscreen, html[data-display-mode="standalone"] .game-shell)
    > .lower-controls > .settings {
    display: flex;
    width: 100%;
  }

  :is(.game-shell:fullscreen, html[data-display-mode="standalone"] .game-shell) .toolbar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  :is(.game-shell:fullscreen, html[data-display-mode="standalone"] .game-shell) > .game-heading {
    height: auto;
    min-height: max-content;
  }

  body:is([data-game-state="playing"], [data-game-state="dying"])
    .game-shell:fullscreen > .game-heading,
  html[data-display-mode="standalone"]
    body:is([data-game-state="playing"], [data-game-state="dying"])
    .game-shell > .game-heading {
    position: static;
    display: block;
    height: auto;
    min-height: auto;
  }

  body:is([data-game-state="playing"], [data-game-state="dying"])
    .game-shell:fullscreen > .instructions,
  html[data-display-mode="standalone"]
    body:is([data-game-state="playing"], [data-game-state="dying"])
    .game-shell > .instructions {
    position: static;
    width: auto;
    height: auto;
    min-height: auto;
    margin: 0;
    padding: 0;
    overflow: visible;
    clip: auto;
    clip-path: none;
    border: 0;
    white-space: normal;
  }

  body:is([data-game-state="playing"], [data-game-state="dying"])
    .game-shell:fullscreen > .hud,
  html[data-display-mode="standalone"]
    body:is([data-game-state="playing"], [data-game-state="dying"])
    .game-shell > .hud {
    position: static;
    display: grid;
    width: auto;
    min-height: auto;
    pointer-events: auto;
  }

  body:is([data-game-state="playing"], [data-game-state="dying"])
    .game-shell:fullscreen > .lower-controls,
  html[data-display-mode="standalone"]
    body:is([data-game-state="playing"], [data-game-state="dying"])
    .game-shell > .lower-controls {
    position: static;
    display: flex;
    width: 100%;
    min-height: auto;
    align-items: stretch;
    flex-direction: column;
    pointer-events: auto;
  }

  html[data-display-mode="standalone"] body {
    height: auto;
    overflow: auto;
  }

  html[data-display-mode="standalone"] main {
    height: auto;
  }
}

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

html[data-reduced-motion="true"] *,
html[data-reduced-motion="true"] *::before,
html[data-reduced-motion="true"] *::after {
  scroll-behavior: auto !important;
  transition-duration: 0.001ms !important;
  animation-duration: 0.001ms !important;
  animation-iteration-count: 1 !important;
}

@media (forced-colors: active) {
  button,
  .game-shell,
  .hud,
  .playfield,
  .overlay-card {
    border: 2px solid ButtonText;
  }

  button:focus-visible,
  [tabindex]:focus-visible {
    outline: 3px solid Highlight;
  }
}
