:root {
  --bg: var(--tg-theme-bg-color, #0f1115);
  --bg2: var(--tg-theme-secondary-bg-color, #171a21);
  --text: var(--tg-theme-text-color, #f2f3f5);
  --hint: var(--tg-theme-hint-color, #8b8f98);
  --accent: var(--tg-theme-button-color, #4c8dff);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: rgba(127, 127, 127, 0.2);
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.28);
  --radius: 18px;
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  font-size: 15px;
  line-height: 1.35;
}

body { min-height: 100vh; padding-bottom: env(safe-area-inset-bottom); }

#app { padding: 16px 14px 0; max-width: 720px; margin: 0 auto; }

.top { padding: 6px 2px 14px; }
.eyebrow {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--hint);
  margin-bottom: 6px;
}
h1 { font-size: 26px; line-height: 1.15; margin: 0 0 6px; font-weight: 700; }
.meta { color: var(--hint); font-size: 13.5px; }

.filters { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 6px 0 10px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  border-radius: 999px;
  padding: 8px 13px;
  font-size: 13px;
  cursor: pointer;
  transition: 0.15s;
}
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }

.range { display: flex; gap: 8px; align-items: center; }
.range input {
  flex: 1;
  min-width: 0;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.range input::placeholder { color: var(--hint); }
.range button {
  border: 0;
  background: var(--accent);
  color: var(--accent-text);
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 14px;
}
.count { margin-top: 8px; color: var(--hint); font-size: 12.5px; }

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 4px 0 calc(24px + env(safe-area-inset-bottom));
}
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

.card {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.12s ease;
}
.card:active { transform: scale(0.98); }

.thumb {
  position: relative;
  aspect-ratio: 1 / 1;
  background: linear-gradient(135deg, rgba(127,127,127,.16), rgba(127,127,127,.05));
  display: grid;
  place-items: center;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb img.failed { display: none; }
.thumb .ph { font-size: 34px; opacity: 0.35; }
.thumb img:not(.failed) + .ph { display: none; }

.badge {
  position: absolute;
  left: 8px;
  top: 8px;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  background: rgba(20, 22, 26, 0.72);
  backdrop-filter: blur(8px);
}
.badge.mine { background: rgba(38, 160, 96, 0.9); }

.card-body { padding: 10px 11px 12px; }
.card-title {
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.28;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.55em;
}
.card-price { margin-top: 6px; font-size: 14px; font-weight: 700; color: var(--text); }
.card-price.empty { color: var(--hint); font-weight: 500; font-size: 12.5px; }

.empty, .error { text-align: center; padding: 56px 20px; color: var(--hint); }
.empty-icon { font-size: 44px; margin-bottom: 10px; }
.ghost {
  display: inline-block;
  margin-top: 14px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 14px;
  text-decoration: none;
}
.cta {
  display: inline-block;
  margin-top: 16px;
  background: var(--accent);
  color: var(--accent-text);
  padding: 12px 20px;
  border-radius: 14px;
  text-decoration: none;
  font-weight: 600;
}

.loader { display: flex; justify-content: center; gap: 6px; padding: 40px; }
.loader span {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--hint);
  animation: pulse 1s infinite ease-in-out;
}
.loader span:nth-child(2) { animation-delay: 0.15s; }
.loader span:nth-child(3) { animation-delay: 0.3s; }
@keyframes pulse { 0%, 100% { opacity: 0.25; transform: scale(0.8); } 50% { opacity: 1; transform: scale(1); } }

.sheet { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.55); backdrop-filter: blur(2px); }
.sheet-card {
  position: relative;
  width: 100%;
  max-width: 640px;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--bg2);
  border-radius: 24px 24px 0 0;
  box-shadow: var(--shadow);
  animation: up 0.2s ease-out;
}
@keyframes up { from { transform: translateY(20px); opacity: 0.6; } to { transform: translateY(0); opacity: 1; } }
.sheet-grab { width: 40px; height: 4px; border-radius: 99px; background: var(--line); margin: 8px auto; }
.sheet-close {
  position: absolute; right: 10px; top: 10px;
  width: 34px; height: 34px; border-radius: 50%;
  border: 0; background: rgba(20,22,26,.55); color: #fff; font-size: 15px;
}
.sheet-media {
  position: relative;
  margin: 4px 14px 0;
  border-radius: 18px;
  overflow: hidden;
  aspect-ratio: 4 / 3;
  background: linear-gradient(135deg, rgba(127,127,127,.18), rgba(127,127,127,.06));
  display: grid;
  place-items: center;
}
.sheet-media img { width: 100%; height: 100%; object-fit: contain; display: block; }
.sheet-media img.failed { display: none; }
.sheet-media .ph { font-size: 46px; opacity: 0.3; }
.sheet-media img:not(.failed) + .ph { display: none; }
.sheet-body { padding: 14px 18px calc(22px + env(safe-area-inset-bottom)); }
.sheet-body h2 { font-size: 21px; margin: 4px 0 8px; line-height: 1.2; }
.sheet-price { font-size: 20px; font-weight: 700; margin-bottom: 8px; }
.sheet-note { color: var(--hint); font-size: 14px; margin: 10px 0; white-space: pre-wrap; }
.sheet-status { margin: 12px 0; font-size: 13px; color: var(--hint); }
.sheet-actions { display: flex; gap: 10px; margin-top: 14px; }
.sheet-actions button, .sheet-actions a { flex: 1; text-align: center; }
.sheet-actions .primary {
  border: 0; background: var(--accent); color: var(--accent-text);
  padding: 14px; border-radius: 14px; font-size: 15px; font-weight: 600;
}
.sheet-actions .danger {
  border: 1px solid var(--line); background: transparent; color: var(--text);
  padding: 14px; border-radius: 14px; font-size: 15px; font-weight: 600;
}
.sheet-actions button:disabled { opacity: 0.5; }
.link { display: block; text-align: center; margin-top: 10px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: rgba(25, 27, 32, 0.95); color: #fff;
  padding: 10px 16px; border-radius: 12px; font-size: 13.5px;
  opacity: 0; pointer-events: none; transition: 0.2s; z-index: 100;
  max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.hidden { display: none !important; }
