/* Deskew — browser-only PDF deskew. Calm, tool-like. Light & dark themes. */

/* ------------------------------------------------------------------ */
/* Theme palette                                                       */
/* ------------------------------------------------------------------ */
/* Three modes, driven by <html data-theme="auto|light|dark">:          */
/*  · dark  (default)                                                  */
/*  · light                                                            */
/*  · auto → follows prefers-color-scheme                              */

:root,
:root[data-theme="dark"] {
  --bg: #0b1220;
  --panel: #111a2c;
  --panel-2: #17223a;
  --border: #223050;
  --border-soft: #1a2742;
  --text: #e6edf7;
  --muted: #8ba0bf;
  --accent: #38bdf8;
  --accent-soft: rgba(56, 189, 248, 0.12);
  --accent-border: rgba(56, 189, 248, 0.4);
  --good: #34d399;
  --good-border: rgba(52, 211, 153, 0.4);
  --warn: #fbbf24;
  --warn-border: rgba(251, 191, 36, 0.4);
  --bad: #f87171;
  --bad-border: rgba(248, 113, 113, 0.4);
  --fixed-text: #a7f3d0;
  --fixed-bg: rgba(52, 211, 153, 0.08);
  --fixed-border: rgba(52, 211, 153, 0.35);
  --tilt-text: #fbbf24;
  --tilt-bg: rgba(251, 191, 36, 0.07);
  --tilt-border: rgba(251, 191, 36, 0.35);
  --glow-a: rgba(56, 189, 248, 0.07);
  --glow-b: rgba(52, 211, 153, 0.05);
  --backdrop: rgba(4, 9, 18, 0.75);
  --logo-bg: #101a2e;
  --logo-ink: #e6edf7;
  --logo-dim: #475569;
  --primary-1: #38bdf8;
  --primary-2: #0ea5e9;
  --primary-text: #06202e;
  --meta-theme: #0b1220;
  --radius: 14px;
  --mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", Menlo, Consolas, monospace;
}

:root[data-theme="light"] {
  --bg: #f2f5fa;
  --panel: #ffffff;
  --panel-2: #eaeff7;
  --border: #c9d4e5;
  --border-soft: #dde4ef;
  --text: #1a2740;
  --muted: #5c6c86;
  --accent: #0284c7;
  --accent-soft: rgba(2, 132, 199, 0.09);
  --accent-border: rgba(2, 132, 199, 0.35);
  --good: #0a9e6f;
  --good-border: rgba(10, 158, 111, 0.35);
  --warn: #b45309;
  --warn-border: rgba(180, 83, 9, 0.35);
  --bad: #dc2626;
  --bad-border: rgba(220, 38, 38, 0.35);
  --fixed-text: #0b7a55;
  --fixed-bg: rgba(10, 158, 111, 0.08);
  --fixed-border: rgba(10, 158, 111, 0.3);
  --tilt-text: #9a4a06;
  --tilt-bg: rgba(180, 83, 9, 0.07);
  --tilt-border: rgba(180, 83, 9, 0.3);
  --glow-a: rgba(2, 132, 199, 0.05);
  --glow-b: rgba(10, 158, 111, 0.04);
  --backdrop: rgba(23, 32, 53, 0.42);
  --logo-bg: #e7f0fa;
  --logo-ink: #1a2740;
  --logo-dim: #8ba0bf;
  --primary-1: #38bdf8;
  --primary-2: #0ea5e9;
  --primary-text: #06202e;
  --meta-theme: #f2f5fa;
}

/* Auto mode: light when the OS prefers light (dark vars above apply otherwise) */
@media (prefers-color-scheme: light) {
  :root[data-theme="auto"] {
    --bg: #f2f5fa;
    --panel: #ffffff;
    --panel-2: #eaeff7;
    --border: #c9d4e5;
    --border-soft: #dde4ef;
    --text: #1a2740;
    --muted: #5c6c86;
    --accent: #0284c7;
    --accent-soft: rgba(2, 132, 199, 0.09);
    --accent-border: rgba(2, 132, 199, 0.35);
    --good: #0a9e6f;
    --good-border: rgba(10, 158, 111, 0.35);
    --warn: #b45309;
    --warn-border: rgba(180, 83, 9, 0.35);
    --bad: #dc2626;
    --bad-border: rgba(220, 38, 38, 0.35);
    --fixed-text: #0b7a55;
    --fixed-bg: rgba(10, 158, 111, 0.08);
    --fixed-border: rgba(10, 158, 111, 0.3);
    --tilt-text: #9a4a06;
    --tilt-bg: rgba(180, 83, 9, 0.07);
    --tilt-border: rgba(180, 83, 9, 0.3);
    --glow-a: rgba(2, 132, 199, 0.05);
    --glow-b: rgba(10, 158, 111, 0.04);
    --backdrop: rgba(23, 32, 53, 0.42);
    --logo-bg: #e7f0fa;
    --logo-ink: #1a2740;
    --logo-dim: #8ba0bf;
    --primary-1: #38bdf8;
    --primary-2: #0ea5e9;
    --primary-text: #06202e;
    --meta-theme: #f2f5fa;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background:
    radial-gradient(1100px 500px at 85% -10%, var(--glow-a), transparent 60%),
    radial-gradient(900px 420px at -10% 110%, var(--glow-b), transparent 60%),
    var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
}

body { display: flex; flex-direction: column; }

/* ---------- header ---------- */

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 22px clamp(16px, 4vw, 48px) 6px;
}

.brand { display: flex; align-items: center; gap: 14px; }
.logo { width: 44px; height: 44px; flex: none; }
.brand h1 { margin: 0; font-size: 26px; letter-spacing: 0.2px; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }

.badges { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.pill {
  font-size: 12.5px;
  color: var(--muted);
  border: 1px solid var(--border);
  background: var(--panel);
  padding: 5px 11px;
  border-radius: 999px;
  white-space: nowrap;
}
.pill-accent { color: var(--accent); border-color: var(--accent-border); background: var(--accent-soft); }

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font: inherit;
  font-size: 12.5px;
  color: var(--muted);
  border: 1px solid var(--border);
  background: var(--panel);
  padding: 5px 12px;
  border-radius: 999px;
  white-space: nowrap;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.theme-toggle:hover { color: var(--accent); border-color: var(--accent); }
.theme-toggle #btnThemeIcon { font-size: 13px; line-height: 1; }

/* ---------- layout ---------- */

main { flex: 1; width: 100%; max-width: 980px; margin: 0 auto; padding: 18px clamp(16px, 4vw, 48px) 24px; }

/* ---------- dropzone ---------- */

#dropzone {
  margin-top: 10px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 44px 24px 34px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.18s ease, background 0.18s ease, transform 0.12s ease;
  outline: none;
}
#dropzone:hover, #dropzone:focus-visible { border-color: var(--accent); background: var(--panel-2); }
#dropzone.drag {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: scale(1.01);
}
.dz-icon { width: 56px; height: 56px; }
#dropzone h2 { margin: 14px 0 4px; font-size: 21px; }
#dropzone p { margin: 0; color: var(--muted); }
.link { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }

.demo-btn {
  margin-top: 18px;
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.demo-btn:hover { color: var(--accent); border-color: var(--accent); }

/* ---------- settings ---------- */

.settings-wrap { margin-top: 14px; }
#settings {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--panel);
}
#settings summary {
  cursor: pointer;
  padding: 13px 18px;
  color: var(--muted);
  font-size: 14.5px;
  user-select: none;
  list-style: none;
}
#settings summary::before { content: "▸ "; }
#settings[open] summary::before { content: "▾ "; }
#settings summary:hover { color: var(--text); }

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  padding: 6px 18px 4px;
}
.settings-grid label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13.5px;
  color: var(--muted);
}
.settings-grid select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  font-size: 14px;
}
.settings-note { padding: 10px 18px 16px; margin: 0; color: var(--muted); font-size: 13px; }
.settings-note em { color: var(--text); font-style: normal; }

/* Output-mode dependent controls */
#settings:not(.mode-custom) label[data-mode="custom"] { display: none; }
#settings.mode-custom label[data-mode="match"] { display: none; }

.check-label {
  flex-direction: row !important;
  align-items: center;
  gap: 9px !important;
  min-height: 38px;
  cursor: pointer;
}
.check-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}
.check-label span { padding-top: 1px; }

.demo-buttons { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }

/* codec badge inside page chips */
.page-chip .codec {
  opacity: .75;
  font-size: 11px;
  margin-left: 4px;
}

/* ---------- file cards ---------- */

#files { display: flex; flex-direction: column; gap: 14px; margin-top: 14px; }

.card {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 16px 18px;
  animation: rise 0.25s ease;
}
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.card-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.card-name { font-weight: 600; word-break: break-all; }
.card-size { color: var(--muted); font-size: 13px; }

.status {
  margin-left: auto;
  font-size: 12.5px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
}
.status.processing { color: var(--accent); border-color: var(--accent-border); }
.status.done { color: var(--good); border-color: var(--good-border); }
.status.error { color: var(--bad); border-color: var(--bad-border); }
/* "no action needed" — a good outcome, but visually quiet: dashed pill
   so it reads as "nothing happened here (and that's fine)". */
.status.skipped { color: var(--good); border-color: var(--good-border); border-style: dashed; }

.progress {
  margin-top: 12px;
  height: 6px;
  border-radius: 999px;
  background: var(--panel-2);
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--good));
  transition: width 0.25s ease;
}

.card-note { margin: 10px 0 0; color: var(--muted); font-size: 13.5px; }
.card-note.err { color: var(--bad); }

.pages { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 6px; }
.page-chip {
  font-family: var(--mono);
  font-size: 12px;
  padding: 4px 9px;
  border-radius: 7px;
  border: 1px solid var(--border-soft);
  background: var(--panel-2);
  color: var(--muted);
  cursor: pointer;
  transition: border-color .15s, transform .1s;
}
.page-chip:hover { border-color: var(--accent); transform: translateY(-1px); }
.page-chip.fixed { color: var(--fixed-text); border-color: var(--fixed-border); background: var(--fixed-bg); }
.page-chip.big-tilt { color: var(--tilt-text); border-color: var(--tilt-border); background: var(--tilt-bg); }
/* tilt beyond the selected search range — warning family, not corrected */
.page-chip.range { color: var(--tilt-text); border-color: var(--tilt-border); background: var(--tilt-bg); border-style: dashed; }

.card-actions { margin-top: 14px; display: flex; gap: 10px; flex-wrap: wrap; }
.card-actions .stats { margin-right: auto; color: var(--muted); font-size: 13.5px; align-self: center; }
.card-actions .stats b { color: var(--good); font-weight: 600; }

/* ---------- buttons ---------- */

button { font: inherit; }
.primary {
  background: linear-gradient(180deg, var(--primary-1), var(--primary-2));
  color: var(--primary-text);
  border: none;
  border-radius: 10px;
  font-weight: 700;
  padding: 10px 18px;
  cursor: pointer;
  transition: filter .15s, transform .1s;
}
.primary:hover { filter: brightness(1.07); }
.primary:active { transform: translateY(1px); }
.primary:disabled { filter: grayscale(0.6) brightness(0.8); cursor: default; }

.ghost {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 10px;
  padding: 10px 16px;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.ghost:hover { color: var(--text); border-color: var(--accent); }

#toolbar {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  justify-content: flex-end;
}

a.download-link { text-decoration: none; display: inline-block; }

/* ---------- footer ---------- */

footer {
  border-top: 1px solid var(--border-soft);
  padding: 18px clamp(16px, 4vw, 48px) 26px;
  max-width: 980px;
  margin: 0 auto;
  width: 100%;
}
.selftest { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.selftest-out { font-family: var(--mono); font-size: 13px; color: var(--muted); }
.selftest-out.ok { color: var(--good); }
.selftest-out.fail { color: var(--bad); }
.tech-note { color: var(--muted); font-size: 12.5px; margin: 14px 0 0; }
.tech-note a { color: var(--accent); }

/* ---------- modal ---------- */

.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; }
.modal[hidden], .toast[hidden] { display: none !important; }
.modal-backdrop { position: absolute; inset: 0; background: var(--backdrop); backdrop-filter: blur(3px); }
.modal-card {
  position: relative;
  max-width: min(94vw, 900px);
  max-height: 92vh;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
}
.modal-close {
  position: absolute; top: 12px; right: 12px;
  background: var(--panel-2); color: var(--muted);
  border: 1px solid var(--border); border-radius: 8px;
  width: 32px; height: 32px; cursor: pointer;
}
.modal-close:hover { color: var(--text); }
.modal-card h3 { margin: 2px 0 4px; }
.modal-meta { color: var(--muted); font-family: var(--mono); font-size: 13px; margin-bottom: 14px; }
.modal-images { display: flex; gap: 14px; flex-wrap: wrap; }
.modal-images figure { margin: 0; flex: 1 1 320px; }
.modal-images figcaption {
  color: var(--muted); font-size: 12.5px; text-transform: uppercase; letter-spacing: .08em;
  margin-bottom: 6px;
}
.modal-images img {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border-soft);
  background: #fff;
  display: block;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 60;
  animation: rise 0.2s ease;
  max-width: 90vw;
}

@media (max-width: 640px) {
  .card-actions .stats { width: 100%; order: 5; }
  .modal-images figure { flex-basis: 100%; }
}
