:root {
  --bg: #0d0d12;
  --bg-2: #151522;
  --bg-3: #1d1d2e;
  --bg-4: #262638;
  --bg-5: #2f2f44;
  --fg: #ffffff;
  --fg-2: #e0e0eb;
  --muted: #8a8aa6;
  --accent: #fbbf24;
  --accent-2: #f7c66b;
  --accent-strong: #f59e0b;
  --tg-blue: #2aabee;
  --good: #21d07a;
  --warn: #ffc73a;
  --bad: #ff5a5a;
  --border: #2a2a3c;
  --border-2: #1a1a28;
  --radius: 12px;
  --radius-lg: 18px;
  --radius-xl: 22px;
  --shadow: 0 10px 28px rgba(0,0,0,.4);
  --safe-top: env(safe-area-inset-top, 0);
  --safe-bottom: env(safe-area-inset-bottom, 0);
}
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  overscroll-behavior: none;
}

#app { display: flex; flex-direction: column; min-height: 100%; }
#view {
  flex: 1;
  max-width: 540px;
  width: 100%;
  margin: 0 auto;
  padding: 12px 14px calc(20px + var(--safe-bottom));
}

/* ─── Tab switcher (segmented) ─────────────────────────────── */
.tabs {
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--bg-3);
  border-radius: var(--radius);
  padding: 4px;
  gap: 4px;
  margin-bottom: 14px;
  position: sticky; top: calc(var(--safe-top) + 8px); z-index: 5;
  box-shadow: 0 8px 18px rgba(0,0,0,.3);
}
.tabs button {
  appearance: none;
  background: transparent;
  border: none;
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
  padding: 10px 4px;
  border-radius: 8px;
  cursor: pointer;
  transition: all .15s;
  font-family: inherit;
}
.tabs button.active {
  background: var(--accent);
  color: #181818;
}
.tabs button:not(.active):hover { color: var(--fg-2); }

/* ─── Toolbar (search + sort) ──────────────────────────────── */
.toolbar { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.search-box {
  position: relative;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex; align-items: center; gap: 10px;
  padding: 0 12px 0 38px;
}
.search-box::before {
  content: "🔍";
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  font-size: 14px; opacity: .6;
}
.search-box input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--fg);
  padding: 12px 0;
  font-size: 14px;
  font-family: inherit;
  outline: none;
}
.search-box input::placeholder { color: var(--muted); }
.sort-row {
  display: flex; gap: 8px; align-items: center;
}
.sort-row select {
  flex: 1;
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 11px 12px;
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  appearance: none;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 12 8' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238a8aa6' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 12px;
  padding-right: 32px;
}
.sort-row select:focus { border-color: var(--accent); }

/* ─── Grid of cards ────────────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.card {
  background: var(--bg-3);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  border: 1px solid var(--border-2);
  display: flex; flex-direction: column;
  transition: transform .12s, border-color .15s;
  text-decoration: none;
  color: var(--fg);
}
.card:active { transform: scale(.97); }
.card:hover { border-color: var(--accent); }

/* picture area */
.pic {
  aspect-ratio: 1 / 1;
  position: relative;
  display: flex; flex-direction: column;
  align-items: center; justify-content: flex-start;
  padding: 18px 12px 12px;
  background: var(--bg-3);
  overflow: hidden;
  gap: 8px;
}

/* Numbers / Usernames: white circular badge with Telegram logo */
.pic-num, .pic-user {
  background:
    radial-gradient(120% 80% at 50% 0%, #1a2536 0%, #0f1218 80%);
}
.pic-num .tg-circle, .pic-user .tg-circle {
  width: 66px; height: 66px;
  background: #ffffff;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 18px rgba(0,0,0,.4);
  margin-top: 4px;
}
.pic-num .tg-circle svg, .pic-user .tg-circle svg {
  width: 52px; height: 52px;
}

/* coloured name pill (green / brown / red by duration) */
.name-tag {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 7px;
  font-weight: 700;
  font-size: 12.5px;
  letter-spacing: .2px;
  color: #fff;
  background: #555;
  max-width: 90%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.name-tag.long  { background: #2f7a4a; }
.name-tag.med   { background: #8a5a32; }
.name-tag.short { background: #913a3a; }

/* duration pill BELOW name tag */
.dur-pill {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 10.5px;
  color: #c8c8d6;
  background: rgba(0,0,0,.45);
  border: 1px solid rgba(255,255,255,.06);
}

/* Gifts: real Fragment image (full bleed) */
.pic-gift {
  padding: 0;
  background: #0d0d12;
  display: block;
}
.pic-gift .gift-img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
}
.pic-gift .gift-fallback {
  position: absolute; inset: 0;
  display: none;
  align-items: center; justify-content: center;
  font-size: 60px; opacity: .85;
  background: radial-gradient(140% 100% at 30% 20%, #2b1f55 0%, #0d0d12 75%);
}
.pic-gift.no-img .gift-fallback { display: flex; }
.pic-gift .ovr-bottom {
  position: absolute; bottom: 8px; left: 8px;
  color: #fff;
  font-size: 11px; font-weight: 700;
  padding: 4px 9px; border-radius: 999px;
  background: rgba(0,0,0,.6);
  border: 1px solid rgba(255,255,255,.08);
  backdrop-filter: blur(4px);
  z-index: 2;
}

.title {
  padding: 10px 12px 2px;
  font-weight: 700;
  font-size: 14px;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-word;
}
.subtitle {
  padding: 0 12px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  line-height: 1.2;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.price-row {
  margin: 6px 10px 10px;
  background: var(--bg-4);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  white-space: nowrap;
}
.price-row .ton-row {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.price-row .ton-row b { font-weight: 700; }
.price-row .ton-ico {
  width: 18px; height: 18px;
  background: #0098ea;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: white;
  font-size: 11px;
  font-weight: 800;
}
.price-row .rub-eq {
  color: var(--accent);
  font-weight: 700;
  font-size: 12px;
}


/* duration pill tint by length */
.tag-dur { background: var(--bg-5); color: #fff; }
.tag-dur.long  { background: #2f6a44; }
.tag-dur.med   { background: #6b4f2a; }
.tag-dur.short { background: #6b2a2a; }

/* infinite scroll sentinel */
.sentinel { grid-column: 1 / -1; padding: 22px 0; text-align: center; color: var(--muted); }

/* skeleton */
.skel-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.skel {
  background: var(--bg-3);
  border-radius: var(--radius-lg);
  aspect-ratio: 1 / 1.4;
  position: relative; overflow: hidden;
}
.skel::after {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.06), transparent);
  animation: shimmer 1.2s infinite;
}
@keyframes shimmer { 0% { transform: translateX(-100%); } 100% { transform: translateX(100%); } }

/* ─── Item page ────────────────────────────────────────────── */
.item-hero {
  background:
    radial-gradient(120% 90% at 50% 0%, #2b1f55 0%, transparent 70%),
    var(--bg-3);
  border-radius: var(--radius-xl);
  padding: 22px 18px;
  text-align: center;
  border: 1px solid var(--border-2);
  position: relative;
  overflow: hidden;
}
.item-hero .ph { font-size: 80px; }
.item-hero .hero-tg { display: flex; justify-content: center; padding: 6px 0 14px; }
.item-hero .hero-tg svg { filter: drop-shadow(0 12px 28px rgba(0,0,0,.45)); }
.item-hero .hero-name-tag {
  display: inline-block;
  padding: 10px 18px;
  border-radius: 12px;
  font-weight: 800;
  font-size: 18px;
  letter-spacing: .3px;
  background: rgba(0,0,0,.45);
  border: 1px solid rgba(255,255,255,.08);
  margin: 0 0 8px;
}
.item-hero .hero-name-tag.long  { background: rgba(64, 122, 76, .85); }
.item-hero .hero-name-tag.med   { background: rgba(128, 90, 52, .85); }
.item-hero .hero-name-tag.short { background: rgba(140, 56, 56, .85); }

.item-hero .hero-img-wrap {
  width: 60%; max-width: 220px; aspect-ratio: 1; margin: 0 auto 10px;
  border-radius: 14px;
  overflow: hidden;
  background: #0d0d12;
  position: relative;
  box-shadow: 0 12px 28px rgba(0,0,0,.45);
}
.item-hero .hero-img { width: 100%; height: 100%; object-fit: cover; }
.item-hero .hero-img-fallback {
  position: absolute; inset: 0;
  display: none;
  align-items: center; justify-content: center;
  font-size: 80px; opacity: .85;
}
.item-hero .hero-img-wrap.no-img .hero-img-fallback { display: flex; }
.item-hero .ttl { margin-top: 6px; font-size: 18px; font-weight: 700; }
.item-hero .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }

.attrs {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px;
  justify-content: center;
}
.attr {
  background: var(--bg-4);
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
}
.attr b { color: var(--fg); }

.info-box {
  margin-top: 14px;
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
}
.info-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-2);
  font-size: 14px;
}
.info-row:last-child { border-bottom: none; }
.info-row .lbl { color: var(--muted); }
.info-row .val { font-weight: 700; }

.dur-prompt { margin: 14px 0 6px; color: var(--muted); text-align: center; font-size: 13px; }
.dur-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
}
.dur-btn {
  padding: 11px 0;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--fg);
  font-size: 14px;
  cursor: pointer;
  text-align: center;
  font-family: inherit;
  transition: all .12s;
}
.dur-btn:active { transform: scale(.96); }
.dur-btn.active { background: var(--accent); border-color: var(--accent); color: #181818; }
.dur-custom {
  width: 100%;
  margin-top: 8px;
  padding: 12px 14px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--fg);
  font-size: 14px;
  text-align: center;
  font-family: inherit;
}
.dur-custom:focus { outline: none; border-color: var(--accent); }

.total {
  margin-top: 14px;
  background: linear-gradient(180deg, #2b1f55, #1a1335);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  display: flex; justify-content: space-between; align-items: center;
}
.total .lbl { color: var(--muted); font-size: 13px; }
.total .val { font-size: 22px; font-weight: 800; color: var(--accent); }

.cta { margin-top: 12px; }
.btn {
  appearance: none;
  background: var(--accent);
  color: #181818;
  font-weight: 700;
  border: none;
  padding: 14px 20px;
  border-radius: 14px;
  cursor: pointer;
  font-size: 15px;
  text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: inherit;
  width: 100%;
}
.btn:active { transform: scale(.98); }
.btn.ghost { background: transparent; border: 1px solid var(--border); color: var(--fg); }

.back-row { margin-top: 12px; text-align: center; }
.back-row a { color: var(--muted); text-decoration: none; font-size: 13px; }
.back-row a:active { color: var(--fg); }

.empty { color: var(--muted); text-align: center; padding: 60px 0; }
.err { color: var(--bad); text-align: center; padding: 24px 0; }

/* ─── Rent card + slider (item page) ───────────────────────── */
.rent-card {
  margin-top: 14px;
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-lg);
  padding: 16px 18px 18px;
}
.rent-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.rent-head-l { color: var(--fg-2); font-weight: 600; font-size: 14px; }
.rent-days { font-weight: 800; font-size: 17px; color: var(--fg); letter-spacing: .2px; }
.rent-card.fixed .rent-head { margin-bottom: 0; }
.rent-fixed {
  margin-top: 14px; padding: 12px 14px;
  background: var(--bg-4); border: 1px solid var(--border-2);
  border-radius: var(--radius); text-align: center;
  color: var(--fg-2); font-size: 13.5px;
}
.rent-fixed b { color: var(--accent); }
.rent-range {
  display: flex; justify-content: space-between;
  color: var(--muted); font-size: 12px; margin-top: 10px;
}
.rent-slider {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 6px; border-radius: 999px;
  background: linear-gradient(90deg,
     var(--accent) 0%, var(--accent) var(--fill, 30%),
     var(--bg-5) var(--fill, 30%), var(--bg-5) 100%);
  outline: none; cursor: pointer; margin: 0;
}
.rent-slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent);
  border: 4px solid var(--bg-3);
  box-shadow: 0 2px 10px rgba(0,0,0,.5), 0 0 0 1px var(--accent-strong);
  cursor: grab;
}
.rent-slider::-webkit-slider-thumb:active { cursor: grabbing; transform: scale(1.08); }
.rent-slider::-moz-range-thumb {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent); border: 4px solid var(--bg-3);
  box-shadow: 0 2px 10px rgba(0,0,0,.5); cursor: grab;
}

/* ─── Price breakdown ──────────────────────────────────────── */
.breakdown {
  margin-top: 12px;
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-lg);
  padding: 6px 18px;
}
.bd-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 0; font-size: 14px;
}
.bd-row span { color: var(--muted); }
.bd-row b { font-weight: 700; color: var(--fg); }
.bd-sep { height: 1px; background: var(--border-2); margin: 0 -18px; }
.bd-total { padding: 14px 0; }
.bd-total span { color: var(--fg-2); font-weight: 600; }
.bd-total b { font-size: 19px; color: var(--accent); }

.rent-note {
  margin-top: 12px; color: var(--muted); font-size: 12.5px;
  line-height: 1.5; text-align: center; padding: 0 6px;
}

/* ─── Sticky pay bar ───────────────────────────────────────── */
.paybar-spacer { height: 92px; }
.paybar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  background: linear-gradient(180deg, rgba(13,13,18,.4), var(--bg) 45%);
  backdrop-filter: blur(14px);
  padding: 10px 14px calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--border-2);
}
.paybar-inner {
  max-width: 540px; margin: 0 auto;
  display: flex; align-items: center; gap: 12px;
}
.paybar-sum { display: flex; flex-direction: column; line-height: 1.15; flex: 0 0 auto; }
.paybar-sum span { color: var(--muted); font-size: 11px; }
.paybar-sum b { font-size: 20px; font-weight: 800; color: var(--accent); }
.paybtn {
  flex: 1;
  appearance: none; border: none; cursor: pointer;
  background: var(--accent); color: #181818;
  font-weight: 800; font-size: 15px; font-family: inherit;
  padding: 15px 16px; border-radius: 14px;
  box-shadow: 0 8px 22px -8px var(--accent-strong);
  transition: transform .1s;
}
.paybtn:active { transform: scale(.98); }

@media (min-width: 720px) {
  #view { max-width: 720px; padding-top: 18px; }
  .grid { grid-template-columns: repeat(3, 1fr); }
  .paybar-inner { max-width: 720px; }
}

/* ─── Bottom nav (Маркет / Мои аренды) ─────────────────────── */
#view { padding-bottom: calc(80px + var(--safe-bottom)); }
.botnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; gap: 8px; justify-content: center;
  padding: 8px 14px calc(8px + var(--safe-bottom));
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  backdrop-filter: blur(16px); border-top: 1px solid var(--border-2);
}
.botnav.hide { display: none; }
.botnav .bn {
  flex: 1; max-width: 240px; border: none; background: transparent; cursor: pointer;
  color: var(--muted); border-radius: 14px; padding: 8px 6px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 11px; font-weight: 600; font-family: inherit; transition: .15s;
}
.botnav .bn svg { width: 22px; height: 22px; }
.botnav .bn.on { color: #181818; background: var(--accent); }

/* ─── My rentals ───────────────────────────────────────────── */
.mr-head { margin: 4px 2px 14px; }
.mr-head .t { font-size: 26px; font-weight: 820; margin: 0; }
.mr-head .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.mr-card {
  background: var(--bg-3); border: 1px solid var(--border-2);
  border-radius: var(--radius-lg); padding: 14px; margin-bottom: 11px;
}
.mr-top { display: flex; align-items: center; gap: 13px; }
.mr-img {
  width: 56px; height: 56px; border-radius: 14px; flex: 0 0 auto;
  object-fit: cover; background: #0d0d12; display: grid; place-items: center;
}
.mr-img.mr-tg { background: radial-gradient(120% 100% at 50% 0%, #1a2536, #0f1218); }
.mr-info { flex: 1; min-width: 0; }
.mr-name { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mr-timer {
  margin-top: 4px; font-size: 15px; font-weight: 700; color: var(--good);
  font-variant-numeric: tabular-nums; letter-spacing: .3px;
}
.mr-timer.exp { color: var(--bad); }
.mr-ext {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  margin-top: 13px; padding: 12px; border-radius: 12px; cursor: pointer;
  background: var(--bg-4); border: 1px solid var(--border);
  color: var(--fg); font-weight: 650; font-size: 14px; text-decoration: none;
}
.mr-ext:active { transform: scale(.98); }
.empty-hint { color: var(--muted); font-size: 12.5px; margin-top: 6px; }
.empty svg { color: var(--muted); margin-bottom: 12px; }

/* ─── Filter chips (gifts) ─────────────────────────────────── */
.fchips { display: flex; gap: 7px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.fchips::-webkit-scrollbar { display: none; }
.fchip {
  flex: 0 0 auto; border: 1px solid var(--border); background: var(--bg-3);
  color: var(--fg-2); border-radius: 999px; padding: 9px 15px; cursor: pointer;
  font-size: 13px; font-weight: 600; font-family: inherit; white-space: nowrap; transition: .15s;
}
.fchip:active { transform: scale(.96); }
.fchip.on { background: var(--accent-soft, color-mix(in srgb, var(--accent) 18%, transparent));
  border-color: var(--accent); color: var(--accent); }
.fchip.fsort { margin-left: auto; color: var(--muted); }

/* ─── Bottom sheet ─────────────────────────────────────────── */
.sheet-ov {
  position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.5);
  opacity: 0; transition: opacity .2s; display: flex; align-items: flex-end;
}
.sheet-ov.show { opacity: 1; }
.sheet {
  width: 100%; max-width: 540px; margin: 0 auto;
  background: var(--bg-2); border-radius: 20px 20px 0 0;
  max-height: 70vh; display: flex; flex-direction: column;
  transform: translateY(100%); transition: transform .24s cubic-bezier(.22,1,.36,1);
  padding-bottom: var(--safe-bottom);
}
.sheet-ov.show .sheet { transform: translateY(0); }
.sheet-h {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px 12px; font-weight: 750; font-size: 16px;
  border-bottom: 1px solid var(--border-2);
}
.sheet-x { background: var(--bg-4); border: none; color: var(--fg); width: 30px; height: 30px;
  border-radius: 50%; cursor: pointer; font-size: 14px; }
.sheet-list { overflow-y: auto; padding: 8px; }
.sheet-i {
  display: block; width: 100%; text-align: left; border: none; cursor: pointer;
  background: transparent; color: var(--fg); padding: 13px 14px; border-radius: 12px;
  font-size: 14.5px; font-family: inherit;
}
.sheet-i:active { background: var(--bg-3); }
.sheet-i.dis { color: var(--muted); font-size: 12.5px; }
