/* Trang gốc: gói trong đúng một màn hình, không cuộn.
   Trên: tiêu đề + mã QR trên nền họa tiết bản sao số. Dưới: bốn ô sản phẩm. */

.page-home { height: 100svh; display: grid; grid-template-rows: var(--bar) minmax(0, 1fr); overflow: hidden; }

.home {
  position: relative; isolation: isolate; min-height: 0;
  display: grid; grid-template-rows: minmax(0, 1fr) auto; gap: clamp(12px, 2svh, 24px);
  padding: clamp(14px, 2.6svh, 32px) var(--gutter) max(clamp(12px, 2.2svh, 28px), env(safe-area-inset-bottom));
}

/* ----- Họa tiết nền ----- */
.home-art { position: absolute; inset: 0; z-index: -1; overflow: hidden; }
.home-art img { width: 100%; height: 100%; object-fit: cover; object-position: 78% 40%; animation: art-drift 26s ease-in-out infinite alternate; }
.home-art::before {
  content: ""; position: absolute; inset: 0; z-index: 1;
  background:
    linear-gradient(to right, #060926 0%, #060926d9 26%, #06092600 62%),
    linear-gradient(to top, #060926 0%, #060926e6 30%, #06092600 58%);
}
/* Vệt quét chạy từ trên xuống: gợi cảm giác công trình đang được số hóa */
.home-art::after {
  content: ""; position: absolute; z-index: 2; left: 0; right: 0; top: 0; height: 28%;
  background: linear-gradient(to bottom, #00d8ff00, #00d8ff1f 92%, #00d8ff8c 100%);
  animation: art-scan 7s linear infinite;
}
@keyframes art-drift { from { transform: scale(1.02); } to { transform: scale(1.1) translate(-1.2%, -1%); } }
@keyframes art-scan { from { transform: translateY(-100%); } to { transform: translateY(360%); } }

/* ----- Phần mở đầu ----- */
.home-head { display: grid; align-content: center; gap: clamp(8px, 1.4svh, 16px); min-height: 0; max-width: 860px; }
.home-head .display { font-size: clamp(1.75rem, 0.4rem + 3.2vw + 2.4svh, 4rem); }
.home-head .display em { font-style: normal; color: var(--cyan-light); }
.home-head .body { max-width: 36ch; font-size: clamp(0.9375rem, 0.85rem + 0.45vw, 1.1875rem); }
.home-scan { display: flex; align-items: center; gap: 14px; margin-top: clamp(4px, 1.6svh, 18px); }
.home-scan .qr { flex: none; width: clamp(84px, 13svh, 128px); aspect-ratio: 1; padding: 7px; background: var(--white); border-radius: var(--radius); }
.home-scan .qr svg { width: 100%; height: 100%; }
.home-scan p { max-width: 13ch; font-size: var(--fs-small); font-weight: 700; line-height: 1.35; }

/* ----- Chỉ báo tải sẵn trên thanh trên (chỉ màn hình lớn) ----- */
.pre { display: inline-grid; place-items: center; width: 22px; height: 22px; flex: none; color: var(--cyan-light); }
.pre[hidden] { display: none; }
.pre svg { width: 22px; height: 22px; }
.pre .trk { stroke: var(--line-strong); }
.pre .bar { stroke: var(--cyan); stroke-linecap: butt; stroke-dasharray: calc(var(--p, 0) * 100) 100; transform: rotate(-90deg); transform-origin: center; transition: stroke-dasharray 300ms linear; }

/* ----- Bốn ô sản phẩm ----- */
.home-tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: clamp(8px, 1vw, 14px); height: clamp(190px, 36svh, 340px); }
.h-tile {
  position: relative; overflow: hidden; display: block; min-height: 0;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--deep);
  transition: border-color 260ms var(--ease), translate 320ms var(--ease);
  animation: tile-in 700ms var(--ease) backwards; /* chỉ dịch chuyển: ô luôn hiện, dù hiệu ứng không chạy */
}
.h-tile:nth-child(2) { animation-delay: 90ms; }
.h-tile:nth-child(3) { animation-delay: 180ms; }
.h-tile:nth-child(4) { animation-delay: 270ms; }
@keyframes tile-in { from { translate: 0 22px; } }
.h-tile img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transition: transform 800ms var(--ease); }
.h-tile::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to top, #060926 8%, #060926f2 40%, #06092600 78%); }
.h-tile::before { content: ""; position: absolute; z-index: 2; left: 0; right: 0; bottom: 0; height: 2px; background: var(--cyan); transform: scaleX(0); transform-origin: left; transition: transform 420ms var(--ease); }
.h-tile:hover, .h-tile:focus-visible { border-color: var(--cyan-light); translate: 0 -4px; }
.h-tile:hover img { transform: scale(1.06); }
.h-tile:hover::before, .h-tile:focus-visible::before { transform: scaleX(1); }
.h-chip { position: absolute; z-index: 1; top: 10px; display: grid; place-items: center; height: 32px; padding-inline: 9px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--deep); }
.h-chip.cat { left: 10px; width: 32px; padding: 0; }
.h-chip.cat svg, .h-chip.ready svg { width: 16px; height: 16px; }
.h-chip.cat svg { color: var(--cyan-light); }
/* Trạng thái tải sẵn: vạch mảnh trên đầu ô khi đang tải, dấu kiểm khi đã có trong bộ nhớ */
.h-chip.ready { left: 48px; width: 32px; padding: 0; display: none; border-color: var(--cyan); color: var(--cyan-light); animation: chip-in 360ms var(--ease); }
.h-tile[data-ready] .h-chip.ready { display: grid; }
@keyframes chip-in { from { scale: 0.6; } }
.h-prog { position: absolute; z-index: 2; left: 0; right: 0; top: 0; height: 2px; background: var(--cyan); transform: scaleX(var(--p, 0)); transform-origin: left; transition: transform 300ms linear; display: none; }
.h-tile[data-loading] .h-prog { display: block; }
.h-tile[data-ready] .h-prog { display: none; }
.h-chip.open { right: 10px; width: 32px; padding: 0; transition: background-color 260ms var(--ease), border-color 260ms var(--ease); }
.h-chip.open svg { width: 15px; height: 15px; }
.h-tile:hover .h-chip.open { background: var(--blue); border-color: var(--blue); }
.h-text { position: absolute; z-index: 1; left: 0; right: 0; bottom: 0; display: grid; gap: 3px; padding: clamp(10px, 1.2vw, 18px); }
.h-text .title { font-size: clamp(1.0625rem, 0.8rem + 0.95vw, 1.625rem); }
.h-stat { display: flex; align-items: baseline; gap: 6px; margin-top: 6px; padding-top: 8px; border-top: 1px solid var(--line); font-size: var(--fs-small); color: var(--ice); }
.h-stat b { font-size: 1.125rem; letter-spacing: -0.02em; color: var(--white); }

/* ----- Điện thoại: một dòng tiêu đề, lưới 2 × 2 gồm ảnh, biểu tượng nhóm và tên ----- */
@media (max-width: 760px) {
  .home { grid-template-rows: auto minmax(0, 1fr); gap: clamp(8px, 1.6svh, 14px); padding-top: clamp(10px, 2svh, 18px); }
  .home-head { padding-block: 0; gap: 0; }
  .home-head .hud, .home-head .body, .home-scan, .home-tagline, .h-stat, .h-text .hud, .pre { display: none; }
  .home-head .display { font-size: clamp(1.25rem, 6vw, 1.625rem); letter-spacing: -0.03em; }
  .home-art img { object-position: 84% 30%; }
  .home-art::before {
    background:
      linear-gradient(to right, #060926e6 0%, #06092699 46%, #06092633 100%),
      linear-gradient(to top, #060926 0%, #060926f2 52%, #06092600 82%);
  }
  .home-tiles { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; height: auto; min-height: 0; gap: 8px; }
  .h-chip { top: 8px; height: 28px; }
  .h-chip.cat { left: 8px; width: 28px; }
  .h-chip.ready { left: 42px; width: 28px; }
  .h-chip.open { right: 8px; width: 28px; }
  .h-chip svg { width: 14px; height: 14px; }
  .h-text { padding: 10px; }
  .h-text .title { font-size: 1rem; line-height: 1.2; }
}

/* Màn hình quá thấp (điện thoại xoay ngang): cho cuộn thay vì ép nội dung */
@media (max-height: 460px) {
  .page-home { height: auto; min-height: 100svh; overflow: visible; }
  .home-tiles { height: 220px; }
}

@media (prefers-reduced-motion: reduce) {
  .home-art img, .h-tile, .h-chip.ready { animation: none; }
  .h-prog, .pre .bar { transition: none; }
  .home-art::after { display: none; }
  .h-tile:hover { translate: none; }
}
