:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-2: #f3f4f6;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --text-muted: #6b7280;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff6ff;
  --success: #16a34a;
  --danger: #dc2626;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 4px 16px rgba(0, 0, 0, .04);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0d12;
    --surface: #14171f;
    --surface-2: #1c2029;
    --border: #262b36;
    --border-strong: #353b48;
    --text: #e5e7eb;
    --text-muted: #9ca3af;
    --accent: #3b82f6;
    --accent-hover: #60a5fa;
    --accent-soft: #172036;
    --shadow: none;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; }

[hidden] { display: none !important; }

body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main { flex: 1; }

.container { width: 100%; max-width: 960px; margin: 0 auto; padding: 0 16px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- Header ---------- */
.site-header { border-bottom: 1px solid var(--border); background: var(--surface); }
.header-inner { display: flex; align-items: center; justify-content: space-between; height: 60px; gap: 12px; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; color: var(--text); text-decoration: none; }
.brand svg { color: var(--accent); }
.privacy-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--success);
  background: color-mix(in srgb, var(--success) 10%, transparent);
  padding: 4px 10px; border-radius: 999px; white-space: nowrap;
}

/* ---------- Hero ---------- */
.hero { text-align: center; padding: 48px 0 28px; }
.hero h1 { font-size: clamp(26px, 5vw, 36px); letter-spacing: -0.02em; margin: 0 0 8px; }
.hero p { color: var(--text-muted); margin: 0; font-size: 16px; }

/* ---------- Tabs ---------- */
.tabs {
  display: flex; gap: 4px; padding: 4px; margin: 0 auto 24px; width: fit-content; max-width: 100%;
  background: var(--surface-2); border-radius: 10px; overflow-x: auto;
}
.tab {
  border: 0; background: transparent; color: var(--text-muted); text-decoration: none;
  font: inherit; font-size: 14px; font-weight: 500;
  padding: 8px 16px; border-radius: 7px; cursor: pointer; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab[aria-current="page"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .08); }

/* ---------- Home: tool cards ---------- */
.tool-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.tool-card {
  display: flex; flex-direction: column; gap: 6px; padding: 22px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); color: var(--text); text-decoration: none;
  transition: border-color .15s, transform .15s;
}
.tool-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.tool-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tool-icon {
  display: grid; place-items: center; width: 44px; height: 44px; margin-bottom: 6px;
  border-radius: 10px; background: var(--accent-soft); color: var(--accent);
}
.tool-name { font-weight: 600; font-size: 17px; }
.tool-text { color: var(--text-muted); font-size: 14px; }

/* ---------- How-to and FAQ ---------- */
.content { max-width: 720px; margin: 0 auto 40px; }
.content h2 { font-size: 20px; letter-spacing: -0.01em; margin: 0 0 14px; }
.content a { color: var(--accent); }
.steps { margin: 0; padding: 0; list-style: none; counter-reset: step; display: grid; gap: 12px; }
.steps li { counter-increment: step; display: flex; gap: 12px; align-items: baseline; color: var(--text-muted); }
.steps li::before {
  content: counter(step); flex-shrink: 0; display: grid; place-items: center;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 13px;
}
.steps strong, .steps em { color: var(--text); }
.faq-item { border-bottom: 1px solid var(--border); }
.faq-item summary {
  cursor: pointer; list-style: none; padding: 14px 28px 14px 0; font-weight: 500; position: relative;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after {
  content: "+"; position: absolute; right: 4px; top: 12px; font-size: 20px; color: var(--text-muted);
}
.faq-item[open] summary::after { content: "−"; }
.faq-item p { margin: 0 0 16px; color: var(--text-muted); }
.tab:focus-visible, .btn:focus-visible, .icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Dropzone ---------- */
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 220px; padding: 32px 16px; text-align: center; cursor: pointer;
  background: var(--surface); border: 2px dashed var(--border-strong); border-radius: var(--radius);
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.dragging, .dropzone:focus-within { border-color: var(--accent); background: var(--accent-soft); }
.dropzone.dragging * { pointer-events: none; }
.dropzone.compact { min-height: 0; flex-direction: row; padding: 14px 16px; gap: 10px; }
.dropzone.compact .dz-icon { width: 22px; height: 22px; }
.dropzone.compact .dz-hint { display: none; }
.dz-icon { color: var(--accent); }
.dz-title { font-weight: 600; font-size: 16px; }
.dz-title u { color: var(--accent); text-decoration: none; }
.dz-hint { color: var(--text-muted); font-size: 14px; }

/* ---------- Workspace / toolbar ---------- */
.workspace { margin-top: 16px; }
.toolbar {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px;
  margin-bottom: 12px;
}
.toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.summary { color: var(--text-muted); font-size: 14px; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit; font-size: 14px; font-weight: 600;
  padding: 9px 18px; border-radius: 8px; border: 1px solid transparent; cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border-strong); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }

.icon-btn {
  display: inline-grid; place-items: center; width: 32px; height: 32px; flex-shrink: 0;
  border: 0; border-radius: 8px; background: transparent; color: var(--text-muted); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { color: var(--danger); }

/* ---------- Merge file list ---------- */
.file-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.file-card {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); cursor: grab; user-select: none;
}
.file-card.static { cursor: default; }
.file-card:active { cursor: grabbing; }
.grip { color: var(--text-muted); flex-shrink: 0; }
.file-order {
  width: 24px; text-align: center; font-size: 13px; font-weight: 600; color: var(--text-muted); flex-shrink: 0;
}
.file-thumb {
  width: 44px; height: 56px; flex-shrink: 0; display: grid; place-items: center;
  background: var(--surface-2); border-radius: 4px; overflow: hidden;
}
.file-thumb canvas { max-width: 100%; max-height: 100%; }
.file-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.file-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta { font-size: 13px; color: var(--text-muted); }

.sortable-ghost { opacity: .35; }
.sortable-chosen { box-shadow: 0 8px 24px rgba(0, 0, 0, .12); }

/* ---------- Page grid ---------- */
.page-grid {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px;
}
.page-card {
  position: relative; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px; box-shadow: var(--shadow);
  cursor: grab; user-select: none;
}
.page-card:active { cursor: grabbing; }
.page-thumb {
  aspect-ratio: 1; display: grid; place-items: center; overflow: hidden;
  background: var(--surface-2); border-radius: 6px;
}
.page-thumb canvas {
  max-width: 100%; max-height: 100%;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .15); transition: transform .2s ease;
}
.page-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.page-num { font-size: 13px; color: var(--text-muted); padding-left: 4px; }
.page-actions { display: flex; gap: 2px; }

/* ---------- Compress ---------- */
.levels { border: 0; padding: 0; margin: 16px 0 0; display: grid; gap: 8px; }
.levels legend { font-weight: 600; margin-bottom: 8px; padding: 0; }
.level {
  display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.level:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.level input { margin-top: 4px; accent-color: var(--accent); }
.level-body { display: flex; flex-direction: column; }
.level-body span { color: var(--text-muted); font-size: 14px; }
.tag {
  font-style: normal; font-size: 11px; font-weight: 600; color: var(--accent);
  background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  padding: 1px 6px; border-radius: 999px; margin-left: 6px; vertical-align: 2px;
}
.note { font-size: 13px; color: var(--text-muted); margin: 10px 2px 0; }
.actions-row { margin-top: 16px; display: flex; justify-content: flex-end; }

.progress { margin-top: 16px; display: flex; align-items: center; gap: 12px; }
.progress-bar { flex: 1; height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress-bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.progress-label { font-size: 13px; color: var(--text-muted); white-space: nowrap; }

.result {
  margin-top: 16px; padding: 20px; text-align: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.result-stats { display: flex; align-items: center; justify-content: center; gap: 20px; flex-wrap: wrap; color: var(--text-muted); }
.result-stats > div { display: flex; flex-direction: column; }
.stat-label { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-size: 22px; font-weight: 700; color: var(--text); }
.saved { font-weight: 700; color: var(--success); font-size: 18px; }
.saved.bad { color: var(--text-muted); }
.result-msg { color: var(--text-muted); font-size: 14px; margin: 12px 0 16px; }
.result-msg:empty { display: none; }

/* ---------- Trust section ---------- */
.trust {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 24px;
  margin: 56px 0 40px; padding-top: 32px; border-top: 1px solid var(--border);
}
.trust h2 { font-size: 15px; margin: 0 0 4px; }
.trust p { margin: 0; font-size: 14px; color: var(--text-muted); }

.site-footer { border-top: 1px solid var(--border); padding: 20px 0; font-size: 13px; color: var(--text-muted); text-align: center; }
.site-footer p { margin: 8px 0 0; }
.footer-links { display: flex; justify-content: center; flex-wrap: wrap; gap: 6px 20px; }
.footer-links a { color: var(--text); text-decoration: none; font-weight: 500; }
.footer-links a:hover { color: var(--accent); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 10px;
  background: var(--text); color: var(--bg); font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 10;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast[data-kind="error"] { background: var(--danger); color: #fff; }
.toast[data-kind="success"] { background: var(--success); color: #fff; }

@media (max-width: 560px) {
  .privacy-pill { display: none; }
  .hero { padding: 32px 0 20px; }
  .page-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar-actions .btn-primary { flex: 1; }
  .actions-row .btn { width: 100%; }
}
