:root {
  color-scheme: light dark;
  --bg: #fff;
  --fg: #111;
  --muted: #666;
  --subtle: #777;
  --border: #ddd;
  --border-strong: #bbb;
  --border-soft: #eee;
  --surface: #fff;
  --surface-soft: #f7f7f7;
  --button-bg: #fff;
  --button-fg: #111;
  --button-active-bg: #111;
  --button-active-fg: #fff;
  --lightbox-bg: rgba(255,255,255,.96);
  --panel-bg: rgba(255,255,255,.88);
  --highlight-bg: #fff9df;
  --highlight-border: #d4a100;
  --highlight-ring: rgba(212,161,0,.22);
  --thumb-aspect: 1440 / 1000;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111;
    --fg: #f3f3ee;
    --muted: #aaa;
    --subtle: #999;
    --border: #333;
    --border-strong: #555;
    --border-soft: #282828;
    --surface: #191919;
    --surface-soft: #222;
    --button-bg: #1d1d1d;
    --button-fg: #f3f3ee;
    --button-active-bg: #f3f3ee;
    --button-active-fg: #111;
    --lightbox-bg: rgba(16,16,16,.96);
    --panel-bg: rgba(25,25,25,.88);
    --highlight-bg: #262111;
    --highlight-border: #c4a03b;
    --highlight-ring: rgba(196,160,59,.24);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111;
  --fg: #f3f3ee;
  --muted: #aaa;
  --subtle: #999;
  --border: #333;
  --border-strong: #555;
  --border-soft: #282828;
  --surface: #191919;
  --surface-soft: #222;
  --button-bg: #1d1d1d;
  --button-fg: #f3f3ee;
  --button-active-bg: #f3f3ee;
  --button-active-fg: #111;
  --lightbox-bg: rgba(16,16,16,.96);
  --panel-bg: rgba(25,25,25,.88);
  --highlight-bg: #262111;
  --highlight-border: #c4a03b;
  --highlight-ring: rgba(196,160,59,.24);
}
:root[data-theme="light"] { color-scheme: light; }
* { box-sizing: border-box; }
body { margin: 24px; font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--fg); background: var(--bg); }
a { color: inherit; }
h1 { margin: 0 0 4px; font-size: 22px; font-weight: 650; }
header { margin-bottom: 16px; }
header p { margin: 0 0 16px; color: var(--muted); }
.header-row { display: flex; gap: 16px; align-items: flex-start; justify-content: space-between; }
.owner-only { display: none !important; }
body.is-owner-mode .owner-block { display: block !important; }
body.is-owner-mode .owner-flex { display: flex !important; }
.owner-tools { gap: 6px; align-items: center; }
.button-link, .icon-link { display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--border); border-radius: 4px; background: var(--button-bg); color: var(--button-fg); padding: 4px 7px; font: inherit; text-decoration: none; white-space: nowrap; }
.button-link:hover, .icon-link:hover { border-color: var(--subtle); }
.icon-link, .icon-button { width: 30px; height: 30px; padding: 0; }
.icon-link svg, .icon-button svg { width: 16px; height: 16px; overflow: visible; }
.controls { position: sticky; top: 0; z-index: 10; background: var(--bg); padding: 8px 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.top-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
input, select { padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: 4px; background: var(--surface); color: var(--fg); font: inherit; }
input { width: min(520px, 100%); flex: 1 1 280px; }
select { max-width: 100%; }
#count { color: var(--muted); }
.control-spacer { flex: 1 1 auto; }
button { border: 1px solid var(--border); border-radius: 4px; background: var(--button-bg); color: var(--button-fg); padding: 4px 7px; font: inherit; cursor: pointer; }
button:hover { border-color: var(--subtle); }
button.active { background: var(--button-active-bg); border-color: var(--button-active-bg); color: var(--button-active-fg); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.card { border: 1px solid var(--border); padding: 10px; background: var(--surface); scroll-margin: 92px; transition: background .2s ease, border-color .2s ease, box-shadow .2s ease; }
.card.is-current { border-color: var(--highlight-border); background: var(--highlight-bg); box-shadow: 0 0 0 3px var(--highlight-ring); }
.thumb { display: block; width: 100%; height: auto; aspect-ratio: var(--thumb-aspect); object-fit: cover; object-position: top left; border: 1px solid var(--border-soft); background: var(--surface-soft); cursor: zoom-in; }
.title { margin: 9px 0 3px; font-weight: 650; }
.url { display: block; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.meta { margin-top: 8px; color: var(--subtle); font-size: 12px; }
.empty { display: none; color: var(--muted); padding: 24px 0; }
.empty.show { display: block; }
.help-modal { display: none; position: fixed; inset: 0; z-index: 70; padding: 18px; place-items: center; background: rgba(0,0,0,.38); }
.help-modal.show { display: grid; }
.help-dialog { width: min(420px, 100%); padding: 16px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); box-shadow: 0 14px 50px rgba(0,0,0,.22); }
.help-dialog h2 { margin: 0 0 10px; font-size: 18px; }
.help-dialog ul { margin: 0 0 14px; padding-left: 20px; color: var(--muted); }
.help-dialog li { margin: 6px 0; }
.help-dialog kbd { border: 1px solid var(--border); border-bottom-color: var(--border-strong); border-radius: 4px; padding: 0 5px; background: var(--surface-soft); color: var(--fg); font: 11px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }
.lightbox { display: none; position: fixed; inset: 0; z-index: 50; background: var(--lightbox-bg); padding: 18px; }
.lightbox.show { display: block; }
.lightbox-frame { position: relative; width: 100%; height: 100%; }
.lightbox-content { position: absolute; inset: 0; }
#preview { position: absolute; display: block; object-fit: contain; border: 1px solid var(--border); background: var(--surface); }
.lightbox-panel { position: absolute; top: 0; right: 0; z-index: 2; width: min(280px, calc(100% - 64px)); max-height: 100%; overflow: auto; display: flex; flex-direction: column; align-items: flex-start; gap: 8px; padding: 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--panel-bg); box-shadow: 0 8px 30px rgba(0,0,0,.12); backdrop-filter: blur(10px); }
.lightbox-info { min-width: 0; width: 100%; }
.lightbox-title { font-weight: 650; }
.lightbox-position, .lightbox-meta { color: var(--subtle); font-size: 12px; }
.lightbox-url { display: flex; gap: 6px; align-items: center; max-width: 100%; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.lightbox-url-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.open-hint { flex: 0 0 auto; display: inline-flex; gap: 4px; align-items: center; color: var(--subtle); font-size: 14px; }
.lightbox-actions { display: flex; width: 100%; gap: 6px; align-items: center; }
.lightbox-action { display: inline-flex; width: 32px; height: 32px; align-items: center; justify-content: center; border: 1px solid var(--border); border-radius: 4px; background: var(--button-bg); color: var(--button-fg); padding: 0; font: inherit; text-decoration: none; }
.lightbox-action:hover { border-color: var(--subtle); }
.lightbox-action svg { width: 16px; height: 16px; overflow: visible; }
#close { margin-left: auto; font-size: 20px; line-height: 1; }
@media (max-width: 820px) { :root { --thumb-aspect: 390 / 844; } .grid { grid-template-columns: repeat(auto-fill, minmax(min(180px, 100%), 1fr)); } }
@media (max-width: 640px) { body { margin: 14px; } .header-row { display: block; } .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; } .control-spacer { display: none; } .card { padding: 8px; } .title { font-size: 13px; } .url, .meta { font-size: 11px; } .lightbox { padding: 12px; } .lightbox-panel { width: min(260px, calc(100% - 24px)); } }
.status { color: var(--muted); padding: 24px 0; }
.status[hidden] { display: none; }
body[data-gallery-state="error"] #loading { display: none; }
body[data-gallery-state="ready"] #loading { display: none; }
body[data-gallery-state="loading"] #error { display: none; }
