:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f3f7);
  --section: var(--tg-theme-section-bg-color, var(--bg));
  --text: var(--tg-theme-text-color, #111418);
  --hint: var(--tg-theme-hint-color, #8a9099);
  --link: var(--tg-theme-link-color, #2f6fed);
  --accent: var(--tg-theme-button-color, #2f6fed);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #e5484d);
  --sep: color-mix(in srgb, var(--hint) 22%, transparent);
  --ok: #1f9d55;
  --warn: #d98a00;
  --radius: 14px;
  --tabbar-h: 62px;
  color-scheme: light dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg2); color: var(--text); font: 15px/1.4 var(--font, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif); }
.h1, .h2, .brand, .big-price, .onb h1, .card .price { font-family: var(--font-head, inherit); }
body { min-height: 100vh; overscroll-behavior-y: none; }
#app { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px); max-width: 720px; margin: 0 auto; }
body.no-tabbar #app { padding-bottom: 24px; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
input, textarea, select { font: inherit; color: var(--text); }
img { display: block; }
a { color: var(--link); text-decoration: none; }
.hidden { display: none !important; }
.center { text-align: center; }
.muted { color: var(--hint); }
.small { font-size: 13px; }
.pad { padding: 16px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* header */
.header { position: sticky; top: 0; z-index: 5; background: var(--bg2); padding: 12px 16px 8px; }
.h1 { font-size: 22px; font-weight: 700; margin: 0; }
.h2 { font-size: 17px; font-weight: 650; margin: 0 0 8px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 20px; letter-spacing: -.2px; }
.brand .dot { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; font-size: 15px; }

/* cards & sections */
.section { background: var(--section); border-radius: var(--radius); margin: 10px 12px; padding: 14px; }
.section.flush { padding: 0; overflow: hidden; }
.list-item { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--sep); background: var(--section); width: 100%; text-align: left; }
.list-item:last-child { border-bottom: 0; }
.list-item .thumb { width: 52px; height: 52px; border-radius: 10px; object-fit: cover; background: var(--bg2); flex: none; display: grid; place-items: center; font-size: 22px; }

/* inputs */
.input, .textarea, .select { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--sep); background: var(--bg); outline: none; }
.input:focus, .textarea:focus, .select:focus { border-color: var(--accent); }
.textarea { min-height: 110px; resize: vertical; }
.label { display: block; font-size: 13px; color: var(--hint); margin: 12px 2px 6px; }
.search { display: flex; align-items: center; gap: 8px; background: var(--section); border-radius: 12px; padding: 0 12px; }
.search input { border: 0; background: transparent; padding: 11px 0; outline: none; width: 100%; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 12px 16px; border-radius: 12px; background: var(--accent); color: var(--accent-text); font-weight: 600; width: 100%; min-height: 46px; }
.btn:disabled { opacity: .5; }
.btn.secondary { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.danger { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.btn.sm { padding: 8px 12px; min-height: 36px; width: auto; font-size: 14px; border-radius: 10px; }
.btn-row { display: flex; gap: 8px; }
.btn-row > .btn { flex: 1; }

/* chips */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 16px 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 7px 12px; border-radius: 999px; background: var(--section); color: var(--text); font-size: 14px; white-space: nowrap; border: 1px solid transparent; }
.chip.active { background: var(--accent); color: var(--accent-text); }
.chip.outline { border-color: var(--sep); }
.seg { display: flex; background: var(--section); border-radius: 12px; padding: 3px; margin: 0 16px; }
.seg button { flex: 1; padding: 8px 4px; border-radius: 9px; font-size: 14px; font-weight: 550; color: var(--hint); }
.seg button.active { background: var(--accent); color: var(--accent-text); }
.options { display: flex; flex-wrap: wrap; gap: 8px; }
.option { padding: 9px 13px; border-radius: 10px; background: var(--bg2); border: 1px solid var(--sep); font-size: 14px; }
.option.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); font-weight: 600; }

/* grid of listings */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding: 4px 12px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.card { background: var(--section); border-radius: var(--radius); overflow: hidden; text-align: left; position: relative; display: flex; flex-direction: column; }
.card .ph { aspect-ratio: 1 / 1; width: 100%; object-fit: cover; background: var(--bg2); display: grid; place-items: center; font-size: 40px; }
.card .body { padding: 8px 10px 10px; }
.card .price { font-weight: 700; font-size: 15px; }
.card .title { font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 2.8em; }
.card .meta { font-size: 12px; color: var(--hint); margin-top: 4px; }
.fav { position: absolute; top: 8px; right: 8px; width: 32px; height: 32px; border-radius: 50%; background: rgba(0,0,0,.35); color: #fff; display: grid; place-items: center; font-size: 17px; backdrop-filter: blur(6px); }
.fav.on { color: #ff4d6d; background: rgba(255,255,255,.9); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--bg2); color: var(--hint); }
.badge.kind { position: absolute; top: 8px; left: 8px; background: rgba(0,0,0,.55); color: #fff; }
.badge.pending { background: #fff3d6; color: #8a5a00; }
.badge.active { background: #dcf5e6; color: #146c3a; }
.badge.rejected, .badge.expired { background: #fde2e2; color: #a12626; }
.badge.sold { background: #e4e7ff; color: #3340a8; }
.badge.alumni { background: #efe4ff; color: #5b2ea6; }
.unread { background: var(--accent); color: var(--accent-text); border-radius: 999px; min-width: 20px; height: 20px; padding: 0 6px; font-size: 12px; display: inline-grid; place-items: center; font-weight: 700; }

/* listing page */
.gallery { position: relative; background: #000; }
.gallery .track { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; }
.gallery .track::-webkit-scrollbar { display: none; }
.gallery img { flex: none; width: 100%; aspect-ratio: 1 / 1; object-fit: contain; scroll-snap-align: center; }
.gallery .noimg { aspect-ratio: 16/9; display: grid; place-items: center; font-size: 64px; background: var(--bg2); }
.dots { position: absolute; bottom: 10px; left: 0; right: 0; display: flex; justify-content: center; gap: 5px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: rgba(255,255,255,.5); }
.dots i.on { background: #fff; }
.big-price { font-size: 24px; font-weight: 800; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--hint); }
.kv dd { margin: 0; }
.desc { white-space: pre-wrap; word-break: break-word; }
.seller { display: flex; align-items: center; gap: 12px; }
.avatar { width: 44px; height: 44px; border-radius: 50%; background: color-mix(in srgb, var(--accent) 18%, var(--bg)); color: var(--accent); font-weight: 700; display: grid; place-items: center; flex: none; font-size: 18px; }
.stars { color: #f5a623; letter-spacing: 1px; }
.sticky-cta { position: fixed; left: 0; right: 0; bottom: 0; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--sep); z-index: 20; }
.sticky-cta .inner { max-width: 720px; margin: 0 auto; }

/* photo uploader */
.photos { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; }
.photo-tile { position: relative; flex: none; width: 84px; height: 84px; border-radius: 12px; overflow: hidden; background: var(--bg2); }
.photo-tile img { width: 100%; height: 100%; object-fit: cover; }
.photo-tile .x { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 50%; background: rgba(0,0,0,.6); color: #fff; font-size: 13px; display: grid; place-items: center; }
.photo-add { flex: none; width: 84px; height: 84px; border-radius: 12px; border: 1.5px dashed var(--sep); display: grid; place-items: center; color: var(--accent); font-size: 13px; text-align: center; }
.cat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.cat-btn { display: flex; align-items: center; gap: 8px; padding: 12px; border-radius: 12px; background: var(--bg2); text-align: left; font-size: 14px; }
.cat-btn span:first-child { font-size: 20px; }

/* chat */
.chat-head { position: sticky; top: 0; z-index: 5; background: var(--bg); border-bottom: 1px solid var(--sep); padding: 10px 12px; display: flex; gap: 10px; align-items: center; }
.chat-head img, .chat-head .thumb { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; background: var(--bg2); display: grid; place-items: center; }
.msgs { padding: 12px; display: flex; flex-direction: column; gap: 6px; min-height: calc(100vh - 170px); }
.msg { max-width: 80%; padding: 8px 12px; border-radius: 16px; background: var(--section); white-space: pre-wrap; word-break: break-word; }
.msg.me { align-self: flex-end; background: var(--accent); color: var(--accent-text); border-bottom-right-radius: 5px; }
.msg.them { align-self: flex-start; border-bottom-left-radius: 5px; }
.msg time { display: block; font-size: 11px; opacity: .65; text-align: right; margin-top: 2px; }
.msg.sys { align-self: center; background: transparent; color: var(--hint); font-size: 13px; text-align: center; }
.composer { position: fixed; left: 0; right: 0; bottom: 0; background: var(--bg); border-top: 1px solid var(--sep); padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); z-index: 20; }
.composer .inner { display: flex; gap: 8px; max-width: 720px; margin: 0 auto; align-items: flex-end; }
.composer textarea { flex: 1; resize: none; border-radius: 20px; padding: 10px 14px; border: 1px solid var(--sep); background: var(--bg2); outline: none; max-height: 120px; min-height: 42px; }
.attach-btn { width: 42px; height: 42px; border-radius: 50%; background: var(--bg2); font-size: 20px; flex: none; }
.msg.has-photo { padding: 4px; }
.msg.has-photo .msg-text, .msg.has-photo time { padding: 0 8px; }
.msg.has-photo time { padding-bottom: 4px; }
.msg-photo { display: block; max-width: 100%; width: 240px; max-height: 320px; object-fit: cover; border-radius: 12px; cursor: zoom-in; background: var(--bg2); }
.msg.has-photo .msg-text { margin-top: 4px; }
.photo-view { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.92); display: grid; place-items: center; padding: 12px; }
.photo-view img { max-width: 100%; max-height: 100%; object-fit: contain; }
.send-btn { width: 42px; height: 42px; border-radius: 50%; background: var(--accent); color: var(--accent-text); font-size: 18px; flex: none; }
.note { font-size: 13px; color: var(--hint); background: var(--bg2); border-radius: 12px; padding: 10px 12px; }
.contacts-box { background: #dcf5e6; color: #0f5130; border-radius: 12px; padding: 10px 12px; font-size: 14px; }

/* tabbar */
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: var(--bg); border-top: 1px solid var(--sep); display: flex; z-index: 10; }
.tabbar button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; color: var(--hint); position: relative; }
.tabbar button .ic { font-size: 21px; line-height: 1; filter: grayscale(1); opacity: .75; }
.tabbar button.active { color: var(--accent); }
.tabbar button.active .ic { filter: none; opacity: 1; }
.tabbar button.sell .ic { width: 40px; height: 32px; border-radius: 12px; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; filter: none; opacity: 1; font-size: 22px; font-weight: 700; }
.tabbar .dotn { position: absolute; top: 6px; left: 55%; background: var(--danger); color: #fff; border-radius: 999px; font-size: 10px; min-width: 16px; height: 16px; display: grid; place-items: center; padding: 0 4px; font-weight: 700; }

/* sheet */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 50; display: flex; align-items: flex-end; animation: fade .15s; }
.sheet { background: var(--bg); width: 100%; max-width: 720px; margin: 0 auto; border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); max-height: 85vh; overflow-y: auto; animation: up .2s; }
.sheet .grabber { width: 38px; height: 5px; border-radius: 3px; background: var(--sep); margin: -6px auto 12px; }
@keyframes up { from { transform: translateY(40px); opacity: .5; } }
@keyframes fade { from { opacity: 0; } }

.toast { position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: rgba(20,22,26,.92); color: #fff; padding: 10px 16px; border-radius: 12px; z-index: 60; font-size: 14px; max-width: 90vw; text-align: center; }

/* onboarding */
.onb { min-height: 100vh; display: flex; flex-direction: column; padding: 24px 20px; background: var(--bg); }
.onb .hero { font-size: 56px; margin: 24px 0 8px; }
.onb h1 { font-size: 24px; margin: 8px 0; }
.progress { display: flex; gap: 6px; margin-bottom: 16px; }
.progress i { flex: 1; height: 4px; border-radius: 2px; background: var(--sep); }
.progress i.on { background: var(--accent); }
.lang-btn { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-radius: 14px; background: var(--bg2); width: 100%; font-size: 17px; font-weight: 550; }
.lang-btn + .lang-btn { margin-top: 10px; }
.code-input { letter-spacing: 8px; font-size: 24px; text-align: center; font-weight: 700; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; }
.check input { width: 20px; height: 20px; margin-top: 1px; accent-color: var(--accent); flex: none; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--bg2); border-radius: 12px; padding: 10px; text-align: center; }
.stat b { display: block; font-size: 20px; }
.stat span { font-size: 12px; color: var(--hint); }
.empty { padding: 48px 24px; text-align: center; color: var(--hint); }
.empty .ic { font-size: 48px; margin-bottom: 8px; }
.skeleton { background: linear-gradient(90deg, var(--section) 25%, var(--bg2) 50%, var(--section) 75%); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: var(--radius); }
@keyframes sk { to { background-position: -200% 0; } }

/* ============================================================
   Smoothness layer (all themes)
   ============================================================ */
html { -webkit-text-size-adjust: 100%; }
body { overscroll-behavior: none; }
button, .card, .list-item, .chip, .option, .cat-btn, .lang-btn, .fav, [data-go] {
  touch-action: manipulation; -webkit-user-select: none; user-select: none;
}
/* instant touch feedback: transform only (cheap for the GPU) */
.card, .btn, .chip, .option, .list-item, .cat-btn, .lang-btn, .fav, .send-btn, .seg button, .tabbar button, .theme-opt {
  transition: transform .16s cubic-bezier(.2, .8, .2, 1), background-color .2s, color .2s, opacity .2s;
}
.card:active, .list-item:active, .cat-btn:active { transform: scale(.975); }
.btn:active, .chip:active, .option:active, .lang-btn:active, .send-btn:active, .fav:active, .seg button:active, .theme-opt:active { transform: scale(.94); }
.tabbar button:active .ic { transform: scale(.88); }

/* photos fade in when decoded instead of popping in line by line */
img.fade { opacity: 0; transition: opacity .28s ease; }
img.fade.in { opacity: 1; }
.card .ph, .list-item .thumb { background-color: color-mix(in srgb, var(--text) 6%, var(--bg)); }

/* filter change: old results stay visible (dimmed) until new ones arrive */
#feed { transition: opacity .18s ease; }
#feed.loading { opacity: .45; pointer-events: none; }

/* thin progress line when a screen takes >160ms to load */
body.busy::after { content: ''; position: fixed; top: 0; left: 0; right: 0; height: 2.5px; z-index: 100; background: var(--accent);
  transform-origin: 0 50%; animation: busy 1.1s cubic-bezier(.4, 0, .2, 1) infinite; }
@keyframes busy { 0% { transform: scaleX(0); opacity: 1; } 70% { transform: scaleX(.85); opacity: 1; } 100% { transform: scaleX(1); opacity: 0; } }

/* chat: optimistic messages */
.msg.pending { opacity: .6; }
.msg.failed { outline: 1.5px solid var(--danger); }
.msg.failed::after { content: ' ⚠︎'; }

/* screen transitions (View Transitions API: Chrome/Android WebView 111+, Safari/iOS 18+) */
#tabbar { view-transition-name: tabbar; }
::view-transition-group(root) { animation-duration: .26s; }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: .26s; animation-timing-function: cubic-bezier(.2, .8, .2, 1); animation-fill-mode: both; }
html[data-nav="forward"]::view-transition-old(root) { animation-name: vt-out-left; }
html[data-nav="forward"]::view-transition-new(root) { animation-name: vt-in-right; }
html[data-nav="back"]::view-transition-old(root) { animation-name: vt-out-right; }
html[data-nav="back"]::view-transition-new(root) { animation-name: vt-in-left; }
html[data-nav="fade"]::view-transition-old(root) { animation-name: vt-fade-out; animation-duration: .16s; }
html[data-nav="fade"]::view-transition-new(root) { animation-name: vt-fade-in; animation-duration: .2s; }
@keyframes vt-in-right { from { transform: translateX(32%); opacity: 0; } }
@keyframes vt-out-left { to { transform: translateX(-12%); opacity: 0; } }
@keyframes vt-in-left { from { transform: translateX(-12%); opacity: 0; } }
@keyframes vt-out-right { to { transform: translateX(32%); opacity: 0; } }
@keyframes vt-fade-in { from { opacity: 0; } }
@keyframes vt-fade-out { to { opacity: 0; } }
/* fallback for WebViews without View Transitions */
.page-enter { animation: vt-fade-in .18s ease both; }

/* first appearance of feed results, and cards added by "show more" */
.grid.appear .card, .card.new { animation: card-in .32s cubic-bezier(.2, .8, .2, 1) both; }
.grid.appear .card:nth-child(2) { animation-delay: .03s; }
.grid.appear .card:nth-child(3) { animation-delay: .06s; }
.grid.appear .card:nth-child(4) { animation-delay: .09s; }
.grid.appear .card:nth-child(n+5) { animation-delay: .12s; }
@keyframes card-in { from { opacity: 0; transform: translateY(8px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
/* low-end Android (Telegram reports performance class LOW): no blur, no animation */
html.perf-low *, html.perf-low *::before, html.perf-low *::after { backdrop-filter: none !important; -webkit-backdrop-filter: none !important; animation: none !important; transition: none !important; }
html.perf-low .header, html.perf-low .chat-head, html.perf-low .composer, html.perf-low .sticky-cta, html.perf-low .tabbar { background: var(--bg2) !important; }
