/* Shared styling for the alt-markdown demo gallery. Plain CSS, no build. */

:root {
  --ink: #1a1a2e;
  --muted: #5a5a72;
  --line: #e4e4ef;
  --accent: #4f46e5;
  --bg: #fbfbfe;
  --code-bg: #1a1a2e;
  --surface: #f3f3fb;
  --surface-card: #ffffff;
  --code-inline-bg: #f0f0f8;
  --callout-note-bg: #eef2ff;
  --callout-warning-bg: #fff7ed;
  --callout-danger-bg: #fef2f2;
  --callout-success-bg: #f0fdf4;
  --iframe-bg: #ffffff;
}

/* Notion-style warm dark grey, automatic on a dark OS, forceable with
   <html data-theme="dark">. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #e6e6e4;
    --muted: #9b9a97;
    --line: #373737;
    --accent: #6aa3da;
    --bg: #191919;
    --code-bg: #111111;
    --surface: #242424;
    --surface-card: #202020;
    --code-inline-bg: #2c2c2c;
    --callout-note-bg: #1c2530;
    --callout-warning-bg: #2a2117;
    --callout-danger-bg: #2a1b1b;
    --callout-success-bg: #1a261c;
    --iframe-bg: #f7f7f5;
  }
}

:root[data-theme="dark"] {
  --ink: #e6e6e4;
  --muted: #9b9a97;
  --line: #373737;
  --accent: #6aa3da;
  --bg: #191919;
  --code-bg: #111111;
  --surface: #242424;
  --surface-card: #202020;
  --code-inline-bg: #2c2c2c;
  --callout-note-bg: #1c2530;
  --callout-warning-bg: #2a2117;
  --callout-danger-bg: #2a1b1b;
  --callout-success-bg: #1a261c;
  --iframe-bg: #f7f7f5;
}

* {
  box-sizing: border-box;
}

body {
  font-family: ui-serif, Georgia, "Times New Roman", serif;
  color: var(--ink);
  background: var(--bg);
  max-width: 46rem;
  margin: 0 auto;
  padding: 3rem 1.25rem 6rem;
  line-height: 1.7;
  font-size: 1.075rem;
}

h1,
h2,
h3 {
  font-family: ui-sans-serif, system-ui, sans-serif;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

h1 {
  font-size: 2.4rem;
  margin: 0 0 0.25rem;
}

h2 {
  margin-top: 2.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--line);
}

a {
  color: var(--accent);
}

code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.9em;
  background: var(--code-inline-bg);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

pre {
  background: var(--code-bg);
  color: #e8e8f5;
  padding: 1rem 1.25rem;
  border-radius: 10px;
  overflow-x: auto;
  font-size: 0.92rem;
}

pre code {
  background: none;
  padding: 0;
  color: inherit;
}

blockquote {
  margin: 1.5rem 0;
  padding: 0.4rem 1.25rem;
  border-left: 4px solid var(--accent);
  color: var(--muted);
  font-style: italic;
}

table {
  border-collapse: collapse;
  width: 100%;
  margin: 1.5rem 0;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.95rem;
}

th,
td {
  border: 1px solid var(--line);
  padding: 0.5rem 0.75rem;
  text-align: left;
}

th {
  background: var(--surface);
}

/* Components ------------------------------------------------------------- */

figure {
  margin: 1.5rem 0;
}

figure > :first-child {
  margin-top: 0;
}

figcaption {
  margin-top: 0.5rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.alt-figlabel {
  font-weight: 600;
  color: var(--accent);
}

.alt-xref {
  font-variant-numeric: tabular-nums;
}

.alt-cite {
  font-variant-numeric: tabular-nums;
}

.alt-references {
  font-size: 0.9rem;
  color: var(--muted);
  padding-left: 1.5rem;
}

.alt-references li {
  margin: 0.3rem 0;
}

.alt-callout {
  margin: 1.5rem 0;
  padding: 1rem 1.25rem;
  border-radius: 10px;
  border-left: 5px solid var(--muted);
  background: var(--surface);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.97rem;
}

.alt-callout p:first-child {
  margin-top: 0;
}
.alt-callout p:last-child {
  margin-bottom: 0;
}

.alt-callout-warning {
  border-left-color: #d97706;
  background: var(--callout-warning-bg);
}
.alt-callout-danger {
  border-left-color: #dc2626;
  background: var(--callout-danger-bg);
}
.alt-callout-note,
.alt-callout-info {
  border-left-color: var(--accent);
  background: var(--callout-note-bg);
}
.alt-callout-success {
  border-left-color: #16a34a;
  background: var(--callout-success-bg);
}

.alt-tablist {
  display: flex;
  gap: 0.25rem;
  border-bottom: 2px solid var(--line);
  margin-bottom: 0.5rem;
}

.alt-tablist button {
  font: inherit;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.95rem;
  border: 0;
  background: none;
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
}

.alt-tablist button[aria-selected="true"] {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

alt-tab section {
  padding: 0.25rem 0;
}

alt-accordion details {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.5rem 1rem;
  margin: 1rem 0;
  background: var(--surface-card);
}

alt-accordion summary {
  cursor: pointer;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-weight: 600;
}

.alt-chart-canvas,
.alt-math-rendered {
  margin: 1.5rem 0;
}

.alt-math-rendered {
  text-align: center;
  overflow-x: auto;
}

alt-diagram iframe {
  display: block;
  margin: 1.5rem auto;
  /* Diagrams render in Mermaid's light theme (dark ink), so the backing stays
     light in dark mode too, presented as a rounded card. */
  background: var(--iframe-bg);
  border-radius: 10px;
  max-width: 100%;
}

ul.contains-task-list,
li.task-list-item {
  list-style: none;
}

/* Footnotes -------------------------------------------------------------- */

/* The inline marker: a small raised number that links down to the note. */
.footnote-ref {
  font-size: 0.75em;
  line-height: 0;
}

.footnote-ref a {
  text-decoration: none;
  padding: 0 0.1em;
}

/* The notes themselves read as a quieter, smaller block. A rule above the
   first note separates it from the body text. */
.footnote {
  display: flex;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.footnote:first-of-type {
  margin-top: 2rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
}

.footnote p {
  margin: 0 0 0.5rem;
}

/* The leading number doubles as the back-link to where the note was cited. */
.footnote-backref {
  flex: none;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  text-decoration: none;
  color: var(--accent);
}

.alt-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Gallery index ---------------------------------------------------------- */

.gallery-card {
  display: block;
  text-decoration: none;
  color: inherit;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  margin: 1rem 0;
  background: var(--surface-card);
  transition: border-color 0.15s, transform 0.15s;
}

.gallery-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.gallery-card h2 {
  margin: 0 0 0.25rem;
  border: 0;
  padding: 0;
  font-size: 1.3rem;
  color: var(--accent);
}

.gallery-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.97rem;
}

.tagline {
  color: var(--muted);
  font-size: 1.1rem;
}

.doc-error {
  color: #dc2626;
  font-family: ui-sans-serif, system-ui, sans-serif;
}

/* Scroll-reveal: heavier blocks fade and rise in as they enter view. The
   runtime adds .altmd-reveal, then .altmd-revealed once on screen. */
.altmd-reveal {
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 0.55s ease, transform 0.55s ease;
  will-change: opacity, transform;
}

.altmd-revealed {
  opacity: 1;
  transform: none;
}

@media (prefers-reduced-motion: reduce) {
  .altmd-reveal {
    opacity: 1;
    transform: none;
    transition: none;
  }
}

/* Playground ------------------------------------------------------------- */

.pg-body {
  margin: 0;
  max-width: none;
  padding: 0;
  height: 100vh;
  /* Track the dynamic viewport so mobile browser chrome appearing or hiding does
     not crop the bottom pane or leave a dead strip. */
  height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family: ui-sans-serif, system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.pg-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  /* Wrap rather than overflow when the controls do not fit a narrow screen. */
  flex-wrap: wrap;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  flex: none;
}

.pg-brand {
  color: var(--accent);
}

.pg-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.pg-field {
  font-size: 0.85rem;
  color: var(--muted);
}

.pg-controls select,
.pg-controls button {
  font: inherit;
  font-size: 0.85rem;
  color: var(--ink);
  background: var(--surface-card);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0.3rem 0.6rem;
  cursor: pointer;
}

.pg-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 0;
}

.pg-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  border-right: 1px solid var(--line);
}

.pg-pane:last-child {
  border-right: none;
}

.pg-pane-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding: 0.4rem 1rem 0.2rem;
}

#src {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  padding: 0.5rem 1rem 1rem;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  tab-size: 2;
}

#out {
  flex: 1;
  overflow: auto;
  padding: 0.5rem 1.5rem 3rem;
  max-width: none;
  /* A long unbroken token (a URL, a hostile zero-width run) must wrap rather
     than push the whole pane wider than its column. */
  overflow-wrap: break-word;
}

/* Rendered media is clamped to the pane: an image or chart canvas can never be
   wider than its column, so nothing forces a horizontal scrollbar on the page.
   Charts also reflow their width via a ResizeObserver in the runtime; this is the
   belt-and-braces guard for the brief moment before that fires and for images. */
#out :is(img, svg, video) {
  max-width: 100%;
  height: auto;
}

/* Wide tables scroll inside their own box instead of stretching the pane. */
#out table {
  display: block;
  overflow-x: auto;
}

.pg-status {
  font-size: 0.8rem;
  color: var(--muted);
  padding: 0 1.5rem;
  min-height: 1.1rem;
}

.pg-status-error {
  color: #c0392b;
}

.pg-foot {
  flex: none;
  font-size: 0.8rem;
  color: var(--muted);
  padding: 0.5rem 1rem;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.pg-embed {
  display: inline-block;
  background: var(--code-inline-bg);
  padding: 0.1rem 0.4rem;
  border-radius: 5px;
  white-space: pre-wrap;
}

@media (max-width: 720px) {
  .pg-grid {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
  }
  .pg-pane {
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
}
