/* ═══════════════════════════════════════════
   Video Library — Dark TV-Friendly Theme
   ═══════════════════════════════════════════ */

:root {
  --bg: #0a0a0e;
  --surface: #14141a;
  --surface-hover: #1c1c24;
  --surface-active: #24242e;
  --text: #eae8e3;
  --text-dim: #7a7a88;
  --text-muted: #565664;
  --accent: #4d7cff;
  --accent-hover: #6a92ff;
  --accent-dim: rgba(77, 124, 255, 0.15);
  --border: #22222a;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
  --focus-ring: 0 0 0 3px rgba(77, 124, 255, 0.6);
  --transition: 0.18s cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* ── Focus Indicator (TV D-pad) ── */
/* Universal focus ring — works on all browsers including old Android */
:focus {
  outline: none;
  box-shadow: var(--focus-ring) !important;
  border-color: var(--accent) !important;
}
/* Modern browsers: remove ring on mouse click, keep only for keyboard/D-pad */
:focus:not(:focus-visible) {
  box-shadow: none !important;
  border-color: var(--border) !important;
}
/* Modern browsers: keyboard focus stays ringed */
:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring) !important;
  border-color: var(--accent) !important;
}

/* ── Top Bar ── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 28px;
  border-bottom: 1px solid var(--border);
  background: #0a0a0e; /* fallback for old Android */
  background: rgba(10, 10, 14, 0.95);
  -webkit-backdrop-filter: blur(12px); /* old WebKit fallback */
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 12px;
}

.topbar-left { display: flex; align-items: baseline; gap: 12px; }

.topbar h1 {
  font-size: 18px; font-weight: 700; letter-spacing: -0.02em; margin: 0;
  background: linear-gradient(135deg, var(--accent) 0%, #a78bfa 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}

.badge {
  font-size: 12px; font-weight: 500; color: var(--text-dim);
  background: var(--surface); padding: 3px 10px; border-radius: 20px;
  border: 1px solid var(--border);
}

.topbar-right { display: flex; gap: 6px; align-items: center; }

.filter-btn {
  background: transparent; color: var(--text-dim); border: 1px solid var(--border);
  padding: 6px 14px; border-radius: 20px; font-size: 13px; font-weight: 500;
  cursor: pointer; transition: var(--transition); font-family: inherit;
}
.filter-btn:hover { background: var(--surface-hover); color: var(--text); }
.filter-btn.active { background: var(--accent-dim); color: var(--accent); border-color: var(--accent); }

.search-toggle {
  background: transparent; border: none; font-size: 18px; cursor: pointer;
  padding: 6px 8px; border-radius: 8px; transition: var(--transition); line-height: 1;
}
.search-toggle:hover { background: var(--surface-hover); }

.search-bar { padding: 0 28px 16px; border-bottom: 1px solid var(--border); background: var(--bg); }
.search-bar.hidden { display: none; }

#search-input {
  width: 100%; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 16px; color: var(--text);
  font-size: 14px; font-family: inherit; transition: var(--transition);
}
#search-input::placeholder { color: var(--text-muted); }
#search-input:focus { border-color: var(--accent); }

/* ── Main Layout ── */

#app { padding: 24px 28px 40px; max-width: 1200px; margin: 0 auto; }

/* ═══════════════════════════════════════════
   GRID / CARDS
   ═══════════════════════════════════════════ */

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

.card {
  position: relative; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  display: flex; flex-direction: column;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 8px 32px rgba(0,0,0,0.4); border-color: var(--surface-hover); }
.card:focus-visible { transform: translateY(-2px); box-shadow: var(--focus-ring), 0 8px 32px rgba(0,0,0,0.4); }
.card:active { transform: translateY(0); }

.card-poster {
  width: 100%; aspect-ratio: 2/3; background: var(--surface-hover);
  display: flex; align-items: center; justify-content: center;
  font-size: 36px; color: var(--text-muted); overflow: hidden; position: relative;
}
/* Fallback for old Android browsers that don't support aspect-ratio */
@supports not (aspect-ratio: 2/3) {
  .card-poster {
    height: 0;
    padding-bottom: 150%; /* 2:3 ratio */
  }
  .card-poster > * {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
  }
}
.card-poster img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.3s ease; }
.card:hover .card-poster img { transform: scale(1.05); }
.card-poster-placeholder { font-size: 40px; opacity: 0.3; }

.card-progress {
  position: absolute; bottom: 0; left: 0; right: 0; height: 3px;
  background: rgba(255,255,255,0.1);
}
.card-progress-bar { height: 100%; background: var(--accent); border-radius: 0 2px 2px 0; transition: width 0.3s ease; }

.card-body { padding: 12px 14px 14px; flex: 1; display: flex; flex-direction: column; gap: 4px; }
.card-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 1.3; }
.card-name.tmdb-title { color: var(--accent); }
.card-filename { font-size: 10px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 1.2; margin-top: 2px; }
.card-meta { font-size: 11px; color: var(--text-dim); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.card-genre { font-size: 10px; background: var(--surface-hover); padding: 1px 6px; border-radius: 4px; color: var(--text-muted); }
.card-rating { font-size: 11px; color: #fbbf24; font-weight: 600; margin-left: auto; }
.card-resume-badge {
  position: absolute; top: 8px; right: 8px; background: var(--accent); color: #fff;
  font-size: 10px; font-weight: 700; padding: 3px 8px; border-radius: 4px;
  z-index: 2; letter-spacing: 0.3px;
}

.card-edit-btn {
  position: absolute; top: 8px; left: 8px; z-index: 3;
  width: 28px; height: 28px; border-radius: 50%; border: none;
  background: rgba(0,0,0,0.7); color: var(--text); font-size: 14px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity 0.2s ease;
  line-height: 1; padding: 0;
}
.card:hover .card-edit-btn,
.card:focus-within .card-edit-btn,
.card-edit-btn:focus-visible { opacity: 1; }
.card-edit-btn:hover { background: var(--accent); color: #fff; }
.card-edit-btn:focus-visible { opacity: 1; box-shadow: var(--focus-ring) !important; }

/* ── Global Hidden Utility ── */
.hidden { display: none !important; }

/* ── Empty State ── */
.empty { color: var(--text-dim); text-align: center; margin-top: 80px; font-size: 15px; line-height: 1.6; }
.empty.hidden { display: none !important; }

/* ── Loader ── */
.loader { text-align: center; color: var(--text-dim); padding: 40px 0; font-size: 14px; }
.loader.hidden { display: none; }

/* ── Footer ── */
.footer { text-align: center; padding: 20px 28px 32px; border-top: 1px solid var(--border); }
.footer-hint { font-size: 12px; color: var(--text-muted); }
.footer-hint a { color: var(--accent); text-decoration: none; }
.footer-hint a:hover { text-decoration: underline; }

/* ── Overlay / Modal ── */
.overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.85); /* slightly darker fallback when blur unsupported */
  background: rgba(0,0,0,0.7);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn 0.15s ease;
}
.overlay.hidden { display: none !important; }
.overlay-panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 28px 32px;
  width: 100%; max-width: 400px; box-shadow: var(--shadow);
}
.overlay-title { font-size: 18px; font-weight: 700; margin: 0 0 20px; color: var(--text); }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--text-dim); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px; }
.form-group input[type="number"] {
  width: 100%; background: var(--surface-active); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 14px; color: var(--text);
  font-size: 14px; font-family: inherit; transition: var(--transition);
}
.form-group input[type="number"]:focus { border-color: var(--accent); }
.form-group input[type="number"]::placeholder { color: var(--text-muted); }

.radio-group { display: flex; gap: 12px; }
.radio-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--text-dim); cursor: pointer;
  padding: 8px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); transition: var(--transition);
}
.radio-label.selected,
.radio-label:has(input:checked) {
  color: var(--accent); border-color: var(--accent);
  background: var(--accent-dim);
}
.radio-label input { accent-color: var(--accent); }

.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }
.btn {
  padding: 10px 20px; border-radius: var(--radius-sm); border: none;
  font-size: 13px; font-weight: 600; cursor: pointer; font-family: inherit;
  transition: var(--transition);
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary { background: var(--surface-active); color: var(--text-dim); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--surface-hover); color: var(--text); }
.btn-danger { background: #e53e3e; color: #fff; border: none; }
.btn-danger:hover { background: #c53030; }

/* ── Animations ── */
@keyframes fadeSlide { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ─── Video Player Modal ─── */
.player-modal-panel {
  background: #111116;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.9);
  width: 96vw;
  max-width: 1120px;
  max-height: 96vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: fadeIn 0.2s ease;
}

.player-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: rgba(20, 20, 26, 0.95);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.player-title-info {
  display: flex;
  align-items: center;
  gap: 12px;
  overflow: hidden;
}

.player-title {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 650px;
}

.player-meta-badge {
  font-size: 11px;
  font-weight: 600;
  background: var(--surface-active);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 8px;
  white-space: nowrap;
}

.player-close-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 16px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}
.player-close-btn:hover {
  background: #e11d48;
  color: #fff;
  border-color: #e11d48;
}

.player-video-wrapper {
  position: relative;
  width: 100%;
  background: #000;
  aspect-ratio: 16 / 9;
  max-height: calc(96vh - 120px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.player-video-wrapper movi-player,
.player-video-wrapper video {
  width: 100%;
  height: 100%;
  max-height: calc(96vh - 120px);
  background: #000;
  outline: none;
}

.player-loading {
  position: absolute;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(10, 10, 14, 0.85);
  padding: 12px 20px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  pointer-events: none;
  z-index: 15;
}

.player-error-fallback {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 30px;
  background: #0e0e13;
  color: var(--text);
  width: 100%;
  height: 100%;
  z-index: 15;
}
.error-icon {
  font-size: 40px;
  margin-bottom: 10px;
}
.error-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 6px;
  color: #f43f5e;
}
.error-desc {
  font-size: 13px;
  color: var(--text-dim);
  max-width: 520px;
  line-height: 1.5;
  margin-bottom: 20px;
}
.error-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 16px;
}
.error-tip {
  font-size: 12px;
  color: #94a3b8;
  background: rgba(255, 255, 255, 0.05);
  padding: 8px 16px;
  border-radius: 20px;
  border: 1px solid var(--border);
}

.player-resume-toast {
  position: absolute;
  top: 16px;
  left: 20px;
  background: rgba(77, 124, 255, 0.9);
  color: #fff;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  pointer-events: none;
  z-index: 20;
  animation: fadeIn 0.3s ease;
}

.player-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 10px;
}

.player-hint {
  font-size: 12px;
  color: var(--text-dim);
}

.player-toolbar-right {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.player-action-btn {
  background: var(--surface-active);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 6px;
}
.player-action-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ── Responsive ── */
@media (max-width: 640px) {
  .topbar { padding: 14px 16px; flex-wrap: wrap; }
  #app { padding: 16px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  .card-body { padding: 10px 10px 12px; }
  .card-name { font-size: 12px; }
  .dl-link { font-size: 12px; }
  .player-modal-panel { width: 100vw; height: 100vh; max-height: 100vh; border-radius: 0; border: none; }
  .player-header { padding: 10px 14px; }
  .player-title { max-width: 240px; font-size: 13px; }
  .player-toolbar { padding: 8px 12px; }
  .player-hint { display: none; }
}
