/* ================================================================
   Plex Movie Browser — Dark Cinematic Theme
   ================================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }   /* beat any author display: rule */

:root {
  --bg:        #0d0d0d;
  --surface:   #181818;
  --surface2:  #222;
  --border:    #2c2c2c;
  --text:      #e8e8e8;
  --muted:     #777;
  --accent:    #e5a00d;
  --accent-bg: rgba(229,160,13,.12);
  --accent-border: rgba(229,160,13,.35);
  --red:       #e05252;
  --green:     #52c97a;
  --blue:      #528be0;
  --live:      #e05252;
  --r:         8px;
}

html { font-size: 15px; color-scheme: dark; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

::-webkit-scrollbar         { width: 6px; height: 6px; }
::-webkit-scrollbar-track   { background: transparent; }
::-webkit-scrollbar-thumb   { background: #333; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #555; }

/* ================================================================
   STREAM BANNER
   ================================================================ */
.stream-banner {
  position: sticky; top: 0; z-index: 200;
  background: #1a0a0a;
  border-bottom: 2px solid var(--live);
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 10px;
  padding: 8px 18px;
  animation: slideDown .25s ease;
}
@keyframes slideDown {
  from { transform: translateY(-100%); opacity: 0; }
  to   { transform: none; opacity: 1; }
}
.stream-banner[hidden] { display: none; }

.stream-banner-left  { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.stream-banner-right { display: flex; align-items: center; gap: 8px;  flex-wrap: wrap; }

/* pulsing red dot */
.stream-pulse {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--live); flex-shrink: 0;
  animation: pulse 1.4s ease infinite;
}
@keyframes pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(224,82,82,.6); }
  50%      { box-shadow: 0 0 0 6px rgba(224,82,82,0); }
}

.stream-label {
  font-size: .68rem; font-weight: 800; letter-spacing: 1px;
  color: var(--live); background: rgba(224,82,82,.15);
  border: 1px solid rgba(224,82,82,.35);
  border-radius: 4px; padding: 2px 6px;
}

.stream-title  { font-size: .88rem; font-weight: 600; color: var(--text); }
.stream-elapsed{ font-size: .75rem; color: var(--muted); }

.stream-url-label { font-size: .72rem; color: var(--muted); white-space: nowrap; }

.stream-url {
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: .75rem; color: var(--accent);
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 5px; padding: 3px 8px;
  max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.stream-copy-btn {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--r); color: var(--text); cursor: pointer;
  font-size: .72rem; padding: 4px 10px; transition: all .14s; white-space: nowrap;
}
.stream-copy-btn:hover { border-color: var(--accent); color: var(--accent); }
.stream-copy-btn.copied { border-color: var(--green); color: var(--green); }

.stream-stop-btn {
  background: rgba(224,82,82,.1); border: 1px solid rgba(224,82,82,.4);
  border-radius: var(--r); color: var(--live); cursor: pointer;
  font-size: .72rem; padding: 4px 10px; transition: all .14s; white-space: nowrap;
}
.stream-stop-btn:hover { background: var(--live); color: #fff; }

/* ================================================================
   HEADER
   ================================================================ */
.header {
  position: sticky; top: 0; z-index: 100;
  height: 60px;
  background: rgba(13,13,13,.96);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 14px; padding: 0 18px;
}

.logo { font-size: 1.15rem; font-weight: 700; white-space: nowrap; color: var(--accent); }
.movie-count { font-size: .75rem; color: var(--muted); white-space: nowrap; }
.header-center { flex: 1; min-width: 0; max-width: 560px; margin: 0 auto; }

.search-wrap { position: relative; display: flex; align-items: center; }

.search-icon {
  position: absolute; left: 11px; width: 15px; height: 15px;
  color: var(--muted); pointer-events: none;
}

#searchInput {
  width: 100%;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 22px; color: var(--text); font-size: .88rem;
  padding: 7px 34px; outline: none; transition: border-color .18s;
}
#searchInput:focus       { border-color: var(--accent); }
#searchInput::placeholder { color: var(--muted); }
#searchInput::-webkit-search-cancel-button { display: none; }

.clear-btn {
  position: absolute; right: 10px;
  background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: .7rem; padding: 4px; display: none;
}
.clear-btn.visible { display: block; }

#sortSelect {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--r); color: var(--text); font-size: .8rem;
  padding: 6px 10px; cursor: pointer; outline: none; white-space: nowrap;
}
#sortSelect:focus { border-color: var(--accent); }

/* ================================================================
   FILTER BAR
   ================================================================ */
.filter-bar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 8px 18px;
}

/* ── Controls row ── */
.filter-controls-row {
  display: flex; align-items: flex-start; gap: 20px;
  flex-wrap: wrap; overflow-x: auto;
}
.filter-controls-row::-webkit-scrollbar { height: 3px; }

/* ── Genre dropdown ── */
.genre-dropdown { position: relative; }

.genre-dropdown-btn {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 14px; color: var(--text); cursor: pointer;
  font-size: .72rem; padding: 3px 10px; white-space: nowrap;
  transition: border-color .14s, color .14s; line-height: 1.4;
}
.genre-dropdown-btn:hover { border-color: var(--accent); color: var(--text); }
.genre-dropdown-btn.has-selection {
  background: var(--accent-bg); border-color: var(--accent);
  color: var(--accent); font-weight: 600;
}
.genre-arrow { font-size: .6rem; color: var(--muted); transition: transform .15s; }
.genre-dropdown.open .genre-arrow { transform: rotate(180deg); }

.genre-panel {
  position: fixed;          /* viewport-relative — never clipped by parent overflow */
  z-index: 9999;            /* above everything including modals */
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 8px 28px rgba(0,0,0,.55);
  min-width: 195px; padding: 4px 0;
  /* top/left set by JS on open */
}
.genre-scroll {
  max-height: 260px; overflow-y: auto; padding: 2px 0;
}
.genre-scroll::-webkit-scrollbar { width: 4px; }
.genre-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.genre-item {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 14px; cursor: pointer;
  font-size: .76rem; color: var(--text);
  user-select: none; transition: background .1s;
}
.genre-item:hover { background: var(--surface); }
.genre-item input[type=checkbox] {
  accent-color: var(--accent); cursor: pointer;
  width: 13px; height: 13px; flex-shrink: 0;
}
.genre-all-item { font-weight: 600; padding: 6px 14px; }
.genre-divider { height: 1px; background: var(--border); margin: 3px 0; }

.filter-group { display: flex; flex-direction: column; gap: 5px; flex-shrink: 0; }
.filter-group label {
  font-size: .68rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: .5px; font-weight: 600; white-space: nowrap;
}

.chip-row { display: flex; flex-wrap: nowrap; gap: 4px; overflow: hidden; }

.chip, .toggle {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 14px; color: var(--muted); cursor: pointer;
  font-size: .72rem; padding: 3px 9px; white-space: nowrap;
  transition: all .14s; line-height: 1.4;
}
.chip:hover, .toggle:hover { border-color: var(--accent); color: var(--text); }
.chip.active, .toggle.active {
  background: var(--accent-bg); border-color: var(--accent);
  color: var(--accent); font-weight: 600;
}

#ratingFilter { width: 110px; accent-color: var(--accent); cursor: pointer; margin-top: 2px; }

.year-row { display: flex; align-items: center; gap: 5px; }
.year-row input {
  width: 64px; background: var(--surface2); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text); font-size: .78rem;
  padding: 4px 7px; outline: none;
  -moz-appearance: textfield;
}
.year-row input::-webkit-outer-spin-button,
.year-row input::-webkit-inner-spin-button { -webkit-appearance: none; }
.year-row input:focus { border-color: var(--accent); }
.year-row span { color: var(--muted); font-size: .8rem; }

.reset-btn {
  background: none; border: 1px solid var(--border);
  border-radius: var(--r); color: var(--muted); cursor: pointer;
  font-size: .72rem; padding: 4px 10px; white-space: nowrap;
  flex-shrink: 0; align-self: flex-end; margin-left: auto; transition: all .14s;
}
.reset-btn:hover { border-color: var(--red); color: var(--red); }

/* ================================================================
   MAIN / GRID
   ================================================================ */
.main { flex: 1; padding: 18px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 14px;
}

/* ── Card ── */
.card {
  position: relative; border-radius: var(--r); overflow: hidden;
  cursor: pointer; background: var(--surface);
  aspect-ratio: 2/3;
  transition: transform .2s ease, box-shadow .2s ease;
  outline: none;
}
.card:hover, .card:focus-visible {
  transform: scale(1.045) translateY(-4px);
  box-shadow: 0 18px 48px rgba(0,0,0,.7);
  z-index: 2;
}
.card:focus-visible { outline: 2px solid var(--accent); }

/* skeleton shimmer */
.card::before {
  content: ''; position: absolute; inset: 0; z-index: 0;
  background: linear-gradient(105deg, var(--surface) 30%, var(--surface2) 50%, var(--surface) 70%);
  background-size: 200% 100%; animation: shimmer 1.6s infinite;
}
.card.img-loaded::before { display: none; }
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.card-img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; display: block;
  opacity: 0; transition: opacity .3s; z-index: 1;
}
.card.img-loaded .card-img { opacity: 1; }
.card.watched .card-img { filter: brightness(.52) saturate(.6); }

/* hover overlay */
.card-overlay {
  position: absolute; inset: 0; z-index: 2;
  background: linear-gradient(to top, rgba(0,0,0,.92) 40%, transparent 100%);
  opacity: 0; transition: opacity .18s;
  display: flex; flex-direction: column; justify-content: flex-end;
  padding: 9px;
}
.card:hover .card-overlay,
.card:focus-visible .card-overlay { opacity: 1; }

.card-title  { font-size: .76rem; font-weight: 600; line-height: 1.3; margin-bottom: 2px; }
.card-sub    { font-size: .67rem; color: var(--muted); }
.card-genres { font-size: .62rem; color: var(--accent); margin-top: 3px;
               white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Stream button on card hover */
.card-stream-btn {
  position: absolute; top: 8px; right: 8px; z-index: 3;
  background: rgba(0,0,0,.75); border: 1px solid rgba(255,255,255,.15);
  border-radius: 6px; color: var(--text); cursor: pointer;
  font-size: .65rem; padding: 3px 7px; white-space: nowrap;
  opacity: 0; transition: opacity .18s, background .14s;
  pointer-events: none;
}
.card:hover .card-stream-btn { opacity: 1; pointer-events: auto; }
.card-stream-btn:hover { background: var(--live); border-color: var(--live); }

/* badges */
.badge-res {
  position: absolute; top: 6px; right: 6px; z-index: 3;
  background: rgba(0,0,0,.72); border: 1px solid rgba(255,255,255,.13);
  border-radius: 4px; font-size: .58rem; font-weight: 700;
  padding: 2px 5px; letter-spacing: .4px;
}
.badge-4k   { color: var(--accent); border-color: var(--accent-border); }
.badge-1080 { color: var(--blue); }
.badge-hd   { color: #aaa; }

/* When streaming, badge moves so it doesn't overlap stream btn */
.card:hover .badge-res { display: none; }

.badge-watched {
  position: absolute; top: 6px; left: 6px; z-index: 3;
  background: rgba(82,201,122,.82); border-radius: 50%;
  width: 19px; height: 19px;
  display: flex; align-items: center; justify-content: center;
  font-size: .6rem; font-weight: 700; color: #000;
}

/* ── Empty / Loading ── */
.loading-state, .empty-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 14px;
  padding: 90px 20px; color: var(--muted); font-size: .9rem; text-align: center;
}
.empty-state span { font-size: 2.8rem; }
.empty-state button {
  background: none; border: 1px solid var(--border);
  border-radius: var(--r); color: var(--muted); cursor: pointer;
  font-size: .8rem; padding: 6px 16px; margin-top: 4px; transition: all .14s;
}
.empty-state button:hover { border-color: var(--accent); color: var(--accent); }

.spinner {
  width: 38px; height: 38px;
  border: 3px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ================================================================
   STATUS BAR
   ================================================================ */
.status-bar {
  position: sticky; bottom: 0; z-index: 50;
  height: 38px;
  background: rgba(13,13,13,.96); backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 18px; gap: 10px;
  font-size: .75rem; color: var(--muted);
}
.refresh-btn {
  background: none; border: 1px solid var(--border);
  border-radius: var(--r); color: var(--muted); cursor: pointer;
  font-size: .72rem; padding: 4px 10px; margin-left: auto; transition: all .14s;
}
.refresh-btn:hover { border-color: var(--accent); color: var(--accent); }
.refresh-btn.spinning { pointer-events: none; animation: spin .9s linear infinite; }

/* ================================================================
   MODAL
   ================================================================ */
.overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.82);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; backdrop-filter: blur(5px);
  animation: fadeIn .15s ease;
}
.overlay[hidden] { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  position: relative;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; overflow: hidden;
  max-width: 880px; width: 100%; max-height: 90vh;
  animation: slideUp .18s ease;
}
@keyframes slideUp {
  from { transform: translateY(14px); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

.modal-close {
  position: absolute; top: 10px; right: 10px; z-index: 10;
  background: rgba(0,0,0,.55); border: 1px solid var(--border);
  border-radius: 50%; color: var(--text); cursor: pointer;
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem; transition: background .14s;
}
.modal-close:hover { background: var(--red); }

.modal-nav {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 10;
  background: rgba(0,0,0,.65); border: 1px solid var(--border);
  border-radius: 50%; color: var(--text); cursor: pointer;
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  font-size: .9rem; transition: background .14s;
}
.modal-nav:hover { background: var(--accent); color: #000; }
.modal-nav.prev { left: 10px; }
.modal-nav.next { right: 44px; }

.modal-body { display: flex; overflow-y: auto; max-height: 90vh; }

.modal-poster-wrap { flex-shrink: 0; width: 240px; }
.modal-poster { width: 100%; height: 100%; object-fit: cover; display: block; }

.modal-info {
  flex: 1; padding: 26px 22px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 11px;
}

.modal-top { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.modal-top h1 { font-size: 1.45rem; font-weight: 700; line-height: 1.2; }
.m-year { font-size: .95rem; color: var(--muted); }

.modal-badges { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.m-badge {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 5px; font-size: .72rem; padding: 2px 8px; color: var(--muted);
}
.m-badge.gold { color: var(--accent); border-color: var(--accent-border);
                background: var(--accent-bg); font-weight: 700; }
.m-badge.blue { color: var(--blue); }

.genre-pills { flex-wrap: wrap; }
.genre-pill {
  background: var(--accent-bg); border: 1px solid var(--accent-border);
  border-radius: 12px; color: var(--accent); font-size: .7rem;
  padding: 3px 10px; white-space: nowrap;
}

.modal-summary { font-size: .86rem; line-height: 1.65; color: #ccc; }

.credits { display: flex; flex-direction: column; gap: 5px; font-size: .82rem; }
.credit-row { display: flex; gap: 6px; }
.credit-label { color: var(--muted); white-space: nowrap; min-width: 68px; }
.credit-val   { color: var(--text); }

.codec-bar {
  background: var(--surface2); border-radius: 6px;
  padding: 7px 11px; font-size: .72rem; color: var(--muted);
  font-family: ui-monospace, "Cascadia Code", monospace; letter-spacing: .2px;
}

/* Action buttons row */
.modal-actions {
  display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px;
}

.play-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent); border-radius: var(--r);
  color: #000; font-weight: 700; font-size: .88rem;
  padding: 9px 22px; text-decoration: none;
  transition: background .14s, transform .1s;
}
.play-btn:hover { background: #f5b420; transform: scale(1.02); }

.stream-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(224,82,82,.1); border: 1px solid rgba(224,82,82,.4);
  border-radius: var(--r); color: var(--live);
  font-weight: 700; font-size: .88rem; cursor: pointer;
  padding: 9px 22px; transition: all .14s;
}
.stream-btn:hover { background: var(--live); color: #fff; transform: scale(1.02); }

/* ================================================================
   TOAST
   ================================================================ */
.toast {
  position: fixed; bottom: 60px; left: 50%; transform: translateX(-50%);
  z-index: 500;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--r); color: var(--text);
  font-size: .82rem; padding: 10px 20px;
  animation: toastIn .2s ease;
  white-space: nowrap;
}
.toast[hidden] { display: none; }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ================================================================
   RESPONSIVE
   ================================================================ */
@media (max-width: 700px) {
  .header-right { display: none; }
  .stream-banner { flex-direction: column; align-items: flex-start; }
  .modal-body   { flex-direction: column; }
  .modal-poster-wrap { width: 100%; height: 220px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
}
