/* Цвета – из темы Telegram (--tg-theme-*, их ставит telegram-web-app.js); вне Telegram – свои светлая и темная. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f3f5);
  --text: var(--tg-theme-text-color, #16181d);
  --muted: var(--tg-theme-hint-color, #6d7380);
  --accent: var(--tg-theme-button-color, #2f6fde);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #2f6fde);
  --danger: var(--tg-theme-destructive-text-color, #d93a3a);
  --line: color-mix(in srgb, var(--muted) 25%, transparent);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not(.tg) {
    --bg: #17191d; --bg2: #212429; --text: #eceef2; --muted: #969ca8;
    --accent: #5b8ff0; --link: #7aa5f5;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg2);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
main { max-width: 560px; margin: 0 auto; padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); }
header h1 { font-size: 22px; margin: 4px 0 4px; letter-spacing: -0.01em; }
header p { margin: 0 0 16px; }
h2 { font-size: 18px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
[hidden] { display: none !important; }

.card {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.center { text-align: center; }

.drop {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 32px 16px;
  background: var(--bg);
  border: 2px dashed color-mix(in srgb, var(--accent) 45%, transparent);
  border-radius: var(--radius);
  text-align: center;
  cursor: pointer;
}
.drop.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--bg)); }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.drop-icon {
  display: grid; place-items: center; width: 56px; height: 56px; border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent);
}
.drop-title { font-size: 17px; font-weight: 600; color: var(--accent); }

.welcome { margin: 16px 0 0; }
.welcome-open { position: relative; display: block; width: 100%; padding: 0; background: none; border-radius: var(--radius); }
.welcome-open img { width: 100%; height: auto; display: block; border-radius: var(--radius); }
.zoom-hint {
  position: absolute; right: 8px; bottom: 8px; display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: 999px; background: rgb(20 22 26 / .78); color: #fff; font-size: 13px;
}

/* просмотр «было – стало»: картинка вдвое шире окна, нужная половина – сдвигом (Было / Стало) */
body.viewing { overflow: hidden; }
.viewer {
  position: fixed; inset: 0; z-index: 10; display: flex; flex-direction: column;
  background: var(--bg2); padding-top: env(safe-area-inset-top);
}
.viewer-bar { display: flex; align-items: center; gap: 8px; padding: 10px 12px; background: var(--bg); }
.viewer-bar .seg { flex: 1; }
.viewer-close {
  flex: none; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%;
  background: var(--bg2); color: var(--text);
}
.viewer-scroll {
  flex: 1; overflow: auto; touch-action: pan-x pan-y; -webkit-overflow-scrolling: touch; cursor: grab;
}
.viewer-scroll.dragging { cursor: grabbing; }
.viewer-page { width: 100%; overflow: hidden; background: #fff; }
.viewer-page img { display: block; width: 200%; height: auto; user-select: none; -webkit-user-select: none; }
.viewer[data-side="both"] .viewer-page img { width: 100%; }
.viewer[data-side="after"] .viewer-page img { margin-left: -100%; }
.viewer-tools {
  display: flex; align-items: center; justify-content: center; gap: 16px; padding: 8px 12px 0; background: var(--bg);
}
.viewer-tools button {
  width: 44px; height: 44px; border-radius: 50%; background: var(--bg2); color: var(--text); font-size: 22px;
}
#zoom-level { min-width: 48px; text-align: center; color: var(--muted); font-size: 14px; }
.viewer-hint {
  margin: 0; padding: 6px 12px calc(10px + env(safe-area-inset-bottom)); text-align: center; background: var(--bg);
}

button { font: inherit; cursor: pointer; border: 0; }
.primary, .secondary {
  display: block; width: 100%; padding: 14px; border-radius: 12px; font-weight: 600; margin-bottom: 8px;
}
.primary { background: var(--accent); color: var(--accent-text); }
.secondary { background: var(--bg); color: var(--accent); }
.primary:disabled { opacity: .55; }
.link { background: none; color: var(--link); padding: 12px 0; display: block; margin: 4px auto 0; }

.file-card { display: flex; align-items: center; gap: 12px; }
.file-icon {
  flex: none; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 10px;
  background: #2b579a; color: #fff; font-weight: 700;
}
.file-name { font-weight: 600; overflow-wrap: anywhere; }

.row-label { font-size: 13px; color: var(--muted); margin: 0 0 6px; }
.row-label:not(:first-child) { margin-top: 14px; }
.seg { display: flex; background: var(--bg2); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button {
  flex: 1; padding: 9px 6px; border-radius: 8px; background: none; color: var(--text); font-size: 14px;
}
.seg button[aria-checked="true"] { background: var(--bg); box-shadow: 0 1px 3px rgb(0 0 0 / .12); font-weight: 600; }
.seg button:disabled { color: var(--muted); opacity: .6; }
#title-hint { margin: 6px 0 0; }
#title-hint:empty { display: none; }

.spinner {
  width: 36px; height: 36px; margin: 8px auto 14px; border-radius: 50%;
  border: 3px solid color-mix(in srgb, var(--accent) 20%, transparent); border-top-color: var(--accent);
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }
#stage { font-weight: 600; }
.bar { height: 4px; background: var(--bg2); border-radius: 2px; margin: 14px 0 10px; overflow: hidden; }
.bar div { height: 100%; width: 0; background: var(--accent); transition: width .4s ease; }

.downloads { display: flex; flex-direction: column; gap: 8px; }
.dl {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px; border-radius: 12px;
  background: var(--bg2); color: var(--text); text-align: left;
}
.dl .file-icon.pdf { background: #c9302c; }
.dl span:last-child { min-width: 0; overflow-wrap: anywhere; }
.dl small { display: block; color: var(--muted); }

.report { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; }
.report code { display: block; white-space: pre-wrap; font: 13px/1.5 ui-monospace, Consolas, monospace; color: var(--muted); }
#fail-text { margin: 0; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom));
  max-width: 528px; margin: 0 auto; padding: 12px 14px; border-radius: 12px;
  background: #1f2329; color: #fff; font-size: 14px; box-shadow: 0 4px 16px rgb(0 0 0 / .25);
}
