/* APEX VideoDownloader — dark console theme */

:root {
  --bg:        #0a0c0f;
  --bg-grad:   radial-gradient(1200px 600px at 50% -10%, #14181f 0%, #0a0c0f 60%);
  --panel:     #12151a;
  --panel-2:   #171b21;
  --line:      #242a33;
  --line-soft: #1c2129;
  --text:      #e7ebf1;
  --muted:     #8b95a5;
  --dim:       #626d7d;
  --accent:    #ff8a3d;
  --accent-2:  #ffb648;
  --ok:        #3ddc97;
  --err:       #ff5f5f;
  --info:      #57a6ff;
  --radius:    12px;
  --radius-sm: 8px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Fira Code", Menlo, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Inter, Roboto, sans-serif;
}

* { box-sizing: border-box; }

/* Author `display` rules outrank the UA stylesheet's [hidden] rule, so every
   element toggled via the hidden attribute needs this to actually disappear. */
[hidden] { display: none !important; }

html { color-scheme: dark; }

body {
  margin: 0;
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }

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

/* ── Top bar ─────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 14px 22px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(10, 12, 15, 0.72);
  backdrop-filter: blur(12px);
  position: sticky; top: 0; z-index: 20;
}

.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }

.hex {
  font-size: 22px; line-height: 1;
  color: var(--accent);
  filter: drop-shadow(0 0 10px rgba(255, 138, 61, 0.45));
}

.brand h1 { font-size: 17px; letter-spacing: 0.06em; text-transform: uppercase; }
.brand h1 span { color: var(--muted); font-weight: 500; letter-spacing: 0.02em; text-transform: none; }

.status { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.pill {
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.04em;
  padding: 4px 9px; border-radius: 99px;
  border: 1px solid var(--line); background: var(--panel);
  color: var(--dim); white-space: nowrap;
}
.pill.ok  { color: var(--ok);  border-color: rgba(61, 220, 151, 0.35); background: rgba(61, 220, 151, 0.08); }
.pill.warn { color: var(--accent-2); border-color: rgba(255,182,72,.35); background: rgba(255,182,72,.08); }
.pill.bad { color: var(--err); border-color: rgba(255, 95, 95, 0.35);  background: rgba(255, 95, 95, 0.08); }
.pill.path { max-width: 34ch; overflow: hidden; text-overflow: ellipsis; direction: rtl; }

/* ── Layout ──────────────────────────────────────────────── */
main {
  max-width: 1020px; margin: 0 auto;
  padding: 26px 22px 90px;
  display: flex; flex-direction: column; gap: 16px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
}

/* ── Fetch ───────────────────────────────────────────────── */
.fetch { padding: 16px; }

.fetch-row { display: flex; gap: 10px; align-items: stretch; }

#url {
  flex: 1; resize: vertical; min-height: 46px; max-height: 240px;
  padding: 12px 14px;
  background: var(--bg); border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: var(--mono); font-size: 13.5px;
  outline: none; transition: border-color .15s, box-shadow .15s;
}
#url:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255, 138, 61, 0.14); }
#url::placeholder { color: var(--dim); }

.hint  { margin: 10px 2px 0; font-size: 12.5px; color: var(--dim); }
.error { margin: 10px 0 0; font-size: 13px; color: var(--err);
         background: rgba(255, 95, 95, 0.08); border: 1px solid rgba(255, 95, 95, 0.25);
         padding: 9px 12px; border-radius: var(--radius-sm); }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 0 18px; height: 46px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--panel-2); color: var(--text);
  font-size: 14px; font-weight: 550; cursor: pointer; white-space: nowrap;
  text-decoration: none;
  transition: background .14s, border-color .14s, transform .06s, opacity .14s;
}
.btn:hover:not(:disabled) { background: #1e232b; border-color: #313945; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn.primary {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  border-color: transparent; color: #241202; font-weight: 700;
}
.btn.primary:hover:not(:disabled) { filter: brightness(1.07); background: linear-gradient(180deg, var(--accent-2), var(--accent)); }

.btn.ghost { background: transparent; }
.btn.ghost:hover:not(:disabled) { background: var(--panel-2); }

.btn.sm { height: 32px; padding: 0 12px; font-size: 12.5px; font-weight: 500; }
.btn.danger:hover:not(:disabled) { border-color: rgba(255,95,95,.5); color: var(--err); }

/* ── Options ─────────────────────────────────────────────── */
.options-toggle {
  width: 100%; display: flex; align-items: center; gap: 9px;
  padding: 13px 16px; background: none; border: 0; cursor: pointer;
  font-size: 13.5px; font-weight: 550; text-align: left; color: var(--text);
}
.options-toggle .chev { color: var(--accent); transition: transform .16s; display: inline-block; }
.options-toggle[aria-expanded="true"] .chev { transform: rotate(90deg); }
.options-toggle .summary {
  margin-left: auto; font-weight: 400; font-size: 12.5px; color: var(--dim);
  font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.options-body { padding: 4px 16px 18px; border-top: 1px solid var(--line-soft); }

.opt-grid {
  display: grid; gap: 13px; padding-top: 15px;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--dim); }
.field select, .field input[type="text"] {
  height: 38px; padding: 0 11px;
  background: var(--bg); border: 1px solid var(--line);
  border-radius: var(--radius-sm); outline: none; font-size: 13.5px;
}
.field select:focus, .field input:focus { border-color: var(--accent); }

.opt-checks {
  margin-top: 18px; padding-top: 15px; border-top: 1px solid var(--line-soft);
  display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}
.check { display: flex; align-items: center; gap: 9px; font-size: 13.5px; cursor: pointer; }
.check.sub { padding-left: 24px; color: var(--muted); font-size: 13px; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

.cookie-box {
  margin-top: 18px; padding: 15px; border-radius: var(--radius-sm);
  background: var(--panel-2); border: 1px solid var(--line);
}
.cookie-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.cookie-head strong { font-size: 13.5px; }
.cookie-head .pill { margin-left: auto; }
.cookie-box .muted { margin: 0 0 12px; font-size: 12.8px; line-height: 1.6; }
.cookie-box code {
  font-family: var(--mono); font-size: 11.5px; padding: 1px 5px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 4px;
  color: var(--accent-2);
}
.cookie-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Result card ─────────────────────────────────────────── */
.result { display: flex; flex-direction: column; gap: 12px; }

.card {
  display: flex; gap: 16px; padding: 16px;
  background: var(--panel); border: 1px solid var(--line-soft); border-radius: var(--radius);
}

.thumb {
  width: 192px; aspect-ratio: 16 / 9; flex-shrink: 0;
  border-radius: var(--radius-sm); overflow: hidden;
  background: var(--panel-2); border: 1px solid var(--line);
  display: grid; place-items: center; color: var(--dim); font-size: 26px;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.card-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 9px; }
.card-title { font-size: 16.5px; font-weight: 620; line-height: 1.3; overflow-wrap: anywhere; }
.card-meta { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 12.5px; color: var(--muted); }
.card-meta .tag {
  font-family: var(--mono); font-size: 11px; padding: 2px 7px; border-radius: 5px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--dim);
}
.card-meta .tag.live { color: var(--err); border-color: rgba(255,95,95,.4); }

.card-controls { display: flex; gap: 10px; align-items: flex-end; margin-top: auto; flex-wrap: wrap; }
.card-controls .field { flex: 1; min-width: 210px; }

/* ── Playlist ────────────────────────────────────────────── */
.pl-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 14px 16px; border-bottom: 1px solid var(--line-soft);
}
.pl-head h3 { font-size: 15px; flex: 1; min-width: 200px; overflow-wrap: anywhere; }
.pl-list { max-height: 380px; overflow-y: auto; }

.pl-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 16px; border-bottom: 1px solid var(--line-soft);
  font-size: 13.5px; cursor: pointer;
}
.pl-item:last-child { border-bottom: 0; }
.pl-item:hover { background: var(--panel-2); }
.pl-item input { width: 16px; height: 16px; accent-color: var(--accent); flex-shrink: 0; }
.pl-item .idx { font-family: var(--mono); font-size: 11.5px; color: var(--dim); width: 3ch; text-align: right; flex-shrink: 0; }
.pl-item .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl-item .dur { font-family: var(--mono); font-size: 12px; color: var(--dim); flex-shrink: 0; }

.pl-foot { display: flex; gap: 10px; align-items: center; padding: 13px 16px; border-top: 1px solid var(--line-soft); }
.pl-foot .muted { margin-left: auto; }

/* ── Queue ───────────────────────────────────────────────── */
.queue-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--line-soft);
}
.queue-head h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); }
.queue-actions { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.count { font-family: var(--mono); font-size: 12px; color: var(--dim); }

.empty { padding: 34px 16px; text-align: center; color: var(--dim); font-size: 13.5px; margin: 0; }

.job {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 14px;
  padding: 13px 16px; border-bottom: 1px solid var(--line-soft);
  align-items: center;
}
.job:last-child { border-bottom: 0; }

.job-title {
  font-size: 14px; font-weight: 520; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; grid-column: 1;
}
.job-actions { grid-column: 2; grid-row: 1 / span 3; display: flex; gap: 6px; align-items: center; }

.bar {
  grid-column: 1; height: 6px; border-radius: 99px;
  background: var(--panel-2); overflow: hidden; margin: 3px 0;
  border: 1px solid var(--line-soft);
}
.bar > i {
  display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .35s ease;
}
.job.done  .bar > i { background: var(--ok); }
.job.error .bar > i { background: var(--err); }
.job.canceled .bar > i { background: var(--dim); }

.job.downloading .bar > i::after {
  content: ""; display: block; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.35), transparent);
  animation: sheen 1.4s linear infinite;
}
@keyframes sheen { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

.job-meta {
  grid-column: 1; display: flex; gap: 5px 14px; flex-wrap: wrap;
  font-family: var(--mono); font-size: 11.5px; color: var(--dim);
}
.job-meta .state { text-transform: uppercase; letter-spacing: 0.05em; }
.job.done  .job-meta .state { color: var(--ok); }
.job.error .job-meta .state { color: var(--err); }
.job.downloading .job-meta .state, .job.processing .job-meta .state { color: var(--accent); }
.job-meta .msg { color: var(--err); overflow-wrap: anywhere; }
/* Finished, but an optional step (cover art, chapters, remux) failed. */
.job-meta .warn { color: var(--accent-2); overflow-wrap: anywhere; }

/* ── Player ──────────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(5, 6, 8, 0.82); backdrop-filter: blur(6px);
  display: grid; place-items: center; padding: 24px;
}
.player-box {
  width: min(1000px, 100%); background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .6);
}
.player-head, .player-foot {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
}
.player-head { border-bottom: 1px solid var(--line-soft); }
.player-head span { font-weight: 560; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-head button { margin-left: auto; }
.player-foot { border-top: 1px solid var(--line-soft); }
.player-foot .muted { margin-left: auto; font-family: var(--mono); font-size: 12px; color: var(--dim); }
#player-video { width: 100%; max-height: 66vh; display: block; background: #000; }

.muted { color: var(--muted); font-size: 12.5px; }

/* ── Toasts ──────────────────────────────────────────────── */
.toasts {
  position: fixed; right: 18px; bottom: 18px; z-index: 60;
  display: flex; flex-direction: column; gap: 9px; align-items: flex-end;
}
.toast {
  padding: 11px 15px; border-radius: var(--radius-sm);
  background: var(--panel-2); border: 1px solid var(--line);
  font-size: 13.5px; max-width: 380px;
  box-shadow: 0 10px 30px rgba(0,0,0,.45);
  animation: rise .22s ease-out;
}
.toast.ok  { border-left: 3px solid var(--ok); }
.toast.err { border-left: 3px solid var(--err); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ── Sign-in ─────────────────────────────────────────────── */
body.centered { display: grid; place-items: center; min-height: 100vh; padding: 24px; }

.auth { width: min(430px, 100%); display: flex; flex-direction: column; gap: 18px; }
.auth-brand { display: flex; align-items: center; gap: 11px; justify-content: center; }
.auth-brand h1 { font-size: 17px; letter-spacing: .06em; text-transform: uppercase; }
.auth-brand h1 span { color: var(--muted); font-weight: 500; letter-spacing: .02em; text-transform: none; }

.auth-card { padding: 24px; display: flex; flex-direction: column; gap: 14px; }
.auth-card h2 { font-size: 17px; }
.auth-card .field input { height: 42px; }
.btn.wide { width: 100%; }

.qr {
  display: grid; place-items: center; padding: 16px;
  background: #fff; border-radius: var(--radius-sm); align-self: center;
}
/* Render at the QR's natural size. Forcing it smaller shrinks each module
   below what a phone camera can reliably resolve off a screen — zbar decodes
   a clean digital image far more easily than a camera does. */
.qr svg { display: block; width: auto; height: auto; max-width: 100%; }

.secret-details { font-size: 13px; color: var(--muted); }
.secret-details summary { cursor: pointer; }
.secret {
  display: block; margin-top: 8px; padding: 10px 12px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-family: var(--mono); font-size: 13px; word-break: break-all; color: var(--accent-2);
}

.auth-foot {
  text-align: center; font-size: 12.5px; color: var(--accent-2);
  background: rgba(255,182,72,.08); border: 1px solid rgba(255,182,72,.28);
  padding: 9px 12px; border-radius: var(--radius-sm); margin: 0;
}

/* ── Admin ───────────────────────────────────────────────── */
.user-row { padding: 14px 16px; border-bottom: 1px solid var(--line-soft); }
.user-row:last-child { border-bottom: 0; }
.user-row.inactive { opacity: .58; }

.user-head { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.user-name { font-size: 15px; font-weight: 600; }
.user-head .tag {
  font-family: var(--mono); font-size: 10.5px; padding: 2px 7px; border-radius: 5px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--dim);
  text-transform: uppercase; letter-spacing: .04em;
}
.user-head .tag.admin { color: var(--accent); border-color: rgba(255,138,61,.4); }
.user-head .tag.ok    { color: var(--ok);  border-color: rgba(61,220,151,.35); }
.user-head .tag.warn  { color: var(--accent-2); border-color: rgba(255,182,72,.35); }
.user-head .tag.off   { color: var(--err); border-color: rgba(255,95,95,.35); }

.user-meta { margin-top: 6px; font-family: var(--mono); font-size: 11.5px; color: var(--dim); }
.user-actions { margin-top: 11px; display: flex; gap: 6px; flex-wrap: wrap; }

.modal-body { padding: 18px 16px; display: flex; flex-direction: column; gap: 14px; }
.player-box.narrow { width: min(520px, 100%); }

.cred { display: flex; align-items: center; gap: 12px; }
.cred > span { font-size: 11.5px; text-transform: uppercase; letter-spacing: .07em;
               color: var(--dim); width: 84px; flex-shrink: 0; }
.cred code {
  flex: 1; padding: 9px 12px; background: var(--bg); border: 1px solid var(--line);
  border-radius: var(--radius-sm); font-family: var(--mono); font-size: 14px;
  color: var(--accent-2); word-break: break-all; user-select: all;
}

.audit-row {
  display: grid; grid-template-columns: 170px 150px 1fr; gap: 10px;
  padding: 8px 16px; border-bottom: 1px solid var(--line-soft);
  font-family: var(--mono); font-size: 11.5px; color: var(--dim);
}
.audit-row:last-child { border-bottom: 0; }
.audit-action { color: var(--accent); }
.audit-detail { overflow-wrap: anywhere; }
@media (max-width: 680px) { .audit-row { grid-template-columns: 1fr; gap: 2px; } }

/* ── About ───────────────────────────────────────────────── */
.doc { padding: 26px 30px; display: flex; flex-direction: column; gap: 18px; }
.doc h2 { font-size: 19px; }
.doc h3 { font-size: 14px; text-transform: uppercase; letter-spacing: .07em;
          color: var(--accent); margin-top: 8px; }
.doc p, .doc li { color: var(--muted); font-size: 14.5px; line-height: 1.65; }
.doc ul, .doc ol { margin: 0; padding-left: 22px; display: flex;
                   flex-direction: column; gap: 7px; }
.doc strong { color: var(--text); font-weight: 600; }
.doc code {
  font-family: var(--mono); font-size: 12.5px; padding: 1px 6px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 5px; color: var(--accent-2);
}
.doc .lede { font-size: 15.5px; color: var(--text); }
.doc .note {
  padding: 12px 15px; border-left: 3px solid var(--accent);
  background: var(--panel-2); border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.steps { counter-reset: step; list-style: none; padding: 0; }
.steps > li {
  counter-increment: step; position: relative; padding-left: 38px;
}
.steps > li::before {
  content: counter(step); position: absolute; left: 0; top: 1px;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent); color: #241202;
  font-size: 12px; font-weight: 700; display: grid; place-items: center;
}

/* ── Footer ──────────────────────────────────────────────── */
.site-foot {
  margin-top: 34px; padding: 22px 16px 8px;
  border-top: 1px solid var(--line-soft);
  display: flex; align-items: center; justify-content: center;
  gap: 8px 16px; flex-wrap: wrap; text-align: center;
  font-size: 12.5px; color: var(--dim);
}
.site-foot a { color: var(--accent); text-decoration: none; }
.site-foot a:hover { text-decoration: underline; }
.site-foot .sep { opacity: .4; }

/* ── Scrollbars ──────────────────────────────────────────── */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #232932; border-radius: 99px; border: 2px solid var(--panel); }
::-webkit-scrollbar-thumb:hover { background: #2f3742; }

/* ── Small screens ───────────────────────────────────────── */
@media (max-width: 680px) {
  .topbar { flex-wrap: wrap; }
  .pill.path { display: none; }
  .card { flex-direction: column; }
  .thumb { width: 100%; }
  .fetch-row { flex-direction: column; }
  .job { grid-template-columns: 1fr; }
  .job-actions { grid-column: 1; grid-row: auto; flex-wrap: wrap; margin-top: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
