/* bindery shared stylesheet.
   Every color/radius comes from CSS variables injected per book by build.py.
   Edit here once, every book updates. */

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: 'Iowan Old Style', 'Palatino Linotype', Palatino, Charter, Georgia, serif;
  font-size: 17px; line-height: 1.65;
}

/* ---------- book page layout ---------- */
.layout { display: grid; grid-template-columns: 280px minmax(0,1fr); max-width: 1180px; margin: 0 auto; }
nav.toc {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  padding: 2.2rem 1.4rem 2.2rem 1.6rem; border-right: 1px solid var(--rule);
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif; font-size: .82rem;
}
nav.toc .home { font-size: .75rem; font-weight: 700; margin-bottom: 1.6rem; border-left: none; padding-left: 0; }
nav.toc .booktag { font-size: .68rem; letter-spacing: .14em; text-transform: uppercase; color: var(--accent); font-weight: 700; margin-bottom: .4rem; }
nav.toc .booktitle { font-weight: 800; font-size: 1rem; line-height: 1.3; margin-bottom: 1.4rem; color: var(--ink); }
nav.toc a { display: block; color: var(--muted); text-decoration: none; padding: .32rem .55rem; border-left: 2px solid transparent; border-radius: 0 var(--radius) var(--radius) 0; line-height: 1.35; }
nav.toc a:hover { color: var(--ink); background: var(--accent-soft); }
nav.toc a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
nav.toc a.active { color: var(--accent); border-left-color: var(--accent); background: var(--accent-soft); font-weight: 600; }
nav.toc .num { display: inline-block; width: 1.5em; color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums; }

main { padding: 3rem 3.4rem 6rem; max-width: 78ch; }
header.bookhead { border-bottom: 3px solid var(--ink); padding-bottom: 1.6rem; margin-bottom: 2.6rem; }
header.bookhead .eyebrow { font-family: system-ui, sans-serif; font-size: .72rem; letter-spacing: .18em; text-transform: uppercase; color: var(--accent); font-weight: 700; }
header.bookhead h1 { font-size: 2.5rem; line-height: 1.12; margin: .5rem 0 .6rem; letter-spacing: -.015em; }
header.bookhead .subtitle { color: var(--muted); font-style: italic; margin: 0; }

h2 { font-size: 1.55rem; line-height: 1.25; margin: 3.2rem 0 1rem; padding-top: 2.2rem; border-top: 1px solid var(--rule); letter-spacing: -.01em; }
h2:first-of-type { border-top: none; padding-top: 0; }
h2 .chnum { font-family: system-ui, sans-serif; font-size: .85rem; color: var(--accent); font-weight: 800; letter-spacing: .1em; display: block; margin-bottom: .2rem; }
h3 { font-family: system-ui, -apple-system, 'Segoe UI', sans-serif; font-size: .95rem; letter-spacing: .04em; text-transform: uppercase; color: var(--accent); margin: 2rem 0 .6rem; }

p { margin: 0 0 1.05rem; }
a { color: var(--accent); }
ul, ol { padding-left: 1.35rem; margin: 0 0 1.05rem; }
li { margin-bottom: .4rem; }
hr { border: none; border-top: 1px solid var(--rule); margin: 2.5rem 0; }
blockquote { margin: 1.2rem 0; padding: .2rem 1.1rem; border-left: 3px solid var(--accent); color: var(--muted); }

code { font-family: ui-monospace, 'Cascadia Code', 'JetBrains Mono', Menlo, Consolas, monospace; font-size: .84em; background: var(--accent-soft); padding: .12em .35em; border-radius: 4px; }
.codehilite { background: var(--code-bg); color: var(--code-ink); border-radius: var(--radius); margin: 1.2rem 0; overflow-x: auto; border: 1px solid var(--rule); }
.codehilite pre { margin: 0; padding: 1rem 1.2rem; font-size: .82rem; line-height: 1.55; }
.codehilite code { background: none; padding: 0; font-size: inherit; color: inherit; }

table { border-collapse: collapse; width: 100%; margin: 1.3rem 0; font-family: system-ui, -apple-system, 'Segoe UI', sans-serif; font-size: .86rem; }
th { text-align: left; font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); border-bottom: 2px solid var(--ink); padding: .5rem .7rem; }
td { border-bottom: 1px solid var(--rule); padding: .55rem .7rem; vertical-align: top; }
tr:nth-child(even) td { background: var(--panel); }
td code { white-space: nowrap; }

footer { margin-top: 4rem; padding-top: 1.4rem; border-top: 3px solid var(--ink); font-family: system-ui, sans-serif; font-size: .82rem; display: flex; justify-content: space-between; gap: 1rem; }
footer a { text-decoration: none; font-weight: 600; }

/* ---------- bookshelf (index) ---------- */
.shelf-wrap { max-width: 1100px; margin: 0 auto; padding: 3.5rem 1.5rem 6rem;
  --accent:#1B2432; --accent-soft:#ECEEF2; --ink:#1B2432; --muted:#5A6675; --rule:#D9DDE4; --bg:#F7F8FA; }
.shelf-head { border-bottom: 3px solid var(--ink); padding-bottom: 1.4rem; margin-bottom: 2.4rem; }
.shelf-head .eyebrow { font-family: system-ui, sans-serif; font-size: .72rem; letter-spacing: .18em; text-transform: uppercase; font-weight: 700; color: var(--muted); }
.shelf-head h1 { font-size: 2.6rem; margin: .4rem 0 .4rem; letter-spacing: -.015em; }
.shelf-head p { color: var(--muted); font-style: italic; margin: 0; }
.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1.4rem; }
.book { display: grid; grid-template-columns: 52px 1fr; text-decoration: none; color: var(--ink);
  border: 1px solid var(--rule); border-radius: var(--r, 6px); overflow: hidden; background: #fff;
  transition: transform .15s ease, box-shadow .15s ease; }
.book:hover { transform: translateY(-3px); box-shadow: 0 10px 24px rgba(20,30,45,.10); }
.book:focus-visible { outline: 3px solid var(--c); outline-offset: 2px; }
.book .spine { background: var(--c); color: #fff; writing-mode: vertical-rl;
  display: flex; align-items: center; justify-content: center;
  font-family: system-ui, sans-serif; font-weight: 800; letter-spacing: .2em; font-size: .8rem; padding: 1rem 0; }
.book .cover { padding: 1.2rem 1.3rem 1.1rem; }
.book .tag { font-family: system-ui, sans-serif; font-size: .66rem; letter-spacing: .14em; text-transform: uppercase; font-weight: 700; color: var(--c); }
.book h2 { font-size: 1.25rem; line-height: 1.25; margin: .35rem 0 .45rem; border: none; padding: 0; }
.book p { font-size: .88rem; color: var(--muted); font-style: italic; margin: 0 0 .8rem; }
.book .meta { font-family: system-ui, sans-serif; font-size: .72rem; font-weight: 600; color: var(--muted);
  border-top: 1px solid var(--rule); padding-top: .6rem; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  nav.toc { position: static; height: auto; border-right: none; border-bottom: 1px solid var(--rule); }
  main { padding: 2rem 1.3rem 4rem; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .book { transition: none; }
}

pre { line-height: 125%; }
td.linenos .normal { color: #aaaaaa; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: #aaaaaa; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.codehilite .hll { background-color: #404040 }
.codehilite { background: #202020; color: #D0D0D0 }
.codehilite .c { color: #ABABAB; font-style: italic } /* Comment */
.codehilite .err { color: #A61717; background-color: #E3D2D2 } /* Error */
.codehilite .esc { color: #D0D0D0 } /* Escape */
.codehilite .g { color: #D0D0D0 } /* Generic */
.codehilite .k { color: #6EBF26; font-weight: bold } /* Keyword */
.codehilite .l { color: #D0D0D0 } /* Literal */
.codehilite .n { color: #D0D0D0 } /* Name */
.codehilite .o { color: #D0D0D0 } /* Operator */
.codehilite .x { color: #D0D0D0 } /* Other */
.codehilite .p { color: #D0D0D0 } /* Punctuation */
.codehilite .ch { color: #ABABAB; font-style: italic } /* Comment.Hashbang */
.codehilite .cm { color: #ABABAB; font-style: italic } /* Comment.Multiline */
.codehilite .cp { color: #FF3A3A; font-weight: bold } /* Comment.Preproc */
.codehilite .cpf { color: #ABABAB; font-style: italic } /* Comment.PreprocFile */
.codehilite .c1 { color: #ABABAB; font-style: italic } /* Comment.Single */
.codehilite .cs { color: #E50808; font-weight: bold; background-color: #520000 } /* Comment.Special */
.codehilite .gd { color: #FF3A3A } /* Generic.Deleted */
.codehilite .ge { color: #D0D0D0; font-style: italic } /* Generic.Emph */
.codehilite .ges { color: #D0D0D0; font-weight: bold; font-style: italic } /* Generic.EmphStrong */
.codehilite .gr { color: #FF3A3A } /* Generic.Error */
.codehilite .gh { color: #FFF; font-weight: bold } /* Generic.Heading */
.codehilite .gi { color: #589819 } /* Generic.Inserted */
.codehilite .go { color: #CCC } /* Generic.Output */
.codehilite .gp { color: #AAA } /* Generic.Prompt */
.codehilite .gs { color: #D0D0D0; font-weight: bold } /* Generic.Strong */
.codehilite .gu { color: #FFF; text-decoration: underline } /* Generic.Subheading */
.codehilite .gt { color: #FF3A3A } /* Generic.Traceback */
.codehilite .kc { color: #6EBF26; font-weight: bold } /* Keyword.Constant */
.codehilite .kd { color: #6EBF26; font-weight: bold } /* Keyword.Declaration */
.codehilite .kn { color: #6EBF26; font-weight: bold } /* Keyword.Namespace */
.codehilite .kp { color: #6EBF26 } /* Keyword.Pseudo */
.codehilite .kr { color: #6EBF26; font-weight: bold } /* Keyword.Reserved */
.codehilite .kt { color: #6EBF26; font-weight: bold } /* Keyword.Type */
.codehilite .ld { color: #D0D0D0 } /* Literal.Date */
.codehilite .m { color: #51B2FD } /* Literal.Number */
.codehilite .s { color: #ED9D13 } /* Literal.String */
.codehilite .na { color: #BBB } /* Name.Attribute */
.codehilite .nb { color: #2FBCCD } /* Name.Builtin */
.codehilite .nc { color: #71ADFF; text-decoration: underline } /* Name.Class */
.codehilite .no { color: #40FFFF } /* Name.Constant */
.codehilite .nd { color: #FFA500 } /* Name.Decorator */
.codehilite .ni { color: #D0D0D0 } /* Name.Entity */
.codehilite .ne { color: #BBB } /* Name.Exception */
.codehilite .nf { color: #71ADFF } /* Name.Function */
.codehilite .nl { color: #D0D0D0 } /* Name.Label */
.codehilite .nn { color: #71ADFF; text-decoration: underline } /* Name.Namespace */
.codehilite .nx { color: #D0D0D0 } /* Name.Other */
.codehilite .py { color: #D0D0D0 } /* Name.Property */
.codehilite .nt { color: #6EBF26; font-weight: bold } /* Name.Tag */
.codehilite .nv { color: #40FFFF } /* Name.Variable */
.codehilite .ow { color: #6EBF26; font-weight: bold } /* Operator.Word */
.codehilite .pm { color: #D0D0D0 } /* Punctuation.Marker */
.codehilite .w { color: #666 } /* Text.Whitespace */
.codehilite .mb { color: #51B2FD } /* Literal.Number.Bin */
.codehilite .mf { color: #51B2FD } /* Literal.Number.Float */
.codehilite .mh { color: #51B2FD } /* Literal.Number.Hex */
.codehilite .mi { color: #51B2FD } /* Literal.Number.Integer */
.codehilite .mo { color: #51B2FD } /* Literal.Number.Oct */
.codehilite .sa { color: #ED9D13 } /* Literal.String.Affix */
.codehilite .sb { color: #ED9D13 } /* Literal.String.Backtick */
.codehilite .sc { color: #ED9D13 } /* Literal.String.Char */
.codehilite .dl { color: #ED9D13 } /* Literal.String.Delimiter */
.codehilite .sd { color: #ED9D13 } /* Literal.String.Doc */
.codehilite .s2 { color: #ED9D13 } /* Literal.String.Double */
.codehilite .se { color: #ED9D13 } /* Literal.String.Escape */
.codehilite .sh { color: #ED9D13 } /* Literal.String.Heredoc */
.codehilite .si { color: #ED9D13 } /* Literal.String.Interpol */
.codehilite .sx { color: #FFA500 } /* Literal.String.Other */
.codehilite .sr { color: #ED9D13 } /* Literal.String.Regex */
.codehilite .s1 { color: #ED9D13 } /* Literal.String.Single */
.codehilite .ss { color: #ED9D13 } /* Literal.String.Symbol */
.codehilite .bp { color: #2FBCCD } /* Name.Builtin.Pseudo */
.codehilite .fm { color: #71ADFF } /* Name.Function.Magic */
.codehilite .vc { color: #40FFFF } /* Name.Variable.Class */
.codehilite .vg { color: #40FFFF } /* Name.Variable.Global */
.codehilite .vi { color: #40FFFF } /* Name.Variable.Instance */
.codehilite .vm { color: #40FFFF } /* Name.Variable.Magic */
.codehilite .il { color: #51B2FD } /* Literal.Number.Integer.Long */