@font-face {
  font-family: "Emerald Dialogue";
  src: url("./public/assets/ui/emerald-dialogue.woff2?v=20260903.1") format("woff2");
  font-display: block;
  font-style: normal;
  font-weight: 400;
}

:root {
  color-scheme: light;
  font-family: var(--hoenn-font-family);
  background: #f8f8f8;
  color: var(--hoenn-color-on-surface-paper);
  font-synthesis: none;
  text-rendering: optimizeSpeed;

  /* Keep the source glyph geometry, but render chrome above the native 16px
     cell so its one-pixel strokes hold up beside the enlarged game canvas. */
  --font-size-caption: 24px;
  --font-size-ui: 24px;
  --font-size-title: 24px;
  --font-size-heading: 32px;
  --font-size-glyph: 16px;
  --letter-spacing-label: 0;
  --dialogue-frame: url("./public/assets/ui/emerald-dialogue-frame.png?v=20260903.1");

  /* Compatibility aliases for product CSS that is migrating to the reusable
     Hoenn design-system package. Core recreation colors remain in canvas
     renderers and exported assets rather than inheriting these tokens. */
  --product-shell: var(--hoenn-color-paper);
  --product-panel: var(--hoenn-color-panel);
  --product-control: var(--hoenn-color-silver);
  --product-control-active: var(--hoenn-color-lime);
  --product-control-edge: var(--hoenn-color-silver-edge);
  --product-cream: var(--hoenn-color-paper);
  --product-paper: var(--hoenn-color-paper-muted);
  --product-paper-raised: var(--hoenn-color-paper);
  --product-paper-edge: var(--hoenn-color-paper-edge);
  --product-ink: var(--hoenn-color-ink);
  --product-muted: var(--hoenn-color-muted);
  --product-emerald: var(--hoenn-color-emerald);
  --product-emerald-bright: var(--hoenn-color-emerald-bright);
  --product-emerald-dark: var(--hoenn-color-emerald-shadow);
  --product-emerald-soft: var(--hoenn-color-emerald-soft);
  --product-coral: var(--hoenn-color-ruby-bright);
  --product-sapphire: var(--hoenn-color-sapphire);
  --product-sapphire-bright: var(--hoenn-color-sapphire-bright);
  --product-ruby: var(--hoenn-color-ruby);
  --product-orange: var(--hoenn-color-orange);
  --product-lime: var(--hoenn-color-lime);
  --product-sun: var(--hoenn-color-sun);
  --product-shadow: var(--hoenn-color-emerald-shadow);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: #f8f8f8;
}

.shell {
  display: grid;
  grid-template-areas:
    "topbar topbar"
    "game control-dock";
  grid-template-columns: minmax(0, 1fr) 196px;
  grid-template-rows: 62px minmax(0, 1fr);
  gap: 0;
  width: 100%;
  height: 100vh;
  height: 100svh;
  height: 100dvh;
  padding: max(0px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
}

.topbar {
  position: relative;
  z-index: 10;
  display: flex;
  grid-area: topbar;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
  padding-inline: 12px;
  color: var(--hoenn-color-muted);
  font-size: var(--font-size-ui);
}

.location {
  display: flex;
  align-items: center;
  min-width: 0;
}

.shell-control-dock {
  position: relative;
  z-index: 9;
  display: grid;
  grid-area: control-dock;
  align-content: center;
  min-width: 0;
  padding: 10px 8px 10px 12px;
  border-left: 1px solid var(--hoenn-color-paper-edge);
  gap: 12px;
}

.shell-control-group {
  display: grid;
  min-width: 0;
  padding: 8px;
  border: 8px solid transparent;
  border-left-width: 16px;
  border-image: var(--dialogue-frame) 8 8 8 16 fill stretch;
  border-radius: 0;
  background: #f8f8f8;
  gap: 6px;
}

.shell-control-label {
  margin: 0;
  color: var(--hoenn-color-muted);
  font-size: var(--font-size-caption);
  font-weight: 400;
  letter-spacing: var(--letter-spacing-label);
  line-height: 1;
  text-transform: uppercase;
}

.shell-control-cluster {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  min-width: 0;
  gap: 6px;
}

.shell-control-group-game-state .shell-control-cluster {
  grid-template-columns: 1fr;
}

.presentation-controls {
  position: relative;
  flex: 0 0 auto;
}

button {
  appearance: none;
  border: 1px solid var(--product-control-edge);
  border-radius: 3px;
  background: var(--product-control);
  color: var(--product-ink);
  font: inherit;
  font-synthesis: none;
  line-height: 1.5;
  cursor: pointer;
}

.presentation-panel {
  position: fixed;
  top: calc(max(0px, env(safe-area-inset-top)) + 66px);
  right: max(8px, env(safe-area-inset-right));
  display: grid;
  width: min(280px, calc(100vw - 16px));
  padding: 8px;
  border: 8px solid transparent;
  border-left-width: 16px;
  border-image: var(--dialogue-frame) 8 8 8 16 fill stretch;
  border-radius: 0;
  background: #f8f8f8;
  box-shadow: none;
  gap: 8px;
}

.presentation-panel[hidden] {
  display: none;
}

.presentation-speed {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  min-height: 32px;
  gap: 8px;
  color: var(--hoenn-color-muted);
}

.presentation-speed select {
  min-width: 88px;
  min-height: 32px;
  border: 1px solid var(--hoenn-color-silver-edge);
  border-radius: 3px;
  background: var(--hoenn-color-paper);
  color: var(--hoenn-color-ink);
  font: inherit;
  font-synthesis: none;
}

.presentation-panel button {
  min-height: 32px;
  padding: 4px 8px;
}

.presentation-fill {
  width: 100%;
  min-width: 0;
  white-space: nowrap;
}

.speed-button {
  min-width: 3.8rem;
  font-variant-numeric: tabular-nums;
}

.shell-control-cluster > button,
.presentation-toggle {
  min-height: 34px;
  padding-inline: 12px;
}

.shell-control-cluster > button,
.shell-control-cluster .presentation-controls,
.shell-control-cluster .presentation-toggle {
  width: 100%;
  min-width: 0;
}

.menu-button {
  min-width: 4.25rem;
  padding-inline: 14px;
  border: 2px solid var(--product-control-edge);
  border-radius: 4px;
  background: var(--product-control);
  box-shadow: 0 3px 0 var(--product-shadow);
  color: var(--product-ink);
  font-size: var(--font-size-ui);
  font-weight: 400;
}

.zoom-button {
  min-width: 42px;
  padding-inline: 10px;
  font-size: var(--font-size-title);
}

@media (hover: hover) {
  .menu-button:not(:disabled):hover {
    border-color: var(--product-control-edge);
    background: var(--product-control-active);
  }
}

@media (hover: hover) {
  button:not(:disabled):hover {
    border-color: var(--product-emerald-dark);
    filter: brightness(1.04);
  }
}

button:focus-visible {
  outline: 3px solid var(--hoenn-color-focus);
  outline-offset: 2px;
}

h1 {
  margin: 0;
  overflow: hidden;
  color: var(--product-ink);
  font: inherit;
  font-size: var(--font-size-title);
  font-weight: 400;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game-stage {
  position: relative;
  display: grid;
  grid-area: game;
  min-width: 0;
  min-height: 0;
  place-items: center;
  overflow: hidden;
}

.mobile-controls {
  display: none;
}

.mobile-dpad,
.mobile-actions,
.mobile-system {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.mobile-controls[hidden] {
  /* biome-ignore lint/complexity/noImportantStyles: Hidden touch controls must beat later JS-enabled display rules. */
  display: none !important;
}

.game-frame {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min-content;
  height: min-content;
  overflow: hidden;
  border: 1px solid #333333;
  background: #000000;
  transform: translate(-50%, -50%);
}

#game {
  display: block;
  outline: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: crosshair;
  touch-action: none;
}

#game[data-pointer-kind="character"],
#game[data-pointer-kind="item"],
#game[data-pointer-kind="sign"],
#game[data-pointer-kind="building"],
#game[data-pointer-kind="transition"] {
  cursor: pointer;
}

.world-pointer-overlay {
  position: absolute;
  z-index: 2;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#game:focus-visible {
  outline: 1px solid #eeeeee;
  outline-offset: -1px;
}

.boot-cover {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: #000000;
  color: #f8f8f8;
  font-size: var(--font-size-ui);
  transition: opacity 120ms linear;
}

.boot-cover.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.boot-cover p {
  margin: 0;
}

.game-menu {
  position: absolute;
  z-index: 3;
  inset: 0;
  display: block;
  background: #000000;
}

.game-menu[hidden] {
  display: none;
}

.game-menu[data-surface="start"] {
  background: transparent;
}

.game-menu-canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  touch-action: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.game-menu-canvas:focus-visible {
  outline: 1px solid #eeeeee;
  outline-offset: -1px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* God View is an invented live atlas surface. It streams exported outdoor
   maps around the engine's active rendered viewport instead of allocating one
   enormous full-resolution Hoenn bitmap. */
.god-view {
  position: relative;
  z-index: 5;
  display: grid;
  grid-area: game;
  min-width: 0;
  min-height: 0;
  padding: 0;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
}

.god-view[hidden] {
  display: none;
}

.god-view-toolbar {
  display: grid;
  min-width: 0;
  align-items: center;
  padding: 10px 12px;
  border: 8px solid transparent;
  border-left-width: 16px;
  border-image: var(--dialogue-frame) 8 8 8 16 fill stretch;
  border-radius: 0;
  background: #f8f8f8;
  box-shadow: none;
  gap: 12px;
  grid-template-columns: minmax(240px, 1fr) auto auto;
}

.god-view-heading {
  min-width: 0;
}

.god-view-eyebrow {
  display: block;
  font-size: var(--font-size-caption);
  font-weight: 400;
  letter-spacing: var(--letter-spacing-label);
  line-height: 1.2;
  text-transform: uppercase;
}

.god-view-heading h2 {
  margin: 0;
  font-size: var(--font-size-heading);
  line-height: 1.2;
}

#god-view-status {
  max-width: 68ch;
  min-height: 15px;
  margin: 2px 0 0;
  overflow: hidden;
  font-size: var(--font-size-ui);
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.god-view-location {
  max-width: 220px;
  overflow: hidden;
  font-size: var(--font-size-ui);
  font-weight: 400;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.god-view-zoom {
  display: flex;
  align-items: center;
  gap: 6px;
}

.god-view-zoom button {
  min-width: 36px;
  min-height: 36px;
  padding: 5px 10px;
  border-radius: 0;
  box-shadow: 0 2px 0 var(--product-shadow);
  font-weight: 400;
}

.god-view-zoom-slider {
  display: grid;
  min-width: 150px;
  align-items: center;
  gap: 5px;
  grid-template-columns: minmax(90px, 1fr) 42px;
}

#god-view-zoom-input {
  width: 100%;
  accent-color: var(--product-emerald-bright);
}

#god-view-zoom-output {
  font-size: var(--font-size-caption);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.god-view-viewport {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 2px solid var(--product-control-edge);
  border-radius: 0;
  background: #000000;
  box-shadow: 0 8px 0 var(--product-shadow);
  outline: none;
  touch-action: none;
}

.god-view-viewport:focus-visible {
  box-shadow: 0 0 0 3px var(--hoenn-color-focus);
}

#god-view-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  image-rendering: pixelated;
  touch-action: none;
}

#god-view-canvas:active {
  cursor: grabbing;
}

.god-view[data-placing="true"] #god-view-canvas {
  cursor: wait;
}

.game-stage.god-view-native-ui {
  z-index: 7;
  pointer-events: none;
}

.game-stage.god-view-native-ui .game-frame {
  box-shadow:
    0 0 0 4px rgb(7 16 18 / 78%),
    0 12px 32px rgb(0 0 0 / 58%);
  pointer-events: auto;
}

@media (max-width: 820px) {
  .god-view-toolbar {
    gap: 8px;
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .god-view-location {
    display: none;
  }

  .god-view-zoom-slider {
    min-width: 105px;
    grid-template-columns: minmax(56px, 1fr) 38px;
  }
}

@media (max-width: 580px) {
  .god-view {
    gap: 7px;
  }

  .god-view-toolbar {
    padding: 8px;
    grid-template-columns: minmax(0, 1fr);
  }

  .god-view-heading h2 {
    font-size: var(--font-size-title);
  }

  #god-view-status {
    white-space: normal;
  }

  .god-view-zoom {
    width: 100%;
  }

  .god-view-zoom-slider {
    flex: 1;
  }

  .god-view-zoom button {
    min-width: 38px;
    min-height: 40px;
    padding-inline: 8px;
  }
}

/* Shared invented overlay picker (Fly destinations, party Pokémon). Flat
   handheld colors keep it visually distinct from the recreated game menus. */
.overlay-picker {
  position: fixed;
  z-index: 30;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgb(0 0 0 / 72%);
}

.overlay-picker-panel {
  display: grid;
  overflow: hidden;
  width: min(320px, calc(100vw - 32px));
  max-height: min(70vh, 480px);
  border: 8px solid transparent;
  border-left-width: 16px;
  border-image: var(--dialogue-frame) 8 8 8 16 fill stretch;
  border-radius: 0;
  background: #f8f8f8;
  box-shadow: none;
  color: var(--product-ink);
  grid-template-rows: auto auto minmax(0, 1fr);
}

.overlay-picker-panel h2 {
  margin: 0;
  padding: 9px 14px 7px;
  border-bottom: 3px solid var(--product-emerald-bright);
  background: #f8f8f8;
  color: var(--product-ink);
  font-size: var(--font-size-title);
  font-weight: 400;
}

.overlay-picker-note {
  margin: 0;
  padding: 5px 14px;
  border-bottom: 1px solid var(--product-paper-edge);
  background: var(--product-paper-raised);
  color: var(--product-muted);
  font-size: var(--font-size-ui);
}

.overlay-picker-list {
  margin: 0;
  padding: 6px;
  overflow-y: auto;
  list-style: none;
}

.overlay-picker-option {
  display: flex;
  width: 100%;
  align-items: baseline;
  justify-content: space-between;
  padding: 7px 10px;
  border: 1px solid transparent;
  border-radius: 3px;
  background: transparent;
  color: var(--product-ink);
  font-size: var(--font-size-ui);
  text-align: left;
}

.overlay-picker-option.is-active {
  border-color: var(--product-emerald);
  background: var(--product-emerald-soft);
  color: var(--product-ink);
}

.overlay-picker-option.is-active::before {
  margin-right: 8px;
  color: var(--product-coral);
  content: "▶";
  font-size: var(--font-size-ui);
}

.overlay-picker-detail {
  margin-left: auto;
  color: var(--product-muted);
  font-size: var(--font-size-ui);
}

.party-pc-panel {
  width: min(560px, calc(100vw - 32px));
  max-height: min(84vh, 640px);
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
}

.party-pc-party {
  padding: 8px 14px 10px;
  border-bottom: 1px solid var(--product-paper-edge);
}

.party-pc-party h3,
.party-pc-storage h3 {
  margin: 0 0 6px;
  color: var(--product-ink);
  font-size: var(--font-size-caption);
  font-weight: 400;
  letter-spacing: var(--letter-spacing-label);
  text-transform: uppercase;
}

.party-pc-slots {
  display: grid;
  margin: 0;
  padding: 0;
  gap: 6px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  list-style: none;
}

.party-pc-slot {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 46px;
}

.party-pc-slot-empty {
  justify-content: center;
  border: 1px dashed var(--product-paper-edge);
  border-radius: 3px;
  color: var(--product-muted);
  font-size: var(--font-size-ui);
}

.party-pc-slot-main {
  display: flex;
  flex: 1;
  min-width: 0;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border: 1px solid var(--product-paper-edge);
  border-radius: 3px;
  background: var(--product-paper-raised);
  color: var(--product-ink);
  font-size: var(--font-size-ui);
  text-align: left;
}

.party-pc-slot-main.is-target {
  border-color: var(--product-emerald-bright);
  background: var(--product-emerald-soft);
  color: var(--product-ink);
}

.party-pc-slot-name {
  overflow: hidden;
  min-width: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.party-pc-slot-action {
  flex: none;
  padding: 4px 5px;
  border: 1px solid var(--product-paper-edge);
  border-radius: 3px;
  background: transparent;
  color: var(--product-muted);
  font-size: var(--font-size-caption);
}

.party-pc-slot-action:hover {
  border-color: var(--product-emerald);
  background: var(--product-emerald-soft);
  color: var(--product-ink);
}

.party-pc-hint {
  margin: 6px 0 0;
  min-height: 14px;
  color: var(--hoenn-color-warning-text);
  font-size: var(--font-size-ui);
}

.party-pc-storage {
  display: grid;
  overflow: hidden;
  padding: 8px 14px;
  gap: 8px;
  grid-template-rows: auto minmax(0, 1fr);
}

.party-pc-search {
  width: 100%;
  box-sizing: border-box;
  padding: 6px 10px;
  border: 1px solid var(--product-paper-edge);
  border-radius: 3px;
  background: var(--product-paper-raised);
  color: var(--product-ink);
  font-size: var(--font-size-ui);
}

.party-pc-search:focus {
  border-color: var(--product-emerald);
  outline: 2px solid var(--hoenn-color-focus);
  outline-offset: 1px;
}

.party-pc-grid {
  display: grid;
  overflow-y: auto;
  padding-right: 2px;
  gap: 4px;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
}

.party-pc-species {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 5px 3px;
  border: 1px solid transparent;
  border-radius: 3px;
  background: transparent;
  color: var(--product-muted);
  font-size: var(--font-size-caption);
}

.party-pc-species:hover {
  border-color: var(--product-emerald);
  background: var(--product-emerald-soft);
  color: var(--product-ink);
}

.party-pc-species-name {
  overflow: hidden;
  max-width: 100%;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.party-pc-icon {
  display: block;
  flex: none;
  background-repeat: no-repeat;
  image-rendering: pixelated;
}

.party-pc-close {
  justify-self: end;
  margin: 0 14px 12px;
  padding: 6px 16px;
  border: 2px solid var(--product-emerald-dark);
  border-radius: 4px;
  background: #f8f8f8;
  box-shadow: 0 3px 0 var(--product-shadow);
  color: var(--product-ink);
  font-size: var(--font-size-ui);
  font-weight: 400;
}

.party-pc-close:hover {
  background: #f8f8f8;
  color: var(--product-ink);
}

@media (max-width: 640px) {
  .topbar {
    padding-block: 5px;
    padding-inline: 5px;
  }

  .location {
    width: 100%;
    height: 28px;
  }
}

.screen-controls-enabled {
  --mobile-dpad-size: 52px;
  --mobile-action-size: 68px;
  --mobile-control-height: 164px;
  --mobile-left-rail: 168px;
  --mobile-right-rail: 152px;
  --mobile-control-surface: var(--hoenn-color-paper);
  --mobile-control-edge: var(--hoenn-color-silver-edge);
  --mobile-control-label: var(--hoenn-color-ink);

  /* One radius pair drives both the d-pad plate mask (authored at 12px and
     5px in the 156px = 3 x 52px reference frame) and the pressed-button
     highlights, so the two shapes stay identical at every control size. */
  --dpad-arm-radius: calc(var(--mobile-dpad-size) * 12 / 52);
  --dpad-arm-inner-radius: calc(var(--mobile-dpad-size) * 5 / 52);
}

.screen-controls-enabled .mobile-game-button,
.screen-controls-enabled .mobile-controls {
  touch-action: none;
}

/*
 * Touch layout is enabled by JavaScript after a real maxTouchPoints check.
 * It deliberately has no width ceiling: large iPads and touch laptops need
 * controls too, while non-touch desktop browsers retain the ordinary shell.
 */
.touch-controls-enabled .shell {
  grid-template-areas:
    "topbar"
    "control-dock"
    "game"
    "controls";
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: 48px auto minmax(0, 1fr) var(--mobile-control-height);
  gap: 0;
}

.touch-controls-enabled .shell-control-dock {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-content: stretch;
  padding: 4px;
  border-top: 1px solid var(--hoenn-color-paper-edge);
  border-left: 0;
  gap: 4px;
}

.touch-controls-enabled .shell-control-group {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  padding: 4px;
  gap: 4px;
}

.touch-controls-enabled .shell-control-label {
  writing-mode: vertical-rl;
}

.touch-controls-enabled .shell-control-group-game-state .shell-control-cluster {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.touch-controls-enabled .mobile-controls {
  position: relative;
  z-index: 8;
  display: flex;
  grid-area: controls;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  height: var(--mobile-control-height);
  padding: 0 max(8px, 2.5vw);
  pointer-events: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.touch-controls-enabled .mobile-dpad {
  order: 1;
}

.touch-controls-enabled .mobile-system {
  order: 2;
}

.touch-controls-enabled .mobile-actions {
  order: 3;
}

.touch-controls-enabled #game,
.touch-controls-enabled .mobile-controls,
.touch-controls-enabled .mobile-game-button {
  touch-action: none;
}

.touch-controls-enabled .shell-control-cluster > button {
  min-width: 56px;
  min-height: 44px;
  padding-inline: 10px;
  touch-action: manipulation;
}

.touch-controls-enabled .presentation-toggle {
  min-width: 56px;
  min-height: 44px;
  padding-inline: 10px;
  touch-action: manipulation;
}

.touch-controls-enabled .presentation-panel button {
  min-height: 44px;
  touch-action: manipulation;
}

.touch-controls-enabled .presentation-speed,
.touch-controls-enabled .presentation-speed select {
  min-height: 44px;
}

.touch-controls-enabled .presentation-panel {
  top: calc(max(0px, env(safe-area-inset-top)) + 102px);
}

@media (max-width: 420px) {
  .touch-controls-enabled .topbar {
    gap: 8px;
  }

  .touch-controls-enabled .shell-control-cluster > button,
  .touch-controls-enabled .presentation-toggle {
    min-width: 48px;
    padding-inline: 6px;
  }
}

.screen-controls-enabled .mobile-dpad {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, var(--mobile-dpad-size));
  grid-template-rows: repeat(3, var(--mobile-dpad-size));
  isolation: isolate;
  pointer-events: auto;
}

.screen-controls-enabled .mobile-dpad::before {
  position: absolute;
  z-index: 0;
  inset: 0;
  background: var(--mobile-control-surface);

  /* A rounded plus authored in the 156-unit reference frame: convex arm-end
     corners use the same 12-unit radius as the pressed-button highlights. */
  -webkit-mask:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 156 156'%3E%3Cpath d='M64 0h28a12 12 0 0 1 12 12v40h40a12 12 0 0 1 12 12v28a12 12 0 0 1-12 12h-40v40a12 12 0 0 1-12 12H64a12 12 0 0 1-12-12v-40H12a12 12 0 0 1-12-12V64a12 12 0 0 1 12-12h40V12A12 12 0 0 1 64 0Z'/%3E%3C/svg%3E")
    center / 100% 100% no-repeat;
  mask:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 156 156'%3E%3Cpath d='M64 0h28a12 12 0 0 1 12 12v40h40a12 12 0 0 1 12 12v28a12 12 0 0 1-12 12h-40v40a12 12 0 0 1-12 12H64a12 12 0 0 1-12-12v-40H12a12 12 0 0 1-12-12V64a12 12 0 0 1 12-12h40V12A12 12 0 0 1 64 0Z'/%3E%3C/svg%3E")
    center / 100% 100% no-repeat;
  content: "";
  filter: drop-shadow(0 2px 0 var(--mobile-control-edge))
    drop-shadow(0 6px 0 var(--hoenn-color-emerald-shadow));
  pointer-events: none;
}

.screen-controls-enabled .mobile-game-button {
  position: relative;
  z-index: 2;
  display: grid;
  width: var(--mobile-dpad-size);
  min-width: var(--mobile-dpad-size);
  height: var(--mobile-dpad-size);
  min-height: var(--mobile-dpad-size);
  place-items: center;
  padding: 0;
  border: 1px solid var(--mobile-control-edge);
  border-radius: 12px;
  background: var(--mobile-control-surface);
  color: var(--mobile-control-label);
  font-size: var(--font-size-glyph);
  font-weight: 400;
  line-height: 1;
  touch-action: none;
  transition:
    background-color 45ms linear,
    color 45ms linear,
    transform 45ms linear;
  -webkit-tap-highlight-color: transparent;
}

.screen-controls-enabled .mobile-game-button.is-pressed {
  border-color: var(--hoenn-color-ink);
  background: var(--hoenn-color-silver-edge);
  transform: scale(0.96);
}

.screen-controls-enabled .mobile-game-button:focus-visible {
  outline: 3px solid var(--hoenn-color-panel);
  outline-offset: 3px;
}

.screen-controls-enabled .mobile-dpad .mobile-game-button {
  border: 0;
  border-radius: var(--dpad-arm-inner-radius);
  background: transparent;
  color: var(--mobile-control-label);
  text-shadow: none;
}

.screen-controls-enabled .mobile-dpad .mobile-game-button.is-pressed {
  background: var(--hoenn-color-control-pressed);
  box-shadow: none;
  color: var(--hoenn-color-panel);
  transform: none;
}

.screen-controls-enabled .mobile-dpad .mobile-game-button:focus-visible {
  outline-offset: -5px;
}

.screen-controls-enabled .mobile-dpad .mobile-game-button span {
  opacity: 0.72;
  transform: scale(0.72);
}

.screen-controls-enabled .mobile-dpad .dpad-up {
  grid-column: 2;
  grid-row: 1;
  border-radius: var(--dpad-arm-radius) var(--dpad-arm-radius) var(--dpad-arm-inner-radius)
    var(--dpad-arm-inner-radius);
}

.screen-controls-enabled .mobile-dpad .dpad-left {
  grid-column: 1;
  grid-row: 2;
  border-radius: var(--dpad-arm-radius) var(--dpad-arm-inner-radius) var(--dpad-arm-inner-radius)
    var(--dpad-arm-radius);
}

.dpad-center {
  position: relative;
  z-index: 1;
  grid-column: 2;
  grid-row: 2;
  margin: 31%;
  border: 1px solid rgb(255 255 255 / 10%);
  border-radius: 50%;
  background: rgb(0 0 0 / 13%);
  pointer-events: none;
}

.screen-controls-enabled .mobile-dpad .dpad-right {
  grid-column: 3;
  grid-row: 2;
  border-radius: var(--dpad-arm-inner-radius) var(--dpad-arm-radius) var(--dpad-arm-radius)
    var(--dpad-arm-inner-radius);
}

.screen-controls-enabled .mobile-dpad .dpad-down {
  grid-column: 2;
  grid-row: 3;
  border-radius: var(--dpad-arm-inner-radius) var(--dpad-arm-inner-radius) var(--dpad-arm-radius)
    var(--dpad-arm-radius);
}

.screen-controls-enabled .mobile-actions {
  display: grid;
  grid-template-columns: repeat(2, var(--mobile-action-size));
  grid-template-rows: repeat(2, var(--mobile-action-size));
  pointer-events: auto;
}

.screen-controls-enabled .mobile-system {
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
}

.screen-controls-enabled .mobile-system .action-start {
  width: 64px;
  min-width: 64px;
  height: 24px;
  min-height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--mobile-control-surface);
  color: var(--mobile-control-label);
  font-size: var(--font-size-ui);
  font-weight: 400;
  letter-spacing: 0;
}

.screen-controls-enabled .mobile-actions .mobile-game-button {
  width: var(--mobile-action-size);
  min-width: var(--mobile-action-size);
  height: var(--mobile-action-size);
  min-height: var(--mobile-action-size);
  border: 1px solid var(--mobile-control-edge);
  border-radius: 50%;
  background: var(--mobile-control-surface);
  box-shadow:
    inset 0 2px 0 rgb(255 255 255 / 22%),
    0 6px 0 var(--product-shadow);
  color: var(--mobile-control-label);
  font-size: var(--font-size-glyph);
  font-weight: 400;
  text-shadow: none;
}

.action-b {
  grid-column: 1;
  grid-row: 2;
}

.action-a {
  grid-column: 2;
  grid-row: 1;
}

.screen-controls-enabled .mobile-actions .action-a {
  border-color: var(--hoenn-color-emerald-bright);
  background: var(--mobile-control-surface);
}

.screen-controls-enabled .mobile-actions .action-b {
  border-color: var(--hoenn-color-silver-edge);
  background: var(--mobile-control-surface);
}

.screen-controls-enabled .mobile-actions .mobile-game-button.is-pressed {
  border-color: var(--product-ink);
  box-shadow:
    inset 0 2px 0 rgb(0 0 0 / 20%),
    0 2px 0 var(--product-shadow);
}

@media (max-width: 350px) {
  .touch-controls-enabled {
    --mobile-dpad-size: 44px;
    --mobile-action-size: 60px;
    --mobile-control-height: 144px;
  }

  .touch-controls-enabled .mobile-controls {
    padding-inline: 4px;
  }
}

@media (min-width: 768px) and (orientation: portrait) {
  .touch-controls-enabled {
    --mobile-dpad-size: 60px;
    --mobile-action-size: 80px;
    --mobile-control-height: 196px;
  }
}

@media (orientation: landscape) {
  .touch-controls-enabled .shell {
    grid-template-areas: none;
    grid-template-columns: var(--mobile-left-rail) minmax(0, 1fr) var(--mobile-right-rail);
    grid-template-rows: 42px auto minmax(0, 1fr);
    gap: 4px;
  }

  .touch-controls-enabled .topbar {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  .touch-controls-enabled .shell-control-dock {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .touch-controls-enabled .presentation-panel {
    top: calc(max(0px, env(safe-area-inset-top)) + 52px);
    right: auto;
    left: 50%;
    width: min(500px, calc(100vw - var(--mobile-left-rail) - var(--mobile-right-rail) - 8px));
    transform: translateX(-50%);
  }

  .touch-controls-enabled .game-stage,
  .touch-controls-enabled .god-view {
    grid-column: 2;
    grid-row: 3;
  }

  .touch-controls-enabled .god-view-toolbar {
    padding: 5px 6px;
    gap: 5px;
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .touch-controls-enabled .god-view-eyebrow,
  .touch-controls-enabled #god-view-status,
  .touch-controls-enabled .god-view-location {
    display: none;
  }

  .touch-controls-enabled .god-view-heading h2 {
    font-size: var(--font-size-title);
  }

  .touch-controls-enabled .god-view-zoom {
    gap: 4px;
  }

  .touch-controls-enabled .god-view-zoom-slider {
    min-width: 92px;
    grid-template-columns: minmax(52px, 1fr) 36px;
  }

  .touch-controls-enabled .god-view-zoom button {
    min-width: 34px;
    min-height: 36px;
    padding-inline: 6px;
  }

  .touch-controls-enabled .mobile-controls {
    display: grid;
    grid-column: 1 / -1;
    grid-row: 3;
    grid-template-columns: var(--mobile-left-rail) minmax(0, 1fr) var(--mobile-right-rail);
    grid-template-rows: minmax(0, 1fr);
    align-self: stretch;
    width: 100%;
    height: auto;
    padding: 0;
    pointer-events: none;
  }

  .touch-controls-enabled .mobile-dpad,
  .touch-controls-enabled .mobile-actions,
  .touch-controls-enabled .mobile-system {
    z-index: 4;
    align-self: center;
    justify-self: center;
    grid-row: 1;
    pointer-events: auto;
  }

  .touch-controls-enabled .mobile-dpad {
    grid-column: 1;
  }

  .touch-controls-enabled .mobile-actions {
    grid-column: 3;
  }

  .touch-controls-enabled .mobile-system {
    grid-column: 2;
  }
}

@media (min-width: 1024px) and (orientation: landscape) {
  .touch-controls-enabled {
    --mobile-dpad-size: 60px;
    --mobile-action-size: 80px;
    --mobile-left-rail: 192px;
    --mobile-right-rail: 176px;
  }
}

@media (min-width: 651px) and (orientation: landscape) {
  .touch-controls-enabled .presentation-panel {
    grid-template-columns: minmax(0, 1fr) 120px 150px;
    align-items: center;
  }

  .touch-controls-enabled .presentation-speed {
    grid-template-columns: auto minmax(80px, 1fr);
  }
}

@media (max-width: 650px) and (orientation: landscape) {
  .touch-controls-enabled {
    --mobile-dpad-size: 44px;
    --mobile-action-size: 60px;
    --mobile-left-rail: 140px;
    --mobile-right-rail: 132px;
  }

  .touch-controls-enabled .shell {
    grid-template-rows: 42px auto minmax(0, 1fr);
  }

  .touch-controls-enabled .presentation-panel {
    top: calc(max(0px, env(safe-area-inset-top)) + 102px);
  }
}

/* The dock is a layout component rather than a toolbar. Experiments can opt
   into the strip variant with one data attribute; narrower desktop windows
   use that same component arrangement automatically. */
.shell[data-control-layout="strip"] {
  grid-template-areas:
    "topbar"
    "control-dock"
    "game";
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: 48px auto minmax(0, 1fr);
}

.shell[data-control-layout="strip"] .shell-control-dock {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-content: stretch;
  padding: 4px 8px;
  border-top: 1px solid var(--hoenn-color-paper-edge);
  border-left: 0;
  gap: 6px;
}

.shell[data-control-layout="strip"] .shell-control-group {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  padding: 4px 6px;
}

.shell[data-control-layout="strip"] .shell-control-group-game-state .shell-control-cluster {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

/* A side rail only works when the browser itself is wide enough. In a tall
   desktop window it steals the width that limits the 3:2 game surface and
   creates huge letterbox bands, so move the same controls into a strip. */
@media (max-width: 900px), (max-aspect-ratio: 3 / 2) {
  html:not(.touch-controls-enabled) .shell {
    grid-template-areas:
      "topbar"
      "control-dock"
      "game";
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 48px auto minmax(0, 1fr);
  }

  html:not(.touch-controls-enabled) .shell-control-dock {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-content: stretch;
    padding: 4px 8px;
    border-top: 1px solid var(--hoenn-color-paper-edge);
    border-left: 0;
    gap: 6px;
  }

  html:not(.touch-controls-enabled) .shell-control-group {
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    padding: 4px 6px;
  }

  html:not(.touch-controls-enabled) .shell-control-group-game-state .shell-control-cluster {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 540px) {
  html:not(.touch-controls-enabled) .shell-control-dock {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  html:not(.touch-controls-enabled) .shell-control-group-game-state {
    grid-column: 1 / -1;
  }
}

/*
 * Fill mode changes presentation only: the native 240x160 canvas and world
 * simulation stay untouched. The stage becomes the viewport-sized backdrop,
 * while the restrained controls remain overlaid in the safe-area-aware shell.
 */
.presentation-fill-enabled .game-stage {
  position: fixed;
  z-index: 0;
  inset: 0;
  grid-area: auto;
  background: #000000;
}

.presentation-fill-enabled .god-view {
  position: fixed;
  z-index: 5;
  inset: 0;
  padding: 50px 8px 8px;
  grid-area: auto;
}

.presentation-fill-enabled .game-stage.god-view-native-ui {
  z-index: 7;
}

.presentation-fill-enabled .game-frame {
  border: 0;
}

.touch-controls-enabled.presentation-fill-enabled .shell-control-cluster > button,
.touch-controls-enabled.presentation-fill-enabled .presentation-toggle {
  border-color: var(--mobile-control-edge);
  background: var(--mobile-control-surface);
  box-shadow: 0 3px 9px rgb(0 0 0 / 24%);
}

.presentation-fill-enabled .topbar {
  z-index: 9;
  text-shadow: 0 1px 2px rgb(0 0 0 / 72%);
}
