/* ==========================================================================
   CodeScope Catalogue — hand-authored stylesheet
   Card-catalogue metaphor: manila stock, ruled tables, typewriter metadata.
   No frameworks. No build step. No remote assets.
   ========================================================================== */

/* --- 1. Tokens ---------------------------------------------------------- */

:root {
  --stock:        #ece3d1;
  --stock-deep:   #ded2ba;
  --card:         #f7f2e6;
  --card-alt:     #f1ead9;
  --ink:          #211e18;
  --ink-soft:     #55503f;
  --ink-faint:    #7d7660;
  --rule:         #c6b995;
  --rule-hard:    #9d8f6c;
  --accent:       #8a2d21;
  --accent-soft:  #b8543f;
  --verdigris:    #2b5a56;
  --ochre:        #8a6a15;
  --slate:        #3c4657;

  --shadow:       0 1px 0 var(--rule), 0 2px 6px rgba(60, 48, 24, .10);
  --texture-op:   .30;

  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas,
          "Liberation Mono", "Courier New", monospace;
  --serif: ui-serif, Georgia, "Iowan Old Style", "Times New Roman", Times, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --maxw: 76rem;
  --rail: 15rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --stock:        #16150f;
    --stock-deep:   #100f0a;
    --card:         #1e1c15;
    --card-alt:     #24211a;
    --ink:          #e9e2cf;
    --ink-soft:     #b3ab94;
    --ink-faint:    #8a8371;
    --rule:         #413c2e;
    --rule-hard:    #5d563f;
    --accent:       #e08a72;
    --accent-soft:  #c9705a;
    --verdigris:    #79b7b0;
    --ochre:        #d3ab4d;
    --slate:        #9aa8c0;

    --shadow:       0 1px 0 var(--rule), 0 2px 8px rgba(0, 0, 0, .45);
    --texture-op:   .10;
  }
}

/* Explicit overrides win in both directions if a UA/user forces a scheme. */
:root[data-theme="dark"] {
  --stock: #16150f; --stock-deep: #100f0a; --card: #1e1c15; --card-alt: #24211a;
  --ink: #e9e2cf; --ink-soft: #b3ab94; --ink-faint: #8a8371;
  --rule: #413c2e; --rule-hard: #5d563f;
  --accent: #e08a72; --accent-soft: #c9705a; --verdigris: #79b7b0;
  --ochre: #d3ab4d; --slate: #9aa8c0;
  --shadow: 0 1px 0 var(--rule), 0 2px 8px rgba(0,0,0,.45);
  --texture-op: .10;
}
:root[data-theme="light"] {
  --stock: #ece3d1; --stock-deep: #ded2ba; --card: #f7f2e6; --card-alt: #f1ead9;
  --ink: #211e18; --ink-soft: #55503f; --ink-faint: #7d7660;
  --rule: #c6b995; --rule-hard: #9d8f6c;
  --accent: #8a2d21; --accent-soft: #b8543f; --verdigris: #2b5a56;
  --ochre: #8a6a15; --slate: #3c4657;
  --shadow: 0 1px 0 var(--rule), 0 2px 6px rgba(60,48,24,.10);
  --texture-op: .30;
}

/* --- 2. Base ------------------------------------------------------------ */

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

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

body {
  margin: 0;
  background-color: var(--stock);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.62;
  overflow-x: hidden;
}

/* Cardstock texture: fixed, subtle, non-interactive. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: url("cardstock.png");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  opacity: var(--texture-op);
  mix-blend-mode: multiply;
  pointer-events: none;
  z-index: 0;
}
@media (prefers-color-scheme: dark) {
  body::before { mix-blend-mode: soft-light; }
}
:root[data-theme="dark"] body::before { mix-blend-mode: soft-light; }
:root[data-theme="light"] body::before { mix-blend-mode: multiply; }

.page { position: relative; z-index: 1; }

a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-soft); }
a:focus-visible,
button:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 1px;
}

code, kbd, samp, pre { font-family: var(--mono); }

.skip {
  position: absolute; left: -9999px; top: 0;
  background: var(--card); color: var(--ink);
  padding: .5rem .9rem; border: 1px solid var(--rule-hard); z-index: 99;
}
.skip:focus { left: .5rem; top: .5rem; }

/* --- 3. Shell ----------------------------------------------------------- */

.shell {
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr);
  gap: 0;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 1rem 4rem;
}

@media (max-width: 60rem) {
  .shell { grid-template-columns: minmax(0, 1fr); padding: 0 .85rem 3rem; }
}

/* --- 4. Drawer rail (navigation) --------------------------------------- */

.rail {
  position: sticky;
  top: 0;
  align-self: start;
  max-height: 100vh;
  overflow-y: auto;
  padding: 1.5rem .9rem 2rem 0;
  border-right: 1px solid var(--rule);
}

@media (max-width: 60rem) {
  .rail {
    position: static; max-height: none; overflow: visible;
    border-right: 0; border-bottom: 1px solid var(--rule);
    padding: 1rem 0 .75rem;
  }
}

.rail__plate {
  font-family: var(--mono);
  font-size: .68rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  border-bottom: 1px solid var(--rule);
  padding-bottom: .4rem;
  margin-bottom: .55rem;
}

.rail__title {
  font-family: var(--mono);
  font-size: 1.02rem;
  font-weight: 700;
  letter-spacing: .02em;
  margin: 0 0 .15rem;
  line-height: 1.25;
}
.rail__title a { color: var(--ink); text-decoration: none; }
.rail__title a:hover { color: var(--accent); }

.rail__sub {
  font-family: var(--mono);
  font-size: .66rem;
  color: var(--ink-faint);
  letter-spacing: .06em;
  margin: 0 0 1.2rem;
}

.drawers { list-style: none; margin: 0; padding: 0; }

@media (max-width: 60rem) {
  .drawers {
    display: flex; flex-wrap: nowrap; gap: .35rem;
    overflow-x: auto; padding-bottom: .35rem;
    scrollbar-width: thin;
  }
}

.drawers li { margin: 0 0 .18rem; }
@media (max-width: 60rem) { .drawers li { flex: 0 0 auto; margin: 0; } }

.drawers a {
  display: block;
  text-decoration: none;
  font-family: var(--mono);
  font-size: .74rem;
  line-height: 1.35;
  padding: .38rem .5rem;
  border: 1px solid transparent;
  border-left: 3px solid var(--rule);
  color: var(--ink-soft);
  background: transparent;
  white-space: nowrap;
}
.drawers a:hover { background: var(--card-alt); color: var(--ink); }
.drawers a[aria-current="page"] {
  border-left-color: var(--accent);
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--shadow);
}
.drawers .num {
  display: inline-block;
  min-width: 2.4em;
  color: var(--ink-faint);
  letter-spacing: .04em;
}

@media (max-width: 60rem) {
  .drawers a { border-left-width: 0; border-bottom: 3px solid var(--rule); }
  .drawers a[aria-current="page"] { border-bottom-color: var(--accent); }
}

.rail__note {
  margin-top: 1.3rem;
  padding-top: .7rem;
  border-top: 1px solid var(--rule);
  font-family: var(--mono);
  font-size: .64rem;
  line-height: 1.6;
  color: var(--ink-faint);
}
@media (max-width: 60rem) { .rail__note { display: none; } }

/* --- 5. Main column ----------------------------------------------------- */

.main { padding: 1.6rem 0 0 1.75rem; min-width: 0; }
@media (max-width: 60rem) { .main { padding: 1.25rem 0 0; } }

.head { border-bottom: 2px solid var(--rule-hard); padding-bottom: .8rem; margin-bottom: 1.5rem; }

.head__call {
  font-family: var(--mono);
  font-size: .68rem;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 .35rem;
}

h1 {
  font-family: var(--mono);
  font-size: clamp(1.35rem, 1.05rem + 1.4vw, 2rem);
  line-height: 1.18;
  letter-spacing: -.01em;
  margin: 0 0 .4rem;
  font-weight: 700;
}

.head__lede {
  margin: 0;
  font-size: 1.02rem;
  color: var(--ink-soft);
  max-width: 62ch;
}

h2 {
  font-family: var(--mono);
  font-size: 1.02rem;
  letter-spacing: .02em;
  margin: 2.6rem 0 .3rem;
  padding-bottom: .3rem;
  border-bottom: 1px solid var(--rule-hard);
  font-weight: 700;
}
h2 .h2num {
  color: var(--ink-faint);
  font-weight: 400;
  margin-right: .5em;
}

h3 {
  font-family: var(--mono);
  font-size: .85rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 1.7rem 0 .5rem;
  font-weight: 700;
}

p { margin: .7rem 0; max-width: 68ch; }

.lead { font-size: 1.02rem; }

/* --- 6. Catalogue cards ------------------------------------------------- */

.cards { display: grid; gap: .9rem; margin: 1.1rem 0; }
.cards--2 { grid-template-columns: repeat(auto-fit, minmax(19rem, 1fr)); }

.ccard {
  background: var(--card);
  border: 1px solid var(--rule);
  border-top: 3px solid var(--rule-hard);
  box-shadow: var(--shadow);
  padding: .85rem 1rem 1rem;
  min-width: 0;
}
.ccard--accent { border-top-color: var(--accent); }
.ccard--verdigris { border-top-color: var(--verdigris); }
.ccard--ochre { border-top-color: var(--ochre); }

.ccard__no {
  font-family: var(--mono);
  font-size: .64rem;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--ink-faint);
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px dotted var(--rule);
  padding-bottom: .3rem;
  margin-bottom: .5rem;
}

.ccard__title {
  font-family: var(--mono);
  font-size: .95rem;
  font-weight: 700;
  margin: 0 0 .3rem;
  word-break: break-word;
}
.ccard p { margin: .35rem 0; font-size: .93rem; max-width: none; }
.ccard p:last-child { margin-bottom: 0; }

/* --- 7. Ruled tables ---------------------------------------------------- */

.tablewrap {
  overflow-x: auto;
  border: 1px solid var(--rule);
  background: var(--card);
  box-shadow: var(--shadow);
  margin: 1rem 0 1.3rem;
  max-width: 100%;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-family: var(--mono);
  font-size: .76rem;
  line-height: 1.5;
}

caption {
  caption-side: top;
  text-align: left;
  font-family: var(--mono);
  font-size: .66rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  padding: .55rem .7rem .45rem;
  border-bottom: 1px solid var(--rule);
  background: var(--card-alt);
}

th, td {
  text-align: left;
  padding: .34rem .7rem;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
}

thead th {
  font-size: .64rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-soft);
  border-bottom: 2px solid var(--rule-hard);
  white-space: nowrap;
  background: var(--card-alt);
  position: sticky;
  top: 0;
}

tbody tr:nth-child(even) { background: var(--card-alt); }
tbody tr:last-child td { border-bottom: 0; }

td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td .path { color: var(--verdigris); }
td .sym { color: var(--ink); font-weight: 700; }

/* --- 8. Status marks ---------------------------------------------------- */

.mark {
  display: inline-block;
  font-family: var(--mono);
  font-size: .6rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  padding: .06rem .38rem;
  border: 1px solid currentColor;
  white-space: nowrap;
  line-height: 1.5;
}
.mark--live   { color: var(--verdigris); }
.mark--part   { color: var(--ochre); }
.mark--stub   { color: var(--accent); }
.mark--dead   { color: var(--ink-faint); }
.mark--opt    { color: var(--slate); }

/* --- 9. Definition lists ------------------------------------------------ */

.deflist {
  margin: 1rem 0 1.4rem;
  border-top: 1px solid var(--rule-hard);
}
.deflist div {
  display: grid;
  grid-template-columns: minmax(9rem, 15rem) minmax(0, 1fr);
  gap: 0 1.2rem;
  border-bottom: 1px solid var(--rule);
  padding: .45rem 0;
}
@media (max-width: 40rem) {
  .deflist div { grid-template-columns: minmax(0, 1fr); gap: .1rem; }
}
.deflist dt {
  font-family: var(--mono);
  font-size: .75rem;
  color: var(--ink);
  font-weight: 700;
  word-break: break-word;
}
.deflist dd { margin: 0; font-size: .92rem; color: var(--ink-soft); }
.deflist dd code { font-size: .78rem; }

/* --- 10. Annotated code ------------------------------------------------- */

.src {
  margin: 1rem 0 1.4rem;
  border: 1px solid var(--rule);
  background: var(--card);
  box-shadow: var(--shadow);
  max-width: 100%;
}
.src__ref {
  font-family: var(--mono);
  font-size: .66rem;
  letter-spacing: .08em;
  color: var(--ink-faint);
  padding: .45rem .7rem;
  border-bottom: 1px solid var(--rule);
  background: var(--card-alt);
  display: flex;
  flex-wrap: wrap;
  gap: .3rem 1rem;
  justify-content: space-between;
}
.src__ref b { color: var(--verdigris); font-weight: 700; }
.src pre {
  margin: 0;
  padding: .7rem .8rem;
  overflow-x: auto;
  font-size: .74rem;
  line-height: 1.62;
  color: var(--ink);
  tab-size: 2;
}
.src pre .c { color: var(--ink-faint); font-style: italic; }
.src pre .k { color: var(--accent); }
.src pre .s { color: var(--verdigris); }
.src pre .n { color: var(--ochre); }
.src__note {
  border-top: 1px dotted var(--rule);
  padding: .5rem .8rem;
  font-size: .86rem;
  color: var(--ink-soft);
}
.src__note strong { color: var(--ink); }

/* --- 11. Terminal renderings -------------------------------------------- */

.term {
  margin: 1rem 0 1.4rem;
  border: 1px solid var(--rule-hard);
  background: var(--card-alt);
  box-shadow: var(--shadow);
  max-width: 100%;
}
.term__bar {
  font-family: var(--mono);
  font-size: .64rem;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--ink-faint);
  padding: .4rem .7rem;
  border-bottom: 1px solid var(--rule);
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.term pre {
  margin: 0;
  padding: .8rem .85rem;
  overflow-x: auto;
  font-size: .73rem;
  line-height: 1.6;
  color: var(--ink);
}
.term .p  { color: var(--accent); }        /* prompt          */
.term .cm { color: var(--ink); font-weight: 700; } /* command  */
.term .ok { color: var(--verdigris); }
.term .wn { color: var(--ochre); }
.term .dm { color: var(--ink-faint); }
.term .st { color: var(--slate); }

/* --- 12. Diagrams ------------------------------------------------------- */

figure.dgm {
  margin: 1.3rem 0 1.6rem;
  border: 1px solid var(--rule);
  background: var(--card);
  box-shadow: var(--shadow);
  padding: .5rem .5rem 0;
  max-width: 100%;
}
figure.dgm svg { display: block; width: 100%; height: auto; }
figure.dgm figcaption {
  font-family: var(--mono);
  font-size: .68rem;
  line-height: 1.6;
  color: var(--ink-soft);
  border-top: 1px solid var(--rule);
  padding: .5rem .3rem .6rem;
  margin-top: .3rem;
}
figure.dgm figcaption b {
  color: var(--ink);
  letter-spacing: .1em;
  text-transform: uppercase;
  font-size: .64rem;
  display: block;
  margin-bottom: .15rem;
}

/* SVG element styling driven by CSS variables (light/dark aware) */
.dgm svg text { font-family: var(--mono); fill: var(--ink); }
.dgm .box   { fill: var(--card-alt); stroke: var(--rule-hard); stroke-width: 1; }
.dgm .box-a { fill: var(--card-alt); stroke: var(--accent);    stroke-width: 1.5; }
.dgm .box-v { fill: var(--card-alt); stroke: var(--verdigris); stroke-width: 1.5; }
.dgm .box-o { fill: var(--card-alt); stroke: var(--ochre);     stroke-width: 1.5; }
.dgm .box-d { fill: none;            stroke: var(--rule);      stroke-width: 1; stroke-dasharray: 4 3; }
.dgm .plate { fill: var(--stock-deep); stroke: var(--rule); stroke-width: 1; }
.dgm .ln    { stroke: var(--rule-hard); stroke-width: 1.2; fill: none; }
.dgm .ln-a  { stroke: var(--accent);    stroke-width: 1.6; fill: none; }
.dgm .ln-v  { stroke: var(--verdigris); stroke-width: 1.6; fill: none; }
.dgm .ln-o  { stroke: var(--ochre);     stroke-width: 1.6; fill: none; }
.dgm .ln-d  { stroke: var(--rule-hard); stroke-width: 1;   fill: none; stroke-dasharray: 3 3; }
.dgm .t     { font-size: 10px; fill: var(--ink); }
.dgm .t-s   { font-size: 8.5px; fill: var(--ink-soft); }
.dgm .t-f   { font-size: 7.5px; fill: var(--ink-faint); }
.dgm .t-b   { font-size: 10px; fill: var(--ink); font-weight: 700; }
.dgm .t-a   { font-size: 8.5px; fill: var(--accent); }
.dgm .t-v   { font-size: 8.5px; fill: var(--verdigris); }
.dgm .t-o   { font-size: 8.5px; fill: var(--ochre); }
.dgm .fillv { fill: var(--verdigris); }
.dgm .filla { fill: var(--accent); }
.dgm .fillr { fill: var(--rule-hard); }
.dgm .mid   { text-anchor: middle; }
.dgm .end   { text-anchor: end; }

/* --- 13. Notes / callouts ----------------------------------------------- */

.note {
  border-left: 3px solid var(--rule-hard);
  background: var(--card);
  padding: .7rem .95rem;
  margin: 1.1rem 0;
  font-size: .93rem;
  color: var(--ink-soft);
}
.note--accent { border-left-color: var(--accent); }
.note--ochre  { border-left-color: var(--ochre); }
.note p { margin: .3rem 0; max-width: none; }
.note p:first-child { margin-top: 0; }
.note p:last-child { margin-bottom: 0; }
.note strong { color: var(--ink); }
.note .lbl {
  font-family: var(--mono);
  font-size: .62rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  display: block;
  margin-bottom: .2rem;
}

/* --- 14. Inline bits ---------------------------------------------------- */

p code, li code, td code, dd code, .note code, figcaption code {
  background: var(--card-alt);
  border: 1px solid var(--rule);
  padding: 0 .22em;
  font-size: .84em;
  word-break: break-word;
}

kbd {
  background: var(--card);
  border: 1px solid var(--rule-hard);
  border-bottom-width: 2px;
  padding: .02em .35em;
  font-size: .8em;
  white-space: nowrap;
}

ul.plain { list-style: none; padding: 0; margin: .8rem 0; }
ul.plain li {
  border-bottom: 1px solid var(--rule);
  padding: .35rem 0;
  font-size: .93rem;
}
ul.plain li:last-child { border-bottom: 0; }

ol.steps { margin: .9rem 0; padding-left: 1.3rem; }
ol.steps li { margin: .4rem 0; font-size: .95rem; max-width: 66ch; }

/* --- 15. Foot ----------------------------------------------------------- */

.foot {
  margin-top: 3rem;
  padding-top: .9rem;
  border-top: 2px solid var(--rule-hard);
  font-family: var(--mono);
  font-size: .68rem;
  line-height: 1.7;
  color: var(--ink-faint);
  display: flex;
  flex-wrap: wrap;
  gap: .4rem 2rem;
  justify-content: space-between;
}
.foot nav { display: flex; flex-wrap: wrap; gap: .2rem 1.1rem; }
.foot a { color: var(--ink-soft); }
.foot a:hover { color: var(--accent); }

/* --- 16. Print ---------------------------------------------------------- */

@media print {
  body::before { display: none; }
  .rail, .foot nav { display: none; }
  .shell { grid-template-columns: 1fr; }
  .main { padding: 0; }
  .tablewrap, .src, .term, figure.dgm { break-inside: avoid; box-shadow: none; }
}
