/* ==========================================================================
   Theo's Notebook — public theme (T04)
   Selected design: spec-bundle/theos-notebook-spec/design/mockups/wiki-shell.html
   (canonical shell) + components from design/assets/style.css (T1 chips,
   A2 replies, feed cards, pagination, forms).
   Cream paper, light-blue chrome, dark blue ink, handwritten headings.

   Contents:
     1. Font and tokens            6. Reading area (headings, intro label)
     2. Base and a11y helpers      7. Feed cards, tags, conversation (A2)
     3. Canvas and notebook card   8. Pagination, empty/error notes
     4. Topbar (brand + search)    9. Lists, boxes, timeline, forms
     5. Sidebar and nav tree      10. Footer, print, responsive
   ========================================================================== */

/* 1. Font and tokens ----------------------------------------------------- */

/* Patrick Hand — SIL Open Font License 1.1 (https://openfontlicense.org).
   Served once from /static/fonts/, never base64-embedded. */
@font-face {
  font-family: 'Patrick Hand';
  src: url('../fonts/patrick-hand.ttf') format('truetype');
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

:root {
  --ink: #173b69;
  --blue: #205da1;
  --link: #1761b2;
  --paper: #fffdf5;
  --edge: #c2d8e7;
  --quiet: #536d86;
  --hand: 'Patrick Hand', 'Comic Sans MS', cursive;
  --body: 'Trebuchet MS', Arial, sans-serif;
  --focus: #bb7721;
  --canvas: linear-gradient(125deg, #bfe3f9, #d8effb 50%, #bfe2f5);
  --card: #dff1fc;
  --card-edge: #a8cee8;
  --topbar: #e9f6ff;
  --topbar-edge: #b7d5ea;
  --sidebar: linear-gradient(125deg, #dbf0fe, #eaf7fd);
  --row-hover: #cee8fa;
  --row-current: #c3e2f7;
  --chip-bg: #dcedfa;
  --chip-edge: #a8cde5;
}

/* 2. Base and a11y helpers ------------------------------------------------ */

* { box-sizing: border-box; }

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

body {
  margin: 0;
  color: var(--ink);
  background: #d7eafa;
  font: 17px/1.65 var(--body);
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; color: var(--ink); }
a, button, input, textarea, select { touch-action: manipulation; }

a { color: var(--link); text-underline-offset: 4px; }
a:hover { text-decoration-thickness: 2px; }

a:focus-visible, button:focus-visible, input:focus-visible,
textarea:focus-visible, select:focus-visible, summary:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 4px;
}

[hidden] { display: none !important; }

.skip {
  position: absolute;
  top: -80px;
  left: 15px;
  z-index: 30;
  padding: 10px 14px;
  background: white;
  border-radius: 0 0 8px 8px;
}
.skip:focus { top: 0; }

.screen-reader {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

img, video { max-width: 100%; height: auto; }
figure { margin: 0 0 18px; }
figcaption { font-size: 13px; color: var(--quiet); }

pre {
  overflow-x: auto;
  max-width: 100%;
  padding: 13px 15px;
  background: #f0f6fa;
  border: 1px solid var(--edge);
  border-radius: 8px;
  font: 14px/1.6 monospace;
}
code { overflow-wrap: anywhere; font-size: 0.95em; }
pre code { background: none; padding: 0; }
code { background: #eef5fa; padding: 1px 5px; border-radius: 5px; }

table { width: 100%; max-width: 100%; border-collapse: collapse; font-size: 15px; }
td, th { text-align: left; border-bottom: 1px solid var(--edge); padding: 11px 8px; overflow-wrap: anywhere; }

/* 3. Canvas and notebook card --------------------------------------------- */

.canvas {
  padding: 23px;
  min-height: 100vh;
  background: var(--canvas);
}

.wiki {
  max-width: 1450px;
  margin: auto;
  border: 1px solid var(--card-edge);
  border-radius: 23px;
  background: var(--card);
  box-shadow: 0 8px 35px #286ca012;
  overflow: hidden;
}

/* 4. Topbar: brand + search ------------------------------------------------ */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 25px;
  padding: 16px 27px;
  border-bottom: 1px solid var(--topbar-edge);
  background: var(--topbar);
}

.brand {
  text-decoration: none;
  color: var(--ink);
  white-space: nowrap;
  font: 32px/1.2 var(--hand);
}
.brand .brand-star {
  color: var(--blue);
  font: 38px/1 var(--body);
  vertical-align: middle;
  margin-right: 10px;
}

.search { position: relative; width: 320px; max-width: 100%; }
.search input {
  width: 100%;
  border: 1px solid #9abfe1;
  border-radius: 24px;
  background: #f8fcff;
  padding: 10px 17px;
  font-size: 16px;
  min-height: 44px;
  color: var(--ink);
}
.search input::placeholder { color: #557796; }

/* 5. Sidebar and nav tree -------------------------------------------------- */

.layout {
  display: grid;
  grid-template-columns: 215px minmax(0, 1fr);
}

.sidebar {
  padding: 26px 18px 22px;
  background: var(--sidebar);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* The whole nav lives inside a native <details> so mobile gets a working
   disclosure with no JS. On wide screens the summary is hidden and the
   open details shows the nav as a plain column. */
.mobile-menu { margin: 0; }
.mobile-menu summary {
  display: none;
  list-style: none;
}
.mobile-menu summary::-webkit-details-marker { display: none; }

.menu-symbol {
  display: inline-block;
  font-size: 20px;
  line-height: 1;
  transition: transform 0.15s ease;
}
.mobile-menu[open] .menu-symbol { transform: rotate(45deg); }

.page-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0;
}

.page-nav a, .tree summary {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 13px;
  border-radius: 9px;
  text-decoration: none;
  color: var(--ink);
  min-height: 46px;
}
.page-nav a:hover, .tree summary:hover { background: var(--row-hover); }
.page-nav a[aria-current="page"] { background: var(--row-current); font-weight: 700; }

.nav-symbol {
  width: 20px;
  font-size: 23px;
  line-height: 1;
  text-align: center;
  color: var(--blue);
  flex: none;
}

.tree summary { cursor: pointer; }
.chevron { margin-left: auto; font-size: 14px; }
.tree[open] .chevron { transform: rotate(180deg); }

.tree-links {
  margin: 3px 0 10px 23px;
  border-left: 1px solid #8db8d9;
  padding-left: 10px;
}
.tree-links a { font-size: 16px; padding: 8px 10px; }

.sidebar-note {
  margin: auto 0 0;
  padding: 90px 15px 12px;
  color: #446e96;
  font: 23px/1.5 var(--hand);
  transform: rotate(-5deg);
}
.sidebar-note .star {
  display: block;
  color: #3477af;
  font: 43px/1 var(--body);
  margin-bottom: 13px;
}

/* 6. Reading area ----------------------------------------------------------- */

.reading-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr); /* two columns only when a rail exists */
  gap: 28px;
  padding: 28px 28px 28px 35px;
  background: var(--paper);
  border-radius: 21px 0 0 0;
  min-width: 0;
}
.reading-shell:has(> .margin) { grid-template-columns: minmax(0, 1fr) 190px; }

main { min-width: 0; overflow-wrap: break-word; }
main[tabindex="-1"]:focus { outline: none; }

.breadcrumbs {
  font-size: 14px;
  margin: 0 0 24px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

main h1 {
  font: 46px/1.17 var(--hand);
  font-weight: 400;
  margin: 0 0 16px;
}

/* Handwritten H1 with an orange underline swash (use inside .page-heading
   together with an optional .intro-label line). */
.page-heading { margin-bottom: 24px; }
.page-heading h1 {
  display: inline-block;
  position: relative;
  z-index: 0;
}
.page-heading h1::after {
  content: '';
  display: block;
  position: absolute;
  left: 5px;
  bottom: -5px;
  width: 94%;
  height: 5px;
  background: #f9dabc;
  border-radius: 50%;
  transform: rotate(-1deg);
  z-index: -1;
}

.intro-label {
  font: 25px/1.4 var(--hand);
  background: #e0f0fa;
  padding: 0 8px;
  display: inline;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

main p { margin: 0 0 18px; }
main h2 {
  font: 30px/1.3 var(--hand);
  font-weight: 400;
  margin: 31px 0 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--edge);
  scroll-margin-top: 16px;
}
main h3 {
  font: 24px/1.3 var(--hand);
  font-weight: 400;
  margin: 24px 0 12px;
}

/* Margin rail (wide screens only; hidden at <=1100px where it moves below) */
.margin {
  border-left: 1px solid #d7e1e5;
  padding-left: 21px;
  font-size: 15px;
  min-width: 0;
}
.margin h2 {
  font: 25px/1.3 var(--hand);
  font-weight: 400;
  margin: 0 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--edge);
}
.margin nav { display: flex; flex-direction: column; gap: 9px; }
.margin nav a { text-decoration: none; min-height: 29px; }
.margin nav a:hover { text-decoration: underline; }
.margin section + section { margin-top: 29px; }

.yellow-note {
  font: 23px/1.25 var(--hand);
  background: #fff2bd;
  padding: 13px 10px;
  margin: 4px 0 29px;
  transform: rotate(4deg);
  text-align: center;
}

.page-status {
  font-size: 13px;
  color: #597189;
  margin-top: 28px;
  border-top: 1px solid var(--edge);
  padding-top: 12px;
}

/* 7. Feed cards, tag chips, conversation (A2) -------------------------------- */

/* One note in a feed or permalink page. */
.article {
  padding: 19px 0;
  border-bottom: 1px solid #d2e0e9;
  min-width: 0;
}
.article:last-child { border-bottom: 0; }

.date { font-size: 13px; color: #56758c; margin-bottom: 8px; }
.date a { color: inherit; }

.note-body { min-width: 0; }
.note-body p:last-child { margin-bottom: 0; }

/* T1: soft inline hashtag label. Small rounded rectangle around the whole
   hashtag; wraps inline; a long tag wraps internally instead of overflowing. */
.tag-row { margin: 10px 0 4px; }
.tag-chip {
  display: inline-block;
  background: var(--chip-bg);
  border: 1px solid var(--chip-edge);
  border-radius: 7px;
  padding: 2px 7px;
  color: var(--blue);
  text-decoration: none;
  white-space: nowrap;
  max-width: 100%;
  font-size: 15px;
}
.tag-chip:hover { text-decoration-thickness: 2px; }

/* Conversation disclosure on feeds: collapsed by default (native details). */
.conversation { margin: 14px 0 0; }
.conversation summary {
  cursor: pointer;
  min-height: 40px;
  padding: 6px 0;
  color: var(--blue);
}
.conversation-body { padding: 4px 0 6px; }
.conversation-body p:last-child { margin-bottom: 0; }

/* A2: flat comments; author replies get a blue left rule and an explicit
   identity label (never inferred from the username). */
.reply {
  padding: 18px;
  border: 1px solid #cbdfea;
  border-radius: 10px;
  margin: 14px 0;
  background: #fffefa;
  min-width: 0;
}
.reply.line { border-left: 4px solid #2b6eaa; }
.reply-meta {
  display: flex;
  gap: 9px;
  align-items: center;
  flex-wrap: wrap;
  font-size: 14px;
  margin-bottom: 9px;
}
.reply-body { min-width: 0; }
.reply-body p:last-child { margin-bottom: 0; }

.label {
  display: inline-block;
  border-radius: 5px;
  padding: 2px 7px;
  background: #dbeefb;
  color: #235e8e;
  font-size: 13px;
}
.author-label { background: #245f92; color: white; }
.small { font-size: 13px; color: var(--quiet); }
.quiet { color: #556f82; font-size: 14px; }

/* 8. Pagination, empty/error notes ------------------------------------------ */

.pagination {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 15px;
  flex-wrap: wrap;
  margin: 25px 0;
}
.pagination .pages { display: flex; gap: 9px; flex-wrap: wrap; align-items: baseline; }
.pagination .pages a { text-decoration: none; padding: 4px 6px; }
.pagination .pages a:hover { text-decoration: underline; }
.pagination .current { font-weight: 700; padding: 4px 6px; }

/* Empty state: a soft margin note, not a decorative dashboard. */
.empty-note {
  border-left: 3px solid #e8bd7d;
  padding: 15px 20px;
  background: #fff7e5;
  border-radius: 0 8px 8px 0;
  margin: 17px 0;
}

/* Unavailable / permission / validation states. */
.notice {
  padding: 14px 17px;
  background: #fff1cf;
  border-left: 3px solid #c4a061;
  margin: 17px 0;
  font-size: 15px;
}
.notice.blue { background: #eaf4fb; border-color: #79a8cb; }
.error { color: #984a40; }
.success { color: #2e6b45; }

/* 9. Lists, boxes, timeline, forms ------------------------------------------- */

.entries { list-style: none; padding: 0; margin: 0; }
.entries li { padding: 15px 0; border-bottom: 1px solid #d7e3ea; }
.entries li:last-child { border: 0; }
.entries small { display: block; color: #526d82; font-size: 13px; }

.box {
  border: 1px solid #c8dce9;
  border-radius: 12px;
  padding: 21px;
  background: #f0f7fc;
}
.box.warm { background: #fff4d8; }
.box p:last-child { margin-bottom: 0; }

.columns { display: grid; grid-template-columns: 1.65fr 1fr; gap: 30px; }
.equal { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 19px; }
.three { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }

/* Manually curated era spine (AI / Homelab pages). */
.timeline { border-left: 3px solid #b3d0e5; margin: 21px 0 0 7px; padding-left: 25px; min-width: 0; }
.timeline h2 { margin-top: 28px; }
.timeline section { padding-bottom: 18px; }

/* Homepage index rows and recent list (H1 shell styling). */
.index-list { border: 1px solid var(--edge); border-radius: 8px; overflow: hidden; }
.index-row {
  display: grid;
  grid-template-columns: minmax(155px, .9fr) 1.25fr;
  gap: 18px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--edge);
  font-size: 15px;
}
.index-row:last-child { border-bottom: 0; }
.index-row a { font-size: 16px; }

.recent { list-style: none; margin: 0; padding: 0; }
.recent li {
  display: grid;
  grid-template-columns: 1fr .85fr;
  gap: 15px;
  padding: 13px 3px;
  border-bottom: 1px solid #dce4e6;
}
.recent li:last-child { border: 0; }
.recent small { font-size: 14px; color: var(--quiet); }

.page-list { list-style: none; margin: 0; padding: 0; }
.page-list li { padding: 10px 0; border-bottom: 1px solid var(--edge); }
.page-list li:last-child { border: 0; }

.backlinks { margin-top: 30px; padding-top: 18px; border-top: 1px solid var(--edge); font-size: 14px; }
.backlinks h2 { font: 23px/1.3 var(--hand); font-weight: 400; margin: 0 0 10px; padding: 0; border: 0; }
.backlinks p { color: var(--quiet); }

/* Forms: ordinary labelled inputs, 44px touch targets, server-side feedback. */
button, .button {
  display: inline-block;
  border: 1px solid #abc9de;
  border-radius: 8px;
  background: #edf6fc;
  padding: 9px 15px;
  text-decoration: none;
  min-height: 44px;
}
.button { color: var(--link); }
button.primary, .primary { background: #24649d; color: white; border-color: #24649d; }

.form label { display: block; margin: 13px 0 5px; font-size: 15px; }
.form input:not([type=checkbox]):not([type=radio]), .form textarea, .form select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #acc8dc;
  border-radius: 8px;
  background: #fffefa;
}
.form textarea { min-height: 140px; resize: vertical; }
.form .check { display: flex; gap: 9px; align-items: flex-start; }
.form .field-error { color: #984a40; font-size: 14px; margin: 4px 0 0; }
.actions, .form .actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 20px; }

/* 10. Footer, print, responsive ------------------------------------------------ */

.footer {
  padding: 17px 29px;
  border-top: 1px solid #cddfea;
  font-size: 13px;
  display: flex;
  gap: 17px;
  flex-wrap: wrap;
}

@media print {
  .sidebar, .topbar, .search, .margin, .footer, .skip, .pagination { display: none; }
  body { background: white; }
  .canvas { padding: 0; min-height: 0; }
  .wiki { border: 0; box-shadow: none; }
  .layout, .reading-shell { display: block; }
  .reading-shell { padding: 0; }
  .article { break-inside: avoid; }
}

/* Narrow desktop: rail drops below the text; sidebar slims. */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 180px minmax(0, 1fr); }
  .sidebar { padding: 23px 10px; }
  .reading-shell { grid-template-columns: minmax(0, 1fr); padding: 27px; }
  .reading-shell:has(> .margin) { grid-template-columns: minmax(0, 1fr); }
  .margin {
    border-left: 0;
    padding: 22px 0 0;
    border-top: 1px solid var(--edge);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
  }
  .yellow-note { display: none; }
  .margin section + section { margin: 0; }
  .page-heading h1, main h1 { font-size: 41px; }
  .sidebar-note { padding-left: 8px; }
  .index-row { grid-template-columns: 1fr 1fr; }
  .columns { grid-template-columns: 1fr; }
}

/* Mobile (<=620px): sidebar becomes document flow behind a native
   "Browse pages" disclosure; columns stack; canvas padding shrinks. */
@media (max-width: 620px) {
  .canvas { padding: 10px; min-height: 0; }
  .wiki { border-radius: 17px; }
  .topbar { padding: 17px 17px 14px; display: block; }
  .brand { font-size: 31px; }
  .brand .brand-star { font-size: 32px; }
  .search { margin-top: 15px; width: 100%; }

  .layout { display: block; }
  .sidebar { padding: 10px 14px; }
  .mobile-menu summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 13px;
    border-radius: 9px;
    min-height: 46px;
    font-size: 16px;
    color: var(--ink);
  }
  .mobile-menu summary:hover { background: var(--row-hover); }
  .sidebar-note { display: none; }

  .reading-shell { border-radius: 17px 17px 0 0; padding: 23px 20px; gap: 24px; }
  .breadcrumbs { margin-bottom: 21px; }
  main h1, .page-heading h1 { font-size: 36px; margin-bottom: 17px; }
  .intro-label { font-size: 23px; }
  main { font-size: 16px; line-height: 1.7; }
  main h2 { font-size: 28px; margin-top: 26px; }

  /* Long tags wrap internally instead of overflowing a 320px viewport. */
  .tag-chip {
    white-space: normal;
    overflow-wrap: anywhere;
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
  }

  .index-row { display: block; padding: 12px 14px; }
  .index-row a { display: block; margin-bottom: 3px; }
  .recent li { display: block; padding: 12px 0; }
  .recent small { display: block; margin-top: 3px; }
  .margin { grid-template-columns: 1fr; gap: 25px; padding-top: 21px; }
  .margin nav { gap: 8px; }
  .margin nav a { min-height: 32px; }
  .page-status { margin-top: 23px; }
  .backlinks { margin-top: 24px; }
  .form .actions > * { flex: 1; text-align: center; }
  .timeline { padding-left: 18px; }
}

/* Very narrow (320px): keep everything inside the viewport. */
@media (max-width: 360px) {
  .canvas { padding: 6px; }
  .reading-shell { padding: 18px 14px; }
  .reply { padding: 14px 12px; }
  .footer { padding: 17px 16px; gap: 12px; }
}
