/*
  Narleaf examples: shared page chrome.

  Color, type, components and motion live here. Every container / grid /
  column / gap decision in the example pages is a Narleaf class in the markup.
*/

/* ---------- Tokens ---------- */

:root {
  color-scheme: light dark;

  --bg:          #FBFBFA;
  --surface:     #FFFFFF;
  --surface-2:   #F4F4F1;
  --line:        #E7E6E1;
  --line-strong: #D3D2CA;
  --muted:       #6B6A64;
  --text:        #3F3E3A;
  --ink:         #141413;

  --accent:      #2A5FD0;   /* text, outlines, data marks */
  --accent-soft: #E6EFFF;   /* soft tint */
  --accent-fill: #BBD5FF;   /* pastel fill for buttons; always paired with --accent-ink */
  --accent-ink:  #0B1B33;
  --on-accent:   #FFFFFF;   /* text on solid --accent */

  --ok:   #15803D;  --ok-soft:   #E3F5E8;
  --warn: #A16207;  --warn-soft: #FBF0D4;
  --bad:  #B91C1C;  --bad-soft:  #FCE4E4;

  --radius:    12px;
  --radius-sm: 8px;
  --shadow:    0 1px 2px rgba(20,20,19,.04), 0 8px 24px -12px rgba(20,20,19,.12);

  --font:      system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:          #0E0E0D;
    --surface:     #171716;
    --surface-2:   #1F1F1D;
    --line:        #2A2A27;
    --line-strong: #3A3A36;
    --muted:       #A3A29B;
    --text:        #CFCEC7;
    --ink:         #F5F4EF;

    --accent:      #8DB8FF;
    --accent-soft: #14233D;
    --accent-fill: #8DB8FF;
    --accent-ink:  #0B1B33;
    --on-accent:   #0B1B33;

    --ok:   #4ADE80;  --ok-soft:   #12281A;
    --warn: #FBBF24;  --warn-soft: #2B2208;
    --bad:  #F87171;  --bad-soft:  #2E1414;

    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px -12px rgba(0,0,0,.5);
  }
}

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-block-start: 88px; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 1rem/1.65 var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { color: var(--ink); line-height: 1.15; margin: 0; letter-spacing: -.02em; text-wrap: balance; }
h1 { font-size: clamp(2.25rem, 1.4rem + 3.6vw, 4rem); font-weight: 700; letter-spacing: -.035em; }
h2 { font-size: clamp(1.6rem, 1.2rem + 1.6vw, 2.5rem); font-weight: 650; }
h3 { font-size: 1.15rem; font-weight: 600; letter-spacing: -.01em; }
h4 { font-size: .95rem; font-weight: 600; letter-spacing: 0; }
p  { margin: 0; text-wrap: pretty; }
a  { color: inherit; }
img, svg { display: block; max-inline-size: 100%; }
ul { margin: 0; padding: 0; list-style: none; }
code { font: .88em var(--font-mono); background: var(--surface-2); padding: .15em .4em; border-radius: 6px; }

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

.sr-only { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.skip {
  position: absolute; inset-inline-start: 16px; inset-block-start: -64px; z-index: 100;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: var(--radius-sm); text-decoration: none;
}
.skip:focus { inset-block-start: 16px; }

/* ---------- Page structure ---------- */

.topbar { background: var(--ink); color: var(--bg); font-size: .8rem; }
.topbar .nar-container, .topbar .nar-container-full { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-block: 9px; }
.topbar a { text-decoration: none; opacity: .85; }
.topbar a:hover { opacity: 1; text-decoration: underline; }

.site-header {
  position: sticky; inset-block-start: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  border-block-end: 1px solid var(--line);
}
.bar { display: flex; align-items: center; gap: 24px; min-block-size: 64px; }
.bar .grow { flex: 1; }
.brand { display: inline-flex; align-items: center; font-weight: 700; letter-spacing: -.02em; color: var(--ink); text-decoration: none; font-size: 1.05rem; }
.nav { display: none; gap: 4px; font-size: .92rem; }
.nav a { padding: 8px 12px; border-radius: var(--radius-sm); text-decoration: none; color: var(--text); }
.nav a:hover, .nav a[aria-current="page"] { background: var(--surface-2); color: var(--ink); }
@media (min-width: 768px) { .nav { display: flex; } }

.section { padding-block: clamp(48px, 7vw, 96px); }
.section.tight { padding-block: clamp(32px, 4vw, 56px); }
.section.alt { background: var(--surface-2); border-block: 1px solid var(--line); }
.section-head { max-inline-size: 640px; margin-block-end: clamp(28px, 4vw, 48px); }
.section-head.center { margin-inline: auto; text-align: center; }
.section-head h2 + p { margin-block-start: 14px; font-size: 1.05rem; color: var(--muted); }

.eyebrow { font-size: .75rem; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--accent); margin-block-end: 12px; }
.lead { font-size: clamp(1.05rem, 1rem + .3vw, 1.25rem); color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.stack > * + * { margin-block-start: var(--stack, 16px); }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.center { text-align: center; }

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

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-block-size: 44px; padding: 0 20px; border-radius: 10px; border: 1px solid transparent;
  background: var(--accent-fill); color: var(--accent-ink); font: 600 .95rem var(--font);
  text-decoration: none; cursor: pointer; transition: transform .15s, background-color .15s, border-color .15s;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: none; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line-strong); }
.btn.ghost:hover { background: var(--surface); }
.btn.dark { background: var(--ink); color: var(--bg); }
.btn.sm { min-block-size: 36px; padding: 0 14px; font-size: .85rem; border-radius: 8px; }
.btn svg { inline-size: 16px; block-size: 16px; }
@media (prefers-reduced-motion: reduce) { .btn { transition: none; } .btn:hover { transform: none; } }

.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px;
  font-size: .75rem; font-weight: 600; background: var(--surface-2); color: var(--text); border: 1px solid var(--line);
}
.badge.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.ok   { background: var(--ok-soft);   color: var(--ok);   border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.bad  { background: var(--bad-soft);  color: var(--bad);  border-color: transparent; }
.dot { inline-size: 6px; block-size: 6px; border-radius: 50%; background: currentColor; }

.chip {
  display: inline-flex; align-items: center; padding: 7px 14px; border-radius: 999px; font-size: .85rem; font-weight: 500;
  border: 1px solid var(--line-strong); color: var(--text); text-decoration: none; background: var(--surface); white-space: nowrap;
}
.chip:hover { border-color: var(--ink); color: var(--ink); }
.chip[aria-current="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-block-end: 6px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: clamp(18px, 2.4vw, 28px); box-shadow: var(--shadow);
}
.card.flat { box-shadow: none; }
.card.link { text-decoration: none; display: block; transition: border-color .15s, transform .15s; }
.card.link:hover { border-color: var(--line-strong); transform: translateY(-2px); }
@media (prefers-reduced-motion: reduce) { .card.link { transition: none; } .card.link:hover { transform: none; } }

.icon-tile {
  inline-size: 40px; block-size: 40px; border-radius: 10px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
}
.icon-tile svg { inline-size: 20px; block-size: 20px; }

.avatar {
  inline-size: 36px; block-size: 36px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: hsl(var(--h, 215) 55% 82%);
}
@media (prefers-color-scheme: dark) { .avatar { background: hsl(var(--h, 215) 35% 32%); } }
.avatar.lg { inline-size: 48px; block-size: 48px; font-size: .95rem; }
.avatar-stack { display: flex; }
.avatar-stack .avatar { margin-inline-start: -8px; border: 2px solid var(--surface); }
.avatar-stack .avatar:first-child { margin-inline-start: 0; }

/* Flat image placeholder: no image files, so the examples stay self-contained.
   --h picks a pastel hue (kept in the blue range across the examples). */
.art {
  border-radius: var(--radius);
  background: hsl(var(--h, 215) 70% 90%);
  aspect-ratio: var(--ratio, 16 / 10);
}
@media (prefers-color-scheme: dark) { .art { background: hsl(var(--h, 215) 30% 22%); } }

.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: .85rem; color: var(--muted); }
.meta .sep { inline-size: 3px; block-size: 3px; border-radius: 50%; background: currentColor; opacity: .6; }
.author { display: flex; align-items: center; gap: 12px; }
.author b { display: block; color: var(--ink); font-weight: 600; font-size: .92rem; line-height: 1.3; }

.link-list { display: grid; gap: 10px; font-size: .92rem; }
.link-list a { color: var(--muted); text-decoration: none; }
.link-list a:hover { color: var(--ink); text-decoration: underline; }

.site-footer { border-block-start: 1px solid var(--line); padding-block: clamp(40px, 6vw, 72px) 32px; font-size: .92rem; }
.site-footer h4 { margin-block-end: 14px; }
.legal { margin-block-start: 40px; padding-block-start: 24px; border-block-start: 1px solid var(--line); display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; color: var(--muted); font-size: .85rem; }

/* Table */
.table-wrap { overflow-x: auto; margin-inline: calc(-1 * clamp(18px, 2.4vw, 28px)); padding-inline: clamp(18px, 2.4vw, 28px); }
.table { inline-size: 100%; min-inline-size: 520px; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: start; font-size: .75rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 600; padding: 10px 12px; border-block-end: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 14px 12px; border-block-end: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-block-end: 0; }
.table .num { text-align: end; font-variant-numeric: tabular-nums; }

/* Progress */
.bar-track { block-size: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar-fill  { block-size: 100%; border-radius: inherit; background: var(--accent); inline-size: var(--v, 50%); }

/* ---------- Layout inspector ---------- */
/* Add data-nar / data-nar-grid / data-nar-container to an element to label it
   when the "Layout" toggle is on. Nothing here changes the layout itself. */

.inspect-toggle {
  position: fixed; inset-inline-end: 16px; inset-block-end: 16px; z-index: 50;
  display: inline-flex; align-items: center; gap: 8px; min-block-size: 40px; padding: 0 16px;
  border-radius: 999px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font: 600 .85rem var(--font); cursor: pointer; box-shadow: var(--shadow);
}
.inspect-toggle[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }

body.show-layout [data-nar],
body.show-layout [data-nar-grid],
body.show-layout [data-nar-container] { outline: 1px dashed var(--accent); outline-offset: -1px; }
/* Labels live in one overlay layer. examples.js places them and nudges each one
   until it no longer overlaps another label. */
.inspect-layer { position: absolute; inset: 0 auto auto 0; inline-size: 0; block-size: 0; z-index: 60; pointer-events: none; }
.inspect-label {
  position: absolute; padding: 2px 6px; border-radius: 4px; white-space: nowrap;
  font: 500 11px/1.5 var(--font-mono); letter-spacing: 0;
  background: var(--accent); color: var(--on-accent);
  box-shadow: 0 0 0 1px var(--bg);
}
.inspect-label.is-grid      { background: var(--ink);   color: var(--bg); }
.inspect-label.is-container { background: var(--muted); color: var(--bg); }
