:root {
  --bg: #0f1115;
  --panel: #161a22;
  --panel-2: #1d2230;
  --ink: #e6e8ee;
  --ink-dim: #9aa3b2;
  --rule: #2a3140;
  --accent: #7aa2ff;
  --accent-2: #b48cff;
  --good: #6ad7a3;
  --warn: #f0b86e;
  --code: #ffd479;
  --serif: ui-serif, Georgia, "Iowan Old Style", "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", sans-serif;
  --mono: ui-monospace, "JetBrains Mono", Menlo, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; max-width: 100%; overflow-x: hidden; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* sidebar */
#sidebar {
  background: var(--panel);
  border-right: 1px solid var(--rule);
  padding: 22px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.brand { margin-bottom: 18px; }
.brand-link {
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 600;
  color: var(--ink);
}
.brand-sub {
  font-size: 12px;
  color: var(--ink-dim);
  margin-top: 4px;
  font-style: italic;
}
#toc { font-size: 13.5px; line-height: 1.55; }
#toc .toc-section {
  margin-top: 12px;
  color: var(--ink-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 11px;
}
#toc .toc-page {
  display: block;
  padding: 4px 8px;
  margin: 2px 0;
  border-radius: 6px;
  color: var(--ink);
}
#toc .toc-page:hover { background: var(--panel-2); text-decoration: none; }
#toc .toc-page.active {
  background: var(--panel-2);
  color: var(--accent);
  border-left: 2px solid var(--accent);
  padding-left: 6px;
}
.sidebar-foot {
  margin-top: 24px;
  padding-top: 14px;
  border-top: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
}
.lib-link { color: var(--ink-dim); }

/* main */
#main {
  padding: 56px 64px 80px;
  max-width: 980px;
  width: 100%;
  min-width: 0;        /* critical: lets the 1fr grid column shrink instead of overflowing */
  margin: 0 auto;
  overflow-x: hidden;  /* clip any stray wide child */
}
#content { overflow-wrap: break-word; word-break: break-word; }
#content { font-family: var(--serif); font-size: 18px; line-height: 1.7; }
#content h1 {
  font-size: 34px;
  line-height: 1.2;
  margin: 0 0 6px;
  font-family: var(--serif);
}
#content h2 {
  font-size: 22px;
  margin: 28px 0 8px;
  color: var(--ink);
  font-family: var(--serif);
}
#content h3 { font-size: 17px; color: var(--ink-dim); margin: 0 0 22px; font-weight: 500; font-style: italic; }
#content p { margin: 14px 0; }
#content blockquote {
  border-left: 3px solid var(--accent);
  margin: 18px 0;
  padding: 4px 16px;
  color: var(--ink-dim);
  background: var(--panel);
  border-radius: 0 8px 8px 0;
  font-size: 16px;
}
#content code {
  font-family: var(--mono);
  background: var(--panel);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.92em;
  color: var(--code);
}
#content .figure {
  margin: 24px 0;
  text-align: center;
  background: var(--panel);
  padding: 16px;
  border: 1px solid var(--rule);
  border-radius: 10px;
}
#content .figure img { max-width: 100%; border-radius: 6px; }
#content .figure .cap {
  font-size: 13px;
  color: var(--ink-dim);
  margin-top: 8px;
  font-family: var(--sans);
  font-style: italic;
}
#content .kbd {
  display: inline-block; padding: 2px 6px; font-family: var(--mono);
  border: 1px solid var(--rule); border-radius: 4px; font-size: 12px; color: var(--ink-dim);
}
#content .pill {
  display: inline-block;
  padding: 2px 10px;
  background: var(--panel-2);
  border-radius: 999px;
  font-size: 12px;
  color: var(--accent);
  font-family: var(--sans);
}
/* PDF screenshot panel */
.pdf-shot-wrap {
  margin: 22px 0 30px;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: #2a2f3a;
  padding: 14px;
}
.pdf-shot-head {
  display: flex; align-items: center; justify-content: space-between;
  font-family: var(--sans); font-size: 12px; color: var(--ink-dim);
  margin-bottom: 10px; letter-spacing: 0.04em; text-transform: uppercase;
}
.pdf-shot-head .left { display: flex; align-items: center; gap: 8px; }
.pdf-shot-head .dot { width: 8px; height: 8px; border-radius: 50%; background: #ff5f57; box-shadow: 14px 0 0 #febc2e, 28px 0 0 #28c840; }
.pdf-shot-head .ttl { margin-left: 36px; }
.pdf-shot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
  gap: 14px;
}
.pdf-shot {
  background: #fff;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35), 0 2px 6px rgba(0,0,0,0.25);
}
.pdf-shot img { display: block; width: 100%; height: auto; }
.pdf-shot .cap {
  background: #f5f5ee;
  color: #555;
  font-size: 11px;
  font-family: var(--sans);
  padding: 6px 10px;
  border-top: 1px solid #ddd;
  text-align: center;
  font-style: italic;
}

.viz {
  margin-top: 32px;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 18px;
  overflow-x: auto;   /* wide SVG demos scroll inside the box, never past the border */
  max-width: 100%;
}
.viz:empty { display: none; }
.viz svg { max-width: 100%; height: auto; }
.viz > div { min-width: 0; }
.viz h4 {
  font-family: var(--sans);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-dim);
  margin: 0 0 14px;
}
.viz .controls {
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  margin: 12px 0; font-family: var(--sans); font-size: 13px; color: var(--ink-dim);
}
.viz input[type=range] { accent-color: var(--accent); }
.viz button {
  background: var(--panel-2); color: var(--ink); border: 1px solid var(--rule);
  padding: 4px 10px; border-radius: 6px; font-family: var(--sans); font-size: 12px;
  cursor: pointer;
}
.viz button:hover { border-color: var(--accent); }

/* pager */
#pager {
  margin-top: 56px;
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; flex-wrap: wrap;
  font-family: var(--sans); font-size: 14px;
  border-top: 1px solid var(--rule); padding-top: 18px;
}
#pager a {
  display: inline-flex; flex-direction: column;
  padding: 10px 14px; border: 1px solid var(--rule); border-radius: 8px;
  background: var(--panel); color: var(--ink); min-width: 200px;
}
#pager a:hover { border-color: var(--accent); text-decoration: none; }
#pager .dir { font-size: 11px; color: var(--ink-dim); text-transform: uppercase; }
#pager .ttl { font-family: var(--serif); }
#pager .spacer { flex: 1; }

/* ===== library: horizontally-scrolling category board ===== */
/* On the library view, collapse the sidebar so the board gets full width. */
body:has(#content.is-library) { grid-template-columns: 1fr; }
body:has(#content.is-library) #sidebar { display: none; }
/* When the content area is showing the library, let it use the full width
   and own the vertical space so the board can manage its own scroll. */
#main:has(#content.is-library) {
  max-width: none;
  padding: 28px 0 0 0;
  height: 100vh;
  display: flex; flex-direction: column;
  overflow: hidden;
}
#content.is-library { font-family: var(--sans); display: flex; flex-direction: column; min-height: 0; flex: 1; }
.lib-top { padding: 0 36px; flex: 0 0 auto; }
#content.is-library h1 { font-family: var(--serif); font-size: 30px; margin: 0 0 6px; }
.lib-sub { font-size: 14px; color: var(--ink-dim); margin: 0 0 2px; line-height: 1.5; }
.lib-add {
  margin-left: 8px; font-size: 12.5px; padding: 2px 10px; border: 1px solid var(--rule);
  border-radius: 999px; color: var(--ink-dim);
}
.lib-add:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.lib-hint { font-size: 12px; color: var(--accent-2); margin: 8px 0 0; letter-spacing: 0.02em; }

.lib-board {
  flex: 1 1 auto;
  display: flex;
  gap: 16px;
  align-items: stretch;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 16px 36px 28px;
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
}
.lib-board::-webkit-scrollbar { height: 10px; }
.lib-board::-webkit-scrollbar-thumb { background: var(--rule); border-radius: 6px; }
.lib-board::-webkit-scrollbar-thumb:hover { background: var(--accent); }

.lib-col {
  flex: 0 0 300px;
  display: flex; flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-top: 3px solid var(--col-accent, var(--accent));
  border-radius: 12px;
  min-height: 0;
  scroll-snap-align: start;
}
.lib-col-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 10px;
  position: sticky; top: 0;
}
.lib-col-title {
  font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--col-accent, var(--accent));
}
.lib-col-n {
  font-size: 11px; color: var(--ink-dim); background: var(--panel-2);
  border-radius: 999px; padding: 1px 9px; min-width: 22px; text-align: center;
}
.lib-col-list {
  flex: 1 1 auto; overflow-y: auto; padding: 0 10px 12px;
  display: flex; flex-direction: column; gap: 7px;
  scrollbar-width: thin;
}
.lib-col-list::-webkit-scrollbar { width: 7px; }
.lib-col-list::-webkit-scrollbar-thumb { background: var(--rule); border-radius: 6px; }

.lib-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel-2);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 10px;
  color: var(--ink);
}
.lib-row:hover {
  border-color: var(--col-accent, var(--accent));
  background: #20283a;
  text-decoration: none;
  transform: translateX(2px);
}
.lib-row { transition: transform .08s ease, border-color .08s ease, background .08s ease; }
.lib-row-yr {
  flex: 0 0 auto; font-family: var(--mono); font-size: 11px; color: var(--ink-dim);
  background: var(--bg); border-radius: 5px; padding: 2px 6px; min-width: 38px; text-align: center;
}
.lib-row-body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.lib-row-t {
  font-size: 13.5px; line-height: 1.3; color: var(--ink);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.lib-row-a {
  font-size: 11px; color: var(--ink-dim); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.lib-row-go { flex: 0 0 auto; color: var(--ink-dim); font-size: 18px; opacity: 0; }
.lib-row:hover .lib-row-go { opacity: 1; color: var(--col-accent, var(--accent)); }

@media (max-width: 880px) {
  #main:has(#content.is-library) { height: auto; overflow: visible; }
  .lib-board { flex-direction: column; overflow-x: hidden; padding: 16px 18px 40px; }
  .lib-col { flex: 0 0 auto; }
  .lib-top { padding: 0 18px; }
}

/* upload */
.upload-box {
  border: 2px dashed var(--rule); border-radius: 12px;
  padding: 30px; text-align: center; color: var(--ink-dim);
  font-family: var(--sans); background: var(--panel);
}
.upload-box.drag { border-color: var(--accent); color: var(--ink); }

/* tables */
.tbl { width: 100%; border-collapse: collapse; margin: 14px 0; font-family: var(--sans); font-size: 14px; }
.tbl th, .tbl td { border-bottom: 1px solid var(--rule); padding: 8px 10px; text-align: left; }
.tbl th { color: var(--ink-dim); font-weight: 500; }

@media (max-width: 880px) {
  body { grid-template-columns: 1fr; }
  #sidebar { position: static; height: auto; }
  #main { padding: 30px 22px 60px; }
}
