/* Stipple's site: guides, examples, and the examples running in the browser.
   Light and dark follow the system. No web fonts: the system's UI and mono
   faces. */

:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --bg-soft: #f6f7f9;
  --bg-code: #f4f5f7;
  --fg: #1d2128;
  --fg-soft: #5a6270;
  --line: #e3e6eb;
  --accent: #047857;
  --accent-soft: #e6f6f0;
  --accent-fg: #ffffff;
  --link: #0b6b52;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 4px 16px rgb(16 24 40 / 6%);
  --tok-k: #a626a4;
  --tok-s: #2f7d32;
  --tok-c: #8a919c;
  --tok-n: #b25b00;
  --tok-t: #0f6fa8;
  --tok-f: #3654c5;
  --tok-m: #c2410c;
  --tok-a: #7c6f00;
  --radius: 10px;
  --top: 56px;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --bg-soft: #171a1f;
    --bg-code: #1a1d23;
    --fg: #e6e8ec;
    --fg-soft: #9aa2ae;
    --line: #2a2f37;
    --accent: #34d399;
    --accent-soft: #10302a;
    --accent-fg: #06261c;
    --link: #5ee0b0;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 6px 20px rgb(0 0 0 / 25%);
    --tok-k: #d38df0;
    --tok-s: #9bd58a;
    --tok-c: #7d8590;
    --tok-n: #f2a65a;
    --tok-t: #6cc4f5;
    --tok-f: #8fb2ff;
    --tok-m: #ff9f6e;
    --tok-a: #d9c56b;
  }
}

* { box-sizing: border-box; }
html { scroll-padding-top: calc(var(--top) + 12px); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.65 var(--sans);
}
a { color: var(--link); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
img { max-width: 100%; height: auto; }
code, pre { font-family: var(--mono); font-size: 0.9em; }

.skip { position: absolute; left: -999px; }
.skip:focus { left: 12px; top: 8px; z-index: 100; background: var(--bg); padding: 4px 8px; }

/* --- The top bar --- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  height: var(--top); padding: 0 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; color: var(--fg); text-decoration: none; font-weight: 700; font-size: 18px; letter-spacing: -0.01em; }
.brand img { display: block; border-radius: 6px; }
.toplinks { margin-left: auto; display: flex; gap: 4px; }
.toplinks a { color: var(--fg-soft); text-decoration: none; padding: 6px 10px; border-radius: 8px; font-size: 15px; font-weight: 500; }
.toplinks a:hover, .toplinks a[aria-current] { color: var(--fg); background: var(--bg-soft); }
.menu-toggle { display: none; width: 36px; height: 36px; border: 0; background: none; border-radius: 8px; cursor: pointer; padding: 0; color: var(--fg); }
.menu-toggle span, .menu-toggle span::before, .menu-toggle span::after { display: block; width: 18px; height: 2px; background: currentColor; border-radius: 2px; position: relative; margin: 0 auto; }
.menu-toggle span::before, .menu-toggle span::after { content: ""; position: absolute; left: 0; }
.menu-toggle span::before { top: -6px; }
.menu-toggle span::after { top: 6px; }

/* --- The three columns --- */
.layout { max-width: 1440px; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr); }
.layout.with-sidebar { grid-template-columns: 260px minmax(0, 1fr); }
.layout.with-sidebar.with-toc { grid-template-columns: 260px minmax(0, 1fr) 220px; }
main { min-width: 0; padding: 32px 48px 64px; }
.home main, .gallery main { padding: 0 24px 64px; max-width: 1180px; width: 100%; margin: 0 auto; }

.sidebar {
  position: sticky; top: var(--top); align-self: start;
  height: calc(100vh - var(--top)); overflow-y: auto;
  padding: 20px 12px 40px 20px; border-right: 1px solid var(--line);
  font-size: 14.5px;
}
.sidebar details { margin-bottom: 14px; }
.sidebar summary { list-style: none; cursor: pointer; font-weight: 650; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--fg-soft); padding: 4px 8px; }
.sidebar summary::-webkit-details-marker { display: none; }
.sidebar ul { list-style: none; margin: 4px 0 0; padding: 0; }
.sidebar a { display: block; padding: 4px 8px; border-radius: 6px; color: var(--fg); text-decoration: none; line-height: 1.35; }
.sidebar a:hover { background: var(--bg-soft); }
.sidebar a[aria-current] { background: var(--accent-soft); color: var(--link); font-weight: 600; }

.toc { position: sticky; top: var(--top); align-self: start; max-height: calc(100vh - var(--top)); overflow-y: auto; padding: 32px 16px 40px 0; font-size: 13.5px; }
.toc p { margin: 0 0 8px; font-weight: 650; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--fg-soft); }
.toc ul { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--line); }
.toc li a { display: block; padding: 3px 0 3px 12px; color: var(--fg-soft); text-decoration: none; line-height: 1.35; }
.toc li.l3 a { padding-left: 24px; }
.toc a:hover { color: var(--fg); }

/* --- Prose --- */
.prose { max-width: 820px; }
.prose h1 { font-size: 2.3rem; line-height: 1.15; letter-spacing: -0.02em; margin: 0.2em 0 0.6em; }
.prose h2 { font-size: 1.55rem; line-height: 1.25; letter-spacing: -0.01em; margin: 2.2em 0 0.6em; padding-top: 0.4em; border-top: 1px solid var(--line); }
.prose h3 { font-size: 1.2rem; margin: 1.8em 0 0.5em; }
.prose h4 { font-size: 1rem; margin: 1.5em 0 0.4em; }
.prose h1 + p { font-size: 1.08rem; }
.prose .anchor { float: left; margin-left: -1em; width: 1em; color: var(--fg-soft); text-decoration: none; opacity: 0; font-weight: 400; }
.prose :is(h1, h2, h3, h4):hover .anchor { opacity: 1; }
.prose p, .prose ul, .prose ol { margin: 0 0 1em; }
.prose li { margin: 0.25em 0; }
.prose li > ul, .prose li > ol { margin: 0.25em 0; }
.prose :not(pre) > code { background: var(--bg-code); border: 1px solid var(--line); padding: 0.08em 0.35em; border-radius: 5px; font-size: 0.86em; overflow-wrap: anywhere; }
.prose a code { color: var(--link); }
.prose blockquote { margin: 1.2em 0; padding: 0.6em 1em; border-left: 3px solid var(--accent); background: var(--bg-soft); border-radius: 0 var(--radius) var(--radius) 0; }
.prose blockquote > :last-child { margin-bottom: 0; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 2em 0; }
.prose img { border-radius: 6px; }
.prose p > img:only-child { display: block; margin: 0 auto; box-shadow: var(--shadow); }
pre {
  position: relative;
  background: var(--bg-code); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; overflow-x: auto; line-height: 1.5; font-size: 0.86rem; margin: 0 0 1.2em;
  tab-size: 4;
}
pre code { background: none; border: 0; padding: 0; font-size: inherit; }
pre .copy {
  position: absolute; top: 6px; right: 6px; font: 12px var(--sans); padding: 3px 8px;
  border: 1px solid var(--line); background: var(--bg); color: var(--fg-soft); border-radius: 6px; cursor: pointer; opacity: 0; transition: opacity 0.15s;
}
pre:hover .copy, pre .copy:focus { opacity: 1; }
.tok-k { color: var(--tok-k); }
.tok-s { color: var(--tok-s); }
.tok-c { color: var(--tok-c); font-style: italic; }
.tok-n { color: var(--tok-n); }
.tok-t { color: var(--tok-t); }
.tok-f { color: var(--tok-f); }
.tok-m { color: var(--tok-m); }
.tok-a, .tok-l { color: var(--tok-a); }
.tok-v { color: var(--tok-n); }
.tok-o { color: var(--tok-t); }

.table-wrap { overflow-x: auto; margin: 0 0 1.4em; border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 0.92rem; }
th, td { padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: top; text-align: left; }
th { background: var(--bg-soft); font-weight: 650; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
td img { max-width: 260px; }
.edit { margin-top: 3em; font-size: 0.9rem; color: var(--fg-soft); }

/* --- Live examples in the guides --- */
.live { margin: 1.6em 0 2em; }
.live-frame { position: relative;
  width: min(100%, var(--w)); height: var(--h);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  background: var(--bg-soft); box-shadow: var(--shadow);
}
.live iframe { display: block; width: 100%; height: 100%; border: 0; }
.live figcaption { margin-top: 10px; font-size: 0.9rem; color: var(--fg-soft); line-height: 1.5; max-width: max(var(--w), 520px); }
.live figcaption strong { color: var(--fg); }
.live-badge { display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--accent-fg); background: var(--accent); border-radius: 4px; padding: 1px 6px; vertical-align: 1px; }
.live-links { display: block; margin-top: 2px; }

/* --- Landing --- */
.hero { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: 40px; align-items: center; padding: 56px 0 40px; }
.hero h1 { font-size: clamp(2.6rem, 6vw, 4rem); line-height: 1; letter-spacing: -0.035em; margin: 0 0 16px; }
.tagline { font-size: 1.25rem; line-height: 1.5; color: var(--fg-soft); margin: 0 0 22px; }
.install { display: inline-block; margin: 0 0 22px; padding: 10px 16px; font-size: 0.95rem; }
.cta { display: flex; flex-wrap: wrap; gap: 10px; margin: 0 0 18px; }
.button { display: inline-block; padding: 9px 18px; border-radius: 9px; border: 1px solid var(--line); color: var(--fg); text-decoration: none; font-weight: 600; background: var(--bg); }
.button:hover { background: var(--bg-soft); }
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.button.primary:hover { filter: brightness(1.08); }
.hero-note { font-size: 0.92rem; color: var(--fg-soft); margin: 0; }
.hero-demo .live { margin: 0; }
.hero-demo .live-frame { width: 100%; height: min(var(--h), 70vh); }
.strip { padding: 8px 0 24px; }
.strip h2, .gallery h2 { font-size: 1.4rem; letter-spacing: -0.01em; margin: 32px 0 16px; }
.more { margin: 16px 0 0; font-weight: 600; }
.readme { margin: 24px auto 0; padding-top: 8px; border-top: 1px solid var(--line); }
.readme > h2:first-child { border-top: 0; }

/* --- Example cards --- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 18px; }
.card { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--bg); transition: box-shadow 0.15s, transform 0.15s; }
.card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.thumb { position: relative; display: block; aspect-ratio: 16 / 10; background: var(--bg-soft); border-bottom: 1px solid var(--line); overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.thumb.none::before { content: "▶"; position: absolute; inset: 0; display: grid; place-items: center; font-size: 28px; color: var(--fg-soft); }
.thumb .play { position: absolute; right: 10px; bottom: 10px; width: 34px; height: 34px; border-radius: 50%; background: var(--accent); opacity: 0; transition: opacity 0.15s; }
.thumb .play::after { content: ""; position: absolute; left: 13px; top: 10px; border-style: solid; border-width: 7px 0 7px 11px; border-color: transparent transparent transparent var(--accent-fg); }
.card:hover .play { opacity: 1; }
.card-body { padding: 12px 14px 14px; display: flex; flex-direction: column; flex: 1; }
.card h3 { margin: 0 0 4px; font-size: 1.02rem; }
.card h3 a { color: var(--fg); text-decoration: none; }
.card h3 a:hover { color: var(--link); }
.card p { margin: 0 0 10px; font-size: 0.88rem; line-height: 1.5; color: var(--fg-soft); }
.card .card-links { margin: auto 0 0; display: flex; gap: 14px; align-items: center; font-weight: 600; }
.card .card-links code { margin-left: auto; font-size: 0.78rem; color: var(--fg-soft); font-weight: 400; }
.page-head { padding: 40px 0 8px; max-width: 760px; }
.page-head h1 { font-size: 2.4rem; letter-spacing: -0.02em; margin: 0 0 8px; }
.page-head p { color: var(--fg-soft); font-size: 1.05rem; margin: 0; }
table.native td:first-child { white-space: nowrap; }

.footer { border-top: 1px solid var(--line); padding: 20px 24px; text-align: center; font-size: 0.88rem; color: var(--fg-soft); }
.footer p { margin: 0; }

/* --- An example, full page or embedded --- */
body.runner { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.runbar { display: flex; align-items: center; gap: 14px; padding: 8px 16px; border-bottom: 1px solid var(--line); min-height: 48px; flex: none; }
.runbar .brand img { border-radius: 5px; }
.runbar h1 { font-size: 16px; margin: 0; white-space: nowrap; }
.runbar .desc { margin: 0; font-size: 13.5px; color: var(--fg-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.runbar .back, .runbar .src { font-size: 14px; font-weight: 600; white-space: nowrap; text-decoration: none; }
.runbar .back::before { content: "← "; }
.stage { position: relative; flex: 1; min-height: 0; padding: 0; max-width: none; }
.stage canvas { display: block; width: 100%; height: 100%; }
.status { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; color: var(--fg-soft); font-size: 15px; pointer-events: none; padding: 24px; text-align: center; }
.status.error { color: #e5484d; background: var(--bg); }
.status[hidden] { display: none; }
body.runner.embed .runbar { display: none; }

/* --- Narrower screens --- */
@media (max-width: 1180px) {
  .layout.with-sidebar.with-toc { grid-template-columns: 240px minmax(0, 1fr); }
  .toc { display: none; }
  main { padding: 28px 32px 56px; }
}
@media (max-width: 860px) {
  .layout.with-sidebar, .layout.with-sidebar.with-toc { grid-template-columns: minmax(0, 1fr); }
  .menu-toggle { display: block; }
  .sidebar {
    position: fixed; top: var(--top); left: 0; bottom: 0; width: min(300px, 85vw); height: auto; z-index: 30;
    background: var(--bg); box-shadow: var(--shadow); transform: translateX(-105%); transition: transform 0.2s;
  }
  .nav-open .sidebar { transform: none; }
  main { padding: 20px 16px 48px; }
  .home main, .gallery main { padding: 0 16px 48px; }
  .hero { grid-template-columns: minmax(0, 1fr); padding: 32px 0 16px; gap: 24px; }
  .hero-demo .live-frame { height: min(var(--h), 60vh); }
  .prose h1 { font-size: 1.9rem; }
  .prose .anchor { display: none; }
  .topbar { padding: 0 12px; gap: 6px; }
  .toplinks a { padding: 6px 7px; font-size: 14px; }
  .toplinks .gh { display: none; }
  .runbar .desc { display: none; }
  .runbar h1 { flex: 1; overflow: hidden; text-overflow: ellipsis; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
