:root {
  --bg: #0b1220;
  --panel: #141c2b;
  --text: #e8eef8;
  --muted: #93a0b5;
  --accent: #3b82f6;
  --ok: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --line: #243044;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(900px 500px at 10% -10%, #17233a, transparent),
              radial-gradient(700px 400px at 100% 0%, #13261f, transparent),
              var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
}
.hidden { display: none !important; }
.screen { min-height: 100vh; }
.muted { color: var(--muted); }
.tiny { font-size: 0.78rem; }
.error { color: var(--bad); min-height: 1.2rem; }

.login-card {
  max-width: 380px;
  margin: 15vh auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1.4rem;
}
.login-card h1 { margin: 0 0 0.3rem; font-size: 1.5rem; }
.login-card label { display: block; margin: 1rem 0 0.35rem; color: var(--muted); font-size: 0.9rem; }
.login-card label.remember {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.85rem 0 0;
  color: var(--text);
  font-size: 0.9rem;
}
.login-card label.remember input { width: auto; margin: 0; }
input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #0d1524;
  color: var(--text);
  border-radius: 10px;
  padding: 0.75rem 0.85rem;
  font: inherit;
}
textarea { resize: vertical; }
button {
  border: 0;
  border-radius: 10px;
  padding: 0.7rem 0.9rem;
  font: inherit;
  cursor: pointer;
}
button.primary {
  background: var(--accent);
  color: white;
  width: 100%;
  margin-top: 0.9rem;
  font-weight: 600;
}
button.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}
button.small {
  padding: 0.35rem 0.55rem;
  font-size: 0.8rem;
  background: #1c273a;
  color: var(--text);
  margin-right: 0.35rem;
}
button.danger { background: #3a1820; color: #fecaca; }

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: rgba(11,18,32,0.92);
  backdrop-filter: blur(8px);
  z-index: 5;
}
main { padding: 1rem 1rem 5.5rem; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; }
h2 { margin: 0 0 0.8rem; font-size: 1.15rem; }
.search-box { display: flex; gap: 0.5rem; margin-bottom: 0.6rem; }
.search-box input { flex: 1; }
.search-box .primary { width: auto; margin: 0; }
.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0 0 0.75rem;
}
.preset-row .preset {
  background: #1a2740;
  color: var(--text);
  border: 1px solid var(--line);
}

.list { display: grid; gap: 0.7rem; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.85rem 0.95rem;
}
.card h3 {
  margin: 0 0 0.35rem;
  font-size: 0.98rem;
  line-height: 1.35;
  word-break: break-word;
}
.meta { color: var(--muted); font-size: 0.8rem; margin-bottom: 0.55rem; }
.bar {
  height: 6px;
  background: #0d1524;
  border-radius: 99px;
  overflow: hidden;
  margin: 0.45rem 0 0.65rem;
}
.bar > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #2563eb, #22c55e);
}

.dl-banner {
  margin: 0.75rem 1rem 0;
  padding: 0.85rem 0.95rem;
  background: linear-gradient(135deg, #1a2f1f, #152238);
  border: 1px solid #2f5d3a;
  border-radius: 14px;
}
.dl-banner-top {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: baseline;
  margin-bottom: 0.35rem;
}
.dl-banner-top strong {
  font-size: 0.95rem;
  line-height: 1.3;
  word-break: break-word;
}
.dl-pct {
  color: #86efac;
  font-weight: 700;
  white-space: nowrap;
}
.dl-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.55rem;
}
.dot {
  display: inline-block;
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
  margin-right: 0.2rem;
  vertical-align: middle;
}
.dot.green { background: #22c55e; box-shadow: 0 0 0 2px rgba(34,197,94,0.25); }
.dot.red { background: #ef4444; box-shadow: 0 0 0 2px rgba(239,68,68,0.25); }
.dot.none { background: #334155; }
.watch-stats { color: var(--muted); font-size: 0.78rem; margin-bottom: 0.45rem; }
.player-convert {
  background: #0f766e;
  color: #fff;
  font-weight: 700;
  min-width: 5.5rem;
  margin: 0;
  width: auto;
  border-radius: 10px;
  padding: 0.7rem 0.9rem;
}
.card.downloading {
  border-color: #3d8b5a;
  box-shadow: 0 0 0 1px rgba(34, 197, 94, 0.25);
}
.card.watch-card { cursor: pointer; }
.card.watch-card:active { transform: scale(0.99); }

.bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.25rem;
  padding: 0.55rem 0.55rem calc(0.55rem + env(safe-area-inset-bottom));
  background: rgba(15, 22, 34, 0.96);
  border-top: 1px solid var(--line);
}

.player-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #000;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.player-overlay.hidden { display: none !important; }
.player-exit {
  position: absolute;
  top: calc(0.75rem + env(safe-area-inset-top));
  right: calc(0.75rem + env(safe-area-inset-right));
  z-index: 2;
  background: rgba(239, 68, 68, 0.95);
  color: #fff;
  font-weight: 700;
  padding: 0.65rem 1.1rem;
  border-radius: 999px;
  min-width: 5.5rem;
}
.player-title {
  position: absolute;
  top: calc(0.85rem + env(safe-area-inset-top));
  left: calc(0.85rem + env(safe-area-inset-left));
  right: 7rem;
  z-index: 1;
  color: #fff;
  font-size: 0.9rem;
  text-shadow: 0 1px 4px #000;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.player-overlay video {
  flex: 1;
  width: 100%;
  height: 100%;
  background: #000;
  object-fit: contain;
}
.player-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0.75rem 1rem calc(0.9rem + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0,0,0,0.85));
  z-index: 2;
}
.player-controls input[type="range"] {
  width: 100%;
  margin: 0 0 0.55rem;
  accent-color: #3b82f6;
}
.player-controls-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.player-time {
  color: #ddd;
  font-size: 0.85rem;
}
.player-playpause {
  background: #3b82f6;
  color: #fff;
  font-weight: 700;
  min-width: 6.5rem;
  margin: 0;
  width: auto;
}
.player-hint {
  position: absolute;
  bottom: calc(5.5rem + env(safe-area-inset-bottom));
  left: 1rem;
  right: 1rem;
  text-align: center;
  background: rgba(0,0,0,0.65);
  padding: 0.6rem;
  border-radius: 10px;
  z-index: 3;
}
.bottom-nav .nav {
  background: transparent;
  color: var(--muted);
  padding: 0.7rem 0.4rem;
}
.bottom-nav .nav.active {
  color: white;
  background: #1a2740;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 5.2rem;
  transform: translateX(-50%);
  background: #111827;
  border: 1px solid var(--line);
  padding: 0.7rem 1rem;
  border-radius: 999px;
  z-index: 20;
  max-width: 90vw;
}
