/* ============================================================
   404CTF writeups - App styles
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-serif);
  font-size: var(--fs-base);
  line-height: var(--lh-base);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background .35s ease, color .35s ease;
}
::selection { background: var(--selection); }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

.mono { font-family: var(--font-mono); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* subtle dotted grid behind everything */
body::before {
  content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image: radial-gradient(var(--hairline) 1px, transparent 1px);
  background-size: 26px 26px;
  opacity: .6; mask-image: linear-gradient(180deg, #000, #000);
}
[data-ambiance="terminal"] body::before { opacity: .9; }

/* ============================================================
   App shell - grid: sidebar | main
   ============================================================ */
.app {
  position: relative; z-index: 1;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
  position: sticky; top: 0; align-self: start;
  height: 100vh;
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 70%, var(--bg));
  backdrop-filter: blur(6px);
}
.sidebar-head { padding: 22px 20px 14px; }
.brand { display: flex; align-items: center; gap: 11px; cursor: pointer; }
.brand-mark {
  width: 38px; height: 38px; flex: none; border-radius: var(--r-md);
  display: grid; place-items: center;
  font-family: var(--font-mono); font-weight: 700; font-size: 13px; letter-spacing: -.04em;
  color: var(--on-accent);
  background: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-28), 0 6px 18px var(--accent-28);
  position: relative; overflow: hidden;
}
.brand-mark::after {
  content: "_"; position: absolute; right: 6px; bottom: 3px; font-size: 12px;
  animation: blink 1.1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.brand-name { font-family: var(--font-mono); font-weight: 700; font-size: 15px; letter-spacing: -.02em; line-height: 1.05; }
.brand-sub { font-family: var(--font-mono); font-size: 10.5px; color: var(--muted); letter-spacing: .14em; text-transform: uppercase; margin-top: 2px; }

/* search */
.search {
  margin: 4px 16px 6px; padding: 0 12px;
  display: flex; align-items: center; gap: 9px;
  height: 40px; border-radius: var(--r-md);
  background: var(--surface-2);
  border: 1px solid var(--border);
  transition: border-color .18s, box-shadow .18s, background .18s;
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-18); background: var(--surface); }
.search svg { width: 16px; height: 16px; color: var(--faint); flex: none; }
.search input {
  border: 0; background: none; outline: none; width: 100%;
  font-family: var(--font-mono); font-size: 13px; color: var(--ink);
}
.search input::placeholder { color: var(--faint); }
.search kbd {
  font-family: var(--font-mono); font-size: 10px; color: var(--muted);
  border: 1px solid var(--border-strong); border-bottom-width: 2px;
  border-radius: 5px; padding: 1px 5px; background: var(--surface);
}

/* nav */
.nav { flex: 1; overflow-y: auto; padding: 10px 12px 18px; scrollbar-width: thin; }
.nav-label {
  font-family: var(--font-mono); font-size: 10px; letter-spacing: .16em;
  text-transform: uppercase; color: var(--faint); padding: 14px 10px 7px;
}
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 8px 10px; border-radius: var(--r-md);
  cursor: pointer; color: var(--ink-2);
  font-family: var(--font-mono); font-size: 13px; font-weight: 500;
  position: relative; transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item .nav-ico {
  width: 26px; height: 26px; flex: none; border-radius: 7px;
  display: grid; place-items: center; font-size: 12px; font-weight: 700;
  background: var(--cat-tint, var(--surface-2)); color: var(--cat-color, var(--muted));
  border: 1px solid color-mix(in srgb, var(--cat-color, var(--border)) 28%, transparent);
  transition: transform .15s;
}
.nav-item:hover .nav-ico { transform: translateY(-1px); }
.nav-item .nav-count {
  margin-left: auto; font-size: 11px; color: var(--faint);
  background: var(--surface-2); border-radius: 999px; padding: 1px 8px; min-width: 24px; text-align: center;
}
.nav-item.active { background: var(--accent-12); color: var(--ink); }
.nav-item.active::before {
  content: ""; position: absolute; left: -12px; top: 6px; bottom: 6px; width: 3px;
  background: var(--accent); border-radius: 0 3px 3px 0;
}
.nav-item.active .nav-count { background: var(--accent-18); color: var(--accent-ink); }

/* sidebar footer */
.sidebar-foot {
  border-top: 1px solid var(--border); padding: 12px 16px;
  display: flex; align-items: center; gap: 8px;
}
.icon-btn {
  width: 36px; height: 36px; border-radius: var(--r-md); flex: none;
  display: grid; place-items: center; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--ink-2);
  transition: background .15s, color .15s, border-color .15s, transform .15s;
}
.icon-btn:hover { background: var(--surface); color: var(--ink); transform: translateY(-1px); }
.icon-btn svg { width: 17px; height: 17px; }
.foot-meta { margin-left: auto; font-family: var(--font-mono); font-size: 10.5px; color: var(--faint); text-align: right; line-height: 1.3; }

/* ============================================================
   Main column
   ============================================================ */
.main { min-width: 0; }
.main-inner { max-width: var(--content-max); margin: 0 auto; }

/* topbar (mobile menu) */
.topbar { display: none; }

/* ============================================================
   HOME
   ============================================================ */
.home { padding: 40px clamp(20px, 4vw, 56px) 80px; }

.hero { display: grid; grid-template-columns: 1.05fr 1fr; gap: 40px; align-items: center; margin-bottom: 46px; }
.hero-eyebrow {
  font-family: var(--font-mono); font-size: 12px; letter-spacing: .18em; text-transform: uppercase;
  color: var(--accent-ink); display: inline-flex; align-items: center; gap: 8px; margin-bottom: 14px;
}
.hero-eyebrow::before { content: "- - - -"; background: none; width: auto; height: auto; }
.hero-title { font-family: var(--font-display); font-weight: 700; font-size: clamp(34px, 4.6vw, 52px); line-height: 1.04; letter-spacing: -.02em; margin: 0 0 16px; text-wrap: balance; }
.hero-title em { font-style: italic; color: var(--accent-ink); }
.hero-lead { font-size: 18px; color: var(--ink-2); max-width: 46ch; margin: 0 0 22px; text-wrap: pretty; }
.hero-stats { display: flex; gap: 26px; }
.hstat { display: flex; flex-direction: column; }
.hstat b { font-family: var(--font-mono); font-size: 24px; font-weight: 700; color: var(--ink); letter-spacing: -.02em; }
.hstat span { font-family: var(--font-mono); font-size: 11px; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; }

/* ---- Mini terminal ---- */
.terminal {
  border-radius: var(--r-lg); overflow: hidden; background: var(--term-bg);
  border: 1px solid var(--term-border);
  box-shadow: var(--shadow-lg);
  font-family: var(--font-mono);
}
.term-bar {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px;
  background: color-mix(in srgb, #ffffff 5%, var(--term-bg));
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.term-dot { width: 11px; height: 11px; border-radius: 50%; }
.term-dot.r { background: #ff5f57; } .term-dot.y { background: #febc2e; } .term-dot.g { background: #28c840; }
.term-title { margin-left: 8px; font-size: 11.5px; color: #8a93a0; letter-spacing: .02em; }
.term-title b { color: var(--accent); font-weight: 500; }
.term-body {
  padding: 16px 16px 14px; height: 268px; overflow-y: auto; cursor: text;
  font-size: 13px; line-height: 1.62; color: var(--term-ink);
  scrollbar-width: thin; scrollbar-color: #2a333c transparent;
}
.term-body::-webkit-scrollbar { width: 8px; }
.term-body::-webkit-scrollbar-thumb { background: #2a333c; border-radius: 4px; }
.term-line { white-space: pre-wrap; word-break: break-word; }
.term-prompt { color: var(--accent); }
.term-path { color: #6cb6ff; }
.term-muted { color: #7a8694; }
.term-ok { color: #4ee59a; }
.term-warn { color: #ffce80; }
.term-flag { color: #ff7bd4; }
.term-input-line { display: flex; align-items: baseline; gap: 8px; }
.term-input-line .ti-prompt { color: var(--accent); flex: none; }
.term-input {
  flex: 1; border: 0; background: none; outline: none; color: var(--term-ink);
  font-family: var(--font-mono); font-size: 13px; line-height: 1.62; caret-color: var(--accent);
}
.term-cursor { display: inline-block; width: 8px; height: 15px; background: var(--accent); margin-left: 1px; transform: translateY(2px); animation: blink 1.1s steps(1) infinite; }

/* ---- Filter row + section heads ---- */
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin: 8px 0 18px; }
.section-title { font-family: var(--font-display); font-size: 24px; font-weight: 700; letter-spacing: -.01em; margin: 0; }
.section-title small { font-family: var(--font-mono); font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 10px; }
.chips-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 24px; }
.fchip {
  font-family: var(--font-mono); font-size: 12px; font-weight: 500;
  padding: 6px 13px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--ink-2);
  transition: all .15s;
}
.fchip:hover { border-color: var(--border-strong); color: var(--ink); }
.fchip.active { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

/* ---- Writeup cards ---- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 18px; }
.card {
  display: flex; flex-direction: column; gap: 13px;
  padding: 20px 20px 18px; border-radius: var(--r-lg);
  background: var(--surface); border: 1px solid var(--border);
  cursor: pointer; position: relative; overflow: hidden;
  transition: transform .2s cubic-bezier(.3,.7,.4,1), box-shadow .2s, border-color .2s;
}
.card::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--cat-color, var(--accent)); opacity: 0; transition: opacity .2s;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); border-color: var(--border-strong); }
.card:hover::before { opacity: 1; }
.card-top { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.card-title { font-family: var(--font-display); font-size: 20px; font-weight: 700; line-height: 1.2; letter-spacing: -.01em; margin: 0; text-wrap: balance; }
.card-excerpt { color: var(--muted); font-size: 15px; line-height: 1.6; margin: 0; flex: 1; }
.card-foot { display: flex; align-items: center; gap: 12px; margin-top: 2px; padding-top: 13px; border-top: 1px solid var(--hairline); }
.card-foot .cf-meta { font-family: var(--font-mono); font-size: 11.5px; color: var(--faint); display: inline-flex; align-items: center; gap: 5px; }
.card-foot .cf-meta svg { width: 13px; height: 13px; }
.card-tags { display: flex; gap: 6px; margin-left: auto; }
.tag { font-family: var(--font-mono); font-size: 11px; color: var(--muted); }
.tag::before { content: "#"; color: var(--faint); }

/* category chip */
.cat-chip {
  font-family: var(--font-mono); font-size: 11px; font-weight: 600; letter-spacing: .03em;
  padding: 3px 9px; border-radius: 999px;
  color: var(--cat-color); background: var(--cat-tint);
  border: 1px solid color-mix(in srgb, var(--cat-color) 26%, transparent);
  display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
}
.cat-chip .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--cat-color); }

/* difficulty badge */
.diff {
  font-family: var(--font-mono); font-size: 11px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px; color: var(--muted);
}
.diff .bars { display: inline-flex; gap: 2px; align-items: flex-end; height: 12px; }
.diff .bars i { width: 3px; border-radius: 1px; background: var(--border-strong); }
.diff .bars i:nth-child(1){height:5px} .diff .bars i:nth-child(2){height:8px} .diff .bars i:nth-child(3){height:11px}
.diff[data-lvl="1"] .bars i:nth-child(-n+1),
.diff[data-lvl="2"] .bars i:nth-child(-n+2),
.diff[data-lvl="3"] .bars i:nth-child(-n+3) { background: var(--diff-color); }
.diff[data-lvl="1"]{--diff-color:#22a06b} .diff[data-lvl="2"]{--diff-color:#d98324} .diff[data-lvl="3"]{--diff-color:#dc3f4f}
.points { font-family: var(--font-mono); font-size: 11.5px; font-weight: 600; color: var(--accent-ink); }
.points::after { content: " pts"; color: var(--faint); font-weight: 400; }

.empty { text-align: center; padding: 80px 20px; color: var(--muted); font-family: var(--font-mono); }
.empty b { display: block; color: var(--ink); font-size: 16px; margin-bottom: 6px; }

/* ============================================================
   WRITEUP / ARTICLE
   ============================================================ */
.article-wrap {
  display: grid; grid-template-columns: minmax(0, 1fr) var(--toc-w);
  gap: clamp(28px, 4vw, 64px);
  padding: 32px clamp(20px, 4vw, 56px) 100px;
  max-width: 1180px; margin: 0 auto;
}
.breadcrumb { display: flex; align-items: center; gap: 8px; font-family: var(--font-mono); font-size: 12.5px; color: var(--muted); margin-bottom: 22px; }
.breadcrumb a { cursor: pointer; }
.breadcrumb a:hover { color: var(--accent-ink); }
.breadcrumb .sep { color: var(--faint); }
.breadcrumb .cur { color: var(--ink-2); }

.article-head { margin-bottom: 26px; }
.ah-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 16px; }
.article-title { font-family: var(--font-display); font-weight: 700; font-size: clamp(30px, 4vw, 44px); line-height: 1.06; letter-spacing: -.022em; margin: 0 0 14px; text-wrap: balance; }
.article-sub { font-size: 19px; color: var(--ink-2); margin: 0 0 20px; max-width: var(--measure); text-wrap: pretty; }
.byline { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding-bottom: 22px; border-bottom: 1px solid var(--border); }
.author { display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-family: var(--font-mono); font-weight: 700; font-size: 12px; color: var(--on-accent); background: var(--accent); }
.author b { font-size: 14px; font-weight: 600; }
.author span { font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); display: block; }
.byline .dot-sep { width: 4px; height: 4px; border-radius: 50%; background: var(--faint); }
.byline .bmeta { font-family: var(--font-mono); font-size: 12.5px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.byline .bmeta svg { width: 14px; height: 14px; }

/* ---- Prose ---- */
.prose { font-size: var(--fs-base); color: var(--ink); }
.prose > * { max-width: var(--measure); }
.prose .full { max-width: 100%; }
.prose p { margin: 0 0 20px; text-wrap: pretty; }
.prose p code, .prose li code, .prose td code {
  font-family: var(--font-mono); font-size: .86em; padding: .12em .4em; border-radius: 5px;
  background: var(--accent-12); color: var(--accent-ink);
  border: 1px solid var(--accent-18);
}
.prose a.link { color: var(--accent-ink); border-bottom: 1px solid var(--accent-28); }
.prose a.link:hover { border-bottom-color: var(--accent); }
.prose strong { font-weight: 700; }
.prose em { font-style: italic; }

.prose h2, .prose h3, .prose h4 { scroll-margin-top: 24px; position: relative; font-family: var(--font-display); letter-spacing: -.018em; line-height: 1.18; }
.prose h2 { font-size: 28px; font-weight: 700; margin: 48px 0 16px; padding-top: 14px; }
.prose h2 .num { font-family: var(--font-mono); font-size: 15px; color: var(--accent-ink); font-weight: 600; margin-right: 12px; }
.prose h3 { font-size: 21px; font-weight: 700; margin: 34px 0 12px; }
.prose h4 { font-size: 17px; font-weight: 700; margin: 26px 0 10px; color: var(--ink-2); }
.anchor {
  position: absolute; left: -26px; top: 50%; transform: translateY(-50%);
  opacity: 0; color: var(--faint); cursor: pointer; transition: opacity .15s, color .15s;
  font-family: var(--font-mono); text-decoration: none;
}
.prose h2:hover .anchor, .prose h3:hover .anchor, .prose h4:hover .anchor { opacity: 1; }
.anchor:hover { color: var(--accent); }

.prose ul, .prose ol { margin: 0 0 20px; padding-left: 22px; }
.prose li { margin: 0 0 9px; }
.prose ul li::marker { color: var(--accent); }
.prose ol li::marker { font-family: var(--font-mono); color: var(--muted); font-size: .9em; }

.prose hr { border: 0; border-top: 1px solid var(--border); margin: 40px 0; }
.prose blockquote {
  margin: 24px 0; padding: 4px 20px; border-left: 3px solid var(--accent);
  color: var(--ink-2); font-style: italic;
}
.prose .lead { font-size: 20px; color: var(--ink-2); }

/* math display block tweak */
.prose mjx-container[display="true"] { margin: 22px 0; overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
.eq {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 6px 18px; margin: 22px 0; overflow-x: auto;
}
.eq-num { display: flex; align-items: center; gap: 14px; }
.eq-num .tag-eq { margin-left: auto; font-family: var(--font-mono); font-size: 12px; color: var(--faint); }

/* figure placeholder */
.figure { margin: 26px 0; }
.fig-ph {
  border: 1px dashed var(--border-strong); border-radius: var(--r-md);
  background: repeating-linear-gradient(45deg, var(--surface-2), var(--surface-2) 12px, transparent 12px, transparent 24px);
  min-height: 200px; display: grid; place-items: center; color: var(--muted);
  font-family: var(--font-mono); font-size: 12.5px; text-align: center; padding: 24px;
}
.fig-cap { font-family: var(--font-mono); font-size: 12px; color: var(--muted); margin-top: 9px; text-align: center; }
.fig-cap b { color: var(--accent-ink); }

/* ---- Callouts ---- */
.callout {
  margin: 24px 0; border-radius: var(--r-md); border: 1px solid var(--co-bd, var(--border));
  background: var(--co-bg, var(--surface)); overflow: hidden;
}
.callout-head {
  display: flex; align-items: center; gap: 11px; padding: 13px 16px;
  font-family: var(--font-mono); font-size: 13px; font-weight: 600; color: var(--co-ink, var(--ink));
  cursor: default;
}
.callout.foldable .callout-head { cursor: pointer; user-select: none; }
.callout-ico { width: 22px; height: 22px; flex: none; display: grid; place-items: center; color: var(--co-ink); }
.callout-ico svg { width: 18px; height: 18px; }
.callout-head .ch-title { flex: 1; }
.callout-head .chevron { transition: transform .2s; color: var(--co-ink); opacity: .7; }
.callout.open .callout-head .chevron { transform: rotate(90deg); }
.callout-body { padding: 0 16px; max-height: 0; overflow: hidden; transition: max-height .3s ease, padding .3s ease; }
.callout.open .callout-body { padding: 2px 16px 14px; max-height: 1400px; }
.callout:not(.foldable) .callout-body { max-height: none; padding: 2px 16px 14px; }
.callout-body > *:first-child { margin-top: 4px; }
.callout-body > *:last-child { margin-bottom: 0; }
.callout-body p { font-size: 15.5px; }

.callout.info    { --co-bg: var(--accent-soft); --co-bd: var(--accent-28); --co-ink: var(--accent-ink); }
.callout.deep    { --co-bg: color-mix(in srgb, #7c6cf0 9%, var(--surface)); --co-bd: color-mix(in srgb, #7c6cf0 32%, transparent); --co-ink: #6a5af0; }
[data-theme="dark"] .callout.deep { --co-ink: #a99bff; }
.callout.warn    { --co-bg: color-mix(in srgb, #e0a40a 11%, var(--surface)); --co-bd: color-mix(in srgb, #e0a40a 34%, transparent); --co-ink: #b07d05; }
[data-theme="dark"] .callout.warn { --co-ink: #ffce80; }
.callout.tip     { --co-bg: color-mix(in srgb, #0db89a 10%, var(--surface)); --co-bd: color-mix(in srgb, #0db89a 32%, transparent); --co-ink: #0a8c75; }
[data-theme="dark"] .callout.tip { --co-ink: #4fd6c8; }

/* spoiler / flag */
.callout.spoiler { --co-bg: var(--surface); --co-bd: var(--border-strong); --co-ink: var(--ink); border-style: dashed; }
.spoiler-flag {
  font-family: var(--font-mono); font-size: 15px; font-weight: 600;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 12px 14px; border-radius: var(--r-sm);
  background: var(--code-bg); border: 1px solid var(--code-border); color: var(--accent-ink);
  transition: filter .25s;
}
.callout.spoiler:not(.revealed) .spoiler-flag { filter: blur(7px); user-select: none; }
.spoiler-flag .copy-flag {
  margin-left: auto; font-family: var(--font-mono); font-size: 11.5px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  border-radius: var(--r-sm); padding: 4px 9px; transition: all .15s;
}
.spoiler-flag .copy-flag:hover { color: var(--ink); border-color: var(--border-strong); }
.reveal-hint { font-family: var(--font-mono); font-size: 12px; color: var(--muted); }

/* ============================================================
   CODE BLOCKS
   ============================================================ */
.codeblock { margin: 24px 0; border-radius: var(--r-md); overflow: hidden; border: 1px solid var(--code-border); background: var(--code-bg); }
.codeblock.term { background: var(--term-bg); border-color: var(--term-border); }
.cb-tabs {
  display: flex; align-items: center; gap: 2px; padding: 7px 8px 0 10px;
  background: color-mix(in srgb, var(--ink) 3%, var(--code-bg));
  border-bottom: 1px solid var(--code-border); position: relative;
}
.codeblock.term .cb-tabs { background: color-mix(in srgb, #fff 4%, var(--term-bg)); border-color: rgba(255,255,255,.06); }
.cb-tab {
  font-family: var(--font-mono); font-size: 12.5px; color: var(--muted);
  padding: 8px 13px; border-radius: 7px 7px 0 0; cursor: pointer; position: relative; top: 1px;
  border: 1px solid transparent; border-bottom: none; display: inline-flex; align-items: center; gap: 7px;
  transition: color .15s, background .15s;
}
.cb-tab .ft { color: var(--faint); }
.cb-tab:hover { color: var(--ink); }
.codeblock.term .cb-tab:hover { color: var(--term-ink); }
.cb-tab.active { color: var(--ink); background: var(--code-bg); border-color: var(--code-border); }
.codeblock.term .cb-tab.active { color: var(--term-ink); background: var(--term-bg); border-color: rgba(255,255,255,.08); }
.cb-lang { margin-left: auto; font-family: var(--font-mono); font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--faint); padding-right: 6px; align-self: center; }
.cb-copy {
  font-family: var(--font-mono); font-size: 11.5px; cursor: pointer; align-self: center;
  display: inline-flex; align-items: center; gap: 6px; margin: 0 2px 4px 0;
  padding: 5px 10px; border-radius: var(--r-sm);
  border: 1px solid var(--code-border); background: var(--code-bg); color: var(--muted);
  transition: all .15s;
}
.codeblock.term .cb-copy { background: rgba(255,255,255,.04); border-color: rgba(255,255,255,.1); color: #9aa6b2; }
.cb-copy:hover { color: var(--ink); border-color: var(--border-strong); }
.codeblock.term .cb-copy:hover { color: var(--term-ink); }
.cb-copy.ok { color: var(--accent-ink); border-color: var(--accent-28); }
.cb-copy svg { width: 13px; height: 13px; }

.cb-panel { display: none; }
.cb-panel.active { display: block; }
.cb-scroll { overflow-x: auto; scrollbar-width: thin; }
pre.code { margin: 0; padding: 14px 0; font-family: var(--font-mono); font-size: 13px; line-height: 1.62; tab-size: 4; }
pre.code code { display: block; }
.cl { display: grid; grid-template-columns: auto 1fr; }
.cl-row { display: contents; }
.ln {
  -webkit-user-select: none; user-select: none; text-align: right;
  padding: 0 16px 0 16px; color: var(--code-gutter); min-width: 42px;
  font-variant-numeric: tabular-nums;
}
.codeblock.term .ln { color: #3f4a54; }
.lc { padding-right: 18px; white-space: pre; color: var(--code-ink); }
.codeblock.term .lc { color: var(--term-ink); }
.cl-row.hl .lc { background: var(--accent-12); box-shadow: inset 3px 0 0 var(--accent); }
.cl-row.hl .ln { background: var(--accent-12); }

/* terminal prompt lines inside code */
.codeblock.term .lc .pr { color: var(--accent); } /* $ prompt */
.codeblock.term .lc .cmt { color: #7a8694; }

/* highlight.js token colors → our vars */
.hljs-comment, .hljs-quote { color: var(--hl-comment); font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-literal, .hljs-section, .hljs-doctag, .hljs-type, .hljs-name, .hljs-strong { color: var(--hl-keyword); }
.hljs-string, .hljs-regexp, .hljs-addition, .hljs-meta-string { color: var(--hl-string); }
.hljs-number, .hljs-symbol, .hljs-bullet { color: var(--hl-number); }
.hljs-title, .hljs-title.function_, .hljs-function .hljs-title { color: var(--hl-func); }
.hljs-built_in, .hljs-class .hljs-title, .hljs-title.class_ { color: var(--hl-builtin); }
.hljs-attr, .hljs-attribute, .hljs-variable, .hljs-template-variable, .hljs-selector-attr, .hljs-property { color: var(--hl-attr); }
.hljs-params { color: var(--code-ink); }
.codeblock.term .hljs-params { color: var(--term-ink); }
.hljs-meta, .hljs-meta .hljs-keyword { color: var(--hl-meta); }
.hljs-punctuation, .hljs-operator { color: var(--hl-punct); }
.hljs-deletion { color: var(--hl-number); }
.hljs-emphasis { font-style: italic; }

/* ============================================================
   TOC (right rail)
   ============================================================ */
.toc { position: sticky; top: 28px; align-self: start; max-height: calc(100vh - 56px); overflow-y: auto; scrollbar-width: thin; padding-right: 4px; }
.toc-title { font-family: var(--font-mono); font-size: 10.5px; letter-spacing: .16em; text-transform: uppercase; color: var(--faint); margin: 0 0 12px; }
.toc-list { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--border); }
.toc-list a {
  display: block; padding: 5px 0 5px 16px; margin-left: -1px;
  border-left: 2px solid transparent; color: var(--muted);
  font-size: 13.5px; line-height: 1.35; cursor: pointer; transition: color .15s, border-color .15s;
}
.toc-list a.lvl3 { padding-left: 28px; font-size: 12.5px; }
.toc-list a:hover { color: var(--ink); }
.toc-list a.active { color: var(--accent-ink); border-left-color: var(--accent); font-weight: 600; }
.toc-progress { margin-top: 18px; font-family: var(--font-mono); font-size: 11px; color: var(--faint); }
.toc-bar { height: 3px; border-radius: 3px; background: var(--border); overflow: hidden; margin-top: 7px; }
.toc-bar i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .15s; }
.toc-share { margin-top: 20px; display: flex; gap: 7px; }
.toc-share button { flex: 1; }

/* ============================================================
   Toast
   ============================================================ */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); font-family: var(--font-mono); font-size: 12.5px;
  padding: 10px 16px; border-radius: var(--r-md); box-shadow: var(--shadow-lg);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 60;
  display: flex; align-items: center; gap: 9px;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast svg { width: 15px; height: 15px; color: var(--accent); }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 1080px) {
  .article-wrap { grid-template-columns: minmax(0,1fr); }
  .toc { display: none; }
  .hero { grid-template-columns: 1fr; }
  /* les ancres en hover ne servent pas au tactile et débordent à gauche */
  .anchor { display: none; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 50; width: 290px; max-width: 86vw;
    transform: translateX(-100%); transition: transform .28s cubic-bezier(.3,.7,.4,1);
    box-shadow: var(--shadow-lg);
  }
  .app.nav-open .sidebar { transform: none; }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 49; opacity: 0; pointer-events: none; transition: opacity .25s; }
  .app.nav-open .scrim { opacity: 1; pointer-events: auto; }
  .topbar {
    display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 30;
    padding: 12px 16px; background: color-mix(in srgb, var(--surface) 80%, var(--bg));
    backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
  }
  .topbar .brand-name { font-size: 14px; }
  .cards { grid-template-columns: 1fr; }
  .home { padding: 24px 18px 60px; }
  .hero { margin-bottom: 34px; gap: 26px; }
  .term-body { height: 230px; }
  .article-title { font-size: clamp(26px, 8vw, 34px); }
  .prose h2 { font-size: 23px; }
  .byline { gap: 10px; }
}

/* empilage vertical du schéma « flow » sur petit écran */
@media (max-width: 560px) {
  .flow { flex-direction: column; }
  .flow-box { width: 100%; }
  .flow-arrow { flex: 0 0 30px; width: 100%; height: 30px; transform: rotate(90deg); }
  .glossary .gl-item { grid-template-columns: 1fr; gap: 4px; text-align: left; }
  .glossary .gl-arrow { display: none; }
  .steps { grid-template-columns: 1fr; }
}
@media (min-width: 861px) { .scrim { display: none; } }

@media print {
  .sidebar, .toc, .topbar, .cb-copy, .toast, .twk-panel { display: none !important; }
  .app { display: block; }
  body::before { display: none; }
}
