:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #11151a;
  --panel: #191f26;
  --panel-2: #202832;
  --border: #303b47;
  --text: #ecf3f8;
  --muted: #92a1ad;
  --accent: #5ea8ff;
  --danger: #f17474;
  --neg: #f07178;
  --zero: #8a97a3;
  --pos: #52c7a5;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { min-height: 100vh; overflow: hidden; }
button, input { font: inherit; }
button { color: var(--text); }

.topbar {
  height: 58px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: #151a20;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: max-content; }
.brand-icon { width: 30px; height: 30px; object-fit: contain; flex: 0 0 auto; }
.brand strong { font-size: 18px; }
.brand span { color: var(--muted); font-size: 13px; }
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  margin-left: auto;
  overflow-x: auto;
  scrollbar-width: thin;
}
.toolbar-group {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
  padding-left: 8px;
  border-left: 1px solid var(--border);
}
.toolbar-group:first-child { padding-left: 0; border-left: 0; }
.toolbar button, .wide {
  border: 1px solid var(--border);
  background: var(--panel-2);
  border-radius: 8px;
  padding: 7px 9px;
  cursor: pointer;
  white-space: nowrap;
}
.toolbar select { border: 1px solid var(--border); background: var(--panel-2); color: var(--text); border-radius: 8px; padding: 7px 8px; }
.toolbar { overflow: visible; }
.toolbar-menu { position: relative; flex: 0 0 auto; }
.toolbar-menu > summary { list-style: none; border: 1px solid var(--border); background: var(--panel-2); border-radius: 8px; padding: 7px 9px; cursor: pointer; white-space: nowrap; font-size: 13px; }
.toolbar-menu > summary::-webkit-details-marker { display: none; }
.toolbar-menu > summary::after { content: '⌄'; margin-left: 6px; color: var(--muted); }
.toolbar-menu[open] > summary { border-color: var(--accent); color: #d9ecff; }
.toolbar-menu-panel { position: absolute; top: calc(100% + 7px); right: 0; z-index: 30; min-width: 142px; padding: 8px; border: 1px solid var(--border); border-radius: 9px; background: #1b222a; box-shadow: 0 12px 26px rgba(0, 0, 0, .35); }
.toolbar-menu-panel .toolbar-group { display: grid; grid-template-columns: 1fr; align-items: stretch; gap: 6px; padding: 0; border: 0; }
.toolbar-menu-panel .toolbar-group button { width: 100%; text-align: left; }
.toolbar-menu-panel .compact-actions, .toolbar-menu-panel .file-actions { grid-template-columns: repeat(2, minmax(76px, 1fr)); }
.toolbar-menu-panel .compact-actions button, .toolbar-menu-panel .file-actions button { min-width: 0; }
.toolbar-menu-panel .project-actions { min-width: 190px; }
.toolbar-menu-panel .project-picker select, .toolbar-menu-panel .project-name { width: 100%; max-width: none; }
.toolbar-menu-panel .menu-field { display: grid; gap: 4px; color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.toolbar-menu-panel .menu-field select { background: #18334a; border-color: #4e8bca; color: #d9ecff; }
.toolbar-menu-panel .menu-field input { background: #151a20; border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 7px 9px; }
.toolbar-menu-panel .menu-primary { background: #1c4668; border-color: #5ea8ff; color: #e4f2ff; font-weight: 650; }
.toolbar-menu-panel .danger-actions button { background: #342228; border-color: rgba(241, 116, 116, .5); }
.toolbar-menu-panel .utility-actions { min-width: 230px; }
.toolbar-menu-panel .utility-actions select { width: 100%; }
.project-message { grid-column: 1 / -1; padding: 7px 8px; border: 1px solid rgba(94, 168, 255, .38); border-radius: 6px; background: #172534; color: #d9ecff; font-size: 11px; line-height: 1.35; overflow-wrap: anywhere; }
.project-message.error { border-color: rgba(241, 116, 116, .62); background: #2a2024; color: #ffc7c7; }
.compact-actions button { min-width: 46px; }
.danger-actions { border-left-color: rgba(241, 116, 116, .45); }
.danger-actions button { background: #292024; }
.toolbar button:hover, .wide:hover, .component-button:hover { border-color: #526579; }
button.danger { color: #ffc7c7; }
button:disabled { opacity: .45; cursor: not-allowed; }

.app-shell {
  height: calc(100vh - 58px);
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr) 230px;
  min-height: 0;
}

.sidebar {
  background: var(--panel);
  padding: 14px;
  overflow-y: auto;
}
.left-panel { border-right: 1px solid var(--border); }
.right-panel { border-left: 1px solid var(--border); }
.sidebar h2 { margin: 0 0 10px; font-size: 14px; text-transform: uppercase; letter-spacing: .08em; color: #c8d4de; }
.sidebar h2:not(:first-child) { margin-top: 22px; }
.sidebar h3 { margin: 16px 0 8px; font-size: 13px; color: #c8d4de; }
.hint { margin: -2px 0 12px; color: var(--muted); font-size: 12px; line-height: 1.35; }
.component-list { display: grid; gap: 8px; }
.component-button {
  text-align: left;
  border: 1px solid var(--border);
  background: var(--panel-2);
  border-radius: 9px;
  padding: 10px;
  cursor: pointer;
}
.component-button strong, .component-button span { display: block; }
.component-button strong { font-size: 13px; }
.component-button span { color: var(--muted); font-size: 11px; margin-top: 3px; }
.legend { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 2px; }
.legend div { display: flex; align-items: center; gap: 8px; color: #cbd5de; font-size: 12px; margin: 7px 0; }
.dot { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }
.dot.neg { background: var(--neg); } .dot.zero { background: var(--zero); } .dot.pos { background: var(--pos); } .dot.floating { background: #efb75f; } .dot.unknown { background: #9570ba; }

.workspace-wrap { min-width: 0; min-height: 0; position: relative; background: #0f1318; }
#workspace { position: absolute; inset: 0; overflow: hidden; }
#workspace canvas { width: 100%; height: 100%; display: block; outline: none; touch-action: none; }
.workspace-help {
  position: absolute;
  left: 12px;
  bottom: 12px;
  display: flex;
  flex-wrap: wrap;
  max-width: calc(100% - 24px);
  gap: 6px 12px;
  pointer-events: none;
  color: #8f9ba5;
  font-size: 11px;
  background: rgba(14, 18, 23, .82);
  border: 1px solid rgba(64, 76, 88, .65);
  border-radius: 8px;
  padding: 7px 9px;
}
.status {
  position: absolute;
  right: 12px;
  bottom: 12px;
  max-width: 40%;
  pointer-events: none;
  color: #cbd5de;
  background: rgba(14, 18, 23, .88);
  border: 1px solid rgba(64, 76, 88, .75);
  border-radius: 8px;
  padding: 7px 9px;
  font-size: 11px;
}
.status.error { color: #ffb3b3; border-color: rgba(241, 113, 116, .55); }

.inspector {
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px;
  background: var(--panel-2);
  font-size: 12px;
}
.inspector.empty { color: var(--muted); }
.inspector dl { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; margin: 0; }
.inspector dt { color: var(--muted); }
.inspector dd { margin: 0; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.toggle-row { display: flex; align-items: center; gap: 8px; font-size: 12px; color: #d6e0e7; margin-bottom: 10px; }
.wide { width: 100%; }
.stats { margin-top: 14px; display: grid; gap: 7px; }
.stats div { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; color: var(--muted); }
.stats strong { color: var(--text); font-family: ui-monospace, monospace; }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 165px minmax(0, 1fr); }
  .right-panel { display: none; }
  .brand span { display: none; }
}

@media (max-width: 1520px) {
  .brand span { display: none; }
}

@media (max-width: 1180px) {
  .topbar { gap: 10px; }
  .brand span { display: none; }
  .toolbar { gap: 5px; }
  .toolbar-group { padding-left: 5px; gap: 3px; }
  .toolbar button { padding-inline: 8px; }
  .project-name { width: 112px; }
}

@media (max-width: 620px) {
  body { overflow: auto; }
  .topbar { height: auto; min-height: 58px; flex-wrap: wrap; padding-block: 8px; }
  .toolbar { width: 100%; margin-left: 0; flex-wrap: wrap; }
  .app-shell { height: calc(100vh - 74px); grid-template-columns: 1fr; grid-template-rows: auto minmax(360px, 1fr); }
  .left-panel { border-right: 0; border-bottom: 1px solid var(--border); padding: 9px; overflow-x: auto; }
  .left-panel h2, .left-panel .hint, .legend { display: none; }
  .component-list { display: flex; gap: 7px; width: max-content; }
  .component-button { min-width: 115px; }
  .workspace-help { display: none; }
  .status { max-width: calc(100% - 24px); }
}

.inspector .selection-actions { margin-top: 10px; display: grid; gap: 7px; }
.inspector .selection-actions button { border: 1px solid var(--border); background: #2a2225; color: #ffc7c7; border-radius: 7px; padding: 7px 9px; cursor: pointer; }
.inspector .wire-endpoint { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; overflow-wrap: anywhere; }

.breadcrumbs {
  height: 34px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
  background: #12171d;
  color: var(--muted);
  font-size: 12px;
}
.breadcrumbs button { border: 0; background: transparent; color: #cbd5de; cursor: pointer; padding: 4px 6px; border-radius: 5px; }
.breadcrumbs button:hover { background: var(--panel-2); }
.breadcrumbs .sep { color: #586675; }
.breadcrumbs .current { color: var(--text); font-weight: 600; }
.app-shell { height: calc(100vh - 120px); }
.project-footer {
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-top: 1px solid var(--border);
  background: #12171d;
  font-size: 11px;
}
.github-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border: 1px solid #344252;
  border-radius: 999px;
  color: #afc1d3;
  background: #18212b;
  text-decoration: none;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .04) inset;
  transition: border-color .15s ease, color .15s ease, background .15s ease, transform .15s ease;
}
.github-icon { width: 14px; height: 14px; fill: currentColor; flex: 0 0 auto; }
.github-link:hover, .github-link:focus-visible {
  color: #f1f6fb;
  border-color: var(--accent);
  background: #1c2b39;
  text-decoration: none;
  transform: translateY(-1px);
}
.github-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (max-width: 620px) {
  .app-shell { height: calc(100vh - 102px); }
}
.inspector input[type="text"] { width: 100%; margin-top: 6px; border: 1px solid var(--border); background: #151a20; color: var(--text); border-radius: 7px; padding: 7px 8px; }
.inspector .primary-action { background: #1c344b !important; color: #d9ecff !important; }
.component-button.custom strong::after { content: ' ↳'; color: var(--accent); }
.library-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.library-heading h2 { margin-right: 0; }
.library-heading button { border: 1px solid #4e8bca; border-radius: 7px; background: #18334a; color: #d9ecff; padding: 5px 8px; cursor: pointer; font-size: 11px; }
.library-heading button:hover { border-color: var(--accent); }
.custom-library-entry { display: flex; align-items: stretch; gap: 6px; }
.custom-library-entry .component-button { flex: 1; min-width: 0; }
.custom-library-actions { display: grid; grid-template-rows: repeat(3, 1fr); gap: 4px; flex: 0 0 auto; }
.open-custom-component, .export-custom-component, .remove-custom-component { border: 1px solid var(--border); border-radius: 7px; padding: 4px 8px; cursor: pointer; font-size: 11px; }
.open-custom-component { background: #1c344b; color: #d9ecff; }
.export-custom-component { background: #20362e; color: #c7f1de; border-color: rgba(82,199,165,.45); }
.open-custom-component:hover, .export-custom-component:hover { border-color: var(--accent); }
.remove-custom-component { background: #292024; color: #ffc7c7; border-color: rgba(241,116,116,.45); }
.remove-custom-component:hover { border-color: var(--danger); }


/* Reusable component isolation test panel */
.component-test-panel { display: grid; gap: 10px; }
.component-test-group { border: 1px solid var(--border); background: var(--panel-2); border-radius: 9px; padding: 9px; }
.component-test-group h3 { margin: 0 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.component-test-fold > summary { list-style: none; cursor: pointer; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); user-select: none; }
.component-test-fold > summary::-webkit-details-marker { display: none; }
.component-test-fold > summary::before { content: '›'; display: inline-block; margin-right: 6px; color: var(--accent); font-size: 15px; line-height: 10px; transform: rotate(0deg); transition: transform .12s ease; }
.component-test-fold[open] > summary::before { transform: rotate(90deg); }
.component-test-fold-content { padding-top: 7px; }
.component-test-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px; margin: 6px 0; }
.component-test-name { min-width: 0; overflow-wrap: anywhere; font: 12px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.trit-choice { display: inline-flex; gap: 4px; }
.trit-choice button { min-width: 34px; border: 1px solid var(--border); background: #151a20; color: var(--text); border-radius: 6px; padding: 5px 7px; cursor: pointer; }
.trit-choice button:hover { border-color: #64788d; }
.trit-choice button.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
/* Trit selection is a value chooser, not a destructive inspector action. */
.inspector .trit-choice button { background: #151a20; color: var(--text); border-color: var(--border); }
.inspector .trit-choice button:hover { background: #1b252e; border-color: #64788d; }
.inspector .trit-choice button.active { background: #18334a; color: #d9ecff; border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.word-input-choice { display: grid; grid-template-columns: 24px minmax(0, 1fr); align-items: center; gap: 6px; margin-top: 6px; font: 12px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.word-input-choice .trit-choice { gap: 3px; flex-wrap: wrap; }
.word-input-choice .trit-choice button { min-width: 30px; padding: 4px 6px; }
.joystick-choice { display: grid; grid-template-columns: repeat(3, 34px); gap: 4px; width: max-content; margin: 9px auto; }
.joystick-choice button { min-height: 31px; border: 1px solid var(--border); border-radius: 7px; background: #151a20; color: var(--muted); cursor: pointer; }
.joystick-choice button:hover { border-color: #64788d; background: #1b252e; }
.joystick-choice button.active { border-color: var(--accent); color: #d9ecff; background: #18334a; box-shadow: 0 0 0 1px var(--accent) inset; }
.component-test-value { min-width: 38px; text-align: center; border-radius: 6px; padding: 4px 7px; background: #151a20; font: 700 12px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.component-test-empty { color: var(--muted); font-size: 12px; }
.component-test-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.component-test-actions input { grid-column: 1 / -1; min-width: 0; border: 1px solid var(--border); background: #151a20; color: var(--text); border-radius: 6px; padding: 6px 7px; }
.component-test-actions button, .case-remove { border: 1px solid var(--border); border-radius: 6px; background: #151a20; color: var(--text); padding: 6px 7px; cursor: pointer; font-size: 11px; }
.component-test-actions button { min-width: 0; }
.component-test-actions button:hover, .case-remove:hover { border-color: #64788d; }
.component-test-case-list, .component-test-run-list { display: grid; gap: 5px; margin-top: 9px; }
/* Keep large saved suites usable: actions remain visible while only the cases scroll. */
.component-test-case-list { max-height: 260px; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; padding-right: 3px; }
.component-test-case, .component-test-run { display: flex; align-items: center; justify-content: space-between; gap: 8px; border-top: 1px solid rgba(48,59,71,.7); padding-top: 6px; font-size: 11px; }
.component-test-run { display: block; line-height: 1.35; }
.component-test-run.passed { color: var(--pos); }
.component-test-run.failed { color: #ffb3b3; }
.case-remove { color: #ffc7c7; padding: 3px 6px; }
.component-test-results { max-height: 240px; overflow: auto; border: 1px solid var(--border); border-radius: 9px; background: var(--panel-2); padding: 9px; }
.component-test-results h3 { margin: 0 0 7px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.component-test-results.has-failures { border-color: rgba(241, 116, 116, .55); }
.component-test-results.all-passed { border-color: rgba(82, 199, 165, .45); }
.truth-table { width: 100%; border-collapse: collapse; font: 11px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; text-align: center; }
.truth-table th, .truth-table td { border: 1px solid rgba(48,59,71,.8); padding: 4px 5px; }
.truth-table th { position: sticky; top: 0; background: #202832; color: var(--muted); font-weight: 600; }

/* v10 editor controls */
.inspector .editor-field { display: block; margin-top: 10px; color: var(--muted); font-size: 11px; }
.inspector .editor-field input,
.inspector .editor-field select { width: 100%; margin-top: 5px; border: 1px solid var(--border); background: #151a20; color: var(--text); border-radius: 7px; padding: 7px 8px; }
.inspector .field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.inspector details.layout-editor { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 10px; }
.inspector details.layout-editor summary { cursor: pointer; color: #cbd5de; font-weight: 600; }

/* v11 simulation scheduler */
.simulation-controls { display: grid; gap: 8px; margin-bottom: 10px; }
.simulation-mode-row, .simulation-step-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.simulation-step-row { grid-template-columns: 1fr 1fr; }
.simulation-controls button {
  min-width: 0; border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  border-radius: 7px; padding: 7px 6px; cursor: pointer; font-size: 11px; font-weight: 700;
}
.simulation-controls button:hover { border-color: #526579; }
.simulation-controls button.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.simulation-speed { display: block; color: var(--muted); font-size: 11px; }
.simulation-speed select { width: 100%; margin-top: 5px; border: 1px solid var(--border); background: #151a20; color: var(--text); border-radius: 7px; padding: 7px 8px; }
.queue-inspector { margin-top: 12px; border: 1px solid var(--border); background: var(--panel-2); border-radius: 9px; overflow: hidden; }
.queue-header { display: flex; justify-content: space-between; align-items: center; padding: 8px 9px; border-bottom: 1px solid var(--border); font-size: 11px; }
.queue-header span { min-width: 24px; text-align: center; border-radius: 999px; background: #151a20; padding: 2px 6px; font: 700 11px ui-monospace, monospace; }
.queue-list { max-height: 180px; overflow-y: auto; }
.queue-empty { padding: 9px; color: var(--muted); font-size: 11px; }
.queue-event { display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 7px; padding: 7px 9px; border-top: 1px solid rgba(48,59,71,.65); font-size: 10px; }
.queue-event:first-child { border-top: 0; }
.queue-event .seq { color: var(--muted); font-family: ui-monospace, monospace; }
.queue-event strong { display: block; font-size: 11px; overflow-wrap: anywhere; }
.queue-event small { display: block; margin-top: 2px; color: var(--muted); overflow-wrap: anywhere; }


/* Primitive-set experiments */
.primitive-set-panel { border: 1px solid var(--border); border-radius: 10px; padding: 10px; margin-bottom: 10px; background: rgba(255,255,255,.02); }
.primitive-set-panel details { margin-top: 8px; }
.primitive-set-panel summary { cursor: pointer; color: var(--muted); font-size: 12px; }
.primitive-set-description { margin: 6px 0 0; }
.primitive-set-checks { display: grid; gap: 5px; margin-top: 8px; }
.primitive-set-check { display: flex; align-items: center; gap: 7px; font-size: 12px; }
.primitive-set-check input { margin: 0; }
.primitive-set-cost { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); color: var(--muted); font-size: 11px; line-height: 1.45; }
.primitive-group { margin: 0 0 14px; }
.primitive-group h3 { margin: 0 0 6px; color: var(--muted); font-size: 11px; font-weight: 750; letter-spacing: .08em; text-transform: uppercase; }
.primitive-group-list { gap: 6px; }
.component-button .candidate-badge { display: inline-block; margin-left: 6px; font-size: 9px; font-weight: 700; color: var(--accent); }
.implementation-panel { margin-top: 10px; border: 1px solid #3a5c72; border-radius: 8px; padding: 8px; background: rgba(59, 115, 148, .09); color: var(--muted); font-size: 11px; line-height: 1.45; }
.implementation-panel summary { cursor: pointer; color: #d5eaff; font-weight: 700; }
.implementation-panel p { margin: 7px 0 0; }
.implementation-panel ol { margin: 5px 0 0; padding-left: 19px; }
.implementation-status strong { color: #9bd1ff; text-transform: capitalize; }
.implementation-label { color: #d5eaff; font-weight: 700; }
.implementation-reference { color: #b9e4d3; }
.cost-note { margin-top: 10px; padding: 8px; border: 1px solid var(--border); border-radius: 8px; font-size: 11px; color: var(--muted); }

/* Project persistence controls */
.project-picker select,
.project-name {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 9px;
  min-width: 120px;
  max-width: 180px;
}
.project-name { width: 135px; }

/* Sequential commit/timeline */
.simulation-step-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.state-timeline .queue-header button { border: 1px solid var(--border); border-radius: 5px; background: #151a20; color: var(--muted); padding: 3px 6px; cursor: pointer; font-size: 10px; }
.state-timeline .queue-list { max-height: 150px; }

/* Hardware-like clock controls */
.simulation-step-row { grid-template-columns: 1fr 1fr; }
