:root {
  --sf-muted:    #6b6b6b;
  --sf-border:   #d9d7cc;
  --sf-surface:  #f6f5ef;
  --sf-accent:   #7a1f2b;
  --sf-pill-bg:  #ecebe1;
  --sf-pill-fg:  #3a3a3a;
  --sf-mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo, Consolas, monospace;
}

html.latex-dark {
  --sf-muted:    #9aa0a6;
  --sf-border:   #3b4048;
  --sf-surface:  #24272c;
  --sf-accent:   #e58a95;
  --sf-pill-bg:  #2b3037;
  --sf-pill-fg:  #d3d8de;
}

/* ---- header / nav -------------------------------------------------------- */
.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.6rem 1rem;
  padding-bottom: 0.8rem;
  margin-bottom: 1.6rem;
  border-bottom: 1px solid var(--sf-border);
}
.site-title {
  font-weight: 700;
  font-size: 1.15rem;
  text-decoration: none;
  font-family: var(--sf-mono);
  letter-spacing: -0.01em;
}
.site-nav { display: flex; flex-wrap: wrap; align-items: center; gap: 0.15rem 1rem; }
.site-nav a { font-size: 0.95rem; text-decoration: none; }
.site-nav a:hover { text-decoration: underline; }

/* ---- theme toggle (after the About link) --------------------------------- */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  color: inherit;
  background: transparent;
  border: 1px solid var(--sf-border);
  border-radius: 6px;
  cursor: pointer;
  line-height: 0;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.theme-toggle:hover { color: var(--sf-accent); border-color: var(--sf-accent); }
.theme-toggle:focus-visible { outline: 2px solid var(--sf-accent); outline-offset: 2px; }
.theme-toggle svg { display: block; }
.theme-toggle .icon-sun { display: none; }
html.latex-dark .theme-toggle .icon-moon { display: none; }
html.latex-dark .theme-toggle .icon-sun { display: block; }

/* ---- breadcrumbs --------------------------------------------------------- */
.breadcrumbs {
  font-family: var(--sf-mono);
  font-size: 0.8rem;
  color: var(--sf-muted);
  margin-bottom: 1rem;
}
.breadcrumbs .sep { opacity: 0.5; }
.breadcrumbs span[aria-current] { color: inherit; }

/* ---- meta line + tags ---------------------------------------------------- */
.meta { color: var(--sf-muted); font-size: 0.85rem; margin: 0.2rem 0 0.3rem; }
.byline time { margin-right: 0.6rem; }
.taglist { display: inline-flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.2em }
.tag {
  font-family: var(--sf-mono);
  font-size: 0.78rem;
  text-decoration: none;
  color: var(--sf-pill-fg);
  background: var(--sf-pill-bg);
  padding: 0.05rem 0.4rem;
  border-radius: 3px;
}
.tag:hover { color: var(--sf-accent); }
.tag-lg { font-size: 0.95rem; padding: 0.2rem 0.55rem; }
.tag-cloud { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.count { color: var(--sf-muted); font-size: 0.75em; }

/* ---- pills (writeup metadata) ------------------------------------------- */
.pill {
  display: inline-block;
  font-family: var(--sf-mono);
  font-size: 0.72rem;
  padding: 0.05rem 0.4rem;
  margin-left: 0.35rem;
  margin-right: 0.35rem;
  border: 1px solid var(--sf-border);
  border-radius: 3px;
  color: var(--sf-muted);
}
.pill-cat { color: var(--sf-accent); border-color: var(--sf-accent); }

/* ---- listing cards ------------------------------------------------------- */
.card-list { display: flex; flex-direction: column; gap: 1.2rem; margin: 1rem 0; }
.card { border-left: 2px solid var(--sf-border); padding-left: 1rem; }
.card-title { margin: 0 0 0.15rem; font-size: 1.1rem; }
.card-title a { text-decoration: none; }
.card-title a:hover { text-decoration: underline; }
.card-summary { margin: 0.3rem 0; color: var(--sf-muted); font-size: 0.92rem; }

/* ---- writeup infobox (the signature element) ----------------------------- */
.infobox {
  border: 1px solid var(--sf-border);
  border-left: 3px solid var(--sf-accent);
  background: var(--sf-surface);
  padding: 0.6rem 1rem;
  margin: 1.2rem 0;
  border-radius: 4px;
  font-size: 0.9rem;
}
.infobox dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.25rem 1rem;
  margin: 0;
}
.infobox dt {
  font-family: var(--sf-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--sf-muted);
  align-self: center;
}
.infobox dd { margin: 0; }
.infobox code { background: none; padding: 0; }

/* ---- collapsible TOC ----------------------------------------------------- */
.toc-box {
  border: 1px solid var(--sf-border);
  border-radius: 4px;
  padding: 0.4rem 0.9rem;
  margin: 1.2rem 0;
  background: var(--sf-surface);
}
.toc-box summary {
  cursor: pointer;
  font-family: var(--sf-mono);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--sf-muted);
}
.toc-box .toc { margin-top: 0.4rem; }
.toc-box ul { margin: 0.2rem 0; }
.toc-box a { text-decoration: none; }
.toc-box a:hover { text-decoration: underline; }

/* ---- CTF grouping -------------------------------------------------------- */
.ctf-group { margin-bottom: 1.6rem; }
.ctf-group h2 a { text-decoration: none; }
.ctf-group h2 a:hover { text-decoration: underline; }

.challenge-list {
  list-style: none;
  padding-left: 0;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  column-gap: 2rem;
}
.challenge-list li { padding: 0.15rem 0; border-bottom: 1px dotted var(--sf-border); }
.challenge-list a  { text-decoration: none; }
.challenge-list a:hover  { text-decoration: underline; }

@media (max-width: 640px) {
  html { font-size: 1rem; }
  body { padding: 1.5rem 1rem; }
  table { font-size: 0.85rem; }
  th, td { padding: 0.35rem 0.4rem; line-height: 1.3; }

  h1 {
      font-size: 1.85rem;
      line-height: 2.35rem;
      margin-bottom: 1rem;
  }
  h2 {
      font-size: 1.4rem;
      line-height: 1.75rem;
      margin-top: 2rem;
  }
  h3 { font-size: 1.2rem; margin-top: 1.6rem; }
  h4 { font-size: 1.1rem; margin-top: 1.4rem; }
  h5 { font-size: 1rem; margin-top: 1.3rem; }
  h6 { font-size: 1rem; margin-top: 1.6rem; }

  h3, h4, h5, h6 { line-height: 1.4rem; }
  h1 + h2 { margin-top: 1rem; }
  h2 + h3, h3 + h4, h4 + h5 { margin-top: 0.6rem; }
  h5 + h6 { margin-top: -0.6rem; }
  h2, h3, h4, h5, h6 { margin-bottom: 0.6rem; }

  .site-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }
  .site-nav {
    width: 100%;
    gap: 0.3rem 0.8rem;
  }
  .site-nav a { font-size: 0.88rem; }

  .infobox dl {
    grid-template-columns: 1fr;
    gap: 0.1rem 0;
  }
  .infobox dt:not(:first-child) { margin-top: 0.4rem; }

  .highlight, .highlight pre { font-size: 0.85rem; }
  .highlight pre { padding: 0.6rem 0.8rem; }

  .challenge-list { grid-template-columns: 1fr; }
}

/* ---- syscall-table variant: dense reference-table look --------------------- */
.syscall-table table {
  font-size: 0.9rem;
}
.syscall-table th {
  padding: 0.35rem 0.6rem;
  border-left: 1px solid var(--sf-border);
  border-right: 1px solid var(--sf-border);
}
.syscall-table td {
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--sf-border);
}
/* ---- code blocks --------------------------------------------------------- */
.highlight {
  overflow-x: auto;
  margin: 1rem 0;
  border: 1px solid var(--sf-border);
  border-radius: 6px;
}
.highlight pre { margin: 0; padding: 0.8rem 1rem; background: none; border: none; }

.code-block {
  margin: 1rem 0;
  border: 1px solid var(--sf-border);
  border-radius: 6px;
  overflow: hidden;
}
.code-block .highlight { margin: 0; border: 0; border-radius: 0; }

.code-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.6rem;
  background: var(--sf-surface);
  border-bottom: 1px solid var(--sf-border);
}
.code-lang {
  margin-right: auto;
  font-family: var(--sf-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--sf-muted);
}
.copy-btn {
  margin-left: auto;
  font-family: var(--sf-mono);
  font-size: 0.72rem;
  color: var(--sf-muted);
  background: transparent;
  border: 1px solid var(--sf-border);
  border-radius: 4px;
  padding: 0.1rem 0.5rem;
  cursor: pointer;
  line-height: 1.4;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.copy-btn:hover { color: var(--sf-accent); border-color: var(--sf-accent); }
.copy-btn:focus-visible { outline: 2px solid var(--sf-accent); outline-offset: 1px; }

/* ---- LaTeX math (KaTeX) -------------------------------------------------- */
.katex { font-size: 1.05em; }
.katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.3rem 0;
  margin: 1rem 0;
}

/* ---- misc ---------------------------------------------------------------- */
.muted { color: var(--sf-muted); }
.site-footer { margin-top: 3rem; color: var(--sf-muted); font-size: 0.85rem; }
.home-section { margin-top: 2rem; }

.search-input {
  width: 100%;
  font-family: var(--sf-mono);
  font-size: 1rem;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--sf-border);
  border-radius: 4px;
  background: var(--sf-surface);
  color: inherit;
  box-sizing: border-box;
}
mark { background: color-mix(in srgb, var(--sf-accent) 25%, transparent); color: inherit; }
