/* emulator-st-core.css — Shell UI styles for /play-next
   Maps to emulator.st design tokens (var(--bg), var(--accent), etc.)
   Requires style.css (site base) to already be loaded.
*/

/* Container ------------------------------------------------------------- */
.emu-st-root {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background: var(--bg, #0a0a0f);
}

/* HUD ------------------------------------------------------------------- */
.emu-st-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  background: rgba(0,0,0,0.35);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.emu-st-hud-left,
.emu-st-hud-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.emu-st-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  color: var(--text-secondary, #a0a0b0);
  font-size: 12px;
}

.emu-st-badge[hidden] { display: none; }

/* Volume control */
.emu-st-volume {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
}

.emu-st-volume input[type="range"] {
  width: 80px;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255,255,255,0.15);
  border-radius: 2px;
  outline: none;
}

.emu-st-volume input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  background: var(--accent, #a29bfe);
  border-radius: 50%;
  cursor: pointer;
}

/* Mobile volume popup - slider drops DOWN below the icon */
@media (max-width: 768px) {
  .emu-st-volume {
    position: relative;
  }
  
  .emu-st-volume input[type="range"] {
    display: none;
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    width: 140px;
    padding: 12px;
    background: rgba(22,22,30,0.95);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    z-index: 100;
    margin-top: 8px;
  }
  
  .emu-st-volume:hover input[type="range"],
  .emu-st-volume:active input[type="range"],
  .emu-st-volume:focus-within input[type="range"] {
    display: block;
  }
  
  .emu-st-volume input[type="range"]:hover {
    display: block;
  }
}

/* Buttons --------------------------------------------------------------- */
.emu-st-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.06);
  color: var(--text, #e4e4ec);
  font-size: 14px;
}

/* Fullscreen button - always visible on mobile */
@media (max-width: 768px) {
  .emu-st-hud-right .emu-st-btn[data-action="fullscreen"] {
    display: inline-flex !important;
    background: var(--accent, #a29bfe);
    color: #0a0a0f;
    font-weight: 600;
  }

  /* Hide less important buttons on small screens */
  .emu-st-hud-right .emu-st-btn[data-panel="multiplayer"],
  .emu-st-hud-right .emu-st-btn[data-panel="streaming"] {
    display: none !important;
  }
}

.emu-st-btn:hover { background: rgba(255,255,255,0.12); }
.emu-st-btn:active { transform: translateY(1px); }

.emu-st-btn-ghost { background: transparent; border-color: transparent; }

.emu-st-btn-primary { 
  background: var(--accent, #a29bfe); 
  color: #0a0a0f; 
  font-weight: 600;
}

/* Mobile menu ----------------------------------------------------------- */
.emu-st-hud-mobile-menu {
  position: absolute;
  top: 100%;
  right: 0;
  display: none; /* Hidden by default */
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  background: rgba(22,22,30,0.95);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  z-index: 100;
}

.emu-st-hud-mobile-menu:not([hidden]) {
  display: flex;
}

/* Mobile/small screen: show mobile menu, hide desktop buttons */
@media (max-width: 768px) {
  /* Show mobile buttons */
  .emu-st-hud-right .emu-st-btn[data-action="mobile-menu"],
  .emu-st-hud-right .emu-st-btn[data-action="fullscreen"] {
    display: inline-flex !important;
  }

  /* Make fullscreen button prominent */
  .emu-st-hud-right .emu-st-btn[data-action="fullscreen"] {
    background: var(--accent, #a29bfe);
    color: #0a0a0f;
    font-weight: 600;
    font-size: 13px;
  }

  /* Hide desktop-only buttons on mobile */
  .emu-st-hud-right .emu-st-btn.emu-st-btn-desktop {
    display: none !important;
  }

  /* Compact HUD on mobile */
  .emu-st-hud {
    padding: 6px 8px;
  }

  .emu-st-hud-title {
    font-size: 12px;
  }

  /* Smaller badges */
  .emu-st-badge {
    font-size: 10px;
    padding: 2px 6px;
  }
}

/* Desktop: show all buttons, hide mobile-only */
@media (min-width: 769px) {
  .emu-st-hud-right .emu-st-btn.emu-st-btn-desktop {
    display: inline-flex !important;
  }

  .emu-st-hud-right .emu-st-btn[data-action="mobile-menu"] {
    display: none !important;
  }
}

/* Stage ----------------------------------------------------------------- */
.emu-st-stage-wrap {
  position: relative;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #000;
}

.emu-st-stage {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.emu-st-stage canvas {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* Mobile canvas sizing */
@media (pointer: coarse), (max-width: 768px) {
  .emu-st-stage-wrap {
    min-height: calc(100vh - 100px);
  }
  
  .emu-st-stage canvas {
    width: 100%;
    height: auto;
    max-height: calc(100vh - 120px);
  }
}

/* Desktop: larger canvas filling viewport */
@media (pointer: fine) and (min-width: 769px) {
  .emu-st-stage-wrap {
    min-height: calc(100vh - 50px);
    height: calc(100vh - 50px);
  }
  
  .emu-st-stage {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  .emu-st-stage canvas {
    width: auto;
    height: auto;
    min-width: 800px;
    min-height: 600px;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
  }
}

/* Fullscreen top bar (PC only) ------------------------------------------- */
.emu-st-fs-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.9), rgba(0,0,0,0.4));
  z-index: 60;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

/* Show in fullscreen on desktop */
.emu-st-stage-wrap:fullscreen .emu-st-fs-bar,
:-webkit-full-screen .emu-st-fs-bar {
  display: flex;
  pointer-events: auto;
}

/* Show on mouse movement */
.emu-st-stage-wrap:fullscreen:hover .emu-st-fs-bar,
.emu-st-stage-wrap:fullscreen .emu-st-fs-bar.visible {
  opacity: 1;
}

/* Keep visible when hovering the bar itself */
.emu-st-stage-wrap:fullscreen .emu-st-fs-bar:hover {
  opacity: 1 !important;
}

.emu-st-fs-bar-left,
.emu-st-fs-bar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.emu-st-fs-title {
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.emu-st-fs-volume {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: rgba(255,255,255,0.1);
  border-radius: 20px;
}

.emu-st-fs-volume input[type="range"] {
  width: 100px;
  height: 4px;
  -webkit-appearance: none;
  background: rgba(255,255,255,0.3);
  border-radius: 2px;
  cursor: pointer;
  pointer-events: auto;
}

.emu-st-fs-volume input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: var(--accent, #a29bfe);
  border-radius: 50%;
  cursor: pointer;
  pointer-events: auto;
}

.emu-st-fs-volume input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: var(--accent, #a29bfe);
  border-radius: 50%;
  cursor: pointer;
}

.emu-st-fs-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.1);
  color: #fff;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}

.emu-st-fs-btn:hover {
  background: rgba(255,255,255,0.2);
}

.emu-st-fs-btn-exit {
  background: rgba(255,107,107,0.2);
  border-color: rgba(255,107,107,0.3);
}

.emu-st-fs-btn-exit:hover {
  background: rgba(255,107,107,0.3);
}

.emu-st-fs-btn-disabled {
  opacity: 0.4;
  cursor: not-allowed;
  background: rgba(255,255,255,0.05) !important;
  border-color: rgba(255,255,255,0.1) !important;
}

.emu-st-fs-btn-disabled:hover {
  background: rgba(255,255,255,0.05) !important;
}

/* Fullscreen pause button - blinks when game is paused */
.emu-st-fs-btn-paused {
  animation: pause-blink 1s ease-in-out infinite;
  background: rgba(255,193,7,0.3) !important;
  border-color: rgba(255,193,7,0.5) !important;
  color: #ffc107 !important;
}

/* Overlay (pause/loading) -------------------------------------------- */
.emu-st-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  pointer-events: auto;
  color: var(--accent-bright, #a29bfe);
}

.emu-st-overlay[hidden] { display: none; }

/* Panels --------------------------------------------------------------- */
.emu-st-panels {
  position: fixed;
  inset: 0;
  z-index: 2000; /* Higher than slot preview (1000) */
  background: rgba(10,10,15,0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 16px;
  overflow: auto;
  pointer-events: auto;
}

/* Panels in fullscreen */
.emu-st-stage-wrap:fullscreen ~ .emu-st-panels,
:-webkit-full-screen ~ .emu-st-panels,
:fullscreen .emu-st-panels {
  z-index: 3000;
}

.emu-st-panels[hidden] { display: none; }

.emu-st-panel {
  max-width: 720px;
  margin: 0 auto;
  background: var(--panel, rgba(22,22,30,0.9));
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  overflow: hidden;
  pointer-events: auto;
}

.emu-st-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.emu-st-panel-title {
  font-weight: 600;
  color: var(--text, #e4e4ec);
}

.emu-st-panel-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
}

.emu-st-panel-body {
  padding: 16px;
  pointer-events: auto;
}

/* Ensure all interactive elements in panels are clickable */
.emu-st-panel-body input,
.emu-st-panel-body select,
.emu-st-panel-body button,
.emu-st-panel-body label,
.emu-st-panel-body textarea {
  pointer-events: auto;
}

/* Slots (save/load) */
.emu-st-slots {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

.emu-st-slot {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 12px;
  border-radius: 10px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.06);
}

/* Toast ---------------------------------------------------------------- */
.emu-st-toast {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(22,22,30,0.95);
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--text, #e4e4ec);
  font-size: 13px;
  pointer-events: none;
}

.emu-st-toast[hidden] { display: none; }

.emu-st-toast-error { color: #ff6b6b; border-color: rgba(255,107,107,0.4); }

.emu-st-toast-success { color: #69db7c; border-color: rgba(105,219,124,0.4); }

/* Fullscreen ----------------------------------------------------------- */
/* Fullscreen mode - support both standard and webkit prefixes */
.emu-st-stage-wrap:fullscreen,
.emu-st-stage-wrap:-webkit-full-screen,
.emu-st-stage-wrap:-moz-full-screen {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  padding: 0 !important;
  margin: 0 !important;
  background: #000 !important;
  z-index: 9999 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

.emu-st-stage-wrap:fullscreen .emu-st-stage,
.emu-st-stage-wrap:-webkit-full-screen .emu-st-stage,
.emu-st-stage-wrap:-moz-full-screen .emu-st-stage {
  max-width: 100vw !important;
  max-height: 100vh !important;
  width: 100vw !important;
  height: 100vh !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

/* Canvas must fill the container in fullscreen */
.emu-st-stage-wrap:fullscreen canvas,
.emu-st-stage-wrap:-webkit-full-screen canvas,
.emu-st-stage-wrap:-moz-full-screen canvas,
.emu-st-stage-wrap:fullscreen .ejs_canvas,
.emu-st-stage-wrap:-webkit-full-screen .ejs_canvas,
.emu-st-stage-wrap:-moz-full-screen .ejs_canvas {
  width: 100vw !important;
  height: 100vh !important;
  max-width: 100vw !important;
  max-height: 100vh !important;
  object-fit: contain !important;
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
}

/* Stock EmulatorJS chrome: hide it so our shell is the single source of
   truth for navigation. */
.emu-st-stage .ejs_top_bar,
.emu-st-stage .ejs_bottom_bar,
.emu-st-stage .ejs_cheat_menu,
.emu-st-stage .ejs_settings_menu {
  display: none !important;
}

/* Touch controls ------------------------------------------------------- */
.emu-st-touch {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 140px;
  z-index: 50;
  background: linear-gradient(to top, rgba(0,0,0,0.8), transparent);
}

.emu-st-touch.emu-st-touch-visible {
  display: block !important;
}

.emu-st-touch:not([hidden]) {
  display: block;
}

.emu-st-touch-inner {
  pointer-events: auto;
}

.emu-st-touch-inner {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 16px 24px;
  height: 100%;
  box-sizing: border-box;
}

.emu-st-touch-dpad {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.emu-st-touch-dpad-mid {
  display: flex;
  gap: 4px;
  align-items: center;
}

.emu-st-touch-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
}

.emu-st-touch-row {
  display: flex;
  gap: 8px;
}

.emu-st-touch-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px solid rgba(162, 155, 254, 0.5);
  background: rgba(10, 10, 15, 0.7);
  color: #e4e4ec;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s, transform 0.1s;
}

.emu-st-touch-btn:active,
.emu-st-touch-active {
  background: rgba(162, 155, 254, 0.3);
  transform: scale(0.95);
}

.emu-st-touch-select,
.emu-st-touch-start {
  width: 72px;
  height: 32px;
  border-radius: 16px;
  font-size: 11px;
}

/* SNES/Genesis controller button styles */
.emu-st-touch-shoulders {
  gap: 16px;
}

.emu-st-touch-l,
.emu-st-touch-r {
  width: 60px;
  height: 28px;
  border-radius: 14px;
  font-size: 12px;
  background: rgba(80, 80, 90, 0.7);
  border-color: rgba(120, 120, 130, 0.5);
}

.emu-st-touch-l {
  margin-right: auto;
}

.emu-st-touch-r {
  margin-left: auto;
}

.emu-st-touch-face {
  gap: 12px;
}

.emu-st-touch-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.emu-st-touch-x,
.emu-st-touch-y {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  font-size: 14px;
  font-weight: 600;
}

.emu-st-touch-x {
  background: rgba(200, 50, 50, 0.7);
  border-color: rgba(220, 80, 80, 0.6);
}

.emu-st-touch-y {
  background: rgba(50, 150, 50, 0.7);
  border-color: rgba(80, 180, 80, 0.6);
}

.emu-st-touch-b {
  background: rgba(50, 50, 200, 0.7);
  border-color: rgba(80, 80, 220, 0.6);
}

.emu-st-touch-a {
  background: rgba(200, 50, 50, 0.7);
  border-color: rgba(220, 80, 80, 0.6);
}

/* Button active states */
.emu-st-touch-x:active,
.emu-st-touch-x.emu-st-touch-active {
  background: rgba(220, 100, 100, 0.9);
}

.emu-st-touch-y:active,
.emu-st-touch-y.emu-st-touch-active {
  background: rgba(100, 200, 100, 0.9);
}

.emu-st-touch-b:active,
.emu-st-touch-b.emu-st-touch-active {
  background: rgba(100, 100, 220, 0.9);
}

.emu-st-touch-a:active,
.emu-st-touch-a.emu-st-touch-active {
  background: rgba(220, 100, 100, 0.9);
}

.emu-st-touch-l:active,
.emu-st-touch-l.emu-st-touch-active,
.emu-st-touch-r:active,
.emu-st-touch-r.emu-st-touch-active {
  background: rgba(120, 120, 140, 0.9);
}

/* Layout for SNES face buttons */
@media (orientation: landscape) {
  .emu-st-touch-x,
  .emu-st-touch-y {
    width: 56px;
    height: 56px;
  }
  
  .emu-st-touch-l,
  .emu-st-touch-r {
    width: 64px;
    height: 32px;
  }
}


/* Touch controls base style */
.emu-st-touch {
  position: fixed !important;
  bottom: 0;

/* SNES diamond layout - matches real SNES controller */
.emu-st-touch-snes-face {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

.emu-st-touch-snes-mid {
  display: flex;
  gap: 40px;
  justify-content: center;
  align-items: center;
}

.emu-st-touch-snes-face .emu-st-touch-x {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  font-size: 16px;
  font-weight: 700;
  background: linear-gradient(135deg, #00a8ff, #0097e6);
  border-color: #00a8ff;
  box-shadow: 0 4px 8px rgba(0, 168, 255, 0.3);
}

.emu-st-touch-snes-face .emu-st-touch-y {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  font-size: 16px;
  font-weight: 700;
  background: linear-gradient(135deg, #44bd32, #3aa027);
  border-color: #44bd32;
  box-shadow: 0 4px 8px rgba(68, 189, 50, 0.3);
}

.emu-st-touch-snes-face .emu-st-touch-a {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  font-size: 16px;
  font-weight: 700;
  background: linear-gradient(135deg, #e84118, #c23616);
  border-color: #e84118;
  box-shadow: 0 4px 8px rgba(232, 65, 24, 0.3);
}


/* ==========================================================================
   SYSTEM-SPECIFIC TOUCH CONTROLLER LAYOUTS
   Matches actual physical controller designs
   ========================================================================== */

/* Base D-Pad styling - refined */
.emu-st-touch-dpad {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.emu-st-touch-dpad-mid {
  display: flex;
  align-items: center;
  gap: 4px;
}

.emu-st-dpad-center {
  width: 20px;
  height: 20px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 50%;
}

/* D-Pad buttons - cross shape */
.emu-st-dpad-up,
.emu-st-dpad-down {
  width: 48px;
  height: 48px;
  border-radius: 8px 8px 4px 4px;
}

.emu-st-dpad-left,
.emu-st-dpad-right {
  width: 48px;
  height: 48px;
  border-radius: 8px;
}

/* ==========================================================================
   NES CONTROLLER LAYOUT
   - D-pad left
   - Select/Start small center buttons
   - B/A buttons right
   ========================================================================== */

.emu-st-touch-nes-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.emu-st-touch-nes-system {
  display: flex;
  gap: 12px;
}

.emu-st-touch-nes-system .emu-st-sys {
  width: 60px;
  height: 28px;
  border-radius: 14px;
  font-size: 10px;
  background: rgba(100, 100, 100, 0.6);
  border-color: rgba(130, 130, 130, 0.5);
}

.emu-st-touch-nes-actions {
  display: flex;
  gap: 16px;
}

.emu-st-nes-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  font-size: 18px;
  font-weight: 700;
}

.emu-st-nes-btn.emu-st-b {
  background: linear-gradient(135deg, #e74c3c, #c0392b);
  border-color: #c0392b;
}

.emu-st-nes-btn.emu-st-a {
  background: linear-gradient(135deg, #e74c3c, #c0392b);
  border-color: #c0392b;
}

/* ==========================================================================
   SNES CONTROLLER LAYOUT
   - D-pad left
   - L/R shoulder buttons (left/right top)
   - X/Y/A/B diamond right
   - Select/Start small bottom center
   ========================================================================== */

.emu-st-touch-snes-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

/* L/R Shoulder buttons */
.emu-st-touch-snes-shoulders {
  display: flex;
  justify-content: space-between;
  width: 100%;
  padding: 0 20px;
}

.emu-st-shoulder {
  width: 70px;
  height: 32px;
  border-radius: 16px;
  font-size: 14px;
  font-weight: 600;
  background: linear-gradient(135deg, #7f8c8d, #616a6b);
  border-color: #616a6b;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.3);
}

.emu-st-shoulder.emu-st-l {
  margin-right: auto;
}

.emu-st-shoulder.emu-st-r {
  margin-left: auto;
}

/* Face buttons - diamond pattern */
.emu-st-touch-snes-face {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
}

.emu-st-touch-snes-mid {
  display: flex;
  gap: 50px;
  align-items: center;
}

.emu-st-face {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  font-size: 18px;
  font-weight: 800;
  box-shadow: 
    inset 0 2px 4px rgba(255, 255, 255, 0.3),
    inset 0 -2px 4px rgba(0, 0, 0, 0.3),
    0 4px 8px rgba(0, 0, 0, 0.4);
  border-width: 3px;
}

/* SNES button colors matching actual controller */
.emu-st-face.emu-st-x {
  background: linear-gradient(135deg, #3498db, #2980b9);
  border-color: #21618c;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.emu-st-face.emu-st-y {
  background: linear-gradient(135deg, #2ecc71, #27ae60);
  border-color: #1e8449;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.emu-st-face.emu-st-a {
  background: linear-gradient(135deg, #e74c3c, #c0392b);
  border-color: #922b21;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.emu-st-face.emu-st-b {
  background: linear-gradient(135deg, #f1c40f, #d4ac0d);
  border-color: #b7950b;
  color: #333;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.3);
}

/* Select/Start - small bottom buttons */
.emu-st-touch-snes-system {
  display: flex;
  gap: 20px;
  margin-top: 8px;
}

.emu-st-touch-snes-system .emu-st-sys {
  width: 70px;
  height: 26px;
  border-radius: 13px;
  font-size: 11px;
  font-weight: 600;
  background: linear-gradient(135deg, #95a5a6, #7f8c8d);
  border-color: #616a6b;
  color: #2c3e50;
}

/* Active states */
.emu-st-face:active,
.emu-st-face.emu-st-touch-active {
  transform: scale(0.92);
  box-shadow: 
    inset 0 3px 6px rgba(0, 0, 0, 0.4),
    0 2px 4px rgba(0, 0, 0, 0.3);
}

.emu-st-shoulder:active,
.emu-st-shoulder.emu-st-touch-active {
  background: linear-gradient(135deg, #95a5a6, #7f8c8d);
  transform: scale(0.95);
}

/* ==========================================================================
   GENESIS/MEGADRIVE CONTROLLER LAYOUT
   - D-pad left
   - A/B/C buttons right (3-button layout)
   - Mode/Start center bottom
   ========================================================================== */

.emu-st-touch-genesis-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.emu-st-touch-genesis-main {
  display: flex;
  justify-content: flex-end;
  width: 100%;
  padding-right: 10px;
}

.emu-st-touch-genesis-cols {
  display: flex;
  flex-direction: row-reverse;
  gap: 10px;
  align-items: flex-end;
}

.emu-st-gen-btn {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  font-size: 20px;
  font-weight: 700;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

/* Genesis button colors */
.emu-st-gen-btn.emu-st-a {
  background: linear-gradient(135deg, #ecf0f1, #bdc3c7);
  border-color: #95a5a6;
  color: #2c3e50;
  margin-bottom: 0;
}

.emu-st-gen-btn.emu-st-b {
  background: linear-gradient(135deg, #ecf0f1, #bdc3c7);
  border-color: #95a5a6;
  color: #2c3e50;
  margin-bottom: 15px;
}

.emu-st-gen-btn.emu-st-c {
  background: linear-gradient(135deg, #ecf0f1, #bdc3c7);
  border-color: #95a5a6;
  color: #2c3e50;
  margin-bottom: 30px;
}

/* Genesis Mode/Start */
.emu-st-touch-genesis-system {
  display: flex;
  gap: 16px;
}

.emu-st-touch-genesis-system .emu-st-sys {
  width: 65px;
  height: 28px;
  border-radius: 14px;
  font-size: 11px;
  background: linear-gradient(135deg, #34495e, #2c3e50);
  border-color: #1a252f;
}

.emu-st-gen-btn:active,
.emu-st-gen-btn.emu-st-touch-active {
  background: linear-gradient(135deg, #fff, #ecf0f1);
  transform: scale(0.92);
}

/* ==========================================================================
   GAME BOY/GBC CONTROLLER LAYOUT
   - D-pad left
   - B/A buttons stacked right
   - Select/Start bottom
   ========================================================================== */

.emu-st-touch-gb-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.emu-st-touch-gb-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.emu-st-gb-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  font-size: 20px;
  font-weight: 700;
  background: linear-gradient(135deg, #8b4513, #5d3a1a);
  border-color: #4a2c17;
  box-shadow: 
    inset 0 2px 4px rgba(255, 255, 255, 0.2),
    0 4px 8px rgba(0, 0, 0, 0.4);
}

.emu-st-touch-gb-system {
  display: flex;
  gap: 12px;
}

.emu-st-touch-gb-system .emu-st-sys {
  width: 55px;
  height: 24px;
  border-radius: 12px;
  font-size: 10px;
  background: linear-gradient(135deg, #7f8c8d, #616a6b);
  border-color: #4a5459;
}

.emu-st-gb-btn:active,
.emu-st-gb-btn.emu-st-touch-active {
  background: linear-gradient(135deg, #a0522d, #8b4513);
  transform: scale(0.92);
}

/* ==========================================================================
   RESPONSIVE ADJUSTMENTS
   ========================================================================== */

@media (orientation: landscape) {
  .emu-st-face {
    width: 62px;
    height: 62px;
    font-size: 20px;
  }
  
  .emu-st-shoulder {
    width: 80px;
    height: 36px;
  }
  
  .emu-st-gen-btn {
    width: 60px;
    height: 60px;
  }
  
  .emu-st-gb-btn {
    width: 58px;
    height: 58px;
  }
  
  .emu-st-nes-btn {
    width: 64px;
    height: 64px;
  }
}

/* Inner layout adjustments for different systems */
.emu-st-touch-inner.emu-st-touch-snes .emu-st-touch-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  padding: 10px 0;
}

.emu-st-touch-inner.emu-st-touch-genesis .emu-st-touch-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  gap: 20px;
}

.emu-st-touch-inner.emu-st-touch-gbc .emu-st-touch-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.emu-st-touch-inner.emu-st-touch-nes .emu-st-touch-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
}

.emu-st-touch-snes-face .emu-st-touch-b {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  font-size: 16px;
  font-weight: 700;
  background: linear-gradient(135deg, #fbc531, #e1b12c);
  border-color: #fbc531;
  color: #333;
  box-shadow: 0 4px 8px rgba(251, 197, 49, 0.3);
}

/* Active states for SNES buttons */
.emu-st-touch-snes-face .emu-st-touch-x:active,
.emu-st-touch-snes-face .emu-st-touch-x.emu-st-touch-active {
  background: linear-gradient(135deg, #00d2ff, #00a8ff);
  transform: scale(0.95);
}

.emu-st-touch-snes-face .emu-st-touch-y:active,
.emu-st-touch-snes-face .emu-st-touch-y.emu-st-touch-active {
  background: linear-gradient(135deg, #55efc4, #44bd32);
  transform: scale(0.95);
}

.emu-st-touch-snes-face .emu-st-touch-a:active,
.emu-st-touch-snes-face .emu-st-touch-a.emu-st-touch-active {
  background: linear-gradient(135deg, #ff6348, #e84118);
  transform: scale(0.95);
}

.emu-st-touch-snes-face .emu-st-touch-b:active,
.emu-st-touch-snes-face .emu-st-touch-b.emu-st-touch-active {
  background: linear-gradient(135deg, #ffeaa7, #fbc531);
  transform: scale(0.95);
}

/* Landscape adjustments for SNES layout */
@media (orientation: landscape) {
  .emu-st-touch-snes-face .emu-st-touch-x,
  .emu-st-touch-snes-face .emu-st-touch-y,
  .emu-st-touch-snes-face .emu-st-touch-a,
  .emu-st-touch-snes-face .emu-st-touch-b {
    width: 64px;
    height: 64px;
    font-size: 18px;
  }
  
  .emu-st-touch-snes-mid {
    gap: 50px;
  }
}

/* Position actions on the right for SNES */
.emu-st-touch-inner:has(.emu-st-touch-snes-face) .emu-st-touch-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  gap: 8px;
}


/* Show touch controls only on touch devices (phones/tablets) - not on PC */
@media (hover: none) and (pointer: coarse) and (max-width: 1024px) {
  .emu-st-touch:not([hidden]) {
    display: block !important;
  }

  .emu-st-stage-wrap {
    padding-bottom: 140px;
  }
}

/* Show touch controls in fullscreen only on touch devices */
@media (hover: none) and (pointer: coarse) {
  :fullscreen .emu-st-touch,
  :-webkit-full-screen .emu-st-touch,
  .emu-st-stage-wrap:fullscreen .emu-st-touch {
    display: block !important;
    pointer-events: auto !important;
    z-index: 9999 !important;
  }
}

/* Landscape orientation styles */
@media (orientation: landscape) {
  .emu-st-touch {
    height: 120px;
  }
  
  .emu-st-touch-btn {
    width: 64px;
    height: 64px;
  }
}

/* Portrait rotate hint - only on true touch devices (phones/tablets) */
@media (orientation: portrait) and (hover: none) and (pointer: coarse) and (max-width: 1024px) {
  .emu-st-stage-wrap::before {
    content: "↻ Rotate to landscape";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0,0,0,0.7);
    color: var(--accent, #a29bfe);
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    z-index: 5;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
  }

  .emu-st-stage-wrap:hover::before,
  .emu-st-stage-wrap:active::before {
    opacity: 1;
  }
}

/* Portrait orientation on mobile - smaller controls */
@media (orientation: portrait) and (hover: none) and (pointer: coarse) {
  .emu-st-touch {
    height: 100px;
    padding: 8px;
    gap: 8px;
  }

  .emu-st-touch-btn {
    width: 48px;
    height: 48px;
    font-size: 12px;
  }
}
  
  .emu-st-touch-btn {
    width: 48px;
    height: 48px;
    font-size: 12px;
  }
}
  
  .emu-st-stage-wrap {
    padding-bottom: 140px;
  }
}

/* Always show touch controls in fullscreen */
.emu-st-stage-wrap:fullscreen .emu-st-touch,
.emu-st-stage-wrap:-webkit-full-screen .emu-st-touch {
  display: block !important;
  pointer-events: auto !important;
  z-index: 100 !important;
}

/* Touch controls base style */
.emu-st-touch {
  position: fixed !important;
  bottom: 0;
  left: 0;
  right: 0;
  height: 140px;
  z-index: 50;
}

/* Settings Panel -------------------------------------------------------- */
.emu-st-settings {
  padding: 0;
}

.emu-st-settings-header {
  padding: 16px 16px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  margin-bottom: 8px;
}

.emu-st-settings-eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent, #a29bfe);
  margin-bottom: 8px;
}

.emu-st-settings-lede {
  font-size: 13px;
  color: var(--text-dim, #8a8a9a);
  line-height: 1.5;
  margin: 0;
}

.emu-st-settings-section {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.emu-st-settings-section:last-child {
  border-bottom: none;
}

.emu-st-settings-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text, #e4e4ec);
  margin: 0 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.emu-st-settings-badge {
  font-size: 10px;
  font-weight: 500;
  padding: 2px 6px;
  background: rgba(162,155,254,0.15);
  color: var(--accent, #a29bfe);
  border-radius: 4px;
}

.emu-st-settings-section-hint {
  font-size: 12px;
  color: var(--text-dim, #8a8a9a);
  margin: -8px 0 12px;
}

.emu-st-settings-field {
  margin-bottom: 12px;
}

.emu-st-settings-field:last-child {
  margin-bottom: 0;
}

.emu-st-settings-field label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text, #e4e4ec);
  cursor: pointer;
}

.emu-st-settings-field select {
  flex: 1;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border, rgba(255,255,255,0.1));
  background: var(--search-bg, rgba(255,255,255,0.05));
  color: var(--text, #e4e4ec);
  font-size: 13px;
  cursor: pointer;
  margin-left: 10px;
}

.emu-st-settings-field select:focus {
  outline: none;
  border-color: var(--accent, #a29bfe);
  background: var(--search-bg-focus, rgba(255,255,255,0.08));
}

.emu-st-settings-field input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent, #a29bfe);
  cursor: pointer;
}

.emu-st-settings-field input[type="range"] {
  flex: 1;
  margin-left: 10px;
  accent-color: var(--accent, #a29bfe);
}

.emu-st-settings-sublabel {
  font-size: 11px;
  color: var(--text-dim, #8a8a9a);
  margin-left: auto;
}

.emu-st-settings-value {
  font-size: 13px;
  color: var(--text-dim, #8a8a9a);
  min-width: 40px;
  text-align: right;
}

.emu-st-settings-actions {
  display: flex;
  gap: 12px;
  padding: 16px;
  border-top: 1px solid rgba(255,255,255,0.06);
  margin-top: 8px;
}

.emu-st-settings-field--row {
  display: flex;
  align-items: center;
}

.emu-st-settings-field--row label {
  flex: 1;
}

/* Settings Mode Toggle */
.emu-st-settings-mode {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  background: rgba(0,0,0,0.2);
}

.emu-st-settings-mode .emu-st-btn {
  flex: 1;
  justify-content: center;
  font-size: 12px;
  padding: 8px 12px;
}

.emu-st-settings-actions-bar {
  display: flex;
  justify-content: flex-end;
  padding: 8px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.emu-st-btn-small {
  font-size: 11px;
  padding: 4px 10px;
}

/* SRAM Save Panel ------------------------------------------------------- */
.emu-st-save-info {
  padding: 12px 16px;
  background: rgba(0,0,0,0.2);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.emu-st-save-notice {
  color: var(--text-dim, #8a8a9a) !important;
  margin-bottom: 8px;
}

.emu-st-save-notice strong {
  color: #ff6b6b;
}

.emu-st-sram-actions {
  display: flex;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.emu-st-sram-actions .emu-st-btn {
  flex: 1;
  justify-content: center;
}

.emu-st-sram-status {
  padding: 8px 16px;
  font-size: 12px;
  color: var(--text-dim, #8a8a9a);
  text-align: center;
  min-height: 20px;
}

.emu-st-save-tip {
  margin: 12px 16px;
  padding: 10px 12px;
  background: rgba(162,155,254,0.1);
  border-left: 3px solid var(--accent, #a29bfe);
  border-radius: 0 4px 4px 0;
}

/* Save Slots ------------------------------------------------------------- */
.emu-st-saves-header {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.emu-st-saves-header h3 {
  margin: 0 0 8px 0;
  font-size: 16px;
  color: var(--text, #e4e4ec);
}

.emu-st-slots {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.emu-st-slot-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.emu-st-slot-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.05);
  color: var(--text, #e4e4ec);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
  flex: 1;
}

.emu-st-slot-btn:hover {
  background: rgba(255,255,255,0.1);
}

.emu-st-slot-save {
  background: rgba(162,155,254,0.1);
  border-color: rgba(162,155,254,0.2);
}

.emu-st-slot-save:hover {
  background: rgba(162,155,254,0.2);
}

.emu-st-slot-thumb {
  width: 80px;
  height: 60px;
  object-fit: cover;
  border-radius: 4px;
  background: rgba(0,0,0,0.3);
}

.emu-st-sram-section {
  padding: 16px;
  border-top: 1px solid rgba(255,255,255,0.06);
  margin-top: 12px;
}

.emu-st-sram-section h4 {
  margin: 0 0 12px 0;
  font-size: 14px;
  color: var(--text-dim, #8a8a9a);
}

/* Enhanced Cheats Panel */
.emu-st-cheats-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border, rgba(255,255,255,0.06));
}

.emu-st-cheats-header h3 {
  margin: 0 0 12px 0;
  font-size: 16px;
}

.emu-st-cheats-search {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.emu-st-cheats-search input {
  flex: 1;
  min-width: 150px;
  padding: 8px 12px;
  background: var(--search-bg, rgba(255,255,255,0.05));
  border: 1px solid var(--border, rgba(255,255,255,0.1));
  border-radius: 6px;
  color: var(--text, #e4e4ec);
  font-size: 13px;
}

.emu-st-cheats-search input:focus {
  outline: none;
  border-color: var(--accent, #a29bfe);
  background: var(--search-bg-focus, rgba(255,255,255,0.08));
}

.emu-st-cheats-search select {
  padding: 8px 12px;
  background: var(--search-bg, rgba(255,255,255,0.05));
  border: 1px solid var(--border, rgba(255,255,255,0.1));
  border-radius: 6px;
  color: var(--text, #e4e4ec);
  font-size: 13px;
  cursor: pointer;
}

.emu-st-cheats-search select:focus {
  outline: none;
  border-color: var(--accent, #a29bfe);
  background: var(--search-bg-focus, rgba(255,255,255,0.08));
}

/* Generic themed form elements */
.emu-st-input {
  padding: 8px 12px;
  background: var(--search-bg, rgba(255,255,255,0.05));
  border: 1px solid var(--border, rgba(255,255,255,0.1));
  border-radius: 6px;
  color: var(--text, #e4e4ec);
  font-size: 13px;
}

.emu-st-input:focus {
  outline: none;
  border-color: var(--accent, #a29bfe);
  background: var(--search-bg-focus, rgba(255,255,255,0.08));
}

.emu-st-select {
  padding: 8px 12px;
  background: var(--search-bg, rgba(255,255,255,0.05));
  border: 1px solid var(--border, rgba(255,255,255,0.1));
  border-radius: 6px;
  color: var(--text, #e4e4ec);
  font-size: 13px;
  cursor: pointer;
}

.emu-st-select:focus {
  outline: none;
  border-color: var(--accent, #a29bfe);
  background: var(--search-bg-focus, rgba(255,255,255,0.08));
}

/* Option styling for dropdowns */
.emu-st-select option {
  background: var(--bg-panel, #12121c);
  color: var(--text, #e4e4ec);
}

.emu-st-cheat-list {
  max-height: 400px;
  overflow-y: auto;
  padding: 8px;
}

.emu-st-cheat-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  margin-bottom: 4px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}

.emu-st-cheat-row:hover {
  background: var(--bg-hover, rgba(255,255,255,0.05));
}

.emu-st-cheat-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent, #6c5ce7);
  cursor: pointer;
}

.emu-st-cheat-icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
}

.emu-st-cheat-name {
  flex: 1;
  font-size: 13px;
}

.emu-st-cheat-desc {
  font-size: 11px;
  color: var(--text-dim, #8a8a9a);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Hint/Info text blocks */
.emu-st-hint {
  font-size: 12px;
  color: var(--text-dim, #8a8a9a);
  margin: 8px 0;
  padding: 8px 12px;
  background: var(--accent-soft, rgba(108,92,231,0.1));
  border-left: 3px solid var(--accent, #6c5ce7);
  border-radius: 0 4px 4px 0;
}

.emu-st-hint code {
  font-family: var(--font-mono, monospace);
  background: rgba(0,0,0,0.2);
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 11px;
}

/* ==========================================================================
   Slot Bar (Top HUD)
   ========================================================================== */

.emu-st-slot-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-right: 8px;
}

.emu-st-hud-label {
  font-size: 12px;
  color: var(--text-dim, #8a8a9a);
  margin-right: 4px;
}

.emu-st-slot-mini {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 4px;
  color: #e4e4ec;
  font-size: 12px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.15s;
  padding: 0;
}

.emu-st-slot-mini:hover {
  background: rgba(255,255,255,0.1);
  border-color: rgba(162,155,254,0.5);
}

.emu-st-slot-mini.emu-st-slot-active {
  background: rgba(108,92,231,0.3);
  border-color: #6c5ce7;
  color: #a29bfe;
}

.emu-st-btn-save,
.emu-st-btn-load {
  padding: 6px 10px;
  font-size: 14px;
}

.emu-st-pill {
  font-size: 11px;
  padding: 4px 8px;
  background: rgba(255,255,255,0.1);
  border-radius: 12px;
  color: var(--text-dim, #8a8a9a);
  margin-left: 4px;
}

/* Slot screenshot preview */
.emu-st-slot-preview {
  position: fixed;
  top: 50px;
  left: 50%;
  transform: translateX(-50%);
  width: 240px;
  height: 180px;
  background: rgba(10,10,15,0.95);
  border: 2px solid rgba(162,155,254,0.5);
  border-radius: 8px;
  overflow: hidden;
  z-index: 1000;
  display: none;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

.emu-st-slot-preview.active {
  display: block;
}

.emu-st-slot-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.emu-st-slot-preview .no-screenshot {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-dim, #8a8a9a);
  font-size: 12px;
  text-align: center;
  padding: 16px;
}

/* ==========================================================================
   Controller Visual & Hotspots
   ========================================================================== */

.emu-st-controller-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 100%;
}

.emu-st-controller-image-container {
  position: relative;
  max-width: 600px;
  width: 100%;
}

.emu-st-controller-img {
  max-width: 100%;
  height: auto;
  display: block;
}

/* Controller Hotspots Overlay */
.emu-st-controller-hotspots {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.emu-st-hotspot {
  position: absolute;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(162, 155, 254, 0.3);
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: bold;
  color: rgba(255, 255, 255, 0.6);
  transition: all 0.2s ease;
  min-width: 24px;
  min-height: 20px;
  pointer-events: auto;
  z-index: 10;
}

.emu-st-hotspot:hover {
  background: rgba(162, 155, 254, 0.3);
  border-color: rgba(162, 155, 254, 0.8);
  color: #fff;
  transform: scale(1.05);
}

.emu-st-hotspot.mapping {
  animation: hotspot-flash 0.5s ease-in-out infinite;
  background: rgba(255, 193, 7, 0.4);
  border-color: #ffc107;
}

@keyframes hotspot-flash {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* SNES Controller Hotspot Positions - TUNED for actual SNES controller image */
/* L/R shoulder buttons - MADE EVEN BIGGER for easier clicking */
.emu-st-hs-l { top: 4%; left: 2%; width: 24%; height: 18%; border-radius: 20px 20px 8px 8px; }
.emu-st-hs-r { top: 4%; right: 2%; width: 24%; height: 18%; border-radius: 20px 20px 8px 8px; }

/* D-Pad - on the left side, cross shape - ADJUSTED */
.emu-st-hs-up { top: 34%; left: 16.5%; width: 9%; height: 12%; border-radius: 8px 8px 4px 4px; }
.emu-st-hs-down { top: 56%; left: 16.5%; width: 9%; height: 12%; border-radius: 4px 4px 8px 8px; }
.emu-st-hs-left { top: 46%; left: 9%; width: 9%; height: 12%; border-radius: 8px 4px 4px 8px; }
.emu-st-hs-right { top: 46%; left: 24%; width: 9%; height: 12%; border-radius: 4px 8px 8px 4px; }

/* Select/Start - center buttons, horizontal oval shape - ADJUSTED */
.emu-st-hs-select { top: 62%; left: 41%; width: 8%; height: 6%; border-radius: 20px; font-size: 9px; }
.emu-st-hs-start { top: 62%; left: 51%; width: 8%; height: 6%; border-radius: 20px; font-size: 9px; }

/* ABXY buttons - diamond pattern on the right - ADJUSTED */
/* X is top, B is bottom, Y is left, A is right */
.emu-st-hs-y { top: 46%; right: 25.5%; width: 10%; height: 12%; border-radius: 50%; } /* Y - left */
.emu-st-hs-x { top: 30%; right: 18%; width: 10%; height: 12%; border-radius: 50%; } /* X - top */
.emu-st-hs-b { top: 62%; right: 18%; width: 10%; height: 12%; border-radius: 50%; } /* B - bottom */
.emu-st-hs-a { top: 46%; right: 10.5%; width: 10%; height: 12%; border-radius: 50%; } /* A - right */

/* Controller Label */
.emu-st-controller-label {
  text-align: center;
  font-size: 12px;
  color: var(--text-dim, #8a8a9a);
  padding: 8px;
  background: rgba(0,0,0,0.2);
  border-radius: 8px;
  margin-top: 8px;
}

/* CSS Fallback Controller */
.emu-st-controller-fallback {
  width: 100%;
  max-width: 500px;
  display: flex;
  justify-content: center;
}

.emu-st-controller-css-render {
  width: 100%;
  padding: 20px;
  background: linear-gradient(145deg, #e0e0e0 0%, #c0c0c0 100%);
  border-radius: 20px;
  box-shadow: 
    inset 0 2px 4px rgba(255,255,255,0.5),
    inset 0 -2px 4px rgba(0,0,0,0.2),
    0 4px 8px rgba(0,0,0,0.3);
}

.emu-st-css-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.emu-st-css-lr {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.emu-st-css-btn {
  flex: 1;
  padding: 12px;
  background: linear-gradient(145deg, #d0d0d0, #b0b0b0);
  border: none;
  border-radius: 8px;
  color: #444;
  font-weight: bold;
  font-size: 14px;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.emu-st-css-face {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  gap: 8px;
  align-items: center;
  justify-items: center;
}

.emu-st-css-dpad {
  width: 40px;
  height: 40px;
  background: #333;
  border: none;
  border-radius: 4px;
  color: #666;
  font-size: 16px;
  cursor: pointer;
}

.emu-st-css-action {
  width: 50px;
  height: 50px;
  background: linear-gradient(145deg, #e74c3c, #c0392b);
  border: 3px solid #a93226;
  border-radius: 50%;
  color: white;
  font-weight: bold;
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 3px 6px rgba(0,0,0,0.3);
}

.emu-st-css-middle {
  padding: 8px 16px;
  background: #999;
  border: none;
  border-radius: 12px;
  color: #444;
  font-size: 10px;
  cursor: pointer;
}

/* Position the CSS buttons */
.emu-st-css-up { grid-column: 2; grid-row: 1; }
.emu-st-css-down { grid-column: 2; grid-row: 3; }
.emu-st-css-left { grid-column: 1; grid-row: 2; }
.emu-st-css-right { grid-column: 3; grid-row: 2; }
.emu-st-css-x { grid-column: 3; grid-row: 1; }
.emu-st-css-y { grid-column: 2; grid-row: 2; }
.emu-st-css-a { grid-column: 3; grid-row: 2; }
.emu-st-css-b { grid-column: 2; grid-row: 3; }
.emu-st-css-select { grid-column: 1; grid-row: 3; }
.emu-st-css-start { grid-column: 3; grid-row: 3; }

/* ==========================================================================
   Controls Panel Layout
   ========================================================================== */

.emu-st-controls {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.emu-st-controls h3 {
  margin: 0;
  font-size: 16px;
  color: var(--text, #e4e4ec);
}

.emu-st-controller-container {
  position: relative;
  padding: 16px;
  background: rgba(0,0,0,0.2);
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.06);
}

.emu-st-side-menu {
  display: flex;
  gap: 24px;
  align-items: flex-start;
}

.emu-st-side-menu .emu-st-controller-wrapper {
  flex: 1;
}

.emu-st-side-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 140px;
  padding: 16px;
  background: rgba(0,0,0,0.2);
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.06);
}

.emu-st-side-actions h4 {
  margin: 0 0 8px 0;
  font-size: 13px;
  color: var(--text-dim, #8a8a9a);
}

.emu-st-quick-map-btn {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid rgba(162,155,254,0.3);
  background: rgba(162,155,254,0.1);
  color: var(--text, #e4e4ec);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.emu-st-quick-map-btn:hover {
  background: rgba(162,155,254,0.2);
  border-color: rgba(162,155,254,0.5);
}

.emu-st-controls-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.emu-st-controls-status {
  font-size: 12px;
  color: var(--text-dim, #8a8a9a);
  min-height: 20px;
}

/* ==========================================================================
   Pause/Resume Button States
   ========================================================================== */

/* Pause button blinks when game is paused */
.emu-st-btn[data-action="pause"].emu-st-btn-paused {
  animation: pause-blink 1s ease-in-out infinite;
  background: rgba(255,193,7,0.3);
  border-color: rgba(255,193,7,0.5);
  color: #ffc107;
}

@keyframes pause-blink {
  0%, 100% { 
    background: rgba(255,193,7,0.3); 
    border-color: rgba(255,193,7,0.5);
    box-shadow: 0 0 10px rgba(255,193,7,0.3);
  }
  50% { 
    background: rgba(255,193,7,0.5); 
    border-color: rgba(255,193,7,0.8);
    box-shadow: 0 0 20px rgba(255,193,7,0.5);
  }
}

/* Pause button hover (when not paused) */
.emu-st-btn[data-action="pause"]:not(.emu-st-btn-paused):hover {
  background: rgba(255,193,7,0.2);
  border-color: rgba(255,193,7,0.4);
}

/* Resume button - solid green, no blinking */
.emu-st-btn[data-action="resume"] {
  background: rgba(76,175,80,0.3);
  border-color: rgba(76,175,80,0.5);
  color: #4caf50;
}

.emu-st-btn[data-action="resume"]:hover {
  background: rgba(76,175,80,0.5);
  border-color: rgba(76,175,80,0.8);
}

/* ==========================================================================
   Mobile Responsiveness for Controller
   ========================================================================== */

@media (max-width: 768px) {
  .emu-st-controller-wrapper {
    max-width: 100%;
  }
  
  .emu-st-controller-img {
    max-width: 100%;
  }
  
  .emu-st-hotspot {
    min-width: 20px;
    min-height: 16px;
    font-size: 8px;
  }
  
  .emu-st-hs-l, .emu-st-hs-r {
    font-size: 10px;
  }
  
  .emu-st-side-menu {
    flex-direction: column;
  }
  
  .emu-st-side-actions {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
  }
  
  .emu-st-side-actions h4 {
    width: 100%;
    text-align: center;
  }
  
  .emu-st-slot-bar {
    flex-wrap: wrap;
    gap: 4px;
  }
  
  .emu-st-slot-mini {
    width: 24px;
    height: 24px;
    font-size: 11px;
  }
}

/* Controller binding animation effects ------------------------------------- */
@keyframes listening-blink {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(2.5); }
}

@keyframes listening-pulse {
  0%, 100% { transform: scale(1); filter: brightness(1); }
  50% { transform: scale(1.15); filter: brightness(2); }
}

@keyframes listening-dpad {
  0%, 100% { filter: brightness(1) drop-shadow(0 0 0 transparent); }
  50% { filter: brightness(2.5) drop-shadow(0 0 8px rgba(255,255,255,0.6)); }
}

/* Controller listening states (work both standalone and in wrapper) */
.listening,
.listening-blink {
  animation: listening-blink 0.8s ease-in-out infinite;
}

.listening-pulse {
  animation: listening-pulse 0.8s ease-in-out infinite;
}

.listening-dpad {
  animation: listening-dpad 0.8s ease-in-out infinite;
}

/* Also support scoped versions */
.snes-controller .listening,
.snes-controller .listening-blink {
  animation: listening-blink 0.8s ease-in-out infinite;
}

.snes-controller .listening-pulse {
  animation: listening-pulse 0.8s ease-in-out infinite;
}

.snes-controller .listening-dpad {
  animation: listening-dpad 0.8s ease-in-out infinite;
}

/* ==========================================================================
   MOBILE CONTROLS FORCE SHOW
   Ensure touch controls are visible on mobile devices
   ========================================================================== */

@media (max-width: 1024px) {
  /* Always show touch controls on mobile/tablet */
  .emu-st-touch {
    display: block !important;
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    height: 140px !important;
    z-index: 9999 !important;
    pointer-events: auto !important;
    visibility: visible !important;
    opacity: 1 !important;
  }
  
  /* Ensure inner container is visible */
  .emu-st-touch-inner {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
  }
  
  /* Ensure all button areas are visible */
  .emu-st-touch-actions,
  .emu-st-touch-dpad,
  .emu-st-touch-snes-area,
  .emu-st-touch-genesis-area,
  .emu-st-touch-gb-area,
  .emu-st-touch-nes-area {
    display: flex !important;
    visibility: visible !important;
  }
  
  /* Force Select/Start buttons visible */
  .emu-st-touch-snes-system,
  .emu-st-touch-genesis-system,
  .emu-st-touch-gb-system,
  .emu-st-touch-nes-system {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
  }
  
  /* Make sure buttons aren't hidden */
  .emu-st-touch-btn {
    visibility: visible !important;
    opacity: 1 !important;
  }
}

/* Portrait mode specific */
@media (orientation: portrait) and (max-width: 1024px) {
  .emu-st-touch {
    height: 160px !important;
  }
  
  .emu-st-touch-btn {
    width: 64px !important;
    height: 64px !important;
  }
  
  /* Larger Select/Start for touch */
  .emu-st-touch-snes-system .emu-st-sys,
  .emu-st-touch-genesis-system .emu-st-sys,
  .emu-st-touch-gb-system .emu-st-sys,
  .emu-st-touch-nes-system .emu-st-sys {
    width: 80px !important;
    height: 32px !important;
    font-size: 12px !important;
  }
}

/* CACHE_BUST_MARKER: 1777149308 */

/* Saved slot indicator */
.emu-st-slot-mini.has-save {
  background: rgba(46, 204, 113, 0.2) !important;
  border-color: #2ecc71 !important;
  color: #2ecc71 !important;
}

/* Slot 0 Auto-Save Styling */
.emu-st-slot-row-auto {
  background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%);
  border: 2px solid #4CAF50;
  border-radius: 8px;
  margin-bottom: 12px;
  padding: 8px;
}
.emu-st-slot-row-auto .emu-st-slot-load-auto {
  background: #4CAF50;
  color: white;
  font-weight: bold;
}
.emu-st-slot-row-auto .emu-st-slot-load-auto:hover {
  background: #45a049;
}
.emu-st-slot-label {
  font-size: 12px;
  color: #2e7d32;
  margin-left: 8px;
  font-style: italic;
}

/* Fullscreen fix (2026-09-05): EJS's wrapper centering left the canvas half
   off-screen in fullscreen. Pin to viewport, letterbox with object-fit. */
.emu-st-stage-wrap:fullscreen .ejs_canvas,
.emu-st-stage-wrap:-webkit-full-screen .ejs_canvas {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  margin: 0 !important;
  transform: none !important;
  object-fit: contain !important;
  z-index: 1;
}
