:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --line: #e6e6eb;
  --text: #14181f;
  --muted: #8a8a8e;
  --accent: #cb11ab;
  --accent-2: #7b2ff7;
  --ok: #12805c;
  --warn: #a86400;
  --err: #d0342c;
  --fill: #f5f5f7;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(15, 20, 30, 0.02), 0 4px 14px rgba(15, 20, 30, 0.022);
}

* { box-sizing: border-box; }

/* [hidden] должен побеждать любые display из правил ниже */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "Segoe UI Variable Text", "Segoe UI", Inter, system-ui, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
}

.wrap { max-width: 940px; margin: 0 auto; padding: 0 16px; }

.top {
  background: linear-gradient(120deg, var(--accent-2), var(--accent));
  color: #fff;
  padding: 14px 0;
}
.top-inner { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.top-text { text-align: right; }
.brand { display: flex; align-items: center; gap: 9px; flex: 0 0 auto; }
.brand-mark { width: 24px; height: 24px; flex: 0 0 auto; }
.brand-name { font-size: 18px; font-weight: 700; letter-spacing: 0.06em; line-height: 1; white-space: nowrap; }
.brand-sub {
  margin-left: 7px; padding: 3px 7px; border-radius: 6px;
  background: rgba(255, 255, 255, 0.18); font-size: 12px; font-weight: 600; letter-spacing: 0.1em;
  vertical-align: 2px;
}

.top h1 { margin: 0; font-size: 15px; line-height: 1.3; font-weight: 600; letter-spacing: -0.01em; }
.top .sub { margin: 2px 0 0; opacity: 0.88; font-size: 12.5px; line-height: 1.3; }

main { padding-bottom: 72px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 36px;
  margin: 20px 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.card h2 { font-size: 20px; margin: 0; font-weight: 650; letter-spacing: -0.02em; }
.card h3 {
  font-size: 13px; margin: 26px 0 10px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600;
}

.engine { font-size: 12px; color: var(--muted); margin: 18px 0 0; }
.engine.err { color: var(--err); }

/* --- кнопки --- */
.btn {
  appearance: none;
  border: 0;
  background: var(--fill);
  color: var(--text);
  border-radius: 13px;
  padding: 13px 18px;
  font-size: 16px;
  font-family: inherit;
  font-weight: 500;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: background 0.15s, transform 0.06s, opacity 0.15s;
}
.btn:hover { background: #ebebef; }
.btn:active { transform: scale(0.985); }
.btn-primary { background: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { background: #b30f96; }
.btn-small { padding: 9px 14px; font-size: 14px; border-radius: 11px; }
.btn-wide { width: 100%; margin-top: 14px; }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--fill); }
.btn[disabled] { opacity: 0.4; cursor: default; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

/*
 * Иконки кнопок живут в CSS, а не в тексте разметки: парсер Яндекса ломает
 * четырёхбайтовые эмодзи и показывал в проиндексированном тексте «ð••·».
 * Генерируемое содержимое в индекс не попадает, а пользователь видит то же самое.
 */
#btn-scan::before { content: "📷 "; }
#btn-file::before { content: "🖼 "; }
#btn-manual::before { content: "⌨️ "; }
#btn-torch::before { content: "🔦 "; }
#btn-switch::before { content: "🔄 "; }
#btn-shot::before { content: "📸 "; }
#btn-print::before { content: "🖨 "; }
#btn-download::before { content: "⬇ "; }
#btn-stop::before { content: "✕ "; }
.btn-row + .btn-row, .preview-row + .btn-row { margin-top: 16px; }

/* --- камера --- */
.camera { margin-top: 18px; }
.video-box { position: relative; background: #000; border-radius: 16px; overflow: hidden; aspect-ratio: 4 / 3; }
video { width: 100%; height: 100%; object-fit: cover; display: block; }
video.mirror { transform: scaleX(-1); }
.roi {
  position: absolute;
  inset: 50% 50%;
  width: min(62%, 62vh);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.roi span { position: absolute; width: 28px; height: 28px; border: 3px solid rgba(255,255,255,0.95); }
.roi span:nth-child(1) { top: 0; left: 0; border-right: 0; border-bottom: 0; border-radius: 10px 0 0 0; }
.roi span:nth-child(2) { top: 0; right: 0; border-left: 0; border-bottom: 0; border-radius: 0 10px 0 0; }
.roi span:nth-child(3) { bottom: 0; left: 0; border-right: 0; border-top: 0; border-radius: 0 0 0 10px; }
.roi span:nth-child(4) { bottom: 0; right: 0; border-left: 0; border-top: 0; border-radius: 0 0 10px 0; }
.cam-close {
  position: absolute; top: 12px; right: 12px; z-index: 2;
  border: 0; border-radius: 999px; cursor: pointer;
  background: var(--accent); color: #fff;
  font-family: inherit; font-size: 14px; font-weight: 600; letter-spacing: -0.01em;
  padding: 9px 16px;
  box-shadow: 0 3px 14px rgba(0, 0, 0, 0.4);
  transition: background 0.15s, transform 0.06s;
}
.cam-close:hover { background: #b30f96; }
.cam-close:active { transform: scale(0.96); }

.hint {
  position: absolute; left: 0; right: 0; bottom: 14px;
  text-align: center; color: #fff; font-size: 14px;
  text-shadow: 0 1px 5px rgba(0,0,0,0.85);
}
.cam-controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 14px; }
.zoom { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.zoom input { width: 120px; }

/* --- поля ввода --- */
.manual { margin-top: 18px; }
.field { display: block; }
.field > span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 8px; }
textarea, input[type=text], input[type=number], select {
  width: 100%;
  font-family: inherit;
  font-size: 16px;
  border: 0;
  background: var(--fill);
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--text);
  outline: none;
  transition: box-shadow 0.15s;
}
textarea:focus, input:focus, select:focus { box-shadow: 0 0 0 2px var(--accent); }
textarea { font-family: ui-monospace, "SF Mono", "Consolas", monospace; font-size: 14px; resize: vertical; }
.field-inline { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.field-inline input, .field-inline select { width: auto; min-width: 84px; }
.chk { display: inline-flex; align-items: center; gap: 8px; font-size: 15px; color: var(--text); cursor: pointer; }
.chk input { accent-color: var(--accent); width: 18px; height: 18px; cursor: pointer; }
.scanner-probe { font-size: 14px; font-weight: 600; }
.scanner-probe.ok { color: var(--ok); }
.scanner-probe.bad { color: var(--err); }

.tip, .hint-text {
  font-size: 13.5px; color: var(--muted); line-height: 1.5;
  background: var(--fill); padding: 12px 14px; border-radius: 12px; margin: 14px 0 0;
}
.hint-text b { color: var(--text); font-weight: 600; }

/* --- статус / бейджи --- */
.status { margin-top: 16px; font-size: 15px; }
.badge { font-size: 12.5px; font-weight: 600; padding: 5px 12px; border-radius: 999px; white-space: nowrap; }
.badge.ok { background: #e3f6ee; color: var(--ok); }
.badge.warn { background: #fdf1e0; color: var(--warn); }
.badge.err { background: #fdeceb; color: var(--err); }

.msg { border-radius: 12px; padding: 12px 14px; margin: 8px 0; font-size: 14px; line-height: 1.45; }
.msg.warn { background: #fdf1e0; color: #7a4a00; }
.msg.err { background: #fdeceb; color: #8c1c1c; }
.msg.info { background: #eef2fb; color: #2c4a7c; }

/* --- результат --- */
.code-hero { margin-top: 18px; }
.hero-note { font-size: 13.5px; color: var(--muted); margin: 12px 0 0; }

.quick { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-top: 22px; }
.kv-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.kv { background: var(--fill); border-radius: 14px; padding: 14px 16px; }
.kv span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.kv b { font-size: 16px; font-weight: 600; word-break: break-all; }
.mono { font-family: ui-monospace, "SF Mono", "Consolas", monospace; }

.code {
  font-family: ui-monospace, "SF Mono", "Consolas", monospace;
  font-size: 15px;
  background: var(--fill);
  border-radius: 14px;
  padding: 16px;
  word-break: break-all;
  line-height: 1.65;
  user-select: all;
}
.code.small { font-size: 13px; padding: 12px; margin-top: 10px; }

/*
 * Символ GS остаётся в тексте (чтобы выделение мышью копировало настоящий код),
 * но глиф не рисуется — вместо «квадратика» просто небольшой отступ.
 */
.gs-hidden { font-size: 0; padding-right: 0.34em; }

.gs-chip {
  display: inline-block; background: var(--accent); color: #fff; border-radius: 6px;
  font-size: 10px; font-weight: 700; padding: 2px 6px; margin: 0 4px; vertical-align: middle;
  font-family: inherit; letter-spacing: 0.03em;
}
.ai-chip { color: var(--accent-2); font-weight: 700; }

/* --- «подробнее» --- */
.more { margin-top: 22px; }
.more > summary {
  cursor: pointer; list-style: none; padding: 14px 0 12px; user-select: none;
}
.more > summary::-webkit-details-marker { display: none; }
.more-title {
  font-size: 16px; font-weight: 600; color: var(--accent);
  text-decoration: underline dashed; text-decoration-thickness: 1px; text-underline-offset: 5px;
}
.more-sub { display: block; font-size: 13px; color: var(--muted); margin-top: 6px; }

/* Шеврон рисуем бордерами — виден в любом шрифте и в любой теме */
.chevron, .more-title::after, .faq > summary::after {
  content: "";
  display: inline-block;
  width: 0.42em; height: 0.42em;
  margin-left: 0.55em;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translateY(-0.15em) rotate(45deg);
  transition: transform 0.18s ease;
}
.more[open] .more-title::after { transform: translateY(0.1em) rotate(-135deg); }

.more-body { padding-top: 8px; }

.struct-note { font-size: 13.5px; color: var(--muted); line-height: 1.55; margin: 0 0 12px; }
.struct-note b { color: var(--text); font-weight: 600; }

/* --- гармошка вопрос-ответ --- */
.faq { border-bottom: 1px solid var(--line); }
.faq:first-of-type { border-top: 1px solid var(--line); }
.faq > summary {
  cursor: pointer; list-style: none; user-select: none;
  padding: 15px 0; font-size: 16px; font-weight: 550; letter-spacing: -0.01em;
  display: flex; align-items: baseline; justify-content: space-between; gap: 14px;
}
.faq > summary::-webkit-details-marker { display: none; }
/* Заголовок внутри summary нужен поисковику; на вид он не должен отличаться от текста. */
summary > h2, summary > h3 {
  display: inline; margin: 0; padding: 0;
  font-size: inherit; font-weight: inherit; letter-spacing: inherit; color: inherit; text-transform: none;
}
.faq > summary:hover { color: var(--accent); }
.faq > summary::after { flex: 0 0 auto; margin-left: 0; align-self: center; color: var(--muted); }
.faq[open] > summary { color: var(--accent); }
.faq[open] > summary::after { transform: translateY(0.1em) rotate(-135deg); }
.faq > p { margin: 0 0 18px; font-size: 15px; color: var(--muted); line-height: 1.6; }
.faq > p b { color: var(--text); font-weight: 600; }

/* Разделы статьи в той же гармошке, но с обычным текстом внутри */
.faq.section > summary { font-size: 17px; font-weight: 600; }
.faq-body { padding-bottom: 18px; }
.faq-body p { margin: 0 0 12px; font-size: 15px; line-height: 1.6; }
.faq-body p.muted { font-size: 13.5px; }
.faq-body ul, .faq-body ol { margin: 0 0 12px; padding-left: 22px; font-size: 15px; }
.faq-body li { margin-bottom: 7px; }
.faq-body .table-wrap { margin: 0 0 14px; }
.faq-body blockquote { margin: 0 0 14px; }

.alt { padding: 18px 0; border-top: 1px solid var(--line); }
.alt:first-of-type { border-top: 0; padding-top: 6px; }
.alt-title { display: block; font-size: 15.5px; font-weight: 600; letter-spacing: -0.01em; }
.alt-sub { display: block; font-size: 13px; color: var(--muted); margin-top: 3px; }
.alt p { margin: 8px 0 0; font-size: 13.5px; color: var(--muted); line-height: 1.5; }
.alt code { font-family: ui-monospace, "SF Mono", monospace; font-size: 12.5px; background: var(--fill); padding: 1px 5px; border-radius: 5px; }
.alt-value { display: flex; gap: 10px; align-items: stretch; margin-top: 10px; }
.alt-value .code { flex: 1; min-width: 0; margin-top: 0; }
.alt-value .btn { flex: 0 0 auto; align-self: flex-start; }

.table-wrap { overflow-x: auto; margin-top: 12px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.tbl td.v { font-family: ui-monospace, "SF Mono", "Consolas", monospace; word-break: break-all; }
.tbl tr.repaired td { background: #fdf7ec; }
.muted { color: var(--muted); font-size: 13px; font-weight: 400; }

/* --- печать --- */
.sizes { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.size {
  border: 0; border-radius: 13px; padding: 13px 12px;
  cursor: pointer; background: var(--fill); text-align: center;
  font-size: 15px; font-family: inherit; font-weight: 500; color: var(--text);
  transition: background 0.15s, color 0.15s;
}
.size:hover { background: #ebebef; }
.size.active { background: var(--accent); color: #fff; font-weight: 600; }
.custom-size { display: flex; gap: 16px; margin-top: 14px; }
.print-opts { display: flex; flex-wrap: wrap; gap: 18px; align-items: center; margin: 22px 0; }

.opt-fields { display: grid; gap: 12px; margin-bottom: 22px; }
.opt-row { display: grid; grid-template-columns: 200px 1fr; gap: 14px; align-items: center; }
.opt-row .chk { white-space: nowrap; }
.opt-row input[type=text]:disabled, .opt-row select:disabled { opacity: 0.4; cursor: not-allowed; }
.opt-inline { display: flex; gap: 10px; }
.opt-inline select { width: auto; min-width: 120px; }

.preview-row { display: flex; gap: 20px; flex-wrap: wrap; align-items: flex-start; }
.preview {
  background: #fff; border-radius: 12px; padding: 8px;
  box-shadow: 0 0 0 1px var(--line);
  display: inline-flex; align-items: center; justify-content: center; min-height: 60px;
}
.preview canvas { display: block; image-rendering: crisp-edges; border-radius: 2px; }
.preview-meta { font-size: 13px; color: var(--muted); flex: 1; min-width: 220px; line-height: 1.6; }

/* --- текстовая часть страницы --- */
.article h2 { font-size: 21px; margin: 34px 0 12px; font-weight: 650; letter-spacing: -0.02em; }
.article h2:first-child { margin-top: 0; }
.article h3 { font-size: 16px; margin: 24px 0 8px; color: var(--text); text-transform: none; letter-spacing: -0.01em; font-weight: 600; }
.article p { margin: 10px 0; font-size: 15.5px; line-height: 1.6; }
.article ul, .article ol { margin: 10px 0; padding-left: 24px; font-size: 15.5px; }
.article li { margin-bottom: 7px; }
.article blockquote {
  margin: 14px 0; padding: 14px 18px; border-left: 3px solid var(--accent);
  background: var(--fill); border-radius: 0 12px 12px 0; font-style: italic; font-size: 15px;
}

.foot { padding: 24px 0 48px; color: var(--muted); font-size: 13px; }
.foot-inner { display: flex; flex-wrap: wrap; gap: 16px 32px; align-items: center; justify-content: space-between; }
.foot-inner p { margin: 0; max-width: 46em; }
.foot-cta { display: flex; align-items: center; gap: 12px; white-space: nowrap; }

/* --- модальное окно обратной связи --- */
.modal { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(10, 12, 16, 0.5); backdrop-filter: blur(3px); }
.modal-card {
  position: relative; width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto;
  background: var(--card); border-radius: var(--radius); padding: 28px 30px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.modal-head h2 { margin: 0; font-size: 20px; font-weight: 650; letter-spacing: -0.02em; }
.modal-x {
  border: 0; background: var(--fill); color: var(--muted); cursor: pointer;
  width: 34px; height: 34px; border-radius: 50%; font-size: 15px; line-height: 1; flex: 0 0 auto;
}
.modal-x:hover { background: #e6e6ea; color: var(--text); }
.modal-card .field { margin-bottom: 16px; }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.modal-foot { display: flex; align-items: center; gap: 14px; margin-top: 4px; }
.fb-status { font-size: 13.5px; }
.fb-status.ok { color: var(--ok); }
.fb-status.err { color: var(--err); }
.honeypot { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.modal .hint-text { margin-top: 16px; }

@media (max-width: 600px) {
  .field-pair { grid-template-columns: 1fr; gap: 0; }
  .modal-card { padding: 22px 18px; }
}

.toast {
  position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%);
  background: rgba(20, 24, 31, 0.94); color: #fff; padding: 13px 22px; border-radius: 999px;
  font-size: 15px; z-index: 50; box-shadow: 0 8px 30px rgba(0,0,0,0.28);
  backdrop-filter: blur(12px);
}

@media (max-width: 700px) {
  .card { padding: 20px 16px; border-radius: 16px; }
  .top-inner { flex-direction: column; align-items: flex-start; gap: 8px; }
  .top-text { text-align: left; }
  .btn-row .btn { flex: 1 1 auto; }
  .opt-row { grid-template-columns: 1fr; gap: 6px; }
  .alt { flex-direction: column; gap: 10px; }
  .alt .btn { align-self: flex-start; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000; --card: #1c1c1e; --line: #2c2c2e; --text: #f2f2f7; --muted: #98989f;
    --fill: #2c2c2e;
    --shadow: none;
  }
  .btn:hover { background: #3a3a3c; }
  .size:hover { background: #3a3a3c; }
  .tbl tr.repaired td { background: #2b2415; }
  .preview { background: #fff; }
  .toast { background: rgba(255,255,255,0.12); }
}
