:root {
  color-scheme: light;
  --paper: #f3f0e9;
  --paper-deep: #e9e4da;
  --surface: #fbfaf7;
  --ink: #1b1f1d;
  --ink-2: #464d49;
  --ink-3: #646a66;
  --line: rgba(27, 31, 29, .12);
  --line-2: rgba(27, 31, 29, .22);
  --accent: #2c4a3f;
  --accent-wash: #e3e9e2;
  --local: #8a5524;
  --local-wash: #f3e6d6;
  --danger: #9a2b20;
  --danger-wash: #f6e3df;
  --focus: #2a5d86;
  --serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, 'Book Antiqua', Georgia, ui-serif, serif;
  --sans: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --radius-lg: 16px;
  --pill: 999px;
  --ease: cubic-bezier(.2, .7, .2, 1);
  --gutter: clamp(.75rem, 1.6vw, 1.5rem);
  --outline-w: 15rem;
  --inspector-w: 22.5rem;
  --panel-w: 26rem;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; background: var(--paper); }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);
  background: var(--paper);
  color: var(--ink);
  font: 400 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: not-allowed; }
a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: .2em; }
::selection { background: #d6e0d8; }
:focus:not(:focus-visible) { outline: none; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}
.skip-link {
  position: absolute;
  top: .5rem; left: var(--gutter);
  z-index: 60;
  padding: .55rem .9rem;
  border-radius: var(--pill);
  background: var(--ink);
  color: var(--paper);
  font-size: .85rem;
  text-decoration: none;
  transform: translateY(-160%);
  transition: transform .2s var(--ease);
}
.skip-link:focus-visible { transform: none; }

/* Masthead */
.masthead {
  grid-row: 1;
  position: relative;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .6rem 1.25rem;
  padding: .75rem var(--gutter);
}
.brand {
  padding: .4rem .1rem;
  margin-right: -.34em;
  border: 0;
  border-radius: 4px;
  background: none;
  font: 500 .98rem/1 var(--serif);
  letter-spacing: .34em;
  color: var(--ink);
}
.brand:hover { color: var(--accent); }
.mode-nav {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--pill);
  background: var(--surface);
}
.mode-link {
  padding: .42rem 1rem;
  border: 0;
  border-radius: var(--pill);
  background: transparent;
  font-size: .84rem;
  font-weight: 500;
  color: var(--ink-2);
  transition: background-color .2s var(--ease), color .2s var(--ease);
}
.mode-link:hover { color: var(--ink); background: rgba(27, 31, 29, .05); }
body[data-mode='configure'] .mode-link[data-mode-target='configure'],
body[data-mode='design'] .mode-link[data-mode-target='design'],
.mode-link.is-active,
.mode-link[aria-current]:not([aria-current='false']) {
  background: var(--ink);
  color: var(--paper);
}
.masthead-tools {
  display: flex;
  align-items: center;
  gap: .35rem .5rem;
  min-width: 0;
  margin-left: auto;
}
.document-status {
  max-width: 18rem;
  margin-right: .35rem;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: .78rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink-3);
}
.toolbar { display: flex; align-items: center; gap: .15rem; }
.tool-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  height: 2.25rem;
  min-width: 2.25rem;
  padding: 0 .8rem;
  border: 1px solid transparent;
  border-radius: var(--pill);
  background: transparent;
  font-size: .84rem;
  font-weight: 500;
  color: var(--ink-2);
  white-space: nowrap;
  transition: background-color .15s var(--ease), color .15s var(--ease), border-color .15s var(--ease);
}
.tool-button:hover:not(:disabled) { background: rgba(27, 31, 29, .06); color: var(--ink); }
.tool-button:disabled { opacity: .38; }
.tool-icon { padding: 0; }
.tool-button svg, .dialog-close svg, .cta-arrow {
  width: 1.1rem; height: 1.1rem;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tool-emphasis { margin-left: .2rem; border-color: var(--line-2); color: var(--ink); }
.tool-divider { width: 1px; height: 1.2rem; margin: 0 .3rem; background: var(--line-2); }
.journal-link {
  margin-left: .35rem;
  padding: .4rem .3rem;
  font-size: .8rem;
  color: var(--ink-2);
  white-space: nowrap;
}
.journal-link:hover { color: var(--ink); }
body[data-mode='discover'] #undo-button,
body[data-mode='discover'] #redo-button,
body[data-mode='discover'] #save-button,
body[data-mode='discover'] #review-button,
body[data-mode='discover'] .tool-divider { display: none; }

/* Conflict banner */
.conflict-banner {
  grid-row: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .75rem 1.25rem;
  margin: 0 var(--gutter) .75rem;
  padding: .8rem 1rem;
  border: 1px solid rgba(138, 85, 36, .32);
  border-radius: 12px;
  background: var(--local-wash);
  font-size: .88rem;
  line-height: 1.45;
  color: #4b2f14;
}
.conflict-banner p { flex: 1 1 22rem; }
.conflict-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.conflict-actions .action { min-height: 2.25rem; padding: .45rem 1rem; font-size: .82rem; }

/* Studio: one persistent stage, reflowed by mode */
.studio {
  grid-row: 3;
  display: flex;
  flex-direction: column;
  gap: .75rem;
  min-width: 0;
  min-height: 0;
  padding: 0 var(--gutter) var(--gutter);
}

/* Discovery */
.discovery { display: none; max-width: 36rem; padding: .75rem .25rem 1.5rem; }
body[data-mode='discover'] .discovery { display: block; order: 2; animation: rise .6s var(--ease) both; }
.hero-kicker {
  margin-bottom: 1.1rem;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.hero-title-row { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem 1.1rem; }
.hero-title { font: 400 clamp(3.1rem, 6.2vw, 5.9rem)/.95 var(--serif); letter-spacing: -.022em; }
.hero-lede {
  max-width: 31rem;
  margin-top: 1.35rem;
  font-size: clamp(1rem, 1.15vw, 1.12rem);
  line-height: 1.62;
  color: var(--ink-2);
  text-wrap: pretty;
}
.hero-registers {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.25rem;
  max-width: 30rem;
  margin: 2rem 0 2.1rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
}
.hero-registers dt {
  display: flex;
  align-items: center;
  gap: .55rem;
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.hero-registers dd { margin: .35rem 0 0; font: 400 1.08rem/1.35 var(--serif); }
.register-glyph { width: 1.35rem; height: 1.35rem; flex: none; color: var(--ink-2); }
.register-glyph circle { fill: none; stroke: currentColor; stroke-width: 1.1; }
.register-glyph .on { fill: currentColor; }
.hero-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem 1.25rem; }
.hero-cta { min-height: 3.15rem; padding: .8rem 1.35rem .8rem 1.6rem; font-size: .95rem; }
.hero-cta .cta-arrow { transition: transform .25s var(--ease); }
.hero-cta:hover .cta-arrow { transform: translateX(3px); }

.status-tag {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  padding: .24rem .6rem .24rem .5rem;
  border: 1px solid var(--line-2);
  border-radius: var(--pill);
  background: rgba(251, 250, 247, .7);
  font-size: .64rem;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-2);
  white-space: nowrap;
}
.status-tag::before { content: ''; width: .4rem; height: .4rem; border-radius: 50%; background: var(--local); }

/* Stage */
.stage {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: clamp(20rem, 60vh, 40rem);
  height: clamp(20rem, 60svh, 40rem);
  overflow: hidden;
  isolation: isolate;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: radial-gradient(120% 95% at 50% 42%, #fefdfa 0%, #f4f0e8 50%, #e8e3d8 100%);
  view-transition-name: watch-stage;
}
.stage:focus { outline: none; }
body[data-mode='discover'] .stage {
  border-color: transparent;
  background: radial-gradient(70% 70% at 50% 46%, #fefdfa 0%, #f6f3ec 46%, rgba(243, 240, 233, 0) 78%);
}
.stage-meta { position: relative; z-index: 2; padding: 1rem 1.15rem 0; }
body[data-mode='discover'] .stage-meta { display: none; }
.stage-title-row { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .75rem; }
.watch-title { font: 400 clamp(1.35rem, 2.1vw, 1.85rem)/1.15 var(--serif); letter-spacing: -.006em; }
.watch-specs {
  margin-top: .3rem;
  font-size: .8rem;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
}
.watch-specs:empty { display: none; }
.watch-specs dl, .watch-specs ul { display: flex; flex-wrap: wrap; gap: .2rem 1.1rem; margin: 0; padding: 0; list-style: none; }
.watch-specs dl > div { display: flex; align-items: baseline; gap: .35rem; }
.watch-specs dt { font-size: .66rem; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); }
.watch-specs dd { margin: 0; }
.stage-frame { position: relative; flex: 1 1 auto; min-height: 12rem; }
.stage-layer { position: absolute; inset: 0; }
#svg-stage > svg { display: block; width: 100%; height: 100%; }
.lug-section-preview { background: #f7f6f0; border-radius: 10px; }
.lug-enable { width: 100%; margin: .35rem 0 .75rem; white-space: normal; line-height: 1.4; }
#scene-stage canvas { display: block; width: 100% !important; height: 100% !important; }
.stage-loading {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: .8rem;
  background: rgba(243, 240, 233, .6);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  font-size: .8rem;
  letter-spacing: .04em;
  color: var(--ink-2);
  animation: fade-in .35s .2s both;
}
.loading-mark { position: relative; width: 1.9rem; height: 1.9rem; border: 1.5px solid var(--line-2); border-radius: 50%; }
.loading-mark::after {
  content: '';
  position: absolute;
  left: calc(50% - .75px);
  bottom: 50%;
  width: 1.5px;
  height: .7rem;
  border-radius: 1px;
  background: var(--ink);
  transform-origin: 50% 100%;
  animation: sweep 1.6s linear infinite;
}
.noscript-note { position: absolute; inset: auto 1rem 1rem; text-align: center; font-size: .85rem; color: var(--ink-2); }
.stage-foot {
  position: relative;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: .6rem 1rem;
  padding: .6rem 1.15rem 1rem;
}
.stage-caption { flex: 1 1 16rem; max-width: 40rem; font-size: .8125rem; line-height: 1.45; color: var(--ink-2); }
.stage-caption:empty { visibility: hidden; }
.view-controls {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--pill);
  background: rgba(251, 250, 247, .86);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
body[data-mode='discover'] .view-controls { display: none; }
.view-controls button {
  padding: .4rem .85rem;
  border: 0;
  border-radius: var(--pill);
  background: transparent;
  font-size: .78rem;
  font-weight: 500;
  color: var(--ink-2);
  transition: background-color .18s var(--ease), color .18s var(--ease);
}
.view-controls button:hover:not(:disabled) { color: var(--ink); background: rgba(27, 31, 29, .05); }
.view-controls button.is-active,
.view-controls button[aria-pressed='true'] { background: var(--ink); color: var(--paper); }
.view-controls button:disabled { opacity: .38; }

/* Guided configuration */
.config-panel {
  display: none;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
}
body[data-mode='configure'] .config-panel { display: flex; animation: rise .5s var(--ease) both; }
.step-nav {
  display: flex;
  gap: .35rem;
  padding: 1rem 1.25rem .25rem;
  overflow-x: auto;
  scrollbar-width: none;
  counter-reset: step;
}
.step-nav::-webkit-scrollbar { display: none; }
.step-button {
  flex: 1 0 4.5rem;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: .3rem;
  padding: .55rem .1rem .2rem;
  border: 0;
  border-top: 2px solid var(--line);
  background: none;
  text-align: left;
  font-size: .74rem;
  font-weight: 500;
  line-height: 1.25;
  color: var(--ink-3);
  counter-increment: step;
  transition: color .2s var(--ease), border-color .2s var(--ease);
}
.step-button::before { content: counter(step, decimal-leading-zero); font: 500 .66rem/1 var(--mono); letter-spacing: .04em; }
.step-button:hover:not(:disabled) { color: var(--ink); border-top-color: var(--ink-3); }
.step-button.is-active,
.step-button[aria-current]:not([aria-current='false']),
.step-button[aria-selected='true'] { color: var(--ink); border-top-color: var(--ink); }
.step-button:disabled { opacity: .45; }
.config-head { padding: 1.1rem 1.25rem .4rem; }
.panel-kicker {
  margin-bottom: .4rem;
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.step-title { font: 400 clamp(1.45rem, 1.9vw, 1.75rem)/1.15 var(--serif); letter-spacing: -.006em; }
.step-description { margin-top: .45rem; font-size: .9rem; line-height: 1.55; color: var(--ink-2); }
.step-description:empty { display: none; }
.step-content { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: 1rem; padding: .9rem 1.25rem 1.5rem; }
.step-actions {
  position: sticky;
  bottom: 0;
  z-index: 4;
  display: flex;
  gap: .6rem;
  padding: .85rem 1.25rem;
  padding-bottom: max(.85rem, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  background: var(--surface);
}
.step-actions .action-primary { flex: 1 1 auto; }

/* Professional workspace */
.pro-panel { display: none; min-width: 0; min-height: 0; }
body[data-mode='design'] .pro-panel { display: flex; flex-direction: column; gap: .75rem; }
.pro-outline, .pro-inspector {
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  animation: rise .5s var(--ease) both;
}
.pro-inspector { animation-delay: .05s; }
.pro-section { padding: 1rem 1rem .9rem; }
.pro-section + .pro-section { border-top: 1px solid var(--line); }
.pro-heading {
  margin-bottom: .6rem;
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.pro-list { display: flex; flex-direction: column; gap: 2px; }
.model-button, .component-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .6rem;
  width: 100%;
  min-height: 2.35rem;
  padding: .5rem .7rem;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
  font-size: .86rem;
  line-height: 1.3;
  color: var(--ink-2);
  transition: background-color .15s var(--ease), color .15s var(--ease);
}
.model-button { font-weight: 500; }
.model-button:hover, .component-button:hover { background: rgba(27, 31, 29, .05); color: var(--ink); }
.model-button.is-active, .model-button[aria-pressed='true'], .model-button[aria-selected='true'], .model-button[aria-current]:not([aria-current='false']),
.component-button.is-active, .component-button[aria-pressed='true'], .component-button[aria-selected='true'], .component-button[aria-current]:not([aria-current='false']) {
  background: var(--accent-wash);
  color: var(--ink);
  box-shadow: inset 2px 0 0 var(--accent);
}
.model-button small, .component-button small { font-size: .72rem; font-weight: 400; color: var(--ink-3); }
.scope-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
}
.scope-controls button {
  padding: .5rem .6rem;
  border: 0;
  border-radius: 7px;
  background: transparent;
  font-size: .82rem;
  font-weight: 500;
  color: var(--ink-2);
  transition: background-color .15s var(--ease), color .15s var(--ease), box-shadow .15s var(--ease);
}
.scope-controls button:hover:not(:disabled) { color: var(--ink); }
.scope-controls button.is-active,
.scope-controls button[aria-pressed='true'] {
  background: var(--surface);
  color: var(--accent);
  box-shadow: 0 0 0 1px var(--line-2), 0 1px 2px rgba(27, 31, 29, .08);
}
.scope-controls button[data-scope='model'].is-active,
.scope-controls button[data-scope='model'][aria-pressed='true'] {
  color: var(--local);
  box-shadow: 0 0 0 1px rgba(138, 85, 36, .45), 0 1px 2px rgba(27, 31, 29, .08);
}
.scope-description { margin-top: .6rem; font-size: .8rem; line-height: 1.5; color: var(--ink-2); }
.scope-description:empty { display: none; }
.parameter-controls { display: flex; flex-direction: column; gap: 1rem; }

/* Root-inserted components */
.group-heading {
  margin-top: .6rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.group-heading:first-child { margin-top: 0; padding-top: 0; border-top: 0; }

.field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  column-gap: .5rem;
  row-gap: .45rem;
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}
.field > * { grid-column: 1 / -1; }
.field-label { grid-column: 1; grid-row: 1; font-size: .84rem; font-weight: 500; color: var(--ink); }
.inheritance {
  grid-column: 2;
  grid-row: 1;
  justify-self: end;
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .12rem .5rem;
  border: 1px solid var(--line);
  border-radius: var(--pill);
  background: var(--paper);
  font-size: .66rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-3);
  white-space: nowrap;
}
.field:has(.reset-button:not([hidden]):not(:disabled)) .inheritance {
  border-color: rgba(138, 85, 36, .4);
  background: var(--local-wash);
  color: var(--local);
}
.reset-button {
  grid-column: 3;
  grid-row: 1;
  justify-self: end;
  padding: .2rem .25rem;
  border: 0;
  border-radius: 4px;
  background: none;
  font-size: .75rem;
  font-weight: 500;
  color: var(--local);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: .18em;
}
.reset-button:hover:not(:disabled) { color: var(--ink); }
.reset-button:disabled { opacity: .4; }
.field-input {
  grid-column: 1 / -1;
  width: 100%;
  min-height: 2.35rem;
  padding: .45rem .65rem;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  background: var(--surface);
  font-size: .9rem;
  font-variant-numeric: tabular-nums;
  transition: border-color .15s var(--ease);
}
.field-input:hover:not(:disabled) { border-color: var(--ink-3); }
.field-input:focus-visible { border-color: var(--focus); }
.field-input:disabled { opacity: .5; }
.field:has(.field-unit) .field-input { grid-column: 1 / 3; }
.field-unit { grid-column: 3; font: 400 .76rem/1 var(--mono); color: var(--ink-3); }
.field-input[aria-invalid='true'] { border-color: var(--danger); }
select.field-input {
  -webkit-appearance: none;
  appearance: none;
  padding-right: 2rem;
  background-image: url('data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 10 6%22%3E%3Cpath d=%22M1 1l4 4 4-4%22 fill=%22none%22 stroke=%22%23464d49%22 stroke-width=%221.3%22 stroke-linecap=%22round%22/%3E%3C/svg%3E');
  background-repeat: no-repeat;
  background-position: right .75rem center;
  background-size: .65rem;
}
input[type='color'].field-input { justify-self: start; width: 3rem; height: 2.25rem; padding: 3px; cursor: pointer; }
input[type='range'].field-input {
  -webkit-appearance: none;
  appearance: none;
  min-height: 1.75rem;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}
input[type='range'].field-input::-webkit-slider-runnable-track { height: 2px; border-radius: 2px; background: var(--line-2); }
input[type='range'].field-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px;
  margin-top: -8px;
  border: 1.5px solid var(--ink);
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(27, 31, 29, .18);
}
input[type='range'].field-input::-moz-range-track { height: 2px; border-radius: 2px; background: var(--line-2); }
input[type='range'].field-input::-moz-range-progress { height: 2px; border-radius: 2px; background: var(--ink); }
input[type='range'].field-input::-moz-range-thumb {
  width: 16px; height: 16px;
  border: 1.5px solid var(--ink);
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(27, 31, 29, .18);
}
input[type='range'].field-input:focus-visible { outline-offset: 4px; }
.field-note { grid-column: 1 / -1; font-size: .76rem; line-height: 1.45; color: var(--ink-3); }
.field-error { grid-column: 1 / -1; font-size: .78rem; line-height: 1.45; color: var(--danger); }
.field-error:empty { display: none; }

.choice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(8.25rem, 1fr));
  gap: .6rem;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}
.choice-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: .5rem;
  width: 100%;
  min-height: 100%;
  margin: 0;
  padding: .9rem 2.1rem .85rem .9rem;
  border: 1px solid var(--line-2);
  border-radius: 12px;
  background: #fdfcf9;
  text-align: left;
  cursor: pointer;
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease), background-color .18s var(--ease);
}
.choice-card::after {
  content: '';
  position: absolute;
  top: .85rem; right: .85rem;
  width: .85rem; height: .85rem;
  border: 1.5px solid var(--line-2);
  border-radius: 50%;
  background: var(--surface);
  transition: background-color .18s var(--ease), border-color .18s var(--ease);
}
.choice-card:hover { border-color: var(--ink-3); }
.choice-card.is-active, .choice-card[aria-pressed='true'], .choice-card[aria-checked='true'], .choice-card[aria-selected='true'], .choice-card:has(input:checked) {
  border-color: var(--ink);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--ink);
}
.choice-card.is-active::after, .choice-card[aria-pressed='true']::after, .choice-card[aria-checked='true']::after, .choice-card[aria-selected='true']::after, .choice-card:has(input:checked)::after {
  border-color: var(--ink);
  background: var(--ink);
  box-shadow: inset 0 0 0 2.5px var(--surface);
}
.choice-card input[type='radio'], .choice-card input[type='checkbox'] {
  position: absolute;
  width: 1px; height: 1px;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}
.choice-card:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.choice-card:disabled, .choice-card[aria-disabled='true'], .choice-card:has(input:disabled) { opacity: .45; cursor: not-allowed; }
.choice-swatch {
  display: block;
  flex: none;
  width: 2.6rem; height: 2.6rem;
  overflow: hidden;
  border: 1px solid rgba(27, 31, 29, .16);
  border-radius: 50%;
  background: var(--swatch, var(--paper-deep));
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, .5), 0 1px 3px rgba(27, 31, 29, .12);
}
.choice-swatch svg, .choice-swatch img { display: block; width: 100%; height: 100%; }
.choice-label { font-size: .9rem; font-weight: 600; line-height: 1.25; color: var(--ink); }
.choice-detail { font-size: .76rem; line-height: 1.4; color: var(--ink-3); }

.summary-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  margin: 0;
  padding: .65rem 0;
  border-bottom: 1px solid var(--line);
  font-size: .87rem;
}
.summary-row > :first-child { margin: 0; color: var(--ink-2); }
.summary-row > :last-child { margin: 0; text-align: right; font-weight: 500; font-variant-numeric: tabular-nums; color: var(--ink); }
.summary-row > :only-child { text-align: left; }
.scope-note { padding: .7rem .85rem; border-radius: 10px; background: var(--accent-wash); font-size: .8rem; line-height: 1.5; color: #23392f; }
.fineprint { font-size: .74rem; line-height: 1.5; color: var(--ink-3); }
.error {
  padding: .65rem .8rem;
  border: 1px solid rgba(154, 43, 32, .28);
  border-radius: 10px;
  background: var(--danger-wash);
  font-size: .82rem;
  line-height: 1.45;
  color: var(--danger);
}
.error:empty { display: none; }
.section-preview {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background-color: #faf8f3;
  background-image: linear-gradient(rgba(27, 31, 29, .045) 1px, transparent 1px), linear-gradient(90deg, rgba(27, 31, 29, .045) 1px, transparent 1px);
  background-size: 14px 14px;
}
.section-preview svg, .section-preview canvas { display: block; width: 100%; height: 100%; }

.action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .55rem;
  min-height: 2.6rem;
  padding: .6rem 1.25rem;
  border: 1px solid var(--line-2);
  border-radius: var(--pill);
  background: var(--surface);
  font-size: .88rem;
  font-weight: 500;
  line-height: 1.2;
  letter-spacing: .01em;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
  transition: background-color .18s var(--ease), border-color .18s var(--ease), color .18s var(--ease);
}
.action-primary { border-color: transparent; background: var(--ink); color: var(--paper); }
.action-primary:hover:not(:disabled) { background: var(--accent); }
.action-secondary { background: transparent; }
.action-secondary:hover:not(:disabled) { border-color: var(--ink-3); background: rgba(27, 31, 29, .04); }
.action:disabled, .action[aria-disabled='true'] { opacity: .4; }

/* Review dialog */
.review-dialog {
  width: min(40rem, calc(100vw - 2rem));
  max-width: none;
  max-height: min(86vh, 48rem);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 40px 90px -30px rgba(20, 24, 22, .45);
}
.review-dialog[open] { display: flex; flex-direction: column; animation: dialog-in .3s var(--ease) both; }
.review-dialog::backdrop { background: rgba(27, 31, 29, .36); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.3rem 1.4rem 1rem;
  border-bottom: 1px solid var(--line);
}
.dialog-title { font: 400 1.6rem/1.15 var(--serif); letter-spacing: -.006em; }
.dialog-close {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  flex: none;
  min-height: 2.25rem;
  padding: .35rem .8rem .35rem .6rem;
  border: 1px solid var(--line-2);
  border-radius: var(--pill);
  background: transparent;
  font-size: .8rem;
  font-weight: 500;
  color: var(--ink-2);
}
.dialog-close:hover { border-color: var(--ink-3); color: var(--ink); }
.review-content { flex: 1 1 auto; min-height: 0; overflow: auto; padding: .5rem 1.4rem 1.1rem; }
.review-content > :not(.summary-row) + *, .review-content > * + :not(.summary-row) { margin-top: .85rem; }
.dialog-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: .6rem;
  padding: 1rem 1.4rem 1.25rem;
  padding-bottom: max(1.25rem, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}
.export-status { flex: 1 1 100%; font-size: .8rem; line-height: 1.45; color: var(--ink-2); }

/* Notice */
.notice {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  bottom: max(1.25rem, calc(env(safe-area-inset-bottom) + .75rem));
  z-index: 50;
  max-width: min(34rem, calc(100vw - 2rem));
  padding: .7rem 1.1rem;
  border-radius: 12px;
  background: var(--ink);
  color: var(--paper);
  font-size: .85rem;
  line-height: 1.45;
  box-shadow: 0 18px 40px -18px rgba(20, 24, 22, .55);
  opacity: 0;
  transform: translate(-50%, .5rem);
  pointer-events: none;
  transition: opacity .25s var(--ease), transform .25s var(--ease);
}
.notice:not(:empty) { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.notice .error { padding: 0; border: 0; background: none; color: #f1c6bd; }

/* Colophon */
.colophon {
  grid-row: 4;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: .3rem 1.25rem;
  padding: .55rem var(--gutter) .85rem;
  font-size: .74rem;
  line-height: 1.45;
  color: var(--ink-3);
}
.colophon-mark { font-family: var(--serif); letter-spacing: .28em; color: var(--ink-2); }
.colophon p { flex: 1 1 24rem; max-width: 52rem; }
.colophon a { white-space: nowrap; }
.colophon a:hover { color: var(--ink); }

/* Stacked layout: sticky stage while configuring */
body[data-mode='configure'] .stage,
body[data-mode='design'] .stage {
  position: sticky;
  top: 0;
  z-index: 6;
  height: clamp(15rem, 42vh, 25rem);
  height: clamp(15rem, 42svh, 25rem);
  box-shadow: 0 14px 28px -24px rgba(27, 31, 29, .55);
}
@media (max-height: 34em) {
  body[data-mode='configure'] .stage,
  body[data-mode='design'] .stage { position: relative; height: clamp(16rem, 80vh, 24rem); }
}
@media not all and (min-width: 62em) and (min-height: 40em) {
  .pro-list { flex-direction: row; gap: .35rem; overflow-x: auto; padding-bottom: .25rem; scrollbar-width: thin; }
  .model-button, .component-button { flex: 0 0 auto; width: auto; border: 1px solid var(--line); border-radius: var(--pill); padding: .45rem .9rem; }
  .model-button.is-active, .model-button[aria-pressed='true'], .model-button[aria-selected='true'], .model-button[aria-current]:not([aria-current='false']),
  .component-button.is-active, .component-button[aria-pressed='true'], .component-button[aria-selected='true'], .component-button[aria-current]:not([aria-current='false']) {
    border-color: var(--accent);
    box-shadow: inset 0 0 0 1px var(--accent);
  }
}

/* Application layout: stage-centred grid, panels scroll independently */
@media (max-width: 80em) {
  :root { --outline-w: 13.5rem; --inspector-w: 20.5rem; --panel-w: 23.5rem; }
}
@media (min-width: 62em) and (min-height: 40em) {
  body { height: 100vh; height: 100dvh; overflow: hidden; }
  .studio { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); gap: var(--gutter); }
  .studio > * { grid-row: 1; min-height: 0; }
  .stage { grid-column: 1; }
  body[data-mode] .stage { position: relative; height: auto; box-shadow: none; }
  body[data-mode='discover'] .studio { grid-template-columns: minmax(19rem, .82fr) minmax(0, 1.5fr); }
  body[data-mode='discover'] .discovery { grid-column: 1; align-self: center; max-height: 100%; overflow: auto; padding: 1.5rem 0 1.5rem clamp(.5rem, 3vw, 3.5rem); }
  body[data-mode='discover'] .stage { grid-column: 2; }
  body[data-mode='configure'] .studio { grid-template-columns: minmax(0, 1fr) var(--panel-w); }
  body[data-mode='configure'] .stage { grid-column: 1; }
  .config-panel { grid-column: 2; overflow: hidden; }
  .step-content { overflow: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: rgba(27, 31, 29, .22) transparent; }
  body[data-mode='design'] .studio { grid-template-columns: var(--outline-w) minmax(0, 1fr) var(--inspector-w); }
  body[data-mode='design'] .stage { grid-column: 2; }
  body[data-mode='design'] .pro-panel {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: var(--outline-w) minmax(0, 1fr) var(--inspector-w);
    grid-template-rows: minmax(0, 1fr);
    column-gap: var(--gutter);
    pointer-events: none;
  }
  .pro-outline, .pro-inspector {
    grid-row: 1;
    overflow: auto;
    overscroll-behavior: contain;
    pointer-events: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(27, 31, 29, .22) transparent;
  }
  .pro-outline { grid-column: 1; }
  .pro-inspector { grid-column: 3; }
  .pro-scope { position: sticky; top: 0; z-index: 2; background: var(--surface); border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
}

/* Narrow screens */
@media (max-width: 47.99em) {
  .masthead { gap: .5rem .75rem; }
  .mode-nav { margin-left: auto; }
  .mode-link { padding: .4rem .8rem; }
  .masthead-tools { order: 3; flex: 1 1 100%; margin-left: 0; overflow-x: auto; scrollbar-width: none; }
  .document-status { flex: 1 1 auto; max-width: none; }
  .stage-meta { padding: .75rem .85rem 0; }
  .stage-foot { padding: .5rem .75rem .75rem; }
  .view-controls { display: flex; flex: 1 1 100%; }
  .view-controls button { flex: 1 1 0; padding: .45rem .3rem; }
  .config-head { padding: 1rem 1rem .3rem; }
  .step-nav { padding: .9rem 1rem .25rem; }
  .step-content { padding: .75rem 1rem 1.25rem; }
  .step-actions { padding-left: 1rem; padding-right: 1rem; }
  .hero-cta { width: 100%; }
  body[data-mode='configure'] .notice { bottom: calc(5.25rem + env(safe-area-inset-bottom)); }
}
@media (max-width: 40em) {
  .review-dialog { width: 100%; max-height: 92vh; max-height: 92dvh; margin: auto 0 0; border-bottom: 0; border-radius: 18px 18px 0 0; }
  .dialog-foot .action { flex: 1 1 100%; }
}

/* Motion */
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes sweep { to { transform: rotate(360deg); } }
@keyframes dialog-in { from { opacity: 0; transform: translateY(10px) scale(.99); } }
::view-transition-group(watch-stage) { animation-duration: .45s; animation-timing-function: cubic-bezier(.2, .7, .2, 1); }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-delay: 0s !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}

@media (forced-colors: active) {
  .mode-link.is-active, .view-controls button.is-active, .view-controls button[aria-pressed='true'],
  .scope-controls button.is-active, .scope-controls button[aria-pressed='true'],
  .model-button.is-active, .component-button.is-active, .step-button.is-active,
  .choice-card.is-active, .choice-card[aria-pressed='true'], .choice-card[aria-checked='true'] {
    outline: 2px solid Highlight;
    outline-offset: -2px;
  }
  .status-tag::before { background: CanvasText; }
}

/* Integration: exact control markup and authoring scope. */
.number-field { display:flex; align-items:center; gap:.65rem; }
.number-field .field-input { min-width:0; flex:1; }
.number-field .field-unit { flex:0 0 2.5rem; }
.color-field { display:flex; align-items:center; gap:.8rem; }
.color-field code { font-size:.78rem; color:var(--ink-2); }
.field-note { display:flex; flex-wrap:wrap; align-items:baseline; gap:.3rem .5rem; }
.inheritance { white-space:normal; letter-spacing:.015em; text-transform:none; }
.field[data-inheritance='linked'] .inheritance { background:var(--accent-wash); color:var(--accent); border-color:var(--line); }
.field[data-inheritance='shared'] .inheritance { background:transparent; color:var(--ink-3); border:0; padding:0; font-weight:400; }
#configuration-panel .field-note { display:none; }
.choice-swatch { position:relative; }
.choice-swatch i { position:absolute; width:.7rem; height:.7rem; border-radius:50%; top:.88rem; border:1px solid #8885; }
.choice-swatch i:first-child {left:.3rem;} .choice-swatch i:last-child {right:.3rem;}
.expression-choices .choice-card > svg { width:100%; aspect-ratio:1; max-height:8rem; }
#timing-dialog { width:min(90vw,34rem); max-height:90dvh; overflow:auto; padding:1.5rem; border:1px solid var(--line); border-radius:var(--radius-lg); background:var(--surface); color:var(--ink); }
#timing-dialog::backdrop {background:#151c1977;backdrop-filter:blur(4px);}
.dialog-header {display:flex; justify-content:space-between; align-items:center; gap:1rem;margin-bottom:1rem;}
.dialog-header h2 {font:400 1.7rem var(--serif);}
#timing-watch {height:19rem;} #timing-watch svg {width:100%;height:100%;}
#timing-dialog .buttons {display:flex;flex-wrap:wrap;gap:.5rem;margin:1rem 0;}
#timing-result {font-variant-numeric:tabular-nums;}
.fit-detail summary {font-size:.8rem;cursor:pointer;} .fit-detail p {margin-top:.6rem;}
body[data-mode='configure'] [data-view='section'] {display:none;}

#parameter-controls .field[data-inheritance='linked'] .inheritance { background:var(--accent-wash); color:var(--accent); border-color:var(--line); }
#svg-stage .dimension-line {fill:none;stroke:#899388;stroke-width:.1;}
#svg-stage .dimension-label {fill:#5d695e;font:1.2px Arial,sans-serif;letter-spacing:.08px;}

.step-nav,.config-head,.step-actions {flex-shrink:0;}

.brand img{display:block;width:124px;height:auto}.colophon-mark img{display:block;width:100px;height:auto}
