/* ============================================================================
 * Amiga KB — Workbench palette + autodoc-flavoured typography.
 *
 * Three sections:
 *   1. Palette tokens (Amiga Workbench light/dark via prefers-color-scheme)
 *   2. Layout (88ch width, compact header, content-driven footer)
 *   3. Per-element typography (mono, numbered headings, code, tables, search)
 *
 * Palette design notes:
 *   - All colours derive from three HSL axes (bg / accent / hi) so
 *     dark/light is one variable swap, not a parallel palette.
 *   - accent = Amiga blue (links, focus rings, navbar accents)
 *   - hi     = Amiga orange (function/type highlights, search matches)
 *   - monospace prose because the autodoc reference is mostly C
 *     signatures, struct tables, and macro names.
 * ========================================================================== */

/* ----- 1. palette ----- */

:root {
  --bg-h: 210;  --bg-s: 30%;  --bg-l: 98%;
  --accent-h: 215;  --accent-s: 75%;  --accent-l: 50%;
  --hi-h: 28;  --hi-s: 100%;  --hi-l: 50%;

  --bg-primary:   hsl(var(--bg-h) var(--bg-s) var(--bg-l));
  --bg-secondary: hsl(var(--bg-h) var(--bg-s) calc(var(--bg-l) - 4%));
  --bg-code:      hsl(var(--bg-h) var(--bg-s) calc(var(--bg-l) - 6%));
  --border:       hsl(var(--bg-h) var(--bg-s) calc(var(--bg-l) - 14%));
  --text-primary: hsl(var(--bg-h) var(--bg-s) clamp(8%, calc(100% - var(--bg-l)), 92%));
  --text-muted:   hsl(var(--bg-h) var(--bg-s) clamp(30%, calc(85% - var(--bg-l)), 75%));
  --accent:       hsl(var(--accent-h) var(--accent-s) var(--accent-l));
  --hi:           hsl(var(--hi-h) var(--hi-s) var(--hi-l));

  --font-prose: ui-monospace, "SF Mono", "Cascadia Code", Consolas,
                "DejaVu Sans Mono", monospace;
  --font-size:  0.92rem;
  --line:       1.6;

  /* bind the same tokens onto bootstrap so its components follow us */
  --bs-body-bg: var(--bg-primary);
  --bs-body-color: var(--text-primary);
  --bs-secondary-bg: var(--bg-secondary);
  --bs-tertiary-bg: var(--bg-code);
  --bs-border-color: var(--border);
  --bs-primary: var(--accent);
  --bs-link-color: var(--accent);
  --bs-link-hover-color: var(--accent);
  --bs-emphasis-color: var(--text-primary);

  /* the page reads at this width regardless of viewport */
  --container: 88ch;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-h: 215;  --bg-s: 55%;  --bg-l: 22%;
    --accent-h: 195;  --accent-s: 80%;  --accent-l: 60%;
    --hi-h: 28;  --hi-s: 100%;  --hi-l: 60%;
  }
}

/* ----- 2. layout ----- */

html { -webkit-text-size-adjust: 100%; }

body {
  font: var(--font-size)/var(--line) var(--font-prose);
  background: var(--bg-primary);
  color: var(--text-primary);
  display: grid;
  grid-template-rows: auto 1fr auto;
  justify-items: center;
}

/* mkdocs's <main role="main"> col-md-9 — constrain to 88ch and center */
[role="main"] {
  width: 100%;
  max-width: var(--container);
  padding: 1rem 2rem;
}

/* mobile: same as desktop — let the dropdown menu reappear if needed */
@media (max-width: 991px) {
  .navbar-collapse > .navbar-nav:first-child { display: flex; flex-direction: column; }
  .navbar-brand { font-size: 0.9rem; }
}

/* hide mkdocs's prev/next nav from the top — keep only search */
.navbar .navbar-nav:last-child a[rel="prev"],
.navbar .navbar-nav:last-child a[rel="next"] { display: none; }

/* sidebar lives in col-md-3 — strip the heavy chrome and let it be a tree.
   mkdocs wraps the TOC in a .card.bg-body-tertiary which makes a stark
   white panel; we just want a plain vertical list of links. */
.col-md-3.bs-sidebar {
  padding: 1rem 1.5rem;
  font-size: 0.85rem;
}
.bs-sidebar .navbar-brand,
.bs-sidebar .navbar-header { display: none; }
/* bootstrap's .bg-body-tertiary sets background-color with !important,
   so we need !important here too to cancel the card chrome. */
.bs-sidebar #toc-collapse,
.bs-sidebar #toc-collapse.card,
.bs-sidebar .card,
.bs-sidebar .bg-body-tertiary {
  background: transparent !important;
  border: none !important;
}
.bs-sidebar .nav-link {
  padding: 0.2rem 0.5rem;
  color: var(--text-muted);
  border-bottom: none;
}
.bs-sidebar .nav-link:hover { color: var(--accent); }
.bs-sidebar .nav-link.active,
.bs-sidebar .dropdown-item.active {
  color: var(--accent);
  font-weight: 700;
}
  padding: 1rem 1.5rem;
  font-size: 0.85rem;
}
.bs-sidebar .navbar-brand,
.bs-sidebar .navbar-header { display: none; }
.bs-sidebar #toc-collapse.card,
.bs-sidebar .card,
.bs-sidebar .bg-body-tertiary {
  background: transparent;
  border: none;
}
.bs-sidebar .nav-link {
  padding: 0.2rem 0.5rem;
  color: var(--text-muted);
  border-bottom: none;
}
.bs-sidebar .nav-link:hover { color: var(--accent); }
.bs-sidebar .nav-link.active,
.bs-sidebar .dropdown-item.active {
  color: var(--accent);
  font-weight: 700;
}
  padding: 1rem 1.5rem;
.col-md-3.bs-sidebar {
  padding: 1rem 1.5rem;
  font-size: 0.85rem;
}
.bs-sidebar .navbar-brand { display: none; }

/* Compact header. Brand is the only nav text; sections live in the sidebar. */
.navbar {
  width: 100%;
  border-bottom: 1px solid var(--border);
  background: var(--bg-primary) !important;
  padding: 0.4rem 0;
  font-size: 0.85rem;
}
.navbar > .container {
  max-width: var(--container);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 2rem;
}
.navbar-brand {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-primary) !important;
  padding: 0;
  margin: 0;
}

/* Hide the dropdown nav (home link + per-section dropdowns).
   The sidebar is the single source of truth for section navigation. */
.navbar-collapse > .navbar-nav:first-child { display: none; }

/* Keep the search button visible. mkdocs puts it in a second .navbar-nav. */
.navbar .navbar-nav:last-child { display: flex; align-items: center; gap: 0.5rem; margin-left: auto; }
.navbar .navbar-nav:last-child .nav-link {
  color: var(--text-muted) !important;
  padding: 0.2rem 0.6rem;
  border-bottom: none;
}
.navbar .navbar-nav:last-child .nav-link:hover { color: var(--accent) !important; }

/* mobile: same as desktop — let the dropdown menu reappear if needed */
@media (max-width: 991px) {
  .navbar-collapse > .navbar-nav:first-child { display: flex; flex-direction: column; }
  .navbar-brand { font-size: 0.9rem; }
}

/* footer: monospace, muted, single line */
.md-copyright, .built-with, .site-footer { display: none !important; }
footer, .footer {
  width: 100%;
  max-width: var(--container);
  border-top: 1px solid var(--border);
  padding: 1rem 2rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* ----- 3. typography ----- */

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-prose);
  font-weight: 700;
}
h1 { font-size: 1.3rem; margin: 1.25rem 0 0.75rem; }
h2 { font-size: 1.05rem; margin: 1.5rem 0 0.6rem; counter-reset: h3; counter-increment: h2; }
h3 { font-size: 0.95rem; margin: 1.25rem 0 0.5rem; counter-increment: h3; }
h2::before { content: counter(h2) ". "; color: var(--text-muted); }
h3::before { content: counter(h2) "." counter(h3) ". "; color: var(--text-muted); }

p, ul, ol, pre, table, blockquote { margin: 0 0 1rem; }
ul, ol { padding-left: 1.5rem; }

a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dotted;
}
a:hover { border-bottom-style: solid; }

/* inline code: orange-on-bg for `function` and `type` highlights */
code, pre { font-family: var(--font-prose); }
:not(pre) > code {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 0.25rem;
  padding: 0.1em 0.35em;
  font-size: 0.88em;
  color: var(--hi);
}

/* code blocks: padded, never overflowing */
pre {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.75rem 1rem;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-x: auto;
}
pre code { background: none; border: none; padding: 0; font-size: inherit; }

blockquote {
  border-left: 3px solid var(--border);
  background: var(--bg-secondary);
  border-radius: 0 0.5rem 0.5rem 0;
  padding: 0.5rem 1rem;
  color: var(--text-muted);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}
th, td { padding: 0.35rem 0.6rem; border-bottom: 1px solid var(--border); text-align: left; }
th { border-bottom: 2px solid currentColor; font-weight: 700; }

/* search highlight inside <mark> elements (mkdocs's lunr integration) */
mark {
  background: var(--hi);
  color: var(--text-primary);
  padding: 0 0.1em;
  border-radius: 0.15em;
}

img { max-width: 100%; height: auto; }
.muted { color: var(--text-muted); font-size: 0.85em; }

/* focus ring — accessible, doesn't depend on bootstrap's default */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ----- print ----- */
@media print {
  body { background: #fff; color: #000; }
  .navbar, .bs-sidebar, .search-modal, nav, footer { display: none !important; }
  [role="main"] { max-width: none; padding: 0; }
  a { color: #000; border-bottom: none; }
  a[href]::after { content: " (" attr(href) ")"; font-size: 0.8em; color: gray; }
}
