:root {
  --bg: #0f1115;
  --surface: #1a1d25;
  --surface-2: #20242f;
  --border: #2a2e3a;
  --border-hover: #3a4050;
  --text: #eee;
  --text-dim: #9aa0ac;
  --text-faint: #6b7180;
  --accent: #4a90e2;
  --accent-dim: #3a72b3;
  --danger: #e0574f;
  --danger-dim: #7a2a2a;
  --warn: #d9a441;
  --ok: #3fae5a;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 14px 24px;
  background: rgba(26, 29, 37, 0.9);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 1100px;
  margin: 0 auto;
}
.logo-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
  flex: 0 0 auto;
}
header h1 { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: 0.2px; }

main { padding: 24px; max-width: 1100px; margin: 0 auto; }
.hidden { display: none !important; }

.back-btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin-bottom: 18px;
  font-size: 13px;
  transition: background 0.15s, border-color 0.15s;
}
.back-btn:hover { background: var(--surface-2); border-color: var(--border-hover); }

/* --- Titres --- */
.title-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}
.title-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  position: relative;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.title-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.title-card h3 {
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 600;
  padding-right: 44px;
  line-height: 1.3;
}
.title-card .count {
  display: inline-block;
  font-size: 11px;
  color: var(--text-dim);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 3px 9px;
}
.title-card-actions {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 4px;
}
.title-card-actions button {
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 14px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.title-card-actions button:hover { color: var(--text); background: var(--surface-2); }
.title-card-actions .delete-btn:hover { color: var(--danger); }

/* --- Saisons --- */
.season-group { margin-bottom: 28px; }
.season-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.season-header h2 {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim);
  margin: 0;
  background: var(--surface-2);
  padding: 5px 12px;
  border-radius: 999px;
}
.season-actions { display: flex; gap: 2px; }
.season-actions button {
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 13px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  transition: background 0.15s, color 0.15s;
}
.season-actions button:hover { color: var(--text); background: var(--surface-2); }
.season-actions .delete-season-btn:hover { color: var(--danger); }

/* --- Episodes --- */
.episode-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 8px;
  transition: border-color 0.15s;
}
.episode-row:hover { border-color: var(--border-hover); }

.ep-row-main {
  display: flex;
  align-items: center;
  gap: 10px;
}
.episode-row .ep-label { flex: 1; cursor: pointer; font-size: 14px; min-width: 0; }
.episode-row .ep-label:hover { color: var(--accent); }
.episode-row .ep-label.not-clickable { cursor: default; }
.episode-row .ep-label.not-clickable:hover { color: inherit; }

.status-downloading { color: var(--warn); }
.status-downloading::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--warn);
  animation: pulse 1.2s ease-in-out infinite;
}
.status-error { color: var(--danger); }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}
.episode-row .subs-tag {
  font-size: 10px;
  color: var(--ok);
  border: 1px solid var(--ok);
  border-radius: 4px;
  padding: 1px 6px;
  margin-left: 8px;
  vertical-align: middle;
}

.ep-actions {
  display: flex;
  gap: 4px;
  flex: 0 0 auto;
}
.icon-btn {
  background: none;
  border: 1px solid transparent;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 13px;
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.icon-btn.subs-btn:hover { color: var(--accent); }
.icon-btn.delete-btn:hover { color: var(--danger); border-color: var(--danger-dim); }
.icon-btn.edit-btn.active { color: var(--accent); background: var(--surface-2); }

.ep-edit-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.ep-edit-panel input[type=text] {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  font-size: 12px;
}
.ep-edit-panel input[type=text]:focus {
  outline: none;
  border-color: var(--accent);
}
.ep-edit-panel .ep-title-input { width: 180px; }
.ep-edit-panel .ep-season-input,
.ep-edit-panel .ep-episode-input { width: 70px; }
.ep-edit-panel .field-label {
  font-size: 10px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-right: -4px;
}

.btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--border); border-color: var(--border-hover); }
.btn.primary { background: var(--accent-dim); border-color: var(--accent); }
.btn.primary:hover { background: var(--accent); }
.btn.danger:hover { background: var(--danger-dim); border-color: var(--danger); }

/* --- Lecteur --- */
.player-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: #000;
  border-radius: var(--radius);
  padding: 12px;
  border: 1px solid var(--border);
}
#video { flex: 1; max-height: 70vh; display: block; border-radius: 6px; }
.nav-btn {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  user-select: none;
}
.nav-btn:hover { background: var(--border); border-color: var(--accent); }

.player-controls {
  margin-top: 12px;
  display: flex;
  gap: 10px;
}
.subs-toggle {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.subs-toggle:hover { background: var(--surface-2); border-color: var(--accent); }

#playerInfo {
  margin-top: 14px;
  font-size: 14px;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
}

.empty-msg { color: var(--text-faint); padding: 60px 0; text-align: center; font-size: 14px; }

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-box {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.modal-box h3 { margin: 0 0 8px; font-size: 16px; }
.modal-desc { margin: 0 0 14px; font-size: 13px; color: var(--text-dim); }
.modal-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-faint);
  margin-bottom: 6px;
}
.modal-select {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  font-size: 14px;
  margin-bottom: 14px;
}
.modal-select:focus { outline: none; border-color: var(--accent); }

.modal-mode-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}
.modal-mode-option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.modal-mode-option:hover { border-color: var(--border-hover); }
.modal-mode-option:has(input:checked) {
  border-color: var(--accent);
  background: rgba(74, 144, 226, 0.08);
}
.modal-mode-option input[type=radio] { margin-top: 3px; accent-color: var(--accent); }
.modal-mode-option span { display: flex; flex-direction: column; gap: 2px; }
.modal-mode-option strong { font-size: 13px; font-weight: 600; }
.modal-mode-option small { font-size: 11.5px; color: var(--text-dim); }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}
.modal-btn {
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font-size: 13px;
  cursor: pointer;
  border: 1px solid var(--border);
}
.modal-btn-secondary { background: var(--surface-2); color: var(--text); }
.modal-btn-secondary:hover { background: var(--border); }
.modal-btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.modal-btn-primary:hover { background: var(--accent-dim); }

/* --- Envoi de videos --- */
.header-btn {
  margin-left: auto;
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
}
.header-btn:hover { background: var(--accent-dim); }
.modal-input {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  font-size: 14px;
  margin-bottom: 14px;
}
.modal-input:focus { outline: none; border-color: var(--accent); }
.modal-input:disabled { opacity: 0.5; }
.modal-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.upload-progress {
  height: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 8px;
}
.upload-bar { height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }
.modal-desc.error { color: var(--danger); }
.modal-desc.warn { color: var(--warn); }

/* --- Responsive --- */
@media (max-width: 560px) {
  main { padding: 16px; }
  .title-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
  .ep-row-main { flex-wrap: wrap; }
  .ep-actions { margin-left: auto; }
  .ep-edit-panel input[type=text] { flex: 1 1 100px; }
}
