:root {
  --bg: #f6f7fb;
  --bg-glow: #e8eeff;
  --surface: #ffffff;
  --text: #16181d;
  --muted: #61656e;
  --line: #e3e6ee;
  --accent: #1c64f2;
  --accent-hover: #1a56d6;
  --accent-soft: #eef3ff;
  --danger: #b42318;
  --danger-soft: #fef3f2;
  --ok: #067647;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 12px 32px -12px rgba(16, 24, 40, .16);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Arabic",
          "Noto Sans Devanagari", "Noto Sans JP", "Noto Sans KR", "Noto Sans SC", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --bg-glow: #131c33;
    --surface: #141b2d;
    --text: #e9ecf3;
    --muted: #98a0b3;
    --line: #263048;
    --accent: #5b8cff;
    --accent-hover: #7aa2ff;
    --accent-soft: #1a2340;
    --danger: #ff9c92;
    --danger-soft: #331a18;
    --ok: #5ed6a0;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 16px 40px -16px rgba(0, 0, 0, .6);
  }
}

* { box-sizing: border-box; }

/* display: flex у класах нижче інакше перебиває атрибут hidden */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1100px 520px at 50% -160px, var(--bg-glow), transparent 70%),
    var(--bg);
  min-height: 100vh;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}

main { max-width: 780px; margin: 0 auto; padding: 0 20px 72px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

/* --- шапка ------------------------------------------------------------ */
.topbar {
  max-width: 780px;
  margin: 0 auto;
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: inline-flex; align-items: center; gap: 9px;
  font-size: 19px; font-weight: 600; letter-spacing: -.01em;
  color: inherit; text-decoration: none;
}
.brand b { font-weight: 700; color: var(--accent); }
.brand-mark {
  width: 26px; height: 26px; flex: none;
  fill: none; stroke: var(--accent); stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round;
}

.lang select {
  font: inherit; font-size: 14px;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 9px;
  padding: 7px 11px; cursor: pointer; max-width: 190px;
}
.lang select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* --- герой ------------------------------------------------------------ */
.hero { text-align: center; padding: 28px 0 30px; }
.hero h1 {
  margin: 0 0 12px;
  font-size: clamp(28px, 6vw, 40px);
  line-height: 1.15; letter-spacing: -.022em; font-weight: 700;
}
.lede { margin: 0 auto; max-width: 54ch; color: var(--muted); font-size: 16.5px; }

/* --- картка інструмента ----------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}

.dropzone {
  border: 2px dashed var(--line);
  border-radius: 12px;
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone:focus-visible, .dropzone.over {
  border-color: var(--accent);
  background: var(--accent-soft);
  outline: none;
}
.drop-icon {
  width: 34px; height: 34px; margin-bottom: 8px;
  fill: none; stroke: var(--accent); stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}
.drop-title { margin: 0; font-weight: 600; font-size: 17px; }
.drop-hint { margin: 4px 0 0; color: var(--muted); font-size: 14.5px; }

/* обраний файл */
.file-row {
  display: flex; align-items: center; gap: 13px;
  padding: 14px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--accent-soft);
}
.file-icon {
  width: 26px; height: 26px; flex: none;
  fill: none; stroke: var(--accent); stroke-width: 1.6;
  stroke-linecap: round; stroke-linejoin: round;
}
.file-meta { min-width: 0; flex: 1; }
.file-name {
  margin: 0; font-weight: 600; font-size: 15px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.file-info { margin: 1px 0 0; color: var(--muted); font-size: 14px; }

/* параметри */
.controls {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px;
  margin-top: 18px;
}
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field.grow { flex: 1; min-width: 190px; }
.field label { font-size: 13.5px; font-weight: 500; color: var(--muted); }
.field input {
  font: inherit; font-size: 15px; color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; width: 100%;
}
/* на всю ширину поля, інакше вузький інпут «відклеюється» від широкої підписи */
#pages-input { width: 100%; min-width: 108px; }
.field input:focus-visible { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }

button { font: inherit; cursor: pointer; border-radius: 10px; }
.primary {
  background: var(--accent); color: #fff; border: 1px solid transparent;
  padding: 11px 22px; font-size: 15px; font-weight: 600;
  transition: background .15s;
}
.primary:hover { background: var(--accent-hover); }
.primary:disabled { opacity: .55; cursor: default; }
.ghost {
  background: transparent; color: var(--accent);
  border: 1px solid var(--line); padding: 8px 14px; font-size: 14px; font-weight: 500;
}
.ghost:hover { border-color: var(--accent); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* помилка */
.alert {
  margin: 16px 0 0; padding: 11px 14px;
  background: var(--danger-soft); color: var(--danger);
  border: 1px solid currentColor; border-radius: 10px; font-size: 14.5px;
}

/* прогрес */
.progress-wrap { margin-top: 18px; }
.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.bar { height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .18s; }
.progress-text { margin: 8px 0 0; font-size: 14px; color: var(--muted); }

/* результати */
.results { margin-top: 22px; border-top: 1px solid var(--line); padding-top: 20px; }
.results-head {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px; margin-bottom: 14px;
}
.results-head h2 { margin: 0; font-size: 17px; font-weight: 600; }

/* minmax(0,1fr) обов'язковий: у grid-елементів min-width: auto, і довге ім'я
   файлу розпирає колонку за межі картки замість того, щоб обрізатись. */
.parts {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px;
}
.parts li {
  display: flex; align-items: center; gap: 12px; min-width: 0;
  padding: 11px 14px; border: 1px solid var(--line); border-radius: 10px;
}
/* Ім'я = довгий префікс (стискається) + хвіст із номером частини (ніколи не
   зникає). Інакше в усіх рядках лишалось би однакове обрізане начало. */
.part-name { display: flex; flex: 1 1 auto; min-width: 0; font-size: 14.5px; }
.part-base { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.part-tail { flex: none; white-space: nowrap; }
.part-meta { flex: none; color: var(--muted); font-size: 13.5px; white-space: nowrap; }
.parts a {
  flex: none; color: var(--accent); text-decoration: none; font-weight: 600;
  font-size: 14px; white-space: nowrap;
}
.parts a:hover { text-decoration: underline; }

/* --- нижні блоки ------------------------------------------------------ */
.note {
  display: flex; gap: 14px; align-items: flex-start;
  margin-top: 30px; padding: 18px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface);
}
.note-icon {
  width: 26px; height: 26px; flex: none; margin-top: 2px;
  fill: none; stroke: var(--ok); stroke-width: 1.6;
  stroke-linecap: round; stroke-linejoin: round;
}
.note h2 { margin: 0 0 4px; font-size: 16px; font-weight: 600; }
.note p { margin: 0; color: var(--muted); font-size: 15px; }

.steps, .faq { margin-top: 34px; }
.steps h2, .faq h2 { font-size: 19px; font-weight: 600; margin: 0 0 14px; }
.steps ol { margin: 0; padding-inline-start: 1.25em; color: var(--muted); }
.steps li { margin-bottom: 7px; }

.faq details {
  border: 1px solid var(--line); border-radius: 11px;
  padding: 13px 16px; margin-bottom: 9px; background: var(--surface);
}
.faq summary { cursor: pointer; font-weight: 600; font-size: 15.5px; }
.faq summary::-webkit-details-marker { display: none; }
.faq summary::marker { content: ''; }
.faq summary::after {
  content: '+'; float: inline-end; color: var(--accent);
  font-weight: 400; font-size: 19px; line-height: 1.2;
}
.faq details[open] summary::after { content: '−'; }
.faq details p { margin: 9px 0 0; color: var(--muted); font-size: 15px; }

/* --- банер згоди ------------------------------------------------------ */
.cookie-bar {
  position: fixed;
  inset-inline: 12px;                 /* логічні відступи — самі дзеркаляться в RTL */
  bottom: 12px;
  z-index: 20;
  max-width: 720px;
  margin-inline: auto;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.cookie-text {
  margin: 0; flex: 1 1 260px; min-width: 0;
  font-size: 13.5px; line-height: 1.45; color: var(--muted);
}
.cookie-actions { display: flex; gap: 8px; flex: none; }
.cookie-actions button { padding: 8px 16px; font-size: 14px; }

@media (max-width: 520px) {
  .cookie-bar { gap: 10px; padding: 12px; }
  .cookie-actions { width: 100%; }
  .cookie-actions button { flex: 1; }
}

footer {
  border-top: 1px solid var(--line);
  padding: 24px 20px 34px; text-align: center;
  color: var(--muted); font-size: 14px;
}
footer p { margin: 0 0 4px; }
.copy { opacity: .7; }

@media (max-width: 520px) {
  .card { padding: 16px; }
  .controls { gap: 10px; }
  .controls .primary { width: 100%; }
  .results-head .primary { width: 100%; }
  .parts li { flex-wrap: wrap; }
}
