/* ============================================================
   TheHackingMachine — single shared custom stylesheet
   Load on EVERY page, after tailwind.css and after
   the AskarLabs design-system bundle.

   Direction: technical-document / editorial. Bone-white paper,
   ink type, hairline rules, no shadows, square corners.
   Primary: #1b1642 (deep indigo).
   ============================================================ */

@import url("https://fonts.googleapis.com/css2?family=Raleway:wght@400;500;600;700;800&display=swap");
@import url("https://api.fontshare.com/v2/css?f[]=satoshi@400,500,700,900&display=swap");
@import url("https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&display=swap");

/* ---------- 1. Tokens ---------- */
:root {
  --font-display: "Raleway", Georgia, serif;
  --font-body: "Satoshi", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, Menlo, monospace;

  --paper: #f7f3ea;         /* bone white */
  --paper-sunk: #efe9dc;
  --ink: #17150f;
  --ink-2: #3c392f;
  --ink-3: #6d6959;
  --ink-4: #a49e8c;
  --rule: #ddd5c3;
  --rule-strong: #c3b9a2;

  --accent: #1b1642;        /* primary */
  --accent-ink: #1b1642;    /* primary as text on paper */

  --band: #1b1642;          /* the one dark surface */
  --band-ink: #f7f3ea;
  --band-ink-2: #b0a9cd;
  --band-rule: rgba(255, 255, 255, 0.15);
  --band-accent: #bab2ef;

  --sev-critical: #b3271d;
  --sev-high: #b05f13;
  --sev-medium: #8b770c;
  --sev-low: #367054;

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);

  --gutter: clamp(20px, 5vw, 76px);
  --measure: 1480px;
}

html.dark {
  --paper: #13110e;
  --paper-sunk: #1b1814;
  --ink: #f5f1e8;
  --ink-2: #d5d0c3;
  --ink-3: #9b9587;
  --ink-4: #706b60;
  --rule: #2c2822;
  --rule-strong: #403b33;

  --accent: #a79ee8;
  --accent-ink: #b0a7ef;

  --band: #16122f;
  --band-ink-2: #a49cc6;

  --sev-critical: #ea6a5c;
  --sev-high: #dd9346;
  --sev-medium: #c8b243;
  --sev-low: #6cb392;
}

/* ---------- 2. Base ---------- */
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.65;
  color: var(--ink-2);
  background: var(--paper);
  text-wrap: pretty;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  color: var(--ink);
  font-weight: 700;
  letter-spacing: -0.015em;
  line-height: 1.1;
  margin: 0;
  text-wrap: balance;
}

a { color: var(--ink); text-decoration: none; }
a:hover { color: var(--accent-ink); }

::selection { background: var(--accent); color: var(--paper); }

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

/* ---------- 3. Layout ---------- */
.mm-wrap {
  width: 100%;
  max-width: var(--measure);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

/* Edge-to-edge band with only gutter padding — used by the hero. */
.mm-wrap-full {
  width: 100%;
  padding-inline: var(--gutter);
}

/* Masthead: wordmark | centered search | controls. The centre track
   yields to the side tracks so control labels never wrap. */
.mm-masthead {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr) max-content;
  align-items: center;
  column-gap: clamp(16px, 3vw, 44px);
  row-gap: 14px;
}
.mm-masthead > :nth-child(2) { justify-self: center; width: min(100%, 320px); }
@media (max-width: 1040px) {
  .mm-masthead {
    grid-template-columns: max-content max-content;
    justify-content: space-between;
  }
  .mm-masthead > :nth-child(2) {
    grid-row: 2;
    grid-column: 1 / -1;
    justify-self: stretch;
    width: 100%;
  }
}

.mm-hair { border: 0; border-top: 1px solid var(--rule); margin: 0; }

.mm-wordmark {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.02em;
  color: var(--ink);
}

/* Dark band — ruled-ledger columns instead of a dot grid. */
.mm-band {
  background: var(--band);
  color: var(--band-ink-2);
  position: relative;
  overflow: hidden;
}
.mm-band::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: repeating-linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.055) 0 1px,
    transparent 1px 132px
  );
  pointer-events: none;
}
.mm-band h1, .mm-band h2, .mm-band h3 { color: var(--band-ink); }

/* ---------- 4. Type helpers ---------- */
.mm-mono {
  font-family: var(--font-mono);
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.mm-eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--ink-4);
}
.mm-band .mm-eyebrow { color: var(--band-ink-2); }

.mm-display {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(2.6rem, 6.4vw, 6rem);
  line-height: 1;
  letter-spacing: -0.035em;
  color: var(--ink);
}

.mm-h2 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.4rem, 2.4vw, 1.95rem);
  letter-spacing: -0.02em;
}

.mm-lead {
  font-size: clamp(1rem, 1.25vw, 1.15rem);
  line-height: 1.7;
  color: var(--ink-3);
}

.mm-t-ink { color: var(--ink); }
.mm-t-2 { color: var(--ink-2); }
.mm-t-3 { color: var(--ink-3); }
.mm-t-4 { color: var(--ink-4); }
.mm-t-accent { color: var(--accent-ink); }

/* ---------- 5. Machine-detail row (hairline separated, no boxes) ---------- */
.mm-specrow {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  margin: 0;
}
.mm-specrow > div {
  border-inline-start: 1px solid var(--rule);
  padding-inline: 22px 28px;
  padding-block: 2px;
}
.mm-specrow > div:first-child { border-inline-start: 0; padding-inline-start: 0; }
.mm-specrow dt {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--ink-4);
  margin-bottom: 5px;
}
.mm-specrow dd {
  margin: 0;
  font-family: var(--font-mono);
  font-size: clamp(0.95rem, 1.1vw, 1.1rem);
  font-weight: 600;
  letter-spacing: -0.03em;
  color: var(--ink);
}

/* ---------- 6. The matrix (shared-hairline cell grid) ---------- */
.mm-matrix {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(clamp(280px, 30vw, 430px), 1fr));
  border-block-start: 1px solid var(--rule);
  border-inline-start: 1px solid var(--rule);
}
.mm-cell {
  border-block-end: 1px solid var(--rule);
  border-inline-end: 1px solid var(--rule);
  padding: clamp(22px, 2.2vw, 32px);
  display: flex;
  flex-direction: column;
  gap: 18px;
  transition: background-color 150ms var(--ease-in-out);
}
.mm-cell:hover { background: var(--paper-sunk); }

.mm-step-cell {
  border-inline-end: 1px solid var(--band-rule);
  padding: clamp(28px, 3vw, 46px) clamp(24px, 2.6vw, 42px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.mm-step-cell:last-child { border-inline-end: 0; }
@media (max-width: 860px) {
  .mm-step-cell { border-inline-end: 0; border-block-end: 1px solid var(--band-rule); }
  .mm-step-cell:last-child { border-block-end: 0; }
}

.mm-step-n {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: var(--band-accent);
}

/* ---------- 7. Marks ---------- */
.mm-cve {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink);
  direction: ltr;
  unicode-bidi: isolate;
}

.mm-sev {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.14em;
}
.mm-sev::before {
  content: "";
  width: 7px;
  height: 7px;
  background: currentColor;
  flex: none;
}
.mm-sev-critical { color: var(--sev-critical); }
.mm-sev-high { color: var(--sev-high); }
.mm-sev-medium { color: var(--sev-medium); }
.mm-sev-low { color: var(--sev-low); }

.mm-tag {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.02em;
  color: var(--ink-3);
}
.mm-tag::before { content: "#"; color: var(--ink-4); }

.mm-spec {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 24px;
  margin: 0;
}
.mm-spec dt {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--ink-4);
  margin-bottom: 3px;
}
.mm-spec dd {
  margin: 0;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--ink);
}
.mm-spec dd.mm-mono { font-weight: 600; }

/* ---------- 8. Controls ---------- */
.mm-field {
  width: 100%;
  font-family: var(--font-mono);
  font-size: 12.5px;
  letter-spacing: 0.02em;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--rule-strong);
  border-radius: 0;
  padding: 7px 2px;
  text-align: center;
  transition: border-color 150ms var(--ease-in-out);
}
.mm-field::placeholder { color: var(--ink-4); }
.mm-field:focus { outline: none; border-bottom-color: var(--accent); }

.mm-select {
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-3);
  background: transparent;
  border: 1px solid var(--rule-strong);
  border-radius: 0;
  padding-block: 7px;
  padding-inline: 10px 28px;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6' fill='none' stroke='%236d6959' stroke-width='1.4'%3E%3Cpath d='M1 1l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  transition: border-color 150ms var(--ease-in-out), color 150ms var(--ease-in-out);
}
[dir="rtl"] .mm-select { background-position: left 10px center; }
.mm-select:hover { border-color: var(--ink); color: var(--ink); }
.mm-select:focus { outline: none; border-color: var(--accent); }

.mm-icon-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid var(--rule-strong);
  border-radius: 0;
  background: transparent;
  color: var(--ink-3);
  cursor: pointer;
  flex: none;
  transition: border-color 150ms var(--ease-in-out), color 150ms var(--ease-in-out);
}
.mm-icon-btn:hover { border-color: var(--ink); color: var(--ink); }

.mm-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  padding: 13px 22px;
  border: 1px solid var(--accent);
  border-radius: 0;
  background: var(--accent);
  color: var(--paper);
  cursor: pointer;
  transition: background-color 150ms var(--ease-in-out), color 150ms var(--ease-in-out),
              border-color 150ms var(--ease-in-out);
}
.mm-btn:hover { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.mm-btn { white-space: nowrap; }

.mm-btn-line {
  background: transparent;
  color: var(--ink);
  border-color: var(--rule-strong);
}
.mm-btn-line:hover { background: transparent; border-color: var(--ink); color: var(--ink); }

.mm-btn-invert {
  background: transparent;
  color: var(--band-ink);
  border-color: var(--band-rule);
  padding: 11px 18px;
}
.mm-btn-invert:hover {
  background: var(--band-ink);
  border-color: var(--band-ink);
  color: var(--band);
}

.mm-txt {
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-4);
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 4px 0;
  cursor: pointer;
  white-space: nowrap;
  transition: color 150ms var(--ease-in-out);
}
.mm-txt:hover:not(:disabled) { color: var(--ink); }
.mm-txt:disabled { opacity: 0.35; cursor: not-allowed; }
.mm-txt[aria-pressed="true"],
.mm-txt[aria-current="page"] {
  color: var(--ink);
  box-shadow: inset 0 -1px 0 0 var(--accent);
}

.mm-link {
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--accent-ink);
  white-space: nowrap;
}
.mm-link:hover { color: var(--ink); }

/* ---------- 9. Copyable command ---------- */
.mm-cmd {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--paper-sunk);
  border: 1px solid var(--rule);
  padding: 9px 11px;
}
.mm-cmd code {
  flex: 1;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-2);
  white-space: nowrap;
  overflow-x: auto;
  direction: ltr;
  unicode-bidi: isolate;
  scrollbar-width: none;
}
.mm-cmd code::-webkit-scrollbar { display: none; }
.mm-cmd code::before { content: "$ "; color: var(--ink-4); }

.mm-copy {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-4);
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
  flex: none;
  transition: color 150ms var(--ease-in-out);
}
.mm-copy:hover { color: var(--accent-ink); }

/* ---------- 9b. Walkthrough pages ---------- */
.mm-doc {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: clamp(32px, 4vw, 64px);
  align-items: start;
}
@media (min-width: 1000px) {
  .mm-doc { grid-template-columns: 232px minmax(0, 1fr); }
  .mm-toc { position: sticky; top: 28px; }
}

.mm-toc { display: flex; flex-direction: column; gap: 2px; }
.mm-toc a {
  font-family: var(--font-mono);
  font-size: 11.5px;
  letter-spacing: 0.04em;
  color: var(--ink-3);
  padding: 7px 0 7px 14px;
  border-inline-start: 1px solid var(--rule);
  transition: color 150ms var(--ease-in-out), border-color 150ms var(--ease-in-out);
}
.mm-toc a:hover { color: var(--ink); border-inline-start-color: var(--accent); }
.mm-toc a .mm-toc-n { color: var(--ink-4); margin-inline-end: 10px; }

.mm-prose { max-width: 74ch; display: flex; flex-direction: column; gap: clamp(40px, 4.5vw, 64px); }
.mm-sec { display: flex; flex-direction: column; gap: 18px; scroll-margin-top: 24px; }
.mm-sec > h2 {
  font-family: var(--font-display);
  font-size: clamp(1.3rem, 2vw, 1.7rem);
  letter-spacing: -0.02em;
}
.mm-sec p { margin: 0; font-size: 15.5px; line-height: 1.75; color: var(--ink-2); }
.mm-sec h3 {
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--ink);
}
.mm-sec ul, .mm-sec ol { margin: 0; padding-inline-start: 20px; display: flex; flex-direction: column; gap: 9px; }
.mm-sec li { font-size: 15px; line-height: 1.7; color: var(--ink-2); }
.mm-sec li::marker { color: var(--ink-4); font-family: var(--font-mono); font-size: 12px; }
.mm-sec code:not(.mm-pre code) {
  font-family: var(--font-mono);
  font-size: 0.88em;
  color: var(--ink);
  background: var(--paper-sunk);
  padding: 1px 5px;
  direction: ltr;
  unicode-bidi: isolate;
}

.mm-sec-head {
  display: flex;
  align-items: baseline;
  gap: 16px;
  border-block-start: 1px solid var(--rule);
  padding-block-start: 14px;
}
.mm-sec-head .mm-sec-n {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--accent-ink);
  flex: none;
}

.mm-pre {
  position: relative;
  background: var(--paper-sunk);
  border: 1px solid var(--rule);
  direction: ltr;
  unicode-bidi: isolate;
}
.mm-pre pre {
  margin: 0;
  padding: 16px 18px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.85;
  color: var(--ink-2);
  tab-size: 2;
}
.mm-pre .mm-copy { position: absolute; top: 12px; right: 14px; }
.mm-pre-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  border-block-end: 1px solid var(--rule);
  padding: 7px 14px;
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--ink-4);
}
.mm-pre-label + pre { padding-top: 13px; }
.mm-pre-label ~ .mm-copy { top: 7px; right: 14px; }

.mm-note {
  border-inline-start: 2px solid var(--accent);
  padding: 2px 0 2px 16px;
  font-size: 14.5px;
  line-height: 1.7;
  color: var(--ink-3);
}
.mm-note strong { color: var(--ink); font-weight: 700; }

.mm-kv {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  border-block-start: 1px solid var(--rule);
  margin: 0;
}
.mm-kv > div {
  border-block-end: 1px solid var(--rule);
  padding: 12px 0;
  padding-inline-end: 20px;
}
.mm-kv dt {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--ink-4);
  margin-bottom: 4px;
}
.mm-kv dd {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.mm-pagenav {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr));
  border-block-start: 1px solid var(--rule);
}
.mm-pagenav a {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: clamp(22px, 2.4vw, 34px) 0;
  padding-inline-end: 28px;
  border-inline-start: 1px solid var(--rule);
  padding-inline-start: 28px;
  transition: background-color 150ms var(--ease-in-out);
}
.mm-pagenav a:first-child { border-inline-start: 0; padding-inline-start: 0; }
.mm-pagenav a:hover { background: var(--paper-sunk); }
.mm-pagenav a[aria-disabled="true"] { opacity: 0.4; pointer-events: none; }
.mm-pagenav .mm-pagenav-t { font-family: var(--font-display); font-weight: 700; font-size: 18px; color: var(--ink); letter-spacing: -0.02em; }

.mm-crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--ink-4);
}
.mm-crumbs a { color: var(--ink-4); }
.mm-crumbs a:hover { color: var(--ink); }

/* ---------- 10. Bidirectional (LTR / RTL) ---------- */
.mm-ltr { direction: ltr; unicode-bidi: isolate; }
[dir="rtl"] .mm-flip { transform: scaleX(-1); }
[dir="rtl"] .mm-mono,
[dir="rtl"] .mm-cve { direction: ltr; unicode-bidi: isolate; }

/* ---------- 11. Motion ---------- */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------- Library page: search hero + filter sidebar ---------- */
.mm-search-hero {
  width: 100%;
  max-width: 640px;
  font-size: 16px;
  text-align: start;
  padding: 14px 2px;
}

.mm-lib {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: clamp(24px, 3vw, 48px);
  align-items: start;
}
@media (max-width: 900px) {
  .mm-lib { grid-template-columns: minmax(0, 1fr); }
  .mm-side { display: none; }
  .mm-side.open { display: block; }
}
@media (min-width: 901px) {
  .mm-side-toggle { display: none; }
}

.mm-side { position: sticky; top: 20px; }
.mm-fgroup { border-block-end: 1px solid var(--rule); padding-block: 14px; }
.mm-fgroup > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink);
}
.mm-fgroup > summary::-webkit-details-marker { display: none; }
.mm-fgroup > summary::after { content: "+"; color: var(--ink-4); }
.mm-fgroup[open] > summary::after { content: "−"; }
.mm-fgroup ul { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.mm-fgroup ul ul { margin-block: 8px 2px; padding-inline-start: 22px; }
.mm-check {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--ink-2);
  cursor: pointer;
}
.mm-check input { accent-color: var(--accent); margin: 0; }
.mm-check .n { margin-inline-start: auto; font-family: var(--font-mono); font-size: 11px; color: var(--ink-4); }
.mm-pages button[aria-current="page"] { color: var(--ink); }
.mm-txt:disabled { opacity: 0.35; cursor: default; }

/* Header logo: dark-text PNG on light theme, white PNG on dark theme */
img.mm-logo { height: 48px; width: auto; display: block; }
html:not(.dark) img.mm-logo-for-dark { display: none; }
html.dark img.mm-logo-for-light { display: none; }
