:root {
  color-scheme: light;
  --page: #f5f6f8;
  --surface: #ffffff;
  --subtle: #edf0f4;
  --text: #202b3c;
  --muted: #5e6b7e;
  --line: #dce2eb;
  --accent: #315bce;
  --accent-hover: #2648a5;
  --accent-soft: #edf2ff;
  --danger: #a5283a;
  --danger-bg: #fff0f1;
  --shadow: 0 6px 24px rgb(20 35 60 / 4%);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #10151f;
  --surface: #19212e;
  --subtle: #222e3f;
  --text: #edf2fb;
  --muted: #aab8cc;
  --line: #334156;
  --accent: #9ab5ff;
  --accent-hover: #bbceff;
  --accent-soft: #243553;
  --danger: #ffb1bd;
  --danger-bg: #3a242e;
  --shadow: 0 6px 24px rgb(0 0 0 / 12%);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--page); color: var(--text); font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 15px; line-height: 1.6; }
button, input, .viewer-button { font: inherit; }
button, .viewer-button { display: inline-flex; align-items: center; justify-content: center; gap: 14px; min-height: 42px; padding: 9px 16px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--text); text-decoration: none; cursor: pointer; font-weight: 600; }
button:hover, .viewer-button:hover { background: var(--subtle); border-color: var(--muted); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.app-shell { max-width: 1440px; margin: 0 auto; padding: 0 40px 40px; }
.app-header { display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 26px 0; }
.brand { display: flex; align-items: center; gap: 12px; font-size: 20px; font-weight: 750; letter-spacing: -.5px; line-height: 1.3; }
.brand-mark { display: grid; place-items: center; width: 42px; height: 42px; background: var(--accent); color: var(--page); border-radius: 12px; font-size: 25px; }
.brand-detail { display: block; font-size: 11px; color: var(--muted); font-weight: 500; letter-spacing: .4px; }
#themeToggle { font-size: 13px; }
.search-panel { padding: 32px 36px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); }
.eyebrow { margin: 0 0 8px; text-transform: uppercase; font-weight: 700; font-size: 11px; letter-spacing: 1.7px; color: var(--accent); }
h1 { margin: 0; font-size: clamp(25px, 3vw, 36px); letter-spacing: -1.2px; line-height: 1.25; font-weight: 700; }
.intro { margin: 10px 0 26px; color: var(--muted); }
label { display: block; font-size: 13px; font-weight: 650; margin-bottom: 8px; }
.search-row { display: flex; gap: 10px; }
input { min-width: 0; flex: 1; padding: 13px 16px; border: 1px solid var(--line); border-radius: 9px; background: var(--page); color: var(--text); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 14px; }
input::placeholder { color: var(--muted); opacity: 1; }
.primary-button { background: var(--accent); border-color: var(--accent); color: var(--page); white-space: nowrap; }
.primary-button:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.hint { margin: 12px 0 0; color: var(--muted); font-size: 12px; }
.request-settings { margin-top: 18px; }
.request-settings input { width: 140px; }
code { padding: 2px 5px; border-radius: 4px; background: var(--subtle); color: var(--text); }
.results-panel { padding-top: 30px; }
.results-heading { display: flex; justify-content: space-between; align-items: center; gap: 16px; min-height: 44px; margin-bottom: 8px; }
h2 { margin: 0; font-size: 19px; letter-spacing: -.4px; }
#loadActions { display: flex; flex-wrap: wrap; gap: 8px; }
#loadActions button { font-size: 12px; min-height: 34px; padding: 5px 12px; }
#status { color: var(--muted); font-size: 13px; margin-bottom: 18px; overflow-wrap: anywhere; }
#loadProgress { display: block; appearance: none; width: 100%; height: 6px; border: 0; border-radius: 10px; overflow: hidden; background: var(--line); accent-color: var(--accent); margin: 0 0 22px; }
#loadProgress::-webkit-progress-bar { background: var(--line); border-radius: 10px; }
#loadProgress::-webkit-progress-value { background: var(--accent); border-radius: 10px; }
#loadProgress::-moz-progress-bar { background: var(--accent); border-radius: 10px; }
#images { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.thumb { min-width: 0; display: flex; flex-direction: column; align-self: start; overflow: hidden; border: 1px solid var(--line); border-radius: 12px; padding: 0; background: var(--surface); color: var(--text); text-decoration: none; cursor: pointer; box-shadow: var(--shadow); transition: border-color .15s, transform .15s; }
.thumb:hover { border-color: var(--accent); transform: translateY(-2px); }
.thumb-media { display: flex; align-items: center; justify-content: center; width: 100%; aspect-ratio: 1; padding: 8px; min-width: 0; overflow: hidden; color: inherit; text-decoration: none; }
/* Keep media elements and their sources intact while skipping offscreen painting.
   The square media area reserves space without estimated placeholder heights. */
.thumb-media { content-visibility: auto; }
.thumb img { display: block; width: 100%; height: 100%; object-fit: contain; }
.thumb-footer { display: flex; align-items: center; border-top: 1px solid var(--line); background: var(--surface); }
.thumb-dimensions { flex: 1; min-width: 0; padding: 6px 4px; color: var(--muted); text-align: center; font-size: 12px; font-weight: 500; font-variant-numeric: tabular-nums; line-height: 1.5; }
.thumb-original { display: inline-flex; align-items: center; justify-content: center; align-self: stretch; min-width: 36px; min-height: 36px; border-left: 1px solid var(--line); color: var(--accent); text-decoration: none; font-size: 20px; }
.thumb-original:hover { background: var(--accent-soft); }
.thumb.video { background: var(--accent-soft); color: var(--accent); font-weight: 600; text-decoration: none; text-align: center; font-size: 14px; }
.thumb.video[data-state="checking"], .thumb.video[data-state="unavailable"] { color: var(--muted); cursor: default; transform: none; }
.thumb.video[data-state="unavailable"] { background: var(--danger-bg); color: var(--danger); }
#emptyState { text-align: center; padding: 64px 20px; border: 1px dashed var(--line); border-radius: 14px; color: var(--muted); }
#images:has(.thumb:not([hidden])) + #emptyState { display: none; }
.empty-icon { display: inline-grid; place-items: center; height: 52px; width: 52px; border-radius: 14px; background: var(--subtle); color: var(--muted); font-size: 30px; }
#emptyState h3 { margin: 16px 0 6px; font-size: 16px; font-weight: 600; color: var(--text); }
#emptyState p { margin: 0; font-size: 13px; }
.gallery-help { display: flex; flex-wrap: wrap; justify-content: center; gap: 20px; padding: 22px 0; color: var(--muted); font-size: 11px; }
kbd { display: inline-block; padding: 0 5px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); font: inherit; }
#viewer { position: fixed; inset: 0; background: rgb(5 9 16 / 95%); display: none; align-items: center; justify-content: center; z-index: 9999; overflow: auto; padding: 80px 16px 16px; }
#viewer.open { display: flex; }
#viewer img, #viewer video { max-width: 96vw; max-height: 84vh; object-fit: contain; }
#viewer img { cursor: zoom-in; display: block; }
#viewer img.fullsize { max-width: none; max-height: none; cursor: zoom-out; }
#viewerToolbar { position: fixed; top: 16px; left: 16px; right: 16px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; z-index: 10000; pointer-events: none; }
#viewerToolbar > * { pointer-events: auto; }
#viewerInfo { color: #e9eef8; margin-left: auto; padding: 8px 10px; background: #1e293b; border-radius: 8px; font-size: 13px; }
@media (max-width: 640px) {
  .app-shell { padding: 0 16px 20px; }
  .app-header { padding: 20px 0; }
  .search-panel { padding: 24px 20px; }
  .search-row { flex-direction: column; }
  input { width: 100%; font-size: 13px; }
  #images { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
  .results-heading { align-items: flex-start; }
  .gallery-help { gap: 12px; }
  #viewerToolbar { top: 8px; left: 8px; right: 8px; gap: 6px; }
  #viewerToolbar .viewer-button { font-size: 12px; min-height: 36px; padding: 6px 10px; }
  #viewerInfo { font-size: 11px; }
  #viewer { padding-top: 120px; }
  #viewer img, #viewer video { max-height: 75vh; }
}
@media (prefers-reduced-motion: reduce) { .thumb { transition: none; } }

.progress-summary {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 12px 0;
  margin-bottom: 10px;
  background: var(--page);
}
.progress-summary #status { margin-bottom: 0; }
.progress-controls { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 16px; }
.progress-controls #status { flex: 1 1 280px; min-width: 0; }
.progress-summary #loadProgress { margin: 10px 0 0; }

button:disabled { opacity: .5; cursor: default; }
