:root {
  --bg: var(--tg-theme-bg-color, #0f0f12);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #1a1a1f);
  --text: var(--tg-theme-text-color, #f2f2f4);
  --hint: var(--tg-theme-hint-color, #8b8b93);
  --accent: var(--tg-theme-button-color, #ff5c39);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --card: var(--tg-theme-secondary-bg-color, #17171b);
  --border: rgba(255,255,255,0.08);
}

* { box-sizing: border-box; }

.hidden { display: none; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.brand span { color: var(--accent); }

.cart-btn {
  position: relative;
  border: none;
  background: var(--card);
  color: var(--text);
  font-size: 18px;
  padding: 8px 12px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.cart-count {
  background: var(--accent);
  color: var(--accent-text);
  font-size: 12px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}

.categories {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 16px;
  scrollbar-width: none;
}
.categories::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--card);
  color: var(--hint);
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--border);
  white-space: nowrap;
}
.chip.active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
}

.feed {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 4px 16px 24px;
}

.card {
  background: var(--card);
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  cursor: pointer;
}

.card img {
  width: 100%;
  aspect-ratio: 4 / 5;
  object-fit: cover;
  display: block;
  background: #222;
}

.card-image-wrap {
  position: relative;
}

.sold-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(0, 0, 0, 0.78);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 9px;
  border-radius: 6px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.sold-label {
  color: var(--hint);
  font-size: 13px;
  font-weight: 600;
}

.gallery {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
}
.gallery::-webkit-scrollbar { display: none; }
.gallery img {
  flex: 0 0 100%;
  scroll-snap-align: start;
  width: 100%;
  aspect-ratio: 4 / 5;
  object-fit: cover;
  display: block;
  background: #222;
}

.gallery-dots {
  position: absolute;
  bottom: 10px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 6px;
}
.gallery-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  transition: width 0.15s, border-radius 0.15s;
}
.gallery-dot.active {
  width: 16px;
  border-radius: 3px;
  background: #fff;
}

.card-body {
  padding: 10px 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.card-title {
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.25;
}

.card-sub {
  font-size: 12px;
  color: var(--hint);
}

.card-bottom {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 8px;
}

.price {
  font-size: 14px;
  font-weight: 700;
}

.add-btn {
  border: none;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 13px;
  font-weight: 700;
  border-radius: 10px;
  width: 108px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}

.qty-control {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--accent);
  border-radius: 10px;
  width: 108px;
  height: 32px;
  box-sizing: border-box;
}
.qty-control button {
  border: none;
  background: transparent;
  color: var(--accent-text);
  font-size: 16px;
  font-weight: 800;
  width: 20px;
  height: 20px;
  line-height: 1;
}
.qty-control span {
  color: var(--accent-text);
  font-weight: 700;
  font-size: 13px;
  min-width: 14px;
  text-align: center;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: flex-end;
  z-index: 20;
}
.overlay.hidden { display: none; }

.sheet {
  width: 100%;
  max-height: 80vh;
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  display: flex;
  flex-direction: column;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.sheet-header h2 { margin: 0; font-size: 18px; }

.icon-btn {
  border: none;
  background: var(--card);
  color: var(--text);
  width: 30px;
  height: 30px;
  border-radius: 999px;
  font-size: 14px;
}

.cart-items {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 45vh;
}

.cart-empty {
  color: var(--hint);
  text-align: center;
  padding: 30px 0;
}
.cart-empty.hidden { display: none; }

.cart-row {
  display: flex;
  gap: 10px;
  align-items: center;
}
.cart-row img {
  width: 52px;
  height: 62px;
  border-radius: 10px;
  object-fit: cover;
  background: #222;
}
.cart-row-info { flex: 1; min-width: 0; }
.cart-row-title { font-size: 13px; font-weight: 600; }
.cart-row-price { font-size: 12px; color: var(--hint); }

.sheet-footer {
  border-top: 1px solid var(--border);
  margin-top: 12px;
  padding-top: 12px;
}
.total-row {
  display: flex;
  justify-content: space-between;
  font-size: 15px;
  margin-bottom: 4px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--card);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  border: 1px solid var(--border);
  z-index: 30;
}
.toast.hidden { display: none; }

.detail-view.hidden { display: none; }

.detail-back {
  font-size: 18px;
}

.detail-content {
  padding-bottom: 100px;
}

.detail-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.detail-category {
  font-size: 12px;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.detail-title {
  font-size: 20px;
  font-weight: 800;
  line-height: 1.25;
}

.detail-price {
  font-size: 18px;
  font-weight: 700;
}

.share-btn {
  align-self: flex-start;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--hint);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
}

.detail-description {
  font-size: 14px;
  line-height: 1.5;
  color: var(--hint);
}

.detail-action {
  margin-top: 8px;
}

.detail-action .add-btn {
  width: 100%;
  padding: 13px;
  font-size: 15px;
  border-radius: 12px;
}

.detail-action .qty-control {
  width: 100%;
  justify-content: center;
  padding: 10px;
  border-radius: 12px;
  gap: 20px;
}
.detail-action .qty-control button {
  width: 26px;
  height: 26px;
  font-size: 18px;
}
