:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --text: #1f2421;
  --muted: #68706b;
  --border: #dddbd3;
  --accent: #1f6f5c;
  --accent-text: #ffffff;
  --danger: #a33a2c;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151816;
    --surface: #1f2421;
    --text: #ecece6;
    --muted: #9aa29c;
    --border: #343a36;
    --accent: #4fb79c;
    --accent-text: #0e1512;
    --danger: #e58a7c;
  }
}

* { box-sizing: border-box; }

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

.site-header,
main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 16px;
}

.site-header { padding-top: 28px; }

h1 {
  margin: 0 0 16px;
  font-size: 1.6rem;
}

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.tab {
  padding: 10px 16px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: none;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.tab[aria-selected="true"] {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

main { padding-top: 24px; padding-bottom: 48px; }

.search label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
}

.search-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.search input {
  flex: 1 1 160px;
  max-width: 240px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.6; cursor: progress; }

.btn.primary {
  padding: 10px 16px;
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  font-size: 1rem;
}

.results { margin-top: 24px; }

.results h2 {
  margin: 0 0 4px;
  font-size: 1.2rem;
}

.note { color: var(--muted); margin: 0 0 16px; }
.error { color: var(--danger); font-weight: 600; }

.bulk {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.bulk .btn { font-size: 0.95rem; }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.chips .btn { padding: 4px 10px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.reorder {
  position: absolute;
  top: 6px;
  right: 6px;
  display: flex;
  gap: 4px;
}

.reorder .btn {
  padding: 2px 8px;
  line-height: 1.3;
}

.drag-ghost { opacity: 0.35; }

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

.thumb {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 4 / 5;
  padding: 0;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  font: inherit;
  font-weight: 700;
  letter-spacing: 0.05em;
  cursor: zoom-in;
}

.thumb.static { cursor: default; }

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.badge {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 0.7rem;
  letter-spacing: 0.05em;
}

.card-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  flex: 1;
}

.file-name {
  font-size: 0.9rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.file-meta { color: var(--muted); font-size: 0.8rem; }

.actions {
  display: flex;
  gap: 8px;
  margin-top: auto;
}

.actions .btn { flex: 1; }

details.folder {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

details.folder > summary {
  padding: 12px 16px;
  font-weight: 600;
  cursor: pointer;
}

.folder-body { padding: 4px 16px 16px; }
.folder-body .card { background: var(--bg); }

#viewer {
  width: min(1000px, 96vw);
  height: 92vh;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
}

#viewer[open] { display: flex; flex-direction: column; }
#viewer::backdrop { background: rgba(0, 0, 0, 0.7); }

.viewer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

#viewer-title {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#viewer-body {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

#viewer-body img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

#viewer-body iframe {
  width: 100%;
  height: 100%;
  border: 0;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: 90vw;
  padding: 10px 16px;
  border-radius: 8px;
  background: #1f2421;
  color: #fff;
  font-size: 0.9rem;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
}
