:root {
  --red: #d71f26;
  --red-dark: #b3161c;
  --red-soft: #fdecec;
  --ink: #1c1d21;
  --muted: #6b7079;
  --line: #e7e8ec;
  --surface: #f4f5f7;
  --bg: #ffffff;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.5 var(--font); color: var(--ink); background: var(--bg); }
img { max-width: 100%; display: block; }
a { color: inherit; }
h1, h2, h3 { line-height: 1.25; margin: 0; }
button, input, textarea { font: inherit; color: inherit; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
.narrow { max-width: 760px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
[hidden] { display: none !important; }

/* Header */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--bg); border-bottom: 1px solid var(--line); }
.topbar-in { display: flex; align-items: center; gap: 12px; height: 60px; }
.logo { font-weight: 900; font-size: 22px; letter-spacing: .06em; text-decoration: none; color: #fff; background: var(--red); padding: 2px 10px; border-radius: 6px; }
.search { flex: 1; display: flex; align-items: center; gap: 8px; background: var(--surface); border-radius: 999px; padding: 0 14px; height: 40px; color: var(--muted); min-width: 0; }
.search input { border: 0; background: transparent; outline: none; flex: 1; min-width: 0; color: var(--ink); height: 100%; }
.cart-link { margin-left: auto; position: relative; display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; text-decoration: none; }
.cart-link:hover { background: var(--surface); }
.cart-count { position: absolute; top: 4px; right: 2px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--red); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }

/* Category tiles (Grab-style) */
.cats-section { padding: 16px 0 4px; }
.cats { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 16px 8px; }
.cat { appearance: none; border: 0; background: none; padding: 0; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.cat-icon { width: 72px; height: 72px; border-radius: 20px; background: var(--surface); display: grid; place-items: center; overflow: hidden; color: var(--red); border: 2px solid transparent; transition: border-color .15s, transform .15s; }
.cat-icon img { width: 100%; height: 100%; object-fit: cover; }
.cat-label { font-size: 12px; line-height: 1.25; text-align: center; max-width: 88px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.cat:hover .cat-icon { transform: translateY(-2px); }
.cat.active .cat-icon { border-color: var(--red); }
.cat.active .cat-label { color: var(--red); font-weight: 600; }
@media (min-width: 900px) {
  .cats { grid-template-columns: repeat(12, minmax(0, 1fr)); }
  .cat-icon { width: 80px; height: 80px; }
}
@media (max-width: 520px) {
  .cats { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px 4px; }
  .cat-icon { width: 64px; height: 64px; border-radius: 18px; }
}

/* Product grid */
.products-section { padding: 20px 16px 48px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 14px; }
.section-head h1 { font-size: 20px; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (min-width: 700px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; } }
@media (min-width: 1000px) { .grid { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.card { text-decoration: none; border-radius: var(--radius); background: var(--bg); border: 1px solid var(--line); overflow: hidden; display: flex; flex-direction: column; transition: box-shadow .15s, transform .15s; }
.card:hover { box-shadow: 0 6px 20px rgba(0,0,0,.08); transform: translateY(-2px); }
.card-img { position: relative; aspect-ratio: 1; background: var(--surface); }
.card-img img { width: 100%; height: 100%; object-fit: cover; }
.card-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.card h3 { font-size: 14px; font-weight: 500; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.price { color: var(--red); font-weight: 700; margin: auto 0 0; }
.price small { font-size: 12px; font-weight: 500; color: var(--muted); }
.badge { position: absolute; top: 8px; left: 8px; background: var(--red); color: #fff; font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; }
.badge-out { left: auto; right: 8px; background: rgba(28,29,33,.8); }
.badge-inline { position: static; display: inline-block; margin-bottom: 8px; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* Product page */
.product { padding: 16px 16px 56px; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 14px; }
.crumbs a { text-decoration: none; }
.crumbs a:hover { color: var(--red); }
.product-grid { display: grid; gap: 24px; }
@media (min-width: 860px) { .product-grid { grid-template-columns: 1.1fr 1fr; gap: 40px; } }
.gallery-main { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; border-radius: var(--radius); background: var(--surface); scrollbar-width: none; }
.gallery-main::-webkit-scrollbar { display: none; }
.gallery-main img { flex: 0 0 100%; aspect-ratio: 1; object-fit: contain; scroll-snap-align: start; }
.thumbs { display: flex; gap: 8px; margin-top: 10px; overflow-x: auto; }
.thumb { flex: 0 0 64px; height: 64px; padding: 0; border: 2px solid transparent; border-radius: 10px; overflow: hidden; background: var(--surface); cursor: pointer; }
.thumb.active { border-color: var(--red); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.buybox h1 { font-size: 22px; margin-bottom: 8px; }
.price.big { font-size: 26px; margin-bottom: 16px; }
.opt-group { margin-bottom: 16px; }
.opt-group h4 { margin: 0 0 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1.5px solid var(--line); background: var(--bg); border-radius: 10px; padding: 7px 12px; font-size: 13px; cursor: pointer; }
.chip:hover { border-color: #c9cbd1; }
.chip.active { border-color: var(--red); color: var(--red); background: var(--red-soft); font-weight: 600; }
.chip.unavailable { color: #b0b3ba; text-decoration: line-through; }
.qty-row { display: flex; align-items: center; gap: 14px; margin: 4px 0 18px; }
.qty { display: inline-flex; border: 1.5px solid var(--line); border-radius: 10px; overflow: hidden; }
.qty button { width: 38px; height: 38px; border: 0; background: var(--surface); cursor: pointer; font-size: 18px; }
.qty input { width: 48px; border: 0; text-align: center; -moz-appearance: textfield; }
.qty input::-webkit-outer-spin-button, .qty input::-webkit-inner-spin-button { -webkit-appearance: none; }
.btn { display: flex; align-items: center; justify-content: center; width: 100%; height: 50px; border-radius: 12px; font-weight: 700; font-size: 16px; text-decoration: none; cursor: pointer; border: 0; margin-bottom: 10px; }
.btn-primary { background: var(--red); color: #fff; }
.btn-primary:hover { background: var(--red-dark); }
.btn-primary:disabled { background: #e3a5a8; cursor: not-allowed; }
.btn-ghost { background: var(--surface); color: var(--ink); }
.perks { list-style: none; padding: 0; margin: 14px 0 0; font-size: 13px; color: var(--muted); }
.perks li::before { content: "✓"; color: var(--red); font-weight: 700; margin-right: 8px; }
.desc { margin-top: 36px; border-top: 1px solid var(--line); padding-top: 24px; max-width: 760px; }
.desc h2 { font-size: 18px; margin-bottom: 12px; }
.desc p { margin: 0 0 12px; color: #33353b; }

/* Cart + checkout */
.narrow h1 { font-size: 24px; margin: 20px 0 16px; }
.cart-items { display: flex; flex-direction: column; gap: 12px; }
.line { display: grid; grid-template-columns: 72px 1fr auto; gap: 12px; align-items: center; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.line img { width: 72px; height: 72px; object-fit: cover; border-radius: 10px; background: var(--surface); }
.line h3 { font-size: 14px; font-weight: 500; }
.line .opts { font-size: 12px; color: var(--muted); }
.line .qty button { width: 30px; height: 30px; }
.line .qty input { width: 36px; }
.line-right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.remove { border: 0; background: none; color: var(--muted); font-size: 12px; cursor: pointer; text-decoration: underline; }
.checkout { margin: 20px 0 48px; }
.checkout h2 { font-size: 18px; margin: 24px 0 12px; }
.totals { background: var(--surface); border-radius: var(--radius); padding: 14px 16px; }
.totals div { display: flex; justify-content: space-between; padding: 3px 0; }
.totals .grand { font-weight: 700; font-size: 18px; border-top: 1px solid var(--line); margin-top: 6px; padding-top: 10px; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.fields label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
.fields .span2 { grid-column: span 2; }
@media (max-width: 520px) { .fields { grid-template-columns: 1fr; } .fields .span2 { grid-column: auto; } }
.fields input, .fields textarea { border: 1.5px solid var(--line); border-radius: 10px; padding: 10px 12px; font-weight: 400; color: var(--ink); background: var(--bg); }
.fields input:focus, .fields textarea:focus { outline: none; border-color: var(--red); }
.fields .invalid { border-color: var(--red); }
.form-error { color: var(--red); font-weight: 600; }

/* Order page */
.order { padding: 40px 16px; text-align: center; }
.order-status { margin-bottom: 24px; }
.order-status h1 { margin: 12px 0 6px; }
.order-status .icon { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto; font-size: 30px; color: #fff; background: #1f9d55; }
.order-status .icon.wait { background: #e0a100; }
.order-status .icon.fail { background: var(--red); }
.order-details { text-align: left; }
.spinner { width: 36px; height: 36px; border: 3px solid var(--line); border-top-color: var(--red); border-radius: 50%; margin: 0 auto; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Footer + toast */
.footer { border-top: 1px solid var(--line); padding: 24px 0 40px; font-size: 13px; color: var(--muted); background: var(--surface); }
.footer p { margin: 0 0 6px; }
.footer-brand { color: var(--ink); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; opacity: 0; pointer-events: none; transition: .2s; z-index: 50; font-size: 14px; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast a { color: #fff; font-weight: 700; margin-left: 8px; }
