/* ============================================================
 * Keel — mdbook theme
 * Drop this into your mdbook `theme/` directory as `css/general.css`
 * overrides, OR load it via `additional-css` in book.toml:
 *
 *   [output.html]
 *   additional-css = ["brand/keel-docs.css"]
 *   preferred-dark-theme = "keel"
 *   default-theme      = "keel"
 *
 * Then register the theme in theme/index.hbs if you want the toggle.
 * ============================================================ */

/* ---------- Fonts ------------------------------------------------
 * Self-hosted in the docs build — see docs/theme/fonts.css, loaded via
 * additional-css before this file. No third-party / render-blocking
 * @import. Embedders outside the docs build must provide the three
 * families (Fraunces, Inter, JetBrains Mono) themselves. */

/* ---------- Palette & tokens ------------------------------------ */
:root {
  --keel-onyx:  #0B0D10;
  --keel-onyx-2:#13161B;
  --keel-onyx-3:#1E232A;
  --keel-ash:   #3A4048;
  --keel-fog:   #9BA3AE;
  --keel-ivory: #F2EFE6;
  --keel-mist:  #D8D4C7;
  --keel-paper: #FAF8F1;
  --keel-amber: #FFB84A;
  --keel-burnt: #D2691A;

  --keel-font-display: 'Fraunces', ui-serif, Georgia, serif;
  --keel-font-body:    'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --keel-font-mono:    'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ---------- Dark theme (default: "keel") ------------------------ */
.keel,
.navy,            /* alias mdbook's navy to keel */
.ayu,
.coal,            /* coal too, so no built-in theme is ever unstyled */
html.keel body,
html.navy body {
  --bg:                var(--keel-onyx);
  --fg:                var(--keel-ivory);
  --sidebar-bg:        var(--keel-onyx-2);
  --sidebar-fg:        var(--keel-mist);
  --sidebar-non-existant: #2a2f37;
  --sidebar-active:    var(--keel-amber);
  --sidebar-spacer:    var(--keel-onyx-3);

  --scrollbar:         var(--keel-ash);

  --icons:             var(--keel-fog);
  --icons-hover:       var(--keel-amber);

  --links:             var(--keel-amber);

  --inline-code-color: var(--keel-amber);

  --theme-popup-bg:        var(--keel-onyx-2);
  --theme-popup-border:    var(--keel-onyx-3);
  --theme-hover:           var(--keel-onyx-3);

  --quote-bg:              var(--keel-onyx-2);
  --quote-border:          var(--keel-amber);

  --table-border-color:    var(--keel-onyx-3);
  --table-header-bg:       var(--keel-onyx-2);
  --table-alternate-bg:    #0f1217;

  --searchbar-border-color: var(--keel-onyx-3);
  --searchbar-bg:          var(--keel-onyx-2);
  --searchbar-fg:          var(--keel-ivory);
  --searchbar-shadow-color:#000;
  --searchresults-header-fg: var(--keel-fog);
  --searchresults-border-color: var(--keel-onyx-3);
  --searchresults-li-bg:   var(--keel-onyx-2);
  --search-mark-bg:        var(--keel-amber);

  --color-scheme: dark;
}

/* ---------- Light theme: "keel-light" --------------------------- */
.keel-light,
.light,
.rust {
  --bg:                var(--keel-paper);
  --fg:                var(--keel-onyx);
  --sidebar-bg:        var(--keel-ivory);
  --sidebar-fg:        var(--keel-onyx);
  --sidebar-non-existant: var(--keel-fog);
  --sidebar-active:    var(--keel-burnt);
  --sidebar-spacer:    var(--keel-mist);

  --scrollbar:         var(--keel-mist);

  --icons:             var(--keel-ash);
  --icons-hover:       var(--keel-burnt);

  --links:             var(--keel-burnt);

  --inline-code-color: var(--keel-burnt);

  --theme-popup-bg:        #fff;
  --theme-popup-border:    var(--keel-mist);
  --theme-hover:           var(--keel-ivory);

  --quote-bg:              var(--keel-ivory);
  --quote-border:          var(--keel-burnt);

  --table-border-color:    var(--keel-mist);
  --table-header-bg:       var(--keel-ivory);
  --table-alternate-bg:    #f6f2e6;

  --searchbar-border-color: var(--keel-mist);
  --searchbar-bg:          #fff;
  --searchbar-fg:          var(--keel-onyx);
  --searchbar-shadow-color:rgba(0,0,0,0.08);
  --searchresults-header-fg: var(--keel-ash);
  --searchresults-border-color: var(--keel-mist);
  --searchresults-li-bg:   var(--keel-ivory);
  --search-mark-bg:        var(--keel-amber);

  --color-scheme: light;
}

/* ---------- Global type ---------------------------------------- */
html { font-family: var(--keel-font-body); font-feature-settings: "ss01", "cv11"; }
body { font-family: var(--keel-font-body); line-height: 1.6; }

.content h1, .content h2, .content h3, .content h4, .content h5 {
  font-family: var(--keel-font-display);
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.15;
}
.content h1 { font-size: 2.5em; margin-top: 0; padding-bottom: 0.4em; border-bottom: 1px solid var(--quote-bg); }
.content h2 { font-size: 1.8em; margin-top: 2.2em; }
.content h3 { font-size: 1.35em; margin-top: 1.8em; }
.content h4 { font-size: 1.12em; margin-top: 1.5em; }

.content a, .content a:visited { color: var(--links); text-decoration: none; border-bottom: 1px solid transparent; transition: border-color 120ms; }
.content a:hover { border-bottom-color: var(--links); }

.content p, .content li { font-size: 1em; }

/* ---------- Sidebar -------------------------------------------- */
.sidebar { font-family: var(--keel-font-body); font-size: 0.9em; }
/* Leave room for the mark bar (::before) so chapter items never scroll under it. */
.sidebar .sidebar-scrollbox { padding: 72px 18px 16px; }
.sidebar .chapter li.chapter-item {
  line-height: 1.5;
  margin: 0.15rem 0;
  padding: 3px 8px;
  border-radius: 4px;
}
.sidebar .chapter li a {
  color: var(--sidebar-fg);
  padding: 2px 0;
  border: none;
}
.sidebar .chapter li a:hover { color: var(--sidebar-active); }
.sidebar .chapter li.chapter-item:has(> a.active) {
  background: var(--theme-hover);
}
.sidebar .chapter li a.active {
  color: var(--sidebar-active);
  font-weight: 600;
}
.sidebar .chapter li.part-title {
  font-family: var(--keel-font-mono);
  font-size: 0.72em;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--keel-fog);
  margin: 1.8rem 0 0.4rem;
  padding: 0;
}

/* Sidebar Keel mark — sticky header bar at top, opaque so chapter items
   can scroll underneath without showing through. */
.sidebar::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 72px;
  background-color: var(--sidebar-bg);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 200'><circle cx='100' cy='100' r='92' fill='none' stroke='%23F2EFE6' stroke-width='6'/><path d='M 100 22 L 148 150 L 52 150 Z' fill='%23F2EFE6'/><line x1='100' y1='22' x2='100' y2='178' stroke='%23FFB84A' stroke-width='10'/><path d='M 40 150 Q 100 192 160 150 L 148 150 Q 100 172 52 150 Z' fill='%23F2EFE6'/></svg>");
  background-repeat: no-repeat;
  background-position: center 16px;
  background-size: 40px 40px;
  border-bottom: 1px solid var(--sidebar-spacer);
  z-index: 2;
  pointer-events: none;
}
.keel-light .sidebar::before, .light .sidebar::before, .rust .sidebar::before {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 200'><circle cx='100' cy='100' r='92' fill='none' stroke='%230B0D10' stroke-width='6'/><path d='M 100 22 L 148 150 L 52 150 Z' fill='%230B0D10'/><line x1='100' y1='22' x2='100' y2='178' stroke='%23D2691A' stroke-width='10'/><path d='M 40 150 Q 100 192 160 150 L 148 150 Q 100 172 52 150 Z' fill='%230B0D10'/></svg>");
}

/* ---------- Menu bar ------------------------------------------- */
#menu-bar {
  border-bottom: 1px solid var(--quote-bg);
  background: var(--bg);
}
#menu-bar .left-buttons button,
#menu-bar .right-buttons button { color: var(--icons); }
#menu-bar .menu-title {
  font-family: var(--keel-font-display);
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* ---------- Code ----------------------------------------------- */
code { font-family: var(--keel-font-mono); font-size: 0.92em; }
.content :not(pre) > code {
  background: var(--quote-bg);
  color: var(--inline-code-color);
  padding: 0.15em 0.45em;
  border-radius: 4px;
  font-weight: 500;
}
pre {
  background: var(--quote-bg) !important;
  border: 1px solid var(--quote-bg);
  border-left: 3px solid var(--keel-amber);
  border-radius: 6px;
  padding: 16px 20px;
  font-size: 0.88em;
  line-height: 1.55;
  overflow-x: auto;
}
pre > code { background: transparent !important; padding: 0; color: var(--fg); }

/* Syntax highlighting — keel-flavored (dark)
   Amber keywords anchor the brand; strings sit in a warm gold, numbers in
   mint, and types/functions take vibrant blue/violet that hold up on the
   onyx code background. Attributes (@role, @tools) use a coral that reads
   far better than the muddy brand burnt did on dark. */
.hljs-keyword, .hljs-selector-tag, .hljs-built_in { color: var(--keel-amber); font-weight: 500; }
.hljs-string, .hljs-attr, .hljs-symbol, .hljs-bullet { color: #E8C078; }
.hljs-number, .hljs-literal { color: #8FE0C0; }
.hljs-comment, .hljs-quote { color: #7E8794; font-style: italic; }
.hljs-title, .hljs-section, .hljs-function { color: #C792EA; }
.hljs-variable, .hljs-name, .hljs-type { color: #82AAFF; }
.hljs-meta, .hljs-tag { color: #F78C6C; }
.keel-light .hljs-keyword, .light .hljs-keyword, .rust .hljs-keyword { color: var(--keel-burnt); }
.keel-light .hljs-string, .light .hljs-string, .rust .hljs-string { color: #8B5A1F; }
.keel-light .hljs-number, .light .hljs-number, .rust .hljs-number { color: #2F7D5B; }
.keel-light .hljs-comment, .light .hljs-comment, .rust .hljs-comment { color: var(--keel-ash); }
/* Dark-saturated counterparts of the pastel function/type colors — the dark
   defaults (#CBB8FF, #A6D6FF, #E8C078) wash out on the ivory code background. */
.keel-light .hljs-title, .light .hljs-title, .rust .hljs-title,
.keel-light .hljs-section, .light .hljs-section, .rust .hljs-section,
.keel-light .hljs-function, .light .hljs-function, .rust .hljs-function { color: #7C3AED; }
.keel-light .hljs-variable, .light .hljs-variable, .rust .hljs-variable,
.keel-light .hljs-name, .light .hljs-name, .rust .hljs-name,
.keel-light .hljs-type, .light .hljs-type, .rust .hljs-type { color: #1D4ED8; }
.keel-light .hljs-attr, .light .hljs-attr, .rust .hljs-attr,
.keel-light .hljs-symbol, .light .hljs-symbol, .rust .hljs-symbol,
.keel-light .hljs-bullet, .light .hljs-bullet, .rust .hljs-bullet { color: #9A5B14; }

/* ---------- Blockquotes / callouts ------------------------------
   Each callout carries a single `--callout` accent that drives the left
   border, the tinted background, and the label colour. keel-callouts.js adds
   `callout-info` / `callout-tip` / `callout-warn` based on the leading bold
   word; unrecognised labels keep the neutral amber default below. The faint
   accent-tinted background also sets callouts apart from code blocks, which
   share the amber left border but stay on the flat `--quote-bg`. */
blockquote {
  --callout: var(--keel-amber);
  --callout-tint: rgba(255, 184, 74, 0.07);
  background: var(--callout-tint);
  border-left: 3px solid var(--callout);
  border-radius: 0 6px 6px 0;
  padding: 14px 20px;
  margin: 1.5em 0;
  color: var(--fg);
}
blockquote p:last-child { margin-bottom: 0; }

blockquote.callout-info { --callout: #6FB6FF; --callout-tint: rgba(111, 182, 255, 0.08); }
blockquote.callout-tip  { --callout: #5FC9A3; --callout-tint: rgba(95, 201, 163, 0.08); }
blockquote.callout-warn { --callout: var(--keel-burnt); --callout-tint: rgba(210, 105, 26, 0.09); }

/* Admonition-style callouts — use `> **Note:**`, `> **Warning:**` etc. */
blockquote p:first-child strong:first-child {
  font-family: var(--keel-font-mono);
  font-size: 0.75em;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--callout);
  display: block;
  margin-bottom: 0.4em;
}

/* ---------- Status badges --------------------------------------
   Used inline in docs as <span class="badge badge-soon">Coming soon</span>
   to mark features that are planned or partially implemented. */
.badge {
  display: inline-block;
  font-family: var(--keel-font-mono);
  font-size: 0.72em;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 4px;
  vertical-align: middle;
  margin-left: 0.4em;
}
.badge-soon {
  background: rgba(255, 184, 74, 0.15);
  color: var(--keel-amber);
  border: 1px solid rgba(255, 184, 74, 0.4);
}
.keel-light .badge-soon, .light .badge-soon, .rust .badge-soon {
  background: rgba(210, 105, 26, 0.12);
  color: var(--keel-burnt);
  border: 1px solid rgba(210, 105, 26, 0.35);
}
.badge-partial {
  background: rgba(155, 163, 174, 0.15);
  color: var(--keel-fog);
  border: 1px solid rgba(155, 163, 174, 0.35);
}

/* ---------- Tables ---------------------------------------------
   Horizontal rules only — no vertical gridlines — for a lighter, more
   modern feel. A heavier rule under the header anchors the columns. */
table {
  border-collapse: collapse;
  margin: 1.5em 0;
  font-size: 0.95em;
  width: 100%;
}
table thead tr { background: transparent; }
table th, table td {
  border: none;
  border-bottom: 1px solid var(--table-border-color);
  padding: 9px 14px 9px 0;
}
table th {
  font-family: var(--keel-font-display);
  font-weight: 600;
  text-align: left;
  border-bottom: 2px solid var(--table-border-color);
}
table tr:last-child td { border-bottom: none; }
table tbody tr:hover td { background: var(--table-alternate-bg); }

/* ---------- Search --------------------------------------------- */
#searchbar {
  border: 1px solid var(--searchbar-border-color);
  background: var(--searchbar-bg);
  color: var(--searchbar-fg);
  border-radius: 6px;
  font-family: var(--keel-font-body);
}
#searchbar:focus {
  border-color: var(--keel-amber);
  outline: none;
  box-shadow: 0 0 0 3px rgba(255,184,74,0.18);
}
.searchresults-header { color: var(--searchresults-header-fg); font-family: var(--keel-font-mono); font-size: 0.75em; letter-spacing: 0.1em; text-transform: uppercase; }
mark { background: var(--search-mark-bg); color: var(--keel-onyx); padding: 0 2px; border-radius: 2px; }

/* ---------- Page nav buttons ----------------------------------- */
.nav-chapters {
  color: var(--icons);
  transition: color 160ms;
}
.nav-chapters:hover { color: var(--keel-amber); }

/* ---------- Theme popup ---------------------------------------- */
.theme-popup {
  background: var(--theme-popup-bg);
  border: 1px solid var(--theme-popup-border);
  border-radius: 6px;
  font-family: var(--keel-font-body);
}
.theme-popup .theme:hover { background: var(--theme-hover); }

/* ---------- Footer / print ------------------------------------- */
@media print {
  .sidebar, #menu-bar, .nav-chapters { display: none !important; }
  body { color: #000; background: #fff; }
  pre { border: 1px solid #ccc; border-left: 3px solid #000; }
}

/* ---------- Content width -------------------------------------- */
.content main { max-width: 780px; padding: 0 20px 80px; }

/* ---------- "On this page" right-rail TOC ----------------------- */
/* Injected by keel-pagetoc.js as the last child of <main>. Pulled out of
   flow and pinned to the right gutter; only shown when the viewport is wide
   enough that it clears the centered 780px body. */
.keel-pagetoc { display: none; }

@media (min-width: 1500px) {
  .keel-pagetoc {
    display: block;
    position: fixed;
    top: var(--menu-bar-height, 50px);
    margin-top: 2.5rem;
    right: max(1.5rem, calc((100vw - var(--sidebar-width, 300px) - 780px) / 2 - 220px));
    width: 200px;
    max-height: calc(100vh - var(--menu-bar-height, 50px) - 5rem);
    overflow-y: auto;
    font-family: var(--keel-font-body);
    font-size: 0.82em;
    line-height: 1.4;
  }
  .keel-pagetoc-title {
    font-family: var(--keel-font-mono);
    font-size: 0.86em;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--keel-fog);
    padding-bottom: 0.5rem;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid var(--table-border-color);
  }
  .keel-pagetoc ul { list-style: none; margin: 0; padding: 0; }
  .keel-pagetoc li { margin: 0; padding: 0; }
  .keel-pagetoc-h3 { padding-left: 0.85rem; }
  .keel-pagetoc a {
    display: block;
    padding: 3px 0 3px 10px;
    color: var(--sidebar-fg);
    border: none;
    border-left: 2px solid transparent;
    transition: color 120ms, border-color 120ms;
  }
  .keel-pagetoc a:hover { color: var(--sidebar-active); border-bottom: none; }
  .keel-pagetoc a.active {
    color: var(--sidebar-active);
    border-left-color: var(--sidebar-active);
    font-weight: 600;
  }
}

/* ---------- Horizontal rules ----------------------------------- */
hr {
  border: 0;
  border-top: 1px solid var(--quote-bg);
  margin: 2.5em 0;
  position: relative;
  text-align: center;
}
hr::after {
  content: "◆";
  position: absolute;
  top: -0.75em;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg);
  padding: 0 1em;
  color: var(--keel-amber);
  font-size: 0.7em;
}

/* ---------- Landing hero --------------------------------------- */
.keel-hero {
  text-align: center;
  padding: 1.5rem 1rem 2.5rem;
  margin: -1rem 0 0;
  position: relative;
  isolation: isolate;
}
/* Soft amber glow behind the logo. */
.keel-hero::before {
  content: "";
  position: absolute;
  z-index: -1;
  top: -10%;
  left: 50%;
  transform: translateX(-50%);
  width: min(560px, 90%);
  height: 320px;
  background: radial-gradient(closest-side, rgba(255, 184, 74, 0.16), transparent 75%);
  pointer-events: none;
}
.keel-hero-logo {
  width: 92px;
  height: 92px;
  margin: 0 auto 1rem;
  display: block;
  filter: drop-shadow(0 6px 18px rgba(0, 0, 0, 0.35));
}
.keel-version-pill {
  display: inline-block;
  font-family: var(--keel-font-mono);
  font-size: 0.72em;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--keel-amber);
  background: rgba(255, 184, 74, 0.12);
  border: 1px solid rgba(255, 184, 74, 0.35);
  border-radius: 999px;
  padding: 4px 12px;
  margin-bottom: 1rem;
  text-decoration: none;
  transition: background 140ms;
}
.keel-version-pill:hover { background: rgba(255, 184, 74, 0.2); border-bottom: 1px solid rgba(255, 184, 74, 0.35); }
.keel-light .keel-version-pill, .light .keel-version-pill, .rust .keel-version-pill {
  color: var(--keel-burnt);
  background: rgba(210, 105, 26, 0.1);
  border-color: rgba(210, 105, 26, 0.3);
}
.content .keel-hero-title {
  font-family: var(--keel-font-display);
  font-size: clamp(2.6em, 6vw, 3.6em);
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.02em;
  margin: 0.2em 0 0.15em;
  padding: 0 0 0.08em;
  border: none;
  background: linear-gradient(135deg, var(--keel-amber), var(--keel-burnt));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.keel-hero-tagline {
  font-size: 1.2em;
  color: var(--keel-fog);
  max-width: 34ch;
  margin: 0 auto 1.6rem;
  line-height: 1.6;
}
.keel-hero-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
}
.keel-btn {
  display: inline-block;
  font-family: var(--keel-font-body);
  font-size: 0.95em;
  font-weight: 600;
  padding: 0.6em 1.3em;
  border-radius: 8px;
  border: 1px solid var(--table-border-color);
  color: var(--fg);
  background: var(--quote-bg);
  text-decoration: none;
  transition: transform 120ms, border-color 120ms, background 120ms, box-shadow 120ms;
}
.keel-btn:hover {
  transform: translateY(-1px);
  border-color: var(--keel-amber);
  border-bottom: 1px solid var(--keel-amber);
}
.keel-btn-primary {
  background: linear-gradient(135deg, var(--keel-amber), var(--keel-burnt));
  color: var(--keel-onyx);
  border-color: transparent;
}
.keel-btn-primary:hover {
  border-bottom-color: transparent;
  box-shadow: 0 8px 22px rgba(255, 184, 74, 0.28);
  color: var(--keel-onyx);
}

/* ---------- Feature cards -------------------------------------- */
.keel-features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin: 2rem 0 3rem;
}
.keel-feature {
  border: 1px solid var(--table-border-color);
  border-radius: 12px;
  padding: 1.3rem 1.4rem;
  background: var(--quote-bg);
  transition: transform 140ms, border-color 140ms;
}
.keel-feature:hover { transform: translateY(-2px); border-color: var(--keel-amber); }
.keel-feature-icon {
  width: 30px;
  height: 30px;
  color: var(--keel-amber);
  margin-bottom: 0.7rem;
}
.keel-light .keel-feature-icon, .light .keel-feature-icon, .rust .keel-feature-icon { color: var(--keel-burnt); }
.content .keel-feature h3 {
  font-size: 1.08em;
  margin: 0 0 0.4rem;
}
.keel-feature p {
  font-size: 0.92em;
  color: var(--keel-fog);
  margin: 0;
  line-height: 1.55;
}
.keel-feature code {
  background: var(--bg);
  color: var(--inline-code-color);
}

/* ---------- Keyboard keys -------------------------------------- */
kbd {
  font-family: var(--keel-font-mono);
  font-size: 0.82em;
  background: var(--quote-bg);
  border: 1px solid var(--table-border-color);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0.1em 0.5em;
  color: var(--fg);
}
