/* Global Reset */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "Inter", sans-serif;
  color: #e0e0e0;
  background: radial-gradient(
    circle at 50% -20%,
    #4a148c 0%,
    #1a0b2e 50%,
    #0d0d1a 100%
  );
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.6;
}

/* App Container */
.app-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

/* Upload Button */
.custom-file-upload {
  display: inline-block;
  padding: 12px 24px;
  cursor: pointer;
  background: linear-gradient(135deg, #bc13fe 0%, #8a2be2 100%);
  border-radius: 30px;
  color: white;
  font-weight: 600;
  font-size: 1rem;
  transition: all 0.3s ease;
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 4px 15px rgba(188, 19, 254, 0.4);
  margin-bottom: 20px;
}

.custom-file-upload:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(188, 19, 254, 0.6);
  background: linear-gradient(135deg, #d54eff 0%, #9d4eff 100%);
}

.custom-file-upload:active {
  transform: translateY(1px);
}

/* Header */
header {
  text-align: center;
  margin-bottom: 2rem;
}

header h1 {
  font-family: "Press Start 2P", cursive;
  color: #fff;
  font-size: 2.5rem;
  text-transform: uppercase;
  text-shadow:
    0 0 10px rgba(138, 43, 226, 0.8),
    0 0 20px rgba(138, 43, 226, 0.4);
  letter-spacing: 2px;
}

.highlight {
  color: #bc13fe;
}

header p {
  margin-top: 1rem;
  color: #a3a3a3;
  font-size: 1.1rem;
}

/* Main Layout */
main {
  display: flex;
  flex-direction: column; /* Mobile first: column */
  gap: 2rem;
  align-items: center;
  position: relative;
  width: 100%;
}

/* Emulator Section */
.emulator-section {
  width: 100%;
  max-width: 800px;
  background: rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 20px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

#game-container {
  width: 100%;
  aspect-ratio: 4 / 3; /* Default aspect ratio */
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

#game-container:fullscreen,
#game-container:-webkit-full-screen,
#game-container:-moz-full-screen {
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
  aspect-ratio: unset;
  border-radius: 0;
  padding: 0;
  margin: 0;
  background-color: #000;
}

/* Game Controls Bar */
.game-controls-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(0, 0, 0, 0.4);
  padding: 10px 15px;
  border-radius: 10px;
  width: 100%;
}

.control-btn {
  background: rgba(188, 19, 254, 0.2);
  border: 1px solid rgba(188, 19, 254, 0.5);
  color: #fff;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 6px;
}

.control-btn:hover {
  background: rgba(188, 19, 254, 0.4);
  transform: translateY(-1px);
}

.controls-hint {
  color: #ccc;
  font-size: 0.85rem;
  max-width: 70%;
  text-align: right;
  line-height: 1.4;
}

/* Placeholder inside emulator before load */
.placeholder-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #fff;
  text-align: center;
  height: 100%;
  width: 100%;
  background: linear-gradient(135deg, #1f1f1f 0%, #2a2a2a 100%);
}

.placeholder-content .icon {
  font-size: 4rem;
  margin-bottom: 1rem;
  animation: float 3s ease-in-out infinite;
}

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

.placeholder-content h2 {
  font-family: "Press Start 2P", cursive;
  font-size: 1.2rem;
  color: #bc13fe;
  margin-bottom: 0.5rem;
}

.placeholder-content p {
  font-size: 0.9rem;
  color: #888;
}

/* Game Selection List */
.games-list-section {
  width: 100%;
  max-width: 1000px;
  display: flex;
  flex-direction: column;
}

.games-list-section h2 {
  font-size: 1.5rem;
  margin-bottom: 1.5rem;
  border-bottom: 2px solid rgba(188, 19, 254, 0.3);
  padding-bottom: 0.5rem;
  display: inline-block;
  color: #ddd;
}

.games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
  flex: 1; /* Allow it to grow in flex container */
}

/* Game Card */
.game-card {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 1.5rem;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
  position: relative;
  overflow: hidden;
}

.game-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 10px 20px rgba(188, 19, 254, 0.2);
  border-color: rgba(188, 19, 254, 0.5);
  background: rgba(255, 255, 255, 0.1);
}

.game-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 4px; /* Purple strip on left */
  height: 100%;
  background: #bc13fe;
  transform: scaleY(0);
  transition: transform 0.3s ease;
  transform-origin: bottom;
}

.game-card:hover::before {
  transform: scaleY(1);
}

.game-title {
  font-weight: 600;
  font-size: 1.1rem;
  color: #fff;
  margin-bottom: 0.5rem;
}

.game-meta {
  font-size: 0.85rem;
  color: #aaa;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.game-icon {
  font-size: 1.2rem;
}

/* Footer */
footer {
  text-align: center;
  margin-top: 3rem;
  color: #666;
  font-size: 0.9rem;
  padding-bottom: 2rem;
}

/* Loader override for Emulator JS */

/* Fix Fullscreen EJS behavior */
#game {
  width: 100% !important;
  height: 100% !important;
  max-width: 100% !important;
  max-height: 100% !important;
}
#game iframe {
  width: 100% !important;
  height: 100% !important;
  border: none !important;
}

/* --- DESKTOP LAYOUT (Split Screen) --- */
@media (min-width: 1024px) {
  /* Hide the regular footer in desktop mode to save space, or make it stick to bottom right */
  footer {
    display: none;
  }

  /* Make header compact */
  header {
    margin-bottom: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 1rem;
  }

  header h1 {
    font-size: 1.8rem;
    margin: 0;
  }

  header p {
    display: none; /* Hide subtitle to save space */
  }

  .upload-container {
    margin-top: 0 !important;
  }

  .custom-file-upload {
    padding: 8px 16px;
    font-size: 0.9rem;
    margin-bottom: 0;
  }

  /* Main Container becomes full height minus header */
  .app-container {
    height: 100vh;
    max-width: 100%;
    padding: 1rem 2rem;
    overflow: hidden; /* Prevent body scroll */
    flex-direction: column;
    gap: 1rem;
  }

  main {
    flex-direction: row;
    align-items: flex-start;
    justify-content: space-between;
    height: 100%;
    gap: 2rem;
    overflow: hidden; /* Container itself doesn't scroll */
  }

  /* Left Side: Emulator */
  .emulator-section {
    flex: 2; /* Takes 2/3 space */
    height: 100%;
    max-width: none;
    display: flex;
    flex-direction: column;
    justify-content: center; /* Center vertically */
  }

  #game-container {
    /* Prioritize width, but limit height to fit screen */
    width: 100%;
    height: auto;
    aspect-ratio: 3 / 2; /* Native GBA aspect ratio fits better */
    max-height: 85vh;
  }

  /* Right Side: Game List */
  .games-list-section {
    flex: 1; /* Takes 1/3 space */
    height: 100%;
    overflow-y: auto; /* Scrollable independently */
    padding-right: 10px; /* Space for scrollbar */
    max-width: 450px; /* Don't get too wide */
    min-width: 300px;
  }

  .games-grid {
    grid-template-columns: 1fr; /* Single column list */
    gap: 1rem;
  }

  .game-card {
    padding: 1rem;
  }
}

/* Custom Scrollbar for the list */
::-webkit-scrollbar {
  width: 8px;
}
::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
}
::-webkit-scrollbar-thumb {
  background: rgba(188, 19, 254, 0.3);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(188, 19, 254, 0.6);
}

/* Responsive */
@media (max-width: 768px) {
  header h1 {
    font-size: 1.8rem;
  }

  .app-container {
    padding: 10px;
    width: 100%;
    gap: 1rem;
  }

  .emulator-section {
    padding: 5px;
    width: 100%;
    max-width: 100%;
    border-radius: 10px;
  }

  #game-container {
    width: 100%;
    /* Let the emulator handle the aspect ratio/height, but ensure minimums */
    min-height: 250px;
  }

  .games-grid {
    grid-template-columns: 1fr; /* Stack on mobile */
  }

  .placeholder-content .icon {
    font-size: 3rem;
  }
}
