:root {
  --bg: #0f1115;
  --bg-raised: #181b22;
  --bg-hover: #1f232c;
  --border: #2a2f3a;
  --text: #e8eaf0;
  --text-muted: #9aa1b2;
  --accent: #e5484d;
  --accent-hover: #f3555a;
  --radius: 10px;
}

* { box-sizing: border-box; }

/* Any rule below that sets `display` (grid/flex) would otherwise defeat the
   hidden attribute — e.g. the watch-page "Loading…" overlay stuck on screen. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
}

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

/* ---- chrome ---- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { font-weight: 700; font-size: 1.15rem; color: var(--accent); }

.topbar nav { display: flex; gap: 1.25rem; align-items: center; }
.topbar nav > a:not(.btn) { color: var(--text-muted); }
.topbar nav > a:not(.btn):hover { color: var(--text); }

.container { max-width: 1200px; margin: 1.5rem auto; padding: 0 1.25rem; }
.container.narrow { max-width: 640px; }
.container.center { text-align: center; }

.page-title { font-size: 1.35rem; margin: 0.25rem 0 1rem; }
.muted { color: var(--text-muted); }

.card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.btn {
  display: inline-block;
  padding: 0.45rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-hover);
  color: var(--text);
  font-size: 0.95rem;
  cursor: pointer;
}

.btn:hover { filter: brightness(1.15); }

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

.btn-danger {
  background: transparent;
  border-color: var(--accent);
  color: var(--accent);
}

.btn-danger:hover { background: var(--accent); color: #fff; }

.btn-lg { padding: 0.7rem 1.5rem; font-size: 1.05rem; width: 100%; }

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- home grid ---- */

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

.video-card {
  position: relative;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.video-card:hover { transform: translateY(-3px); border-color: #3a4150; }

/* The whole card minus the delete corner is one link target. */
.video-card .card-link { display: block; color: inherit; }

.video-card .thumb {
  aspect-ratio: 16 / 9;
  width: 100%;
  object-fit: cover;
  background: #000;
  display: block;
}

.video-card .thumb-placeholder {
  aspect-ratio: 16 / 9;
  display: grid;
  place-items: center;
  background: #05070a;
  color: var(--text-muted);
}

.video-card .meta { padding: 0.7rem 0.9rem; }
.video-card .meta h2 { font-size: 1rem; margin: 0 0 0.25rem; }
.video-card .meta p { margin: 0; color: var(--text-muted); font-size: 0.85rem; }

.video-card .card-delete {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 8px;
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.video-card .card-delete:hover { background: var(--accent); border-color: var(--accent); }
.video-card .card-delete:disabled { opacity: 0.5; cursor: wait; }

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-muted);
  padding: 3rem 1rem;
  background: var(--bg-raised);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.stats-bar {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin: -0.4rem 0 1rem;
}

/* Processing cards: live encode progress right in the grid. */
.video-card.processing { border-style: dashed; opacity: 0.92; }
.video-card.processing:hover { transform: none; }

.processing-thumb {
  aspect-ratio: 16 / 9;
  display: grid;
  place-items: center;
  background: #05070a;
}

.progress-bar.slim { height: 5px; margin-top: 0.5rem; }

/* ---- upload ---- */

.upload-form { display: flex; flex-direction: column; gap: 1.1rem; }

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2.25rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
  outline: none;
}

.dropzone:hover, .dropzone:focus, .dropzone.dragover {
  border-color: var(--accent);
  background: rgba(229, 72, 77, 0.06);
}

.dropzone-title { margin: 0; font-weight: 600; font-size: 1.05rem; }
.dropzone-sub { margin: 0.35rem 0 0; color: var(--text-muted); font-size: 0.9rem; }
.file-name { margin: 0.75rem 0 0; color: var(--accent); font-weight: 600; }

.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field span { font-size: 0.9rem; color: var(--text-muted); }
.field em { font-style: normal; opacity: 0.7; }

.field input, .field textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 0.6rem 0.75rem;
  font: inherit;
  resize: vertical;
}

.field input:focus, .field textarea:focus { outline: 1px solid var(--accent); }

.progress-wrap { display: flex; flex-direction: column; gap: 0.4rem; }

.progress-bar {
  height: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 99px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 99px;
  transition: width 0.2s ease;
}

.progress-fill.encode { background: #3b82f6; }

.progress-label { margin: 0; color: var(--text-muted); font-size: 0.9rem; }

.status-box {
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  border: 1px solid var(--border);
  background: var(--bg);
}

.status-box.ok { border-color: #2f9e63; color: #7dd8a8; }
.status-box.err { border-color: var(--accent); color: #f3555a; }
.status-box.busy { color: var(--text-muted); }

/* ---- watch page ---- */

.watch-layout { max-width: 960px; display: flex; flex-direction: column; gap: 1.25rem; }

.player-shell {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 16 / 9;
}

.player-shell video { width: 100%; height: 100%; display: block; background: #000; }

.player-message {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  gap: 0.75rem;
  align-content: center;
  background: rgba(0, 0, 0, 0.75);
  color: var(--text);
  text-align: center;
  padding: 1rem;
}

.player-message p { margin: 0.5rem 0 0; }

.spinner {
  width: 38px;
  height: 38px;
  border: 3px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.watch-title { font-size: 1.25rem; margin: 0 0 0.35rem; }
.watch-stats { color: var(--text-muted); margin: 0 0 0.6rem; font-size: 0.9rem; }
.watch-description { margin: 0 0 0.75rem; white-space: pre-wrap; }
.watch-actions { display: flex; justify-content: flex-end; }

/* ---- ad overlay ---- */

.ad-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
}

.ad-overlay .ad-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  background: rgba(0, 0, 0, 0.75);
  color: #ffd466;
  font-weight: 700;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  padding: 2px 8px;
  border-radius: 4px;
}

.ad-overlay .ad-countdown {
  position: absolute;
  top: 12px;
  right: 12px;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  font-size: 0.8rem;
  padding: 3px 10px;
  border-radius: 4px;
}

.ad-overlay .ad-click {
  position: absolute;
  inset: 0;
  pointer-events: auto;
  cursor: pointer;
}

.ad-overlay .ad-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  pointer-events: none;
}

.ad-overlay .ad-skip-btn {
  position: absolute;
  bottom: 56px;
  right: 12px;
  pointer-events: auto;
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 0.9rem;
  cursor: pointer;
}

.ad-overlay .ad-skip-btn:hover:not(:disabled) { background: rgba(229, 72, 77, 0.9); border-color: var(--accent); }
.ad-overlay .ad-skip-btn:disabled { opacity: 0.6; cursor: default; }

/* ---- ad manager ---- */

.section-title { font-size: 1.05rem; margin: 0 0 0.75rem; }

.ads-form { display: flex; flex-direction: column; gap: 1.1rem; margin-bottom: 2rem; }
.dropzone.compact { padding: 1.1rem 1rem; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
}

fieldset.field { border: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.4rem; }

.radio-row { display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; }
.radio-row label { display: flex; align-items: center; gap: 0.4rem; font-size: 0.92rem; }

.inline-num {
  width: 4.2rem;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 2px 6px;
  font: inherit;
}

.slot-row { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; }

.chip {
  display: flex; align-items: center; gap: 0.45rem;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 99px;
  padding: 0.35rem 0.85rem;
  font-size: 0.9rem;
  cursor: pointer;
}

.chip:has(input:checked) { border-color: var(--accent); background: rgba(229, 72, 77, 0.08); }

.field-hint { margin: 0; color: var(--text-muted); font-size: 0.82rem; }

.video-picker {
  display: flex; flex-direction: column; gap: 0.4rem;
  max-height: 260px; overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem;
  margin-top: 0.3rem;
}

.pick-row {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.3rem 0.4rem; border-radius: 6px; cursor: pointer;
}

.pick-row:hover { background: var(--bg-hover); }
.pick-thumb { width: 64px; height: 36px; object-fit: cover; border-radius: 4px; background: #000; }
.pick-title { font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.ads-list { display: flex; flex-direction: column; gap: 0.9rem; }

.ad-card {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr) auto;
  gap: 1rem;
  align-items: center;
}

.ad-card.paused { opacity: 0.6; border-style: dashed; }

.ad-preview-wrap { width: 160px; }
.ad-preview { width: 160px; aspect-ratio: 16 / 9; object-fit: contain; border-radius: 6px; background: #000; display: block; }

.ad-info { min-width: 0; }
.ad-title-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.ad-title-row h3 { margin: 0; font-size: 1.02rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.ad-meta { margin: 0.2rem 0 0; color: var(--text-muted); font-size: 0.85rem; display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; }
.ad-stats { margin: 0.35rem 0 0; font-size: 0.85rem; color: #7dd8a8; }

.tag {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 6px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* toggle switch */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; cursor: pointer;
  background: var(--bg-hover); border: 1px solid var(--border);
  border-radius: 99px; transition: 0.15s ease;
}
.switch .slider::before {
  content: ""; position: absolute; height: 16px; width: 16px;
  left: 2px; top: 2px; background: var(--text-muted);
  border-radius: 50%; transition: 0.15s ease;
}
.switch input:checked + .slider { background: rgba(47, 158, 99, 0.35); border-color: #2f9e63; }
.switch input:checked + .slider::before { transform: translateX(18px); background: #7dd8a8; }

@media (max-width: 640px) {
  .ad-card { grid-template-columns: 1fr; }
  .ad-preview-wrap, .ad-preview { width: 100%; }
}

/* ---- docs page ---- */

.docs-layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 1.5rem;
  align-items: start;
}

.docs-toc {
  position: sticky;
  top: 72px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: calc(100vh - 96px);
  overflow-y: auto;
  font-size: 0.88rem;
}

.docs-toc a {
  color: var(--text-muted);
  padding: 4px 10px;
  border-left: 2px solid var(--border);
}

.docs-toc a:hover { color: var(--text); }
.docs-toc a.active { color: var(--accent); border-left-color: var(--accent); }

.docs-body { font-size: 0.95rem; overflow-wrap: break-word; }
.docs-spinner { margin: 0 auto 0.75rem; }

.docs-body h1 { font-size: 1.5rem; margin: 0 0 1rem; }
.docs-body h2 { font-size: 1.2rem; margin: 2rem 0 0.75rem; padding-top: 0.5rem; border-top: 1px solid var(--border); scroll-margin-top: 72px; }
.docs-body h3 { font-size: 1.02rem; margin: 1.4rem 0 0.5rem; scroll-margin-top: 72px; }

.docs-body pre {
  background: #05070a;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  overflow-x: auto;
  line-height: 1.45;
  font-size: 0.8rem;
}

.docs-body code {
  background: #05070a;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.5px 5px;
  font-size: 0.85em;
}

.docs-body pre code { background: none; border: none; padding: 0; }

.docs-body table { border-collapse: collapse; width: 100%; margin: 0.75rem 0; font-size: 0.88rem; display: block; overflow-x: auto; }

.docs-body th, .docs-body td {
  border: 1px solid var(--border);
  padding: 0.45rem 0.6rem;
  text-align: left;
  vertical-align: top;
}

.docs-body th { background: var(--bg-hover); }
.docs-body blockquote {
  margin: 0.75rem 0;
  padding: 0.4rem 1rem;
  border-left: 3px solid var(--accent);
  background: var(--bg-hover);
  border-radius: 0 var(--radius) var(--radius) 0;
}

.docs-body hr { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }
.docs-body img { max-width: 100%; }

@media (max-width: 860px) {
  .docs-layout { grid-template-columns: 1fr; }
  .docs-toc { position: static; max-height: none; flex-direction: row; flex-wrap: wrap; }
  .docs-toc a { border-left: none; border: 1px solid var(--border); border-radius: 99px; }
  .docs-toc a.active { border-color: var(--accent); }
}

/* ---- responsive ---- */

@media (max-width: 640px) {
  .container { padding: 0 0.75rem; }
  .ad-overlay .ad-skip-btn { bottom: 48px; }
}
