:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --border: #2a2f3a;
  --text: #e8eaed;
  --text-dim: #9aa0ac;
  --accent: #e63946;
  --accent-dim: #7a1f27;
  --focus: #4f8cff;
  --success: #2ecc71;
  --success-dim: #1c6b3f;
  --error: #ff5c5c;
  --error-dim: #7a2020;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overscroll-behavior: none;
}

button, input {
  font-family: inherit;
}

/* Tactile press feedback, shared by every interactive control. */
.icon-btn, .fav-filter, .fav-star, .rom-item,
.toolbar-buttons button, .dbtn, .abtn, .mbtn, .overlay-pick {
  transition: transform 0.08s ease, background 0.08s ease;
}
.icon-btn:active,
.fav-filter:active,
.fav-star:active,
.toolbar-buttons button:not(:disabled):active,
.dbtn:active, .dbtn.pressed,
.abtn:active, .abtn.pressed,
.mbtn:active, .mbtn.pressed,
.overlay-pick:active {
  transform: scale(0.92);
}
.rom-item:active { transform: scale(0.98); }

.app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ---------- Topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
  z-index: 20;
}

.icon {
  width: 20px;
  height: 20px;
  fill: currentColor;
  color: inherit;
  flex: 0 0 auto;
}

.hamburger {
  display: none;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  letter-spacing: 0.3px;
  white-space: nowrap;
  color: var(--text);
  flex: 1 1 auto;
}

.brand .dot { color: var(--accent); }

.search-wrap {
  width: 100%;
}

#search {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 12px;
  border-radius: var(--radius);
  font-size: 14px;
  outline: none;
}
#search:focus { border-color: var(--focus); }

.topbar-actions {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  width: 42px;
  height: 42px;
  cursor: pointer;
}
.icon-btn:active { background: var(--border); }

.settings-wrap {
  position: relative;
}

.settings-panel {
  display: none;
  position: absolute;
  top: 46px;
  right: 0;
  width: 240px;
  max-width: 80vw;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.45);
  z-index: 40;
}
.settings-panel.open { display: block; }

.settings-panel h3 {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  margin-bottom: 10px;
}
.setting-row:last-of-type { margin-bottom: 0; }

.setting-row select {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 12.5px;
}

.checkbox-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.setting-hint {
  margin: 10px 0 0;
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.4;
}
.setting-hint.hidden { display: none; }

.settings-btn {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
}
.settings-btn:active { background: var(--border); }

.setting-row input[type="range"] {
  width: 110px;
  accent-color: var(--accent);
}

.checkbox-row input[type="checkbox"]:disabled {
  accent-color: var(--text-dim);
  opacity: 0.5;
  cursor: not-allowed;
}
.setting-row:has(input:disabled) span { color: var(--text-dim); }

.fps-counter {
  position: absolute;
  top: 6px;
  right: 8px;
  background: rgba(0,0,0,0.55);
  color: #9aff9a;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
  pointer-events: none;
}
.fps-counter.hidden { display: none; }

.ff-indicator {
  position: absolute;
  top: 10px;
  left: 10px;
  background: rgba(0, 0, 0, 0.4);
  color: #fff;
  font-size: 20px;
  font-weight: 700;
  padding: 5px 14px;
  border-radius: 999px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.ff-indicator.show { opacity: 1; }

/* ---------- Layout ---------- */

.layout {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
  position: relative;
}

.rom-list {
  flex: 0 0 300px;
  width: 300px;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--border);
  min-height: 0;
}

.rom-list-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.rom-list-filters-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-buttons {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.fav-filter {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.fav-filter .icon { width: 13px; height: 13px; }
.fav-filter.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--text);
}

.rom-count {
  color: var(--text-dim);
  font-size: 11.5px;
  white-space: nowrap;
}

#opt-system-filter {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 12px;
  padding: 6px 8px;
  border-radius: 999px;
  cursor: pointer;
}

.system-badge {
  flex: 0 0 auto;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-dim);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 2px 5px;
}

.rom-items {
  overflow-y: auto;
  padding: 8px;
  flex: 1 1 auto;
  min-height: 0;
}

.rom-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 10px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  border: 1px solid transparent;
}
.rom-item:hover { background: var(--panel-2); }
.rom-item.active {
  background: var(--accent-dim);
  border-color: var(--accent);
}
.rom-item .name {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rom-item .size {
  font-size: 11px;
  color: var(--text-dim);
  flex: 0 0 auto;
}
.fav-star {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 2px;
  cursor: pointer;
}
.fav-star .icon { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.5; }
.fav-star.is-fav { color: #f5c518; }
.fav-star.is-fav .icon { fill: currentColor; stroke: none; }
.saved-badge {
  flex: 0 0 auto;
  display: flex;
  opacity: 0.85;
}
.saved-badge .icon { width: 13px; height: 13px; }
.saved-thumb {
  flex: 0 0 auto;
  width: 26px;
  height: 24px;
  object-fit: cover;
  border-radius: 3px;
  border: 1px solid var(--border);
  image-rendering: pixelated;
}
.rom-empty {
  color: var(--text-dim);
  padding: 20px 10px;
  font-size: 13px;
  text-align: center;
}

.continue-banner.hidden { display: none; }
.continue-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 8px 0;
  padding: 9px 10px;
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  font-size: 12.5px;
}
.continue-banner .continue-text {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.continue-banner button {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  font-size: 12.5px;
  padding: 4px 6px;
}
.continue-banner button .icon { width: 12px; height: 12px; }
.continue-banner .continue-dismiss {
  color: var(--text-dim);
  font-size: 16px;
  line-height: 1;
  padding: 0 2px;
}

.drawer-scrim {
  display: none;
}

/* ---------- Player ---------- */

.player {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
  overflow-y: auto;
  min-width: 0;
}

.player-stage {
  width: 100%;
  max-width: 720px;
  display: flex;
  justify-content: center;
}

.canvas-wrap {
  --console-w: 256;
  --console-h: 240;
  position: relative;
  width: 100%;
  max-width: 640px;
  aspect-ratio: var(--console-w) / var(--console-h);
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
}

#nes-canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
  background: rgba(0,0,0,0.55);
  color: var(--text);
  font-size: 14px;
  transition: opacity 0.15s ease;
}
.overlay-heading {
  margin: 0 0 10px;
  font-size: 12.5px;
  color: var(--text-dim);
}

.overlay-picks {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  max-width: 260px;
  margin: 0 auto;
}

.overlay-pick {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 14px;
  border-radius: var(--radius);
  font-size: 13.5px;
  text-align: left;
  cursor: pointer;
}
.overlay-pick > span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.overlay-pick-thumb {
  flex: 0 0 auto;
  width: 38px;
  height: 35px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--border);
  image-rendering: pixelated;
}
.overlay-pick-icon {
  flex: 0 0 auto;
  display: flex;
}
.overlay-pick-icon .icon { width: 16px; height: 16px; fill: currentColor; }
.overlay-pick.last {
  background: var(--accent-dim);
  border-color: var(--accent);
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.player-toolbar {
  width: 100%;
  max-width: 640px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
}

.now-playing-wrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  overflow: hidden;
}

.now-playing {
  font-size: 13px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.play-timer {
  font-size: 11px;
  color: var(--text-dim);
  opacity: 0.75;
  font-variant-numeric: tabular-nums;
}

.toolbar-buttons {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.toolbar-group {
  display: flex;
  gap: 6px;
  padding-right: 10px;
  border-right: 1px solid var(--border);
}
.toolbar-group:last-child {
  padding-right: 0;
  border-right: none;
}

.toolbar-buttons button {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 10px;
  border-radius: var(--radius);
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
}
.toolbar-buttons button:disabled {
  opacity: 0.4;
  cursor: default;
}
.toolbar-buttons button.icon-only {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
}
.toolbar-buttons button.icon-only .icon {
  width: 22px;
  height: 22px;
}
/* Confirm states (Reset/Save) need room for text, so they grow out of the
   fixed icon-square while armed and shrink back once resolved. */
.toolbar-buttons button.icon-only.armed {
  width: auto;
  padding: 0 14px;
  font-size: 12.5px;
  white-space: nowrap;
}
.toolbar-buttons button:not(:disabled):active { background: var(--border); }
.toolbar-buttons button.armed { background: var(--accent-dim); border-color: var(--accent); color: var(--text); }


.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translate(-50%, 8px);
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 100;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}
.toast.toast-success { background: var(--success-dim); border-color: var(--success); color: var(--text); }
.toast.toast-error { background: var(--error-dim); border-color: var(--error); color: var(--text); }

/* ---------- Pad layout editor ---------- */

.pad-editor {
  position: fixed;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  width: min(92vw, 340px);
  max-height: 70vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  z-index: 90;
}
.pad-editor.hidden { display: none; }

.pad-editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: -14px -14px 6px;
  padding: 12px 14px;
  border-radius: var(--radius) var(--radius) 0 0;
  cursor: grab;
  touch-action: none;
}
.pad-editor-header:active { cursor: grabbing; background: var(--accent-dim); }

.pad-editor-title {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
}

.pad-editor-drag-icon {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  color: var(--text-dim);
}

.pad-editor-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}
.pad-editor-actions button {
  flex: 1 1 auto;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: var(--radius);
  font-size: 12.5px;
  cursor: pointer;
}
.pad-editor-actions button:active { background: var(--border); }
#btn-pad-save {
  background: var(--accent-dim);
  border-color: var(--accent);
}

/* Applied to the D-Pad / A-B / Start / Select while in edit mode, so
   they're clearly identifiable as draggable and don't get confused with
   normal gameplay controls. */
.pad-editable {
  outline: 2px dashed var(--accent);
  outline-offset: 4px;
  border-radius: 12px;
  cursor: grab;
  touch-action: none;
  z-index: 50;
}
.pad-editable:active { cursor: grabbing; }

.kb-help {
  color: var(--text-dim);
  font-size: 12px;
  margin: 12px 0 0;
  text-align: center;
}

/* ---------- Virtual gamepad ---------- */

.gamepad {
  width: 100%;
  max-width: 640px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 18px;
  user-select: none;
  touch-action: none;
}

.dpad {
  position: relative;
  width: 132px;
  height: 132px;
  display: grid;
  grid-template-columns: 44px 44px 44px;
  grid-template-rows: 44px 44px 44px;
}

.dbtn {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.dbtn:active, .dbtn.pressed { background: var(--accent-dim); border-color: var(--accent); }
.dbtn .icon { width: 16px; height: 16px; }
.dbtn.right .icon { transform: rotate(90deg); }
.dbtn.down .icon { transform: rotate(180deg); }
.dbtn.left .icon { transform: rotate(270deg); }
.dbtn.up-right .icon { transform: rotate(45deg); }
.dbtn.down-right .icon { transform: rotate(135deg); }
.dbtn.down-left .icon { transform: rotate(225deg); }
.dbtn.up-left .icon { transform: rotate(315deg); }

.dbtn.up { grid-column: 2; grid-row: 1; border-radius: 6px 6px 0 0; }
.dbtn.left { grid-column: 1; grid-row: 2; border-radius: 6px 0 0 6px; }
.dbtn.right { grid-column: 3; grid-row: 2; border-radius: 0 6px 6px 0; }
.dbtn.down { grid-column: 2; grid-row: 3; border-radius: 0 0 6px 6px; }
.dpad-center { grid-column: 2; grid-row: 2; background: var(--panel-2); border: 1px solid var(--border); }

/* Corner buttons press two directions at once — a single finger on a
   touchscreen can't reliably hold two separate hit targets down together,
   so these give diagonal movement its own dedicated target. Dimmed relative
   to the primary 4 so they read as secondary. */
.dbtn.up-left { grid-column: 1; grid-row: 1; border-radius: 6px 0 0 0; opacity: 0.28; }
.dbtn.up-right { grid-column: 3; grid-row: 1; border-radius: 0 6px 0 0; opacity: 0.28; }
.dbtn.down-left { grid-column: 1; grid-row: 3; border-radius: 0 0 0 6px; opacity: 0.28; }
.dbtn.down-right { grid-column: 3; grid-row: 3; border-radius: 0 0 6px 0; opacity: 0.28; }
.dbtn.up-left:active, .dbtn.up-left.pressed,
.dbtn.up-right:active, .dbtn.up-right.pressed,
.dbtn.down-left:active, .dbtn.down-left.pressed,
.dbtn.down-right:active, .dbtn.down-right.pressed { opacity: 1; }

.abbtns {
  display: flex;
  align-items: flex-end;
  gap: 14px;
}
.abtn {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
}
.abtn.b { margin-bottom: 20px; }
.abtn:active, .abtn.pressed { background: var(--accent-dim); border-color: var(--accent); }

.metabtns {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mbtn {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 10.5px;
  letter-spacing: 0.5px;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
}
.mbtn:active, .mbtn.pressed { background: var(--accent-dim); border-color: var(--accent); color: var(--text); }

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  .hamburger { display: flex; }

  .layout { position: relative; overflow: hidden; }

  .rom-list {
    position: fixed;
    top: 57px;
    bottom: 0;
    left: 0;
    width: min(84vw, 340px);
    flex: none;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 30;
    box-shadow: 8px 0 24px rgba(0,0,0,0.4);
  }
  body.drawer-open .rom-list { transform: translateX(0); }

  .drawer-scrim {
    display: none;
    position: fixed;
    inset: 57px 0 0 0;
    background: rgba(0,0,0,0.5);
    z-index: 25;
  }
  body.drawer-open .drawer-scrim { display: block; }

  .player { padding: 12px 0; }

  /* No boxed-in "card" on phones — the screen should read as edge-to-edge. */
  .canvas-wrap {
    border: none;
    border-radius: 0;
    box-shadow: none;
  }

  .gamepad { margin-top: 22px; }
}

@media (max-width: 420px) {
  .brand span.label { display: none; }
}

/* D-pad/A-B sizing no longer needs a pointer:coarse or narrow-width
   override — the clamp()-based sizes on .dpad/.abtn above already scale
   with actual screen width, which is what those breakpoints were
   approximating with fixed steps (and which were fighting each other:
   pointer:coarse matched on every touch device regardless of orientation
   and, being last in source order, silently overrode both the narrow-
   width AND the landscape sizing meant for that specific case). */

/* Phones in landscape: two zones, stacked. Top zone is a 3-column row —
   D-pad (centered) + Start (bottom) on the left, the screen (top-aligned)
   in the middle, A/B (centered) + Select (bottom) on the right. Bottom
   zone is the info + toolbar strip, same content as portrait, just
   docked under the top zone instead of squeezed beside it. */
@media (orientation: landscape) and (max-height: 480px) {
  .player {
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-rows: 1fr auto;
    grid-template-areas: "left center right" "bottom bottom bottom";
    align-items: stretch;
    padding: 6px 8px;
    gap: 4px;
  }

  .kb-help { display: none; }

  .player-stage {
    grid-area: center;
    align-self: start;
    margin-top: 4px;
  }
  /* Reserve room for the topbar above and the toolbar row below, so the
     canvas never forces the grid to overflow/scroll. */
  .canvas-wrap { max-width: min(100%, calc((100vh - 120px) * var(--console-w) / var(--console-h))); }

  .player-toolbar {
    grid-area: bottom;
    margin-top: 0;
  }
  .toolbar-buttons button { padding: 5px 8px; font-size: 11.5px; }
  .toolbar-buttons button.icon-only { width: 34px; height: 34px; }
  .toolbar-buttons button.icon-only .icon { width: 17px; height: 17px; }

  /* Unwrap .gamepad and .metabtns so their contents become direct grid
     items — that's what lets the D-pad and Start end up in the same
     "left" area but positioned independently within it (same for
     A/B + Select on the right). */
  .gamepad, .metabtns { display: contents; }

  .dpad {
    grid-area: left;
    align-self: center;
    justify-self: center;
    width: 96px;
    height: 96px;
    grid-template-columns: 32px 32px 32px;
    grid-template-rows: 32px 32px 32px;
    touch-action: none;
  }
  .abbtns {
    grid-area: right;
    align-self: center;
    justify-self: center;
    touch-action: none;
  }
  .abtn { width: 44px; height: 44px; font-size: 13px; }
  .abtn.b { margin-bottom: 12px; }

  .mbtn {
    padding: 4px 9px;
    font-size: 9.5px;
    touch-action: none;
  }
  .mbtn[data-btn="START"] { grid-area: left; align-self: end; justify-self: center; margin-bottom: 4px; }
  .mbtn[data-btn="SELECT"] { grid-area: right; align-self: end; justify-self: center; margin-bottom: 4px; }
}

/* True fullscreen: no frame, no padding around the screen. The gamepad
   and toolbar stay visible (needed for touch play) so the canvas is
   sized to fill the space left after them, not the literal viewport. */
:fullscreen .player {
  justify-content: center;
  padding: 8px;
  background: #000;
}
:fullscreen .canvas-wrap {
  border: none;
  border-radius: 0;
  box-shadow: none;
}
