/* The /code source browser. Builds on site.css tokens and components (DESIGN.md);
   token colours for highlighted code are in code-highlight.css. */

.code-browser { padding-bottom: var(--s9); }
.code-browser .container { min-width: 0; }
/* The browser has no side columns, so its content uses the full window width (the site header keeps its own). */
.code-browser > section > .container { width: calc(100% - 2 * var(--gutter)); max-width: none; }

/* ---- Top: session, version picker, star, breadcrumbs, heading ---- */
.code-top { padding-block: var(--s6) var(--s5); border-bottom: 1px solid var(--line); }
.code-session { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s3); font-size: 0.875rem; color: var(--ink-2); }
.code-session .icon { color: var(--ink); }
.code-session strong { color: var(--ink); font-weight: 600; }
.code-signout { display: inline; margin: 0; }
/* Toasts: sign-in and star results, bottom of the window, dismissible. */
.code-toasts { position: fixed; z-index: 50; inset-inline: var(--gutter); bottom: var(--s5); display: grid; justify-items: end; gap: var(--s2); pointer-events: none; }
.code-toast { pointer-events: auto; display: flex; align-items: flex-start; gap: var(--s3); width: min(30rem, 100%); padding: var(--s3) var(--s3) var(--s3) var(--s4); border-radius: var(--r-panel); background: var(--raised); border: 1px solid var(--line); box-shadow: var(--shadow-2); color: var(--ink); font-size: 0.9375rem; line-height: 1.5; animation: code-toast-in 220ms cubic-bezier(0.2, 0.8, 0.2, 1); }
.code-toast > .icon { flex: none; margin-top: 3px; }
.code-toast > span { flex: 1; }
.code-toast.is-success > .icon { color: var(--evergreen); }
.code-toast.is-danger { background: var(--oxblood-tint); }
.code-toast.is-danger > .icon { color: var(--oxblood); }
.code-toast-close { flex: none; display: grid; place-items: center; width: 28px; height: 28px; margin: -2px 0 0; padding: 0; border: 0; border-radius: 6px; background: transparent; color: var(--ink-2); cursor: pointer; }
.code-toast-close:hover { background: var(--stone-2); color: var(--ink); }
.code-toast-close:focus-visible { outline: 2px solid var(--evergreen); outline-offset: 1px; }
.code-toast.is-leaving { opacity: 0; transform: translateY(8px); transition: opacity 200ms, transform 200ms; }
@keyframes code-toast-in { from { opacity: 0; transform: translateY(12px); } }
@media (max-width: 640px) { .code-toasts { justify-items: stretch; bottom: var(--s4); } .code-toast { width: 100%; } }
@media (prefers-reduced-motion: reduce) { .code-toast { animation: none; } .code-toast.is-leaving { transition: none; } }

.code-bar { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: var(--s3) var(--s5); margin-top: var(--s5); }
.code-version { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); margin: 0; min-width: 0; }
.code-version label { font: 600 0.8125rem/1.3 var(--sans); color: var(--ink-3); }
.code-version select { width: auto; max-width: 100%; min-height: 36px; padding-block: 4px; font-variant-numeric: tabular-nums; }
.code-star-wrap { display: grid; justify-items: end; gap: var(--s1); max-width: 100%; }
.code-star { margin: 0; }
.code-count { margin-left: 2px; padding: 1px 8px; border-radius: 999px; background: var(--stone-2); color: var(--ink-2); font: 600 0.8125rem/1.4 var(--sans); font-variant-numeric: tabular-nums; }

.code-crumbs { margin-top: var(--s5); font-size: 0.9375rem; min-width: 0; }
.code-crumbs ol { display: flex; flex-wrap: wrap; gap: 2px 0; margin: 0; padding: 0; list-style: none; }
.code-crumbs li { min-width: 0; overflow-wrap: anywhere; }
.code-crumbs li + li::before { content: "/"; padding-inline: 6px; color: var(--ink-3); }
.code-crumbs a { color: var(--evergreen); }
.code-crumbs [aria-current="page"] { color: var(--ink); font-weight: 600; }

.code-heading { margin-top: var(--s3); }
.code-heading h1 { font-size: clamp(1.75rem, 1.4rem + 1.4vw, 2.5rem); line-height: 1.15; overflow-wrap: anywhere; }
.code-commit { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s3); margin-top: var(--s2); color: var(--ink-2); }
.code-commit .code-tag { font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.code-commit a { color: var(--evergreen); }

.code-actions { margin-top: var(--s5); }
.code-download { margin: 0; }
.code-hint { display: flex; align-items: flex-start; gap: 6px; margin-top: var(--s2); color: var(--ink-2); }
.code-hint .icon { margin-top: 2px; }
.code-star-wrap .code-hint { max-width: 22rem; text-align: right; }

/* ---- Tree ---- */
.code-body { padding-top: var(--s5); }
.code-tree-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-panel); background: var(--raised); }
.code-tree { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
.code-tree th { text-align: left; font: 600 0.8125rem/1.4 var(--sans); color: var(--ink-3); padding: 10px 16px; border-bottom: 1px solid var(--line-strong); background: var(--stone); }
.code-tree td { padding: 0 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.code-tree tr:last-child td { border-bottom: 0; }
.code-tree td a { display: flex; align-items: center; gap: 10px; min-height: 44px; color: var(--ink); text-decoration: none; overflow-wrap: anywhere; }
.code-tree td a .icon { color: var(--ink-3); }
.code-tree td a .icon-dir { transform: rotate(-90deg); color: var(--evergreen); }
.code-tree .code-tree-size { text-align: right; white-space: nowrap; color: var(--ink-3); font-variant-numeric: tabular-nums; width: 1%; }
@media (hover: hover) and (pointer: fine) {
  .code-tree td a:hover span { color: var(--evergreen); text-decoration: underline; text-underline-offset: 3px; }
  .code-tree tbody tr { transition: background-color var(--t-quick) ease; }
  .code-tree tbody tr:hover { background: var(--canvas); }
}

/* ---- README and Markdown documents ---- */
.code-readme { padding-top: var(--s7); }
.code-readme-title { display: flex; align-items: center; gap: var(--s2); font: 600 1.125rem/1.35 var(--sans); letter-spacing: 0; margin-bottom: var(--s4); }
.code-readme-title .icon { color: var(--ink-3); }
.code-doc-panel { background: var(--raised); border: 1px solid var(--line); border-radius: var(--r-panel); padding: clamp(20px, 3vw, 40px); }
.code-doc { min-width: 0; }
.code-doc img { max-width: 100%; height: auto; }
.code-doc table { display: block; max-width: 100%; overflow-x: auto; }

/* ---- About this version ---- */
.code-about { padding-top: var(--s7); }
.code-about h2 { font-size: clamp(1.45rem, 1.25rem + 0.8vw, 1.85rem); }
.code-about > .container > p { margin-top: var(--s3); max-width: 70ch; }
.code-facts { margin-top: var(--s5); }
.code-sha { font-size: 0.875rem; color: var(--ink-2); }
.code-sha code, .code-facts code { font-size: 0.8125rem; overflow-wrap: anywhere; }
@media (max-width: 560px) { .code-facts { grid-template-columns: 1fr; gap: 2px; } .code-facts dd + dt { margin-top: var(--s3); } }

/* ---- File view ---- */
.code-file-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s3) var(--s5); padding: var(--s3) var(--s4); background: var(--stone); border: 1px solid var(--line); border-radius: var(--r-panel) var(--r-panel) 0 0; }
.code-file-meta { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s5); margin: 0; font-size: 0.875rem; }
.code-file-meta div { display: flex; gap: 6px; align-items: baseline; }
.code-file-meta dt { font: 600 0.8125rem/1.4 var(--sans); color: var(--ink-3); }
.code-file-meta dd { margin: 0; font-variant-numeric: tabular-nums; }
.code-file-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); }
.code-file-head + .code-hint { margin: 0; padding: var(--s2) var(--s4); border-inline: 1px solid var(--line); background: var(--canvas); }

.code-toggle a { min-height: 32px; padding: 4px 14px; border-radius: 6px; color: var(--ink-2); font: 600 0.875rem/1.2 var(--sans); text-decoration: none; display: inline-flex; align-items: center; justify-content: center; transition: background-color var(--t-quick) ease, color var(--t-quick) ease; }
.code-toggle a[aria-current="page"] { background: var(--raised); color: var(--ink); box-shadow: 0 1px 2px oklch(0.2 0.02 150 / 0.12); }

/* The code scrolls sideways inside its own panel, never the page. */
.code-note { border-radius: 0; }
.code-panel { overflow-x: auto; max-width: 100%; background: var(--raised); border: 1px solid var(--line); border-radius: 0 0 var(--r-panel) var(--r-panel); }
.code-panel:focus-visible { outline: 2px solid var(--evergreen); outline-offset: 2px; }
/* Line styling is code-highlight.css's; only the frame and the first and last rows' breathing room are set here. */
.code-panel .code-lines { min-width: 100%; width: max-content; }
.code-panel .code-lines .ln { background: var(--stone); border-right: 1px solid var(--line); }
.code-panel .code-lines tr:first-child td { padding-top: 10px; }
.code-panel .code-lines tr:last-child td { padding-bottom: 10px; }

.code-file-head ~ .code-doc-panel { border-top: 0; border-radius: 0 0 var(--r-panel) var(--r-panel); }

/* Images sit on a quiet stone checkerboard so transparency shows. */
.code-image { margin: 0; display: grid; place-items: center; padding: clamp(16px, 4vw, 48px); border: 1px solid var(--line); border-top: 0; border-radius: 0 0 var(--r-panel) var(--r-panel);
  background-color: var(--raised); background-image: repeating-conic-gradient(var(--stone-2) 0 25%, transparent 0 50%); background-size: 20px 20px; }
.code-image img { max-width: 100%; height: auto; max-height: 70vh; }

.code-binary { border-radius: 0 0 var(--r-panel) var(--r-panel); }
.code-binary > p { display: flex; gap: var(--s2); align-items: center; margin-bottom: var(--s4); }
.code-binary code { font-size: 0.8125rem; }
.code-body > .container > .notice { border-radius: 0 0 var(--r-panel) var(--r-panel); }

/* ---- Messages (empty mirror, 404, unavailable) ---- */
.code-message .lead { max-width: 60ch; }

@media (max-width: 640px) {
  .code-star-wrap { justify-items: start; }
  .code-star-wrap .code-hint { text-align: left; }
  .code-file-head { padding: var(--s3); }
  .code-tree th, .code-tree td { padding-inline: 12px; }
}
