/* Base: reset, layout, header, buttons, footer, dialogs, drawer, toast, reveal. */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs-md);
  line-height: 1.55;
  color: var(--ink);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}
img { max-width: 100%; display: block; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, h4 { line-height: 1.2; margin: 0; letter-spacing: -.01em; font-family: var(--font-display); font-weight: 600; }
p { margin: 0; }
:lang(th) h1, :lang(th) h2 { letter-spacing: -.01em; }
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip {
  position: fixed; left: 12px; top: -60px; z-index: 100; background: var(--ink); color: #fff;
  padding: 10px 16px; border-radius: var(--r-sm); text-decoration: none; transition: top var(--t-fast);
}
.skip:focus { top: 12px; }

.wrap { width: min(var(--maxw), 100% - 2 * var(--gutter)); margin-inline: auto; }
.section { padding-block: var(--s16); }
.section-head { display: flex; justify-content: space-between; align-items: end; gap: var(--s4); flex-wrap: wrap; margin-bottom: var(--s6); }
.section-head h2 { font-size: var(--fs-2xl); font-weight: 700; }
.section-head p { color: var(--ink-3); margin-top: var(--s2); max-width: 60ch; }
.eyebrow {
  display: inline-flex; align-items: center; gap: var(--s2);
  font-size: var(--fs-xs); font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--blue);
}
.muted { color: var(--ink-3); }
.small { font-size: var(--fs-sm); }

/* ---------- buttons ---------- */
.btn {
  --bg: var(--white); --fg: var(--ink); --bd: var(--line-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: var(--tap); padding: 0 var(--s5); border-radius: var(--r-pill);
  background: var(--bg); color: var(--fg); border: 1.5px solid var(--bd);
  font-weight: 700; font-size: var(--fs-md); text-decoration: none; white-space: nowrap;
  transition: transform var(--t-fast) var(--ease), background var(--t-fast), box-shadow var(--t-fast), border-color var(--t-fast);
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { border-color: var(--ink); }
.btn:active { transform: scale(.96); }
.btn-primary { --bg: var(--blue); --fg: #fff; --bd: var(--blue); box-shadow: 0 10px 24px rgba(63, 92, 232, .28); }
.btn-primary:hover { --bg: var(--blue-press); --bd: var(--blue-press); }
.btn-dark { --bg: var(--ink); --fg: #fff; --bd: var(--ink); }
.btn-dark:hover { --bg: #0e1628; }
.btn-ghost { --bg: transparent; --bd: transparent; }
.btn-ghost:hover { --bg: var(--lilac-50); --bd: transparent; }
.btn-lg { min-height: 54px; padding: 0 var(--s8); font-size: var(--fs-lg); }
.btn-block { width: 100%; }
.btn:disabled, .btn[aria-disabled="true"] {
  --bg: #E7E6EE; --fg: #6B7187; --bd: #E7E6EE; box-shadow: none; cursor: not-allowed; transform: none;
}
.icon-btn {
  width: var(--tap); height: var(--tap); border-radius: 50%; border: 0; background: var(--lilac-50);
  display: inline-grid; place-items: center; flex: none; color: var(--ink);
  transition: background var(--t-fast), transform var(--t-fast) var(--ease);
}
.icon-btn:hover { background: var(--lilac); }
.icon-btn:active { transform: scale(.92); }
.icon-btn svg, .btn svg { width: 20px; height: 20px; flex: none; }
.ico { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- header ---------- */
.site-header {
  position: sticky; top: 0; z-index: var(--z-header);
  background: rgba(255, 255, 255, .94); backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--line);
}
.header-inner { display: flex; align-items: center; gap: var(--s3); height: 64px; }
.brand { display: inline-flex; align-items: center; gap: 6px; text-decoration: none; flex: none; min-height: var(--tap); }
/* official lockups copied from /svg (never retyped). Guideline minimums: horizontal 180px, icon 32px. */
.brand img { height: auto; }
.logo-h { width: 182px; }
.logo-i { width: 56px; display: none; }
@media (max-width: 599px) { .logo-h { display: none; } .logo-i { display: block; } }
.brand-footer img { width: 143px; }
.main-nav { display: none; gap: 2px; }
.main-nav a {
  display: inline-flex; align-items: center; min-height: var(--tap); padding: 0 14px; border-radius: var(--r-pill);
  font-size: var(--fs-sm); font-weight: 600; color: var(--ink-2); text-decoration: none; white-space: nowrap;
  transition: background var(--t-fast), color var(--t-fast);
}
.main-nav a:hover { background: var(--lilac-50); color: var(--ink); }
.main-nav a[aria-current="true"] { background: var(--ink); color: #fff; }
.search {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: var(--s2);
  height: var(--tap); padding: 0 var(--s4); border-radius: var(--r-pill); background: #fff; border: 1px solid var(--line);
}
.search:focus-within { border-color: var(--blue); box-shadow: 0 0 0 4px rgba(63, 92, 232, .14); }
.search svg { width: 18px; height: 18px; color: var(--ink-3); flex: none; }
.search input { border: 0; outline: 0; background: transparent; width: 100%; min-width: 0; font-size: 16px; }
.cart-btn { position: relative; background: var(--ink); color: #fff; }
.cart-btn:hover { background: #0e1628; }
.count-badge {
  position: absolute; top: -3px; right: -3px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: var(--r-pill);
  background: var(--blue); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center;
  border: 2px solid var(--cloud);
}
@media (min-width: 1080px) {
  .header-inner { gap: var(--s5); height: 72px; }
}
@media (min-width: 1200px) {
  .main-nav { display: flex; }
  .header-inner { gap: var(--s5); height: 72px; }
  .search { max-width: 420px; margin-left: auto; }
}

/* ---------- footer ---------- */
.site-footer { background: var(--ink); color: #C9CEDD; padding-block: var(--s12); }
.footer-inner { display: grid; gap: var(--s6); }
.footer-inner strong { color: #fff; font-weight: 600; }
.footer-inner p { max-width: 60ch; }
.footer-meta { font-size: var(--fs-xs); letter-spacing: .12em; color: #9AA3BC; }
@media (min-width: 768px) { .footer-inner { grid-template-columns: auto 1fr auto; align-items: center; } }

/* ---------- dialogs ---------- */
dialog { color: var(--ink); }
.modal {
  border: 0; padding: 0; width: min(960px, 100% - 24px); max-height: calc(100dvh - 24px);
  border-radius: var(--r-xl); box-shadow: var(--sh-3); background: var(--white); overflow: auto;
  overscroll-behavior: contain;
}
.modal::backdrop { background: rgba(23, 33, 59, .5); backdrop-filter: blur(3px); }
.modal[open] { animation: pop var(--t-med) var(--ease-out); }
.modal-close { position: sticky; top: 12px; float: right; margin: 12px 12px -56px 0; z-index: 3; background: rgba(255, 255, 255, .9); }
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(.98); } }

/* cart drawer (a modal dialog pinned to the right) */
.drawer {
  margin: 0 0 0 auto; height: 100dvh; max-height: none; width: min(440px, 100%); border-radius: 0;
  display: flex; flex-direction: column; background: var(--cloud);
}
.drawer:not([open]) { display: none; }
.drawer[open] { animation: slide-in var(--t-med) var(--ease-out); }
@keyframes slide-in { from { transform: translateX(40px); opacity: 0; } }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: var(--s5) var(--s5) var(--s3); }
.drawer-head h2 { font-size: var(--fs-xl); }
.drawer-body { flex: 1; overflow: auto; padding: var(--s1) var(--s5) var(--s4); display: grid; align-content: start; gap: var(--s3); }
.drawer-foot { padding: var(--s4) var(--s5) calc(var(--s6) + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); display: grid; gap: var(--s3); background: #fff; }
.cart-line { display: grid; grid-template-columns: 64px 1fr auto; gap: var(--s3); align-items: center; background: #fff; padding: var(--s2); border-radius: var(--r-md); }
.cart-line .thumb-sm { width: 64px; height: 64px; border-radius: var(--r-sm); background: var(--ice-50); display: grid; place-items: center; overflow: hidden; }
.cart-line .thumb-sm img { width: 100%; height: 100%; object-fit: contain; }
.cart-line-name { font-size: var(--fs-sm); font-weight: 600; line-height: 1.3; }
.qty { display: inline-flex; align-items: center; background: var(--lilac-50); border-radius: var(--r-pill); }
.qty button { width: 36px; height: 36px; border: 0; background: transparent; border-radius: 50%; font-size: 18px; }
.qty button:hover { background: var(--lilac); }
.qty output { min-width: 24px; text-align: center; font-weight: 700; font-size: var(--fs-sm); }
.total-row { display: flex; justify-content: space-between; align-items: baseline; }
.ship-row { display: grid; grid-template-columns: 1fr auto; gap: 2px var(--s2); font-size: var(--fs-sm); }
.ship-row strong { color: var(--ok); }
.total-row strong { font-size: var(--fs-xl); }
.empty-state { text-align: center; color: var(--ink-3); padding: var(--s12) var(--s4); display: grid; gap: var(--s3); justify-items: center; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--bottom-offset)); z-index: var(--z-toast);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: var(--r-pill); font-size: var(--fs-sm); font-weight: 600;
  max-width: calc(100% - 32px); transition: transform var(--t-med) var(--ease-out), opacity var(--t-med);
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

/* ---------- reveal on scroll (only when JS is running; content stays visible otherwise) ---------- */
.js [data-reveal] { opacity: 0; transform: translateY(18px); transition: opacity var(--t-slow) var(--ease-out), transform var(--t-slow) var(--ease-out); transition-delay: calc(var(--i, 0) * 60ms); }
.js [data-reveal].in { opacity: 1; transform: none; }

/* ---------- skeleton ---------- */
.skeleton { background: linear-gradient(90deg, #EFEEF3 0%, #F7F6FA 50%, #EFEEF3 100%); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; border-radius: var(--r-md); }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- motion preferences ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
  .js [data-reveal] { opacity: 1; transform: none; }
}


/* ---------- search suggestions ---------- */
.search { position: relative; }
.suggest {
  position: absolute; top: calc(100% + 8px); left: 0; right: 0; z-index: 50; min-width: min(420px, calc(100vw - 32px));
  background: #fff; border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--sh-3); padding: var(--s2);
  max-height: min(70vh, 520px); overflow: auto;
}
.sg-topics { font-size: var(--fs-xs); color: var(--ink-3); padding: var(--s1) var(--s2) var(--s2); display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.sg-topics span { background: var(--ice); color: var(--ink); border-radius: var(--r-pill); padding: 2px 8px; font-weight: 600; }
.sg-item { display: grid; grid-template-columns: 48px 1fr auto; gap: var(--s3); align-items: center; padding: 6px var(--s2); border-radius: var(--r-sm); text-decoration: none; min-height: var(--tap); }
.sg-item:hover, .sg-item[aria-selected="true"], .sg-all[aria-selected="true"] { background: var(--ice-50); }
.sg-img { width: 48px; height: 48px; border-radius: 8px; overflow: hidden; background: #F4F5F8; display: grid; place-items: center; }
.sg-img img { width: 100%; height: 100%; object-fit: contain; }
.sg-img .ph span { display: none; }
.sg-img .ph svg { width: 60%; }
.sg-name { font-size: var(--fs-sm); line-height: 1.3; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.sg-price { font-family: var(--font-display); font-weight: 600; font-size: var(--fs-sm); white-space: nowrap; }
.sg-all { width: 100%; min-height: var(--tap); border: 0; background: transparent; border-top: 1px solid var(--line); margin-top: var(--s1); font-weight: 600; color: var(--blue); border-radius: 0 0 var(--r-sm) var(--r-sm); }
.sg-empty { padding: var(--s4); font-size: var(--fs-sm); color: var(--ink-3); }
@media (max-width: 599px) { .suggest { position: fixed; top: 60px; left: 8px; right: 8px; min-width: 0; } }
