:root {
  color-scheme: light dark;
  --page-bg: var(--tg-theme-bg-color, #f4f5f7);
  --card-bg: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #17212b);
  --muted: var(--tg-theme-hint-color, #6d7885);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #168acd);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

:root[data-theme="light"] { color-scheme: light; }

body {
  margin: 0;
  min-width: 280px;
  min-height: 100vh;
  background: var(--page-bg);
  color: var(--text);
}

button, a { font: inherit; }

button:focus-visible, a:focus-visible {
  outline: 3px solid var(--link);
  outline-offset: 3px;
}

.store-header, main, .notice, .status {
  width: min(100% - 24px, 920px);
  margin-inline: auto;
}

.store-header { padding: 20px 0 12px; }
.store-header h1 { margin: 0; font-size: clamp(1.45rem, 6vw, 2rem); }
.support { margin: 6px 0 0; color: var(--muted); overflow-wrap: anywhere; }
.app-nav { display: flex; gap: 7px; overflow-x: auto; margin-top: 14px; padding: 2px 2px 8px; }
.nav-button {
  flex: 0 0 auto;
  border: 0;
  border-radius: 999px;
  padding: 8px 12px;
  background: var(--card-bg);
  color: var(--text);
  cursor: pointer;
}
.nav-button[aria-current="page"] { background: var(--accent); color: var(--accent-text); }

.notice {
  margin-bottom: 12px;
  padding: 12px 14px;
  border: 1px solid #c88a00;
  border-radius: 12px;
  background: #fff4cf;
  color: #5a3b00;
}

.notice strong { display: block; margin-bottom: 3px; }
main { padding-bottom: max(28px, env(safe-area-inset-bottom)); }

.section-title { margin: 14px 0 10px; font-size: 1rem; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 10px; scrollbar-width: thin; }
.chip, .pager button, .back, .buy {
  border: 0;
  border-radius: 999px;
  background: var(--card-bg);
  color: var(--text);
  cursor: pointer;
  padding: 9px 14px;
}
.chip { flex: 0 0 auto; }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(145px, 1fr));
  gap: 12px;
}

.product-card {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 14px;
  overflow: hidden;
  background: var(--card-bg);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  box-shadow: 0 1px 4px rgb(0 0 0 / 10%);
}

.thumb {
  display: grid;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  background: color-mix(in srgb, var(--card-bg) 84%, var(--muted));
}
.thumb > * { grid-area: 1 / 1; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.placeholder { display: grid; place-items: center; font-size: 2.2rem; color: var(--muted); }
.card-copy { display: grid; gap: 7px; align-content: space-between; padding: 11px; }
.card-title { font-weight: 650; overflow-wrap: anywhere; }
.price { color: var(--accent); font-weight: 750; }

.pager { display: flex; justify-content: center; gap: 10px; margin-top: 16px; }
.pager button:disabled { opacity: .45; cursor: default; }
.empty, .status { color: var(--muted); text-align: center; }
.status { padding: 20px 0; }

.detail { display: grid; gap: 16px; }
.detail-photo { width: 100%; aspect-ratio: 16 / 10; object-fit: cover; border-radius: 14px; background: var(--card-bg); }
.detail h2, .detail p { margin: 0; }
.description { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.5; }
.variants { margin: 0; padding-left: 22px; }
.variants li + li { margin-top: 7px; }
.buy { width: 100%; border-radius: 12px; background: var(--accent); color: var(--accent-text); font-weight: 700; }
.back { justify-self: start; padding-inline: 0; background: transparent; color: var(--link); }

.variant-choices { display: grid; gap: 8px; margin: 0; padding: 0; border: 0; }
.variant-choice {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-radius: 12px;
  background: var(--card-bg);
  cursor: pointer;
}
.variant-choice input { accent-color: var(--accent); }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.list-view { display: grid; gap: 10px; }
.section-heading { margin: 8px 0 2px; font-size: 1.2rem; }
.list-card {
  display: grid;
  gap: 8px;
  padding: 14px;
  border-radius: 14px;
  background: var(--card-bg);
  box-shadow: 0 1px 4px rgb(0 0 0 / 8%);
}
.list-card h3, .list-card p { margin: 0; overflow-wrap: anywhere; }
.cart-line, .file-line { grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
.list-copy { display: grid; gap: 6px; min-width: 0; }
.quantity-controls { display: flex; align-items: center; gap: 8px; }
.quantity-button, .secondary-button {
  border: 0;
  border-radius: 10px;
  background: color-mix(in srgb, var(--card-bg) 78%, var(--accent));
  color: var(--text);
  cursor: pointer;
  min-width: 38px;
  min-height: 38px;
  padding: 8px 11px;
}
.quantity-button:disabled, .secondary-button:disabled { opacity: .45; cursor: default; }
.quantity { min-width: 2ch; text-align: center; font-weight: 700; }
.secondary-button { color: var(--accent); font-weight: 700; }
.cart-total { margin: 6px 0; text-align: right; font-size: 1.08rem; font-weight: 750; }
.coupon {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.coupon-line { margin: 0; font-weight: 650; overflow-wrap: anywhere; }
.cart-refusal { margin: 6px 0; font-weight: 650; overflow-wrap: anywhere; }
.referral-line, .referral-note { margin: 0; text-align: right; overflow-wrap: anywhere; }
.referral-note { color: var(--muted); font-size: .92rem; }
.coupon-form { display: flex; gap: 8px; width: 100%; }
.coupon-form input {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 38px;
  padding: 8px 11px;
  border: 1px solid color-mix(in srgb, var(--muted) 45%, transparent);
  border-radius: 10px;
  background: var(--card-bg);
  color: var(--text);
  font: inherit;
  text-transform: uppercase;
}
.coupon-form input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.unavailable { color: #b44; font-weight: 650; }
.muted { color: var(--muted); }
.order-status { color: var(--muted); }
.order-status.paid { color: #238636; }
.order-status.refunded { color: #a15c00; }

:root[data-theme="dark"] {
  color-scheme: dark;
  --page-bg: var(--tg-theme-bg-color, #17212b);
  --card-bg: var(--tg-theme-secondary-bg-color, #232e3c);
  --text: var(--tg-theme-text-color, #f5f5f5);
  --muted: var(--tg-theme-hint-color, #a8b0b8);
}

:root[data-theme="dark"] .notice { background: #493800; color: #ffe8a3; border-color: #a67c00; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --page-bg: var(--tg-theme-bg-color, #17212b);
    --card-bg: var(--tg-theme-secondary-bg-color, #232e3c);
    --text: var(--tg-theme-text-color, #f5f5f5);
    --muted: var(--tg-theme-hint-color, #a8b0b8);
  }
}
