/*
 * extend.css — hand-authored styles for the nominallysane theme.
 * Loaded AFTER the compiled style.css and wins ties by source order.
 * Consumes the theme's CSS variables (RGB triplets, inverted by html.dark):
 *   --color-text-main  --color-bg-main  --color-bg-muted  --color-border-main
 */

/* ============ 1. Base polish ============ */

:root { color-scheme: light; }
html.dark { color-scheme: dark; }

/* Guard the 100vw breakouts below against scrollbar-width overflow.
   clip (not hidden) so it doesn't create a scroll container. */
html { overflow-x: clip; }

::selection {
  background: rgb(var(--color-text-main) / 0.9);
  color: rgb(var(--color-bg-main));
}

:focus-visible {
  outline: 2px solid rgb(var(--color-text-main) / 0.7);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ============ 2. Prose refinements ============ */

.prose :where(hr):not(:where([class~=not-prose], [class~=not-prose] *)) {
  border-top: 1px dashed rgb(var(--color-border-main) / 0.4);
  margin: 3em auto;
  width: 60%;
}

.prose :where(blockquote):not(:where([class~=not-prose], [class~=not-prose] *)) {
  border-left: 2px solid rgb(var(--color-border-main) / 0.5);
  font-family: Newsreader, ui-serif, Georgia, serif;
  font-style: italic;
  font-weight: 400;
  color: rgb(var(--color-text-main) / 0.85);
}

.prose :where(figcaption):not(:where([class~=not-prose], [class~=not-prose] *)) {
  color: rgb(var(--color-text-main) / 0.6);
  font-size: 0.8125rem;
  text-align: center;
  margin-top: 0.75em;
}

.prose :where(th):not(:where([class~=not-prose], [class~=not-prose] *)) {
  border-bottom: 1px solid rgb(var(--color-border-main) / 0.6);
  font-weight: 600;
  text-align: left;
}

.prose :where(td):not(:where([class~=not-prose], [class~=not-prose] *)) {
  border-bottom: 1px solid rgb(var(--color-border-main) / 0.15);
}

.prose :where(code):not(:where(pre code, [class~=not-prose], [class~=not-prose] *)) {
  background: rgb(var(--color-bg-muted));
  padding: 0.125em 0.375em;
  border-radius: 0.25rem;
  font-weight: 500;
}

/* ============ 3. Post meta ============ */

.post-meta { color: rgb(var(--color-text-main) / 0.65); }
.post-meta a { color: inherit; text-decoration: none; }
.post-meta a:hover { text-decoration: underline; text-underline-offset: 2px; }

/* ============ 4. Wide / full breakout (Koenig cards + charts) ============ */
/* The content column is viewport-centered, so left:50% + translateX(-50%)
   on a viewport-based width is an exact breakout. */

.kg-width-wide,
.kg-width-full {
  position: relative;
  left: 50%;
  transform: translateX(-50%);
  margin-left: 0;
}

.kg-width-wide { width: min(100vw - 2.5rem, var(--content-width-wide, 70rem)); }
.kg-width-full { width: 100vw; }

.kg-width-wide img,
.kg-width-full img { width: 100%; }

/* ============ 5. Chart containers (.nsviz) ============ */

.nsviz { margin: 2.5em auto; }
.nsviz .nsviz-mount { width: 100%; }
.nsviz .nsviz-mount svg { display: block; max-width: 100%; height: auto; }
.nsviz > script { display: none; }

.nsviz .nsviz-error {
  font-size: 0.8125rem;
  color: rgb(var(--color-text-main) / 0.6);
  border: 1px dashed rgb(var(--color-border-main) / 0.4);
  padding: 1rem;
  border-radius: 0.375rem;
}

/* Vega-Lite chart tooltips (vega-tooltip with theme: 'custom') */
#vg-tooltip-element.custom-theme {
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: 0.8125rem;
  line-height: 1.5;
  padding: 0.5rem 0.75rem;
  border-radius: 0.375rem;
  color: rgb(var(--color-text-main));
  background: rgb(var(--color-bg-muted));
  border: 1px solid rgb(var(--color-border-main) / 0.3);
  box-shadow: 0 4px 20px rgb(0 0 0 / 0.1);
}

#vg-tooltip-element.custom-theme table tr td.key {
  color: rgb(var(--color-text-main) / 0.6);
}

/* ============ 6. Definition tooltips ============ */

dfn[data-def],
span[data-def] {
  font-style: normal;
  cursor: help;
  text-decoration: underline dotted rgb(var(--color-text-main) / 0.6);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

#ns-def-tip {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 60; /* fixed + body-attached: never clipped by overflow */
  max-width: min(38ch, calc(100vw - 1rem));
  padding: 0.5rem 0.75rem;
  border-radius: 0.375rem;
  font-size: 0.8125rem;
  line-height: 1.55;
  font-style: normal;
  color: rgb(var(--color-text-main));
  background: rgb(var(--color-bg-muted));
  border: 1px solid rgb(var(--color-border-main) / 0.3);
  box-shadow: 0 4px 20px rgb(0 0 0 / 0.1);
}

#ns-def-tip[hidden] { display: none; }

/* ============ 7. Footnotes ============ */

/* Reference markers: quiet superscripts, no prose underline */
.prose sup.footnote-ref a {
  text-decoration: none;
  font-weight: 600;
  color: rgb(var(--color-text-main) / 0.6);
  padding: 0 0.125em;
}

.prose sup.footnote-ref a:hover,
.prose sup.footnote-ref a:focus-visible {
  color: rgb(var(--color-text-main));
}

/* The notes list at the end of the post: smaller and muted */
.prose section.footnotes {
  font-size: 0.875rem;
  color: rgb(var(--color-text-main) / 0.75);
}

.prose section.footnotes .footnote-backref { text-decoration: none; }

/* Landing highlight when a backref jumps to its marker */
.footnote-item:target,
sup.footnote-ref a:target {
  background: rgb(var(--color-text-main) / 0.08);
  border-radius: 0.25rem;
}

/* Hover-preview popup (shared element, body-attached like #ns-def-tip) */
#ns-note-tip {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 60;
  max-width: min(52ch, calc(100vw - 1rem));
  max-height: 40vh;
  overflow-y: auto;
  padding: 0.625rem 0.875rem;
  border-radius: 0.375rem;
  font-size: 0.8125rem;
  line-height: 1.55;
  color: rgb(var(--color-text-main));
  background: rgb(var(--color-bg-muted));
  border: 1px solid rgb(var(--color-border-main) / 0.3);
  box-shadow: 0 4px 20px rgb(0 0 0 / 0.1);
}

#ns-note-tip[hidden] { display: none; }
#ns-note-tip p { margin: 0 0 0.5em; }
#ns-note-tip p:last-child { margin-bottom: 0; }
#ns-note-tip a { color: inherit; }
