:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1b1e23;
  --muted: #5c6470;
  --border: #dce0e6;
  --accent: #1d63d8;
  --accent-text: #ffffff;
  --well: #eceef2;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a20;
    --text: #e5e8ed;
    --muted: #9aa2ae;
    --border: #2a2f38;
    --accent: #5b95ff;
    --accent-text: #0a0f1a;
    --well: #0b0d11;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

a { color: var(--accent); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

code {
  font: 0.9em var(--mono);
  background: var(--well);
  padding: 1px 5px;
  border-radius: 4px;
}

.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }

.top {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 24px 0 16px;
}

h1 { font-size: 24px; line-height: 1.2; margin: 0 0 6px; letter-spacing: -0.01em; }

.lede { margin: 0 0 16px; color: var(--muted); }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.toolbar + .toolbar { margin-top: 10px; }

.toolbar input[type="search"] {
  flex: 1 1 240px;
  min-width: 0;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.count { margin-right: auto; color: var(--muted); font-variant-numeric: tabular-nums; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.small { height: 30px; padding: 0 10px; font-size: 13px; }

.group { margin: 28px 0; }

.group h2 {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  align-items: baseline;
  margin: 0 0 12px;
  font-size: 16px;
}
.folder { font-family: var(--mono); font-size: 15px; overflow-wrap: anywhere; }
.group-count { color: var(--muted); font-weight: 400; font-size: 14px; }

.grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 210px), 1fr));
  gap: 16px;
}

.card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.thumb { display: block; aspect-ratio: 1 / 1; background: var(--well); }
.thumb img { display: block; width: 100%; height: 100%; object-fit: contain; }

.card .name { margin: 10px 12px 6px; font-weight: 600; font-size: 14px; overflow-wrap: anywhere; }

.card .url {
  margin: 0 12px;
  width: calc(100% - 24px);
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--muted);
  font: 12px var(--mono);
}

.actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 12px 12px; margin-top: auto; }
.actions .btn { flex: 1 1 auto; }

.empty {
  margin: 32px 0;
  padding: 32px 16px;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.help { margin-top: 40px; }
.help h2 { font-size: 16px; margin: 0 0 12px; }

details {
  margin-bottom: 8px;
  padding: 0 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
summary { padding: 12px 0; font-weight: 600; cursor: pointer; }
details[open] summary { border-bottom: 1px solid var(--border); }
details p, details ol { margin: 12px 0 14px; }
details li + li { margin-top: 4px; }

.foot { margin: 32px auto 40px; color: var(--muted); font-size: 13px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  max-width: calc(100% - 32px);
  padding: 8px 14px;
  border-radius: 8px;
  background: var(--text);
  color: var(--bg);
  font-weight: 500;
  opacity: 0;
  transform: translate(-50%, 12px);
  transition: opacity 0.15s, transform 0.15s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
