:root {
  --bg: #171717;
  --rail: #242424;
  --surface: #1b1b1b;
  --surface-raised: #242424;
  --surface-hover: #2d2d2d;
  --input: #202020;
  --ink: #f2f2f2;
  --muted: #a6a6a6;
  --faint: #727272;
  --line: #343434;
  --line-strong: #444;
  --blue: #4c9aff;
  --blue-hover: #68aaff;
  --green: #58c78a;
  --rust: #e29367;
  --gold: #d7b65c;
  --quality: #63b78d;
  --quantity: #d79765;
  --measure: #9781d0;
  --danger: #ee7d75;
  --radius: 10px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
  font-size: 14px;
  background: var(--bg);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  height: 100vh;
}

.brand,
.top-actions,
.section-heading,
.canvas-toolbar,
.canvas-identity,
.canvas-command-groups,
.canvas-actions,
.inspector-header,
.dialog-header {
  display: flex;
  align-items: center;
}

.brand {
  gap: 11px;
  min-width: 0;
}

.brand-mark {
  position: relative;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #202020;
}

.brand-mark span {
  position: absolute;
  top: 7px;
  width: 6px;
  height: 14px;
  border: 1.5px solid #b8b8b8;
  border-radius: 2px;
}

.brand-mark span:first-child {
  left: 7px;
}

.brand-mark span:last-child {
  right: 7px;
  background: #b8b8b8;
}

.eyebrow,
.canvas-kicker {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.035em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1,
h2,
h3 {
  font-family: inherit;
}

h1 {
  margin-bottom: 0;
  overflow: hidden;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

h2 {
  margin-bottom: 0;
  font-size: 15px;
  font-weight: 600;
}

h3 {
  font-size: 14px;
  font-weight: 600;
}

.top-actions {
  gap: 8px;
}

.save-state {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-right: 5px;
  color: var(--muted);
  font-size: 12px;
}

.save-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--faint);
}

.save-state.dirty .save-dot {
  background: var(--gold);
}

.save-state.saved .save-dot {
  background: var(--green);
}

.save-state.error .save-dot {
  background: var(--danger);
}

.button,
.icon-button,
.text-button,
.stat {
  border: 0;
  cursor: pointer;
}

.button {
  min-height: 34px;
  border-radius: 8px;
  padding: 0 13px;
  font-size: 13px;
  font-weight: 500;
  transition:
    background 120ms ease,
    border-color 120ms ease,
    opacity 120ms ease;
}

.button.primary {
  color: #fff;
  background: var(--blue);
}

.button.primary:hover:not(:disabled) {
  background: var(--blue-hover);
}

.button.secondary,
.button.ghost {
  color: var(--ink);
  background: var(--surface-raised);
}

.button.secondary:hover:not(:disabled),
.button.ghost:hover:not(:disabled) {
  background: var(--surface-hover);
}

.button:disabled {
  cursor: default;
  opacity: 0.38;
}

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

.sidebar,
.graph-panel {
  min-height: 0;
  overflow: hidden;
}

.side-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border-right: 1px solid var(--line);
  background: var(--rail);
}

.side-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  height: 50px;
  gap: 4px;
  padding: 8px;
  border-bottom: 1px solid var(--line);
  background: #202020;
}

.side-tab {
  position: relative;
  min-height: 34px;
  border: 0;
  border-radius: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  background: transparent;
  cursor: pointer;
}

.side-tab:hover {
  color: var(--ink);
  background: #292929;
}

.side-tab.active {
  color: var(--ink);
  background: #333;
}

.tab-indicator {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--blue);
}

.side-tab-panel {
  min-height: 0;
}

.controls-panel {
  overflow-y: auto;
  background: var(--rail);
}

.panel-section {
  padding: 17px 16px;
  border-bottom: 1px solid var(--line);
}

.section-heading {
  justify-content: space-between;
  gap: 12px;
}

.section-heading.compact {
  margin-bottom: 12px;
}

.score-ring {
  --score: 0deg;
  display: grid;
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  background:
    radial-gradient(circle, var(--rail) 59%, transparent 61%),
    conic-gradient(var(--blue) var(--score), var(--line-strong) 0);
}

.score-ring strong {
  font-size: 11px;
  font-weight: 600;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin-top: 14px;
}

.stat {
  display: flex;
  min-height: 54px;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  color: var(--ink);
  text-align: left;
  background: #292929;
}

.stat strong {
  font-size: 15px;
  font-weight: 600;
}

.stat span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.issue-stat:hover {
  border-color: var(--line-strong);
  background: #303030;
}

.field-label {
  display: block;
  margin: 12px 0 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}

.panel-section > .field-label:first-child {
  margin-top: 0;
}

.search-wrap {
  position: relative;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 9px 10px;
  color: var(--ink);
  background: var(--input);
  outline: none;
}

input,
select {
  min-height: 38px;
}

select {
  text-overflow: ellipsis;
}

textarea {
  resize: vertical;
  line-height: 1.48;
}

input::placeholder,
textarea::placeholder {
  color: #777;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(76, 154, 255, 0.16);
}

.search-wrap input {
  padding-right: 34px;
}

kbd {
  position: absolute;
  top: 9px;
  right: 9px;
  min-width: 20px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 2px 5px;
  color: var(--faint);
  font-family: inherit;
  font-size: 10px;
  text-align: center;
  background: #2a2a2a;
}

.search-results {
  display: none;
  max-height: 188px;
  margin-top: 7px;
  overflow-y: auto;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
}

.search-results.active {
  display: block;
}

.search-result {
  display: block;
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
  color: var(--ink);
  text-align: left;
  background: transparent;
  cursor: pointer;
}

.search-result:last-child {
  border-bottom: 0;
}

.search-result:hover {
  background: var(--surface-hover);
}

.search-result strong,
.search-result span {
  display: block;
}

.search-result strong {
  font-size: 12px;
  font-weight: 500;
}

.search-result span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
}

.control-help,
.field-help {
  margin: 6px 0 0;
  color: var(--faint);
  font-size: 10px;
  line-height: 1.4;
}

.text-button {
  padding: 0;
  color: var(--blue);
  font-size: 12px;
  font-weight: 500;
  background: transparent;
}

.text-button:hover {
  color: var(--blue-hover);
}

.legend {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 11px 8px;
  color: var(--muted);
  font-size: 11px;
}

.legend > div {
  display: flex;
  align-items: center;
  gap: 7px;
}

.swatch {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.swatch.quality {
  background: var(--quality);
}

.swatch.quantity {
  background: var(--quantity);
}

.swatch.measure {
  background: var(--measure);
}

.line-key {
  display: block;
  width: 18px;
  border-top: 2px solid;
}

.line-key.sublates {
  border-color: var(--green);
}

.line-key.negates {
  border-color: var(--rust);
  border-top-style: dashed;
}

.line-key.moment {
  border-color: #929292;
  border-top-style: dotted;
}

.action-stack {
  display: grid;
  gap: 8px;
}

.button.full {
  width: 100%;
}

.graph-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--bg);
}

.canvas-toolbar {
  height: 50px;
  justify-content: space-between;
  gap: 16px;
  padding: 0 12px;
  font-size: 12px;
  border-bottom: 1px solid var(--line);
  background: #191919;
}

.canvas-identity {
  min-width: 0;
  gap: 16px;
}

.canvas-command-groups {
  flex: 0 0 auto;
  gap: 9px;
}

.canvas-toolbar .brand-mark {
  width: 28px;
  height: 28px;
}

.canvas-toolbar .brand-mark span {
  top: 6px;
}

.canvas-toolbar .brand-mark span:first-child {
  left: 6px;
}

.canvas-toolbar .brand-mark span:last-child {
  right: 6px;
}

.toolbar-divider {
  width: 1px;
  height: 24px;
  background: var(--line);
}

.canvas-kicker {
  color: var(--ink);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
}

.canvas-hint {
  margin: 0;
  color: var(--faint);
  font-size: 11px;
}

.canvas-actions {
  gap: 5px;
}

.icon-button {
  display: grid;
  min-width: 28px;
  height: 28px;
  place-items: center;
  /* border: 1px solid var(--line); */
  border-radius: 10px;
  padding: 0 8px;
  color: var(--muted);
  font-weight: 500;
  background: none;
}
.icon-button:hover {
  border-color: var(--line-strong);
  color: var(--ink);
  background: var(--surface-hover);
}

.graph-canvas {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background:
    linear-gradient(rgba(255, 255, 255, 0.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px),
    #171717;
  background-size: 32px 32px;
}

.section-guide {
  fill: rgba(255, 255, 255, 0.012);
  stroke: rgba(255, 255, 255, 0.055);
  stroke-width: 1;
}

.section-guide.section-quality {
  stroke: rgba(99, 183, 141, 0.2);
}

.section-guide.section-quantity {
  stroke: rgba(215, 151, 101, 0.2);
}

.section-guide.section-measure {
  stroke: rgba(151, 129, 208, 0.2);
}

.section-guide-title {
  fill: var(--ink);
  font-size: 13px;
  font-weight: 600;
}

.section-guide-meta {
  fill: var(--faint);
  font-size: 9px;
}

#graph-svg {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

#graph-svg.panning {
  cursor: grabbing;
}

.edge {
  fill: none;
  stroke-width: 3;
  opacity: 0.8;
  cursor: pointer;
  transition:
    opacity 120ms ease,
    stroke-width 120ms ease;
}

.edge:hover,
.edge.selected {
  stroke-width: 3;
  opacity: 1;
}

.edge.sublates_into {
  stroke: var(--green);
  marker-end: url(#arrow-sublates);
}

.edge.negates {
  stroke: var(--rust);
  stroke-dasharray: 7 5;
  marker-end: url(#arrow-negates);
}

.edge.direct_moment_of {
  stroke: #8e8e8e;
  stroke-dasharray: 2 5;
  marker-end: url(#arrow-moment);
}

#arrow-sublates path {
  fill: var(--green);
}

#arrow-negates path {
  fill: var(--rust);
}

#arrow-moment path {
  fill: #8e8e8e;
}

.edge.filtered,
.node.filtered {
  opacity: 0.045;
  pointer-events: none;
}

.node {
  cursor: move;
}

.node .node-disc {
  stroke-width: 2;
  transition: stroke-width 120ms ease;
}

.node.section-quality .node-disc {
  fill: #26332d;
  stroke: var(--quality);
}

.node.section-quantity .node-disc {
  fill: #352c26;
  stroke: var(--quantity);
}

.node.section-measure .node-disc {
  fill: #2d2938;
  stroke: var(--measure);
}

.node:hover .node-disc,
.node.selected .node-disc {
  stroke-width: 3.5;
}

.node.selected .selection-ring {
  fill: none;
  stroke: var(--blue);
  stroke-width: 2;
  stroke-dasharray: 4 4;
}

.node.reviewed .review-mark {
  display: block;
}

.review-mark {
  display: none;
  fill: dodgerblue;
  stroke: #171717;
  stroke-width: 3;
}

.node-label {
  fill: var(--ink);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
  font-size: 10px;
  font-weight: 600;
  text-anchor: middle;
  pointer-events: none;
}

.node-sublabel {
  fill: var(--muted);
  font-size: 7.5px;
  font-weight: 500;
}

.empty-state {
  position: absolute;
  inset: 50% auto auto 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transform: translate(-50%, -50%);
  color: var(--muted);
}

.selection-chip {
  position: absolute;
  bottom: 14px;
  left: 14px;
  max-width: 60%;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 7px 10px;
  color: var(--ink);
  font-size: 11px;
  background: rgba(36, 36, 36, 0.96);
  pointer-events: none;
}

.canvas-footer {
  display: flex;
  min-height: 34px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 14px;
  border-top: 1px solid var(--line);
  color: var(--faint);
  font-size: 10px;
  background: #191919;
}

.inspector-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--surface);
}

.inspector-header {
  min-height: 58px;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
}

.close-inspector {
  font-size: 16px;
}

.inspector-content {
  min-height: 0;
  overflow-y: auto;
  padding: 14px;
}

.inspector-empty {
  padding: 62px 24px 0;
  color: var(--muted);
  text-align: center;
}

.inspector-empty h3 {
  margin-bottom: 8px;
  color: var(--ink);
}

.inspector-empty p {
  font-size: 12px;
  line-height: 1.55;
}

.empty-glyph {
  display: grid;
  width: 44px;
  height: 44px;
  margin: 0 auto 15px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
  font-size: 24px;
  background: #202020;
}

.inspector-form {
  display: grid;
  gap: 11px;
}

.inspector-form .field-label {
  margin: 0 0 5px;
}
.inspector-form label textarea {
  field-sizing: content;
}

.review-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 11px;
  background: var(--surface-raised);
}

.review-card strong,
.review-card span {
  display: block;
}

.review-card strong {
  font-size: 12px;
  font-weight: 600;
}

.review-card span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
}

.review-toggle {
  flex: 0 0 auto;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  padding: 6px 9px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 500;
  background: #202020;
  cursor: pointer;
}

.review-toggle.active {
  border-color: rgba(76, 154, 255, 0.55);
  color: #b8d7ff;
  background: rgba(76, 154, 255, 0.12);
}

.relation-preview {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.relation-preview strong {
  overflow: hidden;
  color: var(--ink);
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.relation-arrow {
  color: var(--blue);
}

.inspector-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 5px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.danger-button {
  border-color: rgba(238, 125, 117, 0.35) !important;
  color: #f09a94 !important;
}

.error-note {
  border: 1px solid rgba(238, 125, 117, 0.35);
  border-radius: 8px;
  padding: 9px 10px;
  color: #f0a09a;
  font-size: 11px;
  line-height: 1.45;
  background: rgba(238, 125, 117, 0.08);
}

dialog {
  width: min(620px, calc(100vw - 40px));
  max-height: min(640px, calc(100vh - 40px));
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  padding: 0;
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.5);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.68);
}

.dialog-header {
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.issue-list {
  display: grid;
  gap: 8px;
  max-height: 470px;
  overflow-y: auto;
  padding: 14px;
}

.issue-item,
.issue-ok {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  background: var(--surface-raised);
}

.issue-item {
  border-color: rgba(238, 125, 117, 0.3);
}

.issue-ok {
  border-color: rgba(88, 199, 138, 0.3);
  color: #8bd8ae;
}

.toast-region {
  position: fixed;
  z-index: 20;
  right: 18px;
  bottom: 18px;
  display: grid;
  gap: 8px;
  width: min(330px, calc(100vw - 36px));
  pointer-events: none;
}

.toast {
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  padding: 11px 13px;
  color: var(--ink);
  font-size: 12px;
  background: #292929;
  box-shadow: 0 14px 35px rgba(0, 0, 0, 0.42);
  animation: toast-in 180ms ease-out;
}

.toast.error {
  border-color: rgba(238, 125, 117, 0.45);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(7px);
  }
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: minmax(470px, 1fr) 270px;
  }

  .canvas-toolbar .save-state,
  .canvas-toolbar .top-actions .button.ghost {
    display: none;
  }
}

@media (max-width: 900px) {
  body {
    overflow: auto;
  }

  .app-shell {
    min-height: 100vh;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: 70vh minmax(430px, auto);
    height: auto;
  }

  .side-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .controls-panel {
    display: block;
  }

  .inspector-panel {
    min-height: 0;
  }

  .canvas-hint {
    display: none;
  }
}
