*,
*::before,
*::after {
  box-sizing: border-box;
}
html {
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
} /* offset badan dikawal oleh global */
img,
svg,
video {
  display: block;
  max-width: 100%;
  height: auto;
}

/* =========================
   1) CSS VARIABLES (tokens)
   ========================= */
/* Guna tokens tempatan untuk layout/typography sahaja.
   JANGAN override --header-h di sini. */
:root {
  /* spacing & sizing */
  --content-gap: 16px; /* grid gap between columns */
  --radius-md: 12px; /* card radius */
  --radius-sm: 8px;
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.2);

  /* typography */
  --text-max: 90ch;
  --ff-heading: "Poppins", system-ui, -apple-system, "Segoe UI", Roboto, Arial,
    sans-serif;
  --ff-body: "Roboto", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;

  /* colors */
  --brand: #1565c0;
  --brand-dark: #0d47a1;
  --ink: #1a1a1a;
  --meta: #555;
  --card: #f9f9f9;
  --muted: #f0f0f0;
}

/* =========================
   2) PAGE HERO / TITLE
   ========================= */
.blog-title {
  width: 100%;
  position: relative;
  min-height: 35svh;
  background-color: var(--brand);
  padding-block: var(--blogtitle-pad-y);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  margin: 0 0 12px;
  box-shadow: var(--shadow-md);
}

.blog-title-inner {
  max-width: 1100px;
  width: 100%;
}
.blog-title h1 {
  margin: 0;
  font-family: var(--ff-heading);
  font-size: clamp(1.8rem, 2vw + 1rem, 2.4rem);
  line-height: 1.25;
  letter-spacing: 0.2px;
  color: #fff;
}
.page-intro {
  max-width: 70ch;
  margin: 0.75rem auto 0;
  text-align: center;
  font-family: var(--ff-body);
  font-size: clamp(1rem, 0.4vw + 0.98rem, 1.15rem);
  line-height: 1.7;
  color: #f0f4ff;
  font-style: italic;
}

/* =====================================
   3) TWO-COLUMN ZONE: articles + sidebar
   ===================================== */
section:not(.blog-title) {
  display: flex;
  align-items: flex-start;
  gap: var(--content-gap);
  margin: 12px 20px 24px;
}
.articles {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
}

/* =========================
   4) ARTICLE CARD
   ========================= */
.info {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
  background: var(--card);
  padding: clamp(16px, 1.5vw + 8px, 24px);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  /* pastikan anchor tak ditindih header fixed */
  scroll-margin-top: calc(var(--header-h) + 20px);
}
.info .post-content {
  max-width: var(--text-max);
  font-size: 1em;
}
.info > header > h4,
.info > h4 {
  margin: 0 0 0.75rem 0;
  font-family: var(--ff-heading);
  font-size: clamp(1.6rem, 1.8vw + 1rem, 2.2rem);
  line-height: 1.25;
  font-weight: 800;
}

.info .post-content .ref-list {
  margin-right: 1rem;
}

.info .post-content .ref-list li {
  font-size: clamp(0.5rem, 0.35vw + 0.7rem, 0.95rem);
}

.info .post-content .ref-list a {
  font-size: clamp(0.5rem, 0.35vw + 0.7rem, 0.95rem);
  line-height: 1.55;
  max-width: none;
  width: 100%;
}

.info .post-content .ref-title {
  font-size: clamp(0.5rem, 0.35vw + 0.7rem, 0.95rem);
}

.post-meta {
  margin: 0 0 0.4rem 0;
  font-family: var(--ff-body);
  font-size: clamp(0.95rem, 0.25vw + 0.9rem, 1.05rem);
  color: var(--meta);
}
.post-content p {
  margin: 0 0 1rem 0;
  color: var(--ink);
  font-family: var(--ff-body);
  font-size: clamp(1.05rem, 1.2vw + 0.6rem, 1.25rem);
  line-height: 1.85;
}

.blog-image {
  text-align: center;
  margin: 1rem 0;
}
.blog-image img {
  width: 100%;
  max-width: 350px;
  height: auto;
  object-fit: cover;
  border-radius: var(--radius-sm);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  margin: 0 auto;
}

/* =========================
   5) SIDEBAR
   ========================= */
aside {
  flex: 0 0 28%;
  width: 28%;
  max-width: 30%;
  min-width: 25%;
  background: var(--muted);
  padding: clamp(14px, 1.4vw + 6px, 20px);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  align-self: stretch;
  /* anchor dalam sidebar juga elak tertutup header */
  scroll-margin-top: var(--header-h);
}
aside ul {
  margin: 0;
  padding: 0;
}
aside li {
  list-style: none;
}
aside a {
  display: block;
  margin: 0 0 0.6rem 0;
  font-family: var(--ff-heading);
  font-weight: 600;
  font-size: 1.15rem;
  color: var(--brand);
  text-decoration: none;
  transition: color 0.25s ease, transform 0.2s ease;
}
aside a:hover {
  color: var(--brand-dark);
  transform: translateX(3px);
}

/* =========================
   6) BACK-TO-TOP BUTTON
   ========================= */
#backToTop {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 4000;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 12px;
  border: 0;
  border-radius: 20px;
  font-size: 1rem;
  cursor: pointer;
  background-color: var(--brand);
  color: #fff;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s;
}
#backToTop.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}
#backToTop:hover {
  background-color: var(--brand-dark);
  transform: translateY(0) scale(1.05);
}
@media (max-width: 480px) {
  #backToTop {
    bottom: calc(72px + env(safe-area-inset-bottom, 0));
    right: 16px;
    font-size: 0.95rem;
    padding: 8px 12px;
  }
}
@media (prefers-reduced-motion: reduce) {
  #backToTop {
    transition: none;
  }
}

/* =====================================
   7) RESPONSIVE BREAKPOINTS
   ===================================== */
@media (min-width: 1536px) {
  :root {
    --content-gap: 20px;
  }
  section:not(.blog-title) {
    max-width: 1400px;
    margin: 16px auto 28px;
  }
  .info .post-content {
    max-width: 95ch;
  }
  aside {
    max-width: 28%;
  }
}
@media (min-width: 1280px) and (max-width: 1535px) {
  section:not(.blog-title) {
    max-width: 1200px;
    margin: 14px auto 24px;
  }
}
@media (max-width: 1024px) {
  section:not(.blog-title) {
    margin: 10px 16px 20px;
  }
  .post-content p {
    line-height: 1.9;
  }
}
@media (max-width: 860px) {
  section:not(.blog-title) {
    flex-direction: column;
  }
  aside {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    order: 1;
  }
  .articles {
    order: 2;
  }
}
@media (max-width: 640px) {
  .blog-title {
    padding: 32px 20px;
    margin: 0 0 12px;
    min-height: 30svh;
  }
  .post-content p {
    font-size: clamp(1rem, 1.2vw + 0.92rem, 1.18rem);
    line-height: 1.9;
  }
}
@media (max-width: 390px) {
  section:not(.blog-title) {
    margin: 8px 12px 18px;
  }
  .info,
  aside {
    padding: 14px;
    border-radius: 10px;
  }
  .info > header > h4,
  .info > h4 {
    font-size: clamp(1.4rem, 3.8vw + 0.8rem, 1.8rem);
  }
  aside a {
    font-size: 1.05rem;
  }
}

/* ==== BLOG TITLE: compact mode (override) ==== */
:root {
  /* ruang atas/bawah yang lebih rendah untuk blog-title */
  --blogtitle-pad-y: clamp(14px, 2.2vw, 34px);
}

.blog-title {
  padding-block: var(--blogtitle-pad-y);
}

.blog-title-inner {
  max-width: 1100px;
  margin-inline: auto;
  /* optional: jika nak rasa lebih seragam seperti hero */
  text-align: center;
}

/* Tajuk lebih padat & tak “tolak” ke bawah */
.blog-title h1 {
  margin: 0 0 0.4em; /* buang margin-top default */
  line-height: 1.15; /* rapat sedikit */
}

/* Perenggan intro lebih padat dan tidak “menolak” ketinggian */
.blog-title .page-intro {
  margin: 0.3em auto 0; /* kecilkan margin */
  max-width: 70ch;
  font-size: clamp(0.95rem, 0.6vw + 0.8rem, 1.1rem);
  line-height: 1.6;
}

/* Pastikan seksyen pertama tak tambah ruang pelik */
main > section.blog-title:first-of-type {
  margin-top: 0;
}

/* Extra kecil (≤640px): lagi sedikit padat) */
@media (max-width: 640px) {
  :root {
    --blogtitle-pad-y: 16px;
  }
  .blog-title h1 {
    line-height: 1.12;
  }
  .blog-title .page-intro {
    line-height: 1.55;
  }
}

/* ============================
RUJUKAN ARTIKEL — kecil, responsif, anti-overflow
   ============================ */

/* Tajuk "Rujukan" */
.ref-title {
  margin: 0.25rem 0 0.35rem;
  font-family: var(--ff-heading);
  font-weight: 700;
  font-size: clamp(0.9rem, 0.25vw + 0.85rem, 0.8rem); /* < p */
  color: var(--meta);
}

/* Senarai & item asas */
.ref-list {
  margin: clamp(0.25rem, 0.6vw, 0.6rem) 0 clamp(0.6rem, 1vw, 1rem)
    clamp(1rem, 1.2vw, 1.2rem);
  padding: 0;
  list-style: decimal;

  /* sentiasa lebih kecil dari <p> artikel */

  line-height: 1.45;
  color: var(--meta);
}

/* ===== Anti-overflow untuk URL rujukan di mobile ===== */
.ref-list,
.ref-list li,
.ref-list a {
  min-width: 0;
}
.ref-list li {
  margin-bottom: clamp(0.35rem, 0.5vw, 0.55rem);
  overflow-wrap: anywhere; /* patahkan URL panjang */
  word-break: break-word; /* fallback lama */
}

/* Pautan */
.ref-list a {
  color: var(--brand-dark);
  text-decoration: none;
  font-style: italic;
  position: relative;
}
.ref-list a::after {
  content: "↗";
  font-style: normal;
  margin-left: 0.25em;
  opacity: 0.7;
  font-size: 0.9em;
}
.ref-list a:hover,
.ref-list a:focus-visible {
  color: var(--brand);
  text-decoration: underline;
  outline: none;
}

/* Spacing & keterbacaan di skrin kecil */
@media (max-width: 640px) {
  .ref-list {
    margin-left: 1rem;
  }
  .ref-list li {
    line-height: 1.5;
  }
}

/* Guard tambahan jika ada elemen “nakal” lain menolak ke kanan */
main,
section,
.articles,
.info,
aside {
  max-width: 100%;
}

/* Mod cetak: papar URL sebenar */
@media print {
  .ref-title {
    color: #000;
  }
  .ref-list a {
    text-decoration: underline;
  }
  .ref-list a::after {
    content: " (" attr(href) ")";
    font-size: 0.85em;
    opacity: 1;
  }
}
