:root {
  /* Design Library tokens — dark catalog by default, light on demand (theme toggle). */
  --bg: #09090b; --panel: #111113; --fg: #ececef; --muted: #a1a1aa; --faint: #63636b;
  --line: #222226; --hover: #1a1a1e; --accent: #ececef; --accent-fg: #09090b; --brand: #8b9cff;
  --ok: #4ade80; --ok-bg: #0d2318; --warn: #fbbf24; --warn-bg: #261d07; --bad: #f87171; --bad-bg: #2a1010;
  --code-bg: #0d0d10; --tok-kw: #c4b5fd; --tok-str: #6ee7b7; --tok-com: #6b7280; --tok-tag: #93c5fd; --tok-num: #fdba74;
  --radius: 12px; --side: 264px; --top: 56px; --bottom: 0px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #fbfbfa; --panel: #ffffff; --fg: #18181b; --muted: #6b6b73; --faint: #a1a1aa;
  --line: #e7e7ea; --hover: #f2f2f4; --accent: #18181b; --accent-fg: #fff; --brand: #4f5bd5;
  --ok: #15803d; --ok-bg: #ecfdf3; --warn: #b45309; --warn-bg: #fffbeb; --bad: #b91c1c; --bad-bg: #fef2f2;
  --code-bg: #f7f7f8; --tok-kw: #7c3aed; --tok-str: #047857; --tok-com: #9ca3af; --tok-tag: #2563eb; --tok-num: #c2410c;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
body { font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; border-radius: 6px; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 30; height: var(--top); display: flex; align-items: center; gap: 12px;
  padding: 0 16px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; text-decoration: none; white-space: nowrap; letter-spacing: -.01em; }
.logo { width: 22px; height: 22px; border-radius: 6px; background: var(--fg);
  -webkit-mask: radial-gradient(circle at 70% 50%, transparent 5px, #000 5.5px); mask: radial-gradient(circle at 70% 50%, transparent 5px, #000 5.5px); }
.search { flex: 1; max-width: 560px; margin-left: auto; display: flex; align-items: center; gap: 8px; height: 36px;
  padding: 0 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--muted); }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--fg); }
kbd { font: 11px ui-monospace, monospace; border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; color: var(--faint); }
.icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; border: 1px solid transparent; border-radius: 10px;
  background: transparent; cursor: pointer; color: var(--muted); }
.icon-btn:hover { background: var(--hover); color: var(--fg); }
.menu-btn, .close-btn { display: none; }

/* layout */
.layout { display: grid; grid-template-columns: var(--side) minmax(0, 1fr); }
.sidebar { position: sticky; top: var(--top); height: calc(100vh - var(--top)); border-right: 1px solid var(--line); background: var(--bg); }
.sidebar-head { display: none; }
.sidebar-scroll { height: 100%; overflow-y: auto; padding: 12px 8px 40px; overscroll-behavior: contain; }
.nav-item { display: flex; align-items: center; gap: 8px; height: 32px; padding: 0 10px; border-radius: 8px; text-decoration: none;
  color: var(--muted); white-space: nowrap; }
.nav-item:hover { background: var(--hover); color: var(--fg); }
.nav-item[aria-current="page"] { background: var(--hover); color: var(--fg); font-weight: 560; }
.nav-item .label { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.nav-item .count { font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; }
.nav-item .count b { color: var(--fg); font-weight: 560; }
.nav-item .badge-new { font-size: 10px; padding: 0 6px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.nav-group { margin: 18px 10px 6px; font-size: 12px; font-weight: 560; color: var(--faint); display: flex; justify-content: space-between; }
.nav-sep { height: 1px; background: var(--line); margin: 12px 8px; }
main { min-width: 0; padding: 28px 32px 80px; outline: 0; }
.loading { color: var(--muted); padding: 40px 0; }

/* page heading */
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.crumbs a { text-decoration: none; } .crumbs a:hover { text-decoration: underline; }
h1 { font-size: 28px; line-height: 1.2; margin: 0 0 6px; letter-spacing: -.02em; }
h2 { font-size: 17px; margin: 32px 0 12px; letter-spacing: -.01em; display: flex; align-items: baseline; gap: 10px; }
h2 a { font-size: 13px; font-weight: 450; color: var(--muted); }
.sub { color: var(--muted); margin: 0 0 20px; max-width: 860px; }
.stats { display: flex; flex-wrap: wrap; gap: 10px; margin: 16px 0 8px; }
.stat { border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius); padding: 12px 14px; min-width: 150px; }
.stat b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.stat span { font-size: 12px; color: var(--muted); }

/* filters */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 16px 0; }
.filters input[type=search], .filters select { height: 34px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); padding: 0 10px; }
.filters input[type=search] { flex: 1 1 220px; min-width: 0; }
.filters select { max-width: 180px; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--panel); color: var(--muted); cursor: pointer; text-decoration: none; font-size: 13px; }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.result-count { color: var(--muted); font-size: 13px; margin: 4px 0 12px; }

/* cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.card { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  background: var(--panel); text-decoration: none; transition: border-color .15s, transform .15s; }
.card:hover { border-color: var(--faint); transform: translateY(-1px); }
.thumb { aspect-ratio: 16 / 10; background: var(--hover); position: relative; overflow: hidden; display: grid; place-items: center; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .ph { font-size: 28px; font-weight: 650; color: var(--faint); letter-spacing: -.02em; }
.thumb .ph-note { position: absolute; bottom: 8px; left: 8px; font-size: 11px; color: var(--muted); }
.card-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 6px; }
.card-title { font-weight: 560; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-meta { font-size: 12px; color: var(--muted); }
.card-body .card-meta, .result-row .card-meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pills { display: flex; flex-wrap: wrap; gap: 4px; }
.pill { font-size: 11px; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.pill.ok { color: var(--ok); background: var(--ok-bg); border-color: transparent; }
.pill.warn { color: var(--warn); background: var(--warn-bg); border-color: transparent; }
.pill.bad { color: var(--bad); background: var(--bad-bg); border-color: transparent; }
.more { display: flex; justify-content: center; margin: 24px 0; }
.btn { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--panel); cursor: pointer; text-decoration: none; font-weight: 500; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.empty { border: 1px dashed var(--line); border-radius: var(--radius); padding: 28px; color: var(--muted); text-align: center; }

/* category tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.tile { display: flex; justify-content: space-between; gap: 8px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel); text-decoration: none; }
.tile:hover { border-color: var(--faint); }
.tile span { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

/* bars / tables */
.bar { height: 6px; border-radius: 999px; background: var(--hover); overflow: hidden; min-width: 80px; }
.bar i { display: block; height: 100%; background: var(--fg); border-radius: 999px; min-width: 2px; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; font-weight: 560; color: var(--muted); cursor: pointer; white-space: nowrap; }
td.num, th.num { text-align: right; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }

/* detail */
.detail-head { display: flex; flex-wrap: wrap; gap: 16px; justify-content: space-between; align-items: flex-start; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin: 20px 0 16px; overflow-x: auto; }
.tab { border: 0; background: transparent; padding: 10px 12px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tab[aria-selected="true"] { color: var(--fg); border-bottom-color: var(--fg); font-weight: 560; }
.preview-frame { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--panel); }
.preview-bar { display: flex; gap: 6px; align-items: center; padding: 8px; border-bottom: 1px solid var(--line); }
.preview-stage { position: relative; height: min(70vh, 720px); overflow: hidden; display: flex; justify-content: center; background: var(--hover); }
.preview-stage iframe { border: 0; background: #fff; height: 100%; width: 100%; }
.preview-stage.mobile iframe { width: 390px; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
.code-files { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
pre.code { margin: 0; padding: 16px; background: var(--code-bg); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto;
  max-height: 70vh; font: 12.5px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; tab-size: 2; }
.tok-kw { color: var(--tok-kw); } .tok-str { color: var(--tok-str); } .tok-com { color: var(--tok-com); font-style: italic; }
.tok-tag { color: var(--tok-tag); } .tok-num { color: var(--tok-num); }
dl.kv { display: grid; grid-template-columns: minmax(140px, 220px) minmax(0, 1fr); gap: 8px 16px; margin: 0; }
dl.kv dt { color: var(--muted); } dl.kv dd { margin: 0; overflow-wrap: anywhere; }
.callout { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; background: var(--panel); }
.callout.ok { border-color: color-mix(in srgb, var(--ok) 40%, var(--line)); }
.try-panel { margin-top: 14px; }
.app-shot { margin: 16px 0 0; } .app-shot img { width: 100%; max-width: 860px; border: 1px solid var(--line); border-radius: var(--radius); display: block; }
.callout.warn { border-color: color-mix(in srgb, var(--warn) 40%, var(--line)); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--accent); color: var(--accent-fg);
  padding: 8px 14px; border-radius: 999px; font-size: 13px; z-index: 50; }

/* explore navigation */
.skip { position: absolute; left: -999px; top: 8px; z-index: 100; background: var(--accent); color: var(--accent-fg); padding: 6px 12px; border-radius: 8px; }
.skip:focus { left: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.nav-back { display: flex; align-items: center; gap: 6px; width: 100%; height: 36px; padding: 0 8px; margin-bottom: 4px; border: 0; border-radius: 8px;
  background: transparent; cursor: pointer; color: var(--fg); font-weight: 560; }
.nav-back:hover { background: var(--hover); }
.nav-back .chev { color: var(--muted); }
.nav-back .title { flex: 1; text-align: center; margin-right: 24px; }
.nav-filter { display: flex; align-items: center; gap: 6px; height: 34px; margin: 0 2px 8px; padding: 0 10px; border-radius: 9px; background: var(--hover); color: var(--muted); }
.nav-filter input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--fg); }
.nav-section { margin: 16px 10px 6px; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); }
.nav-item .ico { width: 16px; height: 16px; flex: none; color: var(--faint); }
.nav-item[aria-current="page"] .ico { color: var(--fg); }
.nav-item .go { color: var(--faint); font-size: 12px; }
.nav-note { margin: 18px 10px 0; font-size: 11.5px; color: var(--faint); line-height: 1.45; }
.bottom-nav { display: none; }

/* explore cards */
.card { position: relative; }
.card-link { display: flex; flex-direction: column; flex: 1; text-decoration: none; color: inherit; }
.card-actions { padding: 0 12px 12px; display: flex; }
.card-actions .btn { height: 30px; padding: 0 10px; font-size: 12.5px; }
/* Direct link: the app's one canonical URL, always visible on its page */
.direct-link { margin-top: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); padding: 12px 14px;
  display: flex; flex-direction: column; gap: 8px; max-width: 860px; }
.direct-link-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.direct-link-label { font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.direct-link-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.direct-link-url { flex: 1 1 260px; min-width: 0; font-size: 14px; font-weight: 500; color: var(--fg); overflow-wrap: anywhere; }
.direct-link-url:hover { text-decoration: underline; }
.direct-link-actions { display: flex; gap: 8px; }
.direct-link-actions .btn { min-width: 76px; justify-content: center; }
.direct-link-actions .btn[data-state="copied"] { border-color: color-mix(in srgb, var(--ok) 50%, var(--line)); color: var(--ok); }
.direct-link-actions .btn[data-state="failed"] { border-color: color-mix(in srgb, var(--bad) 50%, var(--line)); color: var(--bad); }
.save-btn { position: absolute; top: 8px; right: 8px; z-index: 2; display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
  border: 1px solid var(--line); background: color-mix(in srgb, var(--panel) 85%, transparent); color: var(--muted); cursor: pointer; opacity: .9; }
.save-btn:hover { color: var(--fg); }
.save-btn[aria-pressed="true"] { color: var(--brand); border-color: color-mix(in srgb, var(--brand) 50%, var(--line)); }
.save-btn[aria-pressed="true"] svg path { fill: currentColor; }
.save-inline[aria-pressed="true"] { color: var(--brand); border-color: color-mix(in srgb, var(--brand) 50%, var(--line)); }
.save-inline[aria-pressed="true"] svg path { fill: currentColor; }
.save-inline[aria-pressed="true"] span::after { content: "d"; }
.scope-bar { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 4px; margin: 12px 0 4px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); }
.scope-bar .chip { border-color: transparent; height: 28px; }
.scope-bar .chip .n { font-size: 11px; opacity: .7; font-variant-numeric: tabular-nums; }
pre.file-list { max-height: 420px; font-size: 12px; }
dl.kv.avail { margin-bottom: 8px; }
.type-pill { font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; padding: 1px 6px; border-radius: 5px; background: var(--hover); color: var(--muted); }
.section-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.section-card { display: flex; flex-direction: column; gap: 6px; padding: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); text-decoration: none; }
.section-card:hover { border-color: var(--faint); }
.section-card b { font-size: 16px; }
.section-card .nums { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.section-card .bar { margin-top: 4px; }
.swatches { display: flex; gap: 6px; }
.swatches i { width: 22px; height: 22px; border-radius: 999px; border: 1px solid var(--line); display: block; }
.theme-thumb { width: 100%; height: 100%; display: flex; flex-direction: column; justify-content: space-between; padding: 14px; }
.icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.icon-cell { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 6px 8px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel); text-decoration: none; color: var(--fg); min-width: 0; }
.icon-cell:hover { border-color: var(--faint); }
.icon-cell svg { width: 26px; height: 26px; }
.icon-cell span { font-size: 11px; color: var(--muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-hero { display: grid; place-items: center; height: 220px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--fg); }
.icon-hero svg { width: 96px; height: 96px; }
.react-glyph { font: 600 13px ui-monospace, monospace; color: var(--muted); height: 24px; display: grid; place-items: center; }
.icon-play { align-items: center; flex-wrap: wrap; gap: 14px; margin-top: 12px; } .icon-play label { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.result-list { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); overflow: hidden; }
.result-row { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); text-decoration: none; }
.result-row:last-child { border-bottom: 0; }
.result-row:hover { background: var(--hover); }
.result-row .glyph { width: 36px; height: 36px; border-radius: 8px; background: var(--hover); display: grid; place-items: center; font-weight: 650; color: var(--muted); font-size: 13px; }
.result-row .glyph svg { width: 20px; height: 20px; color: var(--fg); }
.result-row .t { font-weight: 560; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.detail-title { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px; }
.detail-title > div:first-child { min-width: 0; }
.detail-title .card-meta { white-space: normal; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.pager { display: flex; justify-content: space-between; gap: 12px; margin: 28px 0 0; }
.pager a { flex: 1; max-width: 48%; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; background: var(--panel); }
.pager a:hover { border-color: var(--faint); }
.pager a small { display: block; color: var(--muted); font-size: 12px; }
.pager a.next { text-align: right; margin-left: auto; }
.progress-row { display: grid; grid-template-columns: 120px 1fr auto; gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }

/* mobile */
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .menu-btn, .close-btn { display: inline-grid; }
  .search kbd { display: none; }
  :root { --bottom: 60px; }
  .sidebar { position: fixed; z-index: 40; top: 0; left: 0; height: 100dvh; width: min(86vw, 320px); transform: translateX(-100%);
    transition: transform .24s cubic-bezier(.2,.8,.2,1), visibility .24s; visibility: hidden; box-shadow: 0 0 40px rgba(0,0,0,.35); }
  .sidebar.open { transform: none; visibility: visible; }
  .topbar .brand { margin-right: auto; }
  .topbar .search { display: none; }
  body { padding-bottom: calc(var(--bottom) + env(safe-area-inset-bottom)); }
  .bottom-nav { display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; z-index: 30; left: 0; right: 0; bottom: 0;
    height: calc(var(--bottom) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(12px); border-top: 1px solid var(--line); }
  .bottom-nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-decoration: none; color: var(--faint); font-size: 11px; }
  .bottom-nav a[aria-current="page"] { color: var(--fg); }
  .toast { bottom: calc(var(--bottom) + 16px); }
  .grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); }
  .pager a { max-width: none; }
  .result-row { grid-template-columns: 36px minmax(0, 1fr); }
  .result-row .pills { grid-column: 2; }
  .sidebar-head { display: flex; align-items: center; justify-content: space-between; height: var(--top); padding: 0 8px 0 18px;
    border-bottom: 1px solid var(--line); font-weight: 560; }
  .sidebar-scroll { height: calc(100% - var(--top)); }
  .scrim { position: fixed; inset: 0; z-index: 35; background: rgba(0,0,0,.5); animation: fade .2s ease; }
  main { padding: 20px 16px 64px; }
  .brand { font-size: 15px; }
  .theme-btn { display: none; }
  h1 { font-size: 22px; }
  dl.kv { grid-template-columns: minmax(0, 1fr); gap: 2px; } dl.kv dd { margin-bottom: 8px; }
}
@keyframes fade { from { opacity: 0; } }
@media (pointer: coarse) { .direct-link-actions .btn, .card-actions .btn { min-height: 44px; } }
@media (max-width: 560px) { .direct-link-actions { width: 100%; } .direct-link-actions .btn { flex: 1; } }
@media (max-width: 380px) { .stat { min-width: 0; flex: 1 1 130px; } main { padding-left: 12px; padding-right: 12px; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
