/* Root Tokens & Design System */
:root {
  --bg-main: #0a0d14;
  --bg-card: #141a29;
  --bg-card-hover: #1f283e;
  --bg-glass: rgba(20, 26, 41, 0.75);
  --accent-primary: #6366f1;
  --accent-glow: #818cf8;
  --accent-bright: #38bdf8;
  --accent-gold: #fbbf24;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border-color: rgba(255, 255, 255, 0.1);
  --focus-ring: #60a5fa;
  --focus-glow: 0 0 25px rgba(96, 165, 250, 0.75), 0 0 50px rgba(96, 165, 250, 0.35);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

body {
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  overflow-x: hidden;
  min-height: 100vh;
  line-height: 1.5;
  background-image: 
    radial-gradient(circle at 15% 15%, rgba(99, 102, 241, 0.15) 0%, transparent 40%),
    radial-gradient(circle at 85% 85%, rgba(56, 189, 248, 0.12) 0%, transparent 40%);
  background-attachment: fixed;
}

/* App Container */
.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Navbar Header */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.5rem 3rem;
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 2rem;
}

.navbar.hidden {
  display: none !important;
}

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

.brand-icon {
  font-size: 2.2rem;
  filter: drop-shadow(0 0 10px rgba(99, 102, 241, 0.6));
}

.brand-title {
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: 1px;
}

.brand-title .highlight {
  color: var(--accent-bright);
}

/* System Tabs */
.system-tabs {
  display: flex;
  gap: 0.5rem;
  background: rgba(0, 0, 0, 0.3);
  padding: 0.5rem;
  border-radius: 50px;
}

.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 0.75rem 1.5rem;
  border-radius: 50px;
  font-family: inherit;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  outline: none;
}

.tab-btn.active {
  background: var(--accent-primary);
  color: #fff;
  box-shadow: 0 0 15px rgba(99, 102, 241, 0.5);
}

.tab-btn.focused {
  background: var(--bg-card-hover);
  color: #fff;
  box-shadow: var(--focus-glow);
  transform: scale(1.05);
}

/* Header Status */
.header-status {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: rgba(255, 255, 255, 0.05);
  padding: 0.5rem 1rem;
  border-radius: 50px;
  border: 1px solid var(--border-color);
}

.user-badge.hidden {
  display: none;
}

.user-avatar {
  font-size: 1.2rem;
}

.user-email {
  font-size: 0.9rem;
  font-weight: 600;
}

.signout-btn {
  background: #e11d48;
  color: #fff;
  border: none;
  padding: 0.4rem 0.8rem;
  border-radius: 50px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform var(--transition-fast);
  outline: none;
}

.signout-btn.focused {
  box-shadow: 0 0 15px rgba(225, 29, 72, 0.75);
  transform: scale(1.1);
}

.gamepad-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(255, 255, 255, 0.05);
  padding: 0.5rem 1rem;
  border-radius: 50px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  border: 1px solid var(--border-color);
  transition: all var(--transition-normal);
}

.gamepad-badge.connected {
  background: rgba(16, 185, 129, 0.1);
  color: #10b981;
  border-color: rgba(16, 185, 129, 0.3);
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.2);
}

/* Main Content */
.main-content {
  flex: 1;
  padding: 2rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.main-content.hidden {
  display: none;
}

/* Search Bar */
.search-bar-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.search-box {
  position: relative;
  width: 400px;
}

.search-icon {
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.2rem;
  pointer-events: none;
}

#search-input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 1rem 1rem 1rem 3rem;
  border-radius: var(--radius-lg);
  font-family: inherit;
  font-size: 1.1rem;
  outline: none;
  transition: all var(--transition-fast);
}

#search-input::placeholder {
  color: var(--text-muted);
}

#search-input.focused {
  border-color: var(--accent-primary);
  box-shadow: var(--focus-glow);
  transform: scale(1.02);
}

.navigation-hint {
  display: flex;
  gap: 1.5rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.navigation-hint kbd {
  background: rgba(255, 255, 255, 0.1);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-family: monospace;
  font-weight: bold;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

/* Game Grid */
.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 2rem;
  align-items: stretch;
}

.game-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border-color);
  transition: all var(--transition-fast);
  cursor: pointer;
  outline: none;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.game-card.focused,
.game-card:focus {
  transform: scale(1.05) translateY(-5px);
  border-color: var(--accent-bright);
  box-shadow: var(--focus-glow);
  z-index: 10;
  outline: none;
}

.card-poster-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 16/9;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.4);
}

.card-poster {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  transition: transform 0.5s ease;
}

.game-card.focused .card-poster {
  transform: scale(1.1);
}

.system-tag {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: 0.2rem 0.6rem;
  border-radius: 50px;
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  border: 1px solid rgba(255, 255, 255, 0.2);
  z-index: 2;
}

.system-tag.n64 { border-color: #e11d48; color: #fda4af; }
.system-tag.snes { border-color: #a855f7; color: #c084fc; }
.system-tag.nes { border-color: #ef4444; color: #fca5a5; }
.system-tag.genesis { border-color: #3b82f6; color: #93c5fd; }
.system-tag.gba { border-color: #8b5cf6; color: #c4b5fd; }
.system-tag.gb { border-color: #64748b; color: #cbd5e1; }

.card-content {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.card-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 0.4rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: auto;
}

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 5rem;
  text-align: center;
  color: var(--text-muted);
}

.empty-state.hidden {
  display: none;
}

.empty-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

/* Emulator View */
.emulator-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  background: #000;
}

.emulator-view.hidden {
  display: none;
}

.emulator-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 1.5rem 3rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(to bottom, rgba(0,0,0,0.9), transparent);
  z-index: 50;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.emulator-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.playing-info {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.playing-badge {
  background: var(--accent-primary);
  padding: 0.25rem 0.75rem;
  border-radius: 4px;
  font-weight: 800;
  font-size: 0.9rem;
}

.playing-title {
  font-size: 1.5rem;
  font-weight: 700;
  text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.exit-btn {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  color: #fff;
  padding: 0.75rem 1.5rem;
  border-radius: 50px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  outline: none;
  transition: all var(--transition-fast);
}

.exit-btn.focused, .exit-btn:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: #ef4444;
  box-shadow: 0 0 15px rgba(239, 68, 68, 0.5);
  transform: scale(1.05);
}

.emulator-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game {
  width: 100%;
  height: 100vh;
}

/* Auth Modal */
.auth-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.auth-modal.hidden {
  display: none;
}

.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 3rem;
  width: 100%;
  max-width: 450px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
}

.auth-header {
  text-align: center;
  margin-bottom: 2.5rem;
}

.auth-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  filter: drop-shadow(0 0 15px rgba(129, 140, 248, 0.6));
}

.auth-header h2 {
  font-size: 2rem;
  font-weight: 800;
  margin-bottom: 0.5rem;
}

.auth-header .highlight {
  color: var(--accent-bright);
}

.auth-header p {
  color: var(--text-muted);
}

.auth-error {
  background: rgba(239, 68, 68, 0.1);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.2);
  padding: 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1.5rem;
  text-align: center;
  font-size: 0.9rem;
}

.auth-error.hidden {
  display: none;
}

.input-group {
  margin-bottom: 1.5rem;
}

.input-group label {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 600;
}

.input-group input {
  width: 100%;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #fff;
  padding: 1rem;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 1rem;
  outline: none;
  transition: all var(--transition-fast);
}

.input-group input:focus, .input-group input.focused {
  border-color: var(--accent-bright);
  background: rgba(0, 0, 0, 0.5);
  box-shadow: var(--focus-glow);
  transform: scale(1.02);
}

.auth-buttons {
  margin-top: 3rem; /* Pushed the button down */
}

.auth-btn {
  width: 100%;
  padding: 1.25rem;
  border-radius: var(--radius-md);
  border: none;
  font-family: inherit;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  outline: none;
  transition: all var(--transition-fast);
}

.auth-btn.primary {
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-glow));
  color: #fff;
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

.auth-btn.primary:hover, .auth-btn.primary.focused {
  transform: scale(1.05);
  box-shadow: 0 0 25px rgba(129, 140, 248, 0.8), 0 0 50px rgba(129, 140, 248, 0.4);
}
