*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  overflow-x: clip;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #f9f9f9;
  color: #1a1a1a;
  line-height: 1.7;
  overflow-x: clip;
  max-width: 100vw;
}

img {
  max-width: 100%;
  height: auto;
}

/* ── Header ── */
header {
  background: #fff;
  border-bottom: 1px solid #e5e5e5;
  padding: 0 2rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1600px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  gap: 1rem;
}

.site-title {
  font-weight: 600;
  font-size: 1rem;
  color: #1a1a1a;
  white-space: nowrap;
  text-decoration: none;
}

.site-title:hover { color: #333; }

nav {
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

nav a {
  text-decoration: none;
  color: #555;
  font-size: 0.875rem;
  padding: 4px 0;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
  white-space: nowrap;
}

nav a:hover, nav a.active {
  color: #1a1a1a;
  border-bottom-color: #1a1a1a;
}

/* ── Main layout ── */
main {
  max-width: 1600px;
  margin: 0 auto;
  padding: 2.5rem 2rem 4rem;
}

/* ── Intro paragraph ── */
p.intro {
  font-size: 1rem;
  color: #333;
  margin-bottom: 2rem;
  max-width: 860px;
  hyphens: none;
  word-break: normal;
  overflow-wrap: break-word;
}

/* ── Projects grid ── */
.projects-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
  align-items: stretch;
}

/* ── Project card ── */
.project-card {
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 10px;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  transition: box-shadow 0.2s, transform 0.2s;
}

.project-card:hover {
  box-shadow: 0 4px 20px rgba(0,0,0,0.08);
  transform: translateY(-2px);
}

.card-image {
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #f0f0f0;
}

.card-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top;
  display: block;
}

.card-body {
  padding: 1.25rem 1.5rem 1.5rem;
  display: flex;
  flex-direction: column;
  flex-grow: 1;
}

.project-card h3 {
  font-size: 1.05rem;
  margin-bottom: 0.6rem;
  color: #1a1a1a;
}

.project-card p {
  font-size: 0.875rem;
  color: #555;
  flex-grow: 1;
  margin-bottom: 1rem;
  line-height: 1.6;
}

.card-link {
  font-size: 0.85rem;
  font-weight: 600;
  color: #0066cc;
  margin-top: auto;
}

/* ── TOC layout ── */
.toc-layout {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 2.5rem;
  align-items: start;
}

.toc {
  position: sticky;
  top: 72px;
  max-height: calc(100vh - 90px);
  overflow-y: auto;
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  padding: 1rem 1rem 1.25rem;
}

.toc-title {
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #999;
  margin-bottom: 0.6rem;
}

.toc ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.toc li { margin-bottom: 0.2rem; }

.toc a {
  font-size: 0.8rem;
  color: #555;
  text-decoration: none;
  display: block;
  padding: 2px 4px;
  border-radius: 3px;
  line-height: 1.4;
  transition: color 0.15s, background 0.15s;
}

.toc a:hover {
  color: #1a1a1a;
  background: #f5f5f5;
}

.toc-h1 {}
.toc-h2 { padding-left: 0.6rem; }
.toc-h3 { padding-left: 1.2rem; }

/* ── TOC main content ── */
.toc-main h1 { font-size: 1.6rem; margin: 2rem 0 0.75rem; font-weight: 700; }
.toc-main h1 strong { font-weight: inherit; }
.toc-main h2 { font-size: 1.25rem; margin: 1.75rem 0 0.6rem; color: #1a1a1a; }
.toc-main h3 { font-size: 1rem; font-weight: 600; margin: 1.25rem 0 0.5rem; }
.toc-main p { margin-bottom: 0.85rem; color: #333; }
.toc-main ul, .toc-main ol { margin: 0.5rem 0 1rem 1.4rem; }
.toc-main li { margin-bottom: 0.3rem; font-size: 0.9rem; color: #333; line-height: 1.6; }

/* Compact code blocks for schema/SQL */
.toc-main pre {
  font-size: 0.78rem;
  line-height: 1.5;
  padding: 0.75rem 1rem;
  margin: 0.5rem 0 1.25rem;
  background: #f6f8fa;
  border: 1px solid #e5e5e5;
  border-radius: 6px;
  overflow-x: auto;
  max-height: 380px;
  overflow-y: auto;
}

/* Compact tables */
.toc-main table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  margin: 0.5rem 0 1.25rem;
}

.toc-main th,
.toc-main td {
  padding: 0.3rem 0.6rem;
  border: 1px solid #ddd;
  text-align: left;
}

.toc-main th {
  background: #f5f5f5;
  font-weight: 600;
}

/* Indented aside note */
p.aside-note {
  margin: 1rem 2rem 1rem;
  padding: 0.75rem 1.25rem;
  border-left: 3px solid #d0d0d0;
  background: #f9f9f9;
  color: #555;
  font-size: 0.875rem;
}

/* 3-column image grid */
.img-triple {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin: 0.75rem 0 1.25rem;
  align-items: start;
}

.img-triple img { border-radius: 6px; display: block; width: 100%; height: auto; }

/* Side-by-side image pairs */
.img-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin: 0.75rem 0 1.25rem;
  align-items: start;
}

.img-pair img,
.img-pair figure { width: 100%; }

.img-pair img {
  border-radius: 6px;
  display: block;
  width: 100%;
  height: auto;
}

/* 4-column image grid */
.img-quad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
  margin: 0.75rem auto 1.25rem;
  align-items: start;
  max-width: 900px;
}

.img-quad img,
.img-quad figure { width: 100%; }

.img-quad img {
  border-radius: 6px;
  display: block;
  width: 100%;
  height: auto;
}

@media (max-width: 900px) {
  .img-quad { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .img-pair { grid-template-columns: 1fr; }
  .img-quad { grid-template-columns: 1fr 1fr; }
}

/* Image captions (figcaption from alt text) */
figure.img-captioned {
  margin: 0;
  display: block;
}

figure.img-captioned img {
  width: 100%;
  border-radius: 6px;
  display: block;
}

figure.img-captioned figcaption {
  font-size: 0.75rem;
  color: #666;
  margin-top: 0.35rem;
  line-height: 1.4;
}

/* Standalone captioned figure (not inside a grid) */
.toc-main > figure.img-captioned,
.findings-card figure.img-captioned {
  margin: 0.75rem 0 1.25rem;
}

/* Collapsible code blocks */
details.code-collapsible {
  margin: 0.75rem 0 1.25rem;
  border: 1px solid #e5e5e5;
  border-radius: 6px;
  overflow: hidden;
}

details.code-collapsible summary {
  padding: 0.45rem 1rem;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  color: #555;
  background: #f6f8fa;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

details.code-collapsible summary::before {
  content: '▶';
  font-size: 0.65rem;
  transition: transform 0.15s;
}

details.code-collapsible[open] summary::before {
  transform: rotate(90deg);
}

details.code-collapsible summary::-webkit-details-marker { display: none; }
details.code-collapsible summary:hover { background: #eef0f2; color: #1a1a1a; }
details.code-collapsible[open] summary { border-bottom: 1px solid #e5e5e5; }

details.code-collapsible pre {
  margin: 0 !important;
  border-radius: 0 !important;
  border: none !important;
  max-height: none;
}

/* Code block alongside section text — text on left, code on right */
.code-alongside {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  align-items: start;
  margin: 0.75rem 0 1.5rem;
}

.code-alongside-text,
.code-alongside-code {
  min-width: 0;
}

/* Remove scroll cap for code in side-by-side layout — full code visible */
.code-alongside-code pre {
  margin: 0;
  max-height: none;
}

/* Tone down formula blocks inside code-alongside to sit flush */
.code-alongside-text p.formula {
  margin-top: 0.5rem;
}

@media (max-width: 900px) {
  .code-alongside {
    grid-template-columns: 1fr;
  }
}

.toc-main pre code {
  background: none;
  padding: 0;
  font-size: inherit;
}

/* ── Schema 2×2 grid ── */
.schema-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin: 1rem 0 1.5rem;
}

.schema-card {
  background: #fff;
  border: 1px solid #e1e4e8;
  border-radius: 6px;
  padding: 0.9rem 1rem;
  overflow: hidden;
  min-width: 0;
}

.schema-card h3 {
  font-size: 0.82rem;
  font-weight: 600;
  margin: 0 0 0.6rem;
  color: #1a1a1a;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid #e1e4e8;
}

.schema-card pre {
  margin: 0;
  font-size: 0.7rem;
  line-height: 1.45;
  padding: 0.5rem 0.6rem !important;
  border-radius: 4px;
  overflow-x: auto;
}

.schema-card p {
  font-size: 0.82rem;
  margin-bottom: 0.4rem;
}

.schema-card img {
  max-width: 100%;
  border-radius: 4px;
}

@media (max-width: 768px) {
  .toc-layout {
    grid-template-columns: 1fr;
  }
  .toc {
    position: static;
    max-height: none;
    margin-bottom: 1.5rem;
  }
  .schema-grid {
    grid-template-columns: 1fr;
  }
}

/* ── Live dashboard embed ── */
.dashboard-embed {
  position: relative;
  width: 100%;
  padding-top: 75%; /* matches 1200x900 dashboard (4:3) */
  margin-bottom: 2.5rem;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #e5e5e5;
  background: #f9f9f9;
}

.dashboard-embed iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: none;
}

/* ── General content styles (dashboard pages) ── */
.content h1 { font-size: 2rem; margin-bottom: 1rem; }
.content h2 { font-size: 1.4rem; margin: 2rem 0 0.75rem; }
.content h3 { font-size: 1.1rem; margin: 1.5rem 0 0.5rem; }
.content p { margin-bottom: 1rem; color: #333; }
.content a { color: #0066cc; text-decoration: underline; }
.content ul, .content ol { margin: 0.75rem 0 1rem 1.5rem; }
.content li { margin-bottom: 0.25rem; }
.content img { max-width: 100%; border-radius: 8px; margin: 1rem 0; }
.content code { background: #f0f0f0; padding: 2px 6px; border-radius: 3px; font-size: 0.9em; }
.content pre { background: #f0f0f0; padding: 1rem; border-radius: 6px; overflow-x: auto; margin: 1rem 0; }
.content blockquote { border-left: 3px solid #ddd; padding-left: 1rem; color: #555; margin: 1rem 0; }
.content table { width: 100%; border-collapse: collapse; margin: 1rem 0; }
.content th, .content td { padding: 0.5rem 0.75rem; border: 1px solid #ddd; text-align: left; }
.content th { background: #f5f5f5; font-weight: 600; }

/* ── Page hero (Notion cover image) ── */
.page-hero {
  width: 100%;
  height: 180px;
  overflow: hidden;
  border-radius: 10px;
  margin-bottom: 1.75rem;
}

.page-hero img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 55%;
  display: block;
}

/* ── Inline formula display ── */
p.formula {
  background: #f6f8fa;
  border: 1px solid #e5e5e5;
  border-radius: 6px;
  padding: 0.6rem 1rem;
  font-size: 0.9rem;
  margin: 0.75rem 0 1rem;
  color: #333;
}

/* ── Key Findings 2-column grid (Countrywide) ── */
.findings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 0.5rem;
}

.findings-card {
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
}

.findings-card h2 {
  margin-top: 0;
}

@media (max-width: 900px) {
  .findings-grid { grid-template-columns: 1fr; }
}

/* ── Footer ── */
footer {
  height: 2rem;
}

/* ── Image lightbox ── */
.lightbox-trigger {
  cursor: zoom-in;
}

#lightbox-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

#lightbox-overlay.open {
  display: flex;
}

#lightbox-overlay img {
  max-width: 100%;
  max-height: 90vh;
  border-radius: 6px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
  object-fit: contain;
}

#lightbox-overlay button {
  position: fixed;
  top: 1rem;
  right: 1.25rem;
  background: none;
  border: none;
  color: #fff;
  font-size: 2rem;
  cursor: pointer;
  line-height: 1;
  opacity: 0.8;
}

#lightbox-overlay button:hover { opacity: 1; }

/* ── Hamburger button ── */
.nav-hamburger {
  display: none;
  flex-direction: column;
  justify-content: space-between;
  width: 22px;
  height: 16px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}

.nav-hamburger span {
  display: block;
  height: 2px;
  background: #1a1a1a;
  border-radius: 2px;
  transition: transform 0.2s, opacity 0.2s;
}

.nav-hamburger.is-open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-hamburger.is-open span:nth-child(2) { opacity: 0; }
.nav-hamburger.is-open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ── Responsive: tablet — nav wraps to two rows, no hamburger ── */
@media (max-width: 1100px) {
  .projects-grid { grid-template-columns: repeat(2, 1fr); }
  nav { gap: 0.75rem; }
  nav a { font-size: 0.8rem; }
}

@media (max-width: 1100px) and (min-width: 501px) {
  header { padding: 0 1.5rem; }

  .header-inner {
    height: auto;
    min-height: 52px;
    flex-wrap: wrap;
    padding: 0.5rem 0;
    gap: 0.5rem;
  }

  .site-title { flex-shrink: 0; }

  nav {
    flex-wrap: wrap;
    width: 100%;
    justify-content: flex-start;
    padding-bottom: 0.4rem;
  }
}

/* ── Responsive: mobile — hamburger ── */
@media (max-width: 500px) {

  /* Header */
  header { padding: 0 1.25rem; }

  .header-inner {
    height: 52px;
    position: relative;
  }

  /* Hamburger visible, nav hidden by default */
  .nav-hamburger { display: flex; }

  #main-nav {
    display: none;
    position: absolute;
    top: 52px;
    left: -1.25rem;
    right: -1.25rem;
    background: #fff;
    border-top: 1px solid #e5e5e5;
    border-bottom: 1px solid #e5e5e5;
    flex-direction: column;
    padding: 0.5rem 1.25rem 0.75rem;
    gap: 0;
    box-shadow: 0 6px 16px rgba(0,0,0,0.08);
    z-index: 200;
  }

  #main-nav.nav-open { display: flex; }

  #main-nav a {
    padding: 0.7rem 0;
    font-size: 0.95rem;
    border-bottom: 1px solid #f0f0f0;
    white-space: normal;
  }

  #main-nav a:last-child { border-bottom: none; }

  /* Main content */
  main { padding: 1.5rem 1rem 3rem; }

  /* Prevent any element from blowing out the viewport */
  .content, .toc-main, .toc-layout {
    max-width: 100%;
    overflow-x: hidden;
  }

  .toc-main img,
  .content img {
    max-width: 100%;
    height: auto;
    display: block;
  }

  pre, code {
    max-width: 100%;
    white-space: pre-wrap;
    word-break: break-all;
    overflow-x: auto;
  }

  details.code-collapsible pre {
    white-space: pre;
    word-break: normal;
    overflow-x: auto;
  }

  /* TOC: stacks above content, collapses */
  .toc-layout { grid-template-columns: 1fr; gap: 0; }

  .toc {
    position: static;
    max-height: none;
    margin-bottom: 1.25rem;
    padding: 0.75rem 1rem;
  }

  .toc-title {
    font-size: 0.8rem;
    margin-bottom: 0;
  }

  /* Page headings */
  .toc-main h1 { font-size: 1.3rem; margin: 1.25rem 0 0.6rem; }
  .toc-main h2 { font-size: 1.1rem; margin: 1.4rem 0 0.5rem; }

  /* Tables: horizontal scroll */
  .toc-main table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }

  /* Projects grid: 1 column */
  .projects-grid { grid-template-columns: 1fr; }

  /* Schema grid: 1 column */
  .schema-grid { grid-template-columns: 1fr; }

  /* Triple image grid: stack on mobile */
  .img-triple { grid-template-columns: 1fr; }

  /* Aside note: remove side margin on mobile */
  p.aside-note { margin: 1rem 0; }

  /* Findings grid: 1 column */
  .findings-grid { grid-template-columns: 1fr; }

  /* Dashboard embed: reduce aspect ratio so it's taller */
  .dashboard-embed { padding-top: 120%; }

  /* Code alongside: stack */
  .code-alongside { grid-template-columns: 1fr; }
}
