/* ==========================================================================
   Kroo8 — Base: reset, typography, layout primitives, chrome
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: var(--fs-base);
  line-height: var(--lh-body);
  color: var(--text);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  padding-bottom: env(safe-area-inset-bottom);
}

h1, h2, h3, h4, h5 { margin: 0; font-weight: 700; line-height: var(--lh-tight); letter-spacing: -.01em; }
h1 { font-size: var(--fs-3xl); }
h2 { font-size: var(--fs-2xl); }
h3 { font-size: var(--fs-xl); }
h4 { font-size: var(--fs-md); }
p  { margin: 0 0 1em; }
p:last-child { margin-bottom: 0; }

a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-h); text-decoration: underline; text-underline-offset: 3px; }

ul, ol { margin: 0 0 1em; padding-left: 1.3em; }
li { margin-bottom: .4em; }
li:last-child { margin-bottom: 0; }

img, svg, canvas { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
hr { border: 0; border-top: 1px solid var(--line); margin: var(--s-6) 0; }
code, kbd, samp { font-family: var(--font-mono); font-size: .92em; }
small { font-size: var(--fs-sm); }
strong, b { font-weight: 700; }

table { border-collapse: collapse; width: 100%; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}
:focus:not(:focus-visible) { outline: none; }

::selection { background: var(--accent); color: #fff; }

/* scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 99px; border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-track { background: transparent; }

/* ---------- skip link ---------- */
.skip-link {
  position: fixed; left: 50%; top: 6px; transform: translate(-50%, -160%);
  z-index: 999; background: var(--btn-primary-bg); color: var(--btn-primary-fg);
  padding: 10px 18px; border-radius: var(--r-pill); font-weight: 600; font-size: var(--fs-sm);
  transition: transform var(--dur-2) var(--ease);
}
.skip-link:focus { transform: translate(-50%, 0); text-decoration: none; }

/* ==========================================================================
   Layout primitives
   ========================================================================== */
.wrap        { width: 100%; max-width: var(--wrap); margin-inline: auto; padding-inline: var(--s-5); }
.wrap-narrow { width: 100%; max-width: var(--wrap-narrow); margin-inline: auto; padding-inline: var(--s-5); }
.wrap-wide   { width: 100%; max-width: var(--wrap-wide); margin-inline: auto; padding-inline: var(--s-5); }

.app { min-height: 60vh; padding-bottom: var(--s-10); }

.stack       { display: flex; flex-direction: column; }
.stack-1 > * + * { margin-top: var(--s-1); }
.stack-2 > * + * { margin-top: var(--s-2); }
.stack-3 > * + * { margin-top: var(--s-3); }
.stack-4 > * + * { margin-top: var(--s-4); }
.stack-5 > * + * { margin-top: var(--s-5); }
.stack-6 > * + * { margin-top: var(--s-6); }
.stack-7 > * + * { margin-top: var(--s-7); }

.row     { display: flex; align-items: center; gap: var(--s-3); }
.row-2   { display: flex; align-items: center; gap: var(--s-2); }
.row-4   { display: flex; align-items: center; gap: var(--s-4); }
.row-wrap{ flex-wrap: wrap; }
.row-top { align-items: flex-start; }
.spread  { justify-content: space-between; }
.center  { justify-content: center; }
.grow    { flex: 1 1 auto; min-width: 0; }
.shrink0 { flex: 0 0 auto; }

.grid { display: grid; gap: var(--s-4); }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.g-auto { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.g-auto-lg { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }

@media (max-width: 1080px) { .g-5 { grid-template-columns: repeat(3, minmax(0,1fr)); } .g-4 { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 760px)  { .g-5, .g-4, .g-3, .g-2 { grid-template-columns: 1fr; } }

.section     { padding-block: var(--s-9); }
.section-sm  { padding-block: var(--s-7); }
.section-top { padding-top: var(--s-7); }

/* ---------- text utilities ---------- */
.t-xs  { font-size: var(--fs-xs); }
.t-sm  { font-size: var(--fs-sm); }
.t-md  { font-size: var(--fs-md); }
.t-lg  { font-size: var(--fs-lg); }
.t-xl  { font-size: var(--fs-xl); }
.t-2xl { font-size: var(--fs-2xl); }
.muted { color: var(--text-2); }
.dim   { color: var(--text-3); }
.b     { font-weight: 700; }
.sb    { font-weight: 600; }
.tc    { text-align: center; }
.tr    { text-align: right; }
.nowrap{ white-space: nowrap; }
.tabnum{ font-variant-numeric: tabular-nums; }
.lead  { font-size: var(--fs-md); color: var(--text-2); line-height: 1.7; }
.clamp2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.clamp3 { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.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;
}
.hide { display: none !important; }

/* ==========================================================================
   Topbar
   ========================================================================== */
.topbar {
  position: sticky; top: 0; z-index: 60;
  height: var(--topbar-h);
  background: color-mix(in srgb, var(--page) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--hairline);
}
.topbar-in {
  height: 100%; display: flex; align-items: center; gap: var(--s-4);
  max-width: var(--wrap-wide); margin-inline: auto; padding-inline: var(--s-5);
}

.brand { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.brand:hover { text-decoration: none; }
/* กระเบื้องแบรนด์ — ไล่สี 5 สีของ "ปัจจัย 5" มีเส้น ∞ สีขาวอยู่ข้างใน
   ∞ คือเลข 8 ที่ตะแคง จึงเป็นทั้งชื่อและความหมายในรูปเดียว */
.brand-mark {
  width: 34px; height: 34px; border-radius: 11px; flex: 0 0 auto;
  background: linear-gradient(135deg, var(--cat-food), var(--cat-clothing) 42%, var(--cat-modern) 78%, var(--cat-home));
  display: grid; place-items: center; color: #fff;
  box-shadow: var(--sh-2);
}
.brand-mark svg { display: block; }

/* เลข 8 ในชื่อ — ย้ำว่ามันคือสัญลักษณ์เดียวกับบนกระเบื้อง
   ใช้สีเดียวกับหมวดอาหารซึ่งเป็นสีเปิดของไล่สี จึงผูกกันด้วยสายตา */
.brand-8 {
  color: var(--cat-food);
  font-weight: 800;
}
.brand-name { display: block; font-weight: 800; font-size: 16.5px; color: var(--text); letter-spacing: -.02em; line-height: 1.15; }
.brand-sub  { display: block; font-size: 10.5px; color: var(--text-3); letter-spacing: .05em; line-height: 1.25; margin-top: 1px; }

.mainnav { display: flex; align-items: center; gap: 2px; }
.mainnav a {
  padding: 7px 13px; border-radius: var(--r-pill); color: var(--text-2);
  font-size: var(--fs-sm); font-weight: 600; white-space: nowrap;
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
}
.mainnav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.mainnav a[aria-current="page"] { background: var(--surface); color: var(--text); box-shadow: var(--sh-1); }

.topbar-actions { display: flex; align-items: center; gap: var(--s-2); margin-left: auto; }

@media (max-width: 940px) { .mainnav { display: none; } }

/* ==========================================================================
   Footer
   ========================================================================== */
.sitefoot {
  border-top: 1px solid var(--hairline);
  background: var(--surface);
  padding-block: var(--s-8) var(--s-7);
  margin-top: var(--s-9);
}
.foot-grid { display: grid; grid-template-columns: 1.6fr 1fr 1fr 1fr; gap: var(--s-7); }
.foot-grid h5 { font-size: var(--fs-sm); text-transform: uppercase; letter-spacing: .07em; color: var(--text-3); margin-bottom: var(--s-3); font-weight: 700; }
.foot-links { display: flex; flex-direction: column; gap: 8px; }
.foot-links a { color: var(--text-2); font-size: var(--fs-sm); }
.foot-links a:hover { color: var(--text); }
.foot-bottom {
  margin-top: var(--s-7); padding-top: var(--s-5); border-top: 1px solid var(--line);
  display: flex; flex-wrap: wrap; gap: var(--s-3); justify-content: space-between;
  font-size: var(--fs-xs); color: var(--text-3);
}
@media (max-width: 860px) { .foot-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 520px) { .foot-grid { grid-template-columns: 1fr; } }

/* ==========================================================================
   Mobile tab bar
   ========================================================================== */
.tabbar { display: none; }
@media (max-width: 940px) {
  .tabbar {
    display: flex; position: fixed; inset: auto 0 0 0; z-index: 70;
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    backdrop-filter: blur(14px);
    border-top: 1px solid var(--hairline);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  }
  .tabbar a {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
    padding: 6px 2px; border-radius: var(--r-md); color: var(--text-3);
    font-size: 10.5px; font-weight: 600; text-decoration: none;
  }
  .tabbar a[aria-current="page"] { color: var(--text); background: var(--surface-2); }
  .tabbar .tb-ico { font-size: 19px; line-height: 1; }
  body { padding-bottom: 74px; }
  .sitefoot { margin-bottom: 60px; }
}

/* print: hide app chrome */
@media print {
  .topbar, .sitefoot, .tabbar, .toasts, .modal-root, .sheet-root, .tip-root { display: none !important; }
  .app { display: none !important; }
  body { background: #fff; }
}
