:root {
  color-scheme: dark;
  --bg: #0f1117;
  --surface: #1a1d27;
  --border: #2a2f3d;
  --text: #e8eaef;
  --muted: #9aa3b5;
  --primary: #ff3d3d;
  --primary-hover: #ff5555;
  --success: #3dd68c;
  --error: #ff6b6b;
  --warning: #f5a623;
  --radius: 12px;
  --font: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html {
  background: var(--bg);
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.5;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem;
}

.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top, 0);
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding-top: 1rem;
  padding-bottom: 1rem;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1;
}

.header-nav-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
}

.header-nav-link:hover,
.header-nav-link:focus-visible {
  color: var(--text);
}

.logo {
  display: flex;
  align-items: center;
  text-decoration: none;
  flex-shrink: 0;
}

.logo-img {
  display: block;
  height: 40px;
  width: auto;
  border-radius: 8px;
}

.login-logo {
  display: block;
  height: 72px;
  width: auto;
  margin: 0 auto 1.25rem;
  border-radius: 12px;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 1rem;
  color: var(--muted);
  margin-left: auto;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.card h2 { margin-bottom: 0.5rem; font-size: 1.25rem; }

.muted { color: var(--muted); font-size: 0.9rem; }

.section-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.form { display: flex; flex-direction: column; gap: 1rem; margin-top: 1rem; }

.form-inline { flex-direction: row; flex-wrap: wrap; align-items: center; }

.form label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.9rem; }

.search-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  flex: 1;
  min-width: 220px;
  max-width: 420px;
}

input[type="text"],
input[type="password"],
input[type="url"],
input[type="search"] {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.65rem 0.85rem;
  font-size: 1rem;
  width: 100%;
}

.input-grow { flex: 1; min-width: 180px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.65rem 1.1rem;
  border-radius: 8px;
  border: none;
  font-size: 0.95rem;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover { background: var(--primary-hover); }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.btn-ghost:hover { color: var(--text); border-color: var(--muted); }

.btn-danger {
  background: transparent;
  color: var(--error);
  border: 1px solid var(--error);
}

.btn-danger:hover {
  background: rgba(255, 107, 107, 0.15);
  color: #ff8888;
}

.btn-block { width: 100%; }

.delete-form { display: inline; margin: 0; }

.login-card {
  max-width: 400px;
  margin: 4rem auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
}

.login-card h1 { margin-bottom: 0.25rem; }

.messages { margin-bottom: 1rem; }

.alert {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

.alert-error { background: rgba(255, 107, 107, 0.15); color: var(--error); }
.alert-success { background: rgba(61, 214, 140, 0.15); color: var(--success); }

.playlists-card h2 {
  margin-bottom: 0.5rem;
}

.playlist-create-form {
  margin-top: 0.75rem;
  margin-bottom: 1rem;
}

.playlist-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.playlist-chip-wrap {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  overflow: hidden;
}

.playlist-chip-wrap.active {
  border-color: var(--primary);
}

.playlist-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.75rem;
  color: var(--text);
  text-decoration: none;
  font-size: 0.9rem;
}

.playlist-chip-wrap > .playlist-chip.active,
a.playlist-chip.active {
  background: rgba(255, 61, 61, 0.15);
  color: var(--primary);
}

.playlist-count {
  font-size: 0.75rem;
  color: var(--muted);
  background: var(--surface);
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
}

.playlist-chip-delete {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 0.35rem 0.55rem;
  font-size: 1.1rem;
  line-height: 1;
}

.playlist-chip-delete:hover {
  color: var(--error);
}

.playlist-chip-wrap.active .playlist-chip-delete {
  border-left: 1px solid var(--border);
}

.playlist-filters > .playlist-chip.active {
  display: inline-flex;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--primary);
  background: rgba(255, 61, 61, 0.15);
  color: var(--primary);
  text-decoration: none;
  font-size: 0.9rem;
}

.video-playlist-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.4rem;
}

.playlist-tag {
  font-size: 0.75rem;
  padding: 0.15rem 0.45rem;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  text-decoration: none;
}

.playlist-tag:hover {
  color: var(--text);
  border-color: var(--muted);
}

.add-to-playlist-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  margin-top: 0.5rem;
}

.playlist-pick {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.35rem 0.5rem;
  font-size: 0.85rem;
  max-width: 160px;
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.85rem;
}

.video-total {
  font-size: 0.9rem;
  font-weight: normal;
}

.video-list-sentinel {
  height: 1px;
  margin-top: 0.5rem;
}

.video-list-loading {
  text-align: center;
  padding: 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.video-list-loading.hidden,
.video-list-sentinel.hidden {
  display: none;
}

.video-grid { display: flex; flex-direction: column; gap: 1rem; }

.video-card {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 1rem;
  padding: 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.video-thumb {
  flex-shrink: 0;
  width: 168px;
  aspect-ratio: 16 / 9;
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
  position: relative;
}

.video-duration {
  position: absolute;
  right: 0.35rem;
  bottom: 0.35rem;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.78);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1.3;
  pointer-events: none;
}

.video-meta-duration {
  font-variant-numeric: tabular-nums;
}

.video-thumb-link {
  display: block;
  width: 100%;
  height: 100%;
  color: inherit;
  text-decoration: none;
}

.video-thumb-link:hover img,
.video-thumb-link:focus-visible img {
  opacity: 0.85;
}

.video-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: opacity 0.15s ease;
}

.video-title-link {
  color: var(--text);
  text-decoration: none;
}

.video-title-link:hover,
.video-title-link:focus-visible {
  color: var(--primary);
}

.video-thumb-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 1.5rem;
  background: var(--surface);
}

.video-card-body {
  flex: 1;
  min-width: 180px;
}

.video-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: flex-start;
  margin-left: auto;
}

.video-title { font-size: 1rem; margin-bottom: 0.35rem; }

.video-meta { color: var(--muted); font-size: 0.85rem; margin-bottom: 0.5rem; }

.badge {
  display: inline-block;
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  font-weight: 600;
}

.download-progress {
  margin-top: 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.download-progress-row {
  display: grid;
  grid-template-columns: 2.75rem 1fr 2.75rem;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
}

.download-progress-label {
  color: var(--muted);
  font-weight: 600;
}

.download-progress-pct {
  text-align: right;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.progress-bar {
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.2s ease;
  min-width: 0;
}

.progress-bar-fill.is-done {
  background: var(--success);
}

.badge-pending, .badge-downloading { background: rgba(245, 166, 35, 0.2); color: var(--warning); }
.badge-completed { background: rgba(61, 214, 140, 0.2); color: var(--success); }
.badge-failed { background: rgba(255, 107, 107, 0.2); color: var(--error); }

.error-text { color: var(--error); font-size: 0.8rem; margin-top: 0.5rem; }

.empty-state { padding: 2rem 0; text-align: center; }

.watch-page h1 { font-size: 1.35rem; margin: 1rem 0; }

.quality-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.75rem;
}

.quality-label {
  font-size: 0.9rem;
  color: var(--muted);
}

.quality-select {
  flex: 1;
  min-width: 10rem;
  max-width: 20rem;
  padding: 0.45rem 0.65rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.quality-single {
  margin: 0 0 0.75rem;
  font-size: 0.9rem;
}

.back-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
}

.back-link:hover { color: var(--text); }

.player-wrap {
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 16 / 9;
}

.player-wrap video {
  width: 100%;
  height: 100%;
  display: block;
}

.watch-details {
  margin-top: 1rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.watch-channel {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.watch-channel-link {
  color: var(--primary);
  text-decoration: none;
}

.watch-channel-link:hover,
.watch-channel-link:focus-visible {
  color: var(--primary-hover);
  text-decoration: underline;
}

.channel-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.channel-list-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: inherit;
  text-decoration: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.channel-list-link:hover,
.channel-list-link:focus-visible {
  border-color: var(--primary);
  background: rgba(255, 61, 61, 0.06);
}

.channel-list-name {
  font-weight: 600;
}

.channel-page-header {
  margin-top: 0.75rem;
}

.watch-description {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 24rem;
  overflow-y: auto;
}

.player-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.player-tools .btn.active {
  border-color: var(--success);
  color: var(--success);
}

.player-hint {
  margin-top: 0.75rem;
  font-size: 0.85rem;
  line-height: 1.45;
}

.player-hint strong {
  color: var(--text);
  font-weight: 600;
}

.btn.hidden {
  display: none;
}

.watch-actions {
  margin-top: 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 28rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.modal-header h2 {
  font-size: 1.15rem;
  margin: 0;
}

.modal-close-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.15rem 0.35rem;
  border-radius: 6px;
}

.modal-close-btn:hover,
.modal-close-btn:focus-visible {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.share-link-label {
  display: block;
  font-size: 0.9rem;
  margin-bottom: 0.4rem;
}

.share-link-input {
  width: 100%;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
}

.share-link-hint {
  margin-top: 0.5rem;
  font-size: 0.85rem;
}

body.modal-open {
  overflow: hidden;
}

.install-banner {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  padding: 0.75rem 0.75rem calc(0.75rem + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(15, 17, 23, 0.95) 20%);
}

.install-banner.hidden {
  display: none;
}

.install-banner-inner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.85rem 1rem;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.4);
}

.install-banner-icon {
  flex-shrink: 0;
  border-radius: 10px;
}

.install-banner-text {
  flex: 1;
  min-width: 0;
  font-size: 0.85rem;
}

.install-banner-text strong {
  display: block;
  font-size: 0.95rem;
  margin-bottom: 0.2rem;
}

.install-banner-text p {
  color: var(--muted);
  margin: 0;
  line-height: 1.35;
}

.install-banner-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

.install-banner-close {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
}

.install-banner-close:hover {
  color: var(--text);
}

.ios-share {
  display: inline-block;
  padding: 0.1rem 0.35rem;
  background: var(--bg);
  border-radius: 4px;
  font-weight: 600;
  color: var(--text);
}

@media (min-width: 901px) {
  .install-banner { display: none !important; }
}

@media (max-width: 600px) {
  .form-inline { flex-direction: column; align-items: stretch; }
  .video-thumb { width: 100%; max-width: 100%; }
  .video-card-actions { width: 100%; margin-left: 0; }
  .video-card-actions .btn { flex: 1; }
}
