/* =====================================================================
   HISTORY TIMELINE — Animasi & Posisi
   Dipakai oleh: public/history.html (section "history")
   Trigger reveal: Alpine x-intersect -> menambah class .is-visible
   Posisi tiap kartu diatur via inline CSS variable:
     --x (left), --y (top), --i (stagger index), --w (lebar kartu)
   ===================================================================== */

/* ---------- Stage (wrapper timeline + popup) ----------
   Stage menampung timeline + tombol plus + popup. Stage TIDAK boleh
   container-type agar popup position:fixed (modal mobile) lolos ke viewport.
   Cap lebar & centering ada di stage; timeline width:100% mengisi stage,
   sehingga koordinat % stage == % timeline. */
.history-stage {
  position: relative;
  width: 100%;
  max-width: 100%;
  margin-inline: auto;
}

/* ---------- Cap lebar per breakpoint (di stage) ---------- */
@media (min-width: 1280px) {  /* xl */
  .history-stage { max-width: 1024px; }
}
@media (min-width: 1440px) {  /* 2xl */
  .history-stage { max-width: 1280px; }
}
@media (min-width: 1920px) {  /* 3xl */
  .history-stage { max-width: 1440px; }
}
@media (min-width: 2560px) {  /* 4xl */
  .history-stage { max-width: 1920px; }
}

/* ---------- Container timeline ---------- */
.history-timeline {
  position: relative;
  width: 100%;
  /* Kunci proporsi background (1440 x 2063) agar koordinat % tetap akurat
     di semua resolusi, dari mobile sampai 4K. */
  aspect-ratio: 1440 / 2063;
  /* Jadikan timeline sebagai container query, supaya font description
     (cqw) skala MULUS terhadap lebar timeline di semua resolusi. */
  container-type: inline-size;
}

/* Background timeline = tulang punggung */
.history-timeline__bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}

/* ---------- Kartu per tahun ---------- */
.hist-piece {
  position: absolute;
  top: var(--y, 0%);
  left: var(--x, 0%);
  width: var(--w, 28%);
  margin: 0;
  padding: 0;
  z-index: 2;
  /* State awal (belum revealed) */
  opacity: 0;
  transform: translateY(28px) scale(0.94);
  filter: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.12));
  transition:
    opacity 1.2s cubic-bezier(0.22, 1, 0.36, 1),
    transform 1.2s cubic-bezier(0.22, 1, 0.36, 1),
    filter 0.45s ease;
  transition-delay: calc(var(--i, 0) * 90ms);
  will-change: opacity, transform;
  cursor: pointer;
}

/* Arah slide masuk sesuai sisi penempatan (efek S-curve mengalir) */
.hist-piece[data-side="left"] {
  transform: translateY(28px) translateX(-24px) scale(0.94);
}
.hist-piece[data-side="right"] {
  transform: translateY(28px) translateX(24px) scale(0.94);
}

.hist-piece img {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

/* ---------- State REVEAL (di-toggle oleh x-intersect) ---------- */
.hist-piece.is-visible {
  opacity: 1;
  transform: translateY(0) translateX(0) scale(1);
}

/* ---------- Hover interaktif (hanya setelah muncul) ---------- */
/* Zoom & lift diperkecil & dihaluskan: 2% zoom, 3px lift, transisi 0.5s ease-out lembut. */
.hist-piece.is-visible:hover {
  transform: scale(1.02) translateY(-3px);
  filter: drop-shadow(0 14px 24px rgba(0, 0, 0, 0.20)) brightness(1.03);
  z-index: 5;
  transition-duration: 0.15s;
  transition-timing-function: cubic-bezier(0.22, 1, 0.36, 1);
}

/* ---------- Kotak description dinamis (menempel di tiap kartu) ----------
   Posisi diatur per-kartu via --tx/--ty/--tw (relatif terhadap kartu, bukan timeline).
   Konten nantinya dinamis dari CI4 API; sementara manual untuk demo.
   Catatan: saat ini text description JUGA masih baked-in di gambar (transisi duplikat)
   → begitu aset bersih (description dihapus dari PNG), kotak ini jadi satu-satunya description. */
.hist-desc {
  position: absolute;
  left: var(--tx, 8%);
  top: var(--ty, 60%);
  width: var(--tw, 84%);
  padding: 4px 6px;
  background: rgba(255, 255, 255, 0.62);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  /* border: 1px solid rgba(17, 17, 17, 0.12); */
  border-radius: 6px;
  font-family: 'Figtree', system-ui, sans-serif;
  /* Font skala MULUS terhadap lebar timeline (bukan step per breakpoint).
     1.1cqw = 1.1% lebar timeline. clamp batas min/max agar aman.
     Override per-kartu: set --desc-size di inline style figure. */
  font-size: var(--desc-size, clamp(3px, 1.1cqw, 24px));
  font-weight: 400;
  line-height: 1.3;
  color: #111;
  text-align: left;
  pointer-events: none;   /* agar hover kartu tetap aktif */
  z-index: 3;
}

/* ---------- Responsive: kartu mengecil di layar sempit ---------- */
@media (max-width: 768px) {
  .hist-piece {
    width: var(--w, 32%);
  }
}

/* ---------- Aksesibilitas: hormati pengguna yang minta gerakan minimal ---------- */
@media (prefers-reduced-motion: reduce) {
  .hist-piece {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }
  .hist-plus { animation: none !important; }
}

/* =====================================================================
   POPUP HISTORY — tombol plus + popup adaptif
   Mode: <768px (mobile) = MODAL terpusat (fixed + backdrop)
         >=768px (tablet + desktop) = POPOVER dekat tombol (absolute + arrow)
   State: Alpine activePopup di .history-stage. Tombol di dalam .history-timeline.
   ===================================================================== */

/* ---------- Tombol plus (di dalam timeline) ---------- */
.hist-plus {
  position: absolute;
  left: var(--bx, 40%);
  top: var(--by, 50%);
  width: var(--bw, 2.5%);
  padding: 0;
  margin: 0;
  border: 0;
  background: transparent;
  border-radius: 50%;
  cursor: pointer;
  z-index: 6;
  /* pulse jelas: scale lebih besar + ring (sonar) berwarna brand.
     Ubah --plus-color untuk ganti warna ring, --plus-speed untuk kecepatan. */
  --plus-color: 255, 115, 36;             /* #FF7324 dark-orange (brand) */
  animation: hist-plus-pulse 1.8s ease-out infinite;
  transition: transform .2s ease, filter .2s ease;
}
.hist-plus:hover { transform: scale(1.14); filter: brightness(1.08); }
.hist-plus[aria-expanded="true"] { animation: none; transform: scale(1.1); box-shadow: none; }
.hist-plus img {
  display: block; width: 100%; height: auto; position: relative; z-index: 2;
  pointer-events: none; user-select: none; -webkit-user-drag: none;
}
@keyframes hist-plus-pulse {
  0%   { transform: scale(1);    box-shadow: 0 0 0 0 rgba(var(--plus-color), 0.55); }
  70%  { transform: scale(1.12); box-shadow: 0 0 0 calc(var(--bw, 2.5%) + 6px) rgba(var(--plus-color), 0); }
  100% { transform: scale(1);    box-shadow: 0 0 0 0 rgba(var(--plus-color), 0); }
}

/* ---------- Popup (DEFAULT = MODAL mobile <768px) ---------- */
.hist-popup {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6%;
  background: rgba(17, 17, 17, 0.55);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

/* kartu popup
   Ukuran MANUAL per breakpoint via var (override inline per-popup):
     --pop-w-sm / --pop-h-sm  -> mobile  (<768px, mode MODAL)
     --pop-w-md / --pop-h-md  -> tablet  (>=768px, mode POPOVER)
     --pop-w-lg / --pop-h-lg  -> desktop (>=1024px, mode POPOVER)
   Default: width terbatas, height auto (mengikuti rasio gambar).
   Kalau height di-set, gambar di-object-fit:contain (rapi, tidak terpotong). */
/* Kartu popup.
   Border gradient: padding tipis (1.5px) + background gradient + inner putih.
   Layout isi di-handle oleh Tailwind di markup (30% gambar | 70% tahun+desc).

   UKURAN FIXED per breakpoint (rasio ~2:1, lebar : tinggi) supaya konsisten &
   profesional — TIDAK mengikuti konten. Yang berubah antar-breakpoint HANYA
   ukuran font (tahun & deskripsi) di markup. Override via var:
     --pop-w-<bp> / --pop-h-<bp>   (sm md lg xl 2xl 3xl 4xl) */
.hist-popup__card {
  position: relative;
  width: var(--pop-w-sm, 320px);
  height: var(--pop-h-sm, 110px);
  max-height: 86vh;
  padding: 1.5px;                       /* ketebalan "border" gradient */
  border-radius: 0.375rem;              /* rounded-md (6px) */
  /* gradient identik dgn border-bottom-gradient / bg-color-gradient di halaman */
  background: linear-gradient(90deg,
              rgba(132, 225, 255, 1) 5.73%,
              rgba(129, 241, 142, 1) 22%,
              rgba(249, 230, 63, 1) 39%,
              rgba(107, 166, 255, 1) 57%,
              rgba(238, 136, 255, 1) 76%,
              rgba(255, 115, 36, 1) 95%);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}
/* Wadah putih di dalam border gradient — di sini layout 30/70 diletakkan.
   Radius sedikit lebih kecil (radius card - padding) biar mengikuti lekuk border.
   overflow:hidden agar sudut gambar ikut membulat. */
.hist-popup__inner {
  position: relative;
  display: flex;
  width: 100%;
  height: 100%;
  border-radius: calc(0.375rem - 1.5px);
  overflow: hidden;
  background: #fff;
}

/* tombol close (X) */
.hist-popup__close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  color: #111;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
  transition: background .2s ease, color .2s ease, transform .2s ease;
}
/* Hover -> merah, ikon X jadi putih (transisi warna halus). */
.hist-popup__close:hover { background: #e11d2a; color: #fff; transform: scale(1.08); }

/* ---------- >=768px (tablet + desktop) = POPOVER dekat tombol ---------- */
@media (min-width: 768px) {
  .hist-popup {
    position: absolute;
    inset: auto;
    left: var(--px, 40%);
    top: var(--py, 40%);
    padding: 0;
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    align-items: flex-start;
    justify-content: flex-start;
    z-index: 8;             /* di bawah navbar (z-10), di atas kartu (z-2) & tombol (z-6) */
  }
  .hist-popup__card {
    /* TABLET (>=768): ukuran FIXED (rasio ~2:1). */
    width: var(--pop-w-md, 360px);
    height: var(--pop-h-md, 120px);
    max-height: none;
    /* --px/--py = posisi tombol. Card duduk di ATAS tombol (arrow nunjuk ke bawah):
       geser kiri 50% (center horizontal) & naik 100% + gap. */
    transform: translate(-50%, calc(-100% - 12px));
  }
  /* arrow penunjuk ke bawah (popup di atas tombol) */
  .hist-popup__card::after {
    content: "";
    position: absolute;
    left: 50%;
    bottom: -8px;
    transform: translateX(-50%);
    border-left: 9px solid transparent;
    border-right: 9px solid transparent;
    border-top: 9px solid #fff;
  }
}

/* ---------- Desktop: ukuran FIXED (rasio ~2:1) per breakpoint ---------- */
@media (min-width: 1024px) {        /* lg */
  .hist-popup__card {
    width: var(--pop-w-lg, 380px);
    height: var(--pop-h-lg, 120px);
  }
}
@media (min-width: 1280px) {        /* xl */
  .hist-popup__card {
    width: var(--pop-w-xl, 400px);
    height: var(--pop-h-xl, 130px);
  }
}
@media (min-width: 1440px) {        /* 2xl */
  .hist-popup__card {
    width: var(--pop-w-2xl, 420px);
    height: var(--pop-h-2xl, 140px);
  }
}
@media (min-width: 1920px) {        /* 3xl */
  .hist-popup__card {
    width: var(--pop-w-3xl, 460px);
    height: var(--pop-h-3xl, 150px);
  }
}
@media (min-width: 2560px) {        /* 4xl */
  .hist-popup__card {
    width: var(--pop-w-4xl, 520px);
    height: var(--pop-h-4xl, 160px);
  }
}
