:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1f242e;
  --border: #2a313d;
  --text: #e6e9ef;
  --muted: #8b94a3;
  --accent: #3b82f6;
  --accent-2: #1d4ed8;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

.hidden { display: none !important; }

/* --- Login --- */
.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 30%, #1a1f2a, #0f1115);
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px;
  width: min(360px, 90vw);
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0 0 4px; color: var(--muted); }
.login-card input,
.sidebar input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 15px;
}
.login-card button {
  background: var(--accent);
  color: white;
  border: 0;
  border-radius: 8px;
  padding: 11px;
  font-size: 15px;
  cursor: pointer;
}
.login-card button:hover { background: var(--accent-2); }
.error { color: #f87171; font-size: 14px; }

/* --- App layout --- */
#app {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: 100vh;
}
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 12px;
  min-height: 0;
}
.sidebar header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sidebar header h1 { margin: 0; font-size: 18px; }
#logout {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 7px;
  padding: 5px 10px;
  cursor: pointer;
  font-size: 13px;
}
#logout:hover { color: var(--text); border-color: var(--muted); }

#video-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.video-item {
  display: flex;
  gap: 10px;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
}
.video-item:hover { background: var(--panel-2); }
.video-item.active {
  background: var(--panel-2);
  border-color: var(--accent);
}
.video-item .thumb {
  position: relative;
  flex: 0 0 96px;
  width: 96px;
  height: 54px;
  border-radius: 6px;
  overflow: hidden;
  background: #0a0c10;
}
.video-item .thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
/* Fallback when no thumbnail could be generated. */
.video-item .thumb.no-thumb { display: grid; place-items: center; }
.video-item .thumb.no-thumb::after {
  content: "🎞";
  font-size: 22px;
  opacity: 0.4;
}
.video-item .thumb .badge {
  position: absolute;
  right: 3px;
  bottom: 3px;
  background: rgba(0, 0, 0, 0.78);
  color: #fff;
  font-size: 11px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
}
.video-item .info { min-width: 0; }
.video-item .title {
  font-weight: 600;
  word-break: break-word;
}
.video-item .sub {
  color: var(--muted);
  font-size: 12.5px;
  margin-top: 2px;
}
.dl-only { color: #fbbf24; }
#count { color: var(--muted); font-size: 12.5px; }

/* --- Stage --- */
.stage {
  display: grid;
  place-items: center;
  padding: 24px;
  min-width: 0;
}
.placeholder { color: var(--muted); font-size: 16px; }
#player-wrap { width: min(1100px, 100%); }
.video-js { width: 100%; border-radius: 10px; overflow: hidden; }
.meta-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  gap: 12px;
}
#now-playing { color: var(--text); font-weight: 600; word-break: break-word; }
#download-link {
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  text-decoration: none;
  white-space: nowrap;
}
#download-link:hover { border-color: var(--accent); }

/* --- Mobile --- */
@media (max-width: 720px) {
  #app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { max-height: 42vh; }
}
