:root {
  --bg: var(--tg-theme-secondary-bg-color, #101012);
  --surface: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #1c1c1f));
  --text: var(--tg-theme-text-color, #f5f5f7);
  --hint: var(--tg-theme-hint-color, #8d8e93);
  --accent: var(--tg-theme-button-color, #3e88f7);
  --on-accent: var(--tg-theme-button-text-color, #ffffff);
  --accent-text: var(--tg-theme-accent-text-color, var(--tg-theme-link-color, #3e88f7));
  --danger: var(--tg-theme-destructive-text-color, #ff453a);
  --head: var(--tg-theme-section-header-text-color, var(--hint));
  --sep: var(--tg-theme-section-separator-color, rgba(128, 128, 128, 0.2));
  --soft: rgba(120, 120, 128, 0.16);
  --track: rgba(120, 120, 128, 0.32);
  --radius: 16px;
  color-scheme: light dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; margin: 0; cursor: pointer; text-align: inherit; }
img { display: block; }

.screen { max-width: 640px; margin: 0 auto; padding: 12px 16px calc(40px + env(safe-area-inset-bottom)); }
.screen.center { min-height: 80vh; display: grid; place-content: center; text-align: center; gap: 4px; }
.hero { padding: 8px 4px 16px; }
.hero h1 { margin: 0 0 6px; font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.hero p { margin: 0; color: var(--hint); }
.hint { color: var(--hint); }
.ellipsis { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Фильтры карточками. minmax(0, …) — иначе длинный текст растягивает карточку за край экрана */
.ftiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 520px) { .ftiles { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); } }
.ftile {
  display: flex; flex-direction: column; min-width: 0; overflow: hidden;
  border-radius: 18px; background: var(--surface); cursor: pointer; transition: opacity 0.2s, transform 0.1s;
}
.ftile:active { transform: scale(0.97); }
.ftile.off { opacity: 0.5; }
.ftile-art { position: relative; aspect-ratio: 1; display: grid; place-items: center; background: var(--soft); }
.ftile-art::before { grid-area: 1 / 1; }
.ftile-art img { width: 78%; height: 78%; object-fit: contain; }
.ftile-art:not(:has(img))::before, .ctile-art:empty::before, .thumb:empty::before {
  content: "🎁"; display: grid; place-items: center; width: 100%; height: 100%; font-size: 36px;
}
.ftile-art .switch { position: absolute; top: 8px; right: 8px; }
.badge {
  position: absolute; left: 8px; bottom: 8px; padding: 2px 8px; border-radius: 999px;
  background: rgba(0, 0, 0, 0.45); color: #fff; font-size: 12px; font-weight: 600; backdrop-filter: blur(6px);
}
.ftile-body { padding: 10px 12px 12px; }
.ftile-title { font-weight: 600; font-size: 15px; }
.ftile-line { margin-top: 2px; font-size: 13px; color: var(--hint); display: flex; align-items: center; gap: 4px; }
.ftile-price { margin-top: 6px; font-size: 13px; font-weight: 600; color: var(--accent-text); }
.ftile.add {
  align-items: center; justify-content: center; gap: 8px; min-height: 200px;
  background: transparent; border: 2px dashed var(--track); color: var(--accent-text); font-weight: 600;
}
.plus {
  width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: var(--on-accent); font-size: 30px; font-weight: 400; line-height: 1;
}
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18); }
.dot:last-of-type { margin-right: 2px; }

.thumb {
  width: 56px; height: 56px; flex: none; border-radius: 14px; overflow: hidden;
  background: var(--soft); display: grid; place-items: center; font-size: 26px;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.empty-icon { font-size: 48px; line-height: 1; }
.center h2 { margin: 14px 0 6px; font-size: 20px; }

/* Выбор коллекции сеткой */
.ctiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; }
.ctile {
  display: flex; flex-direction: column; align-items: center; min-width: 0; padding: 8px 6px 10px;
  border-radius: 16px; background: var(--surface); box-shadow: inset 0 0 0 2px transparent;
  transition: box-shadow 0.15s, transform 0.1s;
}
.ctile:active { transform: scale(0.96); }
.ctile.on { box-shadow: inset 0 0 0 2px var(--accent); }
.ctile-art { width: 100%; aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: var(--soft); }
.ctile-art img { width: 100%; height: 100%; object-fit: cover; }
.ctile-name { max-width: 100%; margin-top: 6px; font-size: 13px; font-weight: 600; text-align: center; line-height: 1.2; }
.ctile-meta { margin-top: 2px; font-size: 12px; color: var(--hint); white-space: nowrap; }

/* Сворачиваемые разделы редактора */
.fold { margin-top: 12px; border-radius: var(--radius); background: var(--surface); }
.fold-head { display: flex; align-items: center; gap: 10px; min-height: 56px; padding: 10px 14px; cursor: pointer; }
.fold-title { font-weight: 600; font-size: 16px; }
.fold-preview { flex: 1; min-width: 0; display: flex; gap: 4px; overflow: hidden; }
.pv { width: 28px; height: 28px; flex: none; border-radius: 8px; object-fit: contain; background: var(--soft); }
.pv.swatch { border-radius: 50%; }
.pv.glyph { padding: 0; width: 24px; height: 24px; margin: 2px; background: var(--text); }
.chev { color: var(--hint); font-size: 20px; line-height: 1; transition: transform 0.2s; }
.fold.open .chev { transform: rotate(90deg); }
.fold-body { display: none; padding: 0 10px 12px; }
.fold.open .fold-body { display: block; }
.fold .search, .fold .seg, .fold .tile, .fold .chip { background-color: var(--bg); }

/* Переключатель */
.switch { position: relative; flex: none; width: 51px; height: 31px; }
.switch input { position: absolute; inset: 0; z-index: 1; margin: 0; opacity: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 31px; background: var(--track); transition: background 0.2s; }
.switch span::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25); transition: transform 0.2s;
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch.sm { width: 42px; height: 26px; }
.switch.sm span { background: rgba(0, 0, 0, 0.35); backdrop-filter: blur(6px); }
.switch.sm span::after { width: 22px; height: 22px; }
.switch.sm input:checked + span { background: var(--accent); }
.switch.sm input:checked + span::after { transform: translateX(16px); }

/* Редактор */
.collection-row { width: 100%; display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: var(--radius); background: var(--surface); }
.grow { flex: 1; min-width: 0; }
.row-title { font-weight: 600; font-size: 17px; }
.row-sub { margin-top: 2px; color: var(--hint); font-size: 13px; }
.row-action { color: var(--accent-text); font-size: 14px; font-weight: 500; }
section { margin-top: 22px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 0 4px 10px; }
.section-head h3 { margin: 0; font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--head); }
.counter { font-size: 13px; color: var(--hint); white-space: nowrap; }
.counter button { color: var(--accent-text); }

.toolbar { display: flex; gap: 8px; margin-bottom: 10px; }
.search {
  display: block; width: 100%; min-width: 0; height: 38px; margin: 0 0 10px; padding: 0 12px 0 34px;
  border: 0; border-radius: 12px; outline: none; color: var(--text); font: inherit; font-size: 16px;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238e8e93' stroke-width='2.4' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") 11px 50% / 15px no-repeat;
  -webkit-appearance: none; appearance: none;
}
.search::-webkit-search-cancel-button { -webkit-appearance: none; }
.toolbar .search { flex: 1; margin: 0; }
.seg { display: flex; flex: none; padding: 3px; border-radius: 12px; background: var(--surface); }
.seg button { height: 32px; padding: 0 10px; border-radius: 9px; font-size: 13px; color: var(--hint); transition: background 0.15s; }
.seg button.on { background: var(--accent); color: var(--on-accent); }
@media (max-width: 380px) {
  .toolbar { flex-direction: column; }
  .seg button { flex: 1; text-align: center; }
}

/* Плитки моделей и узоров */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; }
.grid.small { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }
.tile {
  position: relative; display: flex; flex-direction: column; align-items: center; min-width: 0;
  padding: 6px 6px 8px; border-radius: 14px; background: var(--surface);
  box-shadow: inset 0 0 0 2px transparent; transition: box-shadow 0.15s, transform 0.1s;
}
.tile:active { transform: scale(0.97); }
.tile.on { box-shadow: inset 0 0 0 2px var(--accent); }
.art { width: 100%; aspect-ratio: 1; border-radius: 10px; background: var(--art-bg, var(--soft)); display: grid; place-items: center; overflow: hidden; }
.art img { width: 86%; height: 86%; object-fit: contain; }
.glyph {
  width: 60%; height: 60%; background: var(--glyph, var(--text));
  -webkit-mask: var(--mask) center / contain no-repeat; mask: var(--mask) center / contain no-repeat;
}
.tile-name { max-width: 100%; margin-top: 6px; font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-meta { font-size: 11.5px; color: var(--hint); white-space: nowrap; }
.check {
  position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center; background: var(--accent); color: var(--on-accent);
  font-size: 13px; font-weight: 700; opacity: 0; transform: scale(0.6); transition: opacity 0.15s, transform 0.15s;
}
.tile.on .check { opacity: 1; transform: none; }

/* Фоны */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 12px 0 5px;
  border-radius: 999px; background: var(--surface); font-size: 14px;
  box-shadow: inset 0 0 0 2px transparent; transition: box-shadow 0.15s;
}
.chip.on { box-shadow: inset 0 0 0 2px var(--accent); }
.chip small { color: var(--hint); font-size: 12px; }
.swatch { width: 26px; height: 26px; flex: none; border-radius: 50%; background: var(--soft); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14); }


/* Скидка от флора */
.deal { overflow: hidden; border-radius: var(--radius); background: var(--surface); }
.deal-body { display: none; padding: 0 14px 14px; }
.deal.on .deal-body { display: block; }
.deal-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 10px; }
.pct-field { display: flex; align-items: center; gap: 4px; height: 40px; padding: 0 12px; border-radius: 12px; background: var(--bg); }
.pct-field input {
  width: 48px; border: 0; outline: none; background: none; color: var(--text);
  font: inherit; font-size: 18px; font-weight: 600; text-align: right;
}
.pct-field span { color: var(--hint); font-weight: 600; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.presets button { height: 32px; padding: 0 12px; border-radius: 999px; background: var(--bg); font-size: 14px; }
.presets button.on { background: var(--accent); color: var(--on-accent); }
.deal .seg { width: 100%; background: var(--bg); }
.deal .seg button { flex: 1; text-align: center; }
.deal-hint { margin: 10px 2px 0; color: var(--hint); font-size: 13px; }

/* Поля */
.pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.field { display: flex; align-items: center; gap: 8px; height: 46px; padding: 0 14px; border-radius: 12px; background: var(--surface); }
.field span { color: var(--hint); }
.field input, .field-input { flex: 1; width: 100%; min-width: 0; border: 0; outline: none; background: none; color: var(--text); font: inherit; font-size: 16px; }
.field-input { display: block; width: 100%; height: 46px; padding: 0 14px; border-radius: 12px; background: var(--surface); }
.field input::placeholder, .field-input::placeholder { color: var(--hint); opacity: 0.8; }

.list { overflow: hidden; border-radius: var(--radius); background: var(--surface); }
.list-item { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 52px; padding: 10px 14px; cursor: pointer; }
.list-item + .list-item { box-shadow: inset 0 1px 0 var(--sep); }
.tick { color: var(--accent-text); font-weight: 700; }

.danger { display: block; width: 100%; height: 48px; margin-top: 26px; border-radius: 12px; background: var(--surface); color: var(--danger); text-align: center; font-weight: 500; }
.retry { margin-top: 18px; height: 44px; padding: 0 22px; border-radius: 12px; background: var(--accent); color: var(--on-accent); font-weight: 600; }
.nothing { grid-column: 1 / -1; margin: 12px 4px; color: var(--hint); }

.loader {
  grid-column: 1 / -1; width: 28px; height: 28px; margin: 28px auto; border-radius: 50%;
  border: 3px solid var(--soft); border-top-color: var(--accent); animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; z-index: 10; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom));
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px;
  background: rgba(30, 30, 32, 0.94); color: #fff; font-size: 14px; text-align: center;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3); transform: translateX(-50%); animation: pop 0.2s ease-out;
}
.toast.error { background: #c0362c; }
@keyframes pop { from { opacity: 0; transform: translate(-50%, 8px); } }
