/* =========================================================
   PALET WARNA  (ubah di blok ini)
   ========================================================= */
:root {
  /* 5 warna dasar dari gambar palet */
  --p1: #e3dcbf;   /* krem terang */
  --p2: #bdba92;   /* khaki */
  --p3: #7f8673;   /* sage */
  --p4: #555649;   /* olive tua */
  --p5: #2d2e29;   /* hampir hitam */
  --p5-rgb: 45, 46, 41;

  /* peran warna */
  --judul: var(--p2);
  --teks: var(--p1);
  --teks-lembut: var(--p2);
  --kertas: var(--p1);
  --kertas-2: #ece6cf;
  --kertas-gelap: #d5cfb1;
  --tinta: var(--p5);
  --tinta-lembut: var(--p4);
  --garis: var(--p3);
  --aksen: var(--p3);
  --aksen-2: var(--p4);

  /* foto latar halaman */
  --tekstur: url("img/bg.jpg");

  /* seberapa gelap foto latar (0 = foto polos, 0.8 = sangat gelap) */
  --gelap-foto: 0.45;
}

/* ===== FONT KUSTOM ===== */
@font-face {
  font-family: "FontJudul";
  src: url("fonts/judul.ttf"),
       url("fonts/judul.otf"),
       url("fonts/judul.woff2"),
       url("fonts/judul.woff");
  font-display: swap;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  color: var(--teks);
  text-align: center;
  padding: 40px 20px;
  min-height: 100vh;
  background-color: var(--p5);
}

/* ===== BACKGROUND FOTO (satu lapisan tetap, ringan) ===== */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    linear-gradient(rgba(var(--p5-rgb), var(--gelap-foto)), rgba(var(--p5-rgb), var(--gelap-foto))),
    var(--tekstur) center / cover no-repeat;
  transform: translateZ(0);
}

h1 {
  font-family: "FontJudul", Georgia, serif;
  font-weight: normal;
  font-size: 2.6rem;
  color: var(--judul);
}

.hint { color: var(--teks-lembut); }

/* ===== Grid kartu ===== */
main {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px;
  max-width: 800px;
  margin: 30px auto 0;
}

figure {
  margin: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  animation: cardIn 0.5s cubic-bezier(.2, .8, .2, 1) both;
  animation-delay: calc(var(--i, 0) * 70ms);
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: none; }
}

/* pembungkus gambar (tempat efek glitch) */
.thumb {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.5);
  transition: transform 0.3s cubic-bezier(.2, .8, .2, 1);
  background: var(--p5);
}

.thumb img {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
}

/* dua lapisan salinan gambar: garis tipis yang bergeser */
.thumb::before,
.thumb::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--img) center / cover no-repeat;
  opacity: 0;
  pointer-events: none;
}

/* ===== EFEK GLITCH: saat kursor di atas kartu / jari menahan kartu ===== */
figure:hover .thumb,
figure:active .thumb {
  transform: translateY(-6px) scale(1.04);
}

figure:hover .thumb img,
figure:active .thumb img {
  animation: glitchShake 0.3s steps(1, end) infinite;
}

figure:hover .thumb::before,
figure:active .thumb::before {
  opacity: 1;
  animation: glitchSliceA 0.35s steps(1, end) infinite;
}

figure:hover .thumb::after,
figure:active .thumb::after {
  opacity: 1;
  animation: glitchSliceB 0.28s steps(1, end) infinite;
}

@keyframes glitchShake {
  0%   { transform: translate(0, 0) skewX(0); }
  7%   { transform: translate(-2px, 1px) skewX(-1.5deg); }
  14%  { transform: translate(2px, -1px) skewX(1deg); }
  21%  { transform: translate(-1px, 2px) skewX(0); }
  28%  { transform: translate(0, 0) skewX(0); }
  37%  { transform: translate(2px, 1px) skewX(2deg); }
  44%  { transform: translate(-2px, -1px) skewX(-1deg); }
  52%  { transform: translate(0, 0) skewX(0); }
  61%  { transform: translate(1px, -2px) skewX(1.5deg); }
  69%  { transform: translate(-2px, 1px) skewX(0); }
  78%  { transform: translate(2px, 2px) skewX(-2deg); }
  86%  { transform: translate(0, 0) skewX(0); }
  93%  { transform: translate(-1px, -1px) skewX(1deg); }
  100% { transform: translate(0, 0) skewX(0); }
}

@keyframes glitchSliceA {
  0%   { clip-path: inset(12% 0 85% 0); transform: translate(-4px, 0); }
  9%   { clip-path: inset(34% 0 63% 0); transform: translate(3px, 0); }
  18%  { clip-path: inset(0 0 100% 0);  transform: translate(0, 0); }
  27%  { clip-path: inset(58% 0 39% 0); transform: translate(-5px, 0); }
  36%  { clip-path: inset(21% 0 74% 0); transform: translate(4px, 0); }
  45%  { clip-path: inset(0 0 100% 0);  transform: translate(0, 0); }
  54%  { clip-path: inset(77% 0 20% 0); transform: translate(-3px, 0); }
  63%  { clip-path: inset(44% 0 51% 0); transform: translate(5px, 0); }
  72%  { clip-path: inset(0 0 100% 0);  transform: translate(0, 0); }
  81%  { clip-path: inset(6% 0 90% 0);  transform: translate(-4px, 0); }
  90%  { clip-path: inset(66% 0 31% 0); transform: translate(3px, 0); }
  100% { clip-path: inset(12% 0 85% 0); transform: translate(-4px, 0); }
}

@keyframes glitchSliceB {
  0%   { clip-path: inset(68% 0 29% 0); transform: translate(4px, 0); }
  11%  { clip-path: inset(0 0 100% 0);  transform: translate(0, 0); }
  20%  { clip-path: inset(15% 0 81% 0); transform: translate(-5px, 0); }
  29%  { clip-path: inset(82% 0 15% 0); transform: translate(3px, 0); }
  38%  { clip-path: inset(0 0 100% 0);  transform: translate(0, 0); }
  47%  { clip-path: inset(40% 0 56% 0); transform: translate(5px, 0); }
  56%  { clip-path: inset(3% 0 94% 0);  transform: translate(-3px, 0); }
  65%  { clip-path: inset(0 0 100% 0);  transform: translate(0, 0); }
  74%  { clip-path: inset(62% 0 34% 0); transform: translate(-5px, 0); }
  83%  { clip-path: inset(27% 0 69% 0); transform: translate(4px, 0); }
  92%  { clip-path: inset(0 0 100% 0);  transform: translate(0, 0); }
  100% { clip-path: inset(68% 0 29% 0); transform: translate(4px, 0); }
}

/* ===== Saat kartu dibuka: glitch berhenti total, kartu disembunyikan ===== */
figure.is-open .thumb,
figure.is-open figcaption {
  opacity: 0;
  transition: none;
}

figure.is-open .thumb img,
figure.is-open .thumb::before,
figure.is-open .thumb::after {
  animation: none;
  opacity: 0;
}

figcaption {
  margin-top: 8px;
  font-family: "FontJudul", Georgia, serif;
  font-size: 1.15rem;
  color: var(--teks);
}

/* ===== Popup ===== */
dialog {
  width: min(95vw, 900px);
  max-height: 90vh;
  overflow-y: auto;
  overflow-x: hidden;
  border: 0;
  border-radius: 16px;
  padding: 28px;
  text-align: left;
  color: var(--tinta);
  background: var(--kertas-2);
}

dialog::backdrop { background: rgba(var(--p5-rgb), 0.72); }

dialog[open]::backdrop {
  animation: fadeIn 0.4s ease both;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* isi popup muncul bergantian dari bawah */
dialog[open] .wiki-main > *,
dialog[open] .infobox > * {
  animation: riseIn 0.5s cubic-bezier(.2, .8, .2, 1) both;
  animation-delay: calc(0.2s + var(--i, 0) * 50ms);
}

@keyframes riseIn {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: none; }
}

#close {
  position: sticky;
  top: 0;
  float: right;
  border: 0;
  background: var(--p2);
  color: var(--p5);
  border-radius: 50%;
  width: 34px;
  height: 34px;
  cursor: pointer;
  z-index: 5;
  transition: transform 0.25s, background 0.25s;
}
#close:hover { transform: rotate(90deg); background: var(--p3); }

/* Layout 2 kolom (lebar kolom dikunci) */
.wiki {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 28px;
  clear: both;
}

.wiki-main { min-width: 0; }

.wiki-main h2,
.wiki-main h3,
.timeline summary,
.info-name,
.info-title {
  font-family: "FontJudul", Georgia, serif;
  font-weight: normal;
}

.wiki-main h2 {
  font-size: 1.7rem;
  margin: 24px 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(85, 86, 73, 0.4);
}
.wiki-main h2:first-child { margin-top: 0; }

.wiki-main h3 { font-size: 1.3rem; margin: 20px 0 8px; }

.wiki-main ul { margin: 0; padding-left: 22px; }
.wiki-main li { margin-bottom: 6px; line-height: 1.5; }

/* Timeline (toggle) */
.timeline { margin: 24px 0 8px; }
.timeline summary {
  font-size: 1.7rem;
  cursor: pointer;
}
.timeline ul { margin-top: 10px; }

/* Tabel */
table { width: 100%; border-collapse: collapse; }
th, td {
  border: 1px solid rgba(85, 86, 73, 0.35);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
  font-weight: normal;
}
th { background: var(--kertas-gelap); width: 42%; }
.table-wide th { width: 50%; font-weight: bold; }

/* Infobox kanan */
.infobox { min-width: 0; }

.infobox img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  aspect-ratio: 3 / 4;
  max-height: 380px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--kertas-gelap);
  transform: rotate(-1.5deg);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.35);
  margin-bottom: 14px;
}

.info-name {
  text-align: center;
  font-size: 1.4rem;
  padding: 10px 0;
  border-bottom: 1px solid rgba(85, 86, 73, 0.4);
}

.info-title {
  text-align: center;
  margin: 18px 0 8px;
  font-size: 1.2rem;
}

/* HP: infobox pindah ke atas */
@media (max-width: 700px) {
  dialog { padding: 18px; }
  .wiki { grid-template-columns: minmax(0, 1fr); }
  .infobox { order: -1; }
  .infobox img { max-height: 320px; }
}

/* Hormati pengaturan "kurangi gerakan" */
@media (prefers-reduced-motion: reduce) {
  figure { animation: none; }
  figure:hover .thumb img,
  figure:active .thumb img,
  figure:hover .thumb::before,
  figure:active .thumb::before,
  figure:hover .thumb::after,
  figure:active .thumb::after { animation: none; }
  dialog[open] .wiki-main > *,
  dialog[open] .infobox > *,
  dialog[open]::backdrop { animation: none; }
}