:root {
  color-scheme: dark;
  font-family: Inter, ui-rounded, "SF Pro Rounded", system-ui, sans-serif;
  background: #090c1b;
  color: #f8f5ff;
}

* { box-sizing: border-box; }

body {
  min-height: 100vh;
  margin: 0;
  display: grid;
  place-items: center;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 20% 10%, #28326d 0, transparent 35%),
    radial-gradient(circle at 90% 80%, #3b245f 0, transparent 32%),
    #090c1b;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .22;
  background-image: radial-gradient(#fff 1px, transparent 1px);
  background-size: 33px 33px;
}

button {
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 999px;
  padding: .7rem 1.1rem;
  color: #fff;
  background: rgba(255, 255, 255, .1);
  font: inherit;
  font-weight: 750;
  cursor: pointer;
  white-space: nowrap;
  transition: transform .15s ease, background .15s ease;
}

button:hover { background: rgba(255, 255, 255, .18); transform: translateY(-1px); }
button:active { transform: translateY(1px) scale(.98); }
button:disabled { cursor: not-allowed; opacity: .48; transform: none; }

button,
a {
  position: relative;
  z-index: 120;
  pointer-events: auto;
  touch-action: manipulation;
}

.title-screen,
.map-screen,
.message,
.ending-screen,
.corner-menu,
.corner-menu-panel,
.title-actions {
  pointer-events: auto;
}
.camera-fx-corner-button {
  position: fixed;
  top: calc(72px + env(safe-area-inset-top));
  left: calc(10px + env(safe-area-inset-left));
  z-index: 80;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  max-width: min(44vw, 220px);
  padding: .42rem .68rem;
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 999px;
  color: rgba(255, 255, 255, .88);
  background: rgba(92, 96, 112, .78);
  box-shadow: 0 10px 24px rgba(0, 0, 0, .24);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: clamp(.62rem, 2.2vw, .78rem);
  font-weight: 850;
  line-height: 1.05;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}
.camera-fx-corner-button span {
  margin-left: .22rem;
  color: rgba(255, 255, 255, .66);
  font-weight: 750;
}
.camera-fx-corner-button:hover {
  background: rgba(110, 114, 132, .86);
  transform: translateY(-1px);
}
.camera-fx-corner-button:active {
  transform: translateY(1px) scale(.98);
}
.title-actions { position: relative; display: flex; align-items: center; gap: 8px; }
.hub-button { color: #17182f; background: #9ff5ed; border: 0; }
.hub-button.hidden { display: none; }

.game-shell { width: min(100% - 28px, 1060px); padding: 28px 0; }
body.title-active .game-shell,
body.map-active .game-shell { display: none; }
.game-shell:fullscreen,
.game-shell:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  padding: 14px;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle at 20% 10%, #28326d 0, transparent 35%),
    radial-gradient(circle at 90% 80%, #3b245f 0, transparent 32%),
    #090c1b;
}
.titlebar, .instructions { display: flex; justify-content: space-between; align-items: center; gap: 20px; }
.titlebar { position: relative; z-index: 20; margin-bottom: 14px; }
.game-shell:fullscreen .titlebar,
.game-shell:-webkit-full-screen .titlebar { flex: 0 0 auto; }
.titlebar h1 { margin: 0; font-size: clamp(1.65rem, 5vw, 2.7rem); letter-spacing: -.05em; }
.hud {
  display: flex;
  align-items: stretch;
  gap: 8px;
  margin-left: auto;
}
.hud-item {
  min-width: 112px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 12px;
  border: 1px solid rgba(255,255,255,.13);
  border-radius: 15px;
  background: rgba(8, 11, 30, .55);
  box-shadow: inset 0 1px rgba(255,255,255,.05);
}
.hud-item strong, .hud-item small { display: block; white-space: nowrap; }
.hud-item strong { font-size: .95rem; }
.hud-item small { margin-top: 1px; color: #9ea8d3; font-size: .65rem; font-weight: 750; text-transform: uppercase; letter-spacing: .08em; }
.hud-icon { font-size: 1.15rem; }
.star-icon { color: #ffe68b; text-shadow: 0 0 12px rgba(255,230,139,.7); }
.secret-icon { color: #d28cff; text-shadow: 0 0 12px rgba(210,140,255,.7); }
.time-item { min-width: 138px; }

.stage {
  position: relative;
  z-index: 1;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 24px;
  box-shadow: 0 28px 80px rgba(0,0,0,.45), inset 0 0 0 1px rgba(255,255,255,.04);
  background: #141a38;
}
.game-shell:fullscreen .stage,
.game-shell:-webkit-full-screen .stage {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
}

canvas { display: block; width: 100%; height: auto; aspect-ratio: 16 / 9; touch-action: none; }
.game-shell:fullscreen canvas,
.game-shell:-webkit-full-screen canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.corner-menu {
  position: relative;
  z-index: 30;
  display: grid;
  justify-items: end;
  gap: 8px;
}

.corner-menu-button {
  width: 42px;
  height: 42px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: rgba(7, 9, 24, .68);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .35), inset 0 1px rgba(255,255,255,.16);
  backdrop-filter: blur(10px);
}

.corner-menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 31;
  pointer-events: auto;
  display: grid;
  gap: 7px;
  min-width: 142px;
  padding: 9px;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 18px;
  background: rgba(7, 9, 24, .78);
  box-shadow: 0 18px 44px rgba(0, 0, 0, .42), inset 0 1px rgba(255,255,255,.08);
  backdrop-filter: blur(12px);
}

.corner-menu-panel.hidden { display: none; }
.menu-title {
  display: block;
  padding: 3px 7px 2px;
  color: #8dffe8;
  font-size: .75rem;
  font-weight: 900;
  letter-spacing: .16em;
  text-transform: uppercase;
}
.corner-menu-panel button {
  width: 100%;
  padding: .55rem .8rem;
  border-radius: 12px;
  text-align: left;
  background: rgba(255,255,255,.11);
}

.message {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
  padding: 24px;
  background: rgba(7, 9, 24, .78);
  backdrop-filter: blur(8px);
}
.message.hidden { display: none; }
.message h2 { margin: 0; font-size: clamp(2.2rem, 7vw, 4.5rem); letter-spacing: -.06em; }
.message p { max-width: 420px; color: #cdd2ff; line-height: 1.6; }
.message button { background: #7367f7; border: 0; padding-inline: 1.5rem; }

.ending-screen {
  position: absolute;
  inset: 0;
  z-index: 12;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  background:
    radial-gradient(circle at 50% 28%, rgba(141,255,232,.22), transparent 26%),
    radial-gradient(circle at 72% 70%, rgba(255,82,190,.2), transparent 30%),
    rgba(2, 3, 13, .88);
  backdrop-filter: blur(9px);
}
.ending-screen.hidden { display: none; }
.ending-card {
  width: min(94%, 680px);
  padding: clamp(24px, 5vw, 44px);
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 32px;
  background: linear-gradient(145deg, rgba(10,15,40,.92), rgba(48,21,72,.86));
  box-shadow: 0 30px 90px rgba(0,0,0,.48), inset 0 1px rgba(255,255,255,.1);
}
.ending-card h2 {
  margin: 0;
  font-size: clamp(2.7rem, 8vw, 5.7rem);
  line-height: .9;
  letter-spacing: -.075em;
  text-shadow: 0 0 36px rgba(141,255,232,.28);
}
.ending-stats {
  margin: 18px auto 0;
  max-width: 520px;
  color: #d8ddff;
  line-height: 1.55;
}
.credits-box {
  display: grid;
  gap: 6px;
  max-width: 430px;
  margin: 22px auto 0;
  padding: 16px;
  border: 1px solid rgba(255,255,255,.13);
  border-radius: 18px;
  color: #cdd2ff;
  background: rgba(255,255,255,.07);
}
.credits-box strong { color: #8dffe8; text-transform: uppercase; letter-spacing: .14em; font-size: .78rem; }
.ending-buttons {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 24px;
}
.ending-buttons button:first-child {
  color: #161a35;
  border: 0;
  background: linear-gradient(135deg, #8dffe8, #ffe287);
}

.title-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  background:
    radial-gradient(circle at 50% 35%, rgba(121, 255, 229, .18), transparent 28%),
    radial-gradient(circle at 70% 68%, rgba(255, 82, 190, .18), transparent 30%),
    rgba(3, 5, 18, .84);
  backdrop-filter: blur(8px);
}

.title-screen.hidden { display: none; }
.title-card {
  width: min(92%, 610px);
  padding: clamp(24px, 5vw, 42px);
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 30px;
  background: linear-gradient(145deg, rgba(13,18,45,.88), rgba(40,21,65,.82));
  box-shadow: 0 28px 80px rgba(0,0,0,.42), inset 0 1px rgba(255,255,255,.1);
}
.title-kicker {
  margin: 0 0 8px;
  color: #8dffe8;
  font-size: .78rem;
  font-weight: 900;
  letter-spacing: .18em;
  text-transform: uppercase;
}
.title-card h2 {
  margin: 0;
  font-size: clamp(3rem, 10vw, 6.2rem);
  line-height: .86;
  letter-spacing: -.08em;
  text-shadow: 0 0 34px rgba(141,255,232,.28);
}
.title-copy {
  max-width: 420px;
  margin: 20px auto 0;
  color: #d8ddff;
  line-height: 1.55;
}
.title-buttons {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 24px;
}
.title-buttons a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: .7rem 1.05rem;
  border-radius: 999px;
  color: #fff;
  font-weight: 900;
  text-decoration: none;
  background: rgba(255,255,255,.1);
}
.title-buttons button:first-child {
  color: #161a35;
  border: 0;
  background: linear-gradient(135deg, #8dffe8, #ffe287);
}
.title-buttons .title-fx-link {
  color: #161a35;
  border: 0;
  background: linear-gradient(135deg, #ff88bd, #8dffe8);
  box-shadow: 0 0 28px rgba(255,136,189,.28);
}
.title-hint {
  margin: 18px 0 0;
  color: #9ea8d3;
  font-size: .82rem;
}
.title-links {
  margin: 10px 0 0;
  font-size: .78rem;
}
.title-links a {
  color: #cfd5ff;
  text-decoration: none;
  opacity: .8;
}
.title-links a:hover { opacity: 1; text-decoration: underline; }

body.screenshot-mode .title-card {
  width: min(82vw, 980px);
  padding: clamp(42px, 5vw, 76px);
}

body.screenshot-mode .title-kicker {
  font-size: clamp(.95rem, 1vw, 1.25rem);
}

body.screenshot-mode .title-card h2 {
  font-size: clamp(5.6rem, 9vw, 9.8rem);
}

body.screenshot-mode .title-copy,
body.screenshot-mode .title-hint {
  font-size: clamp(1.05rem, 1.25vw, 1.35rem);
}

.map-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: block;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y;
  padding: 22px;
  background:
    radial-gradient(circle at 16% 18%, rgba(141,255,232,.14), transparent 28%),
    radial-gradient(circle at 84% 72%, rgba(255,82,190,.16), transparent 30%),
    linear-gradient(145deg, #050816, #15143a 52%, #2a143e);
}

.map-screen.hidden { display: none; }
.map-card {
  width: min(100%, 980px);
  min-height: min-content;
  margin: min(4vh, 34px) auto;
  overflow: visible;
  padding: clamp(18px, 4vw, 34px);
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 30px;
  background: linear-gradient(145deg, rgba(9,13,35,.9), rgba(39,22,63,.86));
  box-shadow: 0 30px 90px rgba(0,0,0,.45), inset 0 1px rgba(255,255,255,.1);
}

@media (max-width: 700px), (max-height: 520px) and (orientation: landscape) {
  .map-screen {
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  }
  .map-card {
    width: 100%;
    margin: 0 auto;
    padding: 12px;
    border-radius: 20px;
  }
  .map-heading {
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
  }
  .map-heading h2 {
    font-size: clamp(1.45rem, 8vw, 2.2rem);
    letter-spacing: -.04em;
  }
  .map-heading .title-kicker,
  .map-actions p,
  .level-node small {
    display: none;
  }
  .level-map-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
  }
  .level-node {
    min-height: 0;
    padding: 10px 9px;
    border-radius: 14px;
  }
  .level-node strong {
    margin: 0;
    font-size: .82rem;
    line-height: 1.05;
  }
  .map-actions {
    margin-top: 10px;
    gap: 8px;
  }
  .map-actions button,
  #mapBackButton {
    padding: .52rem .82rem;
    font-size: .82rem;
  }
}

/* Final iPhone landscape layout: gameplay fills the screen, controls float on top. */
@media (orientation: landscape) {
  html,
  body.touch-device {
    width: 100%;
    height: var(--app-height, 100vh);
    height: 100dvh;
    min-height: var(--app-height, 100vh);
    min-height: 100dvh;
    overflow: hidden !important;
  }

  body.touch-device:not(.title-active):not(.map-active) {
    background: #090c1b !important;
    overscroll-behavior: none;
  }

  body.touch-device .camera-fx-corner-button {
    display: none !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .game-shell {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: var(--app-height, 100vh) !important;
    height: 100dvh !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
    overflow: hidden !important;
    background: #090c1b !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .stage {
    position: fixed !important;
    inset: 0 !important;
    z-index: 1 !important;
    width: 100vw !important;
    height: var(--app-height, 100vh) !important;
    height: 100dvh !important;
    max-width: none !important;
    max-height: none !important;
    margin: 0 !important;
    display: grid !important;
    place-items: center !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    background: #10152d !important;
    overflow: hidden !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .stage canvas#game {
    position: static !important;
    display: block !important;
    width: min(100vw, calc(var(--app-height, 100vh) * 16 / 9)) !important;
    width: min(100vw, calc(100dvh * 16 / 9)) !important;
    height: min(var(--app-height, 100vh), calc(100vw * 9 / 16)) !important;
    height: min(100dvh, calc(100vw * 9 / 16)) !important;
    max-width: none !important;
    max-height: none !important;
    transform: none !important;
    object-fit: contain !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .titlebar {
    position: fixed !important;
    top: max(4px, env(safe-area-inset-top)) !important;
    left: max(8px, env(safe-area-inset-left)) !important;
    right: max(8px, env(safe-area-inset-right)) !important;
    z-index: 70 !important;
    height: 34px !important;
    margin: 0 !important;
    display: flex !important;
    align-items: center !important;
    gap: 6px !important;
    pointer-events: none !important;
    background: transparent !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .brand,
  body.touch-device:not(.title-active):not(.map-active) #restartButton,
  body.touch-device:not(.title-active):not(.map-active) .time-item,
  body.touch-device:not(.title-active):not(.map-active) .instructions {
    display: none !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .hud,
  body.touch-device:not(.title-active):not(.map-active) .title-actions {
    pointer-events: auto !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .hud {
    width: auto !important;
    flex: 1 1 auto !important;
    margin: 0 !important;
    gap: 6px !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .hud-item {
    min-width: 0 !important;
    min-height: 30px !important;
    padding: 3px 8px !important;
    border-radius: 14px !important;
    background: rgba(8, 11, 30, .42) !important;
    border-color: rgba(255,255,255,.14) !important;
    box-shadow: 0 10px 28px rgba(0,0,0,.22) !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .hud-item small {
    display: none !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .menu-button {
    width: 34px !important;
    height: 34px !important;
    min-width: 34px !important;
    border-radius: 12px !important;
    background: rgba(8, 11, 30, .42) !important;
  }

  body.touch-device .touch-controls,
  body.touch-device .action-controls {
    z-index: 80 !important;
    pointer-events: auto !important;
  }

  body.touch-device .touch-controls {
    left: calc(10px + env(safe-area-inset-left)) !important;
    bottom: calc(8px + env(safe-area-inset-bottom)) !important;
    gap: 5px !important;
    grid-template-columns: repeat(3, 54px) !important;
    grid-template-rows: repeat(2, 48px) !important;
  }

  body.touch-device .action-controls {
    right: calc(10px + env(safe-area-inset-right)) !important;
    bottom: calc(10px + env(safe-area-inset-bottom)) !important;
    gap: 6px !important;
  }

  body.touch-device .touch-controls button,
  body.touch-device .action-controls button {
    background:
      radial-gradient(circle at 42% 22%, rgba(255,255,255,.18), transparent 36%),
      rgba(8, 11, 30, .24) !important;
    border-color: rgba(255,255,255,.14) !important;
    box-shadow: 0 12px 28px rgba(0,0,0,.22), inset 0 1px rgba(255,255,255,.12) !important;
    opacity: .58 !important;
    backdrop-filter: blur(7px) !important;
    -webkit-backdrop-filter: blur(7px) !important;
  }

  body.touch-device .touch-controls button:active,
  body.touch-device .action-controls button:active {
    opacity: .82 !important;
  }
}

.map-heading {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 18px;
  margin-bottom: 20px;
}
.map-heading h2 {
  margin: 0;
  font-size: clamp(2.4rem, 7vw, 5rem);
  line-height: .88;
  letter-spacing: -.07em;
}

.level-map-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}

.level-node {
  min-height: 116px;
  padding: 14px;
  border-radius: 20px;
  text-align: left;
  border: 1px solid rgba(255,255,255,.16);
  background:
    radial-gradient(circle at 20% 10%, rgba(255,255,255,.2), transparent 28%),
    linear-gradient(145deg, rgba(255,255,255,.13), rgba(255,255,255,.045));
  box-shadow: inset 0 1px rgba(255,255,255,.08), 0 12px 30px rgba(0,0,0,.22);
}
.level-node:hover { transform: translateY(-2px); }
.level-node strong {
  display: block;
  margin-bottom: 7px;
  font-size: 1.05rem;
}
.level-node small {
  display: block;
  color: #c5caff;
  font-weight: 700;
  line-height: 1.35;
  white-space: normal;
}
.level-node.is-3d { border-color: rgba(141,255,232,.34); box-shadow: inset 0 1px rgba(255,255,255,.08), 0 0 24px rgba(141,255,232,.08); }
.level-node.is-hard { border-color: rgba(255,119,184,.38); box-shadow: inset 0 1px rgba(255,255,255,.08), 0 0 24px rgba(255,119,184,.1); }

.map-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 20px;
  color: #aeb5dc;
}
.map-actions button {
  color: #161a35;
  border: 0;
  background: linear-gradient(135deg, #8dffe8, #ffe287);
}

.instructions { color: #aeb5dc; padding: 14px 4px 0; font-size: .9rem; }
kbd { color: #fff; font: inherit; font-weight: 800; }
.touch-controls,
.action-controls {
  display: none;
  -webkit-user-select: none;
  user-select: none;
}
.action-controls[hidden],
.action-controls button[hidden],
.touch-controls button[hidden] {
  display: none !important;
}
.touch-controls {
  grid-template-columns: repeat(3, clamp(54px, 14vw, 68px));
  grid-template-rows: repeat(2, clamp(48px, 12vw, 60px));
  gap: clamp(7px, 2vw, 10px);
}
.action-controls {
  grid-template-columns: repeat(2, clamp(76px, 19vw, 96px));
  grid-template-rows: repeat(2, clamp(48px, 12vw, 60px));
  gap: clamp(8px, 2vw, 12px);
}
.action-controls[data-action-count="1"] {
  grid-template-columns: clamp(82px, 20vw, 104px);
  grid-template-rows: clamp(52px, 12vw, 64px);
}
.action-controls[data-action-count="2"] {
  grid-template-columns: repeat(2, clamp(72px, 17vw, 92px));
  grid-template-rows: clamp(52px, 12vw, 64px);
}
body.touch-device .touch-controls,
body.touch-device .action-controls {
  position: fixed;
  z-index: 26;
  bottom: calc(14px + env(safe-area-inset-bottom));
  display: grid;
  margin: 0;
}
body.title-active .touch-controls,
body.title-active .action-controls,
body.map-active .touch-controls,
body.map-active .action-controls,
body.ending-active .touch-controls,
body.ending-active .action-controls {
  display: none !important;
  pointer-events: none !important;
}
body.touch-device .touch-controls {
  left: max(10px, env(safe-area-inset-left));
  padding-left: clamp(0px, 2vw, 12px);
}
body.touch-device .action-controls {
  right: max(10px, env(safe-area-inset-right));
  padding-right: clamp(0px, 2vw, 12px);
}
body.keyboard-device .touch-controls,
body.keyboard-device .action-controls { display: none; }
.touch-controls button,
.action-controls button {
  min-width: 0;
  min-height: 0;
  border-radius: 18px;
  padding: 0;
  color: #f9fbff;
  background:
    radial-gradient(circle at 30% 18%, rgba(255,255,255,.28), transparent 38%),
    rgba(8, 11, 30, .72);
  border: 1px solid rgba(255, 255, 255, .2);
  box-shadow:
    0 12px 28px rgba(0,0,0,.36),
    inset 0 1px rgba(255,255,255,.16);
  backdrop-filter: blur(12px);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: none;
}
.touch-controls button { font-size: clamp(1.05rem, 4vw, 1.35rem); }
.action-controls button {
  padding: 0 .55rem;
  font-size: clamp(.76rem, 2.8vw, .92rem);
  letter-spacing: .01em;
}
.touch-controls button:active,
.action-controls button:active {
  transform: translateY(2px) scale(.96);
  background:
    radial-gradient(circle at 30% 18%, rgba(255,255,255,.32), transparent 38%),
    rgba(51, 65, 130, .78);
}
.action-controls [data-action="jump"] { color: #151936; background: linear-gradient(135deg, #8dffe8, #ffe287); }
.action-controls [data-action="blink"] { background: rgba(185, 119, 255, .24); }
.action-controls [data-action="dash"] { background: rgba(255, 136, 189, .22); }
.action-controls [data-action="down"] { background: rgba(141, 177, 255, .2); }
.touch-controls [data-direction="up"] { grid-column: 2; }
.touch-controls [data-direction="left"] { grid-column: 1; grid-row: 2; }
.touch-controls [data-direction="down"] { grid-column: 2; grid-row: 2; }
.touch-controls [data-direction="right"] { grid-column: 3; grid-row: 2; }
body[data-direction-count="2"] .touch-controls {
  grid-template-columns: repeat(2, clamp(58px, 15vw, 72px));
  grid-template-rows: clamp(52px, 12vw, 64px);
}
body[data-direction-count="2"] .touch-controls [data-direction="left"] {
  grid-column: 1;
  grid-row: 1;
}
body[data-direction-count="2"] .touch-controls [data-direction="right"] {
  grid-column: 2;
  grid-row: 1;
}
body.touch-device .game-shell { padding-bottom: calc(150px + env(safe-area-inset-bottom)); }
body.touch-device .game-shell:fullscreen,
body.touch-device .game-shell:-webkit-full-screen {
  padding: 12px 10px calc(116px + env(safe-area-inset-bottom));
}

@media (max-width: 950px) {
  .titlebar { flex-wrap: wrap; }
  .brand { flex: 1; min-width: 0; }
  .title-actions { margin-left: auto; }
  .hud { order: 3; width: 100%; }
  .hud-item { flex: 1; justify-content: center; }
}

@media (max-width: 700px) {
  body.touch-device {
    display: block;
  }
  .camera-fx-corner-button {
    top: calc(62px + env(safe-area-inset-top));
    left: calc(8px + env(safe-area-inset-left));
    max-width: 190px;
    padding: .34rem .55rem;
    font-size: .62rem;
  }
  .game-shell {
    width: min(100% - 14px, 1060px);
    margin: 0 auto;
    padding-top: 10px;
  }
  .titlebar { flex-wrap: wrap; }
  .brand { flex: 1; }
  .title-actions { margin-left: auto; }
  .hud { order: 3; width: 100%; }
  .hud-item { flex: 1; min-width: 0; justify-content: center; padding-inline: 7px; }
  .stage { border-radius: 18px; }
  .time-item { display: none; }
  .instructions { justify-content: center; text-align: center; padding-top: 10px; }
  body.touch-device .instructions span:first-child { display: none; }
  body.keyboard-device .instructions span:first-child { display: inline; }
}

@media (max-width: 560px) {
  body.touch-device .touch-controls {
    left: max(6px, env(safe-area-inset-left));
  }
  body.touch-device .action-controls {
    right: max(6px, env(safe-area-inset-right));
  }
}

@media (orientation: portrait) and (max-width: 760px) {
  html,
  body.touch-device {
    width: 100%;
    min-height: var(--app-height, 100vh);
    min-height: var(--app-height, 100dvh);
    overflow: hidden;
  }

  body.touch-device {
    display: block;
  }

  body.touch-device .camera-fx-corner-button {
    top: calc(10px + env(safe-area-inset-top));
    left: calc(10px + env(safe-area-inset-left));
    max-width: 148px;
    padding: .34rem .52rem;
    font-size: .56rem;
    opacity: .86;
  }

  body.touch-device .game-shell {
    width: 100vw;
    max-width: none;
    height: var(--app-height, 100vh);
    height: var(--app-height, 100dvh);
    margin: 0;
    padding:
      calc(42px + env(safe-area-inset-top))
      max(10px, env(safe-area-inset-right))
      calc(108px + env(safe-area-inset-bottom))
      max(10px, env(safe-area-inset-left));
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    gap: 8px;
    overflow: hidden;
  }

  body.touch-device .titlebar {
    flex: 0 0 auto;
    flex-wrap: nowrap;
    align-items: center;
    gap: 7px;
    margin: 0;
  }

  body.touch-device .brand,
  body.touch-device #restartButton,
  body.touch-device .time-item,
  body.touch-device .instructions {
    display: none;
  }

  body.touch-device .hud {
    order: 0;
    width: auto;
    flex: 1 1 auto;
    min-width: 0;
    margin-left: 0;
    gap: 6px;
  }

  body.touch-device .hud-item {
    min-width: 0;
    flex: 1 1 0;
    justify-content: center;
    gap: 5px;
    padding: 6px 7px;
    border-radius: 13px;
  }

  body.touch-device .hud-item strong {
    font-size: .78rem;
  }

  body.touch-device .hud-item small {
    display: none;
  }

  body.touch-device .corner-menu-button {
    width: 38px;
    height: 38px;
    border-radius: 13px;
  }

  body.touch-device .corner-menu-panel {
    right: 0;
    max-width: calc(100vw - 20px);
  }

  body.touch-device .stage {
    flex: 0 0 auto;
    width: 100%;
    display: grid;
    place-items: center;
    border-radius: 18px;
    box-shadow: 0 18px 50px rgba(0,0,0,.42), inset 0 0 0 1px rgba(255,255,255,.04);
  }

  body.touch-device canvas {
    width: min(100%, calc((var(--app-height, 100vh) - 206px) * 16 / 9));
    height: auto;
    max-height: calc(var(--app-height, 100vh) - 206px);
    object-fit: contain;
  }

  body.touch-device .game-shell::after {
    content: "Rotate sideways for the best view";
    position: fixed;
    left: 50%;
    bottom: calc(74px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    z-index: 22;
    padding: .42rem .72rem;
    border: 1px solid rgba(255,255,255,.14);
    border-radius: 999px;
    color: rgba(248,245,255,.82);
    background: rgba(7, 9, 24, .56);
    box-shadow: 0 10px 26px rgba(0,0,0,.22);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    font-size: .72rem;
    font-weight: 850;
    white-space: nowrap;
    pointer-events: none;
  }

  body.touch-device .touch-controls {
    grid-template-columns: repeat(2, clamp(54px, 17vw, 68px));
    grid-template-rows: clamp(48px, 12vw, 58px);
    left: max(12px, env(safe-area-inset-left));
    bottom: calc(14px + env(safe-area-inset-bottom));
    gap: 8px;
  }

  body.touch-device .touch-controls [data-direction="left"] {
    grid-column: 1;
    grid-row: 1;
  }

  body.touch-device .touch-controls [data-direction="right"] {
    grid-column: 2;
    grid-row: 1;
  }

  body.touch-device .action-controls {
    right: max(12px, env(safe-area-inset-right));
    bottom: calc(14px + env(safe-area-inset-bottom));
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  body.touch-device .camera-fx-corner-button {
    display: none !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .game-shell {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: var(--app-height, 100vh) !important;
    height: var(--app-height, 100dvh) !important;
    max-width: none !important;
    margin: 0 !important;
    padding:
      max(2px, env(safe-area-inset-top))
      max(4px, env(safe-area-inset-right))
      max(4px, env(safe-area-inset-bottom))
      max(4px, env(safe-area-inset-left)) !important;
    display: grid !important;
    grid-template-rows: 32px minmax(0, 1fr) !important;
    gap: 2px !important;
    overflow: hidden !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .stage {
    width: 100% !important;
    height: 100% !important;
    max-height: none !important;
    min-height: 0 !important;
    align-self: stretch !important;
    justify-self: stretch !important;
    border-radius: 10px !important;
    overflow: hidden !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .stage canvas#game {
    width: 100% !important;
    height: 100% !important;
    max-width: none !important;
    max-height: none !important;
    object-fit: fill !important;
  }

  body.touch-device .touch-controls,
  body.touch-device .action-controls {
    z-index: 60 !important;
    bottom: calc(10px + env(safe-area-inset-bottom)) !important;
  }

  body.touch-device .touch-controls button,
  body.touch-device .action-controls button {
    background: rgba(8, 11, 30, .34) !important;
    border-color: rgba(255, 255, 255, .16) !important;
    box-shadow:
      0 8px 20px rgba(0,0,0,.24),
      inset 0 1px rgba(255,255,255,.1) !important;
    opacity: .62 !important;
    backdrop-filter: blur(8px) !important;
    -webkit-backdrop-filter: blur(8px) !important;
  }

  body.touch-device .touch-controls button:active,
  body.touch-device .action-controls button:active {
    opacity: .86 !important;
    background: rgba(51, 65, 130, .46) !important;
  }
}

@media (orientation: landscape) {
  body.touch-device .camera-fx-corner-button {
    display: none !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .game-shell {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: var(--app-height, 100vh) !important;
    height: var(--app-height, 100dvh) !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    display: block !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .stage {
    position: fixed !important;
    inset: 0 !important;
    z-index: 1 !important;
    width: 100vw !important;
    height: var(--app-height, 100vh) !important;
    height: var(--app-height, 100dvh) !important;
    min-height: 0 !important;
    max-height: none !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    overflow: hidden !important;
    display: block !important;
    background: #10152d !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .stage canvas#game {
    position: absolute !important;
    inset: 0 !important;
    width: 100vw !important;
    height: var(--app-height, 100vh) !important;
    height: var(--app-height, 100dvh) !important;
    max-width: none !important;
    max-height: none !important;
    object-fit: fill !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .titlebar {
    position: fixed !important;
    top: max(4px, env(safe-area-inset-top)) !important;
    left: max(8px, env(safe-area-inset-left)) !important;
    right: max(8px, env(safe-area-inset-right)) !important;
    z-index: 70 !important;
    height: 34px !important;
    min-height: 34px !important;
    margin: 0 !important;
    display: flex !important;
    align-items: center !important;
    gap: 6px !important;
    pointer-events: none !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .hud,
  body.touch-device:not(.title-active):not(.map-active) .title-actions {
    pointer-events: auto !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .hud-item {
    background: rgba(8, 11, 30, .46) !important;
    backdrop-filter: blur(8px) !important;
    -webkit-backdrop-filter: blur(8px) !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .instructions {
    display: none !important;
  }

  body.touch-device .touch-controls,
  body.touch-device .action-controls {
    z-index: 80 !important;
    bottom: calc(12px + env(safe-area-inset-bottom)) !important;
  }

  body.touch-device .touch-controls button,
  body.touch-device .action-controls button {
    background: rgba(8, 11, 30, .26) !important;
    border-color: rgba(255, 255, 255, .14) !important;
    opacity: .54 !important;
    box-shadow: 0 8px 18px rgba(0,0,0,.2), inset 0 1px rgba(255,255,255,.08) !important;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  body.touch-device .camera-fx-corner-button {
    display: none !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .game-shell {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: var(--app-height, 100vh) !important;
    height: var(--app-height, 100dvh) !important;
    max-width: none !important;
    margin: 0 !important;
    padding:
      max(4px, env(safe-area-inset-top))
      max(8px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom))
      max(8px, env(safe-area-inset-left)) !important;
    display: grid !important;
    grid-template-rows: 34px minmax(0, 1fr) !important;
    gap: 4px !important;
    overflow: hidden !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .titlebar {
    height: 34px !important;
    min-height: 34px !important;
    margin: 0 !important;
    z-index: 35 !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .hud {
    width: auto !important;
    gap: 6px !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .stage {
    width: 100% !important;
    height: 100% !important;
    max-height: none !important;
    min-height: 0 !important;
    align-self: stretch !important;
    justify-self: stretch !important;
    aspect-ratio: auto !important;
    border-radius: 14px !important;
    overflow: hidden !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .stage canvas#game {
    width: 100% !important;
    height: 100% !important;
    max-width: none !important;
    max-height: none !important;
    object-fit: fill !important;
  }

  body.touch-device .touch-controls,
  body.touch-device .action-controls {
    z-index: 45 !important;
    bottom: calc(12px + env(safe-area-inset-bottom)) !important;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  html,
  body.touch-device {
    width: 100%;
    height: var(--app-height, 100vh);
    height: var(--app-height, 100dvh);
    min-height: var(--app-height, 100vh);
    min-height: var(--app-height, 100dvh);
    overflow: hidden !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .game-shell {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    max-width: none !important;
    height: var(--app-height, 100vh) !important;
    height: var(--app-height, 100dvh) !important;
    margin: 0 !important;
    padding:
      max(4px, env(safe-area-inset-top))
      max(14px, env(safe-area-inset-right))
      calc(104px + env(safe-area-inset-bottom))
      max(14px, env(safe-area-inset-left)) !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .titlebar {
    flex: 0 0 auto !important;
    height: 34px !important;
    min-height: 34px !important;
    margin: 0 0 4px !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .hud-item {
    padding: 4px 7px !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .corner-menu-button {
    width: 34px !important;
    height: 34px !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .stage {
    flex: 0 0 auto !important;
    min-height: 0 !important;
    width: min(
      100%,
      calc((var(--app-height, 100vh) - 146px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * 16 / 9)
    ) !important;
    height: auto !important;
    aspect-ratio: 16 / 9 !important;
    max-height: calc(var(--app-height, 100vh) - 146px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) !important;
    display: grid !important;
    place-items: center !important;
    align-self: center !important;
    overflow: hidden !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .stage canvas#game {
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    aspect-ratio: 16 / 9 !important;
    object-fit: contain !important;
  }

  body.touch-device .touch-controls,
  body.touch-device .action-controls {
    bottom: calc(22px + env(safe-area-inset-bottom)) !important;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  html,
  body.touch-device {
    width: 100%;
    height: var(--app-height, 100vh);
    height: var(--app-height, 100dvh);
    min-height: var(--app-height, 100vh);
    min-height: var(--app-height, 100dvh);
    overflow: hidden;
  }

  body.touch-device:not(.title-active):not(.map-active) .game-shell {
    position: fixed;
    inset: 0;
    width: 100vw;
    max-width: none;
    height: var(--app-height, 100vh);
    height: var(--app-height, 100dvh);
    margin: 0;
    padding:
      max(5px, env(safe-area-inset-top))
      max(12px, env(safe-area-inset-right))
      calc(92px + env(safe-area-inset-bottom))
      max(12px, env(safe-area-inset-left));
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  body.touch-device:not(.title-active):not(.map-active) .titlebar {
    flex: 0 0 auto;
    margin-bottom: 5px;
  }

  body.touch-device:not(.title-active):not(.map-active) .stage {
    flex: 1 1 auto;
    min-height: 0;
    max-height: calc(var(--app-height, 100vh) - 138px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    align-self: center;
    width: 100%;
  }

  body.touch-device:not(.title-active):not(.map-active) canvas {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }

  body.touch-device .touch-controls,
  body.touch-device .action-controls {
    bottom: calc(18px + env(safe-area-inset-bottom));
  }
}

@media (orientation: portrait) and (max-width: 760px) and (max-height: 720px) {
  body.touch-device .camera-fx-corner-button {
    max-width: 128px;
    padding: .28rem .46rem;
    font-size: .5rem;
  }

  body.touch-device .game-shell {
    padding-top: calc(36px + env(safe-area-inset-top));
    padding-bottom: calc(96px + env(safe-area-inset-bottom));
    gap: 6px;
  }

  body.touch-device .hud-item {
    padding: 5px 6px;
  }

  body.touch-device .hud-item strong {
    font-size: .7rem;
  }

  body.touch-device .corner-menu-button {
    width: 34px;
    height: 34px;
  }

  body.touch-device canvas {
    width: min(100%, calc((var(--app-height, 100vh) - 184px) * 16 / 9));
    max-height: calc(var(--app-height, 100vh) - 184px);
  }

  body.touch-device .game-shell::after {
    display: none;
  }

  body.touch-device .touch-controls,
  body.touch-device .action-controls {
    bottom: calc(10px + env(safe-area-inset-bottom));
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  html,
  body.touch-device {
    width: 100%;
    min-height: var(--app-height, 100vh);
    min-height: var(--app-height, 100dvh);
    overflow: hidden;
  }
  body.touch-device.map-active,
  body.touch-device.title-active {
    overflow: auto;
  }
  body.touch-device.map-active .map-screen {
    overflow: auto;
    touch-action: pan-x pan-y;
  }

  body.touch-device {
    display: block;
  }

  .camera-fx-corner-button {
    top: calc(48px + env(safe-area-inset-top));
    left: calc(8px + env(safe-area-inset-left));
    max-width: 170px;
    padding: .3rem .48rem;
    font-size: .58rem;
  }

  body.touch-device .game-shell {
    width: 100vw;
    max-width: none;
    height: var(--app-height, 100vh);
    height: var(--app-height, 100dvh);
    margin: 0;
    padding:
      max(6px, env(safe-area-inset-top))
      max(8px, env(safe-area-inset-right))
      calc(78px + env(safe-area-inset-bottom))
      max(8px, env(safe-area-inset-left));
    display: flex;
    flex-direction: column;
  }

  body.touch-device .titlebar {
    flex: 0 0 auto;
    flex-wrap: nowrap;
    gap: 8px;
    margin-bottom: 6px;
  }

  body.touch-device .brand,
  body.touch-device #restartButton {
    display: none;
  }

  body.touch-device .hud {
    order: 0;
    width: auto;
    flex: 1 1 auto;
    min-width: 0;
    margin-left: 0;
    gap: 6px;
  }

  body.touch-device .hud-item {
    min-width: 0;
    padding: 5px 7px;
    border-radius: 12px;
    gap: 5px;
  }

  body.touch-device .hud-item strong {
    font-size: .74rem;
  }

  body.touch-device .hud-item small,
  body.touch-device .time-item {
    display: none;
  }

  body.touch-device .corner-menu-button {
    width: 36px;
    height: 36px;
    border-radius: 12px;
  }

  body.touch-device .stage {
    flex: 1 1 auto;
    min-height: 0;
    display: grid;
    place-items: center;
    border-radius: 14px;
  }

  body.touch-device canvas {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }

  body.touch-device .game-shell:fullscreen,
  body.touch-device .game-shell:-webkit-full-screen {
    padding:
      max(6px, env(safe-area-inset-top))
      max(8px, env(safe-area-inset-right))
      calc(68px + env(safe-area-inset-bottom))
      max(8px, env(safe-area-inset-left));
  }
  .touch-controls {
    grid-template-columns: repeat(3, clamp(44px, 10vw, 56px));
    grid-template-rows: repeat(2, clamp(38px, 9vw, 48px));
    gap: 6px;
  }
  .action-controls {
    grid-template-columns: repeat(2, clamp(62px, 14vw, 78px));
    grid-template-rows: repeat(2, clamp(38px, 9vw, 48px));
    gap: 7px;
  }
  .action-controls[data-action-count="1"] {
    grid-template-columns: clamp(64px, 15vw, 82px);
    grid-template-rows: clamp(40px, 9vw, 50px);
  }
  .action-controls[data-action-count="2"] {
    grid-template-columns: repeat(2, clamp(60px, 14vw, 78px));
    grid-template-rows: clamp(40px, 9vw, 50px);
  }
  .instructions { display: none; }
}

@media (max-width: 700px) {
  .game-shell:fullscreen .brand,
  .game-shell:-webkit-full-screen .brand,
  .game-shell:fullscreen #restartButton,
  .game-shell:-webkit-full-screen #restartButton {
    display: none;
  }
  .game-shell:fullscreen .hud,
  .game-shell:-webkit-full-screen .hud {
    order: 0;
    width: auto;
    margin-left: 0;
  }
}

@media (orientation: portrait) and (max-width: 760px) {
  html,
  body.touch-device {
    width: 100%;
    height: var(--app-height, 100vh);
    height: var(--app-height, 100dvh);
    min-height: var(--app-height, 100vh);
    min-height: var(--app-height, 100dvh);
    overflow: hidden;
  }

  body.touch-device:not(.title-active):not(.map-active) .game-shell,
  body.touch-device:not(.title-active):not(.map-active) .touch-controls,
  body.touch-device:not(.title-active):not(.map-active) .action-controls,
  body.touch-device:not(.title-active):not(.map-active) .camera-fx-corner-button {
    display: none !important;
  }

  body.touch-device:not(.title-active):not(.map-active)::after {
    content: "Rotate your iPhone sideways to play Moonlight Run";
    position: fixed;
    inset:
      max(16px, env(safe-area-inset-top))
      max(16px, env(safe-area-inset-right))
      max(16px, env(safe-area-inset-bottom))
      max(16px, env(safe-area-inset-left));
    z-index: 200;
    display: grid;
    place-items: center;
    padding: 28px;
    border: 1px solid rgba(255,255,255,.16);
    border-radius: 30px;
    color: #f8f5ff;
    background:
      radial-gradient(circle at 50% 28%, rgba(255,230,139,.22), transparent 30%),
      radial-gradient(circle at 66% 72%, rgba(141,255,232,.14), transparent 32%),
      linear-gradient(145deg, rgba(9,13,35,.96), rgba(39,22,63,.94));
    box-shadow: 0 28px 80px rgba(0,0,0,.45), inset 0 1px rgba(255,255,255,.1);
    text-align: center;
    font-size: clamp(1.45rem, 8vw, 2.45rem);
    font-weight: 950;
    line-height: 1.08;
    letter-spacing: -.04em;
  }
}

/* True final iPhone landscape override: no corner anchoring, no boxed playfield. */
@media (orientation: landscape) {
  html,
  body.touch-device {
    width: 100%;
    height: var(--app-height, 100vh);
    height: 100dvh;
    min-height: var(--app-height, 100vh);
    min-height: 100dvh;
    overflow: hidden !important;
  }

  body.touch-device .camera-fx-corner-button {
    display: none !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .game-shell {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: var(--app-height, 100vh) !important;
    height: 100dvh !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
    overflow: hidden !important;
    background: #090c1b !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .stage {
    position: fixed !important;
    inset: 0 !important;
    z-index: 1 !important;
    width: 100vw !important;
    height: var(--app-height, 100vh) !important;
    height: 100dvh !important;
    max-width: none !important;
    max-height: none !important;
    margin: 0 !important;
    display: grid !important;
    place-items: center !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    background: #10152d !important;
    overflow: hidden !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .stage canvas#game {
    position: static !important;
    display: block !important;
    width: min(100vw, calc(var(--app-height, 100vh) * 16 / 9)) !important;
    width: min(100vw, calc(100dvh * 16 / 9)) !important;
    height: min(var(--app-height, 100vh), calc(100vw * 9 / 16)) !important;
    height: min(100dvh, calc(100vw * 9 / 16)) !important;
    max-width: none !important;
    max-height: none !important;
    transform: none !important;
    object-fit: contain !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .titlebar {
    position: fixed !important;
    top: max(4px, env(safe-area-inset-top)) !important;
    left: max(8px, env(safe-area-inset-left)) !important;
    right: max(8px, env(safe-area-inset-right)) !important;
    z-index: 70 !important;
    height: 34px !important;
    margin: 0 !important;
    display: flex !important;
    align-items: center !important;
    gap: 6px !important;
    pointer-events: none !important;
    background: transparent !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .brand,
  body.touch-device:not(.title-active):not(.map-active) #restartButton,
  body.touch-device:not(.title-active):not(.map-active) .time-item,
  body.touch-device:not(.title-active):not(.map-active) .instructions {
    display: none !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .hud,
  body.touch-device:not(.title-active):not(.map-active) .title-actions {
    pointer-events: auto !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .hud {
    width: auto !important;
    flex: 1 1 auto !important;
    margin: 0 !important;
    gap: 6px !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .hud-item {
    min-width: 0 !important;
    min-height: 30px !important;
    padding: 3px 8px !important;
    border-radius: 14px !important;
    background: rgba(8, 11, 30, .42) !important;
    border-color: rgba(255,255,255,.14) !important;
    box-shadow: 0 10px 28px rgba(0,0,0,.22) !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .hud-item small {
    display: none !important;
  }

  body.touch-device:not(.title-active):not(.map-active) .menu-button {
    width: 34px !important;
    height: 34px !important;
    min-width: 34px !important;
    border-radius: 12px !important;
    background: rgba(8, 11, 30, .42) !important;
  }

  body.touch-device .touch-controls,
  body.touch-device .action-controls {
    z-index: 80 !important;
    pointer-events: auto !important;
  }

  body.touch-device .touch-controls {
    left: calc(10px + env(safe-area-inset-left)) !important;
    bottom: calc(8px + env(safe-area-inset-bottom)) !important;
    gap: 5px !important;
    grid-template-columns: repeat(3, 54px) !important;
    grid-template-rows: repeat(2, 48px) !important;
  }

  body.touch-device .action-controls {
    right: calc(10px + env(safe-area-inset-right)) !important;
    bottom: calc(10px + env(safe-area-inset-bottom)) !important;
    gap: 6px !important;
  }

  body.touch-device .touch-controls button,
  body.touch-device .action-controls button {
    background:
      radial-gradient(circle at 42% 22%, rgba(255,255,255,.18), transparent 36%),
      rgba(8, 11, 30, .24) !important;
    border-color: rgba(255,255,255,.14) !important;
    box-shadow: 0 12px 28px rgba(0,0,0,.22), inset 0 1px rgba(255,255,255,.12) !important;
    opacity: .58 !important;
    backdrop-filter: blur(7px) !important;
    -webkit-backdrop-filter: blur(7px) !important;
  }

  body.touch-device .touch-controls button:active,
  body.touch-device .action-controls button:active {
    opacity: .82 !important;
  }
}
