:root {
  --bg: #f7f8fb;
  --surface: #ffffff;
  --field: #ffffff;
  --line: rgba(17, 24, 39, .14);
  --text: #111827;
  --sub: #6f5148;
  --muted: #667085;
  --topbar: #ffffff;
  --primary: #fa9403;
  --primary-strong: #cf6f00;
  --accent: #2563eb;
  --success: #16a34a;
  --danger: #dc2626;
  --shadow: 0 18px 48px rgba(17, 24, 39, .08);
}

html[data-theme="dark"] {
  --bg: #0c0e12;
  --surface: #15171d;
  --field: #0f1117;
  --line: rgba(255, 255, 255, .16);
  --text: #e5e7eb;
  --sub: #d9b8a0;
  --muted: #9ca3af;
  --topbar: #090a0d;
  --primary: #ffad32;
  --primary-strong: #fa9403;
  --accent: #60a5fa;
  --success: #22c55e;
  --danger: #f87171;
  --shadow: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

.dt-topbar {
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 16px;
  background: var(--topbar);
  border-bottom: 1px solid var(--line);
}

.dt-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.dt-logo { display: block; flex: 0 1 auto; }

.dt-logotop {
  width: min(500px, 58vw);
  height: auto;
  display: block;
}

.dt-title {
  color: var(--sub);
  font-weight: 700;
  white-space: nowrap;
}

.dt-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

button,
.dt-secondary-btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  min-height: 40px;
  padding: 9px 12px;
  font-weight: 700;
  cursor: pointer;
}

button:not(.dt-secondary-btn) {
  border-color: transparent;
  background: var(--primary);
  color: #17120a;
}

button:hover,
.dt-secondary-btn:hover {
  border-color: var(--primary);
  color: var(--primary-strong);
}

button:not(.dt-secondary-btn):hover {
  background: var(--primary-strong);
  color: #ffffff;
}

button:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.dt-main {
  width: 100%;
  margin: 18px 0;
  padding: 0 14px 40px;
}

.tool-shell {
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.tool-panel {
  flex: 0 0 430px;
  width: 430px;
  order: 2;
}

.tool-stage {
  flex: 1 1 auto;
  min-width: 0;
  order: 1;
}

.tool-panel,
.tool-stage {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 14px;
}

.tool-panel h1,
.tool-panel h2,
.tool-stage h2 {
  margin: 0 0 10px;
  color: var(--sub);
  font-weight: 650;
}

.tool-panel h2 { margin-top: 16px; }

label {
  display: block;
  font-size: 12px;
  font-weight: 700;
}

input[type="text"],
input[type="number"],
input[type="file"],
select,
textarea {
  width: 100%;
  margin-top: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  background: var(--field);
  color: var(--text);
  font-size: 13px;
}

input[type="color"] {
  width: 100%;
  height: 40px;
  margin-top: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  padding: 2px;
}

input[type="range"] {
  width: 100%;
  margin-top: 8px;
}

textarea {
  min-height: 96px;
  resize: vertical;
}

.tool-row {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.tool-row.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.tool-mini {
  display: inline-block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.drop-zone {
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: 170px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--surface);
  background: color-mix(in srgb, var(--accent) 6%, var(--surface));
  padding: 18px;
  cursor: pointer;
  text-align: center;
  transition: background .18s ease, border-color .18s ease, transform .18s ease;
}

.native-file-input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.drop-zone:hover,
.drop-zone.is-page-drag,
.drop-zone.is-dragover {
  border-color: var(--accent);
  background: var(--surface);
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
}

.drop-zone.is-dragover {
  transform: translateY(-1px);
}

.drop-badge {
  display: inline-grid;
  place-items: center;
  min-width: 72px;
  height: 42px;
  padding: 0 10px;
  border: 2px solid var(--primary);
  border-radius: 8px;
  color: var(--primary-strong);
  font-size: 14px;
  font-weight: 900;
}

.drop-title {
  color: var(--text);
  font-size: 16px;
  font-weight: 800;
}

.drop-browse {
  margin-top: 4px;
}

.drop-meta,
.drop-file,
.file-meta {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.drop-file {
  max-width: 100%;
  overflow-wrap: anywhere;
}

.file-meta {
  min-height: 18px;
  margin-top: 8px;
}

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

.tool-status {
  min-height: 22px;
  margin: 10px 0 0;
  color: var(--success);
  font-weight: 700;
  font-size: 13px;
}

.tool-status.is-error {
  color: var(--danger);
}

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

.stage-count {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.progress-track {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--muted) 18%, transparent);
  overflow: hidden;
  margin-bottom: 14px;
}

.progress-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width .2s ease;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  min-height: 560px;
}

.preview-empty {
  min-height: 540px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 700;
}

.page-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  overflow: hidden;
}

.page-card img {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1.35;
  object-fit: contain;
  background: #f3f4f6;
  border-bottom: 1px solid var(--line);
}

.page-info {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.page-title {
  font-weight: 800;
  color: var(--text);
}

.page-meta {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.download-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  font-weight: 800;
}

.download-link:hover {
  border-color: var(--primary);
  color: var(--primary-strong);
}

.remove-page-btn {
  width: 100%;
  min-height: 36px;
  color: var(--danger);
}

.remove-page-btn:hover {
  border-color: var(--danger);
  color: var(--danger);
}

@media (max-width: 860px) {
  .tool-shell {
    display: block;
  }

  .tool-panel {
    width: auto;
    margin-top: 16px;
  }

  .preview-grid {
    min-height: 360px;
  }
}

@media (max-width: 560px) {
  .dt-topbar {
    height: auto;
    min-height: 86px;
    align-items: flex-start;
    padding-block: 12px;
  }

  .dt-brand {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
  }

  .dt-logotop {
    width: min(380px, 68vw);
  }

  .tool-row.two {
    grid-template-columns: 1fr;
  }

  .stage-head {
    align-items: flex-start;
    flex-direction: column;
  }
}
