/* ==========================================================================
   CTF Writeups: theme on top of Bootstrap 5.3

   Layout, spacing and responsive behaviour come from Bootstrap classes in the
   HTML (container-xxl, row, row-cols-*, col-*, d-flex, gap-*, p-*, m-*).
   This file only holds the dark theme and the pieces Bootstrap does not have.
   Category colours come from data/categories.json.
   ========================================================================== */

:root {
  --bg: #0b0f14;
  --surface: #121821;
  --surface-2: #18202b;
  --toolbar: #1e2836;
  --toolbar-hover: #2c394b;
  --border: #283344;
  --border-strong: #3a4759;
  --text: #e6edf3;
  --muted: #9fb0c0;
  --accent: #3ddc97;
  --accent-ink: #06130d;
  --code-bg: #0e141c;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 8px;
  --footer-space: 4.5rem;
}

/* Bootstrap's own variables, pointed at the theme above. */
[data-bs-theme="dark"] {
  --bs-body-bg: var(--bg);
  --bs-body-bg-rgb: 11, 15, 20;
  --bs-body-color: var(--text);
  --bs-body-color-rgb: 230, 237, 243;
  --bs-body-font-family: var(--sans);
  --bs-body-line-height: 1.6;
  --bs-font-monospace: var(--mono);
  --bs-secondary-color: var(--muted);
  --bs-border-color: var(--border);
  --bs-link-color-rgb: 124, 196, 255;
  --bs-link-hover-color-rgb: 168, 216, 255;
  --bs-code-color: #ffd580;
}

html {
  font-size: 112.5%; /* 18px base. Change this one value to scale the whole site. */
  scroll-behavior: smooth;
}

body {
  padding-bottom: var(--footer-space); /* room for the fixed footer */
  -webkit-font-smoothing: antialiased;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Header ---------- */

.brand {
  display: inline-flex;
  align-items: baseline;
  gap: 10px;
  font-family: var(--mono);
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
}
.brand:hover { color: var(--text); }
.brand .prompt { color: var(--accent); }
.brand .cursor {
  display: inline-block;
  width: 0.55em;
  height: 1.05em;
  background: var(--accent);
  transform: translateY(0.18em);
  animation: blink 1.2s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.intro { max-width: 70ch; color: var(--muted); }
.intro-links { font-family: var(--mono); font-size: 0.9rem; }

/* ---------- Toolbar: search, filters, sort ---------- */

.toolbar {
  background: var(--toolbar);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}

.search { min-width: 0; }
.search svg { flex: none; color: var(--muted); }
.search:focus-within svg { color: var(--accent); }
.search input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: 0;
  color: var(--text);
  font-family: var(--mono);
  font-size: 1.05rem;
  padding: 16px 0;
}
.search input::placeholder { color: var(--muted); opacity: 1; }
.search input:focus { outline: none; }

.btn-tool {
  --bs-btn-color: var(--text);
  --bs-btn-hover-color: var(--text);
  --bs-btn-hover-bg: var(--toolbar-hover);
  --bs-btn-active-color: var(--text);
  --bs-btn-active-bg: var(--toolbar-hover);
  --bs-btn-border-color: transparent;
  --bs-btn-hover-border-color: transparent;
  --bs-btn-active-border-color: transparent;
  font-family: var(--mono);
  white-space: nowrap;
}
.btn-tool[aria-expanded="true"] { background: var(--toolbar-hover); }
.btn-tool .chev { transition: transform 0.15s; }
.btn-tool[aria-expanded="true"] .chev { transform: rotate(180deg); }
.btn-tool .count {
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0 7px;
  line-height: 1.5;
}

.dropdown-menu {
  --bs-dropdown-bg: #131a24;
  --bs-dropdown-border-color: var(--border-strong);
  --bs-dropdown-link-color: var(--text);
  --bs-dropdown-link-hover-color: var(--text);
  --bs-dropdown-link-hover-bg: var(--surface-2);
  --bs-dropdown-link-active-color: var(--accent);
  --bs-dropdown-link-active-bg: transparent;
  --bs-dropdown-item-padding-y: 0.45rem;
  --bs-dropdown-min-width: 13rem;
  font-family: var(--mono);
  font-size: 0.95rem;
}
.dropdown-item.active::before { content: "> "; }

/* ---------- Filter panel ---------- */

.filters-head {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--muted);
}
.filters-head .form-check-label { color: var(--text); cursor: pointer; }
.form-check-input:checked {
  background-color: var(--accent);
  border-color: var(--accent);
}
.form-check-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 0.2rem rgba(61, 220, 151, 0.25);
}

.btn-clear {
  --bs-btn-color: var(--text);
  --bs-btn-border-color: var(--border-strong);
  --bs-btn-hover-color: var(--accent);
  --bs-btn-hover-border-color: var(--accent);
  --bs-btn-active-color: var(--accent);
  --bs-btn-active-border-color: var(--accent);
  font-family: var(--mono);
}

.filter-scroll {
  max-height: 46vh;
  overflow-x: hidden;
  overflow-y: auto;
}
.filter-title {
  font-family: var(--mono);
  font-size: 0.9rem;
  font-weight: 500;
}
.filter-title span { color: var(--muted); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.4;
  padding: 3px 10px;
  white-space: nowrap;
}
a.chip:hover, button.chip:hover { border-color: var(--text); color: var(--text); }
button.chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.chip .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--c, var(--muted));
  flex: none;
}
button.chip[aria-pressed="true"] .dot { outline: 2px solid var(--accent-ink); }
.chip .n { color: var(--muted); }
button.chip[aria-pressed="true"] .n { color: inherit; }
.chip.more { border-style: dashed; color: var(--muted); font-style: italic; }

/* ---------- Writeup tiles ---------- */

.tile {
  --cat: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--cat);
  border-radius: var(--radius);
  color: var(--text);
  transition: transform 0.15s, border-color 0.15s, background 0.15s;
}
.tile:hover {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--cat);
  transform: translateY(-2px);
}
.tile-title {
  font-family: var(--mono);
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.35;
}
.tile:hover .tile-title { color: var(--cat); }
.tile-meta {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--muted);
}
.tile-meta .diff { color: var(--d, var(--text)); font-weight: 600; }
.tile-summary { font-size: 0.92rem; color: #c9d4de; }
.tile .chip { font-size: 0.72rem; padding: 2px 9px; color: #c9d4de; }

.cat-badge {
  flex: none;
  display: inline-block;
  background: var(--cat, var(--muted));
  color: #0b0f14;
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 10px;
  white-space: nowrap;
}
a.cat-badge:hover { color: #0b0f14; filter: brightness(1.1); }

.empty, .notice {
  text-align: center;
  padding: 64px 16px;
  color: var(--muted);
  font-family: var(--mono);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}

.reveal { opacity: 0; transform: translateY(10px); }
.reveal.in { opacity: 1; transform: none; transition: opacity 0.4s, transform 0.4s, border-color 0.15s, background 0.15s; }
.reveal.in:hover { transform: translateY(-2px); }

/* ---------- Footer and back-to-top ---------- */

.site-footer {
  background: var(--toolbar);
  box-shadow: 0 -6px 18px rgba(0, 0, 0, 0.35);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.78rem;
}

.to-top {
  --bs-btn-color: var(--accent-ink);
  --bs-btn-bg: var(--accent);
  --bs-btn-hover-color: var(--accent-ink);
  --bs-btn-hover-bg: #6beab3;
  --bs-btn-active-color: var(--accent-ink);
  --bs-btn-active-bg: #6beab3;
  --bs-btn-border-color: transparent;
  --bs-btn-hover-border-color: transparent;
  --bs-btn-padding-x: 1rem;
  position: fixed;
  right: 24px;
  bottom: calc(var(--footer-space) + 4px);
  z-index: 1030;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 700;
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s, visibility 0.2s;
}
.to-top.show { opacity: 1; visibility: visible; transform: none; }

/* ---------- Writeup page ---------- */

.back { font-family: var(--mono); font-size: 0.9rem; }

.w-head {
  --cat: var(--muted);
  padding-left: 20px;
  border-left: 4px solid var(--cat);
}
.w-head h1 {
  margin: 10px 0 8px;
  font-family: var(--mono);
  font-size: clamp(1.5rem, 3.4vw, 2.1rem);
  font-weight: 700;
  line-height: 1.25;
}
.w-meta {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--muted);
}
.w-meta b { color: var(--text); font-weight: 500; }

.toc {
  position: sticky;
  top: 24px;
  max-height: calc(100vh - 48px - var(--footer-space));
  overflow-y: auto;
  font-family: var(--mono);
  font-size: 0.82rem;
}
.toc h2 {
  margin: 0 0 10px;
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.toc ol { border-left: 1px solid var(--border); }
.toc a {
  display: block;
  padding: 4px 0 4px 14px;
  margin-left: -1px;
  border-left: 2px solid transparent;
  color: var(--muted);
  text-decoration: none;
}
.toc a:hover { color: var(--text); }
.toc a.active { color: var(--accent); border-left-color: var(--accent); }
.toc .lvl3 a { padding-left: 28px; font-size: 0.78rem; }

.w-nav a {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.9rem;
}
.w-nav a:hover { border-color: var(--accent); }
.w-nav small { color: var(--muted); }

/* ---------- Rendered markdown ---------- */

.md {
  max-width: 78ch;
  font-size: 1.02rem;
  line-height: 1.75;
  overflow-wrap: break-word;
}
.md > :first-child { margin-top: 0; }
.md h2 {
  margin: 2.2em 0 0.7em;
  font-family: var(--mono);
  font-size: 1.3rem;
  font-weight: 700;
  scroll-margin-top: 20px;
}
.md h2::before { content: "## "; color: var(--accent); }
.md h3 {
  margin: 1.8em 0 0.5em;
  font-family: var(--mono);
  font-size: 1.08rem;
  font-weight: 700;
  scroll-margin-top: 20px;
}
.md h4 { font-family: var(--mono); font-size: 1rem; font-weight: 700; }
.md p, .md ul, .md ol { margin: 0 0 1.1em; }
.md li { margin: 0.3em 0; }
.md li::marker { color: var(--accent); }
.md strong { color: #fff; }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 2em 0; opacity: 1; }

.md blockquote {
  margin: 0 0 1.2em;
  padding: 12px 18px;
  background: var(--surface);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: #d5dee7;
}
.md blockquote > :last-child { margin-bottom: 0; }

.md :not(pre) > code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.88em;
  padding: 0.1em 0.4em;
}

.code {
  margin: 0 0 1.3em;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.code-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 8px 5px 14px;
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: lowercase;
}
.copy {
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.72rem;
  padding: 2px 8px;
}
.copy:hover { color: var(--accent); border-color: var(--accent); }
.code pre {
  margin: 0;
  padding: 14px 16px;
  overflow-x: auto;
  font-size: 0.88rem;
  line-height: 1.6;
  tab-size: 4;
}
.code pre code { color: #dbe4ec; font-size: inherit; }

.table-wrap { overflow-x: auto; margin: 0 0 1.3em; }
.md table { width: 100%; font-size: 0.93rem; }
.md th, .md td {
  border: 1px solid var(--border);
  padding: 8px 14px;
  text-align: left;
  vertical-align: top;
}
.md th {
  background: var(--surface-2);
  font-family: var(--mono);
  font-weight: 500;
  font-size: 0.85rem;
}
.md tr:nth-child(even) td { background: var(--surface); }

.md img {
  max-width: 100%;
  height: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* Terminal sessions (code blocks with no language): see "Terminal colouring" in writeup.js */
.t-user { color: #3ddc97; font-weight: 600; }  /* user@host */
.t-path { color: #8fc7ff; }                    /* ~ or /some/path */
.t-sym { color: #8496a8; }                     /* : $ # */
.t-cmd { color: #7fe3e0; font-weight: 600; }   /* ssh, ls, cat */
.t-flag { color: #ffc27a; }                    /* -p, --help */
.t-str { color: #a5e6a0; }                     /* "quoted text" */
.t-arg { color: #e6edf3; }                     /* other arguments */
.t-op { color: #ff9eb8; }                      /* | && > */
.t-label { color: #ffd580; }                   /* Password: */
.t-out { color: #b4c2cf; }                     /* command output */
.t-ph { color: #e0b8ff; font-style: italic; }  /* {placeholder} */
.t-error { color: #ff9a9a; }                   /* ```error blocks */
.t-comment { color: #8496a8; font-style: italic; } /* # comment */
.t-var { color: #ffb86b; }                     /* $VARIABLE */

/* highlight.js tokens */
.hljs-comment, .hljs-quote { color: #8496a8; font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-literal, .hljs-section, .hljs-doctag { color: #ff9eb8; }
.hljs-string, .hljs-regexp, .hljs-addition { color: #a5e6a0; }
.hljs-number, .hljs-symbol, .hljs-bullet, .hljs-meta { color: #ffc27a; }
.hljs-title, .hljs-name, .hljs-function .hljs-title { color: #8fc7ff; }
.hljs-built_in, .hljs-type, .hljs-class .hljs-title, .hljs-attr, .hljs-attribute { color: #7fe3e0; }
.hljs-variable, .hljs-template-variable { color: #e0b8ff; }
.hljs-deletion { color: #ff9a9a; }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 700; }

/* ---------- Small screens and motion ---------- */

@media (max-width: 575.98px) {
  :root { --footer-space: 6rem; }
  .to-top { right: 12px; }
  .search input { font-size: 1rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .reveal { opacity: 1; transform: none; }
  .brand .cursor { animation: none; }
  .tile, .reveal.in, .to-top { transition: none; }
}
