:root {
  --green: #5f9e24;
  --green-bar: #6cb51f;
  --green-dark: #3f7a12;
  --text: #2b2b2b;
  --muted: #8a8a8e;
  --ok: #2f8f3a;
  --warn: #c98a12;
  --bad: #b23a3a;
  --sheet-bg: #efeff4;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: #000;
  overscroll-behavior: none;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }

/* ---------- Экраны ---------- */
.screen {
  display: none;
  position: fixed;
  inset: 0;
  flex-direction: column;
  max-width: 600px;
  margin: 0 auto;
  overflow: hidden;
}
.screen.active { display: flex; }

/* Фон-фото: положите assets/bg.jpg, иначе показывается градиент */
.bg-photo {
  position: absolute;
  inset: 0;
  z-index: -1;
  background:
    url("../assets/bg.jpg") center / cover no-repeat,
    radial-gradient(ellipse at 50% 55%, #9fd44a 0%, #5ea52a 45%, #2f6d18 100%);
}
.bg-photo::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(255,255,255,.85) 0%, rgba(255,255,255,.15) 22%, rgba(255,255,255,0) 40%);
}
.bg-photo-soft { opacity: .45; filter: blur(2px); }
.bg-photo-soft::before { background: rgba(240, 250, 225, .55); }

/* ---------- Главная ---------- */
.screen-home { isolation: isolate; padding: calc(var(--safe-top) + 32px) 0 calc(var(--safe-bottom) + 16px); }

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 4vw, 26px);
}
.brand-logo { width: clamp(64px, 17vw, 104px); height: auto; aspect-ratio: 1; }
.brand-name {
  font-family: Georgia, "Times New Roman", Times, serif;
  font-size: clamp(36px, 10.5vw, 62px);
  font-weight: 400;
  color: #6b6b6b;
  line-height: 1;
}

/* Плашки как в приложении Bayer CapSeal: неровные трапеции с тенью.
   Форма — на ::before (clip-path), тень — на самом элементе, иначе clip-path её обрезает. */
.ribbon {
  position: relative;
  display: block;
  margin: 0 auto;
  width: 74%;
  padding: 0 18px;
  text-align: center;
  color: #fff;
  font-weight: 700;
  line-height: 1.15;
  filter: drop-shadow(0 6px 5px rgba(0,0,0,.28));
  text-shadow: 0 1px 2px rgba(0,0,0,.2);
}
.ribbon::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(180deg, #6db52a 0%, #5a9e1e 100%);
}
.ribbon-title {
  margin-top: clamp(24px, 4.5vh, 44px);
  padding-top: clamp(18px, 3.2vh, 28px);
  padding-bottom: clamp(18px, 3.2vh, 28px);
  font-size: clamp(22px, 6.4vw, 34px);
}
/* верх поднимается вправо, правый край скошен внутрь */
.ribbon-title::before { clip-path: polygon(0 21%, 100% 0, 95% 97%, 3% 100%); }
.ribbon-btn {
  padding-top: clamp(20px, 3.4vh, 30px);
  padding-bottom: clamp(16px, 3vh, 26px);
  font-size: clamp(24px, 7vw, 38px);
  transition: transform .1s;
}
/* верх слегка поднимается вправо, низ шире справа */
.ribbon-btn::before { clip-path: polygon(2% 15%, 94% 0, 100% 99%, 0 100%); }
.ribbon-btn:active { transform: scale(.97); }
.home-spacer { flex: 1; }
.footer-note {
  margin: 18px 16px 0;
  text-align: center;
  font-size: clamp(12px, 3.4vw, 16px);
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,.5);
}

/* ---------- Верхняя панель ---------- */
.topbar {
  flex: none;
  display: grid;
  grid-template-columns: 72px 1fr 72px;
  align-items: center;
  height: calc(56px + var(--safe-top));
  padding-top: var(--safe-top);
  background: var(--green-bar);
  color: #fff;
}
.topbar h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.screen-result .topbar h1, .topbar-sheet h1 { color: #111; }
.topbar svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.topbar-back { display: flex; align-items: center; padding-left: 12px; height: 100%; }
.topbar-back-text { gap: 4px; font-size: 17px; color: #f4f9ee; white-space: nowrap; }
.topbar-icon { display: flex; justify-content: flex-end; padding-right: 14px; }
.topbar-done { text-align: right; padding-right: 16px; font-size: 17px; font-weight: 600; color: #f4f9ee; }

/* ---------- Сканер ---------- */
/* Фото видно, пока камера не запустилась или нет доступа к ней; затем его перекрывает видео */
.screen-scan {
  background:
    linear-gradient(rgba(0,0,0,.45), rgba(0,0,0,.45)),
    url("../assets/bg.jpg") center / cover no-repeat,
    #000;
}
#scan-video:not(.live) { visibility: hidden; }
.scan-body { position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; }
#scan-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.scan-hint {
  position: relative;
  width: 100%;
  margin-top: 16vh;
  padding: 12px 16px;
  background: rgba(200, 200, 205, .92);
  color: #222;
  text-align: center;
  font-size: 15px;
  line-height: 1.35;
}
.scan-frame {
  position: relative;
  width: min(90vw, 540px);
  aspect-ratio: 1;
  margin-top: 14px;
  border: 2px solid #fff;
  box-shadow: 0 0 0 100vmax rgba(0,0,0,.35);
  overflow: hidden;
}
.scan-frame.found { border-color: #7bd13a; }
.scan-line {
  position: absolute;
  left: 6%;
  right: 6%;
  height: 2px;
  background: rgba(123, 209, 58, .9);
  box-shadow: 0 0 8px #7bd13a;
  animation: scanline 2.2s ease-in-out infinite;
}
@keyframes scanline { 0%,100% { top: 8%; } 50% { top: 92%; } }
.scan-error {
  position: relative;
  margin: 12px 16px 0;
  padding: 10px 14px;
  border-radius: 8px;
  background: rgba(178, 58, 58, .9);
  color: #fff;
  font-size: 14px;
  text-align: center;
}
.scan-actions {
  position: relative;
  margin-top: auto;
  padding-bottom: calc(var(--safe-bottom) + 28px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.link-btn { background: none; border: 0; color: #e6e6e6; font-size: 15px; text-decoration: underline; }
.link-btn-strong { color: #fff; font-size: 20px; font-weight: 600; text-decoration: none; }

/* ---------- Результат ---------- */
.screen-result { background: #f2f7ea; }
.result-body { position: relative; flex: 1; overflow-y: auto; isolation: isolate; -webkit-overflow-scrolling: touch; }
.result-content { padding: 36px 16px calc(var(--safe-bottom) + 32px); text-align: center; }
.seal { width: 140px; height: 140px; margin: 0 auto; display: block; }
.result-title { margin: 22px 0 16px; font-size: 28px; font-weight: 700; }
.result-lead { margin: 0 0 8px; font-size: 18px; line-height: 1.4; }
.result-lead.ok { color: var(--ok); }
.result-lead.warn { color: var(--warn); }
.result-lead.bad { color: #d40000; }
.result-sub { margin: 0 0 22px; font-size: 17px; line-height: 1.4; color: #333; }
.result-code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 14px; color: #555; word-break: break-all; }

.card {
  margin: 18px auto 0;
  max-width: 480px;
  background: #fff;
  border: 1px solid #e3e3e3;
  border-radius: 4px;
  text-align: left;
  overflow: hidden;
}
.card-survey {
  background: rgba(255,255,255,.35);
  border: 1.5px solid #2e6fd6;
  border-radius: 8px;
  padding: 16px;
  text-align: center;
}
.card-survey h3 { margin: 0 0 10px; font-size: 18px; }
.card-survey p { margin: 0 0 14px; font-size: 16px; line-height: 1.4; }
.btn-light {
  display: inline-block;
  padding: 8px 26px;
  background: #fff;
  border: 1px solid #cfcfcf;
  border-radius: 4px;
  font-size: 16px;
}
.card-img { display: block; width: 100%; max-height: 260px; object-fit: contain; background: #fafafa; }
.card-head { padding: 14px 18px; font-weight: 600; font-size: 17px; border-bottom: 1px solid #ececec; }
.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-top: 1px solid #ececec;
  font-size: 16px;
}
.row:first-child { border-top: 0; }
.row-label { color: #333; }
.row-value { text-align: right; color: #111; font-weight: 500; word-break: break-word; }
.pill {
  flex: none;
  padding: 3px 12px;
  border-radius: 999px;
  background: #6b6b6b;
  color: #fff;
  font-weight: 600;
  font-size: 15px;
}
.weather-top { display: flex; align-items: center; gap: 18px; padding: 22px 18px; }
.weather-icon { width: 64px; height: 64px; flex: none; }
.weather-place { color: var(--muted); font-size: 14px; }
.weather-desc { font-size: 17px; font-weight: 600; }

.btn-primary {
  display: inline-block;
  padding: 12px 28px;
  border: 0;
  border-radius: 8px;
  background: var(--green);
  color: #fff;
  font-size: 17px;
  font-weight: 600;
}
.btn-primary:active { background: var(--green-dark); }
.btn-ghost { padding: 12px 20px; border: 0; background: none; color: var(--green-dark); font-size: 17px; }
.result-actions { margin-top: 26px; }

/* ---------- Информация ---------- */
.screen-info { background: var(--sheet-bg); overflow-y: auto; }
.topbar-sheet { border-radius: 14px 14px 0 0; margin-top: 8px; }
.info-head { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 26px 16px; }
.info-head .brand-logo { width: 64px; }
.info-head .brand-name { font-size: 36px; }
.list { list-style: none; margin: 0; padding: 0; background: #fff; border-top: 1px solid #ddd; border-bottom: 1px solid #ddd; }
.list li + li a { border-top: 1px solid #ddd; }
.list li { padding-left: 16px; }
.list a {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 16px 16px 0;
  font-size: 17px;
  color: #111;
}
.list a::after {
  content: "";
  width: 9px;
  height: 9px;
  border-top: 2px solid #b5b5b9;
  border-right: 2px solid #b5b5b9;
  transform: rotate(45deg);
}
.info-version { margin: 16px; color: var(--muted); font-size: 15px; }
.page-text { padding: 20px 16px calc(var(--safe-bottom) + 32px); font-size: 16px; line-height: 1.55; background: #fff; flex: 1; }
.page-text h2 { font-size: 18px; margin: 24px 0 8px; }
.page-text h2:first-child { margin-top: 0; }
.page-text p { margin: 0 0 12px; }
.page-text ul { margin: 0 0 12px; padding-left: 20px; }
.page-text li { margin-bottom: 6px; }
.page-updated { color: var(--muted); font-size: 14px; }
.page-text a { color: var(--green-dark); text-decoration: underline; }

/* ---------- Опрос ---------- */
.survey { display: flex; flex-direction: column; gap: 16px; padding: 20px 16px calc(var(--safe-bottom) + 32px); }
.survey label { display: flex; flex-direction: column; gap: 6px; font-size: 15px; color: #333; }
.survey label.inline { flex-direction: row; align-items: center; display: inline-flex; margin-right: 18px; }
.survey input:not([type=radio]), .survey select, .survey textarea {
  padding: 11px 12px;
  border: 1px solid #ccc;
  border-radius: 8px;
  background: #fff;
  font: inherit;
  font-size: 16px;
}
.survey fieldset { border: 0; padding: 0; margin: 0; }
.survey legend { font-size: 15px; margin-bottom: 8px; color: #333; }
.survey-done { color: var(--ok); text-align: center; font-weight: 600; }

/* ---------- Диалоги ---------- */
.sheet {
  width: min(92vw, 420px);
  border: 0;
  border-radius: 14px;
  padding: 22px 20px 16px;
  box-shadow: 0 10px 40px rgba(0,0,0,.3);
}
.sheet::backdrop { background: rgba(0,0,0,.5); }
.sheet h2 { margin: 0 0 8px; font-size: 20px; }
.sheet p, .sheet ol { font-size: 15px; line-height: 1.45; color: #444; }
.sheet ol { padding-left: 20px; }
.sheet input {
  width: 100%;
  padding: 12px;
  border: 1px solid #ccc;
  border-radius: 8px;
  font-size: 18px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  letter-spacing: 1px;
}
.sheet-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ---------- Лоадер ---------- */
.loader {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(0,0,0,.55);
  color: #fff;
  font-size: 16px;
}
.loader[hidden] { display: none; }
.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .scan-line, .spinner { animation-duration: 4s; }
}
