/* Common shared styles for Clipsou Streaming */

/* Base */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  color-scheme: light; /* keep light controls regardless of system */
}

/* Type label mappings via data-type (support attribute on .card-info or on .card) */
.card .card-info[data-type="film"]::before,
.card[data-type="film"] .card-info::before { content: 'Film'; }
.card .card-info[data-type="serie"]::before,
.card[data-type="serie"] .card-info::before { content: 'Série'; }
.card .card-info[data-type="série"]::before,
.card[data-type="série"] .card-info::before { content: 'Série'; }
.card .card-info[data-type="trailer"]::before,
.card[data-type="trailer"] .card-info::before { content: 'Trailer'; }

* { box-sizing: border-box; }

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

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

/* Theme variables (can be overridden per page) */
:root {
  --bg-1: #0b1117;
  --bg-2: #0e141b;
  --brand-1: #2B22EE;
  --brand-2: #6c5ce7;
}

body {
  margin: 0;
  min-height: 100vh;
  color: #fff;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
}

/* Navigation (banderole) */
nav[aria-label="Navigation principale"] {
  background: linear-gradient(180deg, rgba(0,0,0,0.85), rgba(0,0,0,0.65));
  backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  padding: 0 40px; /* horizontal only on desktop to lock bar height */
  height: 70px; /* fixed desktop height for consistency */
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: none;
  position: sticky;
  top: 0;
  z-index: 1000;
}

/* Desktop/tablet: shift the whole left group (logo + Accueil) by 40px */
@media (min-width: 769px) {
  .logo { margin-left: 40px; }
}

.logo {
  font-size: 28px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo img {
  width: 35px;
  height: 35px;
  margin-right: 10px;
  display: block;
  flex-shrink: 0;
  object-fit: contain;
}

.logo span { white-space: nowrap; }
.logo span:nth-of-type(1), .logo span:nth-of-type(2) { color: var(--brand-1); }
.logo span:nth-of-type(1) { font-weight: 800; }
.logo span:nth-of-type(2) { margin-left: 6px; font-weight: 300; }

.nav-links { display: flex; gap: 15px; }
.nav-links a {
  padding: 10px 20px;
  border-radius: 5px;
  font-weight: 600;
  color: #fff;
  text-decoration: none;
  transition: all 0.3s ease;
  white-space: nowrap;
}

/* Ensure the Recherche button is visible on all pages (desktop/tablet) */
.nav-links .search-link { display: inline-flex; align-items: center; gap: 8px; position: relative; }
.nav-links .search-link::before {
  content: '';
  display: inline-block;
  width: 20px; height: 20px;
  background: url('loupe.png') no-repeat center / contain;
  filter: none !important;
  opacity: 1 !important;
}

/* Desktop/tablet: ensure search link text is visible (override mobile text-indent rules) */
@media (min-width: 769px) {
  .nav-links .search-link {
    text-indent: 0 !important;
    overflow: visible !important;
    width: auto !important;
    height: auto !important;
    padding: 10px 20px !important;
    position: relative !important;
  }
  .nav-links .search-link::before {
    position: static !important;
    left: auto !important;
    top: auto !important;
    transform: none !important;
    width: 20px !important;
    height: 20px !important;
  }
  /* Keep actions aligned to the far right */
  nav[aria-label="Navigation principale"] .nav-links {
    display: flex !important;
    gap: 15px !important;
    margin-left: auto !important;
    visibility: visible !important;
  }
  nav[aria-label="Navigation principale"] .nav-links .search-link {
    display: inline-flex !important;
    visibility: visible !important;
  }
  /* Fiche pages: harden visibility in case of cascade conflicts */
  body.fiche-page-view nav[aria-label="Navigation principale"] .nav-links .search-link {
    display: inline-flex !important;
    visibility: visible !important;
    color: #ffffff !important;
  }
}

/* When Accueil is placed next to the logo, keep a small gap and slight offset */
.logo .home-link { margin-left: 12px; position: relative; top: 2.5px; left: 60px; }

/* Accueil visual style: slightly bigger and bolder with leading icon */
.home-link {
  font-weight: 500; /* a bit bolder */
  font-size: 1.02rem; /* a bit larger */
  padding: 0;
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.home-link::before {
  content: '';
  display: inline-block;
  width: 18px;
  height: 18px;
  background: url('Accueil.png') no-repeat center / contain;
}

/* Cards (base) */
.card {
  background: linear-gradient(180deg, rgba(26,35,50,0.65), rgba(26,35,50,0.9));
  border-radius: 12px;
  overflow: hidden;
  transition: all 0.3s ease;
  border: 1px solid rgba(255, 255, 255, 0.12);
  cursor: pointer;
  position: relative;
  box-shadow:
    0 10px 30px rgba(0,0,0,0.35),
    inset 0 1px 0 rgba(255,255,255,0.06);
}
.card:hover { 
  transform: translateY(-6px);
  box-shadow: 0 14px 38px rgba(0,0,0,0.45);
}

/* Disable any old overlay watermark: logo now lives in the info bar */
.card::after { content: none; }

.card .card-media > img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}
.card:hover .card-media > img { transform: none; }

/* Brand badge (shared across pages) */
.brand-badge {
  padding: 7px;
  border-radius: 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.85);
  border: 1px solid rgba(255,255,255,0.12);
}
.brand-badge img {
  display: block;
  width: auto;
  height: 10px;
  object-fit: contain;
}

/* Overlay placement on cards: anchor contains a .card-media wrapper */
.card .card-media { 
  position: relative; 
  display: block; 
  margin-bottom: 0; 
  aspect-ratio: 9/12; /* lock poster ratio consistently */
  overflow: hidden; /* clip image to rounded card */
}
.card .card-media .brand-badge {
  position: absolute;
  left: 6px; /* match index/search */
  bottom: 8px; /* match index/search */
  margin-top: 0;
  z-index: 2;
  pointer-events: none; /* don't block clicks on the card */
}

/* Fine-tune badge position for similar-section cards (fiche page) */
.similar-section .card .card-media .brand-badge {
  bottom: 16px; /* raised more to align with other cards */
}

/* Mobile tweak for similar-section cards */
@media (max-width: 768px) {
  .similar-section .card .card-media .brand-badge {
    bottom: 12px; /* adjust for mobile consistently */
  }
}

/* Prevent global card image rules from cropping the badge logo */
.card .card-media .brand-badge img {
  width: auto !important;
  height: 10px !important;
  aspect-ratio: auto !important;
  object-fit: contain !important;
  max-width: none !important; /* prevent stretching */
}

/* Ensure no badge inside popups */
.fiche-popup .brand-badge { display: none !important; }

.card-info {
  position: relative;
  width: 100%;
  padding: 10px 10px; /* tighter vertical space, same text size */
  padding-right: 12px; /* no reserved space for logo */
  display: flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  text-align: left;
  white-space: nowrap;
  /* Remove Clipsou logo background on cards */
  background-image: none;
}
/* Default label + rating pattern */
.card .card-info::before { content: 'Catégorie'; color: #fff; font-weight: 700; font-size: 14px; margin-right: 6px; }
.card .card-info[data-rating]::after {
  content: ' ⭐ ' attr(data-rating);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  opacity: 1;
  display: inline-block;
  padding: 1px 4px; /* keep small badge while preserving text size */
  background-color: rgba(255, 215, 0, 0.18); /* translucent yellow */
  border-radius: 5px; /* rounded corners */
}

/* Accessibility and UX */
:where(a, button, input, [tabindex]):focus-visible {
  outline: 2px solid rgba(99,102,241,0.9);
  outline-offset: 2px;
  box-shadow: 0 0 0 6px rgba(99,102,241,0.25);
}

* { transition: background-color .25s ease, color .25s ease, border-color .25s ease, transform .25s ease, box-shadow .25s ease; }

/* Scrollbars */
html { scrollbar-color: #615d5d #0a0a0a; scrollbar-width: thin; }
*::-webkit-scrollbar { width: 12px; height: 12px; }
*::-webkit-scrollbar-track { background: #0a0a0a; }
*::-webkit-scrollbar-thumb { background: #000000; border-radius: 8px; border: 3px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background: #000000; }

/* Mobile common rules */
@media (max-width: 768px) {
  /* Remove artificial extra height on mobile so page ends exactly at content */
  html, body {
    min-height: 0 !important;
    height: auto !important;
  }
  body { min-height: auto !important; }
  /* Be defensive: ensure last sections/containers don't add bottom gap */
  main, #contenu, #fiche, #fiche-container {
    margin-bottom: 0 !important;
    padding-bottom: 0 !important;
  }
  .section:last-child,
  .section:last-of-type {
    margin-bottom: 0 !important;
    padding-bottom: 0 !important;
  }
  /* Fiche pages (mobile): ensure the search icon appears at top-right */
  body.fiche-page-view nav[aria-label="Navigation principale"] .nav-links {
    display: flex !important;
    margin-left: auto !important; /* push to right */
    gap: 6px;
  }
  body.fiche-page-view nav[aria-label="Navigation principale"] .nav-links .search-link {
    display: inline-flex !important; /* visible on mobile */
  }
  /* Reduce Clipsou badge size on cards for mobile */
  .card .card-media .brand-badge {
    padding: 4px; /* was 7px */
    border-radius: 4px; /* slightly tighter */
  }
  .similar-section .card .card-media .brand-badge { bottom: 10px; }
  .card .card-media .brand-badge img {
    width: auto !important;
    height: 8px !important; /* was 10px */
    max-width: none !important;
  }
  /* Tight mobile layout: logo left, actions right, no overflow */
  nav[aria-label="Navigation principale"] {
    padding: 10px 12px 12px 12px !important; /* slight extra bottom padding to avoid text clipping */
    min-height: 60px; /* allow auto height to avoid clipping */
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: nowrap;
    column-gap: 6px;
  }
  .logo {
    flex: 1 1 auto;
    min-width: 0;
    overflow: visible; /* allow descenders like 'g' to render fully */
    font-size: clamp(18px, 5.5vw, 22px);
    gap: 4px;
    min-height: 42px; /* slight bump to prevent clipping across devices */
    line-height: 1.2; /* more breathing room for glyphs */
    padding-top: 1px; /* micro offset to center vertically */
    padding-bottom: 4px; /* prevent bottom clipping of letters like 'g' */
  }
  .logo img { width: 18px; height: 18px; flex: 0 0 auto; }
  /* Double the logo size on mobile */
  .logo img { width: 36px; height: 36px; }
  .logo span {
    display: inline-block; /* ensure proper line box for descenders */
    overflow-x: hidden;
    overflow-y: visible; /* let descenders show */
    text-overflow: ellipsis;
    color: var(--brand-1);
    max-width: 75vw;
    line-height: 1.2; /* align with container line-height */
    padding-bottom: 1px; /* micro offset to avoid visual clipping */
  }

  /* Hide any accidental scrollbars on the logo or its text without touching page scrollbars */
  .logo, .logo span {
    -ms-overflow-style: none;     /* IE/Edge */
    scrollbar-width: none;        /* Firefox */
  }
  .logo::-webkit-scrollbar,
  .logo span::-webkit-scrollbar { /* Chrome/Safari */
    display: none;
    width: 0; height: 0;
  }
  .nav-links { display: flex; margin-left: auto !important; gap: 6px; }
  /* Hide Accueil on mobile anywhere in the nav: use the logo to go home */
  .home-link { display: none !important; }

  /* Mobile: make the search link an icon-only 44x44 button without extra padding */
  .nav-links .search-link {
    padding: 0 !important;
    font-size: 16px;
    background: transparent !important;
    border-radius: 5px;
    width: 40px;
    height: 40px;
    border: 0;
    box-shadow: none;
    margin-left: auto !important;
    text-indent: -9999px; /* hide text label on mobile */
    overflow: hidden;
    position: relative;
    display: inline-flex; /* ensure proper centering box */
    align-items: center;
    justify-content: center;
  }
  .nav-links .search-link::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 24px;
    height: 24px;
    background: url('loupe.png') no-repeat center / contain;
    filter: none !important;
    opacity: 1 !important;
  }
}

/* Ultra-small phones: extra tightening */
@media (max-width: 360px) {
  nav[aria-label="Navigation principale"] { padding: 10px 12px !important; min-height: 60px; }
  .logo { gap: 4px; }
  /* Double the logo size on very small mobiles as well */
  .logo img { width: 40px; height: 40px; }
  .logo span { max-width: 72vw; font-size: 0.95em; }
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
