/* ─── DESIGN TOKENS (Amethyst Theme) ─── */
    :root {
      --void: #090710; /* Noir teinté violet très profond */
      --surface: #151124;
      --surface-hover: #1F1935;
      --primary: #9D4EDD; /* Violet vibrant */
      --primary-glow: rgba(157, 78, 221, 0.3);
      --text-primary: #F3E8FF;
      --text-secondary: #9B8BAF;
      --error: #EF4444;
      --success: #10B981;
      --radius-sm: 8px;
      --radius-md: 12px;
      --radius-pill: 999px;
      --transition-fast: 150ms ease;
      --transition-base: 300ms ease;
      --sidebar-width: clamp(280px, 25vw, 360px);
      /* On force Plyr à utiliser notre violet et notre typo */
      --plyr-color-main: var(--primary);
      --plyr-font-family: var(--font-main);

      /* On adapte les menus (vitesse, paramètres) au mode sombre */
      --plyr-video-background: var(--void);
      --plyr-menu-background: var(--surface);
      --plyr-menu-color: var(--text-primary);
      --plyr-tooltip-background: var(--surface-hover);
      --plyr-tooltip-color: var(--text-primary);
    }

/* ─── RESET & BASE ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

* {
    scrollbar-width: thin;
    scrollbar-color: rgba(157, 78, 221, 0.3) transparent;
}

/* Pour Chrome, Edge, Safari, Opera */
::-webkit-scrollbar {
    width: 6px;  /* Très fine, non intrusive */
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent; /* Fond invisible */
}

::-webkit-scrollbar-thumb {
    background: rgba(157, 78, 221, 0.3); /* Un violet translucide par défaut */
    border-radius: var(--radius-pill);
}

/* S'illumine quand on passe la souris dessus */
::-webkit-scrollbar-thumb:hover {
    background: var(--primary); /* Notre Violet Améthyste pur */
}

    html, body {
      height: 100%;
      overflow: hidden;
      background: var(--void);
      color: var(--text-primary);
      font-family: 'Outfit', sans-serif;
      font-weight: 400;
      line-height: 1.5;
      -webkit-font-smoothing: antialiased;
    }

    button { font-family: inherit; border: none; background: none; cursor: pointer; color: inherit; }
    input { font-family: inherit; border: none; outline: none; background: none; color: inherit; }
    img { max-width: 100%; display: block; }

    /* ─── APP SHELL ─── */
    .app-shell {
      display: flex;
      height: 100vh;
      width: 100vw;
      position: relative;
      z-index: 1;
    }

    /* ─── SIDEBAR ─── */
    .sidebar {
      width: var(--sidebar-width);
      min-width: 260px;
      background: var(--surface);
      border-right: 1px solid rgba(157, 78, 221, 0.1);
      display: flex;
      flex-direction: column;
      overflow-y: auto;
      overflow-x: hidden;
      flex-shrink: 0;
    }

    .sidebar-brand {
      padding: 28px 24px 20px;
      display: flex;
      align-items: center;
      gap: 14px;
      border-bottom: 1px solid rgba(157, 78, 221, 0.1);
    }

    .sidebar-label-group {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 16px;
    }

    .sidebar-label {
        font-size: 11px;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 1.5px;
        color: var(--text-secondary);
    }

    .clear-history-btn {
        color: var(--text-secondary);
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 6px;
        border-radius: var(--radius-sm);
        transition: all var(--transition-fast);
        opacity: 0.6;
    }

    .clear-history-btn:hover {
        opacity: 1;
        color: var(--error); /* Devient rouge au survol */
        background: rgba(239, 68, 68, 0.1);
        transform: scale(1.05);
    }

    /* Ton Image de Marque Uploadée */
    .brand-logo {
      width: 40px;
      height: 40px;
      border-radius: var(--radius-sm);
      object-fit: cover;
      box-shadow: 0 0 16px var(--primary-glow);
    }

    .brand-name {
      font-size: 24px;
      font-weight: 700;
      letter-spacing: -0.5px;
      color: var(--text-primary);
    }

    .sidebar-section {
      padding: 24px;
      border-bottom: 1px solid rgba(157, 78, 221, 0.05);
    }

    .sidebar-label {
      display: block;
      font-size: 11px;
      font-weight: 600;
      text-transform: uppercase;
      letter-spacing: 1.5px;
      color: var(--text-secondary);
      margin-bottom: 16px;
    }

    .search-box {
      display: flex;
      align-items: center;
      gap: 8px;
      background: var(--void);
      border: 1px solid rgba(157, 78, 221, 0.2);
      border-radius: var(--radius-pill);
      padding: 6px 6px 6px 18px;
      transition: border-color var(--transition-fast);
    }

    .search-box:focus-within {
      border-color: var(--primary);
      box-shadow: 0 0 0 3px rgba(157, 78, 221, 0.1);
    }

    .search-box input {
      flex: 1;
      font-size: 14px;
      font-weight: 400;
      color: var(--text-primary);
      min-width: 0;
    }

    .search-box input::placeholder { color: var(--text-secondary); font-weight: 300; }

    .search-btn {
      width: 38px;
      height: 38px;
      border-radius: var(--radius-pill);
      background: var(--primary);
      color: white;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-shrink: 0;
      transition: transform var(--transition-fast), box-shadow var(--transition-fast);
    }

    .search-btn:hover {
      transform: scale(1.05);
      box-shadow: 0 0 16px var(--primary-glow);
    }

    .history-list { display: flex; flex-direction: column; gap: 8px; }

    .history-empty {
      font-size: 13px;
      color: var(--text-secondary);
      font-weight: 300;
      padding: 8px 0;
      font-style: italic;
    }

    .history-item {
      display: flex;
      align-items: center;
      gap: 14px;
      padding: 10px;
      border-radius: var(--radius-md);
      cursor: pointer;
      transition: background var(--transition-fast);
      border: 1px solid transparent;
    }

    .history-item:hover {
      background: var(--surface-hover);
      border-color: rgba(157, 78, 221, 0.2);
    }

    .history-thumb {
      width: 44px;
      height: 64px;
      object-fit: cover;
      border-radius: var(--radius-sm);
      background: var(--surface-hover);
      flex-shrink: 0;
    }

    .history-info { min-width: 0; flex: 1; }

    .history-title {
      font-size: 14px;
      font-weight: 600;
      color: var(--text-primary);
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .history-meta {
      font-size: 12px;
      color: var(--text-secondary);
      font-weight: 400;
      margin-top: 4px;
    }

    /* ─── STAGE ─── */
    .stage {
      flex: 1;
      background: var(--void);
      position: relative;
      overflow-y: auto;
      overflow-x: hidden;
    }

    .stage-view {
      display: none;
      opacity: 0;
      padding: 40px;
      max-width: 1300px;
      margin: 0 auto;
      transition: opacity var(--transition-base);
    }

    .stage-view.is-active { display: block; opacity: 1; }

    /* ─── HOME VIEW ─── */
    .hero-empty {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      min-height: 70vh;
      text-align: center;
      padding: 40px;
    }

    .hero-empty-icon {
      width: 150px;
      height: 150px;
      background: var(--surface);
        border-radius: 20px;
      border: 1px solid rgba(157, 78, 221, 0.2);
      display: flex;
      align-items: center;
      justify-content: center;
      margin-bottom: 24px;
      color: var(--primary);
      box-shadow: 0 12px 32px var(--primary-glow);
        img {
            border-radius: 20px;
        }
    }

    .hero-empty-title {
      font-size: 32px;
      font-weight: 700;
      letter-spacing: -0.5px;
      margin-bottom: 12px;
    }

    .hero-empty-sub {
      font-size: 16px;
      color: var(--text-secondary);
      max-width: 450px;
      line-height: 1.6;
    }

    /* ─── SEARCH VIEW ─── */
    .search-header { margin-bottom: 32px; }
    .search-heading { font-size: 24px; font-weight: 700; }
    .search-heading span { color: var(--text-secondary); font-weight: 400; }

    .results-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
      gap: 24px;
    }

    .anime-card { cursor: pointer; }

    .anime-card-visual {
      position: relative;
      aspect-ratio: 2 / 3;
      background: var(--surface);
      border-radius: var(--radius-md);
      overflow: hidden;
      border: 1px solid transparent;
      transition: transform var(--transition-base), box-shadow var(--transition-base), border-color var(--transition-base);
    }

    .anime-card:hover .anime-card-visual {
      transform: translateY(-6px);
      border-color: rgba(157, 78, 221, 0.4);
      box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6), 0 0 24px var(--primary-glow);
    }

    .anime-card-visual img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      transition: transform var(--transition-base);
    }

    .anime-card:hover .anime-card-visual img { transform: scale(1.05); }

    .anime-card-fallback {
      position: absolute;
      inset: 0;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 56px;
      font-weight: 700;
      color: var(--primary);
      opacity: 0.1;
    }

    .anime-card-title {
      margin-top: 12px;
      font-size: 15px;
      font-weight: 600;
      color: var(--text-primary);
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      transition: color var(--transition-fast);
    }

    .anime-card:hover .anime-card-title { color: var(--primary); }

    .loading-grid, .empty-grid {
      grid-column: 1 / -1;
      padding: 80px 20px;
      text-align: center;
      color: var(--text-secondary);
      font-size: 16px;
    }

    /* ─── PLAYER VIEW ─── */
    .player-stage { position: relative; }

    /* Configuration en HAUT de la vidéo */
    .player-top-bar {
      display: flex;
      flex-direction: column;
      gap: 24px;
      margin-bottom: 32px;
      background: var(--surface);
      padding: 24px;
      border-radius: var(--radius-md);
      border: 1px solid rgba(157, 78, 221, 0.15);
    }

    .player-meta-header {
      border-bottom: 1px solid rgba(157, 78, 221, 0.1);
      padding-bottom: 20px;
    }

    .player-meta-title {
      font-size: 28px;
      font-weight: 700;
      letter-spacing: -0.5px;
      margin-bottom: 8px;
    }

    .player-meta-context {
      font-size: 15px;
      color: var(--text-secondary);
      font-weight: 400;
    }

    .player-config {
        display: grid;
        /* Crée des colonnes automatiques qui se transforment en 1 seule ligne si l'écran rétrécit */
        grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
        gap: 24px 32px;
        align-items: start; /* Empêche tout étirement vertical et supprime l'espace vide */
        width: 100%;
    }

    .config-group {
        display: flex;
        flex-direction: column;
        gap: 12px;
        min-width: 0; /* CRUCIAL : Autorise les éléments enfants à être coupés s'ils sont trop longs */
    }

    /* Zone Vidéo Centrale */
    .video-chassis {
      position: relative;
      background: #000;
      border-radius: var(--radius-md);
      overflow: hidden;
      aspect-ratio: 16 / 9;
      box-shadow: 0 20px 50px rgba(0,0,0,0.8), 0 0 0 1px rgba(157, 78, 221, 0.1);
    }

    video {
      width: 100%;
      height: 100%;
      object-fit: contain;
      display: block;
    }

    .plyr {
        border-radius: var(--radius-md);
        height: 100%;
        width: 100%;
    }

    .video-overlay {
      position: absolute;
      inset: 0;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      background: rgba(9, 7, 16, 0.9);
      z-index: 10;
      transition: opacity var(--transition-base);
    }

    .video-overlay.is-hidden { opacity: 0; pointer-events: none; }

    .spinner {
      width: 48px;
      height: 48px;
      border: 3px solid rgba(157, 78, 221, 0.2);
      border-top-color: var(--primary);
      border-radius: 50%;
      animation: spin 0.8s linear infinite;
      margin-bottom: 20px;
    }
    @keyframes spin { to { transform: rotate(360deg); } }

    .video-overlay-text { font-size: 15px; color: var(--text-secondary); }

    .retry-btn {
      padding: 12px 28px;
      background: var(--primary);
      color: white;
      border-radius: var(--radius-pill);
      font-size: 14px;
      font-weight: 600;
      margin-top: 16px;
      transition: transform var(--transition-fast), box-shadow var(--transition-fast);
    }
    .retry-btn:hover {
      transform: translateY(-2px);
      box-shadow: 0 8px 24px var(--primary-glow);
    }

    /* Navigation en BAS de la vidéo */
    .player-bottom-bar {
      margin-top: 32px;
      background: var(--surface);
      padding: 24px;
      border-radius: var(--radius-md);
      border: 1px solid rgba(157, 78, 221, 0.1);
    }

    .episode-nav {
      display: flex;
      gap: 16px;
      margin-bottom: 32px;
      border-bottom: 1px solid rgba(157, 78, 221, 0.1);
      padding-bottom: 24px;
    }

    .nav-btn {
      flex: 1;
      padding: 14px 24px;
      background: var(--void);
      border: 1px solid rgba(157, 78, 221, 0.2);
      color: var(--text-primary);
      border-radius: var(--radius-sm);
      font-size: 15px;
      font-weight: 600;
      transition: all var(--transition-fast);
      display: flex;
      justify-content: center;
      align-items: center;
      gap: 12px;
    }

    .nav-btn:not(:disabled):hover {
      background: var(--primary);
      border-color: var(--primary);
      box-shadow: 0 8px 24px var(--primary-glow);
      color: white;
    }

    .nav-btn:disabled {
      opacity: 0.4;
      cursor: not-allowed;
    }

    /* ─── PILLS (Selecteurs) ─── */
    .selector-label {
      display: block;
      font-size: 12px;
      font-weight: 600;
      text-transform: uppercase;
      letter-spacing: 1px;
      color: var(--text-secondary);
      margin-bottom: 12px;
    }

    .pill-group {
        display: flex;
        flex-wrap: wrap;
        gap: 10px;
        min-width: 0;
    }

    .pill {
        padding: 10px 20px;
        border-radius: var(--radius-pill);
        background: var(--void);
        border: 1px solid rgba(157, 78, 221, 0.15);
        color: var(--text-secondary);
        font-size: 14px;
        font-weight: 500;
        cursor: pointer;
        transition: all var(--transition-fast);
        user-select: none;

        /* --- CORRECTION OVERFLOW PARFAITE --- */
        max-width: 100%;          /* Ne dépassera jamais de la grille */
        white-space: nowrap;      /* Force sur une seule ligne */
        overflow: hidden;         /* Cache ce qui dépasse */
        text-overflow: ellipsis;  /* Ajoute les '...' élégamment */
    }

    .pill:hover {
      border-color: rgba(157, 78, 221, 0.5);
      color: var(--text-primary);
    }

    .pill.is-active {
      background: var(--primary);
      border-color: var(--primary);
      color: white;
      box-shadow: 0 4px 16px var(--primary-glow);
      font-weight: 600;
    }

    .pill-empty {
      font-size: 14px;
      color: var(--text-secondary);
      font-style: italic;
    }

    /* ─── TOASTS ─── */
    .toast-stack {
      position: fixed;
      bottom: 32px;
      right: 32px;
      display: flex;
      flex-direction: column;
      gap: 12px;
      z-index: 10000;
      pointer-events: none;
    }

    .toast-item {
      padding: 16px 24px;
      border-radius: var(--radius-md);
      background: var(--surface);
      border: 1px solid rgba(157, 78, 221, 0.2);
      color: var(--text-primary);
      font-size: 14px;
      font-weight: 500;
      box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
      transform: translateY(20px);
      opacity: 0;
      transition: all var(--transition-base);
      pointer-events: auto;
    }

    .toast-item.is-visible { transform: translateY(0); opacity: 1; }
    .toast-item.type-error { border-left: 4px solid var(--error); }
    .toast-item.type-success { border-left: 4px solid var(--success); }

    .mobile-header { display: none; }
    .drawer-backdrop { display: none; }

@media (max-width: 900px) {
    html, body { height: auto; overflow: auto; }
    .app-shell { flex-direction: column; height: auto; }

    /* Le nouveau Header Mobile */
    .mobile-header {
        display: flex;
        align-items: center;
        padding: 16px 20px;
        background: var(--surface);
        border-bottom: 1px solid rgba(157, 78, 221, 0.1);
        position: sticky;
        top: 0;
        z-index: 90;
    }

    .burger-btn {
        color: var(--text-primary);
        padding: 8px;
        margin-left: -8px;
        margin-right: 12px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .mobile-brand { display: flex; align-items: center; gap: 10px; }
    .mobile-brand-logo { width: 28px; height: 28px; border-radius: 6px; box-shadow: 0 0 10px var(--primary-glow); object-fit: cover;}
    .mobile-brand-name { font-size: 18px; font-weight: 700; color: var(--text-primary); }

    /* La Sidebar devient un tiroir flottant */
    .sidebar {
        position: fixed;
        top: 0;
        left: -100%; /* Caché par défaut à gauche de l'écran */
        width: 85vw;
        max-width: 320px;
        height: 100vh;
        max-height: 100vh;
        border-right: 1px solid rgba(157, 78, 221, 0.1);
        z-index: 1000;
        transition: left var(--transition-base) cubic-bezier(0.4, 0, 0.2, 1);
        padding-bottom: 40px;
    }

    .sidebar.is-open {
        left: 0;
        box-shadow: 4px 0 32px rgba(0, 0, 0, 0.6);
    }

    /* Cache le logo dans le tiroir puisqu'il est déjà dans le header mobile */
    .sidebar-brand { display: none; }

    /* Le fond en verre dépoli */
    .drawer-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(9, 7, 16, 0.7);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        z-index: 999;
        opacity: 0;
        pointer-events: none;
        transition: opacity var(--transition-base);
    }

    .drawer-backdrop.is-open {
        opacity: 1;
        pointer-events: auto;
    }

    /* (Le reste de ton responsive CSS actuel reste ici : .stage, .results-grid, etc.) */
    .stage { height: auto; overflow: visible; padding-bottom: 60px; }
    .stage-view { padding: 24px 16px; }
    .results-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 16px; }
    .pill-group { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 8px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
    .pill-group::-webkit-scrollbar { display: none; }
    .pill { white-space: nowrap; flex-shrink: 0; }
    .player-top-bar { padding: 16px; margin-bottom: 20px; gap: 16px; }
    .player-meta-title { font-size: 22px; margin-bottom: 4px; }
    .player-config { gap: 20px; flex-direction: column; }
    .player-bottom-bar { padding: 16px; margin-top: 20px; }
    .episode-nav { flex-direction: column; gap: 12px; padding-bottom: 20px; }
    .nav-btn { width: 100%; padding: 16px; }
    .toast-stack { bottom: 16px; right: 16px; left: 16px; align-items: center; }
    .toast-item { width: 100%; text-align: center; }
}