:root {
  --canvas: #eef0ec;
  --surface: #ffffff;
  --surface-subtle: #f7f8f5;
  --ink: #191a18;
  --muted: #60645d;
  --line: #d8dad4;
  --accent: #168143;
  --accent-soft: #eaf4ed;
  --dark: #191a18;
  --topbar-height: 66px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
  font-synthesis: none;
}
* { box-sizing: border-box; }
html, body { min-width: 320px; min-height: 100%; }
body { margin: 0; background: var(--canvas); color: var(--ink); overflow-x: hidden; }
button, input, select { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.skip-link { position: fixed; z-index: 100; top: 8px; left: 8px; padding: 9px 12px; border-radius: 4px; background: var(--ink); color: #fff; transform: translateY(-150%); }
.skip-link:focus { transform: none; }

.topbar { position: sticky; z-index: 30; top: 0; display: flex; min-height: var(--topbar-height); align-items: center; justify-content: space-between; gap: 24px; padding: 0 28px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.97); }
.brand { display: inline-flex; flex: 0 0 auto; align-items: center; gap: 11px; color: var(--ink); font-size: 15px; font-weight: 850; text-decoration: none; }
.brand-mark { position: relative; display: inline-grid; width: 34px; height: 34px; place-items: center; background: #16aa58; }
.brand-mark::before { width: 19px; height: 14px; border: 3px solid #fff; content: ""; }
.brand-mark i { position: absolute; width: 12px; height: 3px; background: #c8ff39; transform: translateX(1px) skewX(-22deg); }
.topnav { min-width: 0; }
.mode-nav { display: flex; min-height: 42px; align-items: end; gap: 22px; padding: 0 28px; border-bottom: 1px solid var(--line); background: var(--surface); }
.mode-nav a { position: relative; display: inline-flex; min-height: 42px; align-items: center; color: var(--muted); font-size: 12px; font-weight: 750; text-decoration: none; }
.mode-nav a:hover, .mode-nav a[aria-current="page"] { color: var(--ink); }
.mode-nav a[aria-current="page"]::after { position: absolute; right: 0; bottom: -1px; left: 0; height: 2px; background: var(--accent); content: ""; }

.lab-page { min-height: calc(100vh - var(--topbar-height)); }
.lab-commandbar { position: sticky; z-index: 25; top: var(--topbar-height); display: grid; min-height: 72px; grid-template-columns: minmax(0, 1fr) auto auto; align-items: end; gap: 16px; padding: 10px 18px 12px; border-bottom: 1px solid var(--line); background: rgba(247,248,245,.98); }
.system-switcher, .view-switcher { display: grid; min-width: 0; gap: 6px; margin: 0; padding: 0; border: 0; }
.system-switcher > span, .view-switcher legend { color: var(--muted); font-size: 10px; font-weight: 750; }
.system-tabs { display: flex; min-width: 0; overflow-x: auto; border-bottom: 1px solid var(--line); scrollbar-width: none; }
.system-tabs::-webkit-scrollbar { display: none; }
.system-tabs button { position: relative; min-height: 38px; flex: 0 0 auto; padding: 0 14px; border: 0; background: transparent; color: var(--muted); font-size: 11px; font-weight: 700; cursor: pointer; }
.system-tabs button:hover { color: var(--ink); }
.system-tabs button.is-selected { color: var(--ink); }
.system-tabs button.is-selected::after { position: absolute; right: 8px; bottom: -1px; left: 8px; height: 2px; background: var(--accent); content: ""; }
.segmented { display: inline-flex; min-height: 38px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface); }
.segmented button { min-width: 62px; border: 0; border-right: 1px solid var(--line); background: transparent; color: var(--muted); font-size: 11px; font-weight: 750; cursor: pointer; }
.segmented button:last-child { border-right: 0; }
.segmented button.is-selected { background: var(--ink); color: #fff; }
.settings-button { display: inline-flex; min-height: 38px; align-items: center; gap: 8px; padding: 0 12px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface); color: var(--ink); font-size: 11px; font-weight: 750; cursor: pointer; }
.settings-button:hover, .settings-button[aria-expanded="true"] { border-color: var(--accent); background: var(--accent-soft); }
.settings-icon { position: relative; width: 15px; height: 15px; border: 1.6px solid currentColor; border-radius: 50%; }
.settings-icon::after { position: absolute; inset: 4px; border: 1.4px solid currentColor; border-radius: 50%; content: ""; }

.lab-layout { display: grid; min-height: calc(100vh - var(--topbar-height) - 72px); grid-template-columns: minmax(0, 1fr) 280px; }
.preview-workspace { min-width: 0; padding: 14px; background: var(--canvas); }
.workspace-heading { display: flex; min-height: 46px; align-items: flex-start; justify-content: space-between; gap: 14px; }
.workspace-heading h1 { margin: 0; font-size: 16px; line-height: 1.25; }
.workspace-heading p { margin: 5px 0 0; color: var(--muted); font-size: 10px; }
.workspace-status { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.workspace-status span { display: inline-flex; min-height: 24px; align-items: center; padding: 0 7px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); color: var(--muted); font-size: 9px; font-weight: 700; }
.preview-stage { min-height: calc(100vh - 216px); padding: 12px; border: 1px solid var(--line); background: #e7e9e4; overflow: auto; }
.preview-stage.is-single { display: flex; justify-content: center; }
.preview-stage.is-compare { display: grid; grid-template-columns: repeat(4, minmax(540px, 1fr)); gap: 12px; }
.preview-column { min-width: 0; margin: 0; }
.preview-column > header { display: flex; min-height: 42px; align-items: center; justify-content: space-between; gap: 12px; padding: 7px 10px; border: 1px solid var(--line); border-bottom: 0; background: var(--surface); }
.preview-column > header div { display: grid; gap: 2px; }
.preview-column > header strong { font-size: 10px; }
.preview-column > header span { color: var(--muted); font-size: 8px; }
.preview-column > header a { color: var(--accent); font-size: 8px; font-weight: 750; text-decoration: none; white-space: nowrap; }
.device-frame { position: relative; width: min(var(--preview-width), 100%); height: var(--preview-height); border: 1px solid #bfc3bb; background: #fff; overflow: hidden; }
.device-frame iframe { width: var(--preview-width); height: var(--preview-height); border: 0; transform: scale(var(--preview-scale, 1)); transform-origin: top left; }
.device-iphone .device-frame, .device-android .device-frame { max-width: var(--preview-width); border: 8px solid #1d1f1c; border-radius: 24px; }
.device-iphone .preview-column > header, .device-android .preview-column > header { width: min(var(--preview-width), 100%); }

.inspector { min-width: 0; border-left: 1px solid var(--line); background: var(--surface-subtle); }
.inspector-heading { display: flex; min-height: 52px; align-items: center; justify-content: space-between; gap: 10px; padding: 0 14px; border-bottom: 1px solid var(--line); }
.inspector-heading h2 { margin: 0; font-size: 12px; }
.inspector-heading span { color: var(--accent); font-size: 10px; font-weight: 800; }
.inspector-tabs { display: grid; grid-template-columns: repeat(4, 1fr); border-bottom: 1px solid var(--line); }
.inspector-tabs button { min-width: 0; min-height: 38px; padding: 0 3px; border: 0; border-right: 1px solid var(--line); background: transparent; color: var(--muted); font-size: 9px; font-weight: 750; cursor: pointer; }
.inspector-tabs button:last-child { border-right: 0; }
.inspector-tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: inset 0 -2px var(--accent); }
.inspector-content { padding: 14px; }
.inspector-content section > header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.inspector-content h3 { margin: 0 0 12px; font-size: 11px; }
.inspector-content p { color: var(--muted); font-size: 10px; line-height: 1.65; }
.inspector-content hr { margin: 16px 0; border: 0; border-top: 1px solid var(--line); }
.inspector-content header button { border: 0; background: transparent; color: var(--accent); font-size: 9px; font-weight: 750; cursor: pointer; }
.mapping-list, .token-list { margin: 0; border-top: 1px solid var(--line); }
.mapping-list > div, .token-list > div { display: grid; grid-template-columns: 72px minmax(0, 1fr); gap: 8px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 9px; }
.mapping-list span, .token-list dt { color: var(--muted); }
.mapping-list strong { font-weight: 700; overflow-wrap: anywhere; }
.token-list dt, .token-list dd { margin: 0; }
.token-list dd { display: flex; align-items: center; justify-content: space-between; gap: 6px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; }
.token-list i { width: 15px; height: 15px; flex: 0 0 auto; border: 1px solid var(--line); border-radius: 3px; background: var(--swatch); }
.inspector-primary, .inspector-secondary { width: 100%; min-height: 36px; margin-top: 12px; padding: 0 10px; border-radius: 4px; font-size: 10px; font-weight: 750; cursor: pointer; }
.inspector-primary { border: 0; background: var(--ink); color: #fff; }
.inspector-secondary { border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
.source-link { color: var(--accent); font-size: 10px; font-weight: 750; text-decoration: none; }
.status-line { padding: 8px; background: var(--accent-soft); color: var(--accent) !important; font-weight: 750; }
.code-preview { max-height: 360px; margin: 10px 0; padding: 10px; background: #1f211f; color: #eff3ed; font: 9px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; overflow: auto; }

.settings-panel { position: fixed; z-index: 46; top: 0; right: 0; bottom: 0; width: min(360px, 100vw); border-left: 1px solid var(--line); background: var(--surface); box-shadow: -8px 0 20px rgba(0,0,0,.12); overflow-y: auto; }
.settings-panel[hidden], .settings-scrim[hidden] { display: none; }
.settings-panel > header { position: sticky; z-index: 1; top: 0; display: flex; min-height: 66px; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--surface); }
.settings-panel > header span { color: var(--accent); font-size: 8px; font-weight: 850; }
.settings-panel > header h2 { margin: 4px 0 0; font-size: 15px; }
.settings-panel > header button { width: 40px; height: 40px; border: 0; border-radius: 4px; background: transparent; font-size: 24px; cursor: pointer; }
.settings-panel form { display: grid; gap: 20px; padding: 20px 16px; }
.settings-panel label, .settings-panel fieldset { display: grid; gap: 8px; margin: 0; padding: 0; border: 0; }
.settings-panel label > span, .settings-panel legend { color: var(--muted); font-size: 10px; font-weight: 750; }
.settings-panel select { width: 100%; height: 40px; padding: 0 34px 0 10px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface); color: var(--ink); font-size: 11px; }
.device-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.device-options button { display: grid; min-height: 68px; place-items: center; align-content: center; gap: 8px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface); color: var(--muted); font-size: 9px; font-weight: 700; cursor: pointer; }
.device-options button.is-selected { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }
.device-icon { display: block; width: 22px; height: 14px; border: 1.5px solid currentColor; border-radius: 1px; }
.device-iphone.device-icon, .device-android.device-icon { width: 10px; height: 18px; border-radius: 2px; }
.settings-panel .segmented { width: 100%; }
.settings-panel .segmented button { flex: 1; }
.theme-summary { display: grid; gap: 6px; padding-top: 16px; border-top: 1px solid var(--line); }
.theme-summary > span { color: var(--muted); font-size: 9px; }
.theme-summary strong { font-size: 13px; }
.theme-summary p { margin: 0; color: var(--muted); font-size: 10px; line-height: 1.55; }
#activeThemeSwatches { display: flex; gap: 5px; margin-top: 5px; }
#activeThemeSwatches i { display: block; width: 28px; height: 28px; border: 1px solid var(--line); border-radius: 3px; background: var(--swatch); }
.reset-button { min-height: 40px; margin-top: 8px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface); color: var(--ink); font-size: 10px; font-weight: 750; cursor: pointer; }
.settings-scrim { position: fixed; z-index: 45; inset: 0; background: rgba(14,16,14,.3); }

.matrix-drawer { padding: 14px; border: 1px solid var(--line); background: var(--surface); overflow-x: auto; }
.matrix-drawer > header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.matrix-drawer h2 { margin: 0; font-size: 15px; }
.matrix-drawer p { margin: 5px 0 0; color: var(--muted); font-size: 10px; }
.matrix-drawer > header span { color: var(--muted); font-size: 9px; }
.matrix-table { min-width: 850px; border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.matrix-row { display: grid; grid-template-columns: 120px repeat(4, minmax(170px, 1fr)); }
.matrix-row > * { min-width: 0; padding: 10px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.matrix-row > strong, .matrix-row > b { font-size: 9px; }
.matrix-row > div { display: grid; gap: 8px; }
.matrix-row > div > span { color: var(--muted); font-size: 8px; overflow-wrap: anywhere; }
.matrix-head { background: var(--surface-subtle); }
.matrix-button, .matrix-input { min-height: 30px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); color: var(--ink); font-size: 9px; }
.matrix-button { width: fit-content; padding: 0 10px; background: var(--ink); color: #fff; }
.matrix-toast { width: fit-content; padding: 7px 9px; border-radius: 4px; background: var(--accent-soft); color: var(--accent) !important; }
.matrix-shape { display: flex; align-items: center; gap: 5px; }
.matrix-shape i { display: block; width: 18px; height: 18px; border: 1px solid var(--line); border-radius: 3px; background: var(--surface-subtle); }
.system-apple { border-radius: 9px !important; }
.system-material { border-radius: 999px !important; }
.system-carbon { border-radius: 0 !important; }
.toast { position: fixed; z-index: 60; right: 18px; bottom: 18px; padding: 11px 14px; border-radius: 5px; background: var(--ink); color: #fff; font-size: 12px; box-shadow: 0 8px 20px rgba(0,0,0,.2); }

html[data-appearance="dark"] { --canvas: #151715; --surface: #202320; --surface-subtle: #1b1d1b; --ink: #f4f7f3; --muted: #b1b8b1; --line: #3b403b; --accent-soft: #25382c; color-scheme: dark; }
html[data-appearance="dark"] .topbar, html[data-appearance="dark"] .lab-commandbar { background: rgba(32,35,32,.98); }
html[data-appearance="dark"] .preview-stage { background: #111311; }
html[data-appearance="dark"] .settings-scrim { background: rgba(0,0,0,.5); }

@media (max-width: 1080px) {
  .lab-layout { grid-template-columns: minmax(0, 1fr) 240px; }
  .inspector-content { padding: 10px; }
}
@media (max-width: 820px) {
  :root { --topbar-height: auto; }
  .topbar { position: static; align-items: flex-start; flex-direction: column; gap: 8px; padding: 14px 16px 8px; }
  .mode-nav { padding-inline: 16px; }
  .lab-commandbar { position: static; grid-template-columns: minmax(0, 1fr) auto; padding-inline: 12px; }
  .system-switcher { grid-column: 1 / -1; }
  .lab-layout { display: block; }
  .preview-workspace { padding: 10px; }
  .preview-stage { min-height: 620px; padding: 8px; }
  .preview-stage.is-compare { grid-template-columns: repeat(4, minmax(330px, 1fr)); }
  .inspector { border-top: 1px solid var(--line); border-left: 0; }
  .system-tabs button, .segmented, .settings-button { min-height: 44px; }
}
@media (max-width: 520px) {
  .lab-commandbar { grid-template-columns: 1fr auto; }
  .settings-button span:last-child { display: none; }
  .workspace-heading { align-items: flex-start; flex-direction: column; }
  .workspace-status { justify-content: flex-start; }
  .preview-stage { margin-inline: -10px; border-right: 0; border-left: 0; }
  .view-switcher .segmented button { min-width: 54px; }
  .view-switcher .segmented button:last-child { display: none; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; } }
