/* ============================================================
   ELOPHANE — GALERIE COURS DE KIZOMBA
   Design system : dark/light, tokens, composants, responsive
   ============================================================ */

/* ===== TOKENS ===================================================== */
:root {
  /* --- Couleurs light mode --- */
  --bg:             #FAF8F5;
  --surface:        #FFFFFF;
  --surface-alt:    #F2EDE5;
  --border:         #E0D8CC;
  --border-strong:  #C8BDB0;

  --text-1:         #1A1714;
  --text-2:         #5C4F44;
  --text-3:         #9E8E82;

  --accent:         #9A7000;
  --accent-hover:   #7A5800;
  --accent-light:   #C49010;
  --accent-surface: #FFF8E6;
  --accent-subtle:  rgba(154, 112, 0, 0.10);
  --accent-border:  rgba(154, 112, 0, 0.30);

  --overlay-bg:     rgba(15, 12, 8, 0.65);
  --card-shadow:    0 1px 4px rgba(26, 23, 20, 0.08), 0 4px 16px rgba(26, 23, 20, 0.06);
  --card-shadow-hover: 0 8px 32px rgba(26, 23, 20, 0.16), 0 2px 8px rgba(26, 23, 20, 0.08);
  --modal-shadow:   0 24px 80px rgba(26, 23, 20, 0.20);

  /* --- Spacing (8pt grid) --- */
  --s1:  4px;
  --s2:  8px;
  --s3:  12px;
  --s4:  16px;
  --s5:  20px;
  --s6:  24px;
  --s8:  32px;
  --s10: 40px;
  --s12: 48px;
  --s16: 64px;

  /* --- Radius --- */
  --r-sm:  3px;
  --r-md:  6px;
  --r-lg:  8px;
  --r-xl:  10px;

  /* --- Typography --- */
  --font-display: 'Playfair Display', Georgia, 'Times New Roman', serif;
  --font-body:    'Inter', system-ui, -apple-system, sans-serif;

  /* --- Transitions --- */
  --t-fast:   150ms ease;
  --t-base:   250ms ease;
  --t-slow:   350ms ease;

  /* --- Z-index --- */
  --z-header:   10;
  --z-controls: 20;
  --z-modal:    100;

  /* --- Misc --- */
  --header-h: 69px;
  --controls-h: 57px;
}

[data-theme="dark"] {
  --bg:             #0F0D0A;
  --surface:        #1A1714;
  --surface-alt:    #221E19;
  --border:         #2E2822;
  --border-strong:  #3E3530;

  --text-1:         #F5F0E8;
  --text-2:         #B0A090;
  --text-3:         #6B5E52;

  --accent:         #D4A017;
  --accent-hover:   #EBB520;
  --accent-light:   #F0C030;
  --accent-surface: #1E1800;
  --accent-subtle:  rgba(212, 160, 23, 0.12);
  --accent-border:  rgba(212, 160, 23, 0.30);

  --overlay-bg:     rgba(0, 0, 0, 0.75);
  --card-shadow:    0 1px 4px rgba(0, 0, 0, 0.30), 0 4px 16px rgba(0, 0, 0, 0.25);
  --card-shadow-hover: 0 8px 32px rgba(0, 0, 0, 0.50), 0 2px 8px rgba(0, 0, 0, 0.30);
  --modal-shadow:   0 24px 80px rgba(0, 0, 0, 0.70);
}


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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg);
  color: var(--text-1);
  line-height: 1.6;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color var(--t-slow), color var(--t-slow);
}

img, video, canvas {
  display: block;
  max-width: 100%;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  font: inherit;
  color: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

/* Visually hidden (screen readers only) */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ===== FOCUS ====================================================== */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* ===== HEADER ===================================================== */
.header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  background-color: var(--surface);
  border-bottom: 1px solid var(--border);
  transition: background-color var(--t-slow), border-color var(--t-slow);
}

.header-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: var(--s3) var(--s6);
  display: flex;
  align-items: center;
  gap: var(--s4);
  height: var(--header-h);
}

.header-brand {
  font-size: 1rem;          /* reset h1 size */
  font-weight: 400;
  line-height: 1;
  flex-shrink: 0;
}

.header-logo-link {
  display: flex;
  align-items: center;
  border-radius: var(--r-sm);
}

.header-logo {
  height: 48px;
  width: auto;
  object-fit: contain;
}

.header-subtitle {
  font-family: var(--font-display);
  font-size: clamp(0.95rem, 1.5vw, 1.3rem);
  font-weight: 500;
  color: var(--text-2);
  letter-spacing: 0.01em;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: var(--r-md);
  color: var(--text-3);
  flex-shrink: 0;
  transition: color var(--t-fast), background-color var(--t-fast);
}

.theme-toggle:hover {
  color: var(--accent);
  background-color: var(--accent-subtle);
}

.theme-toggle svg {
  width: 20px;
  height: 20px;
  stroke-width: 1.5;
}

.icon-sun,
.icon-moon {
  display: none;
}

[data-theme="dark"]  .icon-sun  { display: block; }
[data-theme="light"] .icon-moon { display: block; }


/* ===== CONTROLS (sticky) ========================================= */
.controls {
  position: sticky;
  top: var(--header-h);
  z-index: var(--z-controls);
  background-color: var(--bg);
  border-bottom: 1px solid var(--border);
  transition: background-color var(--t-slow), border-color var(--t-slow);
}

.controls-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: var(--s2) var(--s6);
  display: flex;
  align-items: center;
  gap: var(--s3);
  min-height: var(--controls-h);
  flex-wrap: wrap;
}

/* Champ de recherche */
.search-wrap {
  position: relative;
  flex: 1;
  min-width: 180px;
}

.search-icon {
  position: absolute;
  left: var(--s3);
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-3);
  pointer-events: none;
  flex-shrink: 0;
}

.search-input {
  width: 100%;
  height: 44px;
  padding: 0 var(--s8) 0 calc(var(--s3) + 24px);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background-color: var(--surface);
  color: var(--text-1);
  font-size: 0.875rem;
  font-family: var(--font-body);
  transition:
    border-color var(--t-fast),
    box-shadow var(--t-fast),
    background-color var(--t-slow);
  -webkit-appearance: none;
  appearance: none;
}

/* Masque le bouton natif des navigateurs webkit */
.search-input::-webkit-search-decoration,
.search-input::-webkit-search-cancel-button,
.search-input::-webkit-search-results-button {
  -webkit-appearance: none;
  appearance: none;
}

.search-input::placeholder { color: var(--text-3); }

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
  outline: none;
}

.search-clear {
  position: absolute;
  right: var(--s2);
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-sm);
  color: var(--text-3);
  transition: color var(--t-fast), background-color var(--t-fast);
}

.search-clear:hover {
  color: var(--text-1);
  background-color: var(--surface-alt);
}

.search-clear svg { width: 15px; height: 15px; }

/* Controls droite */
.controls-right {
  display: flex;
  align-items: center;
  gap: var(--s3);
  flex-shrink: 0;
}

.sort-select {
  height: 44px;
  padding: 0 var(--s3);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background-color: var(--surface);
  color: var(--text-1);
  font-size: 0.8rem;
  font-family: var(--font-body);
  cursor: pointer;
  transition:
    border-color var(--t-fast),
    background-color var(--t-slow);
  -webkit-appearance: none;
  appearance: none;
  padding-right: var(--s5);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239E8E82' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}

.sort-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
  outline: none;
}

.counter {
  font-size: 0.78rem;
  color: var(--text-3);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}


/* ===== MAIN ======================================================= */
.main {
  max-width: 1440px;
  margin: 0 auto;
  padding: var(--s8) var(--s6);
  min-height: 50vh;
}


/* ===== GRILLE ==================================================== */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr));
  gap: var(--s6);
}


/* ===== CARTE VIDÉO =============================================== */
.video-card {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  cursor: pointer;
  position: relative;
  transition:
    transform var(--t-base),
    box-shadow var(--t-base),
    border-color var(--t-base);
  content-visibility: auto;
  contain-intrinsic-size: auto 280px;
  will-change: transform;
}

.video-card:hover {
  transform: translateY(-5px);
  box-shadow: var(--card-shadow-hover);
  border-color: var(--accent-border);
}

.video-card:active {
  transform: translateY(-2px) scale(0.985);
  transition-duration: 80ms;
}

.video-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* Thumbnail — ratio défini dynamiquement par JS via style.aspectRatio */
.card-thumb {
  position: relative;
  aspect-ratio: 4 / 3;   /* fallback avant que JS ne lise la vidéo */
  background-color: var(--surface-alt);
  overflow: hidden;
}

/* Vidéo thumbnail : couvre l'espace, ratio géré par le conteneur */
.card-video-thumb {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.5s ease;
  pointer-events: none;
}

.card-video-thumb.loaded {
  opacity: 1;
}

/* Placeholder shimmer */
.card-thumb::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    var(--surface-alt) 25%,
    var(--border) 50%,
    var(--surface-alt) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.8s ease-in-out infinite;
  z-index: 0;
  transition: opacity 0.4s ease;
}

.card-thumb.thumb-loaded::before {
  opacity: 0;
  pointer-events: none;
}

@keyframes shimmer {
  0%   { background-position:  200% 0; }
  100% { background-position: -200% 0; }
}

/* Icône musicale au centre du placeholder */
.card-thumb-icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
  pointer-events: none;
}

.card-thumb-icon svg {
  width: 36px;
  height: 36px;
  color: var(--border-strong);
  stroke-width: 1;
  opacity: 0.6;
}

/* Overlay lecture */
.card-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  z-index: 2;
  transition: opacity var(--t-base);
}

.video-card:hover .card-overlay,
.video-card:focus-visible .card-overlay {
  opacity: 1;
}

.card-play-btn {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  transition: transform var(--t-fast), background-color var(--t-fast);
}

.video-card:hover .card-play-btn {
  transform: scale(1.08);
  background-color: var(--accent-hover);
}

.card-play-btn svg {
  width: 26px;
  height: 26px;
  color: #fff;
  stroke-width: 2;
  margin-left: 3px; /* centrage optique */
}

/* Badge numéro */
.card-badge {
  position: absolute;
  top: var(--s3);
  left: var(--s3);
  z-index: 3;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--accent-light);
  font-size: 0.7rem;
  font-weight: 700;
  font-family: var(--font-body);
  letter-spacing: 0.08em;
  padding: var(--s1) var(--s2);
  border-radius: var(--r-sm);
  border: 1px solid var(--accent-border);
  line-height: 1;
  user-select: none;
}

/* Corps de la carte */
.card-body {
  padding: var(--s4);
  display: flex;
  flex-direction: column;
  gap: var(--s2);
}

.card-title {
  font-family: var(--font-display);
  font-size: 0.975rem;
  font-weight: 600;
  color: var(--text-1);
  line-height: 1.4;
  cursor: pointer;
  border-radius: 4px;
  padding: 2px 4px;
  margin: -2px -4px;
  transition: color var(--t-fast), background-color var(--t-fast);
}

.card-title:hover {
  color: var(--accent);
}

.card-title:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Input d'édition inline du titre */
.card-title-input {
  width: 100%;
  font-family: var(--font-display);
  font-size: 0.975rem;
  font-weight: 600;
  color: var(--text-1);
  background: var(--accent-surface);
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 2px 6px;
  outline: none;
  line-height: 1.4;
  box-shadow: 0 0 0 3px var(--accent-subtle);
  transition: box-shadow var(--t-fast);
}

.card-date {
  display: flex;
  align-items: center;
  gap: var(--s2);
  font-size: 0.775rem;
  color: var(--text-3);
}

.card-date svg {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
  stroke-width: 1.5;
}

/* (plus de .card-video-src — la vidéo est maintenant le thumbnail direct) */


/* ===== ÉTAT VIDE / ERREUR ======================================== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s4);
  padding: var(--s16) var(--s6);
  text-align: center;
}

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

.empty-icon {
  color: var(--text-3);
  opacity: 0.7;
}

.empty-icon svg {
  width: 56px;
  height: 56px;
  stroke-width: 1;
}

.empty-title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-1);
}

.empty-text {
  font-size: 0.9rem;
  color: var(--text-2);
  max-width: 300px;
  line-height: 1.5;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 44px;
  padding: 0 var(--s6);
  border-radius: var(--r-md);
  background-color: var(--accent);
  color: #0F0D0A;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: var(--font-body);
  transition: background-color var(--t-fast), transform var(--t-fast);
  white-space: nowrap;
}

.btn-primary:hover  { background-color: var(--accent-hover); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }

.btn-primary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}


/* ===== MODAL ===================================================== */
.modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s4);
}

.modal[hidden] { display: none !important; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: var(--overlay-bg);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.modal-content {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 800px;
  max-height: calc(100dvh - var(--s8));
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-xl);
  overflow: hidden;
  box-shadow: var(--modal-shadow);
  display: flex;
  flex-direction: column;
}

/* En-tête modal */
.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s4);
  padding: var(--s5) var(--s6);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-meta {
  display: flex;
  flex-direction: column;
  gap: var(--s1);
  min-width: 0;
}

.modal-title {
  font-family: var(--font-display);
  font-size: clamp(1rem, 2.5vw, 1.35rem);
  font-weight: 600;
  color: var(--text-1);
  line-height: 1.3;
  /* Pas de troncature : le titre s'affiche en entier sur autant de lignes que nécessaire */
}

.modal-date {
  display: flex;
  align-items: center;
  gap: var(--s2);
  font-size: 0.78rem;
  color: var(--text-3);
}

.modal-date svg {
  width: 13px;
  height: 13px;
  stroke-width: 1.5;
  flex-shrink: 0;
}

.modal-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: var(--r-md);
  color: var(--text-3);
  flex-shrink: 0;
  transition: color var(--t-fast), background-color var(--t-fast);
}

.modal-close:hover { color: var(--text-1); background-color: var(--surface-alt); }
.modal-close svg { width: 20px; height: 20px; stroke-width: 2; }

/* Corps modal : vidéo + description côte à côte */
.modal-body {
  display: flex;
  flex-direction: row;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

/* Vidéo modal */
.modal-video-wrap {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  justify-content: center;
  background: #000;
  overflow: hidden;
}

.modal-video {
  display: block;
  max-width: 100%;
  max-height: 72dvh;
}

/* Panneau description — colonne droite */
.modal-desc-panel {
  flex: 0 0 220px;
  max-width: 220px;
  overflow-y: auto;
  padding: var(--s5);
  border-left: 1px solid var(--border);
  background: var(--surface-alt);
  display: flex;
  align-items: flex-start;
}

.modal-desc-panel[hidden] { display: none; }

.modal-description {
  font-size: 0.85rem;
  line-height: 1.65;
  color: var(--text-2);
  white-space: pre-line;
}

/* Navigation modal */
.modal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--s3) var(--s5);
  border-top: 1px solid var(--border);
  gap: var(--s3);
  flex-shrink: 0;
}

.modal-nav-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  min-height: 44px;
  padding: 0 var(--s3);
  border-radius: var(--r-md);
  font-size: 0.825rem;
  font-weight: 500;
  color: var(--text-2);
  transition: color var(--t-fast), background-color var(--t-fast);
}

.modal-nav-btn:hover:not(:disabled) {
  color: var(--accent);
  background-color: var(--accent-subtle);
}

.modal-nav-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.modal-nav-btn svg {
  width: 18px;
  height: 18px;
  stroke-width: 2;
  flex-shrink: 0;
}

.modal-position {
  font-size: 0.78rem;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}


/* ===== RESPONSIVE ================================================ */

/* Tablette */
@media (max-width: 1023px) {
  .main { padding: var(--s6) var(--s5); }
}

/* Mobile large */
@media (max-width: 767px) {
  :root {
    --header-h:   61px;
    --controls-h: auto;
  }

  .header-inner {
    padding: var(--s2) var(--s4) var(--s3);
    height: auto;
    min-height: var(--header-h);
    flex-wrap: wrap;
    align-items: center;
  }

  .header-logo { height: 40px; }

  /* Subtitle passe sur une 2ème ligne sous le logo */
  .header-subtitle {
    order: 3;
    width: 100%;
    font-size: 0.78rem;
    white-space: normal;
    line-height: 1.4;
    text-align: center;
    color: var(--text-3);
  }

  .controls-inner {
    padding: var(--s2) var(--s4);
    flex-direction: column;
    align-items: stretch;
    gap: var(--s2);
  }

  .controls-right {
    justify-content: space-between;
  }

  .main { padding: var(--s5) var(--s4); }

  .grid { gap: var(--s4); }

  .modal {
    padding: var(--s3);
    align-items: flex-end;   /* sheet depuis le bas sur mobile */
  }

  .modal-content {
    border-radius: var(--r-xl) var(--r-xl) var(--r-lg) var(--r-lg);
    max-height: 95dvh;
  }

  .modal-header {
    padding: var(--s4);
  }

  .modal-nav {
    padding: var(--s3) var(--s4);
  }

  .modal-nav-btn span { display: none; }  /* icônes seules sur mobile */
  .modal-nav-btn { padding: 0 var(--s2); }

  /* Description : sous la vidéo en colonne */
  .modal-body { flex-direction: column; }

  .modal-desc-panel {
    flex: 0 0 auto;
    max-width: 100%;
    border-left: none;
    border-top: 1px solid var(--border);
    padding: var(--s4) var(--s5);
  }
}

/* Très petit écran */
@media (max-width: 374px) {
  .sort-select { font-size: 0.75rem; }
}


/* ===== PREFERS-REDUCED-MOTION ==================================== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .video-card:hover  { transform: none; }
  .card-play-btn     { transition: none; }
  .card-thumb::before{ animation: none; background: var(--surface-alt); }
}
