/* ==========================================================================
   YT Video Queue — Claude-style theme
   Warm, flat and editorial: cream canvas, near-black warm ink, a single clay
   accent. Serif display headings, humanist sans for UI. No gradients, no
   glass, no heavy shadows — separation comes from surface tone and hairlines.
   ========================================================================== */

:root {
  /* light — the signature Claude cream */
  --bg: #faf9f5;
  --surface: #ffffff;
  --surface-2: #f0eee6;
  --surface-3: #e8e6dc;
  --border: #e8e6dc;
  --border-strong: #dedcd1;
  --ink: #141413;
  --ink-2: #3d3d3a;
  --muted: #5e5d59;
  --faint: #87867f;
  --accent: #d97757;
  --accent-hover: #c6613f;
  --ring: rgba(217, 119, 87, 0.45);
  --hover: rgba(115, 114, 108, 0.1);
  --ok: #788c5d;
  --danger: #bf4d43;
  --code: #1a1918;

  --font-serif: Georgia, "Iowan Old Style", "Times New Roman", serif;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;

  --radius: 16px;
  --radius-md: 12px;
  --radius-sm: 10px;
  --ease: cubic-bezier(0, 0, 0.2, 1);
}

/* dark — a warm near-black, never blue-black */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1f1f1e;
    --surface: #2c2c2a;
    --surface-2: #262624;
    --surface-3: #30302e;
    --border: rgba(228, 228, 215, 0.15);
    --border-strong: rgba(228, 228, 215, 0.28);
    --ink: #f8f8f6;
    --ink-2: #d8d6cd;
    --muted: #b0aea5;
    --faint: #87867f;
    --ring: rgba(217, 119, 87, 0.5);
    --hover: rgba(255, 255, 255, 0.07);
    --ok: #bcd1ca;
    --danger: #e0857a;
    --code: #171716;
  }
}
:root[data-theme="dark"] {
  --bg: #1f1f1e;
  --surface: #2c2c2a;
  --surface-2: #262624;
  --surface-3: #30302e;
  --border: rgba(228, 228, 215, 0.15);
  --border-strong: rgba(228, 228, 215, 0.28);
  --ink: #f8f8f6;
  --ink-2: #d8d6cd;
  --muted: #b0aea5;
  --faint: #87867f;
  --ring: rgba(217, 119, 87, 0.5);
  --hover: rgba(255, 255, 255, 0.07);
  --ok: #bcd1ca;
  --danger: #e0857a;
  --code: #171716;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* --------------------------------------------------------------- layout --- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar h1 {
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 19px;
  letter-spacing: -0.02em;
  margin: 0;
}
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.user-bar { display: flex; align-items: center; gap: 10px; }

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 20px;
  padding-bottom: max(40px, env(safe-area-inset-bottom));
}

.view { animation: fade 0.18s var(--ease); }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* serif display headings, weight 400 with negative tracking */
h2 {
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 27px;
  line-height: 1.2;
  letter-spacing: -0.02em;
  margin: 4px 0 16px;
}
h3 {
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 20px;
  line-height: 1.25;
  letter-spacing: -0.015em;
  margin: 0 0 6px;
}
.muted { color: var(--muted); font-size: 14px; }
.error { color: var(--danger); min-height: 20px; font-size: 14px; }
hr { border: none; border-top: 1px solid var(--border); margin: 10px 0; }

.section-label {
  margin: 24px 0 10px;
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--faint);
}

/* flat surfaces with a hairline border — no shadow, no blur */
.card, .panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.panel {
  max-width: 430px;
  margin: 48px auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* -------------------------------------------------------------- controls --- */
button {
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  padding: 10px 16px;
  cursor: pointer;
  color: var(--ink);
  background: transparent;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), color 0.15s var(--ease);
  -webkit-tap-highlight-color: transparent;
}
button:hover { background: var(--hover); }
button:active { transform: translateY(1px); }
button:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}
button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

button.ghost { background: transparent; border-color: var(--border-strong); }
button.ghost:hover { background: var(--hover); }

.icon-btn {
  padding: 7px 10px;
  line-height: 1;
  font-size: 15px;
  border-radius: var(--radius-sm);
  min-width: 36px;
  border-color: var(--border);
}

input, textarea {
  font-family: var(--font-sans);
  font-size: 16px;
  width: 100%;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  transition: border-color 0.15s var(--ease);
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, textarea:focus { outline: 2px solid var(--ring); outline-offset: 1px; border-color: var(--accent); }
textarea { resize: vertical; min-height: 84px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }

/* ------------------------------------------------------------ dashboard --- */
.inline-form { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 22px; }
.inline-form input { flex: 1 1 190px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.series-card { display: flex; flex-direction: column; gap: 6px; }
.series-card h3 { margin: 0; overflow-wrap: anywhere; }
.series-card .row-buttons { display: flex; gap: 8px; margin-top: 12px; }

/* --------------------------------------------------------------- series --- */
.series-head {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin: 12px 0 20px;
}
.series-title-wrap { display: flex; align-items: center; gap: 8px; min-width: 0; }
.series-title-wrap h2 { margin: 0; overflow-wrap: anywhere; }
.series-head #series-progress { margin: 0; }

.video-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }

.video-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--border);
  transition: border-color 0.15s var(--ease);
}
.video-item:hover { border-color: var(--border-strong); }

/* thumbnail — hidden in list view, shown in compact and grid */
.video-item .thumb {
  display: none;
  flex: 0 0 auto;
  background: var(--surface-2);
  object-fit: cover;
}
.video-item .thumb.is-missing { visibility: hidden; }

.video-item .vmain {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 auto;
  min-width: 0;
}
.video-item .idx {
  flex: 0 0 auto;
  width: 22px;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}
.video-item .vtitle {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* the title is a link out to its source app */
.video-item .vtitle.link { color: inherit; text-decoration: none; cursor: pointer; }
.video-item .vtitle.link:hover { text-decoration: underline; }
.frame-fallback { margin-top: 10px; }
.loading { text-align: center; padding: 48px 0; color: var(--muted); }
.video-item .row-actions { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }

/* --- view modes (Windows-Explorer style) --------------------------------- */
[data-view="compact"] .video-item .thumb {
  display: block;
  width: 88px;
  aspect-ratio: 16 / 9;
  border-radius: 8px;
}

[data-view="grid"] .video-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 16px;
}
[data-view="grid"] .video-item {
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  padding: 0;
  overflow: hidden;
}
[data-view="grid"] .video-item .thumb {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 0;
}
[data-view="grid"] .video-item .vmain {
  align-items: flex-start;
  min-height: 0;
  overflow: hidden;
  padding: 12px 14px 0;
}
[data-view="grid"] .video-item .idx { display: none; }
[data-view="grid"] .video-item .vtitle {
  white-space: normal;
  /* -webkit-line-clamp only clips the extra lines when overflow is hidden */
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.35;
}
[data-view="grid"] .video-item .row-actions {
  flex: 0 0 auto;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 14px 14px;
}

/* the view switcher itself */
.view-switch {
  display: inline-flex;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.view-switch button {
  border: none;
  border-radius: 0;
  padding: 8px 11px;
  font-size: 15px;
  line-height: 1;
  background: transparent;
  color: var(--muted);
}
.view-switch button + button { border-left: 1px solid var(--border); }
.view-switch button:hover { background: var(--hover); }
.view-switch button[aria-pressed="true"] { background: var(--surface-2); color: var(--ink); }

/* --- selection & bulk actions ------------------------------------------- */
.pick {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}
.video-item.selectable { cursor: pointer; }
.video-item.selectable:hover { background: var(--hover); }
.video-item.selected { border-color: var(--accent); }

.selection-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  margin-bottom: 16px;
  border-color: var(--accent);
}
.selection-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-left: auto; }

/* in grid view the checkbox floats over the thumbnail */
[data-view="grid"] .video-item { position: relative; }
[data-view="grid"] .video-item .pick {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 2;
  width: 20px;
  height: 20px;
  padding: 2px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.92);
}

.hint { font-size: 12px; color: var(--faint); margin: 0; }
.hint code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  background: var(--surface-2);
  border-radius: 4px;
  padding: 1px 4px;
}
.warn { color: var(--danger); font-size: 12px; margin: 8px 0 0; }

select {
  font: inherit;
  width: 100%;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
}
select:focus { outline: 2px solid var(--ring); outline-offset: 1px; border-color: var(--accent); }

.export-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.export-actions .primary { flex: 1 1 100%; }

/* toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 60;
  max-width: min(90vw, 460px);
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  background: var(--ink);
  color: var(--bg);
  font-size: 14px;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.25);
  animation: fade 0.18s var(--ease);
}

/* --- non-YouTube sources ------------------------------------------------ */
.src-chip,
.auto-tag {
  flex: 0 0 auto;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.5px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  color: var(--faint);
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.auto-tag { border-style: dashed; text-transform: uppercase; }

/* generic iframe (Telegram) and the external card for non-framable sites */
.frame-player { width: 100%; height: 100%; border: 0; display: block; background: #000; }
.external {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  height: 100%;
  padding: 22px;
  text-align: center;
  background: var(--surface-2);
}
.external img { max-width: 100%; max-height: 40%; object-fit: contain; border-radius: var(--radius-sm); }
.external-body { display: flex; flex-direction: column; align-items: center; gap: 8px; max-width: 440px; }
.external-body h3 { margin: 0; overflow-wrap: anywhere; }
.btn-link {
  display: inline-block;
  text-decoration: none;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 500;
}
.btn-link.primary { background: var(--accent); color: #ffffff; }
.btn-link.primary:hover { background: var(--accent-hover); }

/* footer */
.foot {
  max-width: 900px;
  margin: 0 auto;
  padding: 8px 20px max(24px, env(safe-area-inset-bottom));
  text-align: center;
  font-size: 12px;
}
.modal-wide { max-width: 640px; }

.opts { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.check { display: flex; align-items: center; gap: 7px; font-size: 14px; color: var(--ink-2); }
.check input { width: auto; accent-color: var(--accent); }

.help { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; }
.help > summary { cursor: pointer; }
.help-body { margin-top: 8px; }
.help-body p { margin: 6px 0; line-height: 1.75; }

.preview { background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px; }
.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.preview-scroll {
  max-height: 300px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.preview-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.preview-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  text-align: left;
  font-weight: 500;
  font-size: 11px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--faint);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 8px 10px;
}
.preview-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.preview-table tr:last-child td { border-bottom: none; }
.preview-table td:first-child, .preview-table th:first-child { width: 34px; }
.preview-table .orig { color: var(--muted); overflow-wrap: anywhere; }
.preview-table .new { color: var(--ink); overflow-wrap: anywhere; }
.preview-table tr.unchanged .new { color: var(--muted); }
.preview-table mark {
  background: rgba(217, 119, 87, 0.25);
  color: inherit;
  border-radius: 3px;
  padding: 0 2px;
}

.undo-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  margin-bottom: 16px;
  border-color: var(--accent);
}

.badge {
  flex: 0 0 auto;
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  color: var(--faint);
}
.video-item.status-watching .badge { color: var(--accent); border-color: var(--accent); }

.empty {
  padding: 18px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
}

.watched { margin-top: 22px; padding: 0; overflow: hidden; }
.watched > summary {
  cursor: pointer;
  list-style: none;
  padding: 16px 20px;
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 17px;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 10px;
  user-select: none;
}
.watched > summary:hover { background: var(--hover); }
.watched > summary::-webkit-details-marker { display: none; }
.watched > summary::before {
  content: "▸";
  color: var(--faint);
  font-size: 13px;
  transition: transform 0.15s var(--ease);
}
.watched[open] > summary::before { transform: rotate(90deg); }
.watched[open] > summary { border-bottom: 1px solid var(--border); }
.watched > ol { padding: 14px 16px; margin: 0; }
.watched .vtitle { color: var(--muted); text-decoration: line-through; }
.watched .video-item { background: var(--surface-2); }

/* --------------------------------------------------------------- player --- */
.player-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--code);
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.player-wrap iframe { width: 100%; height: 100%; display: block; }

.now-playing { margin: 18px 0; }
.now-playing h3 { overflow-wrap: anywhere; }
.controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.toggle { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); }
.toggle input { width: auto; accent-color: var(--accent); }
.up-next { margin-top: 16px; }

/* ---------------------------------------------------------------- modal --- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(20, 20, 19, 0.4);
}
.modal {
  width: 100%;
  max-width: 420px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.12);
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* --------------------------------------------------- responsiveness ------ */
@media (max-width: 600px) {
  main { padding: 18px 14px; }
  h2 { font-size: 23px; }
  .grid { grid-template-columns: 1fr; }
  .topbar { padding: 10px 14px; }
  .topbar h1 { font-size: 17px; }
  .panel { margin: 24px auto; }

  .video-item { flex-wrap: wrap; row-gap: 10px; padding: 12px; }
  .video-item .vmain { flex: 1 1 auto; min-width: 0; }
  .video-item .vtitle { white-space: normal; overflow: visible; }
  .video-item .row-actions { flex: 1 1 100%; justify-content: flex-end; gap: 8px; }

  [data-view="grid"] .video-list { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }

  .series-head { gap: 10px; }
  .series-head #play-btn { flex: 1 1 100%; }

  .icon-btn { min-width: 40px; padding: 9px 11px; }
}

@media (max-width: 380px) {
  .icon-btn { min-width: 36px; padding: 8px; }
}

@media (pointer: coarse) {
  button { padding: 11px 16px; }
  .icon-btn { min-width: 40px; min-height: 40px; }
}
