:root {
  --bg:        var(--tg-theme-bg-color, #ffffff);
  --bg-sec:    var(--tg-theme-secondary-bg-color, #f2f3f5);
  --text:      var(--tg-theme-text-color, #0f172a);
  --muted:     var(--tg-theme-hint-color, #8b95a5);
  /* Фірмові кольори з лого — навмисно не залежать від теми Telegram */
  --accent:      #00854f;
  --accent-fg:   #ffffff;
  --accent-text: #007a48;   /* акцент як текст на світлому тлі */
  --card:      var(--tg-theme-bg-color, #ffffff);
  --border:    rgba(140, 150, 170, .22);
  --radius:    14px;
  --pad:       16px;
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-sec);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  overscroll-behavior-y: none;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  padding: 0 var(--pad) calc(24px + env(safe-area-inset-bottom));
}

.hidden { display: none !important; }

.screen { max-width: 560px; margin: 0 auto; }

/* ---------- Лого ---------- */
.brand-mark {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  margin-bottom: 18px;
  /* темний диск: біла «W» інакше зливається зі світлим тлом */
  background: radial-gradient(circle at 50% 35%, #16241e 0%, #0b1310 100%);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 45%, transparent),
              0 8px 28px -10px color-mix(in srgb, var(--accent) 60%, transparent);
}
.brand-mark img { display: block; width: 96px; height: 96px; }

/* ---------- Стартовий екран ---------- */
.hero { padding: 32px 0 20px; }
.hero-badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--accent-text);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  padding: 5px 10px;
  border-radius: 999px;
  margin-bottom: 12px;
}
.hero h1 { margin: 0 0 8px; font-size: 26px; line-height: 1.2; letter-spacing: -.02em; }
.hero-sub { margin: 0; color: var(--muted); font-size: 15px; }

.all-done {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  margin: 0 0 20px;
  padding: 16px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--accent) 12%, var(--card));
  border: 1.5px solid color-mix(in srgb, var(--accent) 40%, transparent);
}
.all-done-icon {
  flex: 0 0 auto;
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-fg);
  display: grid; place-items: center;
  font-size: 16px; font-weight: 700;
}
.all-done h2 { margin: 2px 0 5px; font-size: 17px; letter-spacing: -.01em; }
.all-done p { margin: 0; font-size: 14px; color: var(--muted); }

.name-field { margin: 0 0 20px; }
.name-field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin: 0 0 7px 2px;
}
.name-field input {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  padding: 13px 14px;
}
.name-field input:focus { outline: none; border-color: var(--accent); }
.name-field input.invalid { border-color: #e64646; }

.test-list { display: flex; flex-direction: column; gap: 12px; }

.test-card {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  font: inherit;
  color: inherit;
  cursor: pointer;
  transition: transform .12s ease, border-color .12s ease;
}
.test-card:active { transform: scale(.985); border-color: var(--accent); }
.test-card h3 { margin: 0 0 6px; font-size: 17px; letter-spacing: -.01em; }
.test-card p { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.test-meta { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.pill {
  background: var(--bg-sec);
  border-radius: 999px;
  padding: 3px 9px;
  font-weight: 500;
}
.pill-progress { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent-text); }
.pill-done { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent-text); }

.btn-deliver { width: 100%; margin-top: 18px; }

.foot-note { margin: 22px 0 0; font-size: 13px; color: var(--muted); text-align: center; }

/* ---------- Прогрес ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg-sec);
  padding: 14px 0 12px;
}
.progress-row { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
.counter { font-size: 13px; font-weight: 600; color: var(--text); }
.test-name { font-size: 12px; color: var(--muted); flex: 1; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-exit {
  flex: 0 0 auto;
  width: 26px; height: 26px;
  margin: -4px -4px -4px 4px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.btn-exit:active { background: var(--border); }
.progress-track { height: 4px; background: var(--border); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width .25s ease; }

/* ---------- Питання ---------- */
/* запас знизу, щоб останній елемент не ховався під липкою панеллю кнопок */
.q-body { padding: 8px 0 100px; }
.q-section {
  margin: 0 0 14px;
  padding: 12px 14px;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border-radius: 12px;
  font-size: 14px;
  color: var(--text);
}
.q-text { margin: 0 0 6px; font-size: 20px; line-height: 1.3; letter-spacing: -.015em; font-weight: 650; }
.q-hint { margin: 0 0 4px; font-size: 14px; color: var(--muted); }
.q-answer { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }

.opt {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  width: 100%;
  text-align: left;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 13px 14px;
  font: inherit;
  color: inherit;
  cursor: pointer;
  transition: border-color .12s ease, background .12s ease;
}
.opt:active { transform: scale(.99); }
.opt.selected { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--card)); }
.opt.disabled { opacity: .45; }

.mark {
  flex: 0 0 auto;
  width: 22px; height: 22px;
  border: 1.5px solid var(--border);
  display: grid;
  place-items: center;
  margin-top: 1px;
  font-size: 13px;
  color: transparent;
  background: transparent;
  transition: all .12s ease;
}
.mark-radio { border-radius: 50%; }
.mark-check { border-radius: 7px; }
.opt.selected .mark { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.opt-text { flex: 1; font-size: 15px; }
.opt-key { font-weight: 650; margin-right: 6px; color: var(--muted); }
.opt.selected .opt-key { color: var(--accent-text); }

/* ---------- Шкала ---------- */
.scale-labels { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.scale-labels span:last-child { text-align: right; }
.scale-grid { display: grid; grid-template-columns: repeat(var(--cols, 5), 1fr); gap: 8px; }
.scale-btn {
  aspect-ratio: 1;
  min-height: 46px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  color: inherit;
  font: inherit;
  font-weight: 600;
  font-size: 16px;
  cursor: pointer;
  transition: all .12s ease;
}
.scale-btn.selected { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }

/* ---------- Текст ---------- */
textarea.free-text, input.other-input {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  padding: 13px 14px;
  resize: vertical;
}
textarea.free-text { min-height: 130px; }
textarea.free-text:focus, input.other-input:focus { outline: none; border-color: var(--accent); }
input.other-input { margin-top: 8px; }
.char-count { font-size: 12px; color: var(--muted); text-align: right; margin-top: 6px; }

/* ---------- Кнопки ---------- */
.actions {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 10px;
  padding: 12px 0 calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg-sec) 70%, transparent);
}
.btn {
  flex: 1;
  border: none;
  border-radius: 12px;
  padding: 15px 18px;
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .12s ease, transform .12s ease;
}
.btn:active { transform: scale(.985); }
.btn-primary { background: var(--accent); color: var(--accent-fg); flex: 2; }
.btn-primary:disabled { opacity: .4; cursor: default; }
.btn-ghost { background: transparent; color: var(--muted); border: 1.5px solid var(--border); }
.btn-danger { background: transparent; color: #e64646; border: 1.5px solid color-mix(in srgb, #e64646 35%, transparent); }

/* ---------- Фінал ---------- */
.done-wrap { padding: 80px 0 40px; text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: center; }
.done-icon {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent-text);
  display: grid; place-items: center;
  font-size: 32px;
  margin-bottom: 4px;
}
.done-icon.error { background: rgba(230,70,70,.15); color: #e64646; }
.done-wrap h2 { margin: 0; font-size: 24px; letter-spacing: -.02em; }
.done-text { margin: 0 0 12px; color: var(--muted); font-size: 15px; max-width: 340px; }
.done-wrap .btn { width: 100%; max-width: 320px; flex: none; }

/* ---------- Нижня шторка ---------- */
.sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(10, 12, 16, .5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade-in .16s ease;
}
.sheet {
  width: 100%;
  max-width: 560px;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding: 24px var(--pad) calc(20px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: sheet-up .22s cubic-bezier(.2, .8, .3, 1);
}
.sheet h3 { margin: 0; font-size: 19px; letter-spacing: -.015em; }
.sheet p { margin: 0 0 8px; color: var(--muted); font-size: 15px; }
.sheet .btn { flex: none; width: 100%; }
@keyframes fade-in { from { opacity: 0; } }
@keyframes sheet-up { from { transform: translateY(100%); } }

/* ---------- Тост ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(92px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(20,22,28,.92);
  color: #fff;
  font-size: 14px;
  padding: 11px 18px;
  border-radius: 999px;
  z-index: 50;
  max-width: 88vw;
  text-align: center;
  animation: toast-in .18s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:     var(--tg-theme-bg-color, #17191c);
    --bg-sec: var(--tg-theme-secondary-bg-color, #0f1114);
    --text:   var(--tg-theme-text-color, #f1f3f5);
    --card:   var(--tg-theme-bg-color, #1d2025);
    --border: rgba(160, 170, 190, .2);
    /* на темному тлі зелений має бути яскравішим, а текст на ньому — темним */
    --accent:      #17c07e;
    --accent-fg:   #06231a;
    --accent-text: #2ad195;
  }
}

/* Telegram може мати темну тему при світлій системній — app.js проставляє data-theme */
:root[data-theme="dark"] {
    --bg:     var(--tg-theme-bg-color, #17191c);
    --bg-sec: var(--tg-theme-secondary-bg-color, #0f1114);
    --text:   var(--tg-theme-text-color, #f1f3f5);
    --card:   var(--tg-theme-bg-color, #1d2025);
    --border: rgba(160, 170, 190, .2);
    /* на темному тлі зелений має бути яскравішим, а текст на ньому — темним */
    --accent:      #17c07e;
    --accent-fg:   #06231a;
    --accent-text: #2ad195;
}
