/* ============================================================================
 * GBA emulator player - /arcade/<gba-game>/ pages.
 * Desktop: the game fills the viewport. Mobile: the game sits on top with a
 * custom on-screen gamepad below it. EmulatorJS's own floating pad is hidden.
 * ========================================================================== */

:root {
  --gba-pink: #e879f9;
  --gba-purple: #a855f7;
  --gba-bg: #0d0015;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background:
    radial-gradient(circle at 20% 0%, rgba(168,85,247,0.16), transparent 45%),
    radial-gradient(circle at 80% 100%, rgba(232,121,249,0.10), transparent 50%),
    var(--gba-bg);
  color: #fff;
  min-height: 100vh;
  padding-top: 60px;
  -webkit-tap-highlight-color: transparent;
}

.gba-wrap {
  max-width: 1400px;
  margin: 0 auto;
  padding: 14px 16px 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

/* The screen. 3:2 (GBA aspect). Desktop: as tall as the viewport allows.  */
.gba-stage {
  aspect-ratio: 3 / 2;
  width: auto;
  height: calc(100vh - 96px);
  max-width: 100%;
  min-height: 260px;
  margin: 0 auto;
  background: #000;
  border: 1px solid rgba(168,85,247,0.4);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 14px 50px rgba(168,85,247,0.2);
}
#game { width: 100%; height: 100%; background: #000; }
#game canvas { display: block; }

/* Hide EmulatorJS's own floating virtual gamepad - we use our own below. */
[class*="virtualGamepad" i],
[class*="virtual-gamepad" i] { display: none !important; }

.gba-status {
  width: 100%;
  max-width: 720px;
  text-align: center;
  padding: 48px 20px;
  border: 1px dashed rgba(168,85,247,0.35);
  border-radius: 14px;
  color: rgba(255,255,255,0.6);
  font-size: 14px;
}
.gba-status.err { border-color: rgba(248,113,113,0.5); color: #fca5a5; }

/* --- On-screen gamepad (mobile only) ------------------------------------- */
#gba-controls {
  display: none;            /* shown under 820px via media query */
  width: 100%;
  max-width: 520px;
  flex-direction: column;
  gap: 22px;
  padding: 16px 6px 4px;
  user-select: none;
  -webkit-user-select: none;
}
.gba-pad-row { display: flex; align-items: center; }
.gba-pad-sh { justify-content: space-between; }
.gba-pad-main { justify-content: space-between; padding: 0 6px; }
.gba-pad-meta { justify-content: center; gap: 24px; }

.gba-btn {
  font-family: inherit;
  color: #fff;
  border: 1px solid rgba(232,121,249,0.5);
  background: linear-gradient(160deg, rgba(168,85,247,0.4), rgba(168,85,247,0.16));
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  transition: filter 0.06s ease, background 0.06s ease;
}
.gba-btn.held {
  filter: brightness(1.5);
  background: linear-gradient(160deg, #e879f9, #a855f7);
}

/* D-pad - a 3x3 grid cross. */
.gba-dpad {
  display: grid;
  grid-template-columns: repeat(3, 62px);
  grid-template-rows: repeat(3, 62px);
}
.gba-d {
  font-size: 17px;
  color: rgba(255,255,255,0.85);
}
.gba-d-up    { grid-area: 1 / 2; border-radius: 10px 10px 0 0; }
.gba-d-left  { grid-area: 2 / 1; border-radius: 10px 0 0 10px; }
.gba-d-mid   { grid-area: 2 / 2; background: rgba(168,85,247,0.28); border-top: 0; border-bottom: 0; }
.gba-d-right { grid-area: 2 / 3; border-radius: 0 10px 10px 0; }
.gba-d-down  { grid-area: 3 / 2; border-radius: 0 0 10px 10px; }
.gba-d-up, .gba-d-down { border-bottom: 0; border-top: 0; }
.gba-d-up    { border-top: 1px solid rgba(232,121,249,0.5); }
.gba-d-down  { border-bottom: 1px solid rgba(232,121,249,0.5); }
.gba-d-left  { border-right: 0; }
.gba-d-right { border-left: 0; }

/* A / B face buttons. Generous spacing + the diagonal offset so they are
   hard to mis-tap. */
.gba-ab { display: flex; align-items: center; gap: 34px; }
.gba-face {
  width: 80px; height: 80px;
  border-radius: 50%;
  font-size: 24px;
}
.gba-a { transform: translateY(-24px); }
/* translateX nudges B clear of the d-pad on narrow screens. */
.gba-b { transform: translate(14px, 24px); }

/* L / R shoulder buttons. */
.gba-sh {
  width: 116px; height: 50px;
  border-radius: 11px;
  font-size: 16px;
}
/* Select / Start. */
.gba-meta {
  padding: 13px 28px;
  border-radius: 999px;
  font-size: 12px;
  letter-spacing: 0.08em;
}

/* --- Controls hint (desktop only) --------------------------------------- */
.gba-hint {
  width: 100%;
  max-width: 760px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  justify-content: center;
  font-size: 12px;
  color: rgba(255,255,255,0.5);
  line-height: 1.6;
}
.gba-hint b { color: rgba(255,255,255,0.8); font-weight: 700; }

/* --- ROM upload card (GBA Player) --------------------------------------- */
.gba-upload {
  width: 100%;
  max-width: 520px;
  margin: 6vh auto 0;
  background: rgba(168,85,247,0.06);
  border: 1.5px dashed rgba(168,85,247,0.45);
  border-radius: 18px;
  padding: 40px 28px;
  text-align: center;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.gba-upload.drag { background: rgba(168,85,247,0.16); border-color: var(--gba-pink); }
.gba-upload-icon { font-size: 42px; margin-bottom: 10px; }
.gba-upload h2 { font-size: 19px; font-weight: 800; margin: 0 0 6px; }
.gba-upload p { font-size: 13px; color: rgba(255,255,255,0.55); margin: 0 0 18px; line-height: 1.6; }
.gba-pick-btn {
  display: inline-block;
  background: linear-gradient(135deg, #e879f9, #a855f7);
  color: #fff; border: none; border-radius: 999px;
  padding: 12px 28px;
  font-family: inherit; font-size: 14px; font-weight: 800;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.gba-pick-btn:hover { transform: translateY(-1px); opacity: 0.92; }
.gba-upload-note { margin-top: 16px; font-size: 11px; color: rgba(255,255,255,0.4); }

/* === Cheats panel ========================================================= */
.gba-cheats {
  width: 100%;
  max-width: 760px;
  background: rgba(168,85,247,0.06);
  border: 1px solid rgba(168,85,247,0.32);
  border-radius: 14px;
  /* no overflow:hidden - it would clip the dropdown popups */
}
.gba-cheats-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; cursor: pointer; user-select: none;
  border-radius: 13px 13px 0 0;
}
.gba-cheats.collapsed .gba-cheats-head { border-radius: 13px; }
.gba-cheats-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 15px; font-weight: 800; color: #fff;
}
.gba-cheats-chev {
  width: 14px; height: 14px; color: var(--gba-pink);
  transition: transform 0.18s ease;
}
.gba-cheats.collapsed .gba-cheats-chev { transform: rotate(-90deg); }
.gba-cheats-count {
  font-size: 11px; font-weight: 800; color: var(--gba-pink);
  background: rgba(232,121,249,0.16); border: 1px solid rgba(232,121,249,0.3);
  border-radius: 999px; padding: 1px 8px;
}
.gba-cheats-sub { font-size: 11px; color: rgba(255,255,255,0.4); }
.gba-cheats-body {
  border-top: 1px solid rgba(168,85,247,0.2);
  padding: 6px 8px 8px;
  border-radius: 0 0 13px 13px;
}
.gba-cheats.collapsed .gba-cheats-body { display: none; }

.gba-cheat-row {
  position: relative;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 9px 8px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.gba-cheat-row:last-of-type { border-bottom: none; }
.gba-cheat-name { font-size: 13px; font-weight: 600; color: rgba(255,255,255,0.88); min-width: 0; }
.gba-cheat-ctl { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.gba-cheats-note {
  font-size: 11px; color: rgba(255,255,255,0.4); line-height: 1.6;
  padding: 10px 8px 4px;
}

/* Toggle switch. */
.gba-toggle {
  width: 42px; height: 23px; flex-shrink: 0;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(255,255,255,0.07);
  cursor: pointer; padding: 0; position: relative;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.gba-toggle::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 17px; height: 17px; border-radius: 50%; background: #fff;
  transition: transform 0.16s ease;
}
.gba-toggle.on { background: linear-gradient(135deg, #e879f9, #a855f7); border-color: transparent; }
.gba-toggle.on::after { transform: translateX(19px); }

/* Searchable dropdown. */
.gba-dd { position: relative; }
.gba-dd-btn {
  display: flex; align-items: center; gap: 8px;
  min-width: 150px; max-width: 200px;
  background: rgba(13,0,21,0.7);
  border: 1px solid rgba(168,85,247,0.32);
  color: #fff; border-radius: 9px; padding: 7px 10px;
  font-family: inherit; font-size: 12.5px; font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.gba-dd-btn:hover { border-color: rgba(232,121,249,0.6); }
.gba-dd.open .gba-dd-btn { border-color: var(--gba-pink); background: rgba(168,85,247,0.12); }
.gba-dd-cur { flex: 1; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gba-dd-chev { width: 12px; height: 12px; color: var(--gba-pink); flex-shrink: 0; transition: transform 0.18s ease; }
.gba-dd.open .gba-dd-chev { transform: rotate(180deg); }
.gba-dd-pop {
  position: absolute; top: calc(100% + 6px); right: 0;
  width: 240px; background: #16001f;
  border: 1px solid rgba(168,85,247,0.4); border-radius: 12px;
  box-shadow: 0 14px 38px rgba(0,0,0,0.55);
  padding: 8px; z-index: 50; display: none;
}
.gba-dd.open .gba-dd-pop { display: block; }
/* Flip the popup above the button when there isn't room below. */
.gba-dd.up .gba-dd-pop { top: auto; bottom: calc(100% + 6px); }
.gba-dd-search {
  width: 100%;
  background: rgba(13,0,21,0.8);
  border: 1px solid rgba(168,85,247,0.3);
  color: #fff; border-radius: 8px; padding: 7px 10px;
  font-family: inherit; font-size: 12.5px; outline: none; margin-bottom: 6px;
}
.gba-dd-search:focus { border-color: var(--gba-pink); }
.gba-dd-search::placeholder { color: rgba(255,255,255,0.35); }
.gba-dd-list { max-height: 240px; overflow-y: auto; }
.gba-dd-opt {
  display: block; width: 100%; text-align: left;
  background: none; border: none; color: rgba(255,255,255,0.78);
  font-family: inherit; font-size: 12.5px; padding: 7px 9px;
  border-radius: 7px; cursor: pointer;
}
.gba-dd-opt:hover { background: rgba(168,85,247,0.18); color: #fff; }
.gba-dd-none { font-size: 12px; color: rgba(255,255,255,0.4); padding: 8px 9px; }

/* === Mobile: game on top, custom gamepad below, no hint text ============== */
@media (max-width: 819px) {
  body { padding-top: 52px; }
  .gba-wrap { padding: 10px 8px 48px; gap: 8px; }
  .gba-stage {
    height: auto;
    width: 100%;
    max-height: 46vh;
    border-radius: 10px;
  }
  #gba-controls { display: flex; }
  .gba-hint { display: none; }
}

@media (max-width: 400px) {
  .gba-dpad { grid-template-columns: repeat(3, 56px); grid-template-rows: repeat(3, 56px); }
  .gba-face { width: 72px; height: 72px; font-size: 22px; }
  .gba-ab { gap: 26px; }
  .gba-sh { width: 98px; height: 46px; }
}
