/* ============================================================
   CBI — ส่วน Brands หน้าแรก
   ต้องใช้คู่กับ components/fx.css (ปุ่ม .cbi-btn และตัวแปรสี)
   ============================================================ */
.cbi-brands {
  --ink: #14382f;
  --muted: #5d6f67;
  --line: #e1eae5;
  --tint: #f1f6f3;
  position: relative;
  overflow: hidden;
  padding: 0 0 96px;
  background:
    radial-gradient(1200px 500px at 50% 0%, #ffffff 0%, rgba(255, 255, 255, 0) 70%),
    linear-gradient(180deg, #f4f8f6 0%, #e9f1ed 100%);
  color: var(--ink);
  font-family: "IBM Plex Sans Thai Looped", system-ui, sans-serif;
}
.cbi-brands a { text-decoration: none; }

/* ============================================================
   แถบชื่อแบรนด์วิ่ง (จุดเด่นของส่วนนี้)
   ============================================================ */
.cbi-ribbon {
  padding: 44px 0 4px;
  user-select: none;
  /* จางที่ขอบซ้าย-ขวา */
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 8%, #000 92%, transparent);
          mask-image: linear-gradient(90deg, transparent, #000 8%, #000 92%, transparent);
}
.cbi-ribbon__row { overflow: hidden; white-space: nowrap; }
.cbi-ribbon__track {
  display: inline-flex;
  align-items: center;
  gap: clamp(28px, 4vw, 64px);
  padding-right: clamp(28px, 4vw, 64px);
  will-change: transform;
  animation: cbi-marquee 46s linear infinite;
}
.cbi-ribbon__row--solid .cbi-ribbon__track { animation-direction: reverse; animation-duration: 58s; }
@keyframes cbi-marquee {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}
.cbi-ribbon__item {
  display: inline-flex;
  align-items: center;
  gap: .32em;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -.02em;
}
.cbi-ribbon__item img {
  width: .8em;
  height: .8em;
  object-fit: contain;
  flex: none;
}
.cbi-ribbon__row--outline .cbi-ribbon__item {
  font-size: clamp(34px, 4.6vw, 72px);
  color: transparent;
  -webkit-text-stroke: 1.2px #16493e;
  transition: color .4s;
}
.cbi-ribbon__row--outline .cbi-ribbon__item img { filter: grayscale(1) opacity(.35); transition: filter .4s; }
.cbi-ribbon__row--outline .cbi-ribbon__item:hover { color: #16493e; }
.cbi-ribbon__row--outline .cbi-ribbon__item:hover img { filter: none; }
.cbi-ribbon__row--solid { margin-top: 2px; }
.cbi-ribbon__row--solid .cbi-ribbon__item {
  font-size: clamp(20px, 2.4vw, 34px);
  color: #c9dbd2;
}
.cbi-ribbon__row--solid .cbi-ribbon__item img { filter: grayscale(1) opacity(.45); }

/* ============================================================
   หัวข้อ (กึ่งกลาง ให้เข้ากับการ์ดที่จัดกึ่งกลาง)
   ============================================================ */
.cbi-brand-intro {
  max-width: 640px;
  margin: 40px auto 48px;
  text-align: center;
}
.cbi-brand-intro h2 {
  font-size: clamp(28px, 3.6vw, 42px);
  line-height: 1.35;
  font-weight: 700;
  margin: 0 0 14px;
  color: var(--ink);
}
.cbi-brand-intro p {
  font-size: 16px;
  line-height: 1.8;
  color: var(--muted);
  margin: 0 auto 28px;
  max-width: 34em;
}

/* ============================================================
   การ์ดแบรนด์: เอียงตามเมาส์ + แสงตามเคอร์เซอร์ + โลโก้เด้ง
   ============================================================ */
.cbi-brand-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center; /* แถวสุดท้าย (7 = 4 + 3) อยู่กึ่งกลาง */
  align-items: flex-start; /* เปิดช่องทางโซเชียลแล้วยืดเฉพาะการ์ดนั้น */
  gap: 22px;
  perspective: 1200px;
}
.cbi-brand-cell { flex: 0 1 calc((100% - 66px) / 4); }
.cbi-brand-card {
  --rx: 0deg;
  --ry: 0deg;
  --gx: 50%;
  --gy: 0%;
  --lift: 0px;
  position: relative;
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 22px;
  text-align: center;
  overflow: hidden;
  transform: perspective(900px) rotateX(var(--rx)) rotateY(var(--ry)) translateY(var(--lift));
  transform-style: preserve-3d;
  transition: transform .6s var(--cbi-ease, ease), box-shadow .4s, border-color .4s;
}
.cbi-brand-card.is-tilting { transition: transform .12s linear, box-shadow .4s, border-color .4s; }
.cbi-brand-card:hover {
  --lift: -6px;
  border-color: #c9ddd2;
  box-shadow: 0 28px 50px -24px rgba(20, 56, 47, .35);
}
/* แสงนุ่มตามตำแหน่งเมาส์ */
.cbi-brand-glow {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(420px circle at var(--gx) var(--gy), rgba(47, 122, 92, .14), transparent 60%);
  transition: opacity .4s;
}
.cbi-brand-card:hover .cbi-brand-glow { opacity: 1; }

.cbi-brand-link {
  position: relative;
  z-index: 1;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 22px 22px 24px;
  color: var(--ink) !important;
}
.cbi-brand-logo {
  width: 100%;
  height: 138px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  margin-bottom: 20px;
  background:
    radial-gradient(circle at 50% 120%, rgba(47, 122, 92, .10), transparent 60%),
    var(--tint);
}
.cbi-brand-logo img {
  max-width: 62%;
  max-height: 98px;
  width: auto;
  height: auto;
  object-fit: contain;
  transform: translateZ(30px);
}
.cbi-brand-card:hover .cbi-brand-logo img { animation: cbi-squish .8s var(--cbi-spring, ease); }
/* โลโก้ยุบแล้วเด้งเหมือนกดโฟม */
@keyframes cbi-squish {
  0% { transform: translateZ(30px) scale(1, 1); }
  30% { transform: translateZ(30px) scale(1.12, .88); }
  55% { transform: translateZ(30px) scale(.94, 1.08); }
  75% { transform: translateZ(30px) scale(1.03, .98); }
  100% { transform: translateZ(30px) scale(1.06); }
}
.cbi-brand-card:hover .cbi-brand-logo img { transform: translateZ(30px) scale(1.06); }

.cbi-brand-link h3 {
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 6px;
  color: var(--ink);
}
.cbi-brand-link p {
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--muted);
  margin: 0 0 18px;
}
/* ปุ่มในการ์ด: ใช้ระบบ .cbi-btn เดียวกัน เติมสีเมื่อชี้ที่การ์ด */
.cbi-brand-card:hover .cbi-brand-cta { color: #fff !important; }
.cbi-brand-card:hover .cbi-brand-cta .cbi-btn__fill { transform: translate(-50%, -50%) scale(1); }
.cbi-brand-card:hover .cbi-brand-cta .cbi-btn__icon { animation: cbi-hop .7s var(--cbi-spring, ease); }
.cbi-brand-link:active .cbi-brand-cta { --press: .94; }
.cbi-brand-cta { --y: 100%; }

/* ---------- ช่องทางอื่นของแบรนด์ ---------- */
.cbi-brand-social {
  position: relative;
  z-index: 1;
  border-top: 1px solid #edf2ef;
  font-size: 12.5px;
  color: var(--muted);
}
.cbi-brand-social summary,
.cbi-brand-social-empty span {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 16px;
}
.cbi-brand-social summary {
  list-style: none;
  cursor: pointer;
  transition: color .2s, background .2s;
}
.cbi-brand-social summary::-webkit-details-marker { display: none; }
.cbi-brand-social summary:hover { color: #16493e; background: #f7faf8; }
.cbi-brand-social summary .bi { font-size: 11px; transition: transform .35s var(--cbi-spring, ease); }
.cbi-brand-social[open] summary .bi { transform: rotate(180deg); }
.cbi-brand-social-empty .bi { font-size: 12px; color: #2f7a5c; }
.cbi-brand-social-icons {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 2px 16px 16px;
}
.cbi-brand-social[open] .cbi-brand-social-icons a { animation: cbi-pop .45s var(--cbi-spring, ease) backwards; }
.cbi-brand-social[open] .cbi-brand-social-icons a:nth-child(2) { animation-delay: .05s; }
.cbi-brand-social[open] .cbi-brand-social-icons a:nth-child(3) { animation-delay: .1s; }
.cbi-brand-social[open] .cbi-brand-social-icons a:nth-child(4) { animation-delay: .15s; }
.cbi-brand-social[open] .cbi-brand-social-icons a:nth-child(5) { animation-delay: .2s; }
@keyframes cbi-pop {
  from { opacity: 0; transform: translateY(8px) scale(.6); }
  to { opacity: 1; transform: none; }
}
.cbi-brand-social-icons a {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--tint);
  transition: background .2s, transform .35s var(--cbi-spring, ease);
}
.cbi-brand-social-icons a:hover { background: #e1ede6; transform: translateY(-3px) scale(1.08); }
.cbi-brand-social-icons img { width: 22px; height: 22px; object-fit: contain; }

/* ---------- หมายเหตุท้ายส่วน ---------- */
.cbi-shop-note {
  margin: 40px 0 0;
  text-align: center;
  font-size: 14px;
  line-height: 1.9;
  color: var(--muted);
}
.cbi-shop-note a {
  font-weight: 700;
  color: #16493e;
  background: linear-gradient(currentColor, currentColor) 0 100% / 0 2px no-repeat;
  padding-bottom: 2px;
  transition: background-size .4s var(--cbi-ease, ease);
}
.cbi-shop-note a:hover { background-size: 100% 2px; }

.cbi-brands a:focus-visible,
.cbi-brands summary:focus-visible {
  outline: 3px solid #d9a441;
  outline-offset: 3px;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 1199px) {
  .cbi-brand-cell { flex-basis: calc((100% - 44px) / 3); }
}
@media (max-width: 991px) {
  .cbi-brand-cell { flex-basis: calc((100% - 22px) / 2); }
  .cbi-ribbon { padding-top: 36px; }
}
@media (max-width: 575px) {
  .cbi-brands { padding-bottom: 64px; }
  .cbi-ribbon { padding-top: 28px; }
  .cbi-ribbon__row--outline .cbi-ribbon__item { -webkit-text-stroke-width: 1px; }
  .cbi-brand-intro { margin: 28px auto 32px; }
  .cbi-brand-intro p { font-size: 15px; }
  .cbi-brand-intro .cbi-btn { width: 100%; }
  .cbi-brand-grid { gap: 12px; }
  .cbi-brand-cell { flex-basis: calc((100% - 12px) / 2); }
  .cbi-brand-card { border-radius: 18px; }
  .cbi-brand-link { padding: 12px 10px 16px; }
  .cbi-brand-logo { height: 100px; margin-bottom: 12px; border-radius: 12px; }
  .cbi-brand-logo img { max-height: 70px; }
  .cbi-brand-link h3 { font-size: 16px; }
  .cbi-brand-link p { font-size: 12px; margin-bottom: 12px; }
  .cbi-brand-cta.cbi-btn--sm { padding: 8px 12px; font-size: 12.5px; }
  .cbi-brand-social summary, .cbi-brand-social-empty span { padding: 10px 6px; font-size: 11.5px; }
}
/* อุปกรณ์สัมผัส: ไม่มีการเอียง ใช้การยุบเมื่อแตะแทน */
@media (hover: none) {
  .cbi-brand-card:hover { --lift: 0px; box-shadow: none; }
  .cbi-brand-card:active { transform: scale(.98); }
}
@media (prefers-reduced-motion: reduce) {
  .cbi-ribbon__track { animation: none; }
  .cbi-ribbon__row { overflow-x: auto; scrollbar-width: none; }
  .cbi-brand-card, .cbi-brand-card *, .cbi-brand-social-icons a {
    animation: none !important;
    transition: none !important;
  }
  .cbi-brand-card { transform: none !important; }
}
