/* ==================================
       Dark Theme · Modern UI (CSS)
       ==================================
       - Netflix-like hero carousel (weekly trending, sorted by rating)
       - Search with suggestions + infinite scroll
       - LocalStorage search history (last 5)
       - Details overlay (single-page)
       - Initial feed (time-ordered) + search results prepended above
    */

    :root {
      --bg: #0b0e11;
      --card: #11151a;
      --muted: #1a1f26;
      --text: #e5eaf0;
      --subtext: #b6bdc7;
      --accent: #f1c40f; /* gold */
      --accent-2: #00d1b2; /* teal */
      --danger: #ff6b6b;
      --shadow: 0 10px 25px rgba(0,0,0,0.35);
      --radius: 16px;
      --radius-sm: 10px;
      --maxw: 1200px;
    }

    * { box-sizing: border-box; }
    html, body { height: 100%; }
    body {
      margin: 0;
      background: radial-gradient(1200px 600px at 20% -10%, #151a21 0%, #0b0e11 60%);
      color: var(--text);
      font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
      line-height: 1.45;
    }
    a { color: inherit; text-decoration: none; }

    /* Header */
    header {
      position: sticky; top: 0; z-index: 50;
      background: linear-gradient(180deg, rgba(11,14,17,0.95) 0%, rgba(11,14,17,0.6) 100%);
      backdrop-filter: saturate(140%) blur(8px);
      border-bottom: 1px solid rgba(255,255,255,0.06);
    }
    .nav { max-width: var(--maxw); margin: 0 auto; padding: 14px clamp(12px,4vw,24px); display: flex; align-items: center; gap: 16px; }
    .brand { font-weight: 800; letter-spacing: .4px; font-size: clamp(16px,2.2vw,22px); display:flex; align-items:center; gap:10px; }
    .brand-badge { width: 45px; height: 45px; }
    /*.brand-badge { width: 10px; height: 10px; background: var(--accent); border-radius: 3px; box-shadow: 0 0 0 3px rgba(241,196,15,0.15); }*/

    /* Search */
    .searchbar { position: relative; flex: 1 1 500px; max-width: 680px; margin-left: auto; }
    .searchbar input {
      width: 100%; padding: 14px 46px 14px 16px; border-radius: var(--radius);
      border: 1px solid rgba(255,255,255,0.08);
      background: var(--card); color: var(--text); font-size: 16px; outline: none; box-shadow: var(--shadow);
    }
    .searchbar input::placeholder { color: #8a93a3; }
    .searchbar .icon { position:absolute; right:12px; top:50%; transform:translateY(-50%); opacity:.8; }
    
    .suggestions { position: absolute; left:0; right:0; top: calc(100% + 8px); background: var(--muted); border:1px solid rgba(255,255,255,0.06); border-radius: var(--radius-sm); overflow:hidden; box-shadow: var(--shadow); display:none; max-height:360px; overflow-y:auto; }
    .suggestions.visible { display:block; }
    .suggestion-item { padding:10px 12px; cursor:pointer; display:flex; align-items:center; gap:10px; }
    .suggestion-item:hover { background: rgba(255,255,255,0.05); }
    .suggestion-thumb { width: 32px; height: 48px; object-fit: cover; border-radius: 6px; background:#232831; flex:0 0 auto; }
    .suggestion-title { font-size:14px; color:var(--text); }
    .suggestion-year { color:var(--subtext); font-size:12px; }
    .hidden {
  display: none !important;
}

.cancel-btn {
  position: absolute;
  right: 38px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--subtext);
  font-size: 18px;
  cursor: pointer;
  opacity: 0.6;
}

.cancel-btn:hover {
  opacity: 1;
}

    main { max-width: var(--maxw); margin: 0 auto; padding: 0 clamp(12px,4vw,24px) 80px; }

    /* History chips */
    .history { display:flex; gap:10px; flex-wrap: wrap; margin: 10px 0 22px; }
    .chip { border:1px solid rgba(255,255,255,0.08); background:#0f1318; color: var(--subtext); padding: 8px 12px; border-radius: 999px; font-size:12px; cursor:pointer; }
    .chip:hover { color: var(--text); border-color: rgba(255,255,255,0.22); }

    /* HERO CAROUSEL */
    .hero-wrap { position: relative; width: 100%; height: 78vh; max-height: 820px; min-height: 420px; overflow: hidden; border-bottom: 1px solid rgba(255,255,255,0.06); }
    .hero-track { display:flex; height:100%; transition: transform .6s ease; }
    .hero-slide { min-width:100%; position:relative; display:flex; align-items:flex-end; }
    .hero-bg { position:absolute; inset:0; background: #111; }
    .hero-bg img { width:100%; height:100%; object-fit: cover; filter: brightness(.72) saturate(105%); }
    .hero-gradient { position:absolute; inset:0; background: linear-gradient(180deg, rgba(0,0,0,0.25) 0%, rgba(0,0,0,0.65) 65%, rgba(0,0,0,0.85) 100%); z-index:1; }
    .hero-video { position:absolute; inset:0; display:none; z-index:0; }
    .hero-video iframe { width:100%; height:100%; border:0; }
    .hero-slide.playing .hero-video { display:block; }
    .hero-content { position: relative; z-index: 2; padding: clamp(16px,4vw,36px); max-width: 880px; }
    .hero-title { font-size: clamp(22px, 4vw, 42px); font-weight: 900; margin: 0 0 8px; }
    .hero-sub { color: var(--subtext); margin-bottom: 12px; }
    .hero-overview { color: var(--text); max-width: 70ch; }
    .hero-btns { display:flex; gap:10px; margin-top: 14px; flex-wrap: wrap; }
    .btn { background: var(--accent); color:#0a0a0a; font-weight:800; border:none; border-radius: 12px; padding: 10px 16px; cursor:pointer; transition: filter 160ms ease; box-shadow: var(--shadow); }
    .btn:hover { filter: brightness(1.05); }
    .btn.ghost { background: transparent; color: var(--text); border: 1px solid rgba(255,255,255,0.2); }
    .btn.ghost:hover { border-color: var(--text); }
    .hero-arrow { position:absolute; top:50%; transform: translateY(-50%); font-size: 26px; background: rgba(0,0,0,0.45); color:#fff; border:none; cursor:pointer; z-index: 5; padding: 10px 12px; border-radius: 999px; backdrop-filter: blur(2px); }
    .hero-arrow.left { left: 12px; }
    .hero-arrow.right { right: 12px; }

    /* Grid of cards */
    .section-title { font-size: clamp(18px, 2.4vw, 24px); font-weight: 700; margin: 22px 0 10px; }
    .subtle { color: var(--subtext); font-size: 14px; }
    .grid { display:grid; gap:16px; grid-template-columns: repeat(2, 1fr); }
    @media (min-width: 640px) { .grid { grid-template-columns: repeat(3, 1fr); } }
    @media (min-width: 920px) { .grid { grid-template-columns: repeat(5, 1fr); } }

    .card { background: linear-gradient(180deg, #0f141a 0%, #0b0e11 100%); border:1px solid rgba(255,255,255,0.06); border-radius: var(--radius); overflow:hidden; transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease; cursor:pointer; }
    .card:hover { transform: translateY(-4px); border-color: rgba(241,196,15,0.35); box-shadow: 0 12px 28px rgba(241,196,15,0.09); }
    .poster { width: 100%; aspect-ratio: 2/3; object-fit: cover; background: #1b2028; display: block; }
    .card-body { padding: 10px 10px 12px; }
    .title { font-size: 14px; font-weight: 700; color: var(--text); margin: 4px 0 6px; min-height: 36px; }
    .meta { display:flex; justify-content: space-between; align-items:center; font-size:12px; color: var(--subtext); }

    /* Loaders & messages */
    .center { display:grid; place-items:center; padding: 20px; color: var(--subtext); }

    /* Details overlay */
    .details { position: fixed; inset:0; z-index: 60; display:none; background: rgba(7,9,12,0.94); backdrop-filter: blur(8px); overflow-y:auto; padding: 24px; }
    .details.visible { display:block; }
    .details-card { max-width: 980px; margin: 0 auto; background: var(--card); border-radius: 20px; border: 1px solid rgba(255,255,255,0.06); overflow:hidden; box-shadow: var(--shadow); }
    .details-top { display:grid; grid-template-columns: 1fr; }
    @media (min-width: 860px) { .details-top { grid-template-columns: 320px 1fr; } }
    .details-poster { width: 100%; height:100%; object-fit: cover; aspect-ratio: 2/3; background:#1b2028; margin-bottom: 1rem;  border-radius: 8px; }
    .details-body { padding: clamp(16px,3vw,28px); width: 100%; }
    .details-title { font-size: clamp(20px,3vw,28px); font-weight: 800; margin: 0 0 8px; }
    .details-sub { color: var(--subtext); margin-bottom: 12px; }
    .pill { display:inline-block; font-size: 12px; color:#0b0e11; background: var(--accent); padding: 6px 10px; border-radius: 999px; font-weight: 800; }
    .divider { height:1px; background: rgba(255,255,255,0.08); margin: 16px 0; }
    .kv { display:grid; grid-template-columns: 120px 1fr; gap:10px; margin:8px 0; font-size:14px; }
    .kv .k { color: var(--subtext); }
    .plot { color: var(--text); line-height: 1.6; margin-top: 6px; }
    .details-actions { display:flex; gap:10px; margin-top: 16px; flex-wrap:wrap; }
    .back { background: transparent; color: var(--text); border: 1px solid rgba(255,255,255,0.2); }
    .back:hover { border-color: var(--text); }

    footer { color: var(--subtext); font-size: 12px; text-align:center; padding: 36px 12px; opacity: .8; }

#detailsTrailerBox {
  width: 100%;
  max-width: 640px;
  aspect-ratio: 16/9;
  margin: 24px auto 0 auto;
  border-radius: 12px;
  overflow: hidden;
  background: #151a21;
  box-shadow: 0 4px 24px rgba(0,0,0,0.18);
  display: flex;
  align-items: center;
  justify-content: center;
}

#detailsTrailerBox iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
  border-radius: 12px;
}