/* Bib UI application chrome. Falls back to a neutral theme until tokens load. */
:root {
  --background: #fafaf9;
  --foreground: #0c0a09;
  --card: #ffffff;
  --card-foreground: #0c0a09;
  --popover: #ffffff;
  --popover-foreground: #0c0a09;
  --primary: #6366f1;
  --primary-foreground: #ffffff;
  --secondary: #f5f5f4;
  --secondary-foreground: #1c1917;
  --muted: #f5f5f4;
  --muted-foreground: #78716c;
  --accent: #eef2ff;
  --accent-foreground: #4338ca;
  --destructive: #dc2626;
  --destructive-foreground: #ffffff;
  --border: #e7e5e4;
  --input: #e7e5e4;
  --ring: #6366f1;
  --success: #16a34a;
  --success-foreground: #ffffff;
  --warning: #f59e0b;
  --warning-foreground: #1c1917;
  --info: #0284c7;
  --info-foreground: #ffffff;
  --radius: 0.625rem;
  --radius-sm: calc(var(--radius) - 4px);
  --radius-md: calc(var(--radius) - 2px);
  --radius-lg: var(--radius);
  --radius-xl: calc(var(--radius) + 4px);
  --spacing: 0.25rem;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", ui-sans-serif, system-ui, sans-serif;
  --font-display: var(--font-sans);
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --code-bg: #14110f;
  --code-fg: #e7e2dc;
  --code-muted: #7c736b;
  --shadow-sm: 0 1px 2px rgb(28 25 23 / 0.04);
  --shadow-md: 0 1px 2px rgb(28 25 23 / 0.04), 0 10px 30px -18px rgb(28 25 23 / 0.18);
  --shadow-lg: 0 1px 2px rgb(28 25 23 / 0.04), 0 24px 48px -24px rgb(28 25 23 / 0.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background-color: var(--background);
  background-image: radial-gradient(900px 420px at 12% -8%, color-mix(in srgb, var(--primary) 6%, transparent), transparent 70%);
  background-attachment: fixed;
  color: var(--foreground);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
code, pre { font-family: var(--font-mono); }
::selection { background: color-mix(in srgb, var(--primary) 26%, transparent); }

.app {
  display: grid;
  grid-template-columns: 252px minmax(0, 1fr);
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 20px 16px 16px;
  background: color-mix(in srgb, var(--card) 97%, var(--primary) 3%);
  border-right: 1px solid var(--border);
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 4px; }
.logo {
  width: 32px; height: 32px; flex: none;
  display: grid; place-items: center;
  border-radius: 10px;
  background: linear-gradient(140deg, var(--primary), color-mix(in srgb, var(--primary) 55%, #000));
  color: #fff; font-weight: 800; font-size: 15px;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / .25), 0 6px 16px -8px var(--primary);
}
.brand-text { display: grid; line-height: 1.15; }
.brand-text strong { font-size: 14px; letter-spacing: -.01em; }
.brand-text span { font-size: 10.5px; color: var(--muted-foreground); letter-spacing: .02em; text-transform: uppercase; }

.nav { display: grid; gap: 3px; }
.nav button {
  display: flex; align-items: center; gap: 10px;
  height: 36px; padding: 0 10px;
  border: 0; border-radius: 9px;
  background: transparent; color: var(--muted-foreground);
  font-size: 13px; font-weight: 500; text-align: left;
  transition: background .12s, color .12s;
}
.nav button:hover { background: var(--muted); color: var(--foreground); }
.nav button.active { background: color-mix(in srgb, var(--primary) 10%, var(--card)); color: var(--foreground); font-weight: 600; }
.nav button.active .nav-ico { color: var(--primary); opacity: 1; }
.nav-ico { width: 16px; text-align: center; font-size: 13px; opacity: .8; }

.side-section { display: grid; gap: 8px; min-height: 0; overflow: auto; padding-right: 2px; }
.side-label {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 6px;
  font-size: 10.5px; font-weight: 600; letter-spacing: .09em; text-transform: uppercase;
  color: var(--muted-foreground);
}
.scale-list { display: grid; gap: 2px; }
.scale-item {
  display: grid; gap: 5px;
  padding: 7px 8px; border: 0; border-radius: 9px;
  background: transparent; text-align: left;
}
.scale-item:hover { background: var(--muted); }
.scale-item.active { background: var(--secondary); }
.scale-item .top { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.scale-item .role { font-size: 12px; font-weight: 600; text-transform: capitalize; }
.scale-item .fname { font-size: 10px; color: var(--muted-foreground); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-swatches { display: flex; height: 6px; border-radius: 999px; overflow: hidden; }
.mini-swatches span { flex: 1; }

.side-footer { margin-top: auto; display: grid; gap: 8px; padding: 10px 6px 4px; border-top: 1px solid var(--border); }
.theme-toggle {
  display: flex; align-items: center; gap: 9px;
  height: 34px; padding: 0 8px;
  border: 1px solid var(--border); border-radius: 9px;
  background: var(--card); font-size: 12px; font-weight: 500;
}
.theme-toggle:hover { background: var(--muted); }
.theme-dot { width: 14px; height: 14px; border-radius: 50%; background: linear-gradient(90deg, #111 50%, #fafafa 50%); border: 1px solid var(--border); }
.save-line { display: grid; gap: 1px; padding: 0 2px; }
.save-status { font-size: 11px; color: var(--muted-foreground); display: flex; align-items: center; gap: 5px; }
.save-status::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: var(--success); }
.save-status.saving::before { background: var(--warning); }
.save-status.error::before { background: var(--destructive); }
.path-hint { font-family: var(--font-mono); font-size: 9.5px; color: var(--muted-foreground); opacity: .7; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Main ---------- */
.main { min-width: 0; padding: 22px 28px 48px; }
.topbar {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 24px;
  margin-bottom: 20px;
}
.topbar-text h1 { margin: 0; font-family: var(--font-sans); font-size: 26px; font-weight: 700; letter-spacing: -.035em; }
.topbar-text p { margin: 3px 0 0; color: var(--muted-foreground); font-size: 13px; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 34px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 9px;
  background: var(--card); color: var(--foreground);
  font-size: 12.5px; font-weight: 500; white-space: nowrap;
  box-shadow: var(--shadow-sm);
  transition: background .12s, border-color .12s, transform .06s;
}
.btn:hover { background: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); border-color: transparent; color: var(--primary-foreground); }
.btn.primary:hover { background: color-mix(in srgb, var(--primary) 90%, #000); }
.btn.ghost { background: transparent; box-shadow: none; }
.btn.ghost:hover { background: var(--muted); }
.btn.tiny, .ghost.tiny { height: 26px; padding: 0 8px; font-size: 11.5px; border-radius: 7px; }
kbd {
  font-family: var(--font-mono); font-size: 9.5px; padding: 1px 4px;
  border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px;
  color: var(--muted-foreground); background: var(--card);
}
.theme-switch { display: flex; padding: 2px; gap: 2px; background: var(--muted); border-radius: 9px; }
.theme-switch button {
  height: 28px; padding: 0 10px; border: 0; border-radius: 7px;
  background: transparent; color: var(--muted-foreground); font-size: 11.5px; font-weight: 500;
}
.theme-switch button.active { background: var(--card); color: var(--foreground); box-shadow: var(--shadow-sm); }

.view { display: none; }
.view.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-md);
  min-width: 0;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 46px; padding: 0 16px;
  border-bottom: 1px solid var(--border);
  font-size: 12px; font-weight: 600; letter-spacing: .02em;
}
.panel-head .panel-meta, .panel-meta { color: var(--muted-foreground); font-weight: 500; font-size: 11px; letter-spacing: 0; }
.panel-subhead {
  padding: 14px 16px 8px;
  font-size: 10.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted-foreground);
}
.head-actions { display: flex; align-items: center; gap: 6px; }
.panel-meta .dot { display: inline-block; width: 5px; height: 5px; border-radius: 50%; background: var(--success); margin-right: 4px; vertical-align: 1px; }

.gen-grid, .tokens-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(340px, .85fr); gap: 18px; align-items: start; }
.tokens-grid { grid-template-columns: minmax(0, 1.2fr) minmax(340px, .8fr); }

/* ---------- Generator ---------- */
#primary-editor { padding: 16px; }
.primary-card {
  position: relative; overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--primary) 22%, var(--border));
  border-radius: 12px;
  padding: 16px;
  background:
    radial-gradient(120% 140% at 100% 0%, color-mix(in srgb, var(--primary) 16%, transparent), transparent 55%),
    linear-gradient(135deg, color-mix(in srgb, var(--primary) 8%, var(--card)), var(--card));
}
.primary-eyebrow { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.primary-eyebrow .label { font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted-foreground); font-weight: 600; }
.primary-eyebrow .name { font-size: 12px; font-weight: 600; }
.primary-row { display: flex; align-items: center; gap: 10px; }
.color-picker-wrap { position: relative; width: 46px; height: 46px; flex: none; }
.color-picker-wrap input[type="color"] {
  position: absolute; inset: 0; width: 100%; height: 100%;
  border: 0; padding: 0; background: none; cursor: pointer; opacity: 0;
}
.color-big {
  width: 46px; height: 46px; border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--foreground) 14%, transparent);
  box-shadow: inset 0 0 0 3px var(--card), 0 8px 18px -12px var(--primary);
  pointer-events: none;
}
.hex-input {
  height: 46px; min-width: 0; flex: 1;
  padding: 0 12px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--card); color: var(--foreground);
  font-family: var(--font-mono); font-size: 15px; letter-spacing: .03em;
  outline: none;
}
.hex-input:focus { border-color: var(--ring); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 18%, transparent); }
.primary-meta { display: flex; align-items: center; gap: 8px; margin-top: 10px; color: var(--muted-foreground); font-size: 11.5px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 7px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--card);
  font-size: 10.5px; font-weight: 500; color: var(--muted-foreground); white-space: nowrap;
}
.chip.strong { color: var(--foreground); }
.chip.action { cursor: pointer; color: var(--foreground); }
.chip.action:hover { background: var(--muted); border-color: var(--foreground); }

.scales-editor { display: grid; }
.scale-block { border-top: 1px solid var(--border); padding: 14px 16px 16px; min-width: 0; }
.scale-block:first-child { border-top: 0; }
.scale-block.highlight { background: color-mix(in srgb, var(--primary) 4%, transparent); }
.scale-block-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.scale-block-title { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.scale-block-title .role { font-size: 12.5px; font-weight: 650; text-transform: capitalize; }
.scale-block-title .pname { font-size: 11px; color: var(--muted-foreground); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scale-block-actions { display: flex; align-items: center; gap: 2px; opacity: .35; transition: opacity .12s; }
.scale-block:hover .scale-block-actions { opacity: 1; }
.icon-btn {
  width: 26px; height: 26px; display: grid; place-items: center;
  border: 0; border-radius: 6px; background: transparent; color: var(--muted-foreground);
}
.icon-btn:hover { background: var(--muted); color: var(--foreground); }
.color-mini { width: 24px; height: 24px; padding: 0; border: 1px solid var(--border); border-radius: 6px; background: transparent; cursor: pointer; }
.color-mini::-webkit-color-swatch-wrapper { padding: 2px; }
.color-mini::-webkit-color-swatch { border: 0; border-radius: 4px; }
.swatches { display: flex; gap: 4px; }
.swatch {
  position: relative; flex: 1; min-width: 0; height: 56px;
  border: 1px solid rgb(0 0 0 / .06); border-radius: 7px;
  padding: 0; transition: transform .1s, box-shadow .1s;
}
.swatch:hover { transform: translateY(-2px); box-shadow: 0 6px 14px -8px rgb(0 0 0 / .4); z-index: 2; }
.swatch .n {
  position: absolute; left: 5px; bottom: 4px;
  font-family: var(--font-mono); font-size: 8.5px; font-weight: 600;
  color: rgb(0 0 0 / .55); mix-blend-mode: normal;
}
.swatch.dark-label .n { color: rgb(255 255 255 / .7); }
.swatch .copy-hint {
  position: absolute; inset: auto 0 0 0; padding: 2px 0 3px;
  font-size: 8px; text-align: center; opacity: 0; background: rgb(0 0 0 / .55); color: #fff;
  border-radius: 0 0 6px 6px;
}
.swatch:hover .copy-hint { opacity: 1; }
.scale-foot { display: flex; justify-content: space-between; gap: 8px; margin-top: 6px; min-width: 0; }
.scale-foot .hexline { font-family: var(--font-mono); font-size: 9.5px; color: var(--muted-foreground); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1; }
.scale-foot .anchorline { font-size: 9.5px; color: var(--muted-foreground); white-space: nowrap; flex: none; }

/* ---------- Preview ---------- */
.preview-panel { position: sticky; top: 22px; max-height: calc(100vh - 44px); overflow: auto; scrollbar-width: thin; }
.preview-canvas { padding: 16px; display: grid; gap: 12px; }
.pv-hero {
  position: relative; overflow: hidden;
  border: 1px solid var(--border); border-radius: 12px;
  padding: 20px;
  background:
    radial-gradient(100% 120% at 90% -10%, color-mix(in srgb, var(--primary) 24%, transparent), transparent 60%),
    var(--card);
}
.pv-hero h2 {
  margin: 10px 0 6px; max-width: 24ch;
  font-family: var(--font-display); font-size: 27px; line-height: 1.08; letter-spacing: -.035em;
}
.pv-hero p { margin: 0 0 16px; max-width: 40ch; color: var(--muted-foreground); font-size: 12.5px; line-height: 1.55; }
.pv-badge {
  display: inline-flex; align-items: center; gap: 5px; height: 20px; padding: 0 8px;
  border-radius: 999px; background: color-mix(in srgb, var(--primary) 12%, transparent);
  color: var(--primary); font-size: 10px; font-weight: 650; letter-spacing: .02em;
  border: 1px solid color-mix(in srgb, var(--primary) 22%, transparent);
}
.pv-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pv-stat { border: 1px solid var(--border); border-radius: 10px; padding: 10px 11px; background: var(--card); }
.pv-stat .k { font-size: 9.5px; color: var(--muted-foreground); letter-spacing: .04em; text-transform: uppercase; }
.pv-stat .v { margin-top: 2px; font-size: 17px; font-weight: 700; letter-spacing: -.03em; }
.pv-stat .d { font-size: 9.5px; color: var(--success); font-weight: 600; }
.pv-card { border: 1px solid var(--border); border-radius: 12px; background: var(--card); padding: 14px; display: grid; gap: 10px; }
.pv-card-title { font-size: 12px; font-weight: 650; display: flex; align-items: center; justify-content: space-between; }
.pv-card-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 11.5px; }
.pv-swatches { display: flex; gap: 3px; }
.pv-swatches span { width: 18px; height: 18px; border-radius: 5px; border: 1px solid rgb(0 0 0 / .06); }
.contrast-list { display: grid; gap: 4px; margin-top: 2px; }
.contrast-row { display: flex; align-items: center; justify-content: space-between; font-size: 10.5px; color: var(--muted-foreground); }
.contrast-row code { font-size: 10px; }
.ratio {
  font-family: var(--font-mono); font-size: 9.5px; font-weight: 700; padding: 1px 5px; border-radius: 4px;
  background: var(--muted); color: var(--muted-foreground);
}
.ratio.pass { color: #166534; background: #dcfce7; }
.ratio.fail { color: #991b1b; background: #fee2e2; }
.mini-check { display: flex; align-items: center; gap: 5px; font-size: 10.5px; color: var(--muted-foreground); font-weight: 500; }

/* ---------- Tokens ---------- */
.token-table-wrap { overflow: visible; }
.token-table { width: 100%; border-collapse: collapse; font-size: 11.5px; }
.token-table th {
  position: sticky; top: 0; z-index: 2;
  padding: 8px 12px; text-align: left;
  background: var(--card); border-bottom: 1px solid var(--border);
  font-size: 9.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted-foreground);
}
.token-table td { padding: 3px 8px; border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent); }
.token-table tr:last-child td { border-bottom: 0; }
.token-table .tok { font-family: var(--font-mono); font-size: 10.5px; color: var(--foreground); padding-left: 12px; }
.color-cell {
  display: flex; align-items: center; gap: 7px; width: 100%;
  padding: 4px 6px; border: 1px solid transparent; border-radius: 7px;
  background: transparent; text-align: left;
}
.color-cell:hover { border-color: var(--border); background: var(--muted); }
.color-cell .dot { width: 16px; height: 16px; border-radius: 50%; border: 1px solid rgb(0 0 0 / .12); flex: none; box-shadow: inset 0 0 0 2px rgb(255 255 255 / .18); }
.color-cell code { font-size: 10px; }
.color-cell small { color: var(--muted-foreground); font-size: 9.5px; margin-left: auto; font-family: var(--font-mono); }

.field-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; padding: 4px 16px 14px; }
.field { display: grid; gap: 4px; min-width: 0; }
.field label { font-size: 10px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted-foreground); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.field label output { font-family: var(--font-mono); font-size: 10px; color: var(--muted-foreground); letter-spacing: 0; text-transform: none; }
.field input, .field select {
  height: 32px; padding: 0 9px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--background); font-size: 11.5px; outline: none;
  min-width: 0;
}
.field input[type="range"] { height: 24px; padding: 0; border: 0; background: transparent; accent-color: var(--primary); cursor: pointer; }
.field input:focus, .field select:focus { border-color: var(--ring); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 15%, transparent); }
.field input[type="range"]:focus { box-shadow: none; }
.field.wide { grid-column: span 2; }
.font-hint { font-size: 9px; font-weight: 400; color: var(--muted-foreground); letter-spacing: 0; text-transform: none; }
.font-picker { position: relative; }
.font-search {
  width: 100%; height: 32px; padding: 0 9px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--background); font-size: 11.5px; outline: none;
}
.font-search:focus { border-color: var(--ring); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 15%, transparent); }
.font-results {
  position: absolute; z-index: 60; top: calc(100% + 4px); left: 0; right: 0;
  max-height: 300px; overflow: auto; padding: 6px;
  background: var(--popover); color: var(--popover-foreground);
  border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow-lg);
}
.font-filter {
  display: flex; align-items: center; gap: 2px;
  position: sticky; top: -6px; z-index: 1;
  padding: 4px 2px 6px; margin: -2px -2px 4px;
  background: var(--popover);
}
.font-filter button {
  height: 22px; padding: 0 7px; border: 0; border-radius: 6px;
  background: transparent; color: var(--muted-foreground);
  font-size: 9.5px; font-weight: 600; text-transform: capitalize;
}
.font-filter button.active { background: var(--secondary); color: var(--foreground); }
.font-filter span { margin-left: auto; font-size: 9px; color: var(--muted-foreground); }
.font-option {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; padding: 7px 8px; border: 0; border-radius: 7px;
  background: transparent; text-align: left; font-size: 14px;
}
.font-option:hover { background: var(--muted); }
.font-option small { font-family: var(--font-mono); font-size: 9px; color: var(--muted-foreground); text-transform: uppercase; }
.font-empty { padding: 10px; font-size: 11px; color: var(--muted-foreground); }
.type-fields { padding: 0 16px 16px; display: grid; gap: 4px; }
.type-row { display: grid; grid-template-columns: 82px repeat(3, 1fr); gap: 6px; align-items: center; }
.type-row.header { font-size: 9px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted-foreground); padding-bottom: 2px; }
.type-row .tname { font-family: var(--font-mono); font-size: 10px; }
.type-row input {
  height: 26px; padding: 0 6px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--background); font-size: 10.5px; min-width: 0;
}

/* ---------- Components ---------- */
.component-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 16px; }
.component-tile {
  position: relative; display: flex; flex-direction: column;
  background: var(--card); border: 1px solid var(--border); border-radius: 18px;
  overflow: hidden; box-shadow: var(--shadow-sm); cursor: pointer; outline: none;
  transition: transform .16s, box-shadow .16s, border-color .16s;
}
.component-tile:hover, .component-tile:focus-visible {
  transform: translateY(-2px);
  border-color: color-mix(in srgb, var(--primary) 38%, var(--border));
  box-shadow: var(--shadow-md);
}
.tile-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 12px 14px 10px; border-bottom: 1px solid var(--border); }
.tile-title { font-size: 12.5px; font-weight: 650; letter-spacing: -.01em; }
.tile-desc { max-width: 62%; text-align: right; font-size: 9.5px; line-height: 1.3; color: var(--muted-foreground); }
.tile-preview {
  position: relative; min-height: 190px; max-height: 250px;
  padding: 20px; display: flex; align-items: center; justify-content: center; overflow: hidden;
  background:
    radial-gradient(70% 100% at 50% -10%, color-mix(in srgb, var(--primary) 7%, transparent), transparent 70%),
    var(--card);
}
.tile-preview::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 22px;
  background: linear-gradient(transparent, var(--card)); pointer-events: none;
}
.tile-preview > * { max-width: 100%; }
.component-tile.tile-tall .tile-preview { align-items: flex-start; padding-top: 22px; }
.tile-foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 14px; border-top: 1px solid var(--border); font-size: 9px; color: var(--muted-foreground); }
.tile-open { color: var(--primary); font-weight: 650; }
.segmented { display: flex; gap: 2px; padding: 2px; background: var(--muted); border-radius: 8px; }
.segmented button { height: 24px; padding: 0 8px; border: 0; border-radius: 6px; background: transparent; font-size: 10.5px; color: var(--muted-foreground); }
.segmented button.active { background: var(--card); color: var(--foreground); box-shadow: var(--shadow-sm); font-weight: 600; }
.modal-preview {
  padding: 28px; display: flex; justify-content: center; max-height: 48vh; overflow: auto;
  border-bottom: 1px solid var(--border);
  background:
    radial-gradient(60% 100% at 50% -10%, color-mix(in srgb, var(--primary) 8%, transparent), transparent 70%),
    var(--background);
}
.modal-preview > * { max-width: 100%; }
.component-code-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 14px; border-bottom: 1px solid var(--border); background: var(--card); }
.component-modal .code-block { max-height: 340px; }
.code-block {
  margin: 0; padding: 16px;
  background: var(--code-bg); color: var(--code-fg);
  font-size: 11px; line-height: 1.6;
  overflow: auto; white-space: pre; tab-size: 2;
}
.code-block .muted { color: var(--code-muted); }

/* ---------- Export ---------- */
.export-grid { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 18px; align-items: start; }
.format-panel { position: sticky; top: 22px; }
.format-list { display: grid; gap: 2px; padding: 8px; }
.format-list button {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  height: 36px; padding: 0 10px;
  border: 0; border-radius: 8px; background: transparent;
  font-size: 12px; text-align: left; color: var(--muted-foreground);
}
.format-list button:hover { background: var(--muted); color: var(--foreground); }
.format-list button.active { background: var(--secondary); color: var(--foreground); font-weight: 600; }
.format-list button .ext { font-family: var(--font-mono); font-size: 9.5px; opacity: .65; }
.ai-box { padding: 0 16px 16px; display: grid; gap: 9px; }
.proj-fields { display: grid; gap: 7px; }
.ai-box p { margin: 0; font-size: 11px; color: var(--muted-foreground); line-height: 1.5; }
.ai-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.ai-code {
  margin: 0; padding: 10px; border-radius: 8px;
  background: var(--code-bg); color: var(--code-fg);
  font-size: 9.5px; line-height: 1.6; overflow: auto;
}
.ai-endpoints { font-size: 9.5px !important; }
.ai-endpoints code { background: var(--muted); padding: 1px 4px; border-radius: 4px; }
.code-panel .code-block { max-height: calc(100vh - 160px); padding: 18px 20px; }
.code-panel .panel-head { position: sticky; top: 0; z-index: 3; background: var(--card); border-radius: 14px 14px 0 0; }

/* ---------- Modal & toast ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  padding: 20px; background: rgb(0 0 0 / .32); backdrop-filter: blur(3px);
  animation: fade .12s ease;
}
.modal {
  width: min(520px, 100%);
  background: var(--card); color: var(--card-foreground);
  border: 1px solid var(--border); border-radius: 16px;
  box-shadow: 0 30px 80px -20px rgb(0 0 0 / .45);
  overflow: hidden;
}
.modal.wide { width: min(1080px, 100%); }
.matrix-legend { display: flex; gap: 14px; align-items: center; padding: 0 18px 10px; font-size: 10px; color: var(--muted-foreground); }
.matrix-legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 4px; }
.matrix-scroll { overflow: auto; padding: 0 18px 6px; }
.contrast-matrix { border-collapse: separate; border-spacing: 2px; }
.contrast-matrix th { font-family: var(--font-mono); font-size: 9px; color: var(--muted-foreground); font-weight: 600; min-width: 30px; padding: 2px; }
.contrast-matrix td { width: 54px; height: 32px; text-align: center; border-radius: 5px; font-family: var(--font-mono); font-size: 9.5px; font-weight: 700; }
.contrast-matrix td span { text-shadow: 0 0 2px rgb(255 255 255 / .25); }
.contrast-matrix td.aaa { box-shadow: inset 0 -2px 0 #16a34a; }
.contrast-matrix td.aa { box-shadow: inset 0 -2px 0 #84cc16; }
.contrast-matrix td.large { box-shadow: inset 0 -2px 0 #f59e0b; }
.contrast-matrix td.fail { box-shadow: inset 0 -2px 0 #dc2626; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 10px; }
.modal-head h3 { margin: 0; font-size: 14px; letter-spacing: -.01em; }
.modal-head p { margin: 2px 0 0; font-size: 11px; color: var(--muted-foreground); }
.modal-body { padding: 6px 18px 16px; display: grid; gap: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px 18px; }
.modal-close { border: 0; background: transparent; font-size: 18px; color: var(--muted-foreground); width: 28px; height: 28px; border-radius: 7px; }
.modal-close:hover { background: var(--muted); }
.picker-scales { display: grid; gap: 8px; }
.picker-scale { display: grid; gap: 4px; }
.picker-scale .ps-head { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted-foreground); }
.picker-scale .ps-head .nm { font-weight: 600; color: var(--foreground); text-transform: capitalize; }
.picker-swatches { display: flex; gap: 3px; }
.picker-swatches button { flex: 1; height: 26px; border: 1px solid rgb(0 0 0 / .08); border-radius: 5px; padding: 0; }
.picker-swatches button:hover { outline: 2px solid var(--ring); outline-offset: 1px; }
.picker-custom { display: flex; gap: 8px; align-items: center; }
.picker-custom input[type="text"] {
  flex: 1; height: 34px; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--background); font-family: var(--font-mono); font-size: 12px;
}
.picker-custom input[type="color"] { width: 38px; height: 34px; border: 1px solid var(--border); border-radius: 8px; background: var(--card); padding: 2px; }
.picker-preview { display: flex; align-items: center; gap: 10px; padding: 10px; border: 1px solid var(--border); border-radius: 9px; }
.picker-preview .sw { width: 30px; height: 30px; border-radius: 8px; border: 1px solid rgb(0 0 0 / .1); }
.picker-preview code { font-size: 12px; }
.picker-preview small { color: var(--muted-foreground); font-size: 10px; margin-left: auto; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 16px);
  z-index: 200; padding: 8px 13px;
  border-radius: 9px; background: var(--foreground); color: var(--background);
  font-size: 12px; font-weight: 500; opacity: 0; pointer-events: none;
  transition: opacity .16s, transform .16s;
  box-shadow: 0 12px 30px -12px rgb(0 0 0 / .5);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.empty { padding: 28px 16px; text-align: center; color: var(--muted-foreground); font-size: 12px; }
.muted { color: var(--muted-foreground); }

@media (max-width: 1180px) {
  .gen-grid, .tokens-grid, .export-grid { grid-template-columns: 1fr; }
  .preview-panel, .format-panel { position: static; }
  .token-table-wrap { max-height: none; }
}
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 12px; border-right: 0; border-bottom: 1px solid var(--border); padding: 12px 16px; }
  .brand { margin-right: 8px; }
  .nav { display: flex; flex-wrap: wrap; }
  .side-section { display: none; }
  .side-footer { margin: 0 0 0 auto; display: flex; align-items: center; gap: 10px; border: 0; padding: 0; }
  .save-line { display: none; }
  .main { padding: 18px 16px 40px; }
  .topbar { flex-direction: column; gap: 12px; }
  .top-actions { width: 100%; justify-content: flex-end; flex-wrap: wrap; }
  .type-row { grid-template-columns: 62px repeat(3, 1fr); }
  .field-grid { grid-template-columns: 1fr; }
  .field.wide { grid-column: span 1; }
}
