/* ============================================================
   Youtube Box — vanilla CSS, mobile-first, responsive
   ============================================================ */

:root {
  --bg: #0f0f10;
  --bg-elev: #18181b;
  --bg-elev-2: #232327;
  --fg: #f4f4f5;
  --fg-dim: #a1a1aa;
  --fg-mute: #71717a;
  --accent: #ef4444;        /* YouTube red */
  --accent-hover: #dc2626;
  --border: #2d2d32;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 4px 12px rgba(0,0,0,0.3);
  --touch: 44px;            /* min touch target */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; height: auto; display: block; }

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  background: var(--bg-elev-2);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  min-height: 36px;
  font-size: 13px;
  transition: background 0.15s, border-color 0.15s;
}
button:hover { background: #2d2d33; }
button:active { background: #1a1a1f; }
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button.danger { background: var(--danger); border-color: var(--danger); color: white; }
button.ghost { background: transparent; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

input, select, textarea {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  min-height: var(--touch);
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2);
}
textarea { resize: vertical; min-height: 80px; }

/* ─── Layout ─────────────────────────────────────────────── */

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.brand {
  font-size: 18px;
  font-weight: 700;
  color: var(--fg);
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.brand .logo { color: var(--accent); font-size: 22px; }
.nav {
  display: flex;
  gap: 4px;
  margin-left: auto;
  flex-wrap: wrap;
}
.nav a {
  color: var(--fg-dim);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  min-height: var(--touch);
  display: flex;
  align-items: center;
}
.nav a:hover { background: var(--bg-elev-2); text-decoration: none; }
.nav a.active { background: var(--bg-elev-2); color: var(--fg); }

.user-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--bg-elev-2);
  border-radius: 20px;
  font-size: 13px;
  color: var(--fg-dim);
}

main {
  flex: 1;
  padding: 16px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

/* ─── Cards / lists ──────────────────────────────────────── */

.toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 16px;
}
.toolbar .grow { flex: 1; min-width: 200px; }

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

.video-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.15s, border-color 0.15s;
}
.video-card:hover { border-color: var(--fg-mute); transform: translateY(-2px); }
.video-card.watched { opacity: 0.65; }

.video-card .thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
  overflow: hidden;
}
.video-card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.video-card .duration {
  position: absolute;
  bottom: 6px;
  right: 6px;
  background: rgba(0,0,0,0.85);
  color: white;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
}
.video-card .watched-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  background: var(--success);
  color: white;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}
.video-card .transcript-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(0,0,0,0.85);
  color: var(--success);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}

.video-card .meta {
  padding: 12px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.video-card .title {
  font-size: 14px;
  font-weight: 600;
  color: var(--fg);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.video-card .channel { font-size: 12px; color: var(--fg-dim); }
.video-card .footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--fg-mute);
}
.stars { display: inline-flex; gap: 2px; cursor: pointer; }
.stars .star {
  font-size: 18px;
  color: var(--fg-mute);
  user-select: none;
  padding: 2px;
  line-height: 1;
}
.stars .star.filled { color: var(--warning); }
.stars .star:hover { color: var(--warning); }

.tag {
  display: inline-block;
  padding: 3px 8px;
  background: var(--bg-elev-2);
  border-radius: 12px;
  font-size: 11px;
  color: var(--fg-dim);
  margin-right: 4px;
  margin-bottom: 4px;
}
.tag.removable { padding-right: 4px; }
.tag .x { margin-left: 4px; cursor: pointer; opacity: 0.6; }
.tag .x:hover { opacity: 1; }

/* ─── Video detail page ──────────────────────────────────── */

.video-detail {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

@media (min-width: 1024px) {
  .video-detail { grid-template-columns: 1fr 380px; }
}

.player-wrap {
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
}
.player-wrap video {
  width: 100%;
  display: block;
  aspect-ratio: 16 / 9;
}
.player-slot:empty { display: none; }
.player-tabs {
  display: flex;
  gap: 4px;
  margin-top: 8px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.player-tabs button {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  color: var(--fg-dim);
  padding: 10px 14px;
  min-height: 40px;
}
.player-tabs button.active {
  color: var(--fg);
  border-bottom-color: var(--accent);
}

.video-title { font-size: 20px; font-weight: 700; margin: 12px 0 6px; }
.video-channel { color: var(--fg-dim); margin-bottom: 12px; }
.video-stats { display: flex; gap: 12px; flex-wrap: wrap; color: var(--fg-mute); font-size: 13px; margin-bottom: 12px; }
.video-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }

.transcript-box {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  max-height: 70vh;
  overflow-y: auto;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: break-word;
  line-height: 1.6;
  font-size: 14px;
}
.transcript-box.empty { color: var(--fg-mute); font-style: italic; }

.chapter-list { list-style: none; padding: 0; margin: 0; }
.chapter-list li {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  gap: 10px;
  align-items: center;
}
.chapter-list li:hover { background: var(--bg-elev-2); }
.chapter-list li:last-child { border-bottom: none; }
.chapter-time { color: var(--fg-mute); font-family: monospace; font-size: 13px; }

/* ─── Login ──────────────────────────────────────────────── */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 380px;
  width: 100%;
  box-shadow: var(--shadow);
}
.login-card h1 {
  margin: 0 0 20px;
  font-size: 22px;
  text-align: center;
}
.login-card .field { margin-bottom: 12px; }
.login-card label { display: block; margin-bottom: 4px; color: var(--fg-dim); font-size: 13px; }
.login-card .err { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 1em; }
.login-card .bypass {
  margin-top: 12px;
  padding: 8px;
  background: var(--bg-elev-2);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--fg-mute);
  text-align: center;
}

/* ─── Channel preview / import ──────────────────────────── */

.preview-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 60vh;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
  background: var(--bg-elev);
}
.preview-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.1s;
}
.preview-item:hover { background: var(--bg-elev-2); }
.preview-item.archived { opacity: 0.55; }
.preview-item input[type="checkbox"] {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  margin: 0;
  cursor: pointer;
  min-height: auto;
}
.preview-item .title { flex: 1; font-size: 14px; }
.preview-item .dur { color: var(--fg-mute); font-size: 12px; font-family: monospace; }
.preview-item .badge {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--success);
  color: white;
}

.progress {
  height: 6px;
  background: var(--bg-elev-2);
  border-radius: 3px;
  overflow: hidden;
  margin: 12px 0;
}
.progress-bar {
  height: 100%;
  background: var(--accent);
  transition: width 0.3s;
}
.progress-text { font-size: 13px; color: var(--fg-dim); }

/* ─── Stats cards ───────────────────────────────────────── */

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.stat-card .label { font-size: 12px; color: var(--fg-mute); text-transform: uppercase; letter-spacing: 0.5px; }
.stat-card .value { font-size: 24px; font-weight: 700; margin-top: 4px; }

/* ─── Tags page ──────────────────────────────────────────── */

.tag-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}
.tag-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.tag-card .name { font-weight: 600; }
.tag-card .count { color: var(--fg-mute); font-size: 12px; }

/* ─── Channel list ───────────────────────────────────────── */

.channel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.channel-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  gap: 12px;
  align-items: center;
}
.channel-card .avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--bg-elev-2);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  color: var(--fg-dim);
}
.channel-card .info { min-width: 0; flex: 1; }
.channel-card .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.channel-card .count { font-size: 12px; color: var(--fg-mute); }

/* ─── Empty state ────────────────────────────────────────── */

.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--fg-mute);
}
.empty .icon { font-size: 48px; margin-bottom: 12px; opacity: 0.4; }

/* ─── Pagination ─────────────────────────────────────────── */

.pagination {
  display: flex;
  gap: 4px;
  justify-content: center;
  margin-top: 20px;
  flex-wrap: wrap;
}
.pagination button { min-width: 40px; }

/* ─── Toast ──────────────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  padding: 10px 18px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 100;
  max-width: 90vw;
  animation: toast-in 0.2s ease-out;
}
.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 20px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ─── Mobile tweaks ──────────────────────────────────────── */

@media (max-width: 640px) {
  main { padding: 12px; }
  .topbar { padding: 8px 12px; flex-wrap: wrap; }
  .brand { font-size: 16px; }
  .nav { gap: 2px; margin-left: 0; width: 100%; }
  .nav a { padding: 6px 10px; font-size: 13px; }
  .video-grid { grid-template-columns: 1fr; gap: 12px; }
  .video-title { font-size: 17px; }
  .toolbar input, .toolbar select { font-size: 16px; }  /* prevent iOS zoom */
  .user-chip { font-size: 12px; }
}

/* ─── Util ───────────────────────────────────────────────── */

/* ─── Modal ───────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fadeIn .15s ease;
}
.modal {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 480px; width: 100%;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  animation: slideUp .2s ease;
}
.modal-header {
  padding: 20px 24px 0;
  font-size: 18px; font-weight: 600;
}
.modal-body {
  padding: 16px 24px;
  font-size: 14px; line-height: 1.5;
}
.modal-footer {
  padding: 0 24px 20px;
  display: flex; gap: 10px; justify-content: flex-end;
}
@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
@keyframes slideUp { from { transform:translateY(20px); opacity:0; } to { transform:translateY(0); opacity:1; } }
/* ─── end Modal ───────────────────────────────────────────── */

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > * { min-width: 0; }
.muted { color: var(--fg-mute); }
.hidden { display: none !important; }
.spacer { flex: 1; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mt-12 { margin-top: 12px; }
