:root {
  color-scheme: light;
  --bg: #f7f5f2;
  --surface: #ffffff;
  --surface-soft: #fbfaf8;
  --text: #20242b;
  --muted: #6f737b;
  --line: #e7e2dc;
  --line-strong: #d5cec6;
  --accent: #e5322d;
  --accent-dark: #c9231e;
  --accent-soft: #fff1ef;
  --danger: #c62828;
  --shadow: 0 18px 50px rgba(35, 31, 27, 0.08);
  --shadow-hover: 0 24px 60px rgba(35, 31, 27, 0.13);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 50% 180px, rgba(255,255,255,.95), transparent 420px),
    var(--bg);
  color: var(--text);
}

button, input, select { font: inherit; }
button { border: 0; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .48; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid rgba(229,50,45,.2);
  outline-offset: 2px;
}

.hidden { display: none !important; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.app-header {
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 clamp(20px, 4vw, 52px);
  border-bottom: 1px solid rgba(45, 40, 35, .08);
  background: rgba(255, 255, 255, .9);
  backdrop-filter: blur(18px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 0;
  background: transparent;
  color: var(--text);
  font-weight: 850;
  font-size: 18px;
}

.brand-icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 900;
}
.brand-icon svg { width: 18px; height: 18px; stroke-width: 2.2; }

.privacy-note { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 13px; }
.privacy-note svg { width: 16px; height: 16px; color: #4f7d58; }

.app-main {
  width: min(1160px, calc(100% - 32px));
  margin: 0 auto;
  padding: clamp(42px, 7vh, 82px) 0 120px;
}

.screen { animation: enter .22s ease-out; }
@keyframes enter { from { opacity: 0; transform: translateY(5px); } }

.picker-heading, .upload-heading {
  max-width: 720px;
  margin: 0 auto 36px;
  text-align: center;
}

.eyebrow, .section-kicker {
  display: block;
  margin-bottom: 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.picker-heading h1, .upload-heading h1, .workspace-topbar h1 {
  margin: 0;
  letter-spacing: 0;
}

.picker-heading h1, .upload-heading h1 {
  font-size: clamp(38px, 6vw, 58px);
  line-height: 1.05;
}

.picker-heading p, .upload-heading p, .workspace-topbar p {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.6;
}

.primary-tools {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.tool-card {
  min-height: 170px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: start;
  gap: 14px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .9);
  color: var(--text);
  text-align: left;
  box-shadow: 0 1px 0 rgba(35,31,27,.04);
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}

.tool-card:hover {
  transform: translateY(-3px);
  border-color: #f1b9b6;
  box-shadow: var(--shadow-hover);
}

.tool-symbol {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 900;
}
.tool-symbol svg { width: 22px; height: 22px; stroke-width: 1.9; }

.tool-card-copy { display: grid; gap: 8px; }
.tool-card-copy strong { font-size: 19px; }
.tool-card-copy small { color: var(--muted); line-height: 1.5; }
.tool-arrow { color: var(--muted); }
.tool-arrow svg { width: 19px; height: 19px; }

.secondary-tools {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.mini-tool {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,255,255,.72);
  color: var(--text);
  text-align: left;
}

.mini-tool:hover { background: #fff; border-color: var(--line-strong); }
.mini-tool > svg { width: 19px; height: 19px; color: var(--accent); flex: 0 0 auto; }
.mini-tool > span { display: grid; gap: 4px; }
.mini-tool small { color: var(--muted); font-size: 12px; }

.back-button, .text-button {
  padding: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 750;
}
.back-button:hover, .text-button:hover { color: var(--text); }
.back-button { margin-bottom: 28px; }
.danger-text { color: var(--danger); }

.upload-dropzone {
  min-height: 380px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  max-width: 760px;
  margin: 0 auto;
  padding: 48px;
  border: 2px dashed #d9d2ca;
  border-radius: 8px;
  background: rgba(255,255,255,.84);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}
.upload-dropzone.is-dragging { border-color: var(--accent); background: #fff8f7; }
.upload-dropzone:hover { border-color: var(--line-strong); background: #fff; }
.upload-dropzone:focus-visible { outline: 3px solid rgba(229,50,45,.2); outline-offset: 4px; }
.upload-dropzone strong { font-size: 24px; }
.upload-dropzone > span { color: var(--muted); }
.upload-file-icon {
  width: 68px;
  height: 68px;
  display: grid;
  place-items: center;
  margin-bottom: 10px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 900;
}
.upload-file-icon svg { width: 30px; height: 30px; stroke-width: 1.8; }

.trust-row {
  max-width: 760px;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 24px;
  margin: 22px auto 0;
  color: var(--muted);
  font-size: 12px;
}
.trust-row span { display: inline-flex; align-items: center; gap: 6px; }
.trust-row svg { width: 15px; height: 15px; color: #4f7d58; }

.primary-button, .secondary-button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 17px;
  border-radius: 8px;
  font-weight: 800;
}
.primary-button {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 12px 26px rgba(229,50,45,.22);
}
.primary-button:hover:not(:disabled) { background: var(--accent-dark); }
.secondary-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
}
.secondary-button:hover:not(:disabled) { border-color: var(--line-strong); background: var(--surface-soft); }

.workspace-screen { display: grid; gap: 18px; }
.workspace-topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 6px;
}
.workspace-topbar h1 { font-size: clamp(32px, 5vw, 48px); line-height: 1.06; }
.workspace-top-actions { display: flex; gap: 9px; flex-wrap: wrap; }

.surface {
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,255,255,.92);
  box-shadow: var(--shadow);
}

.surface-heading, .control-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}
.surface-heading strong { display: block; font-size: 17px; }
.surface-heading small { display: block; margin-top: 4px; color: var(--muted); }
.section-kicker { margin-bottom: 5px; color: #9a8d82; }
.control-title-row h2 { margin: 0; font-size: 24px; }

.doc-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.doc-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}
.doc-card.is-active { border-color: #f0aaa7; background: var(--accent-soft); }
.doc-select { display: grid; gap: 4px; padding: 0; background: transparent; color: var(--text); text-align: left; }
.doc-select strong { overflow-wrap: anywhere; }
.doc-select small { color: var(--muted); }
.doc-actions { display: flex; gap: 5px; }
.icon-button {
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
}
.icon-button:hover { color: var(--text); border-color: var(--line-strong); }

.tool-controls { display: grid; gap: 16px; }
.quick-controls { display: flex; flex-wrap: wrap; gap: 9px; align-items: center; }
.inline-field { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); }
.inline-field input { width: 64px; }

.field { display: grid; gap: 7px; max-width: 520px; }
.field > span { color: var(--muted); font-size: 13px; font-weight: 750; }
input[type="text"], input[type="number"], select {
  width: 100%;
  min-height: 42px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  outline: none;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(229,50,45,.12); }
.inline-field input[type="number"] { width: 64px; flex: 0 0 64px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }

.quality-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.quality-card { position: relative; }
.quality-card input { position: absolute; opacity: 0; }
.quality-card span {
  min-height: 90px;
  display: grid;
  align-content: center;
  gap: 4px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.quality-card small { color: var(--muted); }
.quality-card input:checked + span { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 3px rgba(229,50,45,.09); }
.notice { margin: 0; padding: 13px 14px; border-radius: 8px; background: #fff8ef; color: #74665a; font-size: 13px; line-height: 1.55; }

.split-plan { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 10px; }
.split-card { padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-soft); }
.split-card-head { display: grid; grid-template-columns: minmax(0, 1fr) minmax(140px, 220px); gap: 10px; align-items: center; }
.split-card-title { font-weight: 850; }
.split-card-meta { margin-top: 3px; color: var(--muted); font-size: 12px; }
.thumb-strip { display: flex; gap: 6px; margin-top: 10px; overflow-x: auto; }
.thumb { flex: 0 0 48px; display: grid; gap: 3px; justify-items: center; color: var(--muted); font-size: 10px; }
.thumb img, .thumb-placeholder { width: 44px; height: 58px; object-fit: contain; border: 1px solid var(--line); border-radius: 5px; background: #fff; }
.thumb-placeholder { display: grid; place-items: center; }

.selection-actions { display: flex; gap: 12px; }
.page-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.page-card { display: grid; gap: 9px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; transition: transform .14s ease, box-shadow .14s ease, border-color .14s ease; }
.page-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-hover); }
.page-card.is-selected { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(229,50,45,.1); }
.page-card.is-removed { opacity: .48; background: #fff2f1; }
.page-preview { min-height: 210px; display: grid; place-items: center; overflow: hidden; border-radius: 6px; background: #f3f0ec; }
.page-preview img { max-width: 100%; height: auto; background: #fff; box-shadow: 0 8px 22px rgba(35,31,27,.14); transform: rotate(var(--rotation,0deg)); }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.page-label { display: inline-flex; align-items: center; gap: 7px; font-weight: 800; }
.page-label input { width: 17px; height: 17px; accent-color: var(--accent); }
.page-badge { max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 4px 7px; border-radius: 999px; background: #f1eeea; color: var(--muted); font-size: 10px; }
.page-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.page-actions .icon-button { width: 100%; }
.cut-button { min-height: 36px; border-radius: 999px; background: #f4efea; color: #766b62; font-weight: 750; }
.cut-button:hover { background: var(--accent-soft); color: var(--accent); }
.cut-button.is-active { background: var(--accent); color: #fff; }

body[data-tool="split"] .page-label input,
body[data-tool="compress"] .page-label input,
body[data-tool="merge"] .page-label input,
body:not([data-tool="edit"]) .page-actions { display: none; }
body[data-tool="merge"] .pages-section,
body[data-tool="compress"] .pages-section { display: none; }

.output-section { border-color: #f2bbb8; }
.result-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; }
.result-card { display: grid; gap: 7px; padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-soft); }
.result-card strong { overflow-wrap: anywhere; }
.result-card small { color: var(--muted); }
.download-link { text-decoration: none; }

.action-dock {
  position: sticky;
  bottom: 14px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px;
  border: 1px solid rgba(45,40,35,.09);
  border-radius: 10px;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(18px);
  box-shadow: 0 18px 50px rgba(35,31,27,.14);
}
.status { display: flex; align-items: center; gap: 9px; min-width: 0; padding-left: 6px; color: var(--muted); font-size: 13px; }
.status[data-tone="error"] { color: var(--danger); }
.status[data-tone="ok"] { color: #43704b; }
.spinner { display: none; width: 17px; height: 17px; border: 2px solid rgba(229,50,45,.18); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
.status.is-busy .spinner { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }
.action-button { min-width: 150px; min-height: 48px; }

@media (max-width: 820px) {
  .privacy-note { display: none; }
  .primary-tools { grid-template-columns: 1fr; }
  .tool-card { min-height: 118px; }
  .secondary-tools { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .workspace-topbar { align-items: flex-start; flex-direction: column; }
  .form-grid, .quality-options { grid-template-columns: 1fr; }
  .split-card-head { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .app-main { width: min(100% - 20px, 1160px); padding-top: 34px; }
  .app-header { padding-inline: 14px; }
  .secondary-tools { grid-template-columns: 1fr; }
  .upload-dropzone { min-height: 330px; padding: 28px 18px; }
  .surface { padding: 16px; border-radius: 8px; }
  .page-grid { grid-template-columns: repeat(2, minmax(0,1fr)); gap: 9px; }
  .page-preview { min-height: 150px; }
  .action-dock { align-items: stretch; flex-direction: column; }
  .action-button { width: 100%; }
}
