:root {
  color-scheme: light;
  --background: #fff;
  --foreground: #09090b;
  --card: #fff;
  --card-foreground: #09090b;
  --muted: #f4f4f5;
  --muted-foreground: #71717a;
  --popover: #fff;
  --popover-foreground: #09090b;
  --primary: #18181b;
  --primary-foreground: #fafafa;
  --secondary: #f4f4f5;
  --secondary-foreground: #18181b;
  --border: #e4e4e7;
  --input: #e4e4e7;
  --ring: #a1a1aa;
  --destructive: #dc2626;
  --radius: 0.625rem;
  --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.04);
  --header-height: 3.5rem;
  --page-width: 90rem;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --background: #09090b;
  --foreground: #fafafa;
  --card: #0c0c0f;
  --card-foreground: #fafafa;
  --muted: #18181b;
  --muted-foreground: #a1a1aa;
  --popover: #0c0c0f;
  --popover-foreground: #fafafa;
  --primary: #fafafa;
  --primary-foreground: #18181b;
  --secondary: #18181b;
  --secondary-foreground: #fafafa;
  --border: #27272a;
  --input: #27272a;
  --ring: #71717a;
  --destructive: #ef4444;
  --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.25);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--header-height) + 1.5rem); }
body { margin: 0; min-width: 320px; background: var(--background); color: var(--foreground); font: 400 15px/1.55 Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased; }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
a:hover { text-decoration: none; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 3px; }
code { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; }
.page-container { width: min(100%, var(--page-width)); margin: 0 auto; padding-inline: clamp(1rem, 3vw, 3rem); }
.eyebrow { margin: 0 0 .6rem; color: var(--muted-foreground); font-size: .72rem; font-weight: 600; letter-spacing: .09em; text-transform: uppercase; }

/* Collection header */
.global-header { position: sticky; z-index: 50; top: 0; height: var(--header-height); border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--background) 92%, transparent); backdrop-filter: blur(12px); }
.global-header-inner { display: flex; width: min(100%, var(--page-width)); height: 100%; margin: 0 auto; padding: 0 clamp(1rem, 3vw, 3rem); align-items: center; gap: 1.7rem; }
.brand-link { display: inline-flex; align-items: center; gap: .65rem; font-weight: 650; letter-spacing: -.02em; }
.brand-mark { display: inline-grid; width: 1.55rem; height: 1.55rem; place-items: center; border-radius: 50%; background: var(--foreground); color: var(--background); font-size: .72rem; font-weight: 800; }
.global-nav { display: flex; align-self: stretch; align-items: center; }
.global-nav a { display: inline-flex; height: 100%; align-items: center; color: var(--muted-foreground); font-size: .875rem; }
.global-nav a[aria-current="page"] { color: var(--foreground); }
.global-actions { display: flex; margin-left: auto; align-items: center; gap: .45rem; }
.search-trigger { display: inline-flex; min-width: 12rem; height: 2.15rem; margin: 0; padding: 0 .6rem; align-items: center; gap: .45rem; border: 1px solid var(--input); border-radius: .65rem; color: var(--muted-foreground); box-shadow: var(--shadow-sm); font-size: .82rem; }
.search-trigger svg, .icon-button svg { width: 1rem; height: 1rem; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; }
.search-trigger input { width: 7rem; min-width: 0; padding: 0; border: 0; outline: 0; background: transparent; color: var(--foreground); }
.search-trigger input::placeholder { color: var(--muted-foreground); }
.search-trigger:focus-within { outline: 2px solid var(--ring); outline-offset: 2px; }
.search-trigger kbd { margin-left: auto; padding: .05rem .35rem; border: 1px solid var(--border); border-radius: .3rem; background: var(--muted); font: inherit; }
.icon-button, .demo-back { display: inline-grid; width: 2.15rem; height: 2.15rem; place-items: center; border: 1px solid transparent; border-radius: .55rem; }
.icon-button:hover, .demo-back:hover { border-color: var(--border); background: var(--muted); }
.theme-toggle { display: inline-flex; padding: .15rem; border: 1px solid var(--border); border-radius: .65rem; background: var(--background); }
.theme-toggle button { display: inline-grid; width: 1.8rem; height: 1.8rem; padding: 0; place-items: center; border: 0; border-radius: .45rem; background: transparent; color: var(--muted-foreground); cursor: pointer; font-size: .88rem; }
.theme-toggle button:hover { color: var(--foreground); }
.theme-toggle button.active { background: var(--secondary); color: var(--secondary-foreground); }

/* Catalogue */
.catalogue-page { padding-top: clamp(3.5rem, 7vw, 6.5rem); padding-bottom: 6rem; }
.catalogue-heading { display: flex; align-items: end; justify-content: space-between; gap: 2rem; padding-bottom: 2.25rem; border-bottom: 1px solid var(--border); }
.catalogue-heading h1 { margin: 0; font-size: clamp(2.25rem, 5vw, 4.25rem); line-height: 1; letter-spacing: -.055em; }
.catalogue-heading p:not(.eyebrow) { max-width: 44rem; margin: 1rem 0 0; color: var(--muted-foreground); font-size: 1rem; }
.catalogue-count, .preview-note { flex: none; padding: .25rem .55rem; border: 1px solid var(--border); border-radius: 999px; color: var(--muted-foreground); font-size: .75rem; }
.search-box { width: min(100%, 22rem); height: 2.45rem; padding: 0 .8rem 0 2.35rem; border: 1px solid var(--input); border-radius: .55rem; background: var(--background) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") .75rem center no-repeat; color: var(--foreground); box-shadow: var(--shadow-sm); }
.search-box::placeholder { color: var(--muted-foreground); }
.systems-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1.15rem; padding-top: 1.5rem; }
.system-card { min-width: 0; }
.system-card-link { display: block; overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); color: var(--card-foreground); transition: border-color 150ms ease, transform 150ms ease; }
.system-card-link:hover { border-color: color-mix(in srgb, var(--foreground) 40%, var(--border)); transform: translateY(-2px); }
.system-card-link:active { transform: translateY(0); }
.system-card-preview { position: relative; height: 15.5rem; overflow: hidden; border-bottom: 1px solid var(--border); background: var(--muted); pointer-events: none; }
.system-card-preview::after { position: absolute; inset: 0; content: ""; box-shadow: inset 0 0 0 1px rgb(0 0 0 / .025); }
.system-card-preview iframe { width: 160%; height: 160%; border: 0; transform: scale(.625); transform-origin: top left; background: #fff; }
.preview-unavailable { display: flex; height: 100%; align-items: center; justify-content: center; gap: .6rem; color: var(--muted-foreground); }
.system-card-footer { display: flex; min-height: 5rem; padding: 1rem; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.system-card-copy h2 { margin: 0; font-size: .98rem; letter-spacing: -.015em; }
.system-card-copy p { margin: .35rem 0 0; color: var(--muted-foreground); font-size: .76rem; }
.status-badge, .version-badge { display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 999px; color: var(--muted-foreground); font-size: .68rem; font-weight: 600; line-height: 1.5rem; padding: 0 .5rem; text-transform: capitalize; }
.status-badge[data-status="active"]::before { width: .38rem; height: .38rem; margin-right: .35rem; border-radius: 50%; background: #22c55e; content: ""; }
.empty-state { display: grid; min-height: 18rem; padding: 3rem; place-items: center; align-content: center; border: 1px dashed var(--border); border-radius: var(--radius); text-align: center; }
.empty-state-icon { color: var(--muted-foreground); font-size: 2rem; }
.empty-state h2 { margin: .7rem 0 .25rem; font-size: 1rem; }
.empty-state p { margin: 0; color: var(--muted-foreground); }

/* Detail page */
.detail-page { padding-top: 2.25rem; padding-bottom: 7rem; }
.breadcrumb { display: flex; align-items: center; gap: .55rem; color: var(--muted-foreground); font-size: .82rem; }
.breadcrumb a:hover { color: var(--foreground); }
.system-hero { display: flex; padding: clamp(3rem, 7vw, 6.5rem) 0; align-items: flex-end; justify-content: space-between; gap: 3rem; }
.system-hero-copy { max-width: 48rem; }
.eyebrow-row { display: flex; align-items: center; gap: .65rem; color: var(--muted-foreground); font-size: .78rem; }
.system-hero h1 { margin: 1.2rem 0 .8rem; font-size: clamp(2.8rem, 7vw, 5.75rem); line-height: .95; letter-spacing: -.065em; }
.system-hero-copy > p { max-width: 43rem; margin: 0; color: var(--muted-foreground); font-size: 1.05rem; }
.system-actions { display: flex; flex: none; gap: .65rem; }
.button { display: inline-flex; height: 2.65rem; padding: 0 1.1rem; align-items: center; justify-content: center; gap: .45rem; border: 1px solid var(--border); border-radius: .55rem; font-size: .86rem; font-weight: 550; }
.button-primary { border-color: var(--primary); background: var(--primary); color: var(--primary-foreground); }
.button-secondary { background: var(--background); }
.button:hover { opacity: .88; }
.detail-section { padding: 4.5rem 0; border-top: 1px solid var(--border); }
.section-heading { max-width: 44rem; margin-bottom: 1.75rem; }
.section-heading h2 { margin: 0; font-size: clamp(1.75rem, 3vw, 2.4rem); letter-spacing: -.04em; }
.section-heading > p:not(.eyebrow), .section-heading div > p:not(.eyebrow) { margin: .6rem 0 0; color: var(--muted-foreground); }
.split-heading { display: flex; max-width: none; align-items: end; justify-content: space-between; gap: 1rem; }
.live-preview-frame { overflow: hidden; border: 1px solid var(--border); border-radius: calc(var(--radius) + .15rem); background: var(--muted); box-shadow: var(--shadow-sm); }
.browser-bar { display: grid; height: 2.6rem; padding: 0 .85rem; grid-template-columns: 1fr auto 1fr; align-items: center; border-bottom: 1px solid var(--border); background: var(--card); }
.browser-dots { display: flex; gap: .35rem; }
.browser-dots i { width: .52rem; height: .52rem; border-radius: 50%; background: #ef4444; }
.browser-dots i:nth-child(2) { background: #eab308; }
.browser-dots i:nth-child(3) { background: #22c55e; }
.browser-address { color: var(--muted-foreground); font: .7rem "SFMono-Regular", Consolas, monospace; }
.browser-open-icon { display: flex; justify-content: flex-end; color: var(--muted-foreground); }
.browser-open-icon svg { width: .95rem; fill: none; stroke: currentColor; stroke-width: 1.8; }
.live-preview-frame iframe { display: block; width: 100%; height: min(68vh, 46rem); border: 0; background: #fff; }
.preview-loading { display: flex; min-height: 30rem; align-items: center; justify-content: center; gap: .65rem; color: var(--muted-foreground); }
.live-preview-frame[data-preview-state="loading"] iframe { position: absolute; width: 1px; height: 1px; opacity: 0; }
.live-preview-frame[data-preview-state="ready"] .preview-loading { display: none; }
.live-preview-frame[data-preview-state="error"] iframe { display: none; }
.live-preview-frame[data-preview-state="error"] .preview-loading span:last-child { font-size: 0; }
.live-preview-frame[data-preview-state="error"] .preview-loading span:last-child::after { content: "The preview could not be loaded."; font-size: .9rem; }
.spinner { width: 1rem; height: 1rem; border: 2px solid var(--border); border-top-color: var(--foreground); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.inventory-grid { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--border); border-radius: var(--radius); }
.inventory-grid > div { min-height: 8.5rem; padding: 1.3rem; border-right: 1px solid var(--border); }
.inventory-grid > div:last-child { border: 0; }
.inventory-grid dt { color: var(--muted-foreground); font-size: .78rem; }
.inventory-grid dd { margin: .65rem 0 .1rem; font-size: 2rem; font-weight: 650; letter-spacing: -.04em; }
.inventory-grid small { color: var(--muted-foreground); }
.document-links { display: flex; margin-top: 1rem; gap: 1.5rem; color: var(--muted-foreground); font-size: .82rem; }
.document-links a:hover { color: var(--foreground); }

/* Unified live demo */
.demo-header { position: sticky; z-index: 60; top: 0; display: flex; height: var(--header-height); padding: 0 1rem; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--background) 94%, transparent); backdrop-filter: blur(12px); }
.demo-header-start, .demo-header-end { display: flex; align-items: center; gap: .55rem; }
.demo-system-name { margin-left: .2rem; font-weight: 650; }
.demo-catalogue-link { margin-right: .5rem; color: var(--muted-foreground); font-size: .8rem; }
.demo-catalogue-link:hover { color: var(--foreground); }
.sidebar-open, .sidebar-close { display: none; border: 0; background: transparent; color: inherit; cursor: pointer; }
.demo-layout { display: grid; grid-template-columns: 16.5rem minmax(0, 1fr); }
.demo-sidebar { position: sticky; top: var(--header-height); height: calc(100vh - var(--header-height)); padding: 1.5rem 1rem 2rem; overflow-y: auto; border-right: 1px solid var(--border); background: var(--background); }
.demo-sidebar-head { display: flex; padding: 0 .65rem .7rem; align-items: center; justify-content: space-between; color: var(--muted-foreground); font-size: .7rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }
.demo-nav-list, .demo-nav-list ul { margin: 0; padding: 0; list-style: none; }
.demo-nav-list > li { margin-bottom: .2rem; }
.demo-nav-list a { display: block; padding: .42rem .65rem; border-radius: .42rem; color: var(--muted-foreground); font-size: .82rem; text-transform: capitalize; }
.demo-nav-list a:hover { background: var(--muted); color: var(--foreground); }
.demo-nav-list a.active { background: var(--muted); color: var(--foreground); font-weight: 550; }
.demo-nav-list ul { margin: .1rem 0 .5rem .7rem; padding-left: .65rem; border-left: 1px solid var(--border); }
.demo-nav-list ul a { padding-block: .32rem; font-size: .76rem; }
.sidebar-scrim { display: none; }
.demo-main { min-width: 0; max-width: 82rem; padding: 0 clamp(1.25rem, 4vw, 4.5rem) 8rem; }
.demo-section { padding: clamp(4rem, 8vw, 7rem) 0; border-bottom: 1px solid var(--border); }
.demo-section:last-child { border-bottom: 0; }
.demo-intro { padding-top: clamp(5rem, 10vw, 9rem); }
.demo-intro h1 { margin: 0; font-size: clamp(3.2rem, 8vw, 7rem); line-height: .92; letter-spacing: -.07em; }
.demo-intro > p:not(.eyebrow) { max-width: 48rem; margin: 1.25rem 0 2.5rem; color: var(--muted-foreground); font-size: 1.05rem; }
.inventory-grid.compact > div { min-height: 6rem; }
.inventory-grid.compact dd { margin-bottom: 0; }
.demo-section-heading { display: grid; max-width: 54rem; margin-bottom: 3rem; grid-template-columns: 2.5rem 1fr; gap: 1rem; }
.demo-section-heading > span { color: var(--muted-foreground); font: .75rem "SFMono-Regular", Consolas, monospace; }
.demo-section-heading h2 { margin: -.25rem 0 .4rem; font-size: clamp(2rem, 4vw, 3.25rem); letter-spacing: -.05em; }
.demo-section-heading p { margin: 0; color: var(--muted-foreground); }
.demo-subsection { padding: 2.5rem 0; scroll-margin-top: calc(var(--header-height) + 1rem); }
.demo-subsection + .demo-subsection { border-top: 1px solid var(--border); }
.subsection-title { display: flex; margin-bottom: 1.25rem; align-items: center; justify-content: space-between; gap: 1rem; }
.subsection-title h3 { margin: 0; font-size: 1.15rem; letter-spacing: -.02em; text-transform: capitalize; }
.subsection-title span { color: var(--muted-foreground); font-size: .74rem; }
.token-list { overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius); }
.token-row { display: grid; min-height: 2.65rem; padding: .55rem .8rem; grid-template-columns: minmax(14rem, 1fr) minmax(0, 1fr); align-items: center; gap: 1rem; border-bottom: 1px solid var(--border); font-size: .76rem; }
.token-row:last-child { border: 0; }
.token-name { display: flex; min-width: 0; align-items: center; gap: .55rem; }
.token-swatch { width: 1rem; height: 1rem; flex: none; border: 1px solid var(--border); border-radius: .25rem; background-image: linear-gradient(45deg, #bbb 25%, transparent 25%), linear-gradient(-45deg, #bbb 25%, transparent 25%); }
.token-value { min-width: 0; overflow-wrap: anywhere; color: var(--muted-foreground); }
.component-chip-list { display: flex; margin: 1rem 0 0; padding: 0; flex-wrap: wrap; gap: .45rem; list-style: none; }
.component-chip-list li { padding: .28rem .55rem; border: 1px solid var(--border); border-radius: .4rem; background: var(--secondary); color: var(--secondary-foreground); font-size: .72rem; }
.iframe-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.iframe-card { overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); }
.iframe-card-title { display: flex; min-height: 3.2rem; padding: .7rem .9rem; flex-direction: column; justify-content: center; border-bottom: 1px solid var(--border); }
.iframe-card-title .name { font-size: .8rem; font-weight: 600; }
.iframe-card-title .subtitle { overflow: hidden; color: var(--muted-foreground); font-size: .7rem; text-overflow: ellipsis; white-space: nowrap; }
.iframe-card iframe { display: block; width: 100%; border: 0; background: #fff; }
.iframe-card[data-iframe-state="loading"] { background: linear-gradient(90deg, var(--muted), var(--card), var(--muted)); background-size: 220% 100%; animation: loading 1.4s ease infinite; }
.iframe-card[data-iframe-state="error"] iframe { display: none; }
.iframe-card[data-iframe-state="error"]::after { display: grid; min-height: 12rem; place-items: center; color: var(--muted-foreground); content: "Preview unavailable"; }
@keyframes loading { to { background-position: -220% 0; } }
.full-page-list { display: grid; gap: 1.5rem; }
.iframe-card.full-page iframe { height: 72vh; min-height: 34rem; }

/* Compatibility routes retained during migration */
.shell { display: flex; min-height: 100vh; }
.shell-nav { width: 14rem; flex: none; padding: 1.5rem 1rem; border-right: 1px solid var(--border); }
.shell-main { min-width: 0; flex: 1; padding: 2rem; }
.nav-title { margin: 0 0 .5rem; color: var(--muted-foreground); font-size: .72rem; text-transform: uppercase; }
.nav-list { margin: 0 0 1.25rem; padding: 0; list-style: none; }
.nav-list a { display: block; padding: .35rem .5rem; border-radius: .4rem; }
.nav-list a:hover, .nav-list a.active { background: var(--muted); }
.page-header { margin-bottom: 2rem; }
.page-header h1 { margin: 0; }
.meta { color: var(--muted-foreground); font-size: .8rem; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr)); gap: 1rem; }
.plain-card { padding: 1rem; border: 1px solid var(--border); border-radius: var(--radius); }
.plain-card h2, .plain-card h3 { margin: 0 0 .3rem; }
.token-table { width: 100%; border-collapse: collapse; font-size: .8rem; }
.token-table th, .token-table td { padding: .45rem .6rem; border-bottom: 1px solid var(--border); text-align: left; }

@media (max-width: 1040px) {
  .systems-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .demo-layout { grid-template-columns: 14.5rem minmax(0, 1fr); }
  .iframe-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  :root { --header-height: 3.25rem; }
  .global-header-inner { gap: .8rem; }
  .global-nav, .search-trigger kbd, .global-actions > .icon-button { display: none; }
  .search-trigger { min-width: 7rem; width: 7rem; }
  .search-trigger input { width: 4.8rem; }
  .catalogue-heading, .system-hero, .split-heading { align-items: flex-start; flex-direction: column; }
  .catalogue-count { align-self: flex-start; }
  .systems-grid { grid-template-columns: 1fr; }
  .system-card-preview { height: 13rem; }
  .system-hero { padding-block: 3.5rem; }
  .system-actions { width: 100%; }
  .system-actions .button { flex: 1; }
  .live-preview-frame iframe { height: 30rem; }
  .preview-loading { min-height: 22rem; }
  .inventory-grid { grid-template-columns: repeat(2, 1fr); }
  .inventory-grid > div { border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }
  .inventory-grid > div:nth-child(2n) { border-right: 0; }
  .inventory-grid > div:nth-last-child(-n+2) { border-bottom: 0; }
  .document-links { flex-direction: column; gap: .55rem; }
  .demo-catalogue-link { display: none; }
  .sidebar-open, .sidebar-close { display: inline-grid; width: 2rem; height: 2rem; place-items: center; }
  .demo-layout { display: block; }
  .demo-sidebar { position: fixed; z-index: 80; top: 0; left: 0; width: min(19rem, 86vw); height: 100vh; transform: translateX(-105%); transition: transform 180ms ease; box-shadow: 10px 0 30px rgb(0 0 0 / .18); }
  .sidebar-open .demo-sidebar { transform: none; }
  .sidebar-scrim { position: fixed; z-index: 70; inset: 0; border: 0; background: rgb(0 0 0 / .48); }
  .sidebar-open .sidebar-scrim { display: block; }
  .demo-main { padding-inline: 1.1rem; }
  .token-row { grid-template-columns: 1fr; gap: .15rem; }
  .iframe-card.full-page iframe { height: 65vh; min-height: 28rem; }
  .shell { flex-direction: column; }
  .shell-nav { width: 100%; border-right: 0; border-bottom: 1px solid var(--border); }
}

@media (max-width: 440px) {
  .brand-link > span:last-child { display: none; }
  .system-actions { flex-direction: column; }
  .inventory-grid { grid-template-columns: 1fr; }
  .inventory-grid > div, .inventory-grid > div:nth-child(2n), .inventory-grid > div:nth-last-child(-n+2) { border-right: 0; border-bottom: 1px solid var(--border); }
  .inventory-grid > div:last-child { border-bottom: 0; }
  .browser-address { max-width: 10rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
