* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0f0f;
  --surface: #1c1c1c;
  --surface2: #2a2a2a;
  --text: #f1f1f1;
  --muted: #aaa;
  --accent: #ff0033;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Roboto", "Segoe UI", Arial, sans-serif;
}

/* ---------- Cabecera ---------- */
header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}

.logo {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent);
  cursor: pointer;
  white-space: nowrap;
}
.logo span { color: var(--text); letter-spacing: -0.5px; }
.logo .tagline {
  font-size: 0.7rem;
  font-weight: 400;
  font-style: italic;
  color: var(--muted);
}

#search-form {
  flex: 1;
  display: flex;
  max-width: 600px;
}
#search-form input {
  flex: 1;
  padding: 8px 14px;
  border: 1px solid #303030;
  border-radius: 20px 0 0 20px;
  background: #121212;
  color: var(--text);
  font-size: 1rem;
  outline: none;
}
#search-form input:focus { border-color: #3ea6ff; }
#search-form button {
  padding: 8px 18px;
  border: 1px solid #303030;
  border-left: none;
  border-radius: 0 20px 20px 0;
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
  font-size: 1rem;
}

#buffer-label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.9rem;
  white-space: nowrap;
}
#buffer-select {
  padding: 7px 8px;
  border: 1px solid #303030;
  border-radius: 18px;
  background: var(--surface2);
  color: var(--text);
  font-size: 0.95rem;
  cursor: pointer;
}

#history-btn {
  padding: 8px 14px;
  border: none;
  border-radius: 18px;
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
  font-size: 0.95rem;
  white-space: nowrap;
}
#history-btn:hover { background: #3d3d3d; }

#login-btn {
  padding: 8px 14px;
  border: 1px solid #3ea6ff;
  border-radius: 18px;
  background: transparent;
  color: #3ea6ff;
  cursor: pointer;
  font-size: 0.95rem;
  white-space: nowrap;
}
#login-btn:hover { background: rgba(62,166,255,0.15); }
#login-btn.logged { border-color: #2ba640; color: #2ba640; }
#login-btn.logged:hover { background: rgba(43,166,64,0.15); }
#login-btn.expired { border-color: #e0a800; color: #e0a800; }
#login-btn.expired:hover { background: rgba(224,168,0,0.15); }

/* ---------- Modal de inicio de sesión ---------- */
#login-modal {
  background: var(--surface);
  color: var(--text);
  border: 1px solid #333;
  border-radius: 14px;
  padding: 24px;
  width: min(560px, 92vw);
}
#login-modal::backdrop { background: rgba(0,0,0,0.7); }
#login-modal h2 { margin-bottom: 10px; font-size: 1.2rem; }
#login-modal .hint { color: var(--muted); font-size: 0.9rem; margin: 8px 0; }
#login-modal ol.hint { padding-left: 22px; }
#login-modal ol.hint li { margin: 4px 0; }

.file-label {
  display: inline-block;
  margin: 10px 0;
  padding: 8px 14px;
  background: var(--surface2);
  border-radius: 18px;
  cursor: pointer;
  font-size: 0.9rem;
}
.file-label:hover { background: #3d3d3d; }

#cookie-text {
  width: 100%;
  background: #121212;
  color: var(--text);
  border: 1px solid #303030;
  border-radius: 8px;
  padding: 10px;
  font-family: monospace;
  font-size: 0.8rem;
  resize: vertical;
}

#login-error {
  margin-top: 10px;
  padding: 10px 12px;
  background: rgba(255,0,51,0.12);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  font-size: 0.85rem;
  white-space: pre-wrap;
}
#login-error.ok { background: rgba(43,166,64,0.12); border-left-color: #2ba640; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}
.modal-actions button {
  padding: 8px 18px;
  border: none;
  border-radius: 18px;
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
  font-size: 0.95rem;
}
.modal-actions button.primary { background: #3ea6ff; color: #0f0f0f; font-weight: 600; }
.modal-actions button:disabled { opacity: 0.5; cursor: wait; }

main { padding: 20px; max-width: 1280px; margin: 0 auto; }

/* ---------- Reproductor ---------- */
#player-section { margin-bottom: 28px; }

#player-container {
  position: relative;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  max-height: 75vh;
  margin: 0 auto;
}
#player-container:fullscreen {
  border-radius: 0;
  aspect-ratio: auto;
  max-height: none;
  width: 100%;
  height: 100%;
}

#screen {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  cursor: pointer;
}

#spinner {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.4);
}
#spinner[hidden] { display: none; }
.loader {
  width: 52px;
  height: 52px;
  border: 5px solid rgba(255,255,255,0.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#controls {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: linear-gradient(transparent, rgba(0,0,0,0.85));
  transition: opacity 0.3s;
}
#player-container.hide-controls #controls { opacity: 0; pointer-events: none; }
#player-container.hide-controls { cursor: none; }

#controls button {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.25rem;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
}
#controls button:hover { background: rgba(255,255,255,0.15); }
#btn-win { font-size: 1rem !important; }

#controls span {
  font-size: 0.85rem;
  color: #ddd;
  min-width: 44px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

#quality-select, #lang-select {
  padding: 2px 6px;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 4px;
  background: rgba(0,0,0,0.5);
  color: #fff;
  font-size: 0.8rem;
  cursor: pointer;
  outline: none;
}
#quality-select:hover, #lang-select:hover { border-color: #fff; }
#quality-select option, #lang-select option { background: #1c1c1c; color: #fff; }

#seek {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 5px;
  border-radius: 3px;
  background: rgba(255,255,255,0.3);
  cursor: pointer;
  accent-color: var(--accent);
}
#seek::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent);
}

#video-title { margin: 14px 4px 4px; font-size: 1.15rem; }
#player-stats { margin: 0 4px; color: var(--muted); font-size: 0.85rem; }

/* ---------- Reproducción offline (vídeo descargado al dispositivo) ---------- */
#offline-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  background: #000;
}
#offline-video[hidden] { display: none; }
#controls[hidden] { display: none !important; }

#offline-bar {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  background: linear-gradient(rgba(0,0,0,0.85), transparent);
  z-index: 5;
}
#offline-bar[hidden] { display: none; }
#offline-bar .badge {
  color: #2ba640;
  font-weight: 700;
  font-size: 0.8rem;
  letter-spacing: 1px;
  white-space: nowrap;
}
#offline-bar .hint {
  color: #ddd;
  font-size: 0.8rem;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#btn-online {
  border: none;
  border-radius: 14px;
  background: var(--surface2);
  color: #fff;
  padding: 5px 12px;
  cursor: pointer;
  font-size: 0.8rem;
  white-space: nowrap;
}
#btn-online:hover { background: #3d3d3d; }

#unmute-hint {
  position: absolute;
  left: 50%;
  bottom: 70px;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.85);
  color: #fff;
  padding: 10px 18px;
  border-radius: 22px;
  font-size: 0.95rem;
  cursor: pointer;
  z-index: 6;
  white-space: nowrap;
}
#unmute-hint[hidden] { display: none; }

/* ---------- Lista de vídeos ---------- */
#list-title { margin: 6px 4px 16px; font-size: 1.2rem; }

#message {
  background: var(--surface2);
  border-left: 4px solid var(--accent);
  padding: 14px 16px;
  border-radius: 8px;
  margin-bottom: 18px;
  color: var(--muted);
  white-space: pre-wrap;
}

#grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 18px;
}

.card { cursor: pointer; }
.card .thumb {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface2);
  aspect-ratio: 16 / 9;
}
.card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.2s;
}
.card:hover img { transform: scale(1.04); }
.card .dur {
  position: absolute;
  right: 6px;
  bottom: 6px;
  background: rgba(0,0,0,0.8);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.75rem;
}
.card h3 {
  margin: 8px 2px 2px;
  font-size: 0.92rem;
  font-weight: 500;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card p { color: var(--muted); font-size: 0.82rem; margin: 2px; }
