:root {
  --bg: #071812;
  --bg-2: #0d2a1f;
  --surface: #12352a;
  --surface-2: #184536;
  --border: #22584a;
  --accent: #3ddc97;
  --accent-ink: #052016;
  --text: #e9f7f0;
  --muted: #94bfae;
  --danger: #ff7a8a;

  --shell: #0f5c43;
  --shell-hi: #17795a;
  --shell-lo: #0a3f2e;
  --key: #1d2226;
  --key-hi: #343b41;
  --key-lo: #0c0f11;
  --face: #2a2f6e;
  --face-hi: #4049a3;
  --label: #bfe9d6;

  --radius: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
.no-states tr[data-binding="saveState"], .no-states tr[data-binding="loadState"] { display: none; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  background:
    radial-gradient(1200px 600px at 50% -10%, #1b5b44 0%, transparent 60%),
    radial-gradient(800px 400px at 100% 100%, #0e3b2c 0%, transparent 60%),
    var(--bg);
}

button { font: inherit; color: inherit; }
svg { width: 20px; height: 20px; fill: currentColor; flex: none; }
kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 0 .4em;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface);
  font: 600 .8em/1.6 ui-monospace, SFMono-Regular, Menlo, monospace;
  text-align: center;
  color: var(--text);
}

/* ---------------------------------------------------------------- Desktop layout */

.app {
  height: 100dvh;
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 24px 12px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: 14px;
}

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand img { border-radius: 8px; }
.brand h1 { margin: 0; font-size: 1.15rem; letter-spacing: .01em; }
.rom-name { margin: 0; color: var(--muted); font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chip {
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: .8rem;
  white-space: nowrap;
}

.stage { display: flex; align-items: center; justify-content: center; min-height: 0; container-type: size; }

.screen-wrap {
  position: relative;
  /* As large as the stage allows while keeping the GBA's 3:2 ratio */
  width: min(100cqw - 20px, (100cqh - 20px) * 1.5);
  aspect-ratio: 3 / 2;
  background: #000;
  border-radius: 14px;
  overflow: hidden;
  box-shadow:
    0 0 0 1px #000,
    0 0 0 8px #10261e,
    0 0 0 9px var(--border),
    0 24px 60px rgba(0, 0, 0, .55);
}

#screen {
  display: block;
  width: 100% !important;
  height: 100% !important;
  image-rendering: pixelated;
  outline: none;
}

.start-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  background: radial-gradient(circle, rgba(10, 45, 33, .85), rgba(0, 0, 0, .92));
  cursor: pointer;
  text-align: center;
  padding: 16px;
}
.start-overlay:disabled { cursor: progress; }
.start-overlay:disabled .start-icon { opacity: .35; animation: pulse 1.2s ease-in-out infinite; }
.start-icon {
  display: grid;
  place-items: center;
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 0 0 8px rgba(61, 220, 151, .18);
  transition: transform .15s;
}
.start-icon svg { width: 32px; height: 32px; margin-left: 4px; }
.start-overlay:not(:disabled):hover .start-icon { transform: scale(1.07); }
.start-label { font-size: 1.25rem; font-weight: 700; }
.start-hint { color: var(--muted); font-size: .85rem; }
@keyframes pulse { 50% { opacity: .8; } }

.badges { position: absolute; top: 10px; right: 10px; display: flex; gap: 6px; pointer-events: none; }
.badge {
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(0, 0, 0, .65);
  color: #fff;
  font: 700 .75rem/1.6 ui-monospace, monospace;
  letter-spacing: .05em;
}

.toolbar {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.toolbar .sep { width: 1px; height: 26px; background: var(--border); margin: 0 4px; }

.toolbar button, .grid-actions button, .as-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  cursor: pointer;
  transition: background .12s, border-color .12s, transform .08s;
}
.toolbar button:hover, .grid-actions button:hover, .as-button:hover { background: var(--surface-2); border-color: var(--accent); }
.toolbar button:active, .grid-actions button:active, .as-button:active { transform: translateY(1px); }
.toolbar button[aria-pressed="true"], .grid-actions button[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.toolbar button:focus-visible, .grid-actions button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.key-hints {
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: .82rem;
}
.key-hints .dot { margin: 0 8px; opacity: .5; }

/* ---------------------------------------------------------------- Menu dialog */

.menu {
  width: min(520px, calc(100vw - 24px));
  max-height: min(680px, calc(100dvh - 24px));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--bg-2);
  color: var(--text);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .6);
  overflow: auto;
}
.menu::backdrop { background: rgba(0, 0, 0, .6); backdrop-filter: blur(3px); }
.menu[open] { display: flex; flex-direction: column; }

.menu-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px 4px; }
.menu-head h2 { margin: 0; font-size: 1.1rem; }
.close {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: var(--surface);
  cursor: pointer;
}
.close:hover { background: var(--surface-2); }

.tabs { display: flex; gap: 4px; padding: 8px 18px 0; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg-2); z-index: 1; }
.tabs button {
  padding: 8px 12px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }

.tab-panel { padding: 16px 18px 20px; display: flex; flex-direction: column; gap: 16px; }

.grid-actions { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.grid-actions.two { grid-template-columns: 1fr 1fr; }
.grid-actions button, .as-button { justify-content: flex-start; }
a.as-button { color: var(--text); text-decoration: none; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-weight: 600; font-size: .9rem; }
.field small { color: var(--muted); }
.field select, .field input[type="range"] { width: 100%; accent-color: var(--accent); }
.field select {
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.muted { margin: 0; color: var(--muted); font-size: .9rem; }
.small { font-size: .8rem; }

.bindings { width: 100%; border-collapse: collapse; }
.bindings th { text-align: left; font-weight: 500; padding: 4px 0; }
.bindings th.group { padding-top: 12px; color: var(--accent); font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; }
.bindings td { padding: 3px 0 3px 8px; width: 120px; }
.key {
  width: 100%;
  min-height: 34px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-bottom-width: 3px;
  border-radius: 8px;
  background: var(--surface);
  font: 600 .85rem ui-monospace, SFMono-Regular, Menlo, monospace;
  cursor: pointer;
}
.key:hover { border-color: var(--accent); }
.key.empty { color: var(--muted); border-style: dashed; border-bottom-width: 1px; }
.key.listening { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); animation: pulse .9s infinite; }

.secondary {
  align-self: flex-start;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.secondary:hover { color: var(--text); border-color: var(--accent); }

.toast {
  position: fixed;
  left: 50%;
  top: calc(16px + env(safe-area-inset-top));
  transform: translate(-50%, -20px);
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  font-size: .9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 10;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------------------------------------------------------- Account & ROM screens */

.gate {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  display: grid;
  place-items: center;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
}
.gate-card {
  width: min(420px, 100%);
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: color-mix(in srgb, var(--bg-2) 92%, transparent);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .45);
}
.gate-card.wide { width: min(560px, 100%); }
.gate-card.center { align-items: center; text-align: center; background: none; border: 0; box-shadow: none; }
.gate-card.center img { animation: pulse 1.4s ease-in-out infinite; }
.gate-head { display: flex; gap: 14px; align-items: flex-start; }
.gate-head img { border-radius: 12px; flex: none; }
.gate-head h1 { margin: 0 0 4px; font-size: 1.25rem; }
.gate-icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  flex: none;
  border-radius: 12px;
  background: var(--surface);
  color: var(--accent);
}
.gate-icon svg { width: 26px; height: 26px; }
.gate-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding-top: 4px; border-top: 1px solid var(--border); }

.auth-tabs { padding: 0; position: static; background: none; }

.field input:not([type="range"]) {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }

.primary {
  padding: 12px 16px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  cursor: pointer;
}
.primary:hover { filter: brightness(1.08); }
.primary:disabled { opacity: .6; cursor: progress; }
.link { padding: 4px 0; border: 0; background: none; color: var(--muted); text-decoration: underline; cursor: pointer; }
.link:hover { color: var(--text); }

.form-error {
  margin: 0;
  padding: 9px 12px;
  border-radius: 10px;
  background: rgba(255, 122, 138, .12);
  color: var(--danger);
  font-size: .9rem;
}

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 26px 16px;
  border: 2px dashed var(--border);
  border-radius: 14px;
  background: var(--surface);
  cursor: pointer;
  text-align: center;
  transition: border-color .12s, background .12s;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--surface-2); }
.dropzone strong { color: var(--accent); }

.rom-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.rom-list:empty { display: none; }
.rom-list li { display: flex; gap: 6px; }
.rom-pick {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--muted);
  border-radius: 10px;
  background: var(--surface);
  text-align: left;
  cursor: pointer;
}
.rom-list li.online .rom-pick { border-left-color: var(--accent); }
.rom-pick:hover { border-color: var(--accent); }
.rom-remove {
  width: 40px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.rom-remove:hover { color: var(--danger); border-color: var(--danger); }

.top-right { display: flex; align-items: center; gap: 8px; }
.chip.cloud { display: inline-flex; align-items: center; gap: 6px; }
.chip.cloud svg { width: 16px; height: 16px; }
.chip.cloud[data-state="synced"] { color: var(--accent); }
.chip.cloud[data-state="offline"], .chip.cloud[data-state="logged-out"] { color: var(--danger); }
.chip.cloud[data-state="syncing"] svg, .chip.cloud[data-state="pending"] svg { animation: pulse 1s infinite; }
.user-chip { cursor: pointer; color: var(--text); font: inherit; font-size: .8rem; }
.user-chip:hover { border-color: var(--accent); }

.sync-box { display: flex; gap: 12px; align-items: flex-start; padding: 12px; border-radius: 12px; background: var(--surface); }
.sync-box svg { width: 24px; height: 24px; color: var(--accent); margin-top: 2px; }
.sync-box p { margin: 2px 0 0; }

.info { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0; }
.info dt { color: var(--muted); }
.info dd { margin: 0; font-weight: 600; }

.conflict h2 { margin: 0; font-size: 1.1rem; }
.choice-list { display: flex; flex-direction: column; gap: 8px; }
.choice {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  text-align: left;
  cursor: pointer;
}
.choice:hover { border-color: var(--accent); }

/* ---------------------------------------------------------------- Online */

.online-chip { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font: inherit; font-size: .8rem; }
.online-chip svg { width: 16px; height: 16px; }
.online-chip[data-state="session"] { color: var(--accent); border-color: var(--accent); }
.online-chip[data-state="offline"] { color: var(--danger); }

.panel-title { margin: 0 0 8px; font-size: .95rem; }
.player-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.player-list:empty { display: none; }
.player-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 8px 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}
.player-list .busy { color: var(--muted); font-size: .8rem; }
.player-list button {
  padding: 6px 12px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: none;
  color: var(--accent);
  cursor: pointer;
}
.player-list button:disabled { opacity: .4; cursor: default; }
.sync-box .secondary { margin-top: 8px; }
.howto { color: var(--muted); font-size: .88rem; }
.howto summary { cursor: pointer; color: var(--text); }
.howto ol, .howto ul { margin: 6px 0 8px; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; }
.howto p { margin: 8px 0 0; }

.invite-card {
  position: fixed;
  z-index: 20;
  left: 50%;
  top: calc(16px + env(safe-area-inset-top));
  transform: translateX(-50%);
  width: min(380px, calc(100vw - 24px));
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 12px;
  align-items: center;
  padding: 14px 16px;
  border: 1px solid var(--accent);
  border-radius: 14px;
  background: var(--bg-2);
  box-shadow: 0 20px 50px rgba(0, 0, 0, .55);
}
.invite-card > svg { width: 28px; height: 28px; color: var(--accent); }
.invite-card p { margin: 0; }
.invite-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 8px; }
.invite-actions .secondary { align-self: auto; }
.invite-actions .primary { padding: 8px 16px; }

/* ---------------------------------------------------------------- GBA touch controls */

.pad { display: none; }

@media (pointer: coarse) {
  :root {
    --ctl: rgba(255, 255, 255, .09);
    --ctl-border: rgba(255, 255, 255, .13);
    --ctl-on: rgba(255, 255, 255, .30);
    --ctl-ink: rgba(225, 245, 236, .78);
    --face-ctl: rgba(120, 110, 255, .20);
    --face-border: rgba(170, 160, 255, .30);
  }

  html, body { overflow: hidden; overscroll-behavior: none; position: fixed; inset: 0; }
  body {
    background: linear-gradient(180deg, #0c1f18 0%, #0a1a14 55%, #07130f 100%);
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
  }

  .toolbar, .key-hints, .chip, .rom-name, .brand img { display: none; }

  /* Free space goes above the screen, so screen + controls sit low, within thumb reach */
  .topbar { justify-content: center; align-self: center; }
  .brand h1 {
    font-size: .72rem;
    font-weight: 600;
    letter-spacing: .3em;
    text-transform: uppercase;
    color: var(--ctl-ink);
    opacity: .45;
  }

  .app {
    height: 100dvh;
    max-width: none;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    /* Free space: 60 % above the screen, 40 % between screen and controls */
    grid-template-rows: minmax(0, 3fr) auto minmax(0, 2fr) auto;
    gap: 0;
  }
  .topbar { grid-row: 1; }
  .stage { grid-row: 2; }
  .pad { grid-row: 4; }

  /* Screen: edge to edge, as big as the width allows */
  .stage { padding: 0; container-type: normal; }
  .screen-wrap {
    width: min(100vw, (100dvh - 250px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * 1.5);
    margin: 0 auto;
    border-radius: 0;
    box-shadow: 0 1px 0 rgba(255, 255, 255, .06), 0 10px 30px rgba(0, 0, 0, .5);
  }
  .start-icon { width: 56px; height: 56px; }
  .start-icon svg { width: 26px; height: 26px; }
  .start-label { font-size: 1.05rem; }

  .pad {
    display: grid;
    min-height: 0;
    padding: 10px 14px 8px;
    grid-template-columns: 1fr 1fr;
    /* L/R right under the screen, the rest down in the thumb zone */
    grid-template-rows: auto auto auto;
    grid-template-areas:
      "l r"
      "dpad face"
      "sys sys";
    align-items: center;
    row-gap: clamp(10px, 3dvh, 26px);
    padding-top: clamp(10px, 2dvh, 16px);
    padding-bottom: clamp(12px, 3dvh, 28px);
    touch-action: none;
  }

  .pad button {
    border: 1px solid var(--ctl-border);
    padding: 0;
    background: var(--ctl);
    color: var(--ctl-ink);
    cursor: pointer;
    touch-action: none;
    transition: background .06s, transform .06s;
  }
  .pad .pressed { background: var(--ctl-on) !important; transform: scale(.96); }

  .shoulder {
    width: clamp(84px, 26vw, 120px);
    height: 32px;
    font-size: .8rem;
    font-weight: 600;
    letter-spacing: .08em;
  }
  .shoulder.l { grid-area: l; justify-self: start; border-radius: 16px 8px 8px 8px; }
  .shoulder.r { grid-area: r; justify-self: end; border-radius: 8px 16px 8px 8px; }

  /* D-pad: one zone, the finger position picks the direction(s) */
  .dpad {
    --size: clamp(126px, 38vw, 164px);
    grid-area: dpad;
    justify-self: center;
    position: relative;
    width: var(--size);
    height: var(--size);
    touch-action: none;
  }
  .dpad .arm, .dpad .hub { position: absolute; background: var(--ctl); }
  .dpad .arm { --w: 33.4%; border: 1px solid var(--ctl-border); }
  .dpad .up, .dpad .down { left: calc(50% - var(--w) / 2); width: var(--w); height: 34%; }
  .dpad .left, .dpad .right { top: calc(50% - var(--w) / 2); height: var(--w); width: 34%; }
  .dpad .up { top: 0; border-bottom: 0; border-radius: 8px 8px 0 0; }
  .dpad .down { bottom: 0; border-top: 0; border-radius: 0 0 8px 8px; }
  .dpad .left { left: 0; border-right: 0; border-radius: 8px 0 0 8px; }
  .dpad .right { right: 0; border-left: 0; border-radius: 0 8px 8px 0; }
  .dpad .hub { left: 33.3%; top: 33.3%; width: 33.4%; height: 33.4%; }
  .dpad .arm::after {
    content: "";
    position: absolute;
    inset: 0;
    margin: auto;
    width: 0;
    height: 0;
    border: 5px solid transparent;
    opacity: .55;
  }
  .dpad .up::after { border-bottom-color: var(--ctl-ink); border-top-width: 0; }
  .dpad .down::after { border-top-color: var(--ctl-ink); border-bottom-width: 0; }
  .dpad .left::after { border-right-color: var(--ctl-ink); border-left-width: 0; }
  .dpad .right::after { border-left-color: var(--ctl-ink); border-right-width: 0; }
  .dpad.on-up .up, .dpad.on-down .down, .dpad.on-left .left, .dpad.on-right .right { background: var(--ctl-on); }

  /* A / B: diagonal, like the real console */
  .face {
    --btn: clamp(54px, 16vw, 66px);
    grid-area: face;
    justify-self: center;
    position: relative;
    width: calc(var(--btn) * 2.2);
    height: calc(var(--btn) * 1.6);
    transform: rotate(-22deg);
  }
  .pad .round {
    position: absolute;
    width: var(--btn);
    height: var(--btn);
    border-radius: 50%;
    border-color: var(--face-border);
    background: var(--face-ctl);
    font-size: calc(var(--btn) * .3);
    font-weight: 600;
  }
  .round span { display: inline-block; transform: rotate(22deg); }
  .round.b { left: 0; bottom: 0; }
  .round.a { right: 0; top: 0; }

  .sys {
    grid-area: sys;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 22px;
  }
  .pill-wrap { display: flex; flex-direction: column; align-items: center; gap: 5px; }
  .pill-wrap span { font-size: .56rem; font-weight: 600; letter-spacing: .14em; color: var(--ctl-ink); opacity: .6; }
  .pad .pill { width: 46px; height: 14px; border-radius: 7px; }
  .pad .menu-btn {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: transparent;
    border-color: transparent;
  }
  .menu-btn svg { width: 18px; height: 18px; opacity: .7; }

  .menu { max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); }
  .tab-panel .bindings { font-size: .9rem; }
}

/* Landscape phone: full-height screen in the middle, controls on both sides */
@media (pointer: coarse) and (orientation: landscape) {
  .app {
    --side: max(150px, (100vw - 100dvh * 1.5) / 2);
    grid-template-rows: minmax(0, 1fr);
    grid-template-columns: minmax(0, 1fr);
  }
  .topbar { display: none; }
  .stage { grid-area: 1 / 1; }
  .screen-wrap {
    width: min(100vw - 2 * var(--side), 100dvh * 1.5);
    box-shadow: 0 0 30px rgba(0, 0, 0, .6);
  }

  .pad {
    grid-area: 1 / 1;
    display: block;
    position: relative;
    padding: 0;
    pointer-events: none;
  }
  .pad > * { pointer-events: auto; }
  .shoulder { position: absolute; top: 8px; width: min(18vw, 120px); }
  .shoulder.l { left: 10px; }
  .shoulder.r { right: 10px; }
  .dpad {
    --size: min(var(--side) - 24px, 56dvh, 150px);
    position: absolute;
    left: calc((var(--side) - var(--size)) / 2);
    top: calc(50% - var(--size) / 2 + 6px);
  }
  .face {
    --btn: min((var(--side) - 24px) / 2.2, 24dvh, 62px);
    position: absolute;
    right: calc((var(--side) - var(--btn) * 2.2) / 2);
    top: calc(50% - var(--btn) * .8 + 6px);
  }
  .sys {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 8px;
    justify-content: space-between;
    padding: 0 14px;
    pointer-events: none;
  }
  .sys > * { pointer-events: auto; }
  .pad .menu-btn { position: fixed; top: 48px; left: calc(10px + env(safe-area-inset-left)); }
}
