/* Цвета берутся из темы Telegram (светлая/тёмная), ниже — запасные значения для браузера */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f4ee);
  --text: var(--tg-theme-text-color, #16190f);
  --hint: var(--tg-theme-hint-color, #7b8072);
  --accent: var(--tg-theme-button-color, #3f9b1f);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #d63b2f);
  --line: color-mix(in srgb, var(--text) 10%, transparent);
  --sel: color-mix(in srgb, var(--accent) 12%, var(--bg));
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-tg]) {
    --bg: #17191a; --bg2: #222526; --text: #eef0ea; --hint: #8f948a; --accent: #6cc644;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
#app { max-width: 560px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }

header { position: sticky; top: 0; z-index: 2; background: var(--bg); display: flex; align-items: center; gap: 10px; padding: 12px 16px 8px; }
.back { border: 0; background: var(--bg2); color: var(--text); width: 32px; height: 32px; border-radius: 50%; font-size: 22px; line-height: 1; cursor: pointer; flex: none; }
.progress { flex: 1; height: 4px; background: var(--bg2); border-radius: 4px; overflow: hidden; }
#bar { height: 100%; width: 0; background: var(--accent); transition: width .3s; }

main { flex: 1; padding: 8px 16px 24px; }
.block-tag { font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--hint); margin: 4px 0 6px; }
h1.q { font-size: 20px; line-height: 1.3; font-weight: 650; margin: 0 0 6px; }
.hint { color: var(--hint); font-size: 14px; margin: 0 0 16px; }
.muted { color: var(--hint); }
.center { text-align: center; padding: 48px 8px; }
.demo { font-size: 12px; color: var(--hint); background: var(--bg2); border-radius: 8px; padding: 6px 10px; margin-bottom: 12px; }

.opts { display: flex; flex-direction: column; gap: 8px; }
.opt { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; border: 1.5px solid var(--line); background: var(--bg); color: var(--text);
  border-radius: var(--radius); padding: 13px 14px; font: inherit; cursor: pointer; transition: background .15s, border-color .15s; }
.opt:active { transform: scale(.995); }
.opt .mark { flex: none; width: 22px; height: 22px; border: 2px solid var(--line); display: grid; place-items: center; transition: all .15s; }
.opt.single .mark { border-radius: 50%; }
.opt.multi .mark { border-radius: 6px; }
.opt.on { background: var(--sel); border-color: var(--accent); }
.opt.on .mark { border-color: var(--accent); background: var(--accent); }
.opt.on .mark::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent-text); }
.opt.multi.on .mark::after { width: 10px; height: 6px; border-radius: 0; background: none; border: solid var(--accent-text); border-width: 0 0 2px 2px; transform: translateY(-1px) rotate(-45deg); }
.opt.lang { justify-content: center; font-weight: 600; padding: 16px; }

input.txt { width: 100%; font: inherit; color: var(--text); background: var(--bg2); border: 1.5px solid transparent; border-radius: 12px; padding: 12px 14px; outline: none; }
input.txt:focus { border-color: var(--accent); }
input.txt:disabled { opacity: .45; }
input.txt.other-in { margin: -2px 0 4px 34px; width: calc(100% - 34px); }
.open-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.chip { display: inline-flex; align-items: center; gap: 10px; border: 1.5px solid var(--line); border-radius: var(--radius); padding: 12px 14px; cursor: pointer; width: 100%; background: var(--bg); color: var(--text); font: inherit; text-align: left; }
.chip.on { background: var(--sel); border-color: var(--accent); }
.ghost { border: 0; background: var(--bg2); color: var(--text); font: inherit; border-radius: 12px; padding: 12px 14px; width: 100%; cursor: pointer; margin-bottom: 10px; }

.creative { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; margin-bottom: 16px; }
.creative img { width: 100%; border-radius: 10px; display: block; }
.creative .ph { aspect-ratio: 16/9; border-radius: 10px; background: var(--bg2); color: var(--hint); display: grid; place-items: center; text-align: center; padding: 12px; font-size: 14px; }

/* карточки марок с фото */
.cards { --cols: 4; display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); gap: 8px; margin-bottom: 10px; }
@media (min-width: 420px) { .cards { --cols: 4; } }   /* узкий телефон — 3 в ряд, шире — 4 */
.card { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 4px 8px; min-width: 0;
  border: 2px solid var(--line); border-radius: 14px; background: var(--bg); color: var(--text); font: inherit; cursor: pointer;
  transition: background .15s, border-color .15s; }
.card:active { transform: scale(.97); }
.card .num { position: absolute; top: 6px; left: 6px; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  font-size: 12px; font-weight: 700; background: var(--bg2); color: var(--text); }
.card .pic { width: 100%; height: 96px; display: grid; place-items: center; margin-top: 14px; }
.card .pic img { max-width: 100%; max-height: 96px; object-fit: contain; }
.card .pic.noimg::before { content: ""; width: 32px; height: 84px; opacity: .35; background: var(--hint);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 46 120'%3E%3Cpath d='M17 0h12v6h-12zM16 8h14v12c0 4 12 12 12 26v66c0 4-3 8-8 8H12c-5 0-8-4-8-8V46c0-14 12-22 12-26z'/%3E%3C/svg%3E") center/contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 46 120'%3E%3Cpath d='M17 0h12v6h-12zM16 8h14v12c0 4 12 12 12 26v66c0 4-3 8-8 8H12c-5 0-8-4-8-8V46c0-14 12-22 12-26z'/%3E%3C/svg%3E") center/contain no-repeat; }
.card .name { font-weight: 650; font-size: 13px; text-align: center; line-height: 1.2; min-height: 2.4em; display: grid; place-items: center;
  overflow-wrap: anywhere; }
.card .tick { position: absolute; right: 6px; top: 6px; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); opacity: 0; transform: scale(.6); transition: all .15s; }
.card .tick::after { content: ""; width: 9px; height: 5px; border: solid var(--accent-text); border-width: 0 0 2px 2px; transform: translateY(-1px) rotate(-45deg); }
.card.on { background: var(--sel); border-color: var(--accent); }
.card.on .num { background: var(--accent); color: var(--accent-text); }
.card.on .tick { opacity: 1; transform: none; }

.foot-row { display: flex; gap: 10px; align-items: stretch; }
.foot-row .cta { flex: 1; }
.count { flex: none; display: flex; align-items: center; gap: 6px; padding: 0 16px; border-radius: 12px; background: var(--sel); white-space: nowrap; }
.count b { color: var(--accent); font-size: 20px; }
.count[hidden] { display: none; }

footer { position: sticky; bottom: 0; background: var(--bg); padding: 8px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
#err { color: var(--danger); font-size: 14px; min-height: 0; }
#err:not(:empty) { margin-bottom: 8px; }
.cta { width: 100%; border: 0; border-radius: 12px; padding: 14px; font: inherit; font-weight: 600; background: var(--accent); color: var(--accent-text); cursor: pointer; }
.cta:disabled { opacity: .5; }

.final { text-align: center; padding: 56px 8px; }
.final .emoji { font-size: 56px; margin-bottom: 12px; }
.final h1 { font-size: 22px; margin: 0 0 8px; }
.final p { color: var(--hint); margin: 0 0 24px; }
pre.dump { text-align: left; font-size: 11px; background: var(--bg2); padding: 10px; border-radius: 10px; overflow: auto; max-height: 50vh; }
