:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #efede7;
  --text: #1c1d20;
  --muted: #6a6b70;
  --line: #dfdcd3;
  --accent: #1f5f4a;
  --accent-text: #ffffff;
  --accent-soft: #dcebe4;
  --warn: #9a5a00;
  --warn-soft: #f6e8d2;
  --err: #a1262a;
  --radius: 12px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16171a;
    --surface: #1f2024;
    --surface-2: #2a2b30;
    --text: #ececea;
    --muted: #9c9da3;
    --line: #34353b;
    --accent: #6cc4a1;
    --accent-text: #0f1a15;
    --accent-soft: #23362f;
    --warn: #f0b860;
    --warn-soft: #3a2e1b;
    --err: #ff8a8a;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
[hidden] { display: none !important; }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 920px; margin: 0 auto; padding: 20px 16px 8px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 19px; margin: 0; letter-spacing: -0.01em; }
.top-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

main { max-width: 920px; margin: 0 auto; padding: 8px 16px 24px; display: grid; gap: 16px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h2 { font-size: 15px; margin: 0; }
.muted { color: var(--muted); }

.drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  gap: 6px; padding: 30px 16px; cursor: pointer;
  border: 1.5px dashed var(--line); border-radius: 10px; background: var(--surface-2);
  transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop.has-file { border-style: solid; }
.drop-icon { width: 34px; height: 34px; fill: none; stroke: var(--accent); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.drop-title { font-weight: 600; word-break: break-word; }
.drop-title u { text-decoration-color: var(--accent); text-underline-offset: 3px; }
.drop-sub { color: var(--muted); font-size: 13px; }

.settings { display: grid; gap: 14px; margin: 18px 0 4px; }
.field { border: 0; padding: 0; margin: 0; min-width: 0; }
.field legend { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 6px; padding: 0; }
.seg { display: inline-flex; flex-wrap: wrap; background: var(--surface-2); border-radius: 9px; padding: 3px; gap: 2px; max-width: 100%; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span { display: block; padding: 6px 12px; border-radius: 7px; font-size: 14px; color: var(--muted); user-select: none; }
.seg input:checked + span { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
.seg input:disabled + span { opacity: .55; }

.check { display: flex; align-items: flex-start; gap: 8px; font-size: 14px; cursor: pointer; }
.check input { margin: 3px 0 0; accent-color: var(--accent); }
.check em { color: var(--muted); font-style: normal; }
.check.small { font-size: 13px; align-items: center; }
.check.small input { margin: 0; }

.actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.status { color: var(--muted); font-size: 14px; }
.status.err { color: var(--err); }

.btn {
  font: inherit; font-weight: 600; font-size: 14px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: 9px 16px; border-radius: 9px; cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.small { padding: 6px 11px; font-size: 13px; }

.pill { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.pill.ok { background: var(--accent-soft); color: var(--accent); }

.progress { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 14px; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width .25s; }

.pages { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 10px; }
.pages li { display: grid; gap: 4px; font-size: 12px; }
.thumb {
  aspect-ratio: 1 / 1.414; background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.thumb canvas { max-width: 100%; max-height: 100%; display: block; background: #fff; }
.pages .meta { display: flex; justify-content: space-between; gap: 4px; }
.badge { font-weight: 600; color: var(--muted); }
.badge.ok { color: var(--accent); }
.badge.warn { color: var(--warn); }
.badge.busy { color: var(--text); }

.result-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
textarea {
  width: 100%; min-height: 340px; resize: vertical;
  font: 13px/1.55 var(--mono); color: var(--text);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 12px;
}
.pdf-out { margin: 0; color: var(--muted); }

footer { max-width: 920px; margin: 0 auto; padding: 8px 16px 32px; font-size: 13px; color: var(--muted); display: grid; gap: 2px; }

@media (max-width: 520px) {
  .card { padding: 14px; }
  .seg span { padding: 6px 10px; }
  .card-head { align-items: flex-start; }
}
