/* Slide 3D + khung thiết bị + khu cuộn "Tính năng" (đi cùng js/slides3d.js).
   JS chỉ đặt --d (lệch so với slide đang xem: âm = bên trái/đã qua) và --ad = |--d|;
   mọi hình khối 3D tính bằng CSS ở đây. Màu lấy từ token nên tự theo dark mode. */

.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; }

/* ---------- Khung chung ---------- */
.c3d { position: relative; }
.c3d:focus-visible { outline: 2px solid var(--brand-500); outline-offset: 6px; border-radius: 20px; }
/* Mọi slide xếp chồng trong cùng một ô lưới → khung cao bằng slide cao nhất, không cần đặt chiều cao cứng. */
.c3d-stage { display: grid; justify-items: center; align-items: start; transform-style: preserve-3d; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.c3d-slide { grid-area: 1 / 1; width: 100%; backface-visibility: hidden; transition: transform 760ms var(--ease-out), opacity 520ms var(--ease-out), filter 520ms var(--ease-out); }
.c3d-slide.is-far { opacity: 0 !important; visibility: hidden; pointer-events: none; transition: none; }
.c3d-slide img { -webkit-user-drag: none; }

.c3d-ctl { position: relative; z-index: 120; display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 14px; }
.c3d.is-single .c3d-ctl { display: none; }
.c3d-btn { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--border-1); background: var(--surface); color: var(--fg-1); display: grid; place-items: center; cursor: pointer; box-shadow: var(--shadow-sm); transition: transform var(--dur-med) var(--ease-out), border-color var(--dur-med), color var(--dur-med); }
.c3d-btn:hover { transform: translateY(-2px); border-color: var(--brand-500); color: var(--brand-600); }
.c3d-btn:focus-visible, .c3d-dot:focus-visible { outline: 2px solid var(--brand-500); outline-offset: 2px; }
.c3d-pause .ic + .ic, .c3d.is-paused .c3d-pause .ic:first-child { display: none; }
.c3d.is-paused .c3d-pause .ic + .ic { display: block; }
.c3d-dots { display: flex; align-items: center; gap: 6px; }
.c3d-dot { width: 8px; height: 8px; padding: 0; border: 0; border-radius: 999px; background: var(--ink-200); cursor: pointer; transition: width 360ms var(--ease-out), background 360ms; }
.c3d-dot[aria-current="true"] { width: 28px; background: var(--brand-500); }

/* ---------- 1. Coverflow (hero trang chủ) ---------- */
.c3d[data-carousel="coverflow"] { --gap: 60%; --rot: 34deg; --depth: 170px; }
.c3d[data-carousel="coverflow"] .c3d-stage { perspective: 1500px; padding: 18px 0 8px; }
.c3d[data-carousel="coverflow"] .c3d-slide {
  width: min(360px, 74%);
  transform: translateX(calc(var(--d) * var(--gap))) translateZ(calc(var(--ad) * var(--depth) * -1)) rotateY(calc(var(--d) * var(--rot) * -1));
  opacity: calc(1 - var(--ad) * 0.22);
  filter: saturate(calc(1 - var(--ad) * 0.3)) brightness(calc(1 - var(--ad) * 0.05));
}
.c3d[data-carousel="coverflow"] .c3d-slide:not(.is-active) { cursor: pointer; }

.hs-card { position: relative; display: block; overflow: hidden; color: inherit; text-decoration: none; background: var(--surface); border: 1px solid var(--border-1); border-radius: 20px; box-shadow: var(--shadow-md); transition: box-shadow 520ms var(--ease-out); }
.c3d-slide.is-active .hs-card { box-shadow: var(--shadow-lg), 0 34px 60px -26px var(--brand-a30); }
/* Vệt sáng lướt qua thẻ đang xem mỗi lần chuyển slide. */
.hs-card::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(105deg, transparent 35%, rgba(255, 255, 255, 0.35) 50%, transparent 65%); transform: translateX(-120%); }
.c3d-slide.is-active .hs-card::after { animation: hsShine 1.1s 0.35s var(--ease-out); }
@keyframes hsShine { to { transform: translateX(120%); } }
.hs-screen { position: relative; aspect-ratio: 16 / 10; overflow: hidden; background: var(--bg-2); border-bottom: 1px solid var(--border-1); }
.hs-screen > img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }
.hs-body { padding: 14px 18px 16px; }
.hs-body .cat-lab { font-size: 12px; }
.hs-body h3 { margin: 4px 0 6px; font-size: 17px; line-height: 1.3; color: var(--fg-1); }
.hs-desc { margin: 0 0 12px; font-size: 13px; line-height: 1.5; color: var(--fg-3); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.hs-meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.hs-meta b { font-size: 18px; color: var(--brand-600); }
.hs-go { font-size: 13px; font-weight: 700; color: var(--brand-600); transition: transform var(--dur-med) var(--ease-out); }
.hs-card:hover .hs-go { transform: translateX(4px); }
/* Hero: chỉ hiện 1 thẻ mỗi bên (data-near="1"), xoay sâu hơn cho gọn trong cột;
   phần chữ nằm trên thẻ trái; app.js đổi perspective-origin/translate theo chuột. */
.c3d.hero-c3d { --gap: 52%; --rot: 40deg; --depth: 200px; }
.hero-c3d .c3d-slide { opacity: calc(1 - var(--ad) * 0.28); }
.hero-in > :first-child { position: relative; z-index: 2; }
.hero-c3d .c3d-stage { perspective-origin: 50% 40%; transition: perspective-origin 600ms var(--ease-out), translate 600ms var(--ease-out); }

/* ---------- 2. Deck — bộ bài banner ---------- */
.c3d[data-carousel="deck"] { max-width: 980px; margin: 0 auto; }
/* Thẻ sau thấp hơn 18px và hẹp hơn 5% mỗi lớp → lộ mép dưới như chồng bài. */
.c3d[data-carousel="deck"] .c3d-stage { perspective: 1200px; padding-bottom: 40px; }
.c3d[data-carousel="deck"] .c3d-slide {
  transform-origin: 50% 100%;
  transform: translateX(var(--dx, 0px)) rotate(var(--dr, 0deg)) translateY(calc(var(--d) * 18px)) scale(calc(1 - var(--d) * 0.05));
  opacity: calc(1 - var(--d) * 0.18);
  cursor: grab;
}
.c3d[data-carousel="deck"] .c3d-slide.is-dragging { transition: none; cursor: grabbing; }
/* Thẻ vừa rời đỉnh: bay nghiêng ra một bên (vẫn nằm trên cùng) rồi lùi về cuối chồng. */
.c3d[data-carousel="deck"] .c3d-slide.is-flying { z-index: 200 !important; animation: deckFly 650ms var(--ease-out); }
@keyframes deckFly {
  0% { transform: none; opacity: 1; }
  45% { transform: translateX(var(--fly, 115%)) translateZ(60px) rotate(var(--fr, 9deg)) rotateY(calc(var(--fr, 9deg) * -2.5)); opacity: 0.9; }
}
.deck-card { display: block; overflow: hidden; border-radius: 18px; border: 1px solid var(--border-1); background: var(--surface); box-shadow: var(--shadow-md); }
.c3d-slide.is-active .deck-card { box-shadow: var(--shadow-lg); }
.deck-card img { display: block; width: 100%; height: auto; }

/* ---------- 3. Flip — lật khối (lời khách hàng, ảnh trong laptop) ---------- */
.c3d[data-carousel="flip"] .c3d-stage { perspective: 1600px; }
.c3d[data-carousel="flip"] .c3d-slide {
  transform-origin: 50% 50% calc(var(--fz, 240px) * -1);
  transform: rotateY(calc(var(--d) * 90deg));
  opacity: calc(1 - var(--ad) * 0.85);
  transition-duration: 820ms;
}

/* Lời khách hàng */
.t3d { --fz: 340px; max-width: 680px; margin: 0 auto; }
.t3d .test { position: relative; height: 100%; padding: 40px 36px 30px; text-align: center; box-shadow: var(--shadow-md); }
.t3d .test::before { content: "\201C"; position: absolute; top: -6px; left: 22px; font-size: 110px; line-height: 1; font-weight: 800; color: var(--brand-a20); }
.t3d .quote { font-size: 19px; line-height: 1.6; color: var(--fg-1); }
.t3d .tuser { justify-content: center; }

/* ---------- Khung thiết bị: laptop + điện thoại ---------- */
.dv-laptop { position: relative; transform-style: preserve-3d; }
.dv-lid { position: relative; padding: 14px 14px 18px; border-radius: 16px 16px 6px 6px; background: linear-gradient(160deg, #1F2937, #0B1220); box-shadow: 0 34px 60px -24px rgba(15, 23, 42, 0.5), inset 0 0 0 1px rgba(255, 255, 255, 0.08); }
.dv-cam { position: absolute; top: 5px; left: 50%; width: 5px; height: 5px; border-radius: 50%; background: #334155; translate: -50% 0; }
.dv-screen { position: relative; aspect-ratio: 16 / 10; overflow: hidden; border-radius: 6px; background: var(--surface); }
.dv-screen::after { content: ""; position: absolute; inset: 0; z-index: 3; pointer-events: none; background: linear-gradient(118deg, rgba(255, 255, 255, 0.16) 0%, rgba(255, 255, 255, 0) 38%); }
.dv-screen .sh, .dv-screen .mk-dash { height: 100%; }
.dv-base { position: relative; height: 16px; margin: 0 -7%; border-radius: 2px 2px 18px 18px; background: linear-gradient(#E2E8F0, #94A3B8); box-shadow: 0 20px 30px -14px rgba(15, 23, 42, 0.55); }
.dv-base i { position: absolute; top: 0; left: 50%; width: 16%; height: 6px; translate: -50% 0; border-radius: 0 0 8px 8px; background: #CBD5E1; }
[data-theme="dark"] .dv-base { background: linear-gradient(#475569, #1E293B); }
[data-theme="dark"] .dv-base i { background: #334155; }

.dv-phone { position: absolute; right: 0; bottom: 2%; width: 22%; aspect-ratio: 9 / 19; padding: 6px; border-radius: 26px; background: #0B1220; box-shadow: -18px 30px 50px -18px rgba(15, 23, 42, 0.6), inset 0 0 0 1px rgba(255, 255, 255, 0.12); transform: translateZ(80px) rotateY(-6deg); }
.dv-phone-screen { position: relative; height: 100%; overflow: hidden; border-radius: 20px; background: var(--surface); }
.dv-phone-screen::before { content: ""; position: absolute; top: 6px; left: 50%; z-index: 2; width: 34%; height: 9px; translate: -50% 0; border-radius: 999px; background: #0B1220; }
.dv-phone-screen > img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }

/* Trang chi tiết: khung nghiêng sẵn, trôi nhẹ; rê chuột thì nghiêng theo (--tx/--ty từ JS). */
.device3d { position: relative; perspective: 1800px; padding: 8px 0 26px; }
.dv-rig { position: relative; padding-right: 15%; transform-style: preserve-3d; transform: rotateX(var(--tx, 7deg)) rotateY(var(--ty, -13deg)); transition: transform 800ms var(--ease-out); animation: dvFloat 7s ease-in-out infinite; }
.device3d.is-tilting .dv-rig { transition-duration: 180ms; animation-play-state: paused; }
@keyframes dvFloat { 50% { translate: 0 -10px; } }
.device3d.dv-c3d { --fz: 260px; }
.device3d .dv-screen { view-transition-name: pimg; }
.device3d .c3d-stage { height: 100%; }
.device3d .c3d-slide { height: 100%; }
.device3d .c3d-slide > img { width: 100%; height: 100%; object-fit: cover; object-position: left top; display: block; cursor: zoom-in; }
.device3d .dv-shadow { position: absolute; left: 8%; right: 14%; bottom: 0; height: 30px; border-radius: 50%; background: radial-gradient(ellipse at center, rgba(15, 23, 42, 0.22), transparent 70%); filter: blur(8px); }
.device3d .c3d-ctl { margin-top: 18px; }
.dv-note { margin: 10px 0 0; text-align: center; font-size: 12px; color: var(--fg-3); }

/* Bản "báo cáo" gọn: điện thoại + slide thứ 2 trong laptop */
.mk-dash { display: flex; flex-direction: column; gap: 8px; height: 100%; padding: 22px 10px 10px; font-size: 10px; color: var(--fg-2); background: var(--surface); }
.mk-head { display: flex; flex-direction: column; gap: 1px; }
.mk-head b { font-size: 11px; line-height: 1.3; color: var(--fg-1); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.mk-head span { font-size: 9px; color: var(--fg-3); }
.mk-kpis { display: grid; gap: 6px; }
.mk-kpi { padding: 6px 8px; border-radius: 8px; background: var(--bg-brand-soft, var(--brand-50)); }
.mk-kpi span { display: block; font-size: 8.5px; color: var(--fg-3); }
.mk-kpi b { font-size: 12px; color: var(--brand-600); font-variant-numeric: tabular-nums; }
.mk-bars { flex: 1; min-height: 36px; display: flex; align-items: flex-end; gap: 3px; }
.mk-bars i { flex: 1; border-radius: 3px 3px 0 0; background: linear-gradient(var(--brand-400), var(--brand-600)); }
.mk-list div { display: flex; justify-content: space-between; gap: 6px; padding: 4px 0; border-top: 1px solid var(--border-1); }
.mk-list span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.mk-list b { white-space: nowrap; color: var(--fg-1); font-variant-numeric: tabular-nums; }
.mk-dash:not(.mk-wide) .mk-list div:nth-child(3) { display: none; }
.mk-dash.mk-wide { display: grid; grid-template-columns: 1fr 1.5fr; grid-template-rows: auto 1fr auto; gap: 12px 18px; padding: 20px 22px; font-size: 12px; }
.mk-wide .mk-head { grid-column: 1 / -1; flex-direction: row; justify-content: space-between; align-items: baseline; }
.mk-wide .mk-head b { font-size: 15px; }
.mk-wide .mk-head span { font-size: 12px; }
.mk-wide .mk-kpi { padding: 10px 12px; }
.mk-wide .mk-kpi span { font-size: 11px; }
.mk-wide .mk-kpi b { font-size: 17px; }
.mk-wide .mk-bars { gap: 7px; }
.mk-wide .mk-list { grid-column: 1 / -1; }

/* Bảng tính minh hoạ: thanh tab dưới đáy giống Google Sheets */
.sh-tabs { display: flex; gap: 2px; height: 22px; padding: 0 8px; border-top: 1px solid var(--border-1); background: #F8FAFC; font-size: 10px; color: var(--fg-3); }
.sh-tabs span { display: flex; align-items: center; padding: 0 10px; }
.sh-tabs .on { background: var(--surface); color: var(--brand-600); font-weight: 700; box-shadow: inset 0 2px 0 var(--brand-500); }
[data-theme="dark"] .sh-tabs { background: var(--bg-2); }
.sh-mock .sh-grid .cell { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sh-mock .sh-tb .t { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

/* ---------- 4. Khu "Tính năng": laptop đứng yên, đổi màn hình theo bước đang đọc ---------- */
.showcase { --p: 0.5; }
.sc-in { display: grid; grid-template-columns: 1.1fr 1fr; gap: 64px; align-items: start; }
.sc-stage { position: relative; height: 100%; }
.sc-sticky { position: sticky; top: calc(50vh - 200px); perspective: 1600px; padding: 20px 0 30px; }
.sc-device { transform-style: preserve-3d; transform: rotateX(8deg) rotateY(calc(-20deg + var(--p) * 40deg)); transition: transform 160ms linear; }
.sc-device.is-swap { animation: scSwap 700ms var(--ease-out); }
@keyframes scSwap { 35% { scale: 0.965; } }
.sc-screens { position: absolute; inset: 0; display: grid; perspective: 900px; }
.sc-screen { grid-area: 1 / 1; min-height: 0; opacity: 0; transform: translateZ(-70px) rotateX(-16deg); transform-origin: 50% 100%; transition: opacity 480ms var(--ease-out), transform 720ms var(--ease-out); }
.sc-screen.is-on { opacity: 1; transform: none; }
.sc-screen .sh { height: 100%; }
.sc-img { width: 100%; height: 100%; object-fit: cover; object-position: left top; display: block; }
.sc-step { min-height: 72vh; display: flex; flex-direction: column; justify-content: center; padding: 28px 0; transition: opacity 420ms var(--ease-out), transform 420ms var(--ease-out); }
.js .sc-step { opacity: 0.32; }
.js .sc-step.is-on { opacity: 1; }
.sc-num { display: inline-flex; align-self: flex-start; align-items: center; gap: 8px; padding: 5px 12px; border-radius: 999px; background: var(--brand-a12); color: var(--brand-600); font-size: 13px; font-weight: 800; }
.sc-step h3 { margin: 14px 0 10px; font-size: clamp(24px, 2.6vw, 32px); line-height: 1.2; }
.sc-step > p { margin: 0 0 16px; font-size: 16px; line-height: 1.65; color: var(--fg-2); }
.sc-prods { display: grid; gap: 8px; margin: 0 0 18px; padding: 0; list-style: none; }
.sc-prods a { display: flex; justify-content: space-between; gap: 12px; padding: 10px 14px; border: 1px solid var(--border-1); border-radius: 12px; background: var(--surface); color: var(--fg-1); font-weight: 600; text-decoration: none; transition: border-color var(--dur-med), transform var(--dur-med) var(--ease-out); }
.sc-prods a:hover { border-color: var(--brand-500); transform: translateX(4px); }
.sc-prods b { white-space: nowrap; color: var(--brand-600); }
.sc-more { font-weight: 700; color: var(--brand-600); }
.sc-step-screen { display: none; }

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  .c3d[data-carousel="coverflow"] { --gap: 50%; --rot: 26deg; --depth: 130px; }
  .c3d[data-carousel="coverflow"] .c3d-slide { width: min(330px, 70%); }
  .sc-in { grid-template-columns: 1fr; gap: 0; }
  .sc-stage { display: none; }
  .sc-step, .js .sc-step { min-height: 0; opacity: 1; padding: 22px 0; }
  .sc-step-screen { display: block; order: -1; margin-bottom: 18px; aspect-ratio: 16 / 10; overflow: hidden; border: 1px solid var(--border-1); border-radius: 14px; box-shadow: var(--shadow-md); }
  .sc-step-screen .sh { height: 100%; }
  .t3d { --fz: 220px; }
  .t3d .test { padding: 34px 22px 24px; }
  .t3d .quote { font-size: 17px; }
}
@media (max-width: 560px) {
  .c3d[data-carousel="coverflow"] { --gap: 42%; --rot: 22deg; }
  .c3d[data-carousel="coverflow"] .c3d-slide { width: 76%; }
  .dv-rig { padding-right: 16%; }
  .dv-phone { width: 25%; border-radius: 18px; padding: 4px; }
  .dv-phone-screen { border-radius: 14px; }
  .dv-lid { padding: 9px 9px 12px; border-radius: 12px 12px 5px 5px; }
}

/* Tắt chuyển động: vẫn giữ bố cục 3D tĩnh, bỏ mọi hiệu ứng chạy. */
@media (prefers-reduced-motion: reduce) {
  .c3d-slide, .dv-rig, .sc-device, .sc-screen, .sc-step, .hs-card { transition: none !important; animation: none !important; }
  .hs-card::after { display: none; }
}
