/* ==========================================================================
   whealy.com — site stylesheet
   One stylesheet, design tokens as custom properties, light/dark via
   prefers-color-scheme.  The only non-system typeface is the Underwood
   typewriter face, which is used for transcribed WW1 documents.
   ========================================================================== */

@font-face {
  font-family: "Underwood 1913";
  src: url("/f/underwood_etendu.woff") format("woff"),
       url("/f/underwood_etendu.ttf") format("truetype");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light dark;

  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --font-typewriter: "Underwood 1913", "Courier New", Courier, monospace;

  --bg:          #f6f5f2;
  --surface:     #ffffff;
  --surface-2:   #efede8;
  --text:        #1f2328;
  --text-muted:  #5d6570;
  --border:      #dcd8cf;
  --accent:      #b4530a;
  --accent-soft: #fbe9d8;
  --accent-text: #8a3f05;
  --paper:       #fbf7ea;
  --paper-ink:   #2a2620;

  --sidebar-w:   19rem;
  --content-w:   52rem;
  --radius:      0.6rem;
  --shadow:      0 1px 2px rgb(0 0 0 / .06), 0 4px 14px rgb(0 0 0 / .05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:          #15171a;
    --surface:     #1d2024;
    --surface-2:   #262a2f;
    --text:        #e6e3dc;
    --text-muted:  #9aa1ab;
    --border:      #33383f;
    --accent:      #f0a15a;
    --accent-soft: #3a2a1b;
    --accent-text: #f4b57a;
    --paper:       #25231d;
    --paper-ink:   #e9e3cf;
    --shadow:      0 1px 2px rgb(0 0 0 / .4);
  }
}

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

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

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 1.0625rem;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  grid-template-areas: "nav main" "nav foot";
  grid-template-rows: 1fr auto;
  min-height: 100vh;
}

/* --------------------------------------------------------------------------
   Sidebar and expanding tree
   -------------------------------------------------------------------------- */
.site-nav {
  grid-area: nav;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.site-brand {
  display: block;
  position: relative;
  flex: none;
  height: 7.5rem;
  overflow: hidden;
  color: #fff;
  text-decoration: none;
  background: #2b1a0a url("/img/cedar_tree.jpg") center 35% / 135% auto no-repeat;
}
.site-brand span {
  position: absolute;
  inset: auto 0 0 0;
  padding: 1.6rem 1.1rem .7rem;
  font-size: 1.3rem;
  font-weight: 650;
  letter-spacing: .01em;
  background: linear-gradient(transparent, rgb(0 0 0 / .72));
}

.tree { padding: .75rem .6rem 1.5rem; flex: 1; font-size: .97rem; line-height: 1.35; }
.tree ul { list-style: none; margin: 0; padding: 0; }
.tree ul ul { margin-left: .85rem; padding-left: .55rem; border-left: 1px solid var(--border); }

.tree a,
.tree summary {
  display: block;
  padding: .38rem .6rem;
  border-radius: .4rem;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}
.tree a:hover,
.tree summary:hover { background: var(--surface-2); }

.tree summary {
  display: flex;
  align-items: center;
  gap: .35rem;
  padding: 0;
  list-style: none;
}
.tree summary::-webkit-details-marker { display: none; }
.tree summary a { flex: 1; font-weight: 600; }
.tree summary .twisty {
  flex: none;
  width: 1.6rem; height: 1.9rem;
  display: grid; place-items: center;
  color: var(--text-muted);
  border-radius: .4rem;
}
.tree summary .twisty::before {
  content: "";
  width: .42rem; height: .42rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform .15s ease;
}
.tree details[open] > summary .twisty::before { transform: rotate(45deg); }

.tree li > a { margin-left: 1.95rem; }   /* align leaves with the text of expandable siblings */
.tree a[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: 650;
}
.tree .sections { max-height: 16rem; overflow-y: auto; font-size: .9rem; }
.tree .sections a { color: var(--text-muted); padding: .22rem .6rem; }
.tree .sections a[aria-current="true"] { color: var(--accent-text); font-weight: 650; background: transparent; }

.nav-toggle { display: none; }

/* --------------------------------------------------------------------------
   Page content
   -------------------------------------------------------------------------- */
#container { grid-area: main; padding: 2.25rem clamp(1rem, 4vw, 3rem) 1rem; min-width: 0; }

div.content, div.homepage {
  max-width: var(--content-w);
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(1.1rem, 3vw, 2.2rem);
}

h1, h2, h3, h4 { line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 1.7rem; margin: 2.2rem 0 .8rem; }
h3 { font-size: 1.25rem; margin: 1.8rem 0 .6rem; text-decoration: none; }
h2.first, .content > h2:first-child, [id^="page"] > h2:first-child { margin-top: 0; }

p { margin: 0 0 1em; }
ul, ol { padding-left: 1.5rem; }
li { margin: .25em 0; }
li.first { margin-top: 1em; }
.listHeader { font-weight: 650; }
dt { font-weight: 650; font-style: italic; margin-top: .6em; }

a { color: var(--accent-text); text-underline-offset: .15em; text-decoration-thickness: from-font; }
a:hover { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

img { max-width: 100%; height: auto; }
.largeImg { text-align: center; }
.largeImg img, .content > p > img { border-radius: .35rem; box-shadow: var(--shadow); }
.imageLeft  { float: left;  margin: .3rem 1.2rem .8rem 0; max-width: 45%; }
.imageRight { float: right; margin: .3rem 0 .8rem 1.2rem; max-width: 45%; }
.imageCaption, .caption { font-size: .85rem; color: var(--text-muted); text-align: center; }

blockquote, .quotation {
  margin: 1.2rem 0;
  padding: .8rem 1.2rem;
  border-left: 4px solid var(--accent);
  background: var(--surface-2);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-style: italic;
  color: var(--text-muted);
}
.quotation p { margin: .3em 0; }
q { font-style: italic; font-weight: 600; }
.highlight { background: var(--accent-soft); padding: 0 .2em; border-radius: .2em; }

/* Tables */
table { border-collapse: collapse; max-width: 100%; }
.content td, .content th { padding: .35rem .7rem; vertical-align: top; }
table.spinButton, table.results, table.downloadTable { width: 100%; margin: 1rem 0; font-size: .95rem; }
table.spinButton th, table.results th { text-align: left; background: var(--surface-2); border-bottom: 2px solid var(--border); }
table.spinButton td, table.results td { border-bottom: 1px solid var(--border); }
table.results td { text-align: right; font-variant-numeric: tabular-nums; }
table.results td.text { text-align: left; }
table.results .caption { text-align: center; font-weight: 650; background: var(--surface-2); }
table.results .rowCaption { text-align: right; font-weight: 650; }
table.results th.invisible { background: none; border: 0; }

/* Forms */
input, select, button {
  font: inherit; color: inherit;
  background: var(--surface); border: 1px solid var(--border); border-radius: .35rem;
  padding: .25rem .5rem;
}
input[type="number"] { text-align: right; }
input[type="image"] { border: 0; padding: 0; background: none; vertical-align: middle; }
input[type="submit"], button { cursor: pointer; background: var(--accent); border-color: var(--accent); color: #fff; padding: .35rem 1rem; }
input[type="submit"]:hover, button:hover { filter: brightness(1.1); }

/* Code */
pre, code, .console, table.coding { font-family: var(--font-mono); font-size: .9em; }
pre, div.example {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: .4rem; padding: .7rem 1rem; overflow-x: auto;
}
div.example p { margin: 0; white-space: pre-wrap; font-family: var(--font-mono); }

/* Embedded crate demo galleries: the content box fills the whole main area */
div.content.wide { max-width: none; }
iframe.demo-frame {
  display: block; width: 100%; height: 80vh; min-height: 30rem;
  border: 1px solid var(--border); border-radius: .4rem; background: #fff;
}

/* Canvas pages (Mandelbrot) */
canvas { max-width: 100%; height: auto; border-radius: .4rem; }
#plotArea { text-align: center; }

/* --------------------------------------------------------------------------
   Typewriter material: transcribed WW1 combat reports, summaries, letters.
   Everything else on the site is sans-serif.
   -------------------------------------------------------------------------- */
p.typewriter, div.right, table.logbook, .typewriter {
  font-family: var(--font-typewriter);
  font-size: 1.1rem;
  line-height: 1.2;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}
p.typewriter, div.right, table.logbook {
  background: var(--paper);
  color: var(--paper-ink);
  padding: 1rem 1.25rem;
  margin: 0 0 1rem;
  border: 1px solid var(--border);
  border-radius: .3rem;
  overflow-x: auto;
}
p.typewriter { border-bottom-left-radius: 0; border-bottom-right-radius: 0; margin-bottom: 0; border-bottom: 0; }
p.typewriter + div.right { border-top: 0; border-top-left-radius: 0; border-top-right-radius: 0; padding-top: 0; }
div.right { text-align: right; }
table.logbook td { padding: .1rem .5rem; }
table.logbook td.right { text-align: right; }

/* --------------------------------------------------------------------------
   Sections within a page (pageNN divs) — prev/next strip
   -------------------------------------------------------------------------- */
[id^="page"][hidden] { display: none; }

.pager {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  margin-bottom: 1.5rem; padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  font-size: .95rem;
}
.pager a {
  padding: .35rem .9rem; border: 1px solid var(--border); border-radius: 2rem;
  text-decoration: none; background: var(--surface);
}
.pager a:hover { background: var(--accent-soft); }
.pager a[aria-disabled="true"] { visibility: hidden; }
.pager .where { color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------------------
   Home page
   -------------------------------------------------------------------------- */
div.homepage {
  padding: 0; overflow: hidden;
}
.hero {
  min-height: 15rem;
  display: flex; align-items: flex-end;
  padding: 1.5rem 2rem;
  color: #fff;
  background: #2b1a0a url("/img/cedar_tree.jpg") center 30% / cover no-repeat;
}
.hero h1 { margin: 0; font-size: clamp(1.8rem, 5vw, 2.6rem); text-shadow: 0 2px 12px rgb(0 0 0 / .6); }
.hero p { margin: .3rem 0 0; text-shadow: 0 1px 8px rgb(0 0 0 / .7); }
.cards {
  display: grid; gap: 1rem; padding: 1.5rem;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
}
.card {
  display: block; padding: 1rem 1.2rem;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); text-decoration: none;
  transition: border-color .15s, transform .15s;
}
.card:hover { border-color: var(--accent); transform: translateY(-2px); color: var(--text); }
.card h2 { margin: 0 0 .3rem; font-size: 1.2rem; color: var(--accent-text); }
.card p { margin: 0; font-size: .95rem; color: var(--text-muted); }
.card li { color: var(--text-muted); }

/* --------------------------------------------------------------------------
   Footer
   -------------------------------------------------------------------------- */
.footer {
  grid-area: foot;
  max-width: var(--content-w); width: 100%; margin: 0 auto;
  padding: 1.5rem clamp(1rem, 4vw, 3rem) 2.5rem;
  color: var(--text-muted); font-size: .88rem; text-align: center;
}
.footer blockquote { margin: 1rem auto; border: 0; background: none; padding: 0; font-style: italic; }
.footer cite { display: block; font-style: normal; font-size: .82rem; margin-top: .15rem; }

/* --------------------------------------------------------------------------
   Narrow screens: sidebar becomes a slide-over drawer
   -------------------------------------------------------------------------- */
@media (max-width: 52rem) {
  body { grid-template-columns: minmax(0, 1fr); grid-template-areas: "main" "foot"; }
  .site-nav {
    position: fixed; inset: 0 auto 0 0; width: min(var(--sidebar-w), 85vw); height: 100dvh;
    z-index: 20; transform: translateX(-100%); transition: transform .2s ease;
    box-shadow: var(--shadow);
  }
  body.nav-open .site-nav { transform: none; }
  .nav-toggle {
    display: grid; place-items: center;
    position: fixed; top: .6rem; left: .6rem; z-index: 30;
    width: 2.6rem; height: 2.6rem; padding: 0;
    background: var(--surface); color: var(--text); border: 1px solid var(--border);
    border-radius: .5rem; box-shadow: var(--shadow); font-size: 1.3rem; line-height: 1;
  }
  #container { padding-top: 4rem; }
  .imageLeft, .imageRight { float: none; max-width: 100%; margin: 1rem 0; }
}

@media print {
  .site-nav, .nav-toggle, .pager { display: none; }
  body { display: block; background: #fff; }
  div.content { border: 0; box-shadow: none; }
}
