@font-face {
  font-family: Inter;
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/inter-latin-400-normal.woff2") format("woff2");
}
@font-face {
  font-family: Inter;
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("fonts/inter-latin-500-normal.woff2") format("woff2");
}
@font-face {
  font-family: Inter;
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("fonts/inter-latin-600-normal.woff2") format("woff2");
}
@font-face {
  font-family: Inter;
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/inter-latin-700-normal.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/ibm-plex-mono-latin-400-normal.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("fonts/ibm-plex-mono-latin-500-normal.woff2") format("woff2");
}

:root {
  --canvas: #f3f1ec;
  --dots: #ddd9d0;
  --elevated: #ffffff;
  --chrome-border: #e4e0d8;
  --text: #1a1916;
  --text-2: #5c5850;
  --text-3: #8a857c;
  --accent: #2c5f5a;
  --entity-header: #1c2b2a;
  --entity-title: #f6f4f0;
  --vo-border: #5a7a6e;
  --vo-fill: #f7faf8;
  --event-fill: #fdf0e6;
  --event-accent: #d86a2a;
  --event-text: #7a3a12;
  --edge: #8a857c;
  --danger: #b42318;
  --shadow: 0 10px 30px rgba(28, 27, 24, 0.08);
  --radius: 12px;
  color-scheme: light;
  font-family: Inter, "Segoe UI", sans-serif;
  color: var(--text);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --canvas: #121410;
    --dots: #2a2824;
    --elevated: #1c1b18;
    --chrome-border: #2e2c28;
    --text: #f3f1ec;
    --text-2: #b8b3a8;
    --text-3: #7a766c;
    --accent: #7eb8b0;
    --entity-header: #243533;
    --entity-title: #f3f1ec;
    --vo-border: #7a9a8e;
    --vo-fill: #171c1a;
    --event-fill: #2a2018;
    --event-accent: #e08a45;
    --event-text: #f5d4b8;
    --edge: #7a766c;
    --danger: #f97066;
    --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --canvas: #121410;
  --dots: #2a2824;
  --elevated: #1c1b18;
  --chrome-border: #2e2c28;
  --text: #f3f1ec;
  --text-2: #b8b3a8;
  --text-3: #7a766c;
  --accent: #7eb8b0;
  --entity-header: #243533;
  --entity-title: #f3f1ec;
  --vo-border: #7a9a8e;
  --vo-fill: #171c1a;
  --event-fill: #2a2018;
  --event-accent: #e08a45;
  --event-text: #f5d4b8;
  --edge: #7a766c;
  --danger: #f97066;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

:root[data-theme="light"] {
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--canvas); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.canvas {
  position: fixed;
  inset: 0;
  background-color: var(--canvas);
  background-image: radial-gradient(var(--dots) 1.15px, transparent 1.2px);
  background-size: 22px 22px;
  overflow: hidden;
}
.camera { position: absolute; top: 0; left: 0; transform-origin: 0 0; }
#edges { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
#edges .edge { pointer-events: auto; }
.canvas.panning, .canvas.panning .node { cursor: grab; }

.node {
  position: absolute;
  left: 0;
  top: 0;
  width: 220px;
  background: var(--elevated);
  box-shadow: var(--shadow);
  user-select: none;
}
.node.selected { box-shadow: 0 0 0 3px var(--canvas), 0 0 0 5px var(--accent), var(--shadow); }
.node.entity { border-radius: 8px; border: 1px solid var(--chrome-border); }
.node.valueObject {
  border-radius: 14px;
  background: var(--vo-fill);
  border: 1.5px dashed var(--vo-border);
}
.node.event {
  border-radius: 16px;
  background: var(--event-fill);
  border: 1px solid transparent;
  box-shadow: inset 0 3px 0 var(--event-accent), var(--shadow);
}
.node.event.selected { box-shadow: inset 0 3px 0 var(--event-accent), 0 0 0 3px var(--canvas), 0 0 0 5px var(--accent); }
.node-head {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 10px 0 12px;
}
.node.entity .node-head {
  height: 40px;
  background: var(--entity-header);
  color: var(--entity-title);
  border-radius: 7px 7px 0 0;
}
.node-title { font-size: 13px; font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node.valueObject .node-title, .node.event .node-title { color: var(--text); }
.node.event .node-title { color: var(--event-text); }
.badge {
  font-size: 11px;
  font-weight: 600;
  line-height: 16px;
  padding: 0 7px;
  border-radius: 999px;
  flex: none;
}
.badge-entity { background: rgba(246, 244, 240, 0.16); color: var(--entity-title); }
.badge-valueObject { background: transparent; color: var(--vo-border); border: 1px solid var(--vo-border); }
.badge-event { background: var(--event-accent); color: #fff7f0; }
.node-body { padding: 4px 0 8px; }
.field {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 12px;
  font-size: 12px;
  min-width: 0;
  overflow: hidden;
}
.diamond { font-size: 9px; width: 10px; }
.fname {
  flex: 1 0 auto;
  min-width: 6ch;
  max-width: 70%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ftype {
  margin-left: auto;
  max-width: 50%;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 0 1 auto;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 11px;
  color: var(--text-3);
}
.node.event .ftype, .node.event .fname { color: var(--event-text); }
.more { height: 16px; padding: 0 12px; font-size: 11px; color: var(--text-3); }

.switcher, .command, .panel, .menu, .dialog, .drawer, .first-card, .saved-cluster {
  background: var(--elevated);
  border: 1px solid var(--chrome-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.switcher {
  position: fixed;
  z-index: 30;
  top: 12px;
  left: 12px;
  min-width: 180px;
}
.switcher-button {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 44px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  border-radius: var(--radius);
  width: 100%;
}
.mark {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--accent);
  color: #f6f4f0;
  display: inline-grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
}
.wordmark { font-weight: 700; letter-spacing: 0.04em; font-size: 13px; }
.domain-name { font-size: 13px; color: var(--text-2); max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chevron { color: var(--text-3); margin-left: auto; }
.menu {
  position: absolute;
  top: 50px;
  left: 0;
  min-width: 240px;
  padding: 8px;
  display: grid;
  gap: 6px;
  z-index: 40;
}
.switcher .menu { min-width: min(360px, calc(100vw - 24px)); width: min(380px, calc(100vw - 24px)); }
.switcher .stack textarea { width: 100%; min-height: 48px; resize: vertical; white-space: pre-wrap; }
.menu-item, .menu button, .dialog button, .toolbar button, .empty button, .first-card button {
  border: 1px solid transparent;
  background: transparent;
  border-radius: 8px;
  min-height: 32px;
  padding: 4px 8px;
  text-align: left;
}
.menu-item:hover, .toolbar button:hover, .menu button:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.menu-item.active { color: var(--accent); font-weight: 600; }
.menu-actions { display: flex; gap: 6px; }
.stack { display: grid; gap: 4px; font-size: 11px; color: var(--text-3); min-width: 0; max-width: 100%; }
.stack input, .stack textarea, .panel input, .panel textarea, .grid input[type="text"] {
  border: 1px solid var(--chrome-border);
  background: var(--canvas);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 13px;
  width: 100%;
  min-width: 0;
  max-width: 100%;
}
.panel textarea { resize: vertical; min-height: 64px; }

.toolbar {
  position: fixed;
  z-index: 25;
  top: 12px;
  left: 220px;
  right: 12px;
  height: 44px;
  display: flex;
  justify-content: flex-start;
  align-items: flex-start;
  pointer-events: none;
  background: transparent;
  border: 0;
  box-shadow: none;
  border-radius: 0;
}
body.panel-open .toolbar { right: 384px; }
.toolbar-inner {
  pointer-events: auto;
  height: 44px;
  width: max-content;
  max-width: 100%;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 8px;
  background: var(--elevated);
  border: 1px solid var(--chrome-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.toolbar-inner.measuring {
  position: absolute;
  width: max-content;
  max-width: none;
  visibility: hidden;
}
#theme-toggle { display: inline-grid; place-items: center; width: 32px; height: 32px; padding: 0; }
#theme-toggle svg { display: block; }
.toolbar.is-collapsed .wide-only { display: none !important; }
.toolbar.is-collapsed .narrow-only { display: inline-flex !important; }
.toolbar.is-collapsed .toolbar-inner.measuring .wide-only,
.toolbar-inner.measuring .wide-only { display: inline-flex !important; }
.toolbar.is-collapsed .toolbar-inner.measuring .narrow-only,
.toolbar-inner.measuring .narrow-only { display: none !important; }
.toolbar button, .select-label {
  font-size: 13px;
  white-space: nowrap;
}
.select-label { display: flex; align-items: center; gap: 4px; color: var(--text-3); font-size: 11px; }
.select-label select {
  border: 1px solid var(--chrome-border);
  background: var(--canvas);
  border-radius: 8px;
  height: 30px;
  font-size: 12px;
}
.zoom { display: inline-flex; align-items: center; }
#zoom-label { min-width: 52px; text-align: center; }
.narrow-only { display: none; }
.pop { position: fixed; top: 62px; }

.command {
  position: fixed;
  z-index: 35;
  top: 68px;
  left: 220px;
  right: 12px;
  margin: 0 auto;
  width: min(560px, calc(100% - 24px));
  padding: 8px;
}
body.panel-open .command { right: 384px; }
.command-row { display: flex; gap: 8px; align-items: center; min-width: 0; }
#command-input { flex: 1 1 auto; min-width: 0; border: 0; background: transparent; font-size: 14px; padding: 4px 6px; }
.chip {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border-radius: 999px;
  padding: 3px 8px;
  max-width: none;
  overflow: visible;
  text-overflow: clip;
  white-space: nowrap;
}
.command-preview, .command-status { font-size: 12px; color: var(--text-2); padding: 0 6px; min-height: 0; line-height: 1.3; }
.suggest { list-style: none; margin: 2px 0 0; padding: 0; display: grid; }
.suggest button { width: 100%; text-align: left; border: 0; background: transparent; border-radius: 6px; padding: 2px 8px; min-height: 0; line-height: 1.25; }

.panel {
  position: fixed;
  z-index: 28;
  top: 12px;
  right: 12px;
  bottom: 12px;
  width: 360px;
  padding: 12px;
  overflow-x: hidden;
  overflow-y: auto;
  display: grid;
  align-content: start;
  gap: 10px;
}
.panel > * { min-width: 0; max-width: 100%; }
.panel-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.panel input.panel-name {
  flex: 1 1 0%;
  min-width: 0;
  width: auto;
  max-width: 100%;
  font-size: 16px;
  font-weight: 600;
  border: 0;
  background: transparent;
  border-radius: 0;
  padding: 4px;
  box-shadow: none;
}
.panel-head .badge,
.panel-head .icon-button { flex: none; flex-shrink: 0; }
.check-line { font-size: 12px; color: var(--text-2); display: flex; gap: 6px; align-items: center; }
.check-line input { width: 16px; height: 16px; flex: none; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--chrome-border); }
.tab { border: 0; background: transparent; border-radius: 8px 8px 0 0; font-size: 12px; color: var(--text-2); }
.tab.active { color: var(--accent); box-shadow: inset 0 -2px 0 var(--accent); }
.icon-button { border: 0; background: transparent; width: 32px; height: 32px; border-radius: 8px; font-size: 18px; }
#prop-table, #method-table, #rule-table {
  overflow-x: auto;
  max-width: 100%;
  min-width: 0;
}
.grid { width: 100%; min-width: 0; table-layout: fixed; border-collapse: collapse; }
.grid .col-identity { width: 28px; }
.grid .col-type { width: 26%; }
.grid .col-required { width: 74px; }
.grid .col-inputs { width: 28%; }
.grid .col-result { width: 24%; }
.grid .col-expression { width: 34%; }
.grid .col-id { width: 64px; }
.grid th, .grid td { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grid th { font-size: 11px; font-weight: 600; color: var(--text-3); text-align: left; padding: 4px; }
.grid td { padding: 3px; }
.grid th.col-identity, .grid td.col-identity, .grid th.col-required, .grid td.col-required { padding-left: 2px; padding-right: 2px; }
.grid td.col-identity, .grid td.col-required { text-align: center; }
.grid input[type="text"] { width: 100%; min-width: 0; max-width: 100%; text-overflow: ellipsis; }
.grid input[type="checkbox"] { width: 16px; height: 16px; }
.add-row {
  margin-top: 4px;
  border: 0;
  background: transparent;
  color: var(--text-3);
  font-size: 12px;
  padding: 4px 2px;
  min-height: 0;
  text-align: left;
}
.add-row:hover { color: var(--accent); }
#rule-table input[data-field="expression"], #method-table input[data-field="inputs"], #method-table input[data-field="result"] {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 12px;
}
.event-fields { display: grid; gap: 8px; }
.sheet-handle { display: none; }

.empty, .first-run {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  text-align: center;
}
.empty h1, .first-card h1 { font-size: 22px; font-weight: 600; margin: 0 0 8px; }
.empty p, .first-card p { color: var(--text-2); margin: 6px 0; }
.empty-actions { display: flex; gap: 8px; justify-content: center; pointer-events: auto; }
.empty button, .first-card button {
  background: var(--elevated);
  border: 1px solid var(--chrome-border);
  border-radius: 10px;
  padding: 8px 12px;
  box-shadow: var(--shadow);
}
.first-card .primary { background: var(--accent); color: #f6f4f0; }
.quiet { color: var(--text-3); font-size: 12px; }
.first-run { z-index: 50; background: color-mix(in srgb, var(--canvas) 78%, transparent); pointer-events: auto; }
.first-card { padding: 28px 32px; max-width: 460px; }
.mark-line { display: flex; gap: 8px; align-items: center; justify-content: center; font-weight: 700; }

.dialogs {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: color-mix(in srgb, #1a1916 28%, transparent);
  display: grid;
  place-items: center;
  padding: 24px;
}
.dialogs[hidden], [hidden] { display: none !important; }
.dialog { width: min(460px, 100%); padding: 18px; }
.dialog h2 { margin: 0 0 8px; font-size: 18px; }
.dialog h3 { margin: 10px 0 4px; font-size: 12px; color: var(--text-2); }
.dialog ul { margin: 0; padding-left: 18px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.dialog .danger { background: var(--danger); color: white; border-radius: 8px; padding: 6px 12px; }

.drawer {
  position: fixed;
  z-index: 32;
  left: 12px;
  bottom: 42px;
  width: min(380px, calc(100% - 24px));
  max-height: 40vh;
  overflow: auto;
  padding: 12px;
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; }
.drawer h2 { margin: 0; font-size: 14px; }
.warning-list { margin: 8px 0 0; padding-left: 18px; font-size: 13px; }
.saved-cluster {
  position: fixed;
  z-index: 22;
  left: 12px;
  bottom: 12px;
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 11px;
  color: var(--text-3);
}
.text-button { border: 0; background: transparent; color: var(--accent); font-size: 11px; }
.banner {
  position: fixed;
  z-index: 45;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--elevated);
  border: 1px solid var(--chrome-border);
  border-radius: 10px;
  padding: 8px 12px;
  box-shadow: var(--shadow);
  font-size: 13px;
}
.export-menu { position: fixed; width: min(260px, calc(100vw - 16px)); }

@media (max-width: 1100px) {
  .wordmark { display: none; }
  .command { left: 12px; }
}
@media (max-width: 767px) {
  .toolbar .wide-only { display: none !important; }
  .toolbar .narrow-only { display: inline-flex; }
  .switcher { max-width: 46vw; }
  .domain-name { max-width: 28vw; }
  body.panel-open .toolbar { right: 12px; }
  .panel {
    top: auto;
    left: 8px;
    right: 8px;
    width: auto;
    height: 64%;
    bottom: 8px;
  }
  .sheet-handle {
    display: block;
    width: 42px;
    height: 4px;
    border-radius: 99px;
    background: var(--chrome-border);
    margin: 0 auto 6px;
  }
  .command { top: 64px; left: 12px; right: 12px; width: auto; }
}
