:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1f242c;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --primary: #1f6feb;
  --primary-hover: #388bfd;
  --danger: #f85149;
  --accent: #2ea043;
  --radius: 10px;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f8fa;
    --panel: #ffffff;
    --panel-2: #f0f3f6;
    --border: #d0d7de;
    --text: #1f2328;
    --muted: #57606a;
    --primary: #0969da;
    --primary-hover: #218bff;
    --danger: #cf222e;
    --accent: #1a7f37;
    --shadow: 0 4px 16px rgba(140, 149, 159, 0.2);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
}

header {
  text-align: center;
  padding: 2rem 1rem 1rem;
}
header h1 {
  margin: 0;
  font-size: 1.75rem;
  letter-spacing: -0.01em;
}
header .tagline {
  margin: 0.5rem 0 0;
  color: var(--muted);
}

main {
  max-width: 880px;
  margin: 0 auto;
  padding: 1rem 1rem 4rem;
}

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 2.5rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover,
.dropzone:focus-visible {
  border-color: var(--primary);
  outline: none;
}
.dropzone.dragover {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 8%, var(--panel));
}
.dropzone-inner svg {
  color: var(--muted);
  margin-bottom: 0.5rem;
}
.dropzone-inner p { margin: 0.25rem 0; }
.muted { color: var(--muted); font-size: 0.875rem; }
.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font: inherit;
  padding: 0;
  text-decoration: underline;
}

.settings {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  margin-top: 1.5rem;
  padding: 1rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.settings label {
  display: flex;
  flex-direction: column;
  font-size: 0.875rem;
  color: var(--muted);
  gap: 0.25rem;
}
.settings select,
.settings input {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.5rem;
  font: inherit;
}

.thumb-list {
  list-style: none;
  padding: 0;
  margin: 1.5rem 0 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.75rem;
}
.thumb {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: grab;
  user-select: none;
}
.thumb.dragging,
.thumb.sortable-chosen {
  cursor: grabbing;
  box-shadow: var(--shadow);
}
.thumb .img-wrap {
  aspect-ratio: 1 / 1;
  background: var(--panel-2);
  display: flex;
  align-items: center;
  justify-content: center;
}
.thumb img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  pointer-events: none;
}
.thumb .meta {
  padding: 0.4rem 0.5rem;
  font-size: 0.75rem;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: center;
}
.thumb .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.thumb .index {
  position: absolute;
  top: 0.4rem;
  left: 0.4rem;
  background: var(--primary);
  color: white;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 999px;
  width: 1.5rem;
  height: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.thumb .remove {
  position: absolute;
  top: 0.3rem;
  right: 0.3rem;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  border: none;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 999px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  line-height: 1;
  padding: 0;
}
.thumb .remove:hover { background: var(--danger); }

.actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.btn {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 0.55rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition: background 0.12s, border-color 0.12s, transform 0.05s;
}
.btn:hover { background: var(--panel-2); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn .spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: none;
}
.btn.working .spinner { display: inline-block; }
.btn.working .label { opacity: 0.85; }
@keyframes spin { to { transform: rotate(360deg); } }

.status {
  margin-top: 1rem;
  min-height: 1.2em;
  color: var(--muted);
  text-align: right;
}
.status.error { color: var(--danger); }
.status.success { color: var(--accent); }

footer {
  text-align: center;
  padding: 1rem;
  color: var(--muted);
  font-size: 0.8rem;
}
