:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e0e2e7;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161a;
    --surface: #1d2026;
    --border: #2c2f37;
    --text: #e8e9ec;
    --text-muted: #9a9ea8;
    --accent: #6366f1;
    --accent-hover: #7678f4;
    --shadow: 0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
  }
}

:root[data-theme="dark"] {
  --bg: #14161a;
  --surface: #1d2026;
  --border: #2c2f37;
  --text: #e8e9ec;
  --text-muted: #9a9ea8;
  --accent: #6366f1;
  --accent-hover: #7678f4;
  --shadow: 0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 760px;
  margin: 0 auto;
  padding: 32px 16px 64px;
}

.app-header {
  text-align: center;
  margin-bottom: 28px;
}

.app-header h1 {
  font-size: 28px;
  margin: 0 0 8px;
  letter-spacing: -0.02em;
}

.subtitle {
  color: var(--text-muted);
  margin: 0;
  font-size: 14.5px;
  line-height: 1.5;
}

.dropzone {
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.dropzone:hover,
.dropzone:focus-visible,
.dropzone.drag-over {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 6%, var(--surface));
  outline: none;
}

.dropzone-content svg {
  color: var(--accent);
  margin-bottom: 10px;
}

.dropzone-content p {
  margin: 4px 0;
}

.hint {
  color: var(--text-muted);
  font-size: 13px;
}

.hidden { display: none !important; }

.controls {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 16px;
  box-shadow: var(--shadow);
}

.controls-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.controls-row + .controls-row {
  margin-top: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  flex: 1 1 160px;
}

.field select,
.field input[type="text"] {
  font-size: 14px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.actions {
  justify-content: flex-end;
  align-items: center;
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: white;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg); }

.btn-danger-ghost {
  background: transparent;
  color: var(--danger);
  border: none;
  cursor: pointer;
  font-size: 13px;
  padding: 4px 8px;
}
.btn-danger-ghost:hover { color: var(--danger-hover); }

.list-section {
  margin-top: 20px;
}

.list-hint {
  color: var(--text-muted);
  font-size: 13px;
  margin: 0 0 10px;
}

.image-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 12px;
}

.image-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: grab;
  box-shadow: var(--shadow);
  position: relative;
}

.image-item.dragging {
  opacity: 0.4;
}

.image-item .thumb-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 6px;
  overflow: hidden;
  background: var(--bg);
}

.image-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.page-badge {
  position: absolute;
  top: 4px;
  left: 4px;
  background: rgba(0,0,0,0.6);
  color: white;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 20px;
}

.image-item .file-name {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 24px 0;
  font-size: 14px;
}

.progress {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 20px;
  color: var(--text-muted);
  font-size: 14px;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.result-box {
  margin-top: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  text-align: center;
  box-shadow: var(--shadow);
}

.result-box p {
  margin: 0 0 12px;
  font-weight: 600;
}

.app-footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 12.5px;
  margin-top: 36px;
  line-height: 1.6;
}

@media (max-width: 480px) {
  .actions { justify-content: stretch; }
  .actions .btn { flex: 1; justify-content: center; }
}
