/* Pulldit — dark-first, responsive, dependency-free styles. */
:root {
  --bg: #0e1116;
  --bg-elev: #161b22;
  --bg-elev-2: #1c2330;
  --border: #2a3340;
  --text: #e6edf3;
  --text-dim: #9aa7b4;
  --brand: #ff5414;
  --brand-2: #ff8717;
  --safe: #2ea043;
  --warn: #d29922;
  --danger: #f85149;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  --maxw: 1080px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f8fa; --bg-elev: #ffffff; --bg-elev-2: #f0f3f6;
    --border: #d0d7de; --text: #1f2328; --text-dim: #57606a; --shadow: 0 6px 24px rgba(140, 149, 159, 0.2);
  }
}

* { box-sizing: border-box; }

/* The `hidden` attribute must always win, even over author rules that set `display`
   (e.g. `.radio { display: flex }` would otherwise keep a [hidden] element visible). */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  background: radial-gradient(1200px 600px at 50% -10%, rgba(255, 84, 20, 0.10), transparent 60%), var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
}

a { color: var(--brand-2); }
code { background: var(--bg-elev-2); padding: 0.1em 0.4em; border-radius: 4px; font-size: 0.9em; }

.skip-link {
  position: absolute; left: -9999px; top: 0; background: var(--brand); color: #fff;
  padding: 0.6rem 1rem; border-radius: 0 0 var(--radius-sm) 0; z-index: 100;
}
.skip-link:focus { left: 0; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* Header — sticky bar, full-bleed background, centered inner content */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: var(--bg); /* fallback for browsers without color-mix */
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: var(--maxw); margin: 0 auto; padding: 0.7rem 1.2rem;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 0.85rem; }
.brand-logo { border-radius: 12px; box-shadow: var(--shadow); }
.brand-text h1 { margin: 0; font-size: 1.5rem; letter-spacing: -0.02em; }
.brand-text h1 span { color: var(--brand); }
.tagline { margin: 0.1rem 0 0; color: var(--text-dim); font-size: 0.92rem; }
.header-links { display: flex; gap: 1rem; font-weight: 600; }
.header-links a { text-decoration: none; }
.header-links a:hover { text-decoration: underline; }

/* Layout */
main { max-width: var(--maxw); margin: 0 auto; padding: 1rem 1.2rem 4rem; }

.panel {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.2rem; margin: 1rem 0; box-shadow: var(--shadow);
}

/* Form */
.field { display: block; margin-bottom: 0.4rem; }
.field-label { display: block; font-size: 0.82rem; color: var(--text-dim); margin-bottom: 0.3rem; font-weight: 600; }
input[type="text"], input[type="url"], input[type="number"], select {
  width: 100%; padding: 0.7rem 0.8rem; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 1rem; font-family: inherit;
}
/* :focus-visible (not :focus) so a MOUSE click on a checkbox/radio/button shows no ring;
   keyboard navigation still does, and text inputs still ring while typing. */
input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand);
}
/* Belt-and-suspenders: never draw the heavy ring on pointer focus of toggles. */
input[type="checkbox"]:focus:not(:focus-visible),
input[type="radio"]:focus:not(:focus-visible) { outline: none; }
.hint { margin: 0.1rem 0 0.9rem; color: var(--text-dim); font-size: 0.85rem; }
.pagination-hint { margin: 0.7rem 0 0; padding: 0.5rem 0.7rem; border: 1px solid var(--border);
  border-left: 3px solid var(--brand); border-radius: var(--radius-sm); background: var(--bg-elev-2); }
.pagination-hint.warn { border-left-color: var(--warn); color: var(--warn); }
.row { display: flex; gap: 0.8rem; align-items: flex-end; flex-wrap: wrap; }
.field.compact { flex: 1 1 120px; margin-bottom: 0; }

/* Buttons */
.btn {
  appearance: none; cursor: pointer; font: inherit; font-weight: 600;
  padding: 0.7rem 1.1rem; border-radius: var(--radius-sm);
  background: var(--bg-elev-2); color: var(--text); border: 1px solid var(--border);
  transition: transform 0.04s ease, filter 0.15s ease;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; filter: none; }
.btn.primary { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.danger-outline { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.danger-outline:hover { background: rgba(248, 81, 73, 0.12); }
.dl-controls { display: flex; gap: 0.5rem; justify-content: center; margin-bottom: 1rem; }

/* Proxy panel */
.collapsible > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 0.6rem;
  font-weight: 700; user-select: none;
}
.collapsible > summary::-webkit-details-marker { display: none; }
.collapsible > summary::after { content: "▸"; color: var(--text-dim); transition: transform 0.15s ease; }
.collapsible[open] > summary::after { transform: rotate(90deg); }
#proxy-panel .summary-title::before { content: "⚙ "; }
.history-title::before { content: "🕓 "; }
.stats-title::before { content: "📊 "; }
.links-title::before { content: "🔗 "; }
.advanced-title::before { content: "🛠 "; }
.badge.good { background: rgba(46, 160, 67, 0.18); color: var(--safe); border-color: transparent; }
.badge.bad { background: rgba(248, 81, 73, 0.18); color: var(--danger); border-color: transparent; }
.badge.warn { background: rgba(210, 153, 34, 0.18); color: var(--warn); border-color: transparent; }

/* Link history */
.links-toolbar { margin: 1rem 0 0.6rem; display: flex; gap: 0.7rem; align-items: center; flex-wrap: wrap; }
.links-hint { margin: 0; }
.links-list { list-style: none; margin: 0; padding: 0; max-height: 320px; overflow-y: auto; display: flex; flex-direction: column; gap: 0.35rem; }
.link-item { display: flex; gap: 0.4rem; align-items: stretch; }
.link-use { flex: 1; display: flex; align-items: center; gap: 0.5rem; min-width: 0; text-align: left; cursor: pointer;
  font: inherit; font-weight: 600; color: var(--text); background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 0.45rem 0.7rem; }
.link-use:hover { border-color: var(--brand); }
.link-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-latest { flex: none; font-size: 0.62rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--safe); background: rgba(46, 160, 67, 0.16); border-radius: 999px; padding: 0.1rem 0.45rem; }
.link-del { flex: none; cursor: pointer; font: inherit; font-weight: 700; color: var(--text-dim);
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0 0.6rem; }
.link-del:hover { border-color: var(--danger); color: var(--danger); }

/* Advanced settings */
.adv-row { margin-top: 1rem; }
.adv-toggles { list-style: none; margin: 0.6rem 0 0.4rem; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.adv-tools { margin-top: 0.9rem; padding-top: 0.9rem; border-top: 1px solid var(--border);
  display: flex; gap: 0.7rem; align-items: center; flex-wrap: wrap; }
.adv-tools-hint { margin: 0; }

/* History */
.history-list { list-style: none; margin: 1rem 0 0; padding: 0; max-height: 340px; overflow-y: auto; display: flex; flex-direction: column; gap: 0.3rem; }
.history-item { display: flex; gap: 0.6rem; align-items: baseline; font-size: 0.85rem; padding: 0.35rem 0.55rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg); }
.history-time { color: var(--text-dim); font-size: 0.74rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.history-icon { width: 1.3em; text-align: center; flex: none; }
.history-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.05rem; }
.history-text { word-break: break-word; }
.history-detail { color: var(--text-dim); font-size: 0.74rem; word-break: break-word; }
.history-del { flex: none; align-self: center; cursor: pointer; font: inherit; font-size: 0.78rem; font-weight: 700;
  line-height: 1; color: var(--text-dim); background: transparent; border: 1px solid transparent;
  border-radius: var(--radius-sm); padding: 0.15rem 0.4rem; }
.history-del:hover { border-color: var(--danger); color: var(--danger); }
.history-more { display: flex; justify-content: center; margin-top: 0.25rem; }
.history-more-btn { font-size: 0.78rem; padding: 0.35rem 0.9rem; }
.history-item.good .history-icon { color: var(--safe); }
.history-item.bad .history-icon { color: var(--danger); }
.history-item.warn .history-icon { color: var(--warn); }
.history-empty { color: var(--text-dim); font-size: 0.85rem; margin: 0.4rem 0 0; }
.badge {
  margin-left: auto; font-size: 0.78rem; font-weight: 700; padding: 0.2rem 0.6rem;
  border-radius: 999px; background: var(--bg-elev-2); border: 1px solid var(--border); color: var(--text-dim);
}
.proxy-modes { border: 0; margin: 1rem 0 0; padding: 0; display: grid; gap: 0.7rem; }
.radio {
  display: flex; gap: 0.7rem; padding: 0.85rem; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--bg); cursor: pointer;
}
.radio:hover { border-color: var(--brand); }
.radio input { margin-top: 0.3rem; accent-color: var(--brand); }
.radio strong { display: inline; }
.radio small { display: block; color: var(--text-dim); margin-top: 0.2rem; font-size: 0.85rem; }
.tag { font-style: normal; font-size: 0.7rem; font-weight: 700; padding: 0.1rem 0.45rem; border-radius: 999px; vertical-align: middle; }
.tag.safe { background: rgba(46, 160, 67, 0.18); color: var(--safe); }
.tag.warn { background: rgba(210, 153, 34, 0.18); color: var(--warn); }
.ext-ver { color: var(--safe); font-weight: 700; }
.ext-update-hint { padding: 0.5rem 0.7rem; border: 1px solid var(--border); border-left: 3px solid var(--warn);
  border-radius: var(--radius-sm); background: var(--bg-elev-2); color: var(--warn); }
.ext-update-hint .linklike { color: var(--brand-2); }
.inline-input { margin-top: 0.6rem; max-width: 420px; }

/* Statistics */
.statsbox-title { font-size: 0.95rem; font-weight: 700; margin: 0 0 0.6rem; display: flex; align-items: center; gap: 0.5rem; }
/* Gap between the panel summary (title) and its content — matches the rhythm the proxy
   and history panels get from their own first-child top margins. */
#fetch-stats, #download-stats { margin-top: 1rem; }
.stat-group + .stat-group { margin-top: 1rem; }
.stat-group-title { font-size: 0.78rem; font-weight: 700; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; margin: 0 0 0.5rem; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 0.6rem; }
.stat { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0.55rem 0.7rem; }
.stat-label { display: block; font-size: 0.72rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.03em; }
.stat-value { display: block; font-size: 1.15rem; font-weight: 700; margin-top: 0.15rem; }
.stat.good .stat-value { color: var(--safe); }
.stat.bad .stat-value { color: var(--danger); }
.stat.warn .stat-value { color: var(--warn); }
.stat.accent .stat-value { color: var(--brand-2); }
.stat.wide { grid-column: 1 / -1; }
.stat.wide .stat-value { font-size: 0.9rem; font-weight: 600; word-break: break-word; }
.pill { font-size: 0.72rem; font-weight: 700; padding: 0.12rem 0.5rem; border-radius: 999px; }
.pill.good { background: rgba(46, 160, 67, 0.18); color: var(--safe); }
.pill.bad { background: rgba(248, 81, 73, 0.18); color: var(--danger); }
.pill.warn { background: rgba(210, 153, 34, 0.18); color: var(--warn); }

/* Filters */
.filters-panel .hint { margin: 0.7rem 0 0; }
.filters { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.filters-label { color: var(--text-dim); font-size: 0.82rem; font-weight: 600; }
.chip { display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.3rem 0.6rem; border: 1px solid var(--border); border-radius: 999px; font-size: 0.85rem; cursor: pointer; user-select: none; background: var(--bg); }
.chip:hover { border-color: var(--brand); }
.chip input { accent-color: var(--brand); cursor: pointer; }

/* Toolbar + results */
.toolbar { display: flex; justify-content: space-between; gap: 0.8rem; flex-wrap: wrap; margin-bottom: 0.9rem; }
.toolbar-left, .toolbar-right { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.count { color: var(--text-dim); font-size: 0.9rem; }

.progress { position: relative; height: 26px; background: var(--bg); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; margin-bottom: 1rem; }
.progress-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--brand), var(--brand-2)); transition: width 0.2s ease; }
.progress-label { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 0.8rem; font-weight: 600; }
.fetch-progress { margin: 0.8rem 0 0; }
/* Indeterminate (single-request fetch): a 35%-wide bar sliding across, no known total. */
.progress-bar.indeterminate { width: 35%; transition: none; animation: progress-indeterminate 1.1s infinite ease-in-out; }
@keyframes progress-indeterminate { 0% { margin-left: -35%; } 100% { margin-left: 100%; } }

.grid { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.9rem; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  /* Scroll the results internally instead of growing the page to kilometers at 1000+ items.
     content-visibility on each card still virtualizes paint/decode inside this scroll port. */
  max-height: min(78vh, 900px); overflow-y: auto; overscroll-behavior: contain;
  padding-right: 0.3rem; scrollbar-gutter: stable; }
.grid::-webkit-scrollbar { width: 10px; }
.grid::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; }
.grid::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }
.card { position: relative; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; display: flex; flex-direction: column;
  /* Cheap virtualization: the browser skips layout/paint/decode for off-screen cards, so a grid
     of hundreds of images stays responsive. `auto` height is remembered after first render. */
  content-visibility: auto; contain-intrinsic-size: auto 300px; }
.card.selected { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand); }
.card-media { position: relative; aspect-ratio: 1 / 1; background: var(--bg-elev-2); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.card-media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-media .placeholder { color: var(--text-dim); font-size: 2rem; }
.card-check { position: absolute; top: 8px; left: 8px; width: 22px; height: 22px; accent-color: var(--brand); cursor: pointer; z-index: 2; }
.card-discard, .card-restore { position: absolute; top: 8px; right: 8px; z-index: 2; height: 26px; min-width: 26px; padding: 0 0.4rem; border: none; border-radius: 6px; background: rgba(0, 0, 0, 0.62); color: #fff; cursor: pointer; font-size: 0.85rem; font-weight: 700; line-height: 1; display: inline-flex; align-items: center; justify-content: center; }
.card-discard:hover { background: var(--danger); }
.card-restore { background: var(--safe); }
.type-badge { position: absolute; bottom: 8px; right: 8px; font-size: 0.68rem; font-weight: 700; text-transform: uppercase; padding: 0.15rem 0.45rem; border-radius: 6px; background: rgba(0, 0, 0, 0.6); color: #fff; }
.got-badge { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); z-index: 2; font-size: 0.62rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; padding: 0.12rem 0.5rem; border-radius: 999px; background: rgba(46, 160, 67, 0.92); color: #fff; }
.card.downloaded { opacity: 0.72; }
.card.downloaded:hover { opacity: 1; }
.nsfw-badge { position: absolute; bottom: 8px; left: 8px; font-size: 0.65rem; font-weight: 700; padding: 0.12rem 0.4rem; border-radius: 6px; background: var(--danger); color: #fff; }
.card-body { padding: 0.55rem 0.6rem; display: flex; flex-direction: column; gap: 0.4rem; }
.card-title { font-size: 0.82rem; line-height: 1.3; max-height: 2.6em; overflow: hidden; }
.card-actions { display: flex; gap: 0.4rem; }
.card-actions .btn { padding: 0.4rem 0.6rem; font-size: 0.8rem; flex: 1; text-align: center; }

/* Status + about */
.status { min-height: 1.4em; text-align: center; color: var(--text-dim); }
.status:empty { display: none; }
.status.error { color: var(--danger); }
.status.ok { color: var(--safe); }
.about h2, .disclaimer h2 { margin-top: 0; }
.about h3 { margin: 1.1rem 0 0.3rem; font-size: 1rem; }
.disclaimer { border-color: rgba(248, 81, 73, 0.4); }
.disclaimer ul, .about ul { padding-left: 1.2rem; }
.disclaimer li, .about li { margin: 0.3rem 0; }

/* Modal */
.btn.danger { background: var(--danger); color: #fff; border-color: transparent; }
.modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.62); backdrop-filter: blur(2px); }
.modal-card { position: relative; z-index: 1; width: min(480px, 100%); max-height: 90vh; overflow-y: auto; background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.4rem; }
.modal-card h2 { margin: 0 0 0.3rem; font-size: 1.2rem; }
.modal-desc { margin: 0 0 1rem; color: var(--text-dim); font-size: 0.9rem; }
.modal-options { list-style: none; margin: 0 0 0.6rem; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.check-row { display: flex; gap: 0.7rem; align-items: flex-start; padding: 0.6rem 0.7rem; border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; background: var(--bg); }
.check-row:hover { border-color: var(--brand); }
.check-row input { margin-top: 0.2rem; accent-color: var(--brand); flex: none; }
.check-row small { display: block; color: var(--text-dim); font-size: 0.8rem; margin-top: 0.1rem; }
.check-row.is-disabled { opacity: 0.5; cursor: not-allowed; }
.check-row.is-disabled:hover { border-color: var(--border); }
.select-all-row { background: transparent; border-style: dashed; margin-bottom: 1.1rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.6rem; }

/* Inline "link-styled" button (used for the extension install call-to-action) */
.linklike {
  appearance: none; background: none; border: 0; padding: 0; margin: 0; cursor: pointer;
  color: var(--brand-2); font: inherit; font-weight: 700; text-decoration: underline;
}
.linklike:hover { filter: brightness(1.15); }

/* Extension install steps */
.install-steps { margin: 0 0 0.8rem; padding-left: 1.3rem; display: flex; flex-direction: column; gap: 0.55rem; }
.install-steps li { line-height: 1.5; }
.install-steps .btn { margin-bottom: 0.15rem; }

/* Footer — sticky to the bottom of the viewport, always visible, full-bleed bar */
.site-footer {
  position: sticky; bottom: 0; z-index: 40; margin-top: 1rem;
  background: var(--bg-elev); /* fallback for browsers without color-mix */
  background: color-mix(in srgb, var(--bg-elev) 92%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
}
.footer-inner {
  max-width: var(--maxw); margin: 0 auto; padding: 0.7rem 1.2rem;
  display: flex; align-items: center; justify-content: center; gap: 0.4rem 1.2rem;
  flex-wrap: wrap; text-align: center; color: var(--text-dim); font-size: 0.82rem;
}
.footer-brand { display: inline-flex; align-items: center; gap: 0.4rem; font-weight: 700; }
.footer-logo { border-radius: 6px; }
.footer-name { letter-spacing: -0.01em; }
.footer-name span { color: var(--brand); }
.footer-ver { font-weight: 600; font-size: 0.72rem; color: var(--text-dim); background: var(--bg-elev-2);
  border: 1px solid var(--border); border-radius: 999px; padding: 0.05rem 0.45rem; }
.footer-note { margin: 0; flex: 1 1 100%; font-size: 0.78rem; opacity: 0.9; }
/* Local two-tone status pills (shields-style) — no external images, CSP stays strict. */
.footer-badges { display: inline-flex; gap: 0.45rem; flex-wrap: wrap; justify-content: center; }
.fbadge { display: inline-flex; align-items: stretch; border-radius: 5px; overflow: hidden;
  font-size: 0.68rem; font-weight: 700; text-decoration: none; line-height: 1.6;
  border: 1px solid var(--border); }
.fbadge:hover { filter: brightness(1.12); }
.fbadge-k { padding: 0 0.4rem; background: #30363d; color: #e6edf3; }
.fbadge-v { padding: 0 0.4rem; color: #fff; }
.fbadge.ok .fbadge-v { background: var(--safe); }
.fbadge.license .fbadge-v { background: #0a7ea4; }

@media (max-width: 560px) {
  .brand-text h1 { font-size: 1.25rem; }
  .row { gap: 0.6rem; }
  .field.compact { flex: 1 1 100%; }
  #fetch-btn { width: 100%; }
}
