/* ==========================================================================
   GBA Web Player - Core Design System & Layout
   ========================================================================== */

:root {
  /* Color Palette */
  --bg-primary: #07090e;
  --bg-surface: #0e131f;
  --bg-surface-elevated: #161c2d;
  --bg-glass: rgba(18, 24, 40, 0.75);
  --bg-glass-border: rgba(255, 255, 255, 0.08);

  --accent-gba-indigo: #6d5dfc;
  --accent-gba-purple: #8b5cf6;
  --accent-cyber-cyan: #06b6d4;
  --accent-neon-green: #10b981;
  --accent-fire-red: #ef4444;
  --accent-gold: #f59e0b;

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  /* Geometry & Shadows */
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-pill: 9999px;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 25px rgba(109, 93, 252, 0.35);
  --shadow-bezel: 0 25px 50px -12px rgba(0, 0, 0, 0.8), inset 0 1px 1px rgba(255, 255, 255, 0.15);

  --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-smooth: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-primary);
  background-image: 
    radial-gradient(circle at 50% 0%, rgba(109, 93, 252, 0.15) 0%, transparent 65%),
    radial-gradient(circle at 10% 90%, rgba(6, 182, 212, 0.08) 0%, transparent 50%);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  user-select: none;
  -webkit-user-select: none;
}

/* App Header */
.app-header {
  height: 64px;
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--bg-glass-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 50;
}

.logo-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-badge {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.75rem;
  background: linear-gradient(135deg, var(--accent-gba-indigo), var(--accent-gba-purple));
  color: #fff;
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius-sm);
  box-shadow: 0 0 12px rgba(109, 93, 252, 0.5);
  letter-spacing: 0.5px;
}

.logo-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(to right, #fff, #cbd5e1);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.gamepad-indicator {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent-neon-green);
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.3);
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius-pill);
  animation: pulseGreen 2.5s infinite;
}

@keyframes pulseGreen {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.65; }
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Glass Buttons */
.btn-glass {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--bg-glass-border);
  color: var(--text-main);
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-glass:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.btn-glass:active {
  transform: translateY(0);
}

.btn-glass.active {
  background: rgba(109, 93, 252, 0.25);
  border-color: var(--accent-gba-indigo);
  color: #c7d2fe;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-gba-indigo), var(--accent-gba-purple));
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(109, 93, 252, 0.4);
  transition: all var(--transition-fast);
}

.btn-primary:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(109, 93, 252, 0.55);
}

/* Main Layout */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 1rem;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

/* Top Game Info Bar */
.game-info-bar {
  width: 100%;
  max-width: 900px;
  background: var(--bg-surface);
  border: 1px solid var(--bg-glass-border);
  border-radius: var(--radius-md);
  padding: 0.75rem 1.25rem;
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
}

.game-title-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.game-code-badge {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.65rem;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--accent-gba-indigo);
  color: #e2e8f0;
}

.game-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: #fff;
}

.game-subtext {
  font-size: 0.78rem;
  color: var(--text-dim);
}

.status-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-pill);
  letter-spacing: 0.5px;
}

.status-idle {
  background: rgba(148, 163, 184, 0.15);
  color: var(--text-muted);
}

.status-loading {
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent-gold);
  animation: pulseGreen 1.5s infinite;
}

.status-running {
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-neon-green);
}

.status-paused {
  background: rgba(239, 68, 68, 0.15);
  color: var(--accent-fire-red);
}

/* Stage Area (Viewport & Bezel) */
.stage-area {
  position: relative;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* Drop Zone (Idle overlay) */
.drop-zone {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 2px dashed rgba(109, 93, 252, 0.4);
  border-radius: var(--radius-lg);
  background: rgba(14, 19, 31, 0.85);
  backdrop-filter: blur(10px);
  padding: 2.5rem;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition-smooth);
}

.drop-zone.drag-active {
  border-color: var(--accent-cyber-cyan);
  background: rgba(14, 19, 31, 0.95);
  box-shadow: 0 0 35px rgba(6, 182, 212, 0.4);
  transform: scale(1.02);
}

.drop-zone-icon {
  font-size: 3.5rem;
  margin-bottom: 1rem;
  filter: drop-shadow(0 0 15px rgba(109, 93, 252, 0.5));
  animation: floatBounce 3s ease-in-out infinite;
}

@keyframes floatBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.drop-zone h3 {
  font-size: 1.35rem;
  font-weight: 600;
  margin-bottom: 0.4rem;
}

.drop-zone p {
  color: var(--text-muted);
  font-size: 0.9rem;
  max-width: 480px;
  line-height: 1.45;
  margin-bottom: 1.25rem;
}

.format-tags {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.format-tag {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.6rem;
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--bg-glass-border);
  color: #cbd5e1;
}

.format-tag.highlight {
  border-color: var(--accent-neon-green);
  color: var(--accent-neon-green);
  background: rgba(16, 185, 129, 0.1);
}

/* Control Toolbar */
.control-toolbar {
  width: 100%;
  max-width: 900px;
  margin-top: 1.25rem;
  background: var(--bg-surface);
  border: 1px solid var(--bg-glass-border);
  border-radius: var(--radius-md);
  padding: 0.75rem 1.25rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  box-shadow: var(--shadow-sm);
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Slot Selector */
.slot-selector {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  background: rgba(0, 0, 0, 0.3);
  padding: 0.25rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--bg-glass-border);
}

.slot-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.3rem 0.6rem;
  border-radius: 4px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.slot-btn.active {
  background: var(--accent-gba-indigo);
  color: #fff;
  box-shadow: 0 0 10px rgba(109, 93, 252, 0.4);
}

/* Library Drawer */
.drawer {
  position: fixed;
  top: 0;
  right: -460px;
  width: 440px;
  max-width: 92vw;
  height: 100vh;
  background: var(--bg-surface-elevated);
  border-left: 1px solid var(--bg-glass-border);
  box-shadow: -15px 0 40px rgba(0, 0, 0, 0.85);
  z-index: 100;
  display: flex;
  flex-direction: column;
  transition: right var(--transition-smooth);
}

.drawer.open {
  right: 0;
}

.drawer-header {
  padding: 1.15rem 1.25rem;
  border-bottom: 1px solid var(--bg-glass-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-surface);
}

.drawer-header h3 {
  font-size: 1.1rem;
  font-weight: 600;
}

.drawer-close-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
}

.drawer-close-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.08);
}

/* Search Box */
.library-search-box {
  padding: 0.75rem 1.25rem;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--bg-glass-border);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  position: relative;
}

.library-search-box input {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--bg-glass-border);
  border-radius: var(--radius-md);
  padding: 0.6rem 2.2rem 0.6rem 2.4rem;
  color: #fff;
  font-family: inherit;
  font-size: 0.88rem;
  outline: none;
  transition: all var(--transition-fast);
}

.library-search-box input:focus {
  border-color: var(--accent-gba-indigo);
  background: rgba(255, 255, 255, 0.08);
  box-shadow: 0 0 12px rgba(109, 93, 252, 0.35);
}

.library-search-box .search-icon {
  position: absolute;
  left: 1.95rem;
  pointer-events: none;
  font-size: 0.95rem;
  color: var(--text-dim);
}

.clear-search-btn {
  position: absolute;
  right: 1.75rem;
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0.2rem 0.4rem;
}

.clear-search-btn:hover {
  color: #fff;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem;
}

/* Enhanced Game Cards */
.library-item {
  background: var(--bg-surface);
  border: 1px solid var(--bg-glass-border);
  border-radius: var(--radius-md);
  padding: 0.95rem 1.1rem;
  margin-bottom: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-fast);
}

.library-item:hover {
  border-color: var(--accent-gba-indigo);
  background: rgba(22, 28, 45, 0.9);
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
}

.title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.game-title-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  overflow: hidden;
}

.badge {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.55rem;
  padding: 0.2rem 0.45rem;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--accent-gba-indigo);
  white-space: nowrap;
}

.game-name {
  font-size: 0.95rem;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sub-meta {
  font-size: 0.78rem;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.item-actions-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 0.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.lib-play-btn {
  background: linear-gradient(135deg, var(--accent-gba-indigo), var(--accent-gba-purple));
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.85rem;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  box-shadow: 0 2px 8px rgba(109, 93, 252, 0.4);
  transition: all 0.15s ease;
}

.lib-play-btn:hover {
  filter: brightness(1.15);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(109, 93, 252, 0.6);
}

.lib-action-tools {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.lib-tool-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--bg-glass-border);
  cursor: pointer;
  color: var(--text-muted);
  padding: 0.35rem 0.55rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  transition: all 0.15s ease;
}

.lib-tool-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.lib-tool-btn.danger:hover {
  background: rgba(239, 68, 68, 0.2);
  color: var(--accent-fire-red);
  border-color: rgba(239, 68, 68, 0.4);
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-dim);
}

.empty-icon {
  font-size: 2.5rem;
  display: block;
  margin-bottom: 0.75rem;
}

.subtext {
  font-size: 0.8rem;
  display: block;
  margin-top: 0.4rem;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  z-index: 120;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-smooth);
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--bg-glass-border);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  width: 90%;
  max-width: 520px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.9);
  text-align: center;
}

.modal-card h3 {
  font-size: 1.25rem;
  margin-bottom: 0.75rem;
}

.progress-track {
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-pill);
  overflow: hidden;
  margin: 1.25rem 0 0.75rem 0;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-gba-indigo), var(--accent-cyber-cyan));
  border-radius: var(--radius-pill);
  transition: width 0.3s ease;
}

.extractor-status-text {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Key Help Dialog */
.key-table {
  width: 100%;
  margin: 1.25rem 0;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.88rem;
}

.key-table th {
  color: var(--text-dim);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--bg-glass-border);
}

.key-table td {
  padding: 0.6rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

kbd {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.4);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.8rem;
  color: #e2e8f0;
}

/* Toast System */
.toast-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 150;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--bg-glass-border);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  color: #fff;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  transform: translateY(20px);
  opacity: 0;
  transition: all var(--transition-smooth);
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.toast-success {
  border-left: 4px solid var(--accent-neon-green);
}

.toast-info {
  border-left: 4px solid var(--accent-gba-indigo);
}

.toast-warning {
  border-left: 4px solid var(--accent-gold);
}

.toast-error {
  border-left: 4px solid var(--accent-fire-red);
}

.hidden {
  display: none !important;
}

.mobile-only {
  display: none !important;
}

.desktop-only {
  display: inline-flex !important;
}

/* ==========================================================================
   Mobile Options Bottom Sheet
   ========================================================================== */
.mobile-sheet {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  pointer-events: none;
  visibility: hidden;
  transition: visibility 0.25s ease;
}

.mobile-sheet.open {
  visibility: visible;
  pointer-events: auto;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity 0.25s ease;
}

.mobile-sheet.open .sheet-backdrop {
  opacity: 1;
}

.sheet-content {
  position: relative;
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--bg-glass-border);
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -15px 40px rgba(0, 0, 0, 0.9);
  padding: 1rem 1.25rem max(env(safe-area-inset-bottom, 22px), 22px) 1.25rem;
  max-height: min(88dvh, 88vh);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
  -webkit-overflow-scrolling: touch;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 2;
}

.sheet-content::-webkit-scrollbar {
  width: 4px;
}

.sheet-content::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}

.mobile-sheet.open .sheet-content {
  transform: translateY(0);
}

.sheet-drag-handle {
  width: 44px;
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
  margin: 0 auto 0.85rem auto;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--bg-glass-border);
  margin-bottom: 1rem;
}

.sheet-header h3 {
  font-size: 1.05rem;
  font-weight: 700;
  color: #fff;
}

.sheet-close-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
}

.sheet-body {
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
}

.sheet-section {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sheet-section-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.sheet-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
}

.sheet-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.btn-sheet {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--bg-glass-border);
  color: var(--text-main);
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  cursor: pointer;
  transition: all 0.12s ease;
}

.btn-sheet:active {
  background: rgba(109, 93, 252, 0.3);
  transform: scale(0.98);
}

.m-slot-btn {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--bg-glass-border);
  color: var(--text-dim);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.45rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
}

.m-slot-btn.active {
  background: var(--accent-gba-indigo);
  color: #fff;
  border-color: var(--accent-gba-purple);
}

/* ==========================================================================
   Responsive Adaptations & Authentic Mobile GBA Layout
   ========================================================================== */
@media (max-width: 768px) {
  .mobile-only {
    display: inline-flex !important;
  }

  .desktop-only {
    display: none !important;
  }

  .app-header {
    height: 54px;
    padding: 0 0.65rem;
    gap: 0.35rem;
  }

  .logo-group {
    gap: 0.35rem;
    flex-shrink: 0;
  }

  .logo-badge {
    font-size: 0.7rem;
    padding: 0.25rem 0.45rem;
  }

  .logo-title {
    display: none;
  }

  .header-actions {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    flex-shrink: 0;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    max-width: calc(100vw - 65px);
  }

  .header-actions::-webkit-scrollbar {
    display: none;
  }

  .header-actions .btn-glass,
  .header-actions .btn-primary {
    padding: 0.38rem 0.52rem;
    font-size: 0.78rem;
    border-radius: 8px;
    gap: 0.25rem;
    white-space: nowrap;
    flex-shrink: 0;
  }

  .user-auth-btn {
    max-width: 105px;
  }

  .user-auth-btn #user-auth-label {
    max-width: 60px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .main-content {
    padding: 0.4rem 0.4rem 1rem 0.4rem;
    max-width: 100%;
  }

  .game-info-bar {
    padding: 0.45rem 0.75rem;
    margin-bottom: 0.5rem;
    border-radius: 10px;
  }

  .game-title {
    font-size: 0.88rem;
  }

  .game-subtext {
    font-size: 0.68rem;
  }

  /* Drop Zone on mobile */
  .drop-zone {
    padding: 1.5rem 0.85rem;
  }

  .drop-zone-icon {
    font-size: 2.2rem;
    margin-bottom: 0.4rem;
  }

  .drop-zone h3 {
    font-size: 1.05rem;
  }

  .drop-zone p {
    font-size: 0.8rem;
    margin-bottom: 0.8rem;
  }

  .format-tags {
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.35rem;
    margin-bottom: 0.85rem;
  }

  .format-tag {
    font-size: 0.55rem;
    padding: 0.2rem 0.4rem;
  }

  /* Fullscreen-like experience for Library Drawer on mobile */
  .drawer {
    width: 100vw !important;
    max-width: 100vw !important;
    right: -100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: max(env(safe-area-inset-bottom, 16px), 16px);
  }

  .drawer.open {
    right: 0 !important;
  }

  /* Bottom sheet mobile tweaks */
  .sheet-header h3 {
    font-size: 0.95rem;
  }

  .btn-sheet {
    padding: 0.55rem 0.5rem;
    font-size: 0.8rem;
    min-height: 42px;
  }

  /* Modal cards fit snugly on mobile screens with safe-area */
  .modal-card {
    padding: 1.25rem 1rem max(env(safe-area-inset-bottom, 16px), 16px) 1rem !important;
    max-height: min(90dvh, 90vh) !important;
    overflow-y: auto !important;
    width: 95% !important;
  }

  /* Center floating toasts at top of screen on mobile */
  .toast-container {
    bottom: auto !important;
    top: max(env(safe-area-inset-top, 14px), 14px) !important;
    left: 50% !important;
    right: auto !important;
    transform: translateX(-50%) !important;
    width: 90% !important;
    max-width: 380px !important;
    z-index: 2500 !important;
  }

  .toast {
    font-size: 0.82rem !important;
    padding: 0.65rem 0.95rem !important;
    width: 100% !important;
    justify-content: center !important;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.8) !important;
  }

  /* Hide Desktop Control Toolbar on mobile - all features accessible in GBA Menu / Sheet! */
  .control-toolbar {
    display: none;
  }
}

@media (max-width: 420px) {
  .header-actions .btn-glass,
  .header-actions .btn-primary {
    padding: 0.35rem 0.45rem;
    font-size: 0.74rem;
    gap: 0.2rem;
  }

  .sheet-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.35rem;
  }
}

/* ==========================================================================
   PWA Installation & Offline Mode Styles
   ========================================================================== */
.pwa-install-btn {
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%) !important;
  color: #ffffff !important;
  font-weight: 700 !important;
  border: 1px solid rgba(255, 255, 255, 0.25) !important;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.4) !important;
  animation: pulse-subtle 3s infinite;
}

@keyframes pulse-subtle {
  0%, 100% {
    transform: translateY(0);
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.4);
  }
  50% {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.7);
  }
}

.network-badge {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: 12px;
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.3);
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.network-badge.online {
  background: rgba(34, 197, 94, 0.15);
  color: #4ade80;
  border-color: rgba(34, 197, 94, 0.3);
}

.library-tabs {
  display: flex;
  gap: 0.4rem;
  padding: 0.5rem 1rem 0 1rem;
  background: rgba(0, 0, 0, 0.2);
}

.lib-tab {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.5rem 0.25rem;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.lib-tab:hover {
  color: var(--text-main);
}

.lib-tab.active {
  color: var(--accent-gba-cyan);
  border-bottom-color: var(--accent-gba-cyan);
}

.pwa-steps-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.pwa-step-item {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--bg-glass-border);
  border-radius: 10px;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.pwa-step-badge {
  display: inline-block;
  align-self: flex-start;
  font-size: 0.7rem;
  font-weight: 800;
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
  background: rgba(99, 102, 241, 0.2);
  color: var(--accent-gba-cyan);
  border: 1px solid rgba(99, 102, 241, 0.3);
  text-transform: uppercase;
}

.pwa-step-item p {
  font-size: 0.82rem;
  color: var(--text-dim);
  margin: 0;
  line-height: 1.4;
}

.pwa-step-item p strong {
  color: var(--text-main);
}

/* iOS Specific PWA Instructions Card */
.pwa-step-ios {
  background: linear-gradient(135deg, rgba(14, 165, 233, 0.08) 0%, rgba(99, 102, 241, 0.08) 100%) !important;
  border: 1px solid rgba(14, 165, 233, 0.35) !important;
  box-shadow: 0 4px 15px rgba(14, 165, 233, 0.15);
}

.ios-steps-box {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin-top: 0.35rem;
}

.ios-step-row {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  font-size: 0.84rem;
  line-height: 1.45;
  color: var(--text-main);
}

.ios-step-num {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #0284c7;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(2, 132, 199, 0.4);
}

.ios-badge-note {
  margin-top: 0.5rem;
  background: rgba(14, 165, 233, 0.12);
  border: 1px solid rgba(14, 165, 233, 0.28);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  font-size: 0.76rem;
  line-height: 1.4;
  color: #bae6fd;
}

.ios-badge-note strong {
  color: #38bdf8;
}

.offline-indicator-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  background: rgba(34, 197, 94, 0.15);
  color: #4ade80;
  border: 1px solid rgba(34, 197, 94, 0.25);
}

/* ==========================================================================
   Auth & Cloud Saves Styling
   ========================================================================== */

.cloud-dot {
  width: 8px;
  height: 8px;
  background: #10b981;
  border-radius: 50%;
  box-shadow: 0 0 8px #10b981;
  display: inline-block;
  margin-left: 2px;
}

.user-auth-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  font-weight: 600;
  border-color: rgba(99, 102, 241, 0.35);
}

.user-auth-btn.logged-in {
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.4);
  color: #4ade80;
}

.auth-modal-card {
  max-width: 460px;
  text-align: left;
  padding: 1.5rem;
  background: var(--bg-surface-elevated);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.8), 0 0 30px rgba(99, 102, 241, 0.2);
}

.auth-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--bg-glass-border);
  padding-bottom: 0.75rem;
}

.auth-modal-badge-icon {
  font-size: 2rem;
  filter: drop-shadow(0 2px 8px rgba(6, 182, 212, 0.4));
}

.auth-tabs {
  display: flex;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 10px;
  padding: 3px;
  gap: 4px;
  margin-bottom: 1.25rem;
  border: 1px solid var(--bg-glass-border);
}

.auth-tab {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  padding: 0.6rem 0.5rem;
  border-radius: 8px;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: center;
}

.auth-tab:hover {
  color: var(--text-main);
}

.auth-tab.active {
  background: var(--accent-gba-indigo);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(109, 93, 252, 0.4);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-group label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group input {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 0.7rem 0.85rem;
  color: #ffffff;
  font-family: inherit;
  font-size: 0.92rem;
  outline: none;
  transition: border-color var(--transition-fast);
}

.form-group input:focus {
  border-color: var(--accent-gba-indigo);
  box-shadow: 0 0 0 2px rgba(109, 93, 252, 0.25);
}

.auth-error-banner {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  font-size: 0.82rem;
  line-height: 1.4;
}

.auth-submit-btn {
  width: 100%;
  justify-content: center;
  padding: 0.75rem 1rem;
  font-size: 0.95rem;
  margin-top: 0.35rem;
}

.auth-hint-box {
  margin-top: 1rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--bg-glass-border);
  border-radius: 10px;
  padding: 0.75rem 0.85rem;
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
}

.auth-hint-box p {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin: 0;
  line-height: 1.45;
}

.auth-hint-box strong {
  color: var(--text-main);
}

/* Logged-in Profile View */
.user-status-card {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--bg-glass-border);
  border-radius: 12px;
  padding: 0.85rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin-bottom: 1rem;
}

.user-avatar-circle {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-gba-indigo), var(--accent-cyber-cyan));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
  box-shadow: 0 2px 10px rgba(109, 93, 252, 0.3);
}

.user-info-text {
  flex: 1;
  min-width: 0;
}

.user-badge-online {
  font-size: 0.65rem;
  font-weight: 800;
  color: #4ade80;
  letter-spacing: 0.5px;
}

.user-email-display {
  font-size: 0.9rem;
  font-weight: 700;
  color: #ffffff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-folder-note {
  font-size: 0.72rem;
  color: var(--text-dim);
  display: block;
}

.btn-logout {
  color: #f87171;
  border-color: rgba(239, 68, 68, 0.3);
  font-size: 0.8rem;
  padding: 0.35rem 0.75rem;
}

.btn-logout:hover {
  background: rgba(239, 68, 68, 0.15);
  border-color: #ef4444;
}

.auth-current-game-box {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--bg-glass-border);
  border-radius: 10px;
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
}

.cloud-saves-section {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--bg-glass-border);
  border-radius: 10px;
  padding: 0.85rem;
}

.cloud-saves-list {
  max-height: 180px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.cloud-empty-hint {
  font-size: 0.8rem;
  color: var(--text-dim);
  text-align: center;
  padding: 1.25rem 0.5rem;
  font-style: italic;
}

.cloud-save-item {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--bg-glass-border);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  transition: background var(--transition-fast);
}

.cloud-save-item:hover {
  background: rgba(255, 255, 255, 0.06);
}

.cloud-save-meta {
  flex: 1;
  min-width: 0;
}

.cloud-save-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: #ffffff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cloud-save-time {
  font-size: 0.7rem;
  color: var(--text-dim);
}

.cloud-save-actions {
  display: flex;
  gap: 0.35rem;
}

.btn-mini-refresh {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 0.85rem;
  opacity: 0.7;
  transition: opacity var(--transition-fast), transform var(--transition-fast);
}

.btn-mini-refresh:hover {
  opacity: 1;
  transform: rotate(90deg);
}

/* ========================================================
   MULTIPLAYER & NETPLAY UI STYLES
   ======================================================== */

.multiplayer-btn {
  position: relative;
  border-color: rgba(99, 102, 241, 0.4) !important;
}

.multiplayer-btn:hover {
  border-color: var(--accent-gba-indigo) !important;
  box-shadow: 0 0 15px rgba(99, 102, 241, 0.35) !important;
}

.netplay-dot {
  width: 8px;
  height: 8px;
  background: #10b981;
  border-radius: 50%;
  position: absolute;
  top: 6px;
  right: 6px;
  box-shadow: 0 0 8px #10b981;
  animation: pulse-dot 1.5s infinite;
}

@keyframes pulse-dot {
  0% { transform: scale(0.9); opacity: 0.8; }
  50% { transform: scale(1.25); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.8; }
}

.multiplayer-modal-card {
  max-width: 500px;
}

.mp-game-indicator-box {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--bg-glass-border);
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
  margin-bottom: 0.85rem;
}

.mp-mode-selector {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.mp-mode-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--bg-glass-border);
  border-radius: 10px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.mp-mode-card:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(99, 102, 241, 0.4);
}

.mp-mode-card.active {
  background: rgba(99, 102, 241, 0.15);
  border-color: var(--accent-gba-indigo);
  box-shadow: 0 0 12px rgba(99, 102, 241, 0.25);
}

.mp-mode-card .mode-icon {
  font-size: 1.4rem;
}

.mp-mode-card .mode-info {
  display: flex;
  flex-direction: column;
}

.mp-mode-card .mode-info strong {
  font-size: 0.88rem;
  color: #fff;
}

.mp-mode-card .mode-info span {
  font-size: 0.73rem;
  color: var(--text-muted);
  line-height: 1.3;
}

.room-code-banner {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: 12px;
  padding: 1rem 0.85rem;
  text-align: center;
  margin-bottom: 0.85rem;
}

.room-code-badge {
  font-size: 2rem;
  font-weight: 900;
  letter-spacing: 4px;
  color: #38bdf8;
  text-shadow: 0 0 15px rgba(56, 189, 248, 0.6);
  font-family: monospace;
  margin: 0.35rem 0;
}

.mp-status-box {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--bg-glass-border);
  border-radius: 8px;
  padding: 0.6rem 0.85rem;
  font-size: 0.85rem;
}

.status-pulse-dot {
  width: 10px;
  height: 10px;
  background: #fbbf24;
  border-radius: 50%;
  box-shadow: 0 0 8px #fbbf24;
  animation: pulse-dot 1.2s infinite;
}

.status-pulse-dot.connected {
  background: #10b981;
  box-shadow: 0 0 10px #10b981;
}

/* Floating In-Game HUD */
.multiplayer-hud {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 50;
  pointer-events: auto;
}

.hud-pill {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(56, 189, 248, 0.4);
  padding: 0.3rem 0.65rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 700;
  color: #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.hud-pill .hud-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 6px #10b981;
}

.hud-pill .hud-ping {
  color: var(--accent-cyber-cyan);
  font-size: 0.7rem;
  background: rgba(0, 0, 0, 0.4);
  padding: 1px 5px;
  border-radius: 6px;
}

.btn-hud-action {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
  font-size: 0.8rem;
  opacity: 0.8;
  transition: opacity var(--transition-fast), transform var(--transition-fast);
}

.btn-hud-action:hover {
  opacity: 1;
  transform: scale(1.15);
}

.btn-reaction {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--bg-glass-border);
  border-radius: 8px;
  padding: 0.4rem 0.65rem;
  font-size: 1.15rem;
  cursor: pointer;
  transition: transform var(--transition-fast), background var(--transition-fast);
}

.btn-reaction:hover {
  background: rgba(99, 102, 241, 0.2);
  transform: scale(1.15);
}

/* Remote video element in screen housing */
#multiplayer-remote-video {
  width: 100% !important;
  height: 100% !important;
  object-fit: contain;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
}



