:root {
  color-scheme: light dark;
  --bg: var(--tg-theme-bg-color, #0e0e10);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #17171b);
  --text: var(--tg-theme-text-color, #f4f4f5);
  --hint: var(--tg-theme-hint-color, #9a9aa2);
  --accent: var(--tg-theme-button-color, #c9a15a);
  --accent-text: var(--tg-theme-button-text-color, #1a1a1a);
  --border: rgba(255, 255, 255, 0.08);
  --radius: 16px;
}

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 32px;
}

/* Header */
.header { padding: 16px 16px 8px; position: sticky; top: 0; background: var(--bg); z-index: 5; }
.header__top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.logo { font-weight: 300; letter-spacing: 3px; font-size: 22px; margin: 0; }
.logo b { font-weight: 700; }

.city-note { margin: 0 0 12px; font-size: 12px; color: var(--hint); }
.fav-chip.active { background: #d64545; color: #fff; border-color: #d64545; }

.controls { display: flex; gap: 8px; align-items: center; overflow-x: auto; padding-bottom: 4px; }
.chip {
  flex: 0 0 auto; padding: 7px 14px; border-radius: 999px;
  border: 1px solid var(--border); background: transparent; color: var(--text);
  font-size: 13px; cursor: pointer; transition: .15s;
}
.chip.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.sort-btn { margin-left: auto; }

/* Grid */
.grid {
  display: grid; grid-template-columns: repeat(2, 1fr);
  gap: 12px; padding: 12px 16px;
}
.card {
  background: var(--secondary-bg); border-radius: var(--radius);
  overflow: hidden; cursor: pointer; border: 1px solid var(--border);
  display: flex; flex-direction: column; transition: transform .12s;
}
.card:active { transform: scale(.97); }
.card__img {
  aspect-ratio: 1 / 1; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #26262c, #131317);
  font-size: 40px; font-weight: 300; color: var(--hint); position: relative;
}
.card__img img { width: 100%; height: 100%; object-fit: cover; }
.heart {
  position: absolute; top: 8px; right: 8px; width: 32px; height: 32px;
  border-radius: 50%; border: none; background: rgba(0,0,0,.5); backdrop-filter: blur(4px);
  font-size: 15px; cursor: pointer; z-index: 2; color: #fff; line-height: 1;
}
.heart.active { color: #ff5a5a; }
.badges { position: absolute; top: 8px; left: 8px; display: flex; flex-direction: column; gap: 4px; }
.badge {
  font-size: 10px; padding: 3px 7px; border-radius: 6px; font-weight: 600;
  letter-spacing: .3px; background: rgba(0,0,0,.55); color: #fff; backdrop-filter: blur(4px);
}
.badge--sale { background: #d64545; }
.badge--new { background: #3a8f5a; }
.badge--hit { background: var(--accent); color: var(--accent-text); }
.badge--low { background: #c77b2b; }

.card__body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 3px; }
.card__brand { font-size: 11px; color: var(--hint); text-transform: uppercase; letter-spacing: .5px; }
.card__name { font-size: 14px; font-weight: 500; line-height: 1.25; }
.card__price { margin-top: 4px; display: flex; gap: 6px; align-items: baseline; }
.price { font-size: 15px; font-weight: 600; }
.old-price { font-size: 12px; color: var(--hint); text-decoration: line-through; }

/* States */
.state { text-align: center; color: var(--hint); padding: 60px 20px; }

/* Detail overlay */
.overlay {
  position: fixed; inset: 0; background: var(--bg); z-index: 20;
  overflow-y: auto; transform: translateY(100%); transition: transform .25s ease;
}
.overlay.open { transform: translateY(0); }
.overlay__img {
  aspect-ratio: 1 / 1; background: linear-gradient(135deg, #26262c, #131317);
  display: flex; align-items: center; justify-content: center; font-size: 80px;
  font-weight: 300; color: var(--hint); position: relative;
}
.overlay__img img { width: 100%; height: 100%; object-fit: cover; }
.back-btn {
  position: absolute; top: 14px; left: 14px; width: 38px; height: 38px;
  border-radius: 50%; border: none; background: rgba(0,0,0,.5); color: #fff;
  font-size: 20px; cursor: pointer; backdrop-filter: blur(6px); z-index: 3;
}

/* Gallery (tap left/right zones + dots, как в Stories) */
.gallery-zone { position: absolute; top: 0; bottom: 0; width: 45%; border: none; background: transparent; padding: 0; z-index: 1; }
.gallery-zone--prev { left: 0; cursor: w-resize; }
.gallery-zone--next { right: 0; cursor: e-resize; }
.gallery-dots {
  position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 6px; z-index: 2;
}
.gallery-dot { width: 6px; height: 6px; border-radius: 50%; background: rgba(255,255,255,.4); transition: .15s; }
.gallery-dot.active { background: #fff; width: 16px; border-radius: 3px; }

.detail { padding: 18px 16px 40px; }
.detail__brand { color: var(--hint); text-transform: uppercase; letter-spacing: 1px; font-size: 12px; }
.detail__name { font-size: 24px; font-weight: 600; margin: 4px 0 6px; }
.detail__meta { display: flex; gap: 12px; align-items: center; color: var(--hint); font-size: 13px; margin-bottom: 14px; }
.stars { color: var(--accent); }

.volumes { display: flex; gap: 8px; margin: 14px 0; flex-wrap: wrap; }
.vol {
  padding: 8px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: transparent; color: var(--text); cursor: pointer; font-size: 13px;
}
.vol.active { border-color: var(--accent); background: rgba(201,161,90,.12); }
.vol.out { opacity: .4; text-decoration: line-through; }

.price-row { display: flex; align-items: baseline; gap: 10px; margin: 10px 0 4px; }
.price-row .price { font-size: 26px; }
.price-row .discount { background: #d64545; color: #fff; font-size: 12px; padding: 2px 8px; border-radius: 6px; }
.stock-note { font-size: 13px; margin-bottom: 16px; }
.stock-note.low { color: #e0913f; }
.stock-note.out { color: #d64545; }

.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--hint); margin: 22px 0 8px; }
.desc { line-height: 1.55; font-size: 14px; color: var(--text); white-space: pre-line; }

.pyramid { display: flex; flex-direction: column; gap: 8px; }
.pyramid__row { display: flex; gap: 10px; font-size: 14px; }
.pyramid__label { color: var(--hint); min-width: 74px; }

.specs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.spec { display: flex; flex-direction: column; }
.spec__k { font-size: 11px; color: var(--hint); text-transform: uppercase; letter-spacing: .4px; }
.spec__v { font-size: 14px; }

.cta {
  position: sticky; bottom: 0; margin-top: 26px; padding: 14px 0 0;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.cta button {
  width: 100%; padding: 15px; border: none; border-radius: 14px;
  background: var(--accent); color: var(--accent-text);
  font-size: 15px; font-weight: 600; cursor: pointer;
  box-shadow: 0 6px 16px rgba(201,161,90,.25); transition: transform .1s;
}
.cta button:disabled { opacity: .5; box-shadow: none; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #222; color: #fff; padding: 12px 20px; border-radius: 12px; font-size: 14px;
  opacity: 0; transition: .2s; z-index: 50; pointer-events: none;
  box-shadow: 0 8px 24px rgba(0,0,0,.35); max-width: 85vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.skeleton { animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .5 } }

/* Cart */
.back-btn--static { position: static; backdrop-filter: none; }
.cart-head {
  display: flex; align-items: center; gap: 12px; padding: 16px;
  position: sticky; top: 0; background: var(--bg); z-index: 3;
  border-bottom: 1px solid var(--border); font-size: 18px; font-weight: 600;
}
.cart-items { padding: 8px 16px 160px; }
.cart-item {
  display: flex; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--border);
}
.cart-item__img {
  width: 68px; height: 68px; border-radius: 12px; flex: 0 0 auto;
  background: linear-gradient(135deg, #26262c, #131317); display: flex;
  align-items: center; justify-content: center; color: var(--hint); font-size: 24px;
  overflow: hidden;
}
.cart-item__img img { width: 100%; height: 100%; object-fit: cover; }
.cart-item__info { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cart-item__brand { font-size: 11px; color: var(--hint); text-transform: uppercase; }
.cart-item__name { font-size: 14px; font-weight: 500; }
.cart-item__vol { font-size: 12px; color: var(--hint); }
.cart-item__bottom { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; }
.cart-item__price { font-weight: 600; }

.stepper { display: flex; align-items: center; gap: 0; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.stepper button {
  width: 32px; height: 32px; border: none; background: var(--secondary-bg);
  color: var(--text); font-size: 18px; cursor: pointer;
}
.stepper span { min-width: 32px; text-align: center; font-size: 14px; }
.remove-btn { background: none; border: none; color: var(--hint); font-size: 13px; cursor: pointer; }

.cart-footer {
  position: fixed; bottom: 0; left: 0; right: 0; padding: 16px;
  background: var(--secondary-bg); border-top: 1px solid var(--border);
  transform: translateY(100%); transition: transform .25s;
}
.cart-overlay.open .cart-footer { transform: translateY(0); }
.cart-footer.hidden { display: none; }
.summary-row { display: flex; justify-content: space-between; margin-bottom: 6px; font-size: 14px; }
.summary-row.total { font-size: 18px; font-weight: 700; margin: 10px 0 14px; }
.summary-row.discount { color: #3a8f5a; }
.cart-footer button {
  width: 100%; padding: 15px; border: none; border-radius: 14px;
  background: var(--accent); color: var(--accent-text); font-size: 15px; font-weight: 600; cursor: pointer;
}
.cart-empty { text-align: center; color: var(--hint); padding: 80px 20px; }

/* Checkout */
.checkout { padding: 4px 16px 40px; display: flex; flex-direction: column; gap: 20px; }

.checkout-block {
  background: var(--secondary-bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px 4px; margin: 0 16px 16px;
}
.checkout-block .section-title { margin: 2px 0 10px; }
.checkout-block .field { margin-bottom: 14px; }
.checkout .checkout-block { margin: 0; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field__label { font-size: 13px; color: var(--hint); }
.field__label i { color: #d64545; font-style: normal; }
.field input, .field textarea {
  width: 100%; padding: 13px 14px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 15px; font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(201,161,90,.15);
}
.field textarea { resize: vertical; }

.slot-options { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.slot-opt {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 13px; font-weight: 500; cursor: pointer;
  transition: border-color .15s, background .15s, transform .1s;
}
.slot-opt small { color: var(--hint); font-weight: 400; font-size: 11px; }
.slot-opt:active { transform: scale(.97); }
.slot-opt.active {
  border-color: var(--accent); background: rgba(201,161,90,.14);
  box-shadow: 0 0 0 1px var(--accent) inset;
}
.slot-opt.active small { color: var(--text); opacity: .8; }

.checkout-note {
  font-size: 12px; color: var(--hint); margin: 0 16px; line-height: 1.5;
  padding: 10px 12px; border-radius: 10px; background: rgba(201,161,90,.08);
  border: 1px solid rgba(201,161,90,.18);
}
.field.hidden { display: none; }

.checkout-summary { padding: 0; }
.checkout-summary .cart-item { padding-top: 0; }
.checkout-totals { padding-top: 10px; margin-top: 4px; border-top: 1px solid var(--border); }
.checkout-totals .summary-row.total { margin-bottom: 0; }

.cta button:active { transform: scale(.98); }

/* Success */
.success {
  padding: 90px 24px; text-align: center; display: flex; flex-direction: column;
  align-items: center; gap: 14px; animation: success-in .35s ease;
}
.success__icon { font-size: 64px; }
.success__title { font-size: 22px; font-weight: 600; }
.success__text { color: var(--hint); line-height: 1.5; }
.success button {
  margin-top: 16px; padding: 14px 28px; border: none; border-radius: 14px;
  background: var(--accent); color: var(--accent-text); font-size: 15px; font-weight: 600; cursor: pointer;
  transition: transform .1s;
}
.success button:active { transform: scale(.97); }
@keyframes success-in {
  from { opacity: 0; transform: translateY(12px) scale(.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
