:root {
  --bg: #0e1016;
  --panel: #171b24;
  --panel-2: #202632;
  --line: #2c3342;
  --text: #ece7de;
  --muted: #8d94a3;
  --amber: #ff8a3d;
  --amber-dim: #c45f1c;
  --teal: #3ee0b4;
  --ps: #2e6cff;
  --danger: #ff5d6c;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  max-width: 100%;
  min-height: 100%;
  min-height: 100dvh;
  background-color: var(--bg);
  background-image:
    radial-gradient(1200px 600px at 10% -10%, #1b2436 0%, transparent 55%),
    radial-gradient(900px 500px at 110% 10%, #2a1a12 0%, transparent 50%);
  background-attachment: fixed;
  color: var(--text);
  font-family: Sora, sans-serif;
}

html { overflow-x: clip; }
body {
  display: block;
  overflow-x: clip;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: #0e1016; }
::-webkit-scrollbar-thumb { background: #2c3342; border-radius: 8px; }

.crt-overlay {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 80;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0 2px,
    rgba(0, 0, 0, 0.08) 2px 3px
  );
  mix-blend-mode: multiply;
}

.hidden, [hidden] { display: none !important; }

/* Capivara/Atlas: o rail mobile força Salvar/Abrir — esta classe vence. */
body.no-hub-saves #btn-save,
body.no-hub-saves #btn-load {
  display: none !important;
}

body.mode-playing #view-library,
body.mode-playing #view-login,
body.mode-library #view-player,
body.mode-library #view-login,
body.mode-login #view-library,
body.mode-login #view-player,
body.mode-boot #view-login,
body.mode-boot #view-library,
body.mode-boot #view-player { display: none !important; }

body.mode-playing {
  overflow: hidden;
  background-color: #0e1016;
}

body.mode-playing .topbar {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
}

body.mode-playing #view-player {
  position: fixed;
  left: 0;
  right: 0;
  top: 73px;
  bottom: 0;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 16px 16px 20px;
  background: #0e1016;
  z-index: 5;
  overflow: hidden;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 16px;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  padding: 16px 28px;
  background: rgba(14, 16, 22, 0.86);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
  overflow: hidden;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 0;
  background: none;
  color: inherit;
  cursor: pointer;
  padding: 0;
  flex: 0 1 auto;
  min-width: 0;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  background: var(--amber);
  color: #1a1008;
  font-family: Tektur, sans-serif;
  font-size: 22px;
  border-radius: 8px;
}

.brand strong {
  display: block;
  font-family: Tektur, sans-serif;
  letter-spacing: 0.12em;
  font-size: 18px;
}

.brand small {
  color: var(--muted);
  letter-spacing: 0.18em;
  font-size: 10px;
}

.topbar-status {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px 14px;
  min-width: 0;
  flex: 1 1 auto;
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  color: var(--muted);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.lang-wrap {
  display: inline-flex;
  align-items: center;
  margin: 0;
}

.lang-wrap select {
  appearance: none;
  background: #12151c;
  color: var(--text, #e8eaef);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px 28px 4px 10px;
  font: inherit;
  font-size: 11px;
  letter-spacing: 0.04em;
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 12px) 55%, calc(100% - 8px) 55%;
  background-size: 4px 4px, 4px 4px;
  background-repeat: no-repeat;
  max-width: 11rem;
}

.lang-wrap select:focus {
  outline: 1px solid var(--teal);
  outline-offset: 2px;
}

.pad-status {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  max-width: 52vw;
}
.pad-status .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #5a6170;
}
.pad-status.online .dot { background: var(--teal); box-shadow: 0 0 10px var(--teal); }
.pad-status.online { color: var(--teal); }

.build-chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #12151c;
  color: var(--amber);
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.kicker #login-build,
.kicker #lib-build {
  color: var(--amber);
  font-family: "IBM Plex Mono", monospace;
}

.user-chip {
  color: var(--text);
  max-width: 28vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ghost-link {
  border: 0;
  background: none;
  color: var(--amber);
  font: inherit;
  cursor: pointer;
  padding: 0;
}

body.mode-login .pad-status,
body.mode-login #btn-logout,
body.mode-login #user-chip { display: none !important; }

.login-card {
  width: min(440px, 100%);
  margin: 48px auto 0;
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.login-card form {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.login-card label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.login-card input {
  background: #11141b;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 14px;
  font: inherit;
}

.login-submit { width: 100%; padding: 12px 14px; }
#login-error { color: var(--danger); margin: 0; }
#register-disabled { color: var(--muted); margin: 0; }
#login-info { color: var(--teal); margin: 0; }
.auth-links { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px 16px; margin: 0; font-size: 13px; }

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 16px;
}

.auth-tab {
  border: 1px solid var(--line);
  background: #11141b;
  color: var(--muted);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  cursor: pointer;
}

.auth-tab.on {
  color: var(--text);
  border-color: var(--amber);
  background: color-mix(in srgb, var(--amber) 14%, #11141b);
}

.login-submit:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

#view-login,
#view-library,
#view-player {
  width: 100%;
  max-width: none;
  margin: 0;
}

#view-login,
#view-library {
  padding: 28px 48px 80px;
}

#view-player {
  padding: 20px 24px 40px;
}

#view-login[hidden],
#view-library[hidden],
#view-player[hidden],
#view-login.hidden,
#view-library.hidden,
#view-player.hidden {
  display: none !important;
}

.hero h1 {
  margin: 8px 0 12px;
  font-family: Tektur, sans-serif;
  font-size: clamp(28px, 5vw, 48px);
  line-height: 1.05;
}

.kicker {
  margin: 0;
  color: var(--amber);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 11px;
  font-family: "IBM Plex Mono", monospace;
}

.lede { max-width: 680px; color: var(--muted); line-height: 1.6; }

.toolbar {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 16px;
  margin-top: 28px;
}

.search, .filter {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.search input, .filter select, .modal input, .file-pick {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 14px;
  font: inherit;
}

.search input, .filter select, .modal input, .file-pick, .login-card input {
  font-size: 16px;
}

.search input { width: min(420px, 80vw); }

#btn-cheats,
#btn-favs {
  align-self: end;
}

#btn-cheats.on {
  background: var(--teal);
  color: #082018;
  border-color: var(--teal);
}

#cheat-form {
  display: grid;
  gap: 16px;
}

#cheat-code {
  font-size: 22px;
  letter-spacing: 0.18em;
  text-align: center;
}

#cheat-code {
  font-size: 22px;
  letter-spacing: 0.18em;
  text-align: center;
}

.library {
  margin-top: 36px;
  display: grid;
  gap: 36px;
}

.system-shelf { display: grid; gap: 14px; }

.system-shelf h2 {
  margin: 0;
  font-family: Tektur, sans-serif;
  font-size: 20px;
  letter-spacing: 0.04em;
}

.system-shelf .shelf-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.system-shelf .count {
  color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
}

.shelf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, 230px);
  justify-content: start;
  gap: 18px;
}

.shelf-locked {
  min-height: 120px;
  display: grid;
  place-items: center;
  padding: 28px 20px;
  border: 1px dashed var(--line);
  border-radius: 16px;
  color: var(--muted);
  text-align: center;
  line-height: 1.6;
}

.shelf-locked strong {
  display: block;
  color: var(--amber);
  margin-bottom: 6px;
  font-family: Tektur, sans-serif;
}

.card {
  position: relative;
  width: 230px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  text-align: left;
  color: inherit;
  padding: 0;
  box-shadow: var(--shadow);
  transition: transform 0.18s ease, border-color 0.18s ease;
}

.card-open {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.fav-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(14, 16, 22, 0.86);
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}

.fav-btn.on,
.card.is-fav .fav-btn {
  color: var(--amber);
  border-color: var(--amber);
}

.card.has-cheats-off .card-body {
  padding-bottom: 52px;
}
.cheats-off-btn {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  z-index: 2;
  border: 1px solid var(--danger);
  border-radius: 10px;
  background: rgba(14, 16, 22, 0.92);
  color: var(--danger);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 8px 10px;
  cursor: pointer;
}
.cheats-off-btn:hover,
.cheats-off-btn:focus-visible {
  background: var(--danger);
  color: #fff;
  outline: none;
}
.cheats-off-btn.restore {
  border-color: var(--teal);
  color: var(--teal);
}
.cheats-off-btn.restore:hover,
.cheats-off-btn.restore:focus-visible {
  background: var(--teal);
  color: #0e1016;
}

.system-pick {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}

.system-chip {
  display: grid;
  gap: 4px;
  text-align: left;
  padding: 16px 18px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.system-chip strong {
  font-family: Tektur, sans-serif;
  font-size: 15px;
}

.system-chip span {
  color: var(--muted);
  font-size: 12px;
  font-family: "IBM Plex Mono", monospace;
}

.system-chip.fav {
  border-color: var(--amber);
  color: var(--amber);
}

.system-chip:hover,
.system-chip:focus-visible {
  border-color: var(--amber);
  outline: none;
}

.overview-hint { margin: 0 0 8px; }

.more-btn {
  margin-top: 8px;
  width: 100%;
  border: 1px dashed var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 12px;
  padding: 14px;
  font: inherit;
  cursor: pointer;
}

.more-btn:hover {
  color: var(--text);
  border-color: var(--amber);
}

#btn-favs.on,
#btn-favorite.on {
  background: var(--amber);
  color: #1a1008;
  border-color: var(--amber);
}

.card:hover, .card:focus-visible {
  transform: translateY(-4px);
  border-color: var(--amber);
  outline: none;
}

.cover {
  height: 148px;
  display: grid;
  place-items: center;
  background:
    linear-gradient(135deg, rgba(255,138,61,0.18), rgba(46,108,255,0.16)),
    #12151d;
  font-family: Tektur, sans-serif;
  font-size: 34px;
  color: var(--amber);
}

.cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card-body { padding: 14px 14px 16px; }
.card-body h2 {
  margin: 0 0 6px;
  font-size: 16px;
  line-height: 1.25;
}
.card-body p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-family: "IBM Plex Mono", monospace;
}

.empty {
  grid-column: 1 / -1;
  padding: 48px 24px;
  border: 1px dashed var(--line);
  border-radius: 16px;
  color: var(--muted);
  line-height: 1.7;
}

.player-shell {
  width: 100%;
  max-width: 100%;
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  grid-template-areas:
    "rail screen"
    "rail touch";
  gap: 18px;
  align-items: start;
}

.player-rail { grid-area: rail; }
.screen-wrap { grid-area: screen; }

.player-rail {
  position: relative;
  z-index: 6;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* iOS 15+: user-agent força color:-apple-system-blue em <button>. */
button {
  color: inherit;
  -webkit-appearance: none;
  appearance: none;
}

.rail-btn, .modal footer button, .slot button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 14px;
  font: inherit;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

.rail-btn.accent, .accent {
  background: var(--amber);
  color: #1a1008;
  border-color: var(--amber);
  font-weight: 700;
}

.ghost {
  background: transparent;
  color: var(--text);
}

.lib-foot {
  margin-top: 12px;
}

.lib-foot .ghost,
button#btn-lib-reset {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.lib-foot .ghost:hover,
button#btn-lib-reset:hover {
  border-color: var(--amber);
  color: var(--amber);
}

.now-playing {
  margin-top: 12px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.now-playing small {
  color: var(--amber);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 10px;
}

.now-playing strong { display: block; margin: 6px 0 4px; }
.now-playing span { color: var(--muted); font-size: 12px; }

.screen-wrap {
  position: relative;
  z-index: 1;
  min-width: 0;
  overflow: hidden;
}

.bezel {
  position: relative;
  background: #07080c;
  border: 8px solid #2a241c;
  box-shadow: inset 0 0 0 2px #5a4a38, var(--shadow);
  border-radius: 18px;
  overflow: hidden;
  min-height: 62vh;
}

.speed-dock {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 4px;
  padding: 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
}

/* span, não <button>: iOS Safari pinta botão de azul (-apple-system-blue). */
.speed-dock .speed-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  min-width: 32px;
  min-height: 32px;
  margin: 0;
  border: 0;
  border-radius: 7px;
  padding: 6px 8px;
  background: transparent;
  color: #ece7de;
  font: 700 13px Tektur, sans-serif;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

.speed-dock .speed-btn.on {
  background: #ff8a3d;
  color: #1a1008;
}

#game-stage {
  width: 100%;
  height: calc(100dvh - 200px);
  background: #000;
  overflow: hidden;
  position: relative;
}

  /* Godot / Atlas: desktop também precisa de stage com altura real (senão iframe = 0). */
body.mode-playing.html-fill .player-shell {
  align-items: stretch;
  grid-template-rows: minmax(0, 1fr) auto;
  min-height: calc(100dvh - 110px);
}
body.mode-playing.html-fill .screen-wrap,
body.mode-playing.html-fill .bezel {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
body.mode-playing.html-fill #game-stage {
  flex: 1 1 auto;
  width: 100%;
  height: calc(100dvh - 180px);
  min-height: 420px;
  position: relative;
}
body.mode-playing.html-fill #game-stage iframe.html-fill-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  border: 0;
  display: block;
  background: #000;
}

/* Atlas/Capivara: o jogo tem controles próprios — some o painel J1/J2 do hub. */
body.mode-playing.html-fill .input-hud {
  display: none !important;
}

@media (hover: none) and (pointer: coarse) {
  /* No telefone o stage preenche o flex — não forçar 100dvh (corta o mapa). */
  body.mode-playing.html-fill .player-shell {
    min-height: 0;
    height: 100%;
  }
  body.mode-playing.html-fill #game-stage {
    height: 100% !important;
    min-height: 0 !important;
    flex: 1 1 auto;
  }
  body.mode-playing.html-fill .player-rail .rail-btn:not(#btn-back):not(#btn-sound) {
    display: none !important;
  }
  body.mode-playing.html-fill .speed-dock {
    display: none !important;
  }
  body.mode-playing.html-fill.has-touch-pad .screen-wrap {
    padding-bottom: calc(270px + env(safe-area-inset-bottom));
  }
  /* Capivara (fill sem pad do hub): sem faixa preta reservada para teclado/pad. */
  body.mode-playing.html-fill:not(.has-touch-pad) .screen-wrap {
    padding-bottom: 0 !important;
  }
}

#game .ejs_virtualGamepad,
#game [class*="virtualGamepad"],
#game [class*="ejs_virtual"],
#game .nipple,
#game .ejs_dpad {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

.input-hud {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 12px;
  margin-top: 10px;
  padding: 10px 12px;
  background: #171b24;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 12px;
  line-height: 1.45;
}

.hud-col strong {
  display: block;
  color: var(--amber);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.hud-col span { color: var(--muted); }

.pad-switch { display: flex; gap: 6px; margin-top: 6px; }

.pad-switch button {
  border: 1px solid var(--line);
  background: #11141b;
  color: var(--text);
  border-radius: 8px;
  padding: 6px 10px;
  font: inherit;
  cursor: pointer;
}

.pad-switch button.on {
  background: var(--amber);
  color: #1a1008;
  border-color: var(--amber);
  font-weight: 700;
}

#game-stage iframe,
#game-stage #ejs-container,
#game-stage > div {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

/* Menos filtro no canvas = composição mais rápida (menos atraso visual). */
#game canvas,
#game-stage canvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  transform: translateZ(0);
  backface-visibility: hidden;
}

.audio-unlock {
  position: absolute;
  inset: 0;
  z-index: 14;
  border: 0;
  margin: 0;
  padding: 24px;
  background: rgba(8, 10, 16, 0.72);
  color: #ece7de;
  font: 700 18px Tektur, sans-serif;
  letter-spacing: 0.04em;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}
.audio-unlock-body,
.continue-gate {
  position: fixed;
  inset: 0;
  z-index: 2147483646;
  border: 0;
  margin: 0;
  padding: 24px;
  background: rgba(8, 10, 16, 0.88);
  color: #ece7de;
  font: 700 22px Tektur, sans-serif;
  letter-spacing: 0.04em;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}
#game-stage > .html-load-error {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex !important;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  background: #0e1016;
  color: #ece7de;
  text-align: center;
}
.html-load-error p {
  margin: 0;
  font: 700 20px Tektur, sans-serif;
  letter-spacing: 0.04em;
}
.html-load-error small {
  color: var(--muted);
  font-size: 14px;
}
.html-load-error button {
  margin-top: 8px;
  padding: 12px 22px;
  border: 1px solid var(--amber);
  border-radius: 10px;
  background: transparent;
  color: var(--amber);
  font: 700 16px Tektur, sans-serif;
  cursor: pointer;
  touch-action: manipulation;
}
body.play-gate-open #touch-pad,
body.play-gate-open .touch-pad {
  pointer-events: none !important;
  opacity: 0.35;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  width: 100%;
  height: 100%;
  background: rgba(6, 8, 12, 0.72);
  display: grid;
  place-items: start center;
  align-content: start;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  transform: translateZ(0);
}

.modal-card {
  width: min(520px, 100%);
  margin-top: 8vh;
  background: #161a22;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px;
  box-shadow: var(--shadow);
}

.modal-card.wide { width: min(860px, 100%); }

.memory-card header p,
.modal-card header p {
  margin: 0;
  color: var(--teal);
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.modal-card h2 { margin: 6px 0 18px; font-family: Tektur, sans-serif; }

.modal-card label {
  display: grid;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

.file-pick {
  display: grid;
  gap: 8px;
}
.file-pick input[type="file"] {
  width: 100%;
  min-height: 44px;
  font-size: 16px;
}

.hint { color: var(--muted); font-size: 13px; line-height: 1.5; }

.modal-card footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.save-list { display: grid; gap: 8px; margin-bottom: 16px; max-height: min(320px, 42vh); overflow: auto; }

.slot {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}

.slot-main {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 4px;
  text-align: left;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  padding: 0;
  cursor: pointer;
}

.slot strong { display: block; }
.slot small { color: var(--muted); }
.slot .actions { display: flex; gap: 8px; }

#btn-pad-modal { margin: 12px 0 8px; width: 100%; }

#btn-game-cheats.on {
  border-color: var(--teal);
  color: var(--teal);
}

body.modal-open #touch-pad,
body.modal-open .touch-pad {
  display: none !important;
}

/* Cabe na tela: só a lista rola; cabeçalho, busca e rodapé ficam sempre visíveis. */
#modal-game-cheats .modal-card {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 8vh - 48px);
  max-height: calc(100dvh - 8vh - 48px);
}
#modal-game-cheats .modal-card > * { flex: none; }
#modal-game-cheats .modal-card > .gc-list {
  flex: 1 1 auto;
  min-height: 96px;
  max-height: none;
}

.gc-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.gc-close {
  flex: none;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}

.gc-search input,
.gc-add input {
  width: 100%;
  min-height: 44px;
  font-size: 16px;
}
.gc-search { margin-bottom: 4px; }

.gc-progress {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 8px 0 0;
  padding: 10px 12px;
  border: 1px solid var(--teal);
  border-radius: 10px;
  background: var(--panel-2);
}
.gc-progress[hidden] { display: none; }
.gc-progress progress { width: 100%; height: 10px; accent-color: var(--teal); }
.gc-progress small { color: var(--muted); font-size: 12px; }

.gc-list {
  display: grid;
  align-content: start;
  gap: 6px;
  max-height: min(420px, 48vh);
  overflow: auto;
  overscroll-behavior: contain;
  margin: 8px 0 14px;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

.gc-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px 8px 4px 4px;
}
.gc-row.on { border-color: var(--teal); }

.gc-toggle {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  padding: 8px;
  cursor: pointer;
  touch-action: manipulation;
}

.gc-switch {
  flex: none;
  position: relative;
  width: 40px;
  height: 22px;
  border-radius: 999px;
  background: var(--line);
  transition: background 0.15s;
}
.gc-switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text);
  transition: transform 0.15s;
}
.gc-row.on .gc-switch { background: var(--teal); }
.gc-row.on .gc-switch::after { transform: translateX(18px); }

.gc-text { display: grid; gap: 2px; min-width: 0; }
.gc-text strong { font-size: 14px; overflow-wrap: anywhere; }
.gc-text small { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.gc-text code { font-family: "IBM Plex Mono", monospace; }

.gc-row.blocked { border-color: var(--danger); }
.gc-text .gc-tally { color: var(--amber); }
.gc-row.blocked .gc-text .gc-tally { color: var(--danger); }

.gc-actions {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  max-width: 128px;
}
.gc-actions .gc-voted { color: var(--muted); font-size: 11px; text-align: center; }

.gc-row .gc-remove,
.gc-row .gc-vote {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.gc-add { margin-bottom: 6px; }
.gc-add summary { cursor: pointer; color: var(--teal); font-size: 14px; padding: 6px 0; }
.gc-add form { display: grid; gap: 10px; margin-top: 10px; }
.gc-add button { justify-self: start; border-radius: 10px; padding: 12px 14px; font: inherit; cursor: pointer; }

.controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.key-map {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

kbd {
  display: inline-block;
  min-width: 22px;
  padding: 2px 6px;
  margin-right: 2px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: #11141b;
  color: var(--text);
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  text-align: center;
}

.pad-svg { width: 100%; height: auto; }
.pad-body { fill: #2a3140; }
.btn { fill: #12151c; stroke: #4a5160; stroke-width: 1.5; }
.btn.face.x { stroke: #7ec8ff; }
.btn.face.o { stroke: #ff8a9a; }
.btn.face.sq { stroke: #d6a6ff; }
.btn.face.tri { stroke: #7cffc4; }
.btn.on { fill: var(--amber); stroke: var(--amber); }

#pad-name {
  text-align: center;
  color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
}

.toast {
  position: fixed;
  bottom: 22px;
  right: 22px;
  z-index: 10001;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 12px 16px;
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.lib-loading {
  position: fixed;
  inset: 0;
  z-index: 10050;
  display: grid;
  place-items: center;
  background: rgba(8, 10, 14, 0.55);
  backdrop-filter: blur(2px);
}

.lib-loading.hidden { display: none; }

.lib-loading-card {
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 22px 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  color: var(--text);
}

.lib-loading-card p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.lib-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--line);
  border-top-color: var(--amber);
  border-radius: 50%;
  animation: lib-spin 0.7s linear infinite;
}

@keyframes lib-spin {
  to { transform: rotate(360deg); }
}

/* Cobre a troca de página ao abrir save: some só quando o jogo já está rodando no save. */
.boot-cover {
  position: fixed;
  inset: 0;
  z-index: 2147483600;
  display: grid;
  place-items: center;
  background: #0e1016;
  opacity: 1;
  transition: opacity 0.35s ease;
}

.boot-cover[hidden] { display: none; }

.boot-cover.leaving {
  opacity: 0;
  pointer-events: none;
}

.boot-cover-card {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 24px 32px;
  max-width: min(86vw, 420px);
  text-align: center;
  color: var(--text);
}

.boot-cover-card strong {
  font-size: 16px;
}

.boot-cover-card strong:empty { display: none; }

.boot-cover-card p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.touch-pad {
  display: none;
  grid-area: touch;
  margin-top: 10px;
  padding: 10px 8px 12px;
  background: rgba(10, 12, 16, 0.88);
  border: 1px solid var(--line);
  border-radius: 16px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

body.has-touch-pad .touch-pad {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-areas:
    "shoulders shoulders"
    "dpad face"
    "menu menu";
  gap: 10px;
  align-items: center;
}

body.has-touch-pad .touch-pad.no-shoulders {
  grid-template-areas:
    "dpad face"
    "menu menu";
}

body.has-touch-pad .touch-pad.no-shoulders .touch-shoulders { display: none; }

body.has-touch-pad .input-hud { display: none; }

.touch-shoulders {
  grid-area: shoulders;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
}

.touch-dpad { grid-area: dpad; }
.touch-face { grid-area: face; justify-self: end; }
.touch-menu { grid-area: menu; display: flex; justify-content: center; gap: 16px; }

.touch-pad button {
  border: 1px solid #3a4254;
  background: #1b2130;
  color: var(--text);
  border-radius: 999px;
  font: 700 14px Tektur, sans-serif;
  min-width: 52px;
  min-height: 52px;
  touch-action: none;
  pointer-events: auto;
}

/* Sem filter/transform: em tablet Samsung antigo isso atrasava cada toque do pad. */
.touch-pad button.is-down,
.touch-pad button:active {
  background: #3a4660;
  border-color: var(--amber);
}

.touch-shoulders button {
  flex: 1;
  min-width: 0;
  min-height: 36px;
  border-radius: 10px;
}

.touch-dpad {
  width: 156px;
  height: 156px;
  display: grid;
  grid-template-columns: 48px 48px 48px;
  grid-template-rows: 48px 48px 48px;
  gap: 2px;
  place-items: center;
  justify-content: center;
}

.touch-dpad [data-touch="up"] { grid-column: 2; grid-row: 1; }
.touch-dpad [data-touch="left"] { grid-column: 1; grid-row: 2; }
.touch-dpad [data-touch="right"] { grid-column: 3; grid-row: 2; }
.touch-dpad [data-touch="down"] { grid-column: 2; grid-row: 3; }
.touch-dpad [data-touch="up,left"] { grid-column: 1; grid-row: 1; }
.touch-dpad [data-touch="up,right"] { grid-column: 3; grid-row: 1; }
.touch-dpad [data-touch="down,left"] { grid-column: 1; grid-row: 3; }
.touch-dpad [data-touch="down,right"] { grid-column: 3; grid-row: 3; }

.touch-dpad .dpad-hub {
  grid-column: 2;
  grid-row: 2;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.touch-dpad button.diag {
  min-width: 44px;
  min-height: 44px;
  font-size: 0.85rem;
  opacity: 0.72;
}

.touch-face[data-face="diamond"] {
  width: 150px;
  height: 150px;
  display: grid;
  grid-template-columns: 48px 48px 48px;
  grid-template-rows: 48px 48px 48px;
  place-items: center;
}

.touch-face[data-face="diamond"] .face-x { grid-column: 2; grid-row: 1; }
.touch-face[data-face="diamond"] .face-y { grid-column: 1; grid-row: 2; }
.touch-face[data-face="diamond"] .face-a { grid-column: 3; grid-row: 2; }
.touch-face[data-face="diamond"] .face-b { grid-column: 2; grid-row: 3; }

.touch-face[data-face="pair"] {
  width: 148px;
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
}

.touch-face[data-face="pair"] button {
  min-width: 64px;
  min-height: 64px;
}

.touch-face[data-face="genesis"] {
  width: 168px;
  display: grid;
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: 52px 52px;
  gap: 6px;
  place-items: center;
}

.touch-face[data-face="genesis"] button {
  min-width: 48px;
  min-height: 48px;
}

.touch-face[data-face="n64"] {
  width: 196px;
  height: 132px;
  display: grid;
  grid-template-columns: 40px 40px 40px 12px 52px;
  grid-template-rows: 40px 40px 40px;
  gap: 4px;
  place-items: center;
}

.touch-face[data-face="n64"] .face-c-up { grid-column: 2; grid-row: 1; }
.touch-face[data-face="n64"] .face-c-left { grid-column: 1; grid-row: 2; }
.touch-face[data-face="n64"] .face-c-right { grid-column: 3; grid-row: 2; }
.touch-face[data-face="n64"] .face-c-down { grid-column: 2; grid-row: 3; }
.touch-face[data-face="n64"] .face-n64-b { grid-column: 5; grid-row: 1; }
.touch-face[data-face="n64"] .face-n64-a {
  grid-column: 5;
  grid-row: 2 / 4;
  min-height: 84px;
}

.touch-face[data-face="n64"] .face-c-up,
.touch-face[data-face="n64"] .face-c-left,
.touch-face[data-face="n64"] .face-c-right,
.touch-face[data-face="n64"] .face-c-down {
  min-width: 40px;
  min-height: 40px;
  font-size: 11px;
  background: #e6c14a;
  color: #1a1408;
}

.face-x { background: #2e6cff; color: #fff; }
.face-y { background: #2f9e5a; color: #06140c; }
.face-a, .face-n64-a, .face-md-c { background: #c45f1c; color: #1a1008; }
.face-b, .face-n64-b, .face-md-b { background: #e6c14a; color: #1a1408; }
.face-n64-a { background: #2e6cff; color: #fff; }
.face-n64-b { background: #2f9e5a; color: #06140c; }
.face-md-x, .face-md-y, .face-md-z { background: #2a3344; color: #ece7de; }
.face-md-a { background: #c45f1c; color: #1a1008; }

.touch-pad[data-layout="psx"] .face-x { background: #2f9e5a; color: #06140c; }
.touch-pad[data-layout="psx"] .face-y { background: #e08ad4; color: #1a1018; }
.touch-pad[data-layout="psx"] .face-a { background: #ff5d6c; color: #fff; }
.touch-pad[data-layout="psx"] .face-b { background: #6cb6ff; color: #081018; }

.touch-menu button {
  min-width: 88px;
  min-height: 36px;
  border-radius: 10px;
  font-size: 12px;
}

@media (max-width: 860px) {
  .player-shell, .controls-grid { grid-template-columns: 1fr; }
  #view-library, #view-login { padding: 20px 16px calc(72px + env(safe-area-inset-bottom)); }
  #view-player { padding: 16px; }
  .topbar {
    padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
    gap: 8px 10px;
  }
  .brand { gap: 8px; }
  .brand-mark { width: 32px; height: 32px; font-size: 18px; }
  .brand strong { font-size: 15px; letter-spacing: 0.08em; }
  .brand small { display: none; }
  .topbar-status {
    gap: 8px;
    flex: 1 1 0;
    max-width: 100%;
  }
  .lang-wrap { flex: 0 1 auto; min-width: 0; }
  .lang-wrap select {
    max-width: min(9.5rem, 42vw);
    padding: 4px 22px 4px 8px;
    font-size: 10px;
  }
  .user-chip {
    max-width: 7.5rem;
    font-size: 11px;
  }
  .ghost-link { font-size: 11px; }
  .pad-status,
  .clock { display: none; }
  .build-chip { order: -1; flex-shrink: 0; }
  .input-hud { grid-template-columns: 1fr; }
  .shelf-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .card { width: 100%; }
}

@media (max-width: 420px) {
  .user-chip { display: none; }
  .lang-wrap select { max-width: min(8.5rem, 48vw); }
}

@media (hover: none) and (pointer: coarse) {
  body.mode-playing .crt-overlay { display: none; }
  body.mode-playing .topbar { display: none; }
  body.mode-playing #view-player {
    top: 0;
    padding: 0;
    width: 100%;
    max-width: none;
  }
  body.mode-playing .player-shell {
    display: flex;
    flex-direction: column;
    /* Com "start" a tela do jogo nasce com largura 0 e o WebKit (iPhone) não pinta mais o canvas WebGL. */
    align-items: stretch;
    height: 100%;
    gap: 0;
  }
  body.mode-playing .player-rail {
    position: relative;
    top: auto;
    left: auto;
    z-index: 40;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    width: 100%;
    max-width: none;
    flex-shrink: 0;
    gap: 6px;
    padding: calc(8px + env(safe-area-inset-top)) 8px 8px;
    background: #0e1016;
    border-bottom: 1px solid var(--line);
  }
  body.mode-playing .player-rail .rail-btn:not(#btn-back):not(#btn-save):not(#btn-load):not(#btn-favorite):not(#btn-sound):not(#btn-game-cheats) { display: none; }
  body.mode-playing .now-playing { display: none; }
  body.mode-playing .rail-btn { padding: 7px 9px; font-size: 12px; }
  body.mode-playing .speed-dock {
    margin-left: auto;
    background: transparent;
    border: 0;
    padding: 0;
    flex-shrink: 0;
  }
  body.mode-playing .speed-dock .speed-btn {
    color: #ece7de;
  }
  body.mode-playing .speed-dock .speed-btn.on {
    background: #ff8a3d;
    color: #1a1008;
  }
  body.mode-playing .screen-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: visible;
    padding-bottom: calc(250px + env(safe-area-inset-bottom));
  }
  body.mode-playing .bezel {
    flex: 1;
    min-height: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }
  body.mode-playing #game-stage {
    height: 100%;
    min-height: 42vh;
  }
  body.mode-playing.has-touch-pad .touch-pad,
  body.has-touch-pad > #touch-pad {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2147483000;
    margin: 0;
    border-radius: 16px 16px 0 0;
    padding: 10px 10px calc(12px + env(safe-area-inset-bottom));
    pointer-events: auto !important;
    -webkit-user-select: none;
    user-select: none;
  }
  body.has-touch-pad .ejs_virtualGamepad,
  body.has-touch-pad [class*="virtualGamepad"],
  body.has-touch-pad [class*="ejs_virtual"],
  body.has-touch-pad .nipple {
    display: none !important;
    pointer-events: none !important;
  }
  body.has-touch-pad:not(.html-fill) .bezel,
  body.has-touch-pad:not(.html-fill) #game-stage,
  body.has-touch-pad:not(.html-fill) #game,
  body.has-touch-pad:not(.html-fill) #game canvas {
    pointer-events: none !important;
  }
  /* Popup “Click to resume” do EmulatorJS precisa receber toque no iOS. */
  body.has-touch-pad .ejs_popup_container,
  body.has-touch-pad .ejs_popup_container * {
    pointer-events: auto !important;
  }
  body.has-touch-pad[data-pad="nds"] .bezel,
  body.has-touch-pad[data-pad="nds"] #game-stage,
  body.has-touch-pad[data-pad="nds"] #game,
  body.has-touch-pad[data-pad="nds"] #game canvas {
    pointer-events: auto !important;
  }
  /* Atlas/Godot: clique/toque no iframe — nunca bloquear (menus, mapa, botões). */
  body.html-fill.has-touch-pad .bezel,
  body.html-fill.has-touch-pad #game-stage,
  body.html-fill.has-touch-pad #game-stage iframe.html-fill-frame {
    pointer-events: auto !important;
  }
  /* iOS: iframe absoluto preenche o stage — senão colapsa no tamanho do splash. */
  body.mode-playing.html-fill #game-stage {
    position: relative !important;
    width: 100% !important;
    height: 100% !important;
    min-height: 42vh;
    overflow: hidden;
    display: block;
  }
  body.mode-playing.html-fill #game-stage iframe.html-fill-frame {
    position: absolute !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    max-width: none !important;
    max-height: none !important;
    margin: 0 !important;
    border: 0 !important;
    display: block !important;
    background: #000;
  }
  body.mode-playing.has-touch-pad:has(.touch-pad.no-shoulders) .screen-wrap {
    padding-bottom: calc(220px + env(safe-area-inset-bottom));
  }
  body.mode-playing.has-touch-pad:has(.touch-pad[data-layout="segaMD"]) .screen-wrap,
  body.mode-playing.has-touch-pad:has(.touch-pad[data-layout="n64"]) .screen-wrap,
  body.mode-playing.has-touch-pad:has(.touch-pad[data-layout="psx"]) .screen-wrap,
  body.mode-playing.has-touch-pad:has(.touch-pad[data-layout="godot"]) .screen-wrap {
    padding-bottom: calc(300px + env(safe-area-inset-bottom));
  }
  body.modal-open .touch-pad {
    display: none !important;
  }
  body.modal-open .screen-wrap,
  body.modal-open #game-stage,
  body.modal-open #game {
    pointer-events: none !important;
  }
  .modal-card { margin-top: 12px; }
  .slot {
    flex-wrap: wrap;
  }
  .slot .actions {
    width: 100%;
    justify-content: flex-end;
  }
  .slot .actions button {
    min-height: 44px;
    min-width: 88px;
  }
}

@media (max-width: 860px), (hover: none) and (pointer: coarse) {
  #modal-game-cheats {
    padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom));
  }
  #modal-game-cheats .modal-card {
    margin-top: 0;
    padding: 14px;
    border-radius: 14px;
    max-height: calc(100vh - 16px);
    max-height: calc(100dvh - max(8px, env(safe-area-inset-top)) - max(8px, env(safe-area-inset-bottom)));
  }
  #modal-game-cheats .modal-card h2 { margin: 2px 0 8px; font-size: 20px; }
  #modal-game-cheats .gc-list { margin: 6px 0 8px; }
  #modal-game-cheats .gc-note { display: none; }
  #modal-game-cheats #gc-status { margin: 6px 0 0; font-size: 12px; }
  #modal-game-cheats footer { margin-top: 8px; }
  #modal-game-cheats footer button { flex: 1; min-height: 44px; }
}
