:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --surface: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --surface-alt: var(--tg-theme-secondary-bg-color, #f2f3f5);
  --text: var(--tg-theme-text-color, #0f0f0f);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --subtitle: var(--tg-theme-subtitle-text-color, var(--tg-theme-hint-color, #8a8f98));
  --link: var(--tg-theme-link-color, #2a7cdb);
  --accent: var(--tg-theme-button-color, #2a7cdb);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #e5484d);

  --radius-lg: 18px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --tabbar-height: 58px;

  --border: color-mix(in srgb, var(--hint) 22%, transparent);
  --shadow: 0 1px 2px color-mix(in srgb, #000 8%, transparent),
    0 8px 24px color-mix(in srgb, #000 6%, transparent);
}

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

/* Class-level `display` beats the UA rule for [hidden], so state it explicitly —
   without this the boot and error overlays stay painted over the app. */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto,
    'Helvetica Neue', sans-serif;
  font-size: 16px;
  line-height: 1.45;
  overscroll-behavior-y: none;
}

body {
  min-height: 100dvh;
}

button {
  font: inherit;
  color: inherit;
  border: none;
  background: none;
  cursor: pointer;
}

/* ---------- boot / fatal ---------- */

.boot {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  background: var(--bg);
  z-index: 50;
}

.boot__spinner {
  width: 28px;
  height: 28px;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.boot__text {
  margin: 0;
  color: var(--hint);
  font-size: 14px;
}

.fatal {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  padding: 24px;
  background: var(--bg);
  z-index: 60;
}

.fatal__card {
  text-align: center;
  max-width: 320px;
}

.fatal__emoji {
  font-size: 40px;
  margin: 0 0 8px;
}

.fatal__title {
  margin: 0 0 8px;
  font-size: 19px;
}

.fatal__text {
  margin: 0 0 20px;
  color: var(--hint);
  font-size: 14px;
}

/* ---------- layout ---------- */

.app {
  padding-bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom, 0px) + 12px);
}

.screen {
  animation: fade 0.18s ease;
}

@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
}

.masthead {
  padding: 20px 16px 12px;
}

.masthead--compact {
  padding-bottom: 6px;
}

.masthead__eyebrow {
  margin: 0 0 2px;
  font-size: 13px;
  font-weight: 590;
  color: var(--accent);
  letter-spacing: 0.01em;
}

.masthead__title {
  margin: 0;
  font-size: 26px;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.masthead__sub {
  margin: 8px 0 0;
  font-size: 14px;
  color: var(--subtitle);
}

.footnote {
  margin: 18px 16px 0;
  font-size: 12.5px;
  color: var(--hint);
  text-align: center;
}

/* ---------- chips ---------- */

.chips {
  display: flex;
  gap: 8px;
  padding: 4px 16px 14px;
  overflow-x: auto;
  scrollbar-width: none;
}

.chips::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: 0 0 auto;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--surface-alt);
  color: var(--text);
  font-size: 14px;
  font-weight: 510;
  transition: background 0.15s ease, color 0.15s ease;
}

.chip[aria-selected='true'] {
  background: var(--accent);
  color: var(--accent-text);
}

/* ---------- product grid ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  padding: 0 16px;
}

@media (max-width: 340px) {
  .grid {
    grid-template-columns: 1fr;
  }
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  text-align: left;
  padding: 12px;
  border-radius: var(--radius-lg);
  background: var(--surface-alt);
  transition: transform 0.12s ease;
}

.card:active {
  transform: scale(0.975);
}

.card__cover {
  display: grid;
  place-content: center;
  aspect-ratio: 1.45;
  margin-bottom: 10px;
  border-radius: var(--radius-md);
  font-size: 34px;
  background: linear-gradient(
    145deg,
    color-mix(in srgb, var(--card-accent, var(--accent)) 26%, transparent),
    color-mix(in srgb, var(--card-accent, var(--accent)) 9%, transparent)
  );
}

/* With real artwork the box stops being an emoji holder and becomes a frame. */
.card__cover--photo,
.hero--photo,
.row__cover--photo {
  display: block;
  background: var(--surface-alt);
  overflow: hidden;
}

.card__cover img,
.hero img,
.row__cover img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card__title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.card__sub {
  margin: 3px 0 0;
  font-size: 12.5px;
  color: var(--subtitle);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  /* auto keeps the price line flush with the bottom whatever the title height */
  margin-top: auto;
  padding-top: 10px;
}

.price {
  font-size: 15px;
  font-weight: 680;
  white-space: nowrap;
}

.price--lg {
  font-size: 20px;
}

.card__add {
  display: grid;
  place-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 19px;
  line-height: 1;
  flex: 0 0 auto;
}

.card__add[data-in-cart='true'] {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  color: var(--accent);
}

.badge {
  position: absolute;
  top: 18px;
  right: 18px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 11px;
  font-weight: 620;
}

/* ---------- product detail ---------- */

.hero {
  display: grid;
  place-content: center;
  aspect-ratio: 1.9;
  font-size: 68px;
  background: linear-gradient(
    145deg,
    color-mix(in srgb, var(--card-accent, var(--accent)) 30%, transparent),
    color-mix(in srgb, var(--card-accent, var(--accent)) 8%, transparent)
  );
}

.detail {
  padding: 18px 16px 8px;
}

.detail__title {
  margin: 0;
  font-size: 23px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.detail__sub {
  margin: 6px 0 0;
  color: var(--subtitle);
  font-size: 14.5px;
}

.detail__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
}

.detail__text {
  margin: 16px 0 0;
  font-size: 15px;
  color: var(--text);
}

.section-title {
  margin: 24px 0 8px;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--tg-theme-section-header-text-color, var(--hint));
}

.list {
  margin: 0;
  padding: 0;
  list-style: none;
  border-radius: var(--radius-md);
  background: var(--surface-alt);
  overflow: hidden;
}

.list__item {
  display: flex;
  gap: 10px;
  padding: 11px 14px;
  font-size: 14.5px;
}

.list__item + .list__item {
  border-top: 1px solid var(--border);
}

.list__mark {
  color: var(--accent);
  flex: 0 0 auto;
}

/* ---------- cart ---------- */

.rows {
  padding: 8px 16px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius-md);
  background: var(--surface-alt);
}

.row__cover {
  display: grid;
  place-content: center;
  width: 46px;
  height: 46px;
  border-radius: var(--radius-sm);
  font-size: 22px;
  flex: 0 0 auto;
  background: color-mix(in srgb, var(--card-accent, var(--accent)) 18%, transparent);
}

.row__body {
  flex: 1;
  min-width: 0;
}

.row__title {
  margin: 0;
  font-size: 14.5px;
  font-weight: 590;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row__meta {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--subtitle);
}

.stepper {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--surface);
  padding: 2px;
}

.stepper__btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-content: center;
  font-size: 17px;
  color: var(--accent);
}

.stepper__value {
  min-width: 20px;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
}

.total {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 18px 16px 0;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.total__label {
  font-size: 15px;
  color: var(--subtitle);
}

/* ---------- orders ---------- */

.order {
  padding: 13px 14px;
  border-radius: var(--radius-md);
  background: var(--surface-alt);
}

.order__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.order__date {
  font-size: 12.5px;
  color: var(--hint);
}

.order__items {
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  font-size: 14px;
}

.order__item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 2px 0;
}

.order__qty {
  color: var(--hint);
}

.pill {
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 620;
  background: color-mix(in srgb, #2ea043 18%, transparent);
  color: #2ea043;
}

.pill--refunded {
  background: color-mix(in srgb, var(--danger) 16%, transparent);
  color: var(--danger);
}

/* ---------- empty ---------- */

.empty {
  padding: 56px 32px;
  text-align: center;
}

.empty__emoji {
  font-size: 42px;
  margin: 0 0 10px;
}

.empty__title {
  margin: 0 0 6px;
  font-size: 17px;
  font-weight: 620;
}

.empty__text {
  margin: 0 0 18px;
  font-size: 14px;
  color: var(--hint);
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 600;
  transition: opacity 0.15s ease;
}

.btn:active {
  opacity: 0.7;
}

.btn--primary {
  background: var(--accent);
  color: var(--accent-text);
}

.btn--quiet {
  background: var(--surface-alt);
  color: var(--text);
}

.btn--link {
  padding: 8px 0;
  color: var(--link);
  font-weight: 560;
}

.btn--danger {
  color: var(--danger);
}

.btn--block {
  width: 100%;
}

.btn-row {
  display: flex;
  gap: 8px;
  margin: 14px 16px 0;
}

/* ---------- tabbar ---------- */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  height: calc(var(--tabbar-height) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--border);
}

.tab {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--hint);
  transition: color 0.15s ease;
}

.tab[aria-selected='true'] {
  color: var(--accent);
}

.tab__icon {
  font-size: 19px;
  line-height: 1;
}

.tab__label {
  font-size: 10.5px;
  font-weight: 560;
}

.tab__badge {
  position: absolute;
  top: 6px;
  left: calc(50% + 7px);
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom, 0px) + 16px);
  transform: translate(-50%, 12px);
  z-index: 40;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--text) 86%, transparent);
  color: var(--bg);
  font-size: 13.5px;
  font-weight: 550;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast[data-visible='true'] {
  opacity: 1;
  transform: translate(-50%, 0);
}
