/* === RESET & BASE === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0a0a0f;
  --surface: #111118;
  --surface2: #1a1a24;
  --border: #2a2a3a;
  --accent: #1d6fa4;
  --accent2: #3a9bd5;
  --gold: #f4a261;
  --text: #e8e8f0;
  --text-muted: #7070a0;
  --success: #2a9d8f;
  --radius: 8px;
  --card-w: 160px;
}

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Rajdhani', sans-serif;
  font-size: 16px;
  min-height: 100vh;
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(29,111,164,0.18) 0%, transparent 60%),
    repeating-linear-gradient(0deg, transparent, transparent 40px, rgba(255,255,255,0.01) 40px, rgba(255,255,255,0.01) 41px),
    repeating-linear-gradient(90deg, transparent, transparent 40px, rgba(255,255,255,0.01) 40px, rgba(255,255,255,0.01) 41px);
}

/* === HEADER === */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(10,10,15,0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0 2rem;
}

.header-inner {
  max-width: 1600px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon { font-size: 1.6rem; }

.logo h1 {
  font-family: 'Press Start 2P', monospace;
  font-size: 1.1rem;
  color: var(--accent);
  text-shadow: 0 0 20px rgba(29,111,164,0.6), 0 0 40px rgba(29,111,164,0.3);
  letter-spacing: 2px;
}

.stats-bar {
  display: flex;
  gap: 1.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.stats-bar span {
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 4px 14px;
  border-radius: 20px;
  letter-spacing: 0.5px;
}

/* === CONTROLS === */
.controls {
  max-width: 1600px;
  margin: 0 auto;
  padding: 1.5rem 2rem;
  display: flex;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
}

.search-box { flex: 1; min-width: 200px; }
.filter-box { min-width: 200px; }

.search-box input,
.filter-box select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: var(--radius);
  font-family: 'Rajdhani', sans-serif;
  font-size: 0.95rem;
  font-weight: 500;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search-box input:focus,
.filter-box select:focus {
  border-color: var(--accent2);
  box-shadow: 0 0 0 3px rgba(58,155,213,0.15);
}

.filter-box select option { background: var(--surface2); }

.btn-add {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 10px 22px;
  border-radius: var(--radius);
  font-family: 'Rajdhani', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.5px;
  transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
  white-space: nowrap;
  box-shadow: 0 0 15px rgba(29,111,164,0.3);
}
.btn-add:hover {
  background: #c1121f;
  box-shadow: 0 0 25px rgba(29,111,164,0.5);
  transform: translateY(-1px);
}
.btn-add:active { transform: translateY(0); }

/* === GAMES GRID === */
.games-grid {
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 2rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.platform-section { }

.platform-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 1rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--border);
}

.platform-name {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.65rem;
  color: var(--gold);
  letter-spacing: 2px;
  text-shadow: 0 0 10px rgba(244,162,97,0.4);
}

.platform-count {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
  background: var(--surface2);
  padding: 2px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
}

.games-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--card-w), 1fr));
  gap: 16px;
}

/* === GAME CARD === */
.game-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
  position: relative;
  group: true;
}

.game-card:hover {
  transform: translateY(-4px) scale(1.02);
  border-color: var(--accent2);
  box-shadow: 0 8px 30px rgba(0,0,0,0.5), 0 0 15px rgba(69,123,157,0.2);
}

.game-card-img {
  width: 100%;
  aspect-ratio: 3/4;
  object-fit: contain;
  display: block;
  background: var(--surface2);
}

.game-card-img.no-img {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  background: var(--surface2);
  color: var(--text-muted);
  aspect-ratio: 3/4;
}


/* === LANDSCAPE CARDS (SNES, N64, GAMECUBE...) === */
.games-row.landscape {
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}

.games-row.landscape .game-card-img {
  aspect-ratio: 4/3;
}

.games-row.landscape .game-card-img.no-img {
  aspect-ratio: 4/3;
}


/* === SQUARE CARDS (PS1, DREAMCAST) === */
.games-row.square {
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}

.games-row.square .game-card-img {
  aspect-ratio: 1/1;
}

.games-row.square .game-card-img.no-img {
  aspect-ratio: 1/1;
}

.game-card-info {
  padding: 8px 10px;
}

.game-card-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Actions au hover */
.game-card-actions {
  position: absolute;
  top: 6px;
  right: 6px;
  display: flex;
  gap: 5px;
  opacity: 0;
  transition: opacity 0.2s;
}

.game-card:hover .game-card-actions { opacity: 1; }

.btn-edit, .btn-del {
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.btn-edit { background: rgba(69,123,157,0.9); color: #fff; }
.btn-del  { background: rgba(193,18,31,0.9);  color: #fff; }
.btn-edit:hover { background: var(--accent2); }
.btn-del:hover  { background: #c1121f; }

/* === LOADING & EMPTY === */
.loading, .empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
  font-size: 0.95rem;
  letter-spacing: 0.5px;
}

.loading::after {
  content: '';
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid var(--text-muted);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-left: 10px;
  vertical-align: middle;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* === MODAL === */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal.hidden { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
}

.modal-box {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 90%;
  max-width: 480px;
  box-shadow: 0 25px 60px rgba(0,0,0,0.8);
  overflow: hidden;
  animation: modalIn 0.25s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.94) translateY(-10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.confirm-box { max-width: 360px; padding: 2rem; text-align: center; }
.confirm-box h2 { font-size: 1.1rem; margin-bottom: 0.7rem; color: #e63946; }
.confirm-box p { color: var(--text-muted); margin-bottom: 1.5rem; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.2rem 1.5rem;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 1.1rem; font-weight: 700; letter-spacing: 0.5px; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}
.modal-close:hover { color: var(--text); background: var(--surface2); }

.modal-body { padding: 1.5rem; display: flex; flex-direction: column; gap: 1rem; }

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 0.82rem; font-weight: 600; color: var(--text-muted); letter-spacing: 0.5px; text-transform: uppercase; }

.form-group input,
.form-group select {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-family: 'Rajdhani', sans-serif;
  font-size: 0.95rem;
  font-weight: 500;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.form-group input:focus,
.form-group select:focus {
  border-color: var(--accent2);
  box-shadow: 0 0 0 3px rgba(58,155,213,0.15);
}
.form-group select option { background: var(--surface2); }

.jaquette-preview {
  margin-top: 8px;
  border-radius: 6px;
  overflow: hidden;
  max-height: 150px;
  text-align: center;
}
.jaquette-preview img {
  max-height: 150px;
  max-width: 100%;
  object-fit: contain;
  border-radius: 6px;
}
.jaquette-preview.hidden { display: none; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
}

.btn-cancel, .btn-save, .btn-delete {
  padding: 9px 22px;
  border-radius: var(--radius);
  border: none;
  font-family: 'Rajdhani', sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.5px;
  transition: background 0.15s, transform 0.1s;
}
.btn-cancel  { background: var(--surface2); color: var(--text-muted); border: 1px solid var(--border); }
.btn-save    { background: var(--accent2); color: #fff; box-shadow: 0 0 10px rgba(58,155,213,0.3); }
.btn-delete  { background: #c1121f;  color: #fff; box-shadow: 0 0 10px rgba(193,18,31,0.3); }
.btn-cancel:hover  { background: var(--border); color: var(--text); }
.btn-save:hover    { background: #356a88; }
.btn-delete:hover  { background: #c1121f; }
.btn-save:active, .btn-delete:active, .btn-cancel:active { transform: scale(0.97); }

/* === TOAST === */
#toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--success);
  color: var(--text);
  padding: 12px 20px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.9rem;
  box-shadow: 0 8px 25px rgba(0,0,0,0.5);
  z-index: 2000;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.3s ease;
  pointer-events: none;
}
#toast.show { opacity: 1; transform: translateY(0); }
#toast.error { border-left-color: #e63946; }

/* === SCROLLBAR === */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* === RESPONSIVE === */
@media (max-width: 600px) {
  .header-inner { padding: 0; }
  .logo h1 { font-size: 0.75rem; }
  .stats-bar { display: none; }
  .controls { padding: 1rem; }
  :root { --card-w: 130px; }
}

/* === PLATFORM SELECT ROW === */
.platform-select-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.platform-select-row select {
  flex: 1;
}

.btn-add-platform {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, border-color 0.2s, transform 0.1s;
}

.btn-add-platform:hover {
  background: var(--border);
  border-color: var(--gold);
  transform: scale(1.08);
}

.btn-add-platform:active {
  transform: scale(0.95);
}

.form-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
  display: block;
  font-style: italic;
}
