/* ============================================================================
 * crypto-docs.css
 * Stylesheet for cryptography documentation — cyber, serious, precise.
 *
 * Fonts: IBM Plex Sans / IBM Plex Mono / IBM Plex Serif
 * Compatible with mdBook, rustdoc, Docusaurus, VitePress, or raw HTML.
 *
 * Author: cslashm <cslashm@pm.me>
 * Co-author: Claude (Anthropic) — AI-assisted implementation
 * License: Apache-2.0
 * ========================================================================= */

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@300;400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&family=IBM+Plex+Serif:wght@400;500;600&display=swap');

/* ---------- Design tokens ------------------------------------------------- */

:root {
  /* Surfaces — deep, slightly blue-shifted blacks */
  --bg-0: #08090c;           /* page background */
  --bg-1: #0d1016;           /* panels, code blocks */
  --bg-2: #141822;           /* hover, elevated */
  --bg-3: #1c2130;           /* borders of elevated items */

  /* Foreground */
  --fg-0: #e5e9f0;           /* primary text */
  --fg-1: #c0c6d4;           /* body */
  --fg-2: #8a92a6;           /* secondary */
  --fg-3: #5a6278;           /* muted, captions */

  /* Lines */
  --line: #1e2330;
  --line-strong: #2a3042;

  /* Accents — phosphor palette, used sparingly */
  --cyan:   #5ad7ff;         /* primary accent */
  --green:  #7df2b0;          /* success, valid */
  --amber:  #ffb347;          /* caution, deprecated */
  --red:    #ff6b7a;          /* danger, broken */
  --violet: #b79dff;          /* crypto / PQC domain */

  /* Semantic aliases */
  --accent:       var(--cyan);
  --accent-soft:  color-mix(in srgb, var(--cyan) 18%, transparent);
  --link:         var(--cyan);
  --link-hover:   #8ae3ff;

  /* Typography */
  --font-sans:  'IBM Plex Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono:  'IBM Plex Mono', ui-monospace, SFMono-Regular, Consolas, monospace;
  --font-serif: 'IBM Plex Serif', Georgia, serif;

  /* Metrics */
  --radius: 3px;
  --radius-lg: 6px;
  --content-width: 76ch;
  --sidebar-width: 280px;

  /* Motion */
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* ---------- Base ---------------------------------------------------------- */

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

html {
  background: var(--bg-0);
  color-scheme: dark;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 16px;
  font-weight: 400;
  line-height: 1.65;
  color: var(--fg-1);
  background:
    /* very subtle grid — invisible unless you look for it */
    linear-gradient(var(--line) 1px, transparent 1px) 0 0 / 100% 64px,
    linear-gradient(90deg, var(--line) 1px, transparent 1px) 0 0 / 64px 100%,
    radial-gradient(ellipse at top, #0e1320 0%, var(--bg-0) 60%);
  background-attachment: fixed;
  background-blend-mode: normal, normal, normal;
}

/* the grid is too strong by default — fade it */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: var(--bg-0);
  opacity: 0.92;
  pointer-events: none;
  z-index: -1;
}

::selection {
  background: var(--accent-soft);
  color: var(--fg-0);
}

/* ---------- Layout -------------------------------------------------------- */

.doc-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100vh;
}

.doc-main {
  padding: 4rem 3rem 6rem;
  max-width: calc(var(--content-width) + 6rem);
  margin: 0 auto;
}

@media (max-width: 900px) {
  .doc-layout { grid-template-columns: 1fr; }
  .doc-main { padding: 2rem 1.25rem 4rem; }
}

/* ---------- Top bar (optional) ------------------------------------------- */

.doc-topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  background: color-mix(in srgb, var(--bg-0) 85%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--fg-2);
}

.doc-topbar .dots {
  display: inline-flex;
  gap: 6px;
}
.doc-topbar .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--bg-3);
  border: 1px solid var(--line-strong);
}
.doc-topbar .dot.live { background: var(--green); box-shadow: 0 0 6px var(--green); }

.doc-topbar .prompt {
  color: var(--accent);
}
.doc-topbar .prompt::before {
  content: "~ ";
  color: var(--fg-3);
}

/* ---------- Sidebar ------------------------------------------------------- */

.doc-sidebar {
  border-right: 1px solid var(--line);
  padding: 2.5rem 1.5rem;
  background: var(--bg-1);
  position: sticky;
  top: 0;
  max-height: 100vh;
  overflow-y: auto;
  font-size: 0.92rem;
}

.doc-sidebar::-webkit-scrollbar { width: 6px; }
.doc-sidebar::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 3px;
}

.doc-sidebar .brand {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--fg-0);
  letter-spacing: 0.02em;
  margin-bottom: 2rem;
  display: block;
}
.doc-sidebar .brand::before {
  content: "// ";
  color: var(--accent);
}

.doc-sidebar .nav-section {
  margin-bottom: 1.75rem;
}

.doc-sidebar .nav-title {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--fg-3);
  margin: 0 0 0.5rem;
}

.doc-sidebar ul {
  list-style: none;
  padding: 0; margin: 0;
}
.doc-sidebar li { margin: 0.1rem 0; }
.doc-sidebar a {
  display: block;
  padding: 0.3rem 0.6rem;
  color: var(--fg-2);
  text-decoration: none;
  border-radius: var(--radius);
  border-left: 2px solid transparent;
  transition: all 0.15s var(--ease);
}
.doc-sidebar a:hover {
  color: var(--fg-0);
  background: var(--bg-2);
}
.doc-sidebar a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--accent-soft);
}

/* ---------- Typography ---------------------------------------------------- */

h1, h2, h3, h4, h5, h6 {
  color: var(--fg-0);
  font-weight: 600;
  line-height: 1.25;
  margin: 2.5em 0 0.6em;
  scroll-margin-top: 5rem;
}
h1:first-child, h2:first-child, h3:first-child { margin-top: 0; }

h1 {
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: clamp(2rem, 4vw, 2.8rem);
  letter-spacing: -0.02em;
  border-bottom: 1px solid var(--line-strong);
  padding-bottom: 0.6rem;
  margin-bottom: 0.4em;
}
h1 .eyebrow {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.2em;
  margin-bottom: 0.8rem;
}

h2 {
  font-family: var(--font-sans);
  font-size: 1.6rem;
  font-weight: 600;
  position: relative;
  padding-left: 1.2rem;
}
h2::before {
  content: "";
  position: absolute;
  left: 0; top: 0.25em; bottom: 0.25em;
  width: 3px;
  background: var(--accent);
}

h3 {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--fg-0);
}
h3::before {
  content: "§ ";
  color: var(--fg-3);
  font-weight: 400;
}

h4 {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--fg-2);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

p { margin: 0 0 1.1em; }

a {
  color: var(--link);
  text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, var(--link) 40%, transparent);
  transition: border-color 0.15s var(--ease), color 0.15s var(--ease);
}
a:hover {
  color: var(--link-hover);
  border-bottom-color: var(--link-hover);
}

strong { color: var(--fg-0); font-weight: 600; }
em { color: var(--fg-0); font-style: italic; }

small, .small { font-size: 0.85em; color: var(--fg-2); }

hr {
  border: 0;
  height: 1px;
  background: var(--line);
  margin: 3rem 0;
}
hr.dashed {
  background: repeating-linear-gradient(90deg,
    var(--line) 0 8px, transparent 8px 16px);
}

/* ---------- Inline code & kbd --------------------------------------------- */

code, kbd, samp {
  font-family: var(--font-mono);
  font-size: 0.88em;
}

:not(pre) > code {
  background: var(--bg-1);
  color: var(--cyan);
  padding: 0.12em 0.45em;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  font-weight: 500;
  white-space: nowrap;
}

kbd {
  display: inline-block;
  padding: 0.15em 0.5em;
  background: var(--bg-2);
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: var(--radius);
  color: var(--fg-0);
  font-size: 0.8em;
  font-weight: 500;
}

/* crypto-specific inline token: <span class="hex">0xDEADBEEF</span> */
.hex, .bin {
  font-family: var(--font-mono);
  color: var(--violet);
  background: color-mix(in srgb, var(--violet) 10%, transparent);
  padding: 0.1em 0.4em;
  border-radius: var(--radius);
  font-size: 0.88em;
  word-break: break-all;
}
.bin { color: var(--green); background: color-mix(in srgb, var(--green) 10%, transparent); }

/* ---------- Code blocks --------------------------------------------------- */

pre {
  position: relative;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.4rem;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  line-height: 1.6;
  margin: 1.4em 0;
  tab-size: 4;
  color: var(--fg-0);
}
pre code {
  background: none; border: 0; padding: 0; color: inherit;
  font-size: inherit; white-space: pre;
}

pre::-webkit-scrollbar { height: 6px; }
pre::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 3px; }

/* language tag — add data-lang="rust" on <pre> */
pre[data-lang]::before {
  content: attr(data-lang);
  position: absolute;
  top: 0; right: 0;
  padding: 0.25rem 0.7rem;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--fg-3);
  background: var(--bg-2);
  border-left: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  border-top-right-radius: var(--radius-lg);
  border-bottom-left-radius: var(--radius);
}

/* minimal syntax highlighting — pair with highlight.js / rustdoc / Prism */
.hljs-keyword, .token.keyword     { color: var(--violet); font-weight: 500; }
.hljs-string, .token.string       { color: var(--green); }
.hljs-number, .token.number       { color: var(--amber); }
.hljs-comment, .token.comment     { color: var(--fg-3); font-style: italic; }
.hljs-function, .token.function   { color: var(--cyan); }
.hljs-type, .token.class-name     { color: var(--cyan); }
.hljs-title, .token.title         { color: var(--fg-0); font-weight: 500; }
.hljs-built_in, .token.builtin    { color: var(--amber); }
.hljs-variable, .token.variable   { color: var(--fg-0); }
.hljs-attr, .token.attr-name      { color: var(--violet); }
.hljs-operator, .token.operator   { color: var(--fg-2); }
.hljs-punctuation, .token.punctuation { color: var(--fg-2); }

/* ---------- Blockquote ---------------------------------------------------- */

blockquote {
  margin: 1.5em 0;
  padding: 0.2em 1.2em;
  border-left: 2px solid var(--line-strong);
  color: var(--fg-2);
  font-style: italic;
  font-family: var(--font-serif);
}
blockquote cite {
  display: block;
  margin-top: 0.5em;
  font-style: normal;
  font-family: var(--font-mono);
  font-size: 0.82em;
  color: var(--fg-3);
}
blockquote cite::before { content: "— "; }

/* ---------- Admonitions --------------------------------------------------- */
/* Usage:
   <div class="admonition note">      <p class="admonition-title">Note</p> ... </div>
   Variants: .note .tip .warning .danger .crypto .deprecated
*/

.admonition {
  margin: 1.5em 0;
  padding: 1rem 1.2rem 1rem 1.2rem;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-left: 3px solid var(--fg-3);
  border-radius: var(--radius);
}
.admonition > :last-child { margin-bottom: 0; }
.admonition-title {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin: 0 0 0.5rem;
  color: var(--fg-2);
}
.admonition-title::before {
  content: "▸ ";
  margin-right: 0.3em;
}

.admonition.note     { border-left-color: var(--cyan);   }
.admonition.note .admonition-title { color: var(--cyan); }

.admonition.tip      { border-left-color: var(--green);  }
.admonition.tip .admonition-title { color: var(--green); }

.admonition.warning  { border-left-color: var(--amber);  }
.admonition.warning .admonition-title { color: var(--amber); }

.admonition.danger   { border-left-color: var(--red);    }
.admonition.danger .admonition-title { color: var(--red); }

.admonition.crypto   { border-left-color: var(--violet); }
.admonition.crypto .admonition-title { color: var(--violet); }
.admonition.crypto .admonition-title::before { content: "⚿ "; }

.admonition.deprecated {
  border-left-color: var(--red);
  background: color-mix(in srgb, var(--red) 5%, var(--bg-1));
}
.admonition.deprecated .admonition-title { color: var(--red); }
.admonition.deprecated .admonition-title::before { content: "⚠ DEPRECATED — "; }

/* ---------- Tables -------------------------------------------------------- */

table {
  border-collapse: collapse;
  width: 100%;
  margin: 1.5em 0;
  font-size: 0.92rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
th, td {
  padding: 0.7rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
}
th {
  background: var(--bg-1);
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-2);
}
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--bg-1); }

/* crypto comparison tables — highlight strength cells */
td.secure   { color: var(--green); font-family: var(--font-mono); }
td.weak     { color: var(--amber); font-family: var(--font-mono); }
td.broken   { color: var(--red);   font-family: var(--font-mono); text-decoration: line-through; }
td.pqc      { color: var(--violet); font-family: var(--font-mono); }

/* ---------- Lists --------------------------------------------------------- */

ul, ol { padding-left: 1.4em; margin: 0 0 1.1em; }
li { margin: 0.2em 0; }
li::marker { color: var(--accent); }

ul.clean { list-style: none; padding-left: 0; }
ul.clean li { position: relative; padding-left: 1.4em; }
ul.clean li::before {
  content: "›";
  position: absolute;
  left: 0;
  color: var(--accent);
  font-family: var(--font-mono);
}

/* definition lists — perfect for protocol specs */
dl {
  display: grid;
  grid-template-columns: minmax(140px, 200px) 1fr;
  gap: 0.5rem 1.5rem;
  margin: 1.5em 0;
  padding: 1rem 1.2rem;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}
dt {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--accent);
  padding-top: 0.1em;
}
dd { margin: 0; color: var(--fg-1); }

/* ---------- Math (KaTeX-friendly) ---------------------------------------- */

.math, .katex {
  color: var(--fg-0);
  font-size: 1.02em;
}
.katex-display {
  margin: 1.5em 0;
  padding: 1rem;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow-x: auto;
}

/* ---------- Figures ------------------------------------------------------- */

figure {
  margin: 1.5em 0;
  padding: 1rem;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}
figure img, figure svg { max-width: 100%; display: block; margin: 0 auto; }
figcaption {
  margin-top: 0.8rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--fg-3);
  text-align: center;
  letter-spacing: 0.03em;
}
figcaption::before { content: "fig. "; color: var(--accent); }

/* ---------- Utilities ----------------------------------------------------- */

.badge {
  display: inline-block;
  padding: 0.15em 0.55em;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border-radius: var(--radius);
  background: var(--bg-2);
  color: var(--fg-2);
  border: 1px solid var(--line-strong);
}
.badge.cyan   { color: var(--cyan);   border-color: color-mix(in srgb, var(--cyan) 40%, var(--line-strong)); }
.badge.green  { color: var(--green);  border-color: color-mix(in srgb, var(--green) 40%, var(--line-strong)); }
.badge.amber  { color: var(--amber);  border-color: color-mix(in srgb, var(--amber) 40%, var(--line-strong)); }
.badge.red    { color: var(--red);    border-color: color-mix(in srgb, var(--red) 40%, var(--line-strong)); }
.badge.violet { color: var(--violet); border-color: color-mix(in srgb, var(--violet) 40%, var(--line-strong)); }

/* Anchor link on headings */
h1 .anchor, h2 .anchor, h3 .anchor, h4 .anchor {
  opacity: 0;
  margin-left: 0.4em;
  color: var(--fg-3);
  font-weight: 400;
  text-decoration: none;
  border: 0;
  transition: opacity 0.15s var(--ease);
}
h1:hover .anchor, h2:hover .anchor, h3:hover .anchor, h4:hover .anchor {
  opacity: 1;
}

/* Focus visible — accessible + on-brand */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius);
}

/* Print — flatten everything */
@media print {
  body { background: white; color: black; }
  .doc-sidebar, .doc-topbar { display: none; }
  pre, code { background: #f5f5f5; color: black; border-color: #ccc; }
  a { color: black; border-bottom: 1px solid #666; }
}
