:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --border: #e3e6eb;
  --border-strong: #c8cdd5;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1e4fd1;
  --success: #16a34a;
  --error: #dc2626;
  --error-bg: #fef2f2;
  --accent-bg: #eff4ff;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.04);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

body {
  display: flex;
  justify-content: center;
  padding: 40px 20px;
}

.card {
  width: 100%;
  max-width: 960px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

header h1 { margin: 0 0 4px; font-size: 22px; font-weight: 600; }
header .sub { margin: 0; color: var(--text-muted); }

h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.row-between {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px;
}

.hint { color: var(--text-muted); font-size: 12px; margin: 0; }
.hidden { display: none !important; }

.dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  outline: none;
}
.dropzone:hover, .dropzone:focus-visible, .dropzone.dragover {
  border-color: var(--primary); background: var(--accent-bg);
}
.dropzone-title { margin: 0 0 4px; font-size: 16px; font-weight: 500; }
.dropzone-sub { margin: 0; color: var(--text-muted); font-size: 13px; }

.settings {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 0 16px;
}
.settings summary {
  cursor: pointer; padding: 12px 0; font-weight: 500; user-select: none; list-style: none;
}
.settings summary::-webkit-details-marker { display: none; }
.settings summary::before {
  content: "▸"; display: inline-block; margin-right: 8px;
  transition: transform 0.15s; color: var(--text-muted);
}
.settings[open] summary::before { transform: rotate(90deg); }
.settings-body { padding: 8px 0 16px; display: flex; flex-direction: column; gap: 14px; }

.checkbox-row { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.checkbox-row span { font-size: 13px; }

.slider-row {
  display: grid; grid-template-columns: 80px 1fr 48px;
  align-items: center; gap: 12px;
}
.slider-label { color: var(--text-muted); font-size: 13px; }
.slider-row input[type="range"] { width: 100%; }
.slider-row output {
  text-align: right; font-variant-numeric: tabular-nums;
  color: var(--text); font-size: 13px;
}

.btn {
  font: inherit; border-radius: var(--radius-sm); padding: 10px 18px;
  border: 1px solid transparent; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px; transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: var(--primary); color: white; font-weight: 500;
  align-self: flex-start; min-width: 140px;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-ghost {
  background: transparent; color: var(--text-muted);
  border-color: var(--border); padding: 6px 12px; font-size: 13px;
}
.btn-ghost:hover:not(:disabled) { color: var(--text); border-color: var(--border-strong); }

.spinner {
  width: 14px; height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: white; border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

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

.tile {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden; background: var(--bg);
  display: flex; flex-direction: column; font-size: 12px;
}
.tile-thumb {
  position: relative; width: 100%; aspect-ratio: 1 / 1;
  background: #e9ecf1; overflow: hidden;
}
.tile-thumb img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.tile-thumb img.after {
  position: absolute; inset: 0; opacity: 0; transition: opacity 0.15s;
}
.tile.success:hover .tile-thumb img.after { opacity: 1; }
.tile-meta {
  padding: 6px 8px; display: flex; flex-direction: column; gap: 2px;
  background: white; border-top: 1px solid var(--border);
}
.tile-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.tile-action { color: var(--primary); text-decoration: none; font-size: 11px; }
.tile-action:hover { text-decoration: underline; }
.tile.pending .tile-thumb img { opacity: 0.4; filter: grayscale(0.6); }
.tile.failed { border-color: var(--error); background: var(--error-bg); }
.tile.failed .tile-thumb img { opacity: 0.5; }
.tile-error { color: var(--error); font-size: 11px; }

.progress-bar {
  width: 100%; height: 6px; background: var(--border);
  border-radius: 999px; overflow: hidden; margin-bottom: 16px;
}
.progress-fill {
  height: 100%; background: var(--primary); width: 0%; transition: width 0.2s;
}
.status-pill {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 2px 8px; background: var(--accent-bg); color: var(--primary);
  border-radius: 999px;
}
.status-pill.done { background: #dcfce7; color: var(--success); }
.status-pill.error { background: var(--error-bg); color: var(--error); }

#download-all-btn { margin-top: 16px; }

footer { color: var(--text-muted); font-size: 12px; }
footer a { color: var(--text-muted); }
footer a:hover { color: var(--text); }
footer .built-by {
  text-align: center;
  font-size: 16px;
  font-weight: 500;
  margin-top: 16px;
  color: var(--text);
}
footer .built-by a { color: var(--primary); }
footer .built-by a:hover { color: var(--primary-hover); }

dialog {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px; max-width: 480px;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.3); }
dialog h2 { font-size: 16px; text-transform: none; letter-spacing: 0; margin-bottom: 12px; }
