/*
 * The archive's stylesheet — a developer file-browser, not a card deck.
 *
 * White page, GitHub's subtle grey for secondary surfaces, 1px rules to
 * structure it, and one brand green reserved for the primary action. The
 * previous version leaned on large rounded cards with no borders; this one
 * is the opposite instinct, and the radius drops from 16px to 6px to match.
 *
 * Light only, deliberately. Following the system theme turned the archive
 * dark on a phone, and every figure in this study is drawn on white. The
 * exception is a fenced code block, which is dark on purpose.
 *
 * Mobile-first: everything below 768px is the real layout.
 */

:root {
  /* Surfaces */
  --canvas: #ffffff;
  --canvas-subtle: #f6f8fa;
  --canvas-inset: #f0f3f6;

  /* Lines. One weight, one colour, used everywhere. */
  --border: #d1d9e0;
  --border-muted: #e4e8ed;

  /* Text */
  --fg: #1f2328;
  --fg-muted: #59636e;
  --fg-subtle: #818b98;

  /* Brand green: primary actions only. */
  --accent: #2f7044;
  --accent-hover: #255a37;
  --accent-fg: #ffffff;

  /* Icons, as GitHub colours them. */
  --folder: #54aeff;
  --file: #636c76;

  /* Dark code block */
  --code-bg: #0d1117;
  --code-fg: #e6edf3;
  --code-border: #30363d;

  --radius: 6px;

  /*
   * SF Pro on Apple, Segoe on Windows, Inter where it is installed. Named
   * rather than fetched: a web font is a blocking request on a metered
   * connection, which is the connection this archive is read on.
   */
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", "JetBrains Mono",
    "Fira Code", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--canvas);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

.wrap { max-width: 1012px; margin: 0 auto; padding: 0 16px; }

@media (min-width: 768px) { .wrap { padding: 0 24px; } }

/* ---- 1. top bar -------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--canvas);
  border-bottom: 1px solid var(--border);
}

.topbar .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 52px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fg);
}

.brand:hover { text-decoration: none; color: var(--accent); }
.brand svg { width: 17px; height: 17px; color: var(--accent); flex: 0 0 auto; }

.menu-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--canvas-subtle);
  color: var(--fg);
  cursor: pointer;
}

.menu-btn:hover { background: var(--canvas-inset); }
.menu-btn svg { width: 17px; height: 17px; }

@media (min-width: 768px) { .menu-btn { display: none; } }

/* The sheet the hamburger opens. */
.menu {
  border-bottom: 1px solid var(--border);
  background: var(--canvas-subtle);
}

.menu[hidden] { display: none; }

.menu ul { list-style: none; margin: 0; padding: 6px 0; }

.menu a {
  display: block;
  padding: 11px 16px;
  color: var(--fg);
  font-size: 15px;
  font-weight: 500;
}

.menu a:hover { background: var(--canvas-inset); text-decoration: none; }
.menu .mono { font-family: var(--mono); font-size: 13.5px; }

@media (min-width: 768px) {
  .menu { display: block !important; border: 0; background: none; }
  .menu[hidden] { display: block; }
  .menu .wrap { display: flex; }
  .menu ul { display: flex; gap: 2px; padding: 0; }
  .menu a { padding: 8px 12px; border-radius: var(--radius); font-size: 14px; }
}

/* ---- 2. hero ----------------------------------------------------------- */

.hero { padding: 20px 0 16px; }

.hero h1 {
  margin: 0;
  font-size: 23px;
  line-height: 1.22;
  letter-spacing: -0.02em;
  font-weight: 700;
}

.hero .meta {
  margin: 8px 0 0;
  color: var(--fg-muted);
  font-size: 13.5px;
  line-height: 1.5;
}

.hero .meta a { color: var(--fg-muted); text-decoration: underline; text-underline-offset: 2px; }
.hero .meta a:hover { color: var(--accent); }

@media (min-width: 768px) {
  .hero { padding: 28px 0 20px; }
  .hero h1 { font-size: 32px; }
  .hero .meta { font-size: 14px; }
}

/* Compact once you are inside the tree. */
body.deep .hero { padding: 14px 0 10px; }
body.deep .hero h1 { font-size: 16px; font-weight: 600; }
body.deep .hero .meta,
body.deep .hero .actions { display: none; }

/* ---- action bar -------------------------------------------------------- */

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--canvas-subtle);
  color: var(--fg);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  text-decoration: none;
}

.btn:hover { background: var(--canvas-inset); text-decoration: none; border-color: var(--fg-subtle); }
.btn svg { width: 15px; height: 15px; flex: 0 0 auto; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
}

.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

/* ---- breadcrumb -------------------------------------------------------- */

body:not(.deep) .pathbar { display: none; }

.pathbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
}

.trail {
  display: flex;
  align-items: center;
  gap: 3px;
  min-width: 0;
  flex: 1 1 auto;
  overflow-x: auto;
  scrollbar-width: none;
  font-family: var(--mono);
  font-size: 13.5px;
  mask-image: linear-gradient(to right, #000 calc(100% - 16px), transparent);
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 16px), transparent);
}

.trail::-webkit-scrollbar { display: none; }
.trail a, .trail span { white-space: nowrap; }
.trail a { font-weight: 600; }
.trail .sep { color: var(--fg-subtle); padding: 0 2px; }
.trail .here { color: var(--fg-muted); font-weight: 600; }
.pathbar .btn { flex: 0 0 auto; }

/* ---- 3. file explorer -------------------------------------------------- */

.filter {
  width: 100%;
  min-height: 34px;
  margin: 0 0 12px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--canvas);
  color: var(--fg);
  font: inherit;
  font-size: 14px;
}

.filter::placeholder { color: var(--fg-subtle); }
.filter:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgba(47, 112, 68, 0.15); }

.explorer {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.explorer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 14px;
  background: var(--canvas-subtle);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--fg-muted);
}

.explorer-head .what { font-weight: 600; color: var(--fg); }
.explorer-head .count { font-variant-numeric: tabular-nums; white-space: nowrap; }

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

.row {
  position: relative;
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) auto;
  align-items: start;
  column-gap: 11px;
  padding: 10px 14px;
  border-top: 1px solid var(--border-muted);
}

.explorer ul > li:first-child .row { border-top: 0; }
.row:hover { background: var(--canvas-subtle); }

.row .icon { margin-top: 2px; }
.row .icon svg { display: block; width: 16px; height: 16px; }
.row.is-dir .icon { color: var(--folder); }
.row.is-file .icon { color: var(--file); }

.row .fname {
  display: block;
  color: var(--fg);
  font-size: 14.5px;
  font-weight: 500;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.row .fname:hover { color: var(--accent); text-decoration: underline; }

/* The whole row is the target; the name is one line of text on a phone. */
.row .fname::after { content: ""; position: absolute; inset: 0; }

.row .fdesc {
  margin: 1px 0 0;
  max-height: 2.8em; /* exactly two line boxes — clips between lines */
  overflow: hidden;
  color: var(--fg-muted);
  font-size: 12.5px;
  line-height: 1.4;
}

.row .when {
  color: var(--fg-muted);
  font-size: 12px;
  white-space: nowrap;
  text-align: right;
  padding-top: 2px;
  font-variant-numeric: tabular-nums;
}

.row .size {
  display: block;
  color: var(--fg-subtle);
  font-size: 11.5px;
}

@media (min-width: 768px) {
  .row { grid-template-columns: 18px minmax(0, 17rem) minmax(0, 1fr) auto; align-items: center; }
  .row .icon { margin-top: 0; }
  .row .fdesc { margin: 0; font-size: 13px; }
  .row .when { padding-top: 0; }
  .row .size { display: inline; font-size: 12px; }
  .row .size::after { content: " · "; color: var(--fg-subtle); }
}

.empty {
  padding: 26px 14px;
  color: var(--fg-muted);
  text-align: center;
  font-size: 14px;
}

/* ---- file view --------------------------------------------------------- */

.viewer {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  /* `clip`, not `hidden`: `hidden` would make this a scroll container, and
     the sticky header below would then stick to *it* — sitting 52px inside
     the box at every scroll position with the content sliding under it. */
  overflow: clip;
  margin-bottom: 20px;
}

.viewer-head {
  position: sticky;
  top: 52px;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 14px;
  background: var(--canvas-subtle);
  border-bottom: 1px solid var(--border);
}

.viewer-head .label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--fg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.viewer-head .label svg { width: 15px; height: 15px; color: var(--file); flex: 0 0 auto; }
.viewer-head .stat { color: var(--fg-muted); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }

.filenote {
  margin: 0 0 12px;
  color: var(--fg-muted);
  font-size: 13px;
}

/* ---- 4. prose ---------------------------------------------------------- */

.prose { padding: 16px; overflow-wrap: break-word; }

@media (min-width: 768px) { .prose { padding: 28px 32px; } }

.prose > :first-child { margin-top: 0; }
.prose h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.25; margin: 26px 0 14px; padding-bottom: 9px; border-bottom: 1px solid var(--border-muted); }
.prose h2 { font-size: 18px; font-weight: 650; margin: 26px 0 12px; padding-bottom: 7px; border-bottom: 1px solid var(--border-muted); }
.prose h3 { font-size: 15.5px; font-weight: 650; margin: 22px 0 8px; }
.prose h4 { font-size: 14.5px; font-weight: 650; margin: 18px 0 6px; }
.prose p, .prose li { font-size: 14.5px; }
.prose li { margin: 4px 0; }
.prose ul, .prose ol { padding-left: 22px; }

.prose blockquote {
  margin: 14px 0;
  padding: 2px 14px;
  border-left: 3px solid var(--border);
  color: var(--fg-muted);
}

/* Inline code: a path, a filename, a flag. */
.prose code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--canvas-inset);
  border-radius: var(--radius);
  padding: 2px 6px;
}

.prose hr { border: 0; border-top: 1px solid var(--border); margin: 26px 0; }
.prose img { max-width: 100%; height: auto; display: block; margin: 16px 0; border-radius: var(--radius); }

.prose table {
  display: block;
  overflow-x: auto;
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin: 16px 0;
}

.prose th, .prose td { border: 1px solid var(--border); padding: 7px 12px; text-align: left; vertical-align: top; }
.prose thead th { background: var(--canvas-subtle); font-weight: 600; white-space: nowrap; }

/* ---- dark code blocks -------------------------------------------------- */

.codeblock {
  position: relative;
  margin: 16px 0;
  border-radius: var(--radius);
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  overflow: hidden;
}

.codeblock pre {
  margin: 0;
  padding: 14px 16px;
  padding-right: 48px; /* keeps every line clear of the copy button */
}

.codeblock code {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.65;
  color: var(--code-fg);
  background: none;
  padding: 0;
  tab-size: 2;
  /*
   * Wrapped, not scrolled.
   *
   * These blocks hold shell commands and paths, not long listings, and a
   * command you have to drag sideways to read is a command you will mistype.
   * Wrapping also keeps every line inside the padding, so the copy button
   * never has code running underneath it.
   */
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.copy {
  position: absolute;
  top: 7px;
  right: 7px;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--code-border);
  border-radius: var(--radius);
  background: #161b22;
  color: #9198a1;
  cursor: pointer;
}

.copy:hover { color: var(--code-fg); background: #21262d; }
.copy svg { width: 15px; height: 15px; }
.copy.done { color: #3fb950; border-color: #3fb950; }

/* Syntax colours — GitHub dark. */
.tok-comment { color: #8b949e; font-style: italic; }
.tok-string  { color: #a5d6ff; }
.tok-keyword { color: #ff7b72; }
.tok-number  { color: #79c0ff; }
.tok-fn      { color: #d2a8ff; }
.tok-builtin { color: #ffa657; }

/* ---- data table -------------------------------------------------------- */

.tablewrap { overflow: auto; max-height: 72vh; -webkit-overflow-scrolling: touch; }

.datatable {
  border-collapse: collapse;
  width: 100%;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

.datatable th, .datatable td {
  border: 1px solid var(--border-muted);
  padding: 7px 12px;
  text-align: left;
  white-space: nowrap;
}

.datatable thead th { position: sticky; top: 0; z-index: 1; background: var(--canvas-subtle); font-weight: 600; }
.datatable td.idx { color: var(--fg-subtle); text-align: right; }

/* ---- light code viewer (a whole file, GitHub's file view) -------------- */

.code {
  margin: 0;
  padding: 12px 0;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.6;
  tab-size: 4;
}

.code .ln { display: block; padding: 0 16px 0 56px; position: relative; white-space: pre; }

.code .ln::before {
  content: attr(data-n);
  position: absolute;
  left: 0;
  width: 42px;
  text-align: right;
  color: var(--fg-subtle);
  user-select: none;
}

.code .ln:hover { background: var(--canvas-subtle); }

/* Light syntax colours, for the file view. */
.code .tok-comment { color: #6a737d; font-style: italic; }
.code .tok-string  { color: #0a3069; }
.code .tok-keyword { color: #cf222e; }
.code .tok-number  { color: #0550ae; }
.code .tok-fn      { color: #8250df; }
.code .tok-builtin { color: #953800; }

/* ---- media ------------------------------------------------------------- */

.imgview { padding: 16px; text-align: center; background: var(--canvas-subtle); }
.imgview img { max-width: 100%; height: auto; border-radius: var(--radius); background: #fff; }
.pdfview { display: block; width: 100%; height: 70vh; border: 0; }

@media (min-width: 768px) { .pdfview { height: 78vh; } }

.more {
  display: block;
  width: 100%;
  min-height: 42px;
  border: 0;
  border-top: 1px solid var(--border);
  background: var(--canvas-subtle);
  color: var(--accent);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}

.more:hover { background: var(--canvas-inset); }

.gate { padding: 26px 18px; text-align: center; }
.gate p { margin: 0 0 14px; color: var(--fg-muted); font-size: 14px; }
.gate strong { color: var(--fg); }
.gate .btn { margin: 0 4px; }

/* ---- 5. footer --------------------------------------------------------- */

.pagefoot { margin-top: 32px; border-top: 1px solid var(--border); background: var(--canvas-subtle); }

.accordion { border-bottom: 1px solid var(--border-muted); }
.accordion:last-of-type { border-bottom: 0; }

.accordion > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0;
  list-style: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: var(--fg);
}

.accordion > summary::-webkit-details-marker { display: none; }

.accordion > summary::after {
  content: "";
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-right: 1.5px solid var(--fg-muted);
  border-bottom: 1.5px solid var(--fg-muted);
  transform: rotate(45deg) translate(-2px, -2px);
  transition: transform 0.15s ease;
}

.accordion[open] > summary::after { transform: rotate(-135deg) translate(-2px, -2px); }

.accordion .body { padding: 0 0 16px; color: var(--fg-muted); font-size: 13.5px; }
.accordion .body p { margin: 0 0 10px; max-width: 70ch; }
.accordion .body p:last-child { margin-bottom: 0; }

.accordion .body .cite {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--fg);
  background: var(--canvas);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}

/* Past a phone, three columns rather than three accordions. */
@media (min-width: 768px) {
  .foot-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 32px; padding: 26px 0 8px; }
  .accordion { border: 0; }
  .accordion > summary { padding: 0 0 10px; cursor: default; pointer-events: none; font-size: 13px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--fg-muted); }
  .accordion > summary::after { display: none; }
  .accordion .body { padding: 0; }
}

.subfoot {
  border-top: 1px solid var(--border-muted);
  padding: 16px 0 28px;
  color: var(--fg-subtle);
  font-size: 12.5px;
}

.subfoot .links { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-bottom: 8px; }
.subfoot .links a { color: var(--fg-muted); }
