:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f3f5);
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #777777);
  --link: var(--tg-theme-link-color, #2a7fd4);
  --btn: var(--tg-theme-button-color, #2a7fd4);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --line: rgba(128, 128, 128, 0.22);
  --danger: #d9534f;
  --ok: #2e9e5b;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font: 16px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
body { overscroll-behavior-y: none; }
button { font: inherit; color: inherit; }
#app { min-height: 100vh; display: flex; flex-direction: column; }
.screen { flex: 1; display: flex; flex-direction: column; }
.center { align-items: center; justify-content: center; text-align: center; padding: 24px 16px; gap: 10px; }
.big { font-size: 56px; }
h2 { margin: 6px 0; font-size: 20px; }
p.hint, .hint { color: var(--hint); font-size: 14px; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--btn); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.95em; background: var(--bg2); padding: 1px 5px; border-radius: 5px; }

/* top bar */
.top { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 8px 12px 6px; border-bottom: 1px solid var(--line); }
.top .row { display: flex; gap: 8px; align-items: center; }
.top h1 { font-size: 17px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search { display: flex; align-items: center; gap: 6px; background: var(--bg2); border-radius: 12px; padding: 0 10px; flex: 1; height: 40px; }
.search input { flex: 1; border: 0; background: transparent; outline: none; font-size: 16px; min-width: 0; color: var(--text); }
.search .x { border: 0; background: transparent; color: var(--hint); font-size: 18px; padding: 4px; display: none; }
.search.has .x { display: block; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 8px 0 2px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; border: 1px solid var(--line); background: var(--bg2); border-radius: 999px; padding: 6px 12px; font-size: 13px; white-space: nowrap; }
.chip.on { background: var(--btn); color: var(--btn-text); border-color: var(--btn); }
.iconbtn { position: relative; border: 0; background: var(--bg2); border-radius: 12px; height: 40px; min-width: 40px; padding: 0 10px; font-size: 18px; display: flex; align-items: center; gap: 4px; }
.badge { position: absolute; top: -5px; right: -5px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; border-radius: 999px; min-width: 18px; height: 18px; padding: 0 5px; display: flex; align-items: center; justify-content: center; }

/* gallery */
.note { padding: 8px 12px 0; font-size: 13px; color: var(--hint); }
.note.warn { color: #b8860b; }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; padding: 10px 12px calc(90px + var(--safe-b)); }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 820px) { .grid { grid-template-columns: repeat(4, 1fr); } }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; text-align: left; padding: 0; cursor: pointer; }
.card.off { opacity: 0.6; }
.ph { aspect-ratio: 4 / 3; background: var(--bg2); display: flex; align-items: center; justify-content: center; color: var(--hint); font-size: 13px; overflow: hidden; }
.ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ph.big { aspect-ratio: 4 / 3; border-radius: 12px; }
.cbody { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 4px; }
.name { font-size: 14px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 2.5em; }
.price { font-weight: 700; font-size: 15px; }
.na { color: var(--danger); font-size: 12px; font-weight: 600; }
.stock { color: var(--hint); font-size: 12px; }
.stock b { color: var(--text); }
.incart { color: var(--ok); font-size: 12px; font-weight: 600; }
.more { margin: 4px 12px 20px; }
.empty { padding: 40px 16px; text-align: center; color: var(--hint); }

/* buttons */
.btn { display: flex; align-items: center; justify-content: center; gap: 6px; width: 100%; border: 0; border-radius: 12px; background: var(--btn); color: var(--btn-text); font-weight: 600; font-size: 16px; height: 48px; cursor: pointer; }
.btn:disabled { opacity: 0.45; }
.btn.sec { background: var(--bg2); color: var(--text); }
.btn.danger { background: transparent; color: var(--danger); }
.btn.sm { height: 40px; font-size: 14px; width: auto; padding: 0 14px; }
.fab { position: fixed; left: 12px; right: 12px; bottom: calc(12px + var(--safe-b)); z-index: 6; box-shadow: 0 6px 20px rgba(0,0,0,0.18); }

/* bottom sheet */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 20; display: flex; align-items: flex-end; }
.sheet { background: var(--bg); width: 100%; max-height: 92vh; overflow-y: auto; border-radius: 18px 18px 0 0; padding: 10px 16px calc(16px + var(--safe-b)); }
.sheet .grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 12px; }
.sheet h3 { margin: 10px 0 4px; font-size: 18px; line-height: 1.25; }
.meta { color: var(--hint); font-size: 13px; }
.qty { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 16px 0; }
.qty button { width: 52px; height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg2); font-size: 24px; }
.qty input { width: 90px; height: 48px; text-align: center; font-size: 20px; font-weight: 700; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); color: var(--text); }
.sheet .price { font-size: 20px; margin-top: 6px; }

/* cart */
.list { padding: 0 12px calc(120px + var(--safe-b)); }
.line { display: flex; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); align-items: center; }
.line .thumb { width: 54px; height: 54px; border-radius: 10px; flex: 0 0 auto; }
.line .info { flex: 1; min-width: 0; }
.line .info .name { min-height: 0; }
.line .ctr { display: flex; align-items: center; gap: 2px; }
.line .ctr button { width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line); background: var(--bg2); font-size: 18px; }
.line .ctr span { min-width: 30px; text-align: center; font-weight: 700; }
.line .del { border: 0; background: transparent; color: var(--danger); font-size: 18px; padding: 6px; }
.total { display: flex; justify-content: space-between; font-size: 18px; font-weight: 700; padding: 14px 0 6px; }
textarea { width: 100%; min-height: 64px; border: 1px solid var(--line); border-radius: 12px; padding: 10px; font: inherit; background: var(--bg2); color: var(--text); resize: vertical; }
.bottom { position: fixed; left: 0; right: 0; bottom: 0; padding: 10px 12px calc(10px + var(--safe-b)); background: var(--bg); border-top: 1px solid var(--line); z-index: 6; display: flex; flex-direction: column; gap: 8px; }
.err { color: var(--danger); font-size: 14px; padding: 8px 12px; }
.toast { position: fixed; left: 50%; bottom: calc(80px + var(--safe-b)); transform: translateX(-50%); background: rgba(30,30,30,0.92); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 30; max-width: 90vw; text-align: center; }
.done .big { font-size: 64px; }
.done code { font-size: 18px; padding: 4px 8px; }
.row2 { display: flex; gap: 8px; }
.row2 .btn { flex: 1; }
