/* Khối TraceMax — chuyển từ style scoped của ProductTrace.vue. Mọi selector có tiền tố [data-ex-section="trace"]. */

/* Sân khấu (từ 992px ghim, cao đúng phần màn dưới header — user 21/10), KHÔNG padding dưới: ảnh bàn tay bị cắt ở đáy
   ⇒ nối liền khối Đối tác khi nhả ghim. overflow hidden đặt ở ĐÂY, không ở section — hidden trên cha phá sticky. */
[data-ex-section="trace"] .ex-trace-stage {
  display: flex;
  flex-direction: column;
  padding-top: 72px;
  overflow: hidden;
}
[data-ex-section="trace"] .ex-trace-grain {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.04 0 0 0 0 0.12 0 0 0 0 0.11 0 0 0 0.09 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* Sân khấu: ảnh tay căn giữa, đáy ảnh bị cắt bởi đáy khối (chiều cao sân khấu < chiều cao ảnh). */
[data-ex-section="trace"] .ex-trace-scene {
  --hw: min(100vw, 440px); /* bề ngang ảnh tay */
  --ih: calc(var(--hw) * 2000 / 1428); /* bề cao ảnh tay */
  position: relative;
  margin-top: 36px;
  height: calc(var(--ih) * 0.8);
}
/* Màn máy có tâm ở 48,3% bề ngang ảnh ⇒ dời ảnh để MÀN MÁY đứng đúng giữa khối. */
[data-ex-section="trace"] .ex-trace-hand {
  position: absolute;
  z-index: 2;
  left: calc(50% - var(--hw) * 0.483);
  top: 0;
  width: var(--hw);
}

/* Mặt kính trong ảnh: x 400–980, y 230–1456 trên ảnh gốc 1428×2000. Vị trí + bo góc do user chỉnh tay trên DevTools 21/10. */
[data-ex-section="trace"] .ex-trace-screen {
  position: absolute;
  left: 28.2%;
  top: 11.33%;
  width: 40.6%;
  height: 61.75%;
  overflow: hidden;
  border-radius: 11.06% 11.06% 9.83% 9.83% / 5.24% 5.24% 4.66% 4.66%;
  background: #fff;
}
[data-ex-section="trace"] .ex-trace-canvas {
  position: absolute;
  left: 0;
  top: 0;
  width: 300px; /* SCREEN_BASE */
  height: 634px; /* mặc định trước khi đo; JS đặt lại theo tỉ lệ thật của lớp màn (`canvasH`) */
  transform-origin: 0 0;
}
/* Mặt kính trắng trong ảnh — lót đen phủ dư ~6px ảnh mỗi phía. */
[data-ex-section="trace"] .ex-trace-glass {
  position: absolute;
  left: 27.5%;
  top: 11.2%;
  width: 41.6%;
  height: 62.2%;
  border-radius: 12% / 5.6%;
  background: #0b0d10;
}
/* Tai thỏ trong ảnh: x 543–841, đáy y ~272. */
[data-ex-section="trace"] .ex-trace-notch {
  position: absolute;
  left: 24.2%;
  top: -1px;
  width: 51.4%;
  height: 3.5%;
  border-radius: 0 0 14px 14px;
  background: #0b0d10;
}
[data-ex-section="trace"] .ex-trace-cam {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #1c2a1a;
  container-type: size;
}
[data-ex-section="trace"] .ex-trace-art {
  position: absolute;
  left: 50%;
  top: 50%;
  width: max(100cqw, 100cqh);
  aspect-ratio: 1 / 1;
  translate: -50% -50%; /* = -TAG_X -TAG_Y */
  will-change: transform;
}
[data-ex-section="trace"] .ex-trace-status {
  position: absolute;
  inset: 0 0 auto;
  z-index: 1;
  display: flex;
  height: 30px;
  align-items: flex-end;
  justify-content: space-between;
  padding: 0 22px 2px;
  font-size: 11px;
  font-weight: 600;
}
[data-ex-section="trace"] .ex-trace-batt {
  width: 20px;
  height: 10px;
  border: 1.5px solid currentColor;
  border-radius: 3px;
  background: linear-gradient(90deg, currentColor 70%, transparent 70%) content-box;
  padding: 1px;
}
[data-ex-section="trace"] .ex-trace-reticle {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 64cqw;
  height: 64cqw;
  translate: -50% -50%;
  pointer-events: none;
}
[data-ex-section="trace"] .ex-trace-reticle > span {
  position: absolute;
  width: 20%;
  height: 20%;
  border-color: #fff;
  border-radius: 6px;
}
[data-ex-section="trace"] .ex-trace-scanline {
  position: absolute;
  inset-inline: 8%;
  top: 10%;
  height: 3px;
  border-radius: 3px;
  background: #9fd477;
  box-shadow: 0 0 14px #9fd477;
}
[data-ex-section="trace"] .ex-trace-result {
  position: absolute;
  inset: 0;
  background: #fff;
}

/* Đường lượn: trải hết bề ngang khối, giữa phần máy; dưới tay (z 2), trên sóng. */
[data-ex-section="trace"] .ex-trace-lines {
  position: absolute;
  z-index: 1;
  left: 50%;
  top: calc(var(--ih) * 0.02);
  width: 100vw;
  max-width: none;
  height: auto;
  translate: -50% 0;
  display: none;
  pointer-events: none;
}
@media (min-width: 992px) { [data-ex-section="trace"] .ex-trace-lines { display: block; } }

/* Sóng toả sau bàn tay: các vòng viền nở ra từ tâm máy rồi tan. */
[data-ex-section="trace"] .ex-trace-waves {
  position: absolute;
  z-index: 0;
  left: 50%; /* = tâm màn máy */
  top: calc(var(--ih) * 0.42);
  width: 0;
  height: 0;
}
[data-ex-section="trace"] .ex-trace-waves > i {
  position: absolute;
  left: 0;
  top: 0;
  width: calc(var(--hw) * 1.1);
  aspect-ratio: 1;
  border: 1.5px solid rgba(24, 102, 211, 0.34);
  border-radius: 9999px;
  translate: -50% -50%;
  opacity: 0;
}

/* Thẻ tính năng — 4 tông trắng viền / xám xanh / xanh lơ đặc / xanh lá đặc, KHÔNG bóng đổ. Lớp trên tay (z 3 > tay 2 >
   ô icon 1 > sóng 0), KHÔNG đè lên điện thoại. Dưới 992px xếp 1 cột. */
[data-ex-section="trace"] .ex-trace-card {
  --c-bg: #fff;
  --c-title: #0b1a33;
  --c-desc: #4a5a70;
  --c-ico-bg: #1866d3;
  --c-ico: #fff;
  position: relative;
  z-index: 3;
  border-radius: 24px;
  background: var(--c-bg);
  padding: 24px;
}
[data-ex-section="trace"] .ex-trace-card.is-line { box-shadow: inset 0 0 0 2px #dfe5ef; }
[data-ex-section="trace"] .ex-trace-card.is-mist {
  --c-bg: #e6edf7;
  box-shadow: inset 0 0 0 2px #cfdbec; /* user 21/10: thẻ GS1 thêm viền */
  --c-ico-bg: #cfdcf1;
  --c-ico: #1866d3;
}
/* Xanh lơ = đỉnh chữ "max" trong logo Ecomax, user 21/10 cho thẻ Chống hàng giả. */
[data-ex-section="trace"] .ex-trace-card.is-cyan {
  --c-bg: linear-gradient(150deg, #00b4fc 0%, #0084f0 100%);
  --c-title: #fff;
  --c-desc: rgba(255, 255, 255, 0.95);
  --c-ico-bg: #fff;
  --c-ico: #0084f0;
}
[data-ex-section="trace"] .ex-trace-card.is-green {
  --c-bg: linear-gradient(150deg, #5cb244 0%, #2f8a37 100%);
  --c-title: #fff;
  --c-desc: rgba(255, 255, 255, 0.9);
  --c-ico-bg: #fff;
  --c-ico: #2f8a37;
}
[data-ex-section="trace"] .ex-trace-card-icon {
  display: inline-flex;
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  background: var(--c-ico-bg);
  color: var(--c-ico);
}
[data-ex-section="trace"] .ex-trace-card-icon > svg { width: 30px; height: 30px; } /* user 21/10: icon trong to ra, khung giữ nguyên */
[data-ex-section="trace"] .ex-trace-card-title {
  font-size: 19px;
  font-weight: 700;
  line-height: 1.25;
  color: var(--c-title);
}
[data-ex-section="trace"] .ex-trace-card-desc {
  margin-top: 16px;
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--c-desc);
}

/* Ô icon trang trí: lớp dưới tay (z 1). Chỉ hiện từ 1200px VÀ màn cao ≥ 1150px — thấp hơn thì icon bị thẻ che. */
[data-ex-section="trace"] .ex-trace-deco {
  position: absolute;
  z-index: 1;
  display: none;
}
[data-ex-section="trace"] .ex-trace-deco-tile {
  display: inline-flex;
  width: var(--s, 60px);
  height: var(--s, 60px);
  align-items: center;
  justify-content: center;
  border-radius: calc(var(--s, 60px) * 0.3);
  background: #1866d3;
  color: #fff;
}
[data-ex-section="trace"] .ex-trace-deco-tile > svg { width: calc(var(--s, 60px) * 0.42); height: calc(var(--s, 60px) * 0.42); }
[data-ex-section="trace"] .ex-trace-deco-tile.is-violet { background: linear-gradient(150deg, #6a3fc4 0%, #3f1f86 100%); }
[data-ex-section="trace"] .ex-trace-deco-tile.is-amber { background: linear-gradient(150deg, #f7b52c 0%, #e8790f 100%); }
[data-ex-section="trace"] .ex-trace-deco-tile.is-slate { background: linear-gradient(150deg, #47505f 0%, #222833 100%); }

@media (max-width: 991.98px) {
  [data-ex-section="trace"] .ex-trace-scene {
    display: flex;
    flex-direction: column;
    gap: 12px;
    height: auto;
    padding: 0 20px calc(var(--ih) * 0.8);
  }
  [data-ex-section="trace"] .ex-trace-hand { top: auto; bottom: calc(var(--ih) * -0.2); }
  [data-ex-section="trace"] .ex-trace-waves { display: none; }
  [data-ex-section="trace"] .ex-trace-card { opacity: 1 !important; translate: none !important; }
}

/* Từ 992px: khối cao tối thiểu bằng màn, ảnh tay lấp phần còn lại; thẻ đặt tuyệt đối hai bên. */
@media (min-width: 992px) {
  [data-ex-section="trace"] .ex-trace-stage {
    position: sticky;
    top: 56px; /* HEADER_PX */
    height: calc(100vh - 56px);
    padding-top: 28px; /* 80 → 28 (user 21/10); màn cao ≥1150px vẫn 80/96 */
  }
  [data-ex-section="trace"] .ex-trace-scene {
    /* Cỡ ảnh tay co theo chiều cao màn (phần chữ phía trên + header ≈ 470px). Cho phép đáy khối cắt phần dưới bàn tay. */
    --hw: min(640px, max(500px, calc((100vh - 470px) * 1.4)));
    flex: 1;
    min-height: 0;
    height: auto;
    /* Ảnh có ~10% khoảng trong suốt trên đầu máy — kéo lên để đầu máy cách sapo vừa phải. */
    margin-top: calc(64px - var(--ih) * 0.09); /* 64 = khe dưới nút Tìm hiểu thêm */
  }
  [data-ex-section="trace"] .ex-trace-card {
    position: absolute;
    width: 300px;
  }
  /* Ngang theo tâm màn máy (= tâm khối): mép máy ở ±0,225 hw (`--e`); thẻ đứng NGOÀI mép máy. */
  [data-ex-section="trace"] .ex-trace-scene { --e: calc(var(--hw) * 0.225); }
  /* Khe thẻ ↔ mép máy: trái `--gl`, phải `--gr`; từ 1200px gấp đôi. */
  [data-ex-section="trace"] .ex-trace-scene { --gl: 24px; --gr: 32px; }
  /* DỌC: JS đặt `top` (layoutCards). `top` dưới đây chỉ là chỗ chờ trước khi JS chạy. */
  [data-ex-section="trace"] .ex-trace-card { top: 0; }
  [data-ex-section="trace"] .ex-trace-card.is-lt { right: calc(50% + var(--e) + var(--gl)); }
  [data-ex-section="trace"] .ex-trace-card.is-lb { right: calc(50% + var(--e) + var(--gl) + 48px); } /* lệch trái so với thẻ trên */
  [data-ex-section="trace"] .ex-trace-card.is-rt { left: calc(50% + var(--e) + var(--gr)); }
  [data-ex-section="trace"] .ex-trace-card.is-rb { left: calc(50% + var(--e) + var(--gr) + 40px); }
}
@media (min-width: 1200px) {
  [data-ex-section="trace"] .ex-trace-scene { --hw: min(720px, max(500px, calc((100vh - 470px) * 1.4))); --gl: 48px; --gr: 64px; }
  [data-ex-section="trace"] .ex-trace-card { width: 320px; }
}
/* Thẻ GỌN (layoutCards gắn `is-compact` khi thẻ cỡ thường không xếp vừa): thẻ nhỏ, xếp từ ĐÁY lên. */
@media (min-width: 992px) {
  [data-ex-section="trace"] .ex-trace-scene.is-compact .ex-trace-card { width: 290px; padding: 14px 16px; border-radius: 18px; }
  [data-ex-section="trace"] .ex-trace-scene.is-compact .ex-trace-card-icon { width: 40px; height: 40px; border-radius: 12px; }
  [data-ex-section="trace"] .ex-trace-scene.is-compact .ex-trace-card-icon > svg { width: 24px; height: 24px; }
  [data-ex-section="trace"] .ex-trace-scene.is-compact .ex-trace-card-title { font-size: 15.5px; }
  [data-ex-section="trace"] .ex-trace-scene.is-compact .ex-trace-card-desc { margin-top: 8px; font-size: 13px; line-height: 1.45; }
}
/* Khoảng trống phía trên logo + khe logo ↔ tít ↔ sapo ↔ nút — màn thấp rút lại; màn CAO (≥1150px) giữ số đã duyệt. */
@media (min-width: 992px) and (max-height: 1000px) {
  [data-ex-section="trace"] .ex-trace-title { margin-top: 14px; }
  [data-ex-section="trace"] .ex-trace-sapo { margin-top: 10px; }
  [data-ex-section="trace"] .ex-trace-more { margin-top: 16px; }
  [data-ex-section="trace"] .ex-trace-scene { margin-top: calc(36px - var(--ih) * 0.09); }
}
/* Vị trí ô icon theo 4 chỗ user khoanh (quy về tay rộng 800px, màn 2560×1305). */
@media (min-width: 1200px) and (min-height: 1150px) {
  [data-ex-section="trace"] .ex-trace-deco { display: block; }
  [data-ex-section="trace"] .ex-trace-deco.is-gov { left: calc(50% + var(--e) + 25px); top: 10%; }
  [data-ex-section="trace"] .ex-trace-deco.is-leaf { right: calc(50% + var(--e) + var(--gl) + 52px); top: calc(45.5% - 20px); }
  [data-ex-section="trace"] .ex-trace-deco.is-scan { left: calc(50% + var(--e) + var(--gr) + 187px); top: 87%; }
}
@media (min-width: 1600px) {
  [data-ex-section="trace"] .ex-trace-stage { padding-top: 36px; }
  [data-ex-section="trace"] .ex-trace-scene { --hw: min(800px, max(500px, calc((100vh - 490px) * 1.4))); }
}
@media (min-width: 992px) and (min-height: 1150px) { [data-ex-section="trace"] .ex-trace-stage { padding-top: 80px; } }
@media (min-width: 1600px) and (min-height: 1150px) { [data-ex-section="trace"] .ex-trace-stage { padding-top: 96px; } }

@media (prefers-reduced-motion: no-preference) {
  [data-ex-section="trace"] .ex-trace-scanline { animation: ex-trace-scan 1.2s ease-in-out infinite alternate; }
  [data-ex-section="trace"] .ex-trace-waves > i { animation: ex-trace-wave 6.4s cubic-bezier(.2, .6, .3, 1) infinite; }
  [data-ex-section="trace"] .ex-trace-deco-tile { animation: ex-trace-pulse 3.4s ease-in-out infinite alternate; }
}
@keyframes ex-trace-pulse {
  from { transform: scale(0.88); }
  to { transform: scale(1.1); }
}
@keyframes ex-trace-scan {
  from { top: 10%; }
  to { top: 88%; }
}
@keyframes ex-trace-wave {
  0% { scale: 0.25; opacity: 0; }
  12% { opacity: 1; }
  100% { scale: 1.6; opacity: 0; }
}
