/* ============================================================
   STATIC "book-of-books" terminal menu
   Distilled from book.rymcg.tech's Hugo "terminal" theme.
   Drop this file + menu.js + site-menu.js into any collection of
   plain .html files -- no build step, no server-side templating.
   ============================================================ */

/* ---------- palettes -----------------------------------------------
   Everything below this block is written against these variables only,
   so a palette is nothing but a set of seven colors. The active one is
   chosen by data-theme on <html>; menu.js flips that attribute (and
   remembers your choice) when you click the ◐ button in the sidebar.
   Add more palettes by copying either block below.                   */

:root,                              /* default = amber, dark */
:root[data-theme="amber"]{
  --bg:        #0d0e0c;
  --panel:     #131512;
  --fg:        #eed2a7;
  --fg-dim:    #6f776b;
  --fg-bright: #d6ddd0;
  --accent:    #dfa22c;
  --rule:      #2a2d27;
  --shadow:    rgba(0,0,0,.5);
  --scrim:     rgba(4,5,4,.74);
  color-scheme: dark;
}

/* black on white: paper, not a screen. The accent is darkened well
   past the amber above so it still passes contrast on white. */
:root[data-theme="lite"]{
  --bg:        #ffffff;
  --panel:     #f3f3f0;
  --fg:        #1b1b19;
  --fg-dim:    #6a6e67;
  --fg-bright: #000000;
  --accent:    #9a5200;
  --rule:      #d8d8d2;
  --shadow:    rgba(0,0,0,.22);
  --scrim:     rgba(70,70,66,.55);
  color-scheme: light;
}

:root{
  --col: 74ch;                      /* reading width of the text column */
  --gutter: clamp(1.25rem, 3vw, 3rem);  /* space either side of it */
  --font-mono: "Inconsolata", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --font-read: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

*{ box-sizing:border-box; }
html,body{ margin:0; }
body{
  min-height:100vh;
  background:var(--bg);
  color:var(--fg);
  font-family:var(--font-mono);
  line-height:1.7;
}
a{ color:inherit; }

/* ---------- layout: sidebar + reading column ---------------------- */
.wrap{ display:grid; grid-template-columns:30ch minmax(0,1fr); min-height:100vh; }

/* ---------- sidebar: book-of-books tree ---------------------------- */
.sidebar{
  border-right:1px solid var(--rule);
  padding:.85rem 1.1rem 1.4rem;
  position:sticky; top:0; align-self:start; height:100vh; overflow:hidden;
  display:flex; flex-direction:column;
  background:var(--panel);
  font-size:.82rem;
}
.sidebar .brand{ color:var(--accent); font-weight:600; margin-bottom:.2rem; flex:none; }
.sidebar .brand a{ color:inherit; text-decoration:none; }
.sidebar .brand a:hover{ color:var(--fg-bright); }
.sidebar .tag{ color:var(--fg-dim); font-size:.85em; margin-bottom:1.3rem; flex:none; }

.tree{ list-style:none; margin:0; padding:0;
  flex:1 1 auto; min-height:0; overflow:auto; }
.tree li{ overflow-wrap:anywhere; }
.tree a{ color:var(--fg); text-decoration:none; display:block; padding:1px 0; }
.tree a:hover{ color:var(--accent); }

/* top-level "book" entries: ▸ closed / ▾ open */
.tree > li.book::before{ content:"▸ "; color:var(--fg-dim); }
.tree > li.book.open::before{ content:"▾ "; color:var(--accent); }
.tree > li.book.open > a{ color:var(--fg-bright); }

/* nested "chapter" list, indented with a rule down the left edge */
.tree .chapters{ list-style:none; margin:.1rem 0 .7rem; padding:0 0 0 1.6ch; border-left:1px solid var(--rule); }
.tree .chapters li::before{ content:none; }
.tree .chapters a::before{ content:"· "; color:var(--fg-dim); }
.tree .chapters a.active{ color:var(--accent); }
.tree .chapters a.active::before{ content:"› "; color:var(--accent); }

/* third-level "section" list -- same treatment, one notch deeper */
.tree .sections{ list-style:none; margin:.1rem 0 .4rem; padding:0 0 0 1.6ch; border-left:1px solid var(--rule); }
.tree .sections a::before{ content:"· "; color:var(--fg-dim); }
.tree .sections a.active{ color:var(--accent); }
.tree .sections a.active::before{ content:"› "; color:var(--accent); }

/* ---- per-page "#" outline ------------------------------------------
   menu.js renders <ul class="outline"> in two places: inside the tree,
   right after the link for whichever entry is the page you're on, and
   inside the .outline-panel that the "#" button opens on narrow
   screens. These rules cover both. Marked with "#" instead of "·" so
   in-page anchors read differently from page links. Depth classes
   d1/d2/d3 are relative to the page's shallowest heading; add a .d4
   rule if you list four levels.
   (:is() here just raises specificity enough to beat the "·" marker
   inherited from .tree .chapters / .tree .sections.) */
:is(.tree, .outline-panel) .outline{
  list-style:none; margin:.15rem 0 .5rem; padding:0 0 0 1.6ch;
  border-left:1px solid var(--rule); font-size:.94em;
}
:is(.tree, .outline-panel) .outline li{ padding:0; overflow-wrap:anywhere; }
:is(.tree, .outline-panel) .outline a{
  color:var(--fg-dim); text-decoration:none; display:block; padding:1px 0;
}
:is(.tree, .outline-panel) .outline a::before{ content:"# "; color:var(--fg-dim); }
:is(.tree, .outline-panel) .outline a:hover{ color:var(--accent); }
/* .here is set by menu.js as you scroll */
:is(.tree, .outline-panel) .outline a.here{ color:var(--accent); }
:is(.tree, .outline-panel) .outline a.here::before{ content:"# "; color:var(--accent); }
:is(.tree, .outline-panel) .outline .d2{ padding-left:1.6ch; }
:is(.tree, .outline-panel) .outline .d3{ padding-left:3.2ch; }

/* bottom action row + build date, pinned under the tree */
.sidebar-actions{ flex:none; margin-top:1rem; padding-top:1rem; border-top:1px solid var(--rule);
  display:flex; flex-wrap:wrap; gap:.55rem; }
/* used for both <a> (git) and <button> (◐ palette switch) */
.iconbtn{ display:inline-flex; align-items:center; justify-content:center;
  width:2.1rem; height:2.1rem; padding:0; border:1px solid var(--rule); border-radius:2px;
  color:var(--fg-dim); text-decoration:none;
  font:inherit; background:transparent; cursor:pointer; }
.iconbtn:hover{ color:var(--accent); border-color:var(--accent); }
.build-date{ flex:none; margin-top:.6rem; color:var(--fg-dim); font-size:.62rem; }
.build-date .lbl{ color:var(--accent); }

/* ---------- top bar: terminal-prompt breadcrumb -------------------- */
.topbar{
  border-bottom:1px solid var(--rule); padding:.7rem 8.25rem .7rem 2rem;
  color:var(--fg-dim); display:flex; gap:1.5ch; align-items:center; flex-wrap:wrap;
  background:var(--panel); position:sticky; top:0; z-index:10;
}
.topbar .prompt{ color:var(--accent); }
.topbar .prompt .at{ color:var(--fg-dim); }
.topbar .username{ font-weight:700; }
.topbar a{ text-decoration:none; }
.topbar .path .pseg:hover{ color:var(--accent); }
.topbar .pcur{ color:var(--fg-bright); }

/* ---------- fixed top-right cluster: prev / # / next --------------- */
.topnav{ position:fixed; top:.5rem; right:.55rem; z-index:70; display:flex; gap:.4rem; }
.navbtn{
  width:2.1rem; height:2.1rem; flex:none; padding:0;
  display:inline-flex; align-items:center; justify-content:center;
  font:inherit; font-weight:700; font-size:1.2rem; line-height:1;
  color:var(--fg-dim); background:var(--panel); text-decoration:none;
  border:1px solid var(--rule); border-radius:3px; cursor:pointer;
}
.navbtn:hover{ color:var(--accent); border-color:var(--accent); }
.navbtn[aria-disabled="true"]{ opacity:.32; pointer-events:none; }
.navprev::before{ content:"\2039"; }
.navnext::before{ content:"\203A"; }

/* ---------- narrow-screen "#" outline button + drop-panel ----------
   Above the sidebar breakpoint the outline already lives in the always-
   visible tree, so both of these stay hidden; the media query at the
   bottom of this file switches them on. */
.navoutline{ display:none; }
.navoutline::before{ content:"#"; }
.navoutline[aria-expanded="true"]{
  color:var(--bg); background:var(--accent); border-color:var(--accent);
}
/* Absolute inside .topnav (itself position:fixed), so the panel hangs
   directly under the button cluster. */
.outline-panel{
  display:none; position:absolute; top:2.6rem; right:0;
  width:min(84vw, 36ch); max-height:min(68vh, 34rem); overflow:auto;
  padding:.7rem .95rem .8rem;
  font-size:.82rem; text-align:left;
  background:var(--panel); border:1px solid var(--accent); border-radius:3px;
  box-shadow:0 10px 26px var(--shadow);
}
.outline-panel .tag{ color:var(--fg-dim); font-size:.85em; margin-bottom:.45rem; }
/* the panel is the outline's whole reason to exist -- no left rule */
.outline-panel .outline{ margin:0; padding:0; border-left:0; font-size:1em; }


/* ---------- menu toggle (mobile) ----------------------------------- */
/* Pure-CSS checkbox hack: the sidebar opens/closes with NO javascript.
   #navtoggle:checked ~ selector rules below do all the work. */
.nav-checkbox{ position:fixed; top:0; left:0; width:1px; height:1px; margin:-1px; padding:0;
  border:0; overflow:hidden; clip:rect(0 0 0 0); white-space:nowrap; }
.menutoggle{ display:none; }
.menutoggle::before{ content:"\25CB"; }                        /* ○ closed */
#navtoggle:checked ~ .menutoggle::before{ content:"\25CF"; }   /* ● open   */
#navtoggle:checked ~ .menutoggle{ color:var(--bg); background:var(--accent); border-color:var(--accent); }
.nav-backdrop{ display:none; }

/* ---------- reading column ------------------------------------------ */
/* The column keeps its --col reading width, but sits just to the right
   of the sidebar instead of being centered in whatever space is left --
   centering on a wide monitor pushed the text into the middle with huge
   gutters on both sides. --gutter caps how wide those get; the narrow
   layout below re-centers, since there's no sidebar to sit next to. */
main{ display:flex; justify-content:flex-start; padding:2rem var(--gutter); }
.content{ width:100%; max-width:var(--col); font-family:var(--font-read); }
.content h1,.content h2,.content h3,.content h4{ font-family:var(--font-mono); color:var(--fg-bright); }
/* clear the sticky topbar when jumping to an outline anchor */
.content h1,.content h2,.content h3,.content h4{ scroll-margin-top:4.5rem; }
.content a{ color:var(--accent); }

/* ============ narrow screens: off-canvas sidebar ===================
   Breakpoint = sidebar (30ch) + reading column (74ch) + two gutters,
   plus a little slack. Tightening the gutters above let this come down
   from 1352px, so the two-column layout survives on smaller screens. */
@media (max-width:1080px){
  .wrap{ grid-template-columns:minmax(0,1fr); }
  /* no sidebar to sit beside, so center the column again */
  main{ justify-content:center; }
  .menutoggle{
    display:inline-flex; align-items:center; justify-content:center;
    position:fixed; top:.5rem; left:.55rem; z-index:70;
    width:2.1rem; height:2.1rem; padding:0;
    font:inherit; font-weight:700; font-size:1.4rem; line-height:1; color:var(--accent);
    background:var(--panel); border:1px solid var(--rule); border-radius:3px; cursor:pointer;
  }
  .menutoggle:hover{ color:var(--fg-bright); border-color:var(--accent); }
  #navtoggle:checked ~ .topnav{ opacity:.32; pointer-events:none; }
  /* the tree is off-canvas now, so surface the outline as a "#" button */
  .navoutline{ display:inline-flex; }
  .outline-panel:not([hidden]){ display:block; }
  /* ...and drop the copy nested in the tree, so the off-canvas menu
     stays a plain list of pages */
  .tree .outline{ display:none; }
  .topbar{ padding-left:4rem; }
  .sidebar{ padding-top:.55rem; }
  .sidebar .brand, .sidebar .tag{ padding-left:2rem; }
  .sidebar{
    position:fixed; z-index:60; top:0; left:0;
    width:min(86vw, 34ch); height:100vh; height:100dvh;
    display:none; border-right:1px solid var(--accent);
  }
  #navtoggle:checked ~ .wrap .sidebar{ display:flex; }
  .nav-backdrop{ display:none; position:fixed; inset:0; z-index:55; background:var(--scrim); }
  #navtoggle:checked ~ .wrap .nav-backdrop{ display:block; }
}
