/* Reset, page frame, buttons, icons, tooltips, chips, segmented controls and form fields. */
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  min-width: 320px;
  height: 100%;
}
body {
  font: var(--font-size-base)/1.55 var(--font-ui);
  color: var(--color-text);
  background: var(--color-page);
  -webkit-font-smoothing: antialiased;
}
button,
input,
select,
textarea,
output {
  font: inherit;
  color: inherit;
}
button {
  cursor: pointer;
  border: 0;
  background: none;
  padding: 0;
}
button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}
[hidden] {
  display: none !important;
}
h1,
h2,
h3 {
  margin: 0;
}
textarea {
  resize: vertical;
}
#app {
  height: 100dvh;
  min-height: 480px;
  display: flex;
  flex-direction: column;
}
.skip-link {
  position: absolute;
  z-index: var(--z-skip-link);
  left: 8px;
  top: -60px;
  padding: var(--space-4) var(--space-6);
  border-radius: var(--radius-sm);
  background: var(--color-inverse-surface);
  color: var(--color-inverse-text);
}
.skip-link:focus {
  top: 8px;
}
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}
.mono-count,
.mono {
  font-family: var(--font-mono);
}

/* Buttons */
.primary-button,
.secondary-button,
.small-button,
.danger-button,
.dashed-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  min-height: var(--control-height);
  padding: 0 var(--space-7);
  border-radius: var(--radius-md);
  font-size: var(--font-size-base);
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
}
.primary-button,
.danger-button {
  background: var(--color-accent);
  color: var(--color-on-accent);
  font-weight: 700;
}
.primary-button:hover:not(:disabled),
.danger-button:hover:not(:disabled) {
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--fp-color-ink) 25%, transparent);
}
.primary-button .icon,
.danger-button .icon {
  width: 16px;
  height: 16px;
}
.secondary-button,
.small-button {
  border: 1px solid var(--color-border-strong);
  background: var(--color-surface);
  color: var(--color-text);
}
.small-button {
  min-height: 36px;
  padding: 0 var(--space-6);
  font-size: var(--font-size-sm);
}
.secondary-button:hover:not(:disabled),
.small-button:hover:not(:disabled) {
  background: var(--color-hover);
}
.dashed-button {
  width: 100%;
  border: 1px dashed var(--color-border-dashed);
  color: var(--color-text-2);
}
.dashed-button:hover:not(:disabled) {
  background: var(--color-hover);
  color: var(--color-text);
}
.dashed-button .icon {
  width: 16px;
  height: 16px;
}
.link-button {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 32px;
  color: var(--color-accent-text);
  font-size: var(--font-size-sm);
  font-weight: 500;
}
.link-button:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}
.link-button .icon {
  width: 14px;
  height: 14px;
}
.icon-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: var(--control-height);
  height: var(--control-height);
  border-radius: var(--radius-md);
  color: var(--color-text);
}
.icon-button:hover:not(:disabled) {
  background: var(--color-hover);
}
.icon-button.outlined {
  border: 1px solid var(--color-border);
}
.icon-button.tool {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  color: var(--color-text-2);
}
.icon-button.tool .icon {
  width: 16px;
  height: 16px;
}
.icon-button.bare-pencil:hover:not(:disabled) {
  color: var(--color-accent-text);
}

/* CSS tooltip for icon-only tools; the native title stays for touch and AT. */
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-tooltip);
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  background: var(--color-inverse-surface);
  color: var(--color-inverse-text);
  font: 500 var(--font-size-xs)/1.3 var(--font-ui);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
}
[data-tooltip]:hover::after,
[data-tooltip]:focus-visible::after {
  opacity: 1;
  visibility: visible;
}

/* Chips (node kind filter) */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
}
.chip {
  height: 30px;
  padding: 0 var(--space-6);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-pill);
  font-size: var(--font-size-sm);
  color: var(--color-text);
  white-space: nowrap;
}
.chip:hover {
  background: var(--color-hover);
}
.chip[aria-pressed="true"] {
  border-color: var(--color-selected);
  background: var(--color-selected);
  color: var(--color-on-selected);
}

/* Segmented controls (mode tabs, graph density, pane modes) */
.segmented {
  display: inline-flex;
  gap: var(--space-1);
  padding: 3px;
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
}
.segmented > button {
  height: 34px;
  padding: 0 var(--space-7);
  border-radius: var(--radius-sm);
  color: var(--color-text-2);
  white-space: nowrap;
}
.segmented > button:hover {
  color: var(--color-text);
}
.segmented > button[aria-selected="true"] {
  background: var(--color-surface);
  box-shadow: var(--shadow-thumb);
  color: var(--color-text);
  font-weight: 700;
}
.segmented.floating {
  background: var(--color-floating);
  box-shadow: var(--shadow-floating);
}
.segmented.floating > button {
  height: 32px;
  padding: 0 var(--space-6);
  font-size: var(--font-size-sm);
}
.segmented.floating > button[aria-pressed="true"] {
  background: var(--color-selected);
  color: var(--color-on-selected);
  font-weight: 500;
}

/* Form fields */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-width: 0;
  margin: 0 0 var(--space-6);
}
.field > label {
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
  font-weight: 700;
}
.field small,
.help {
  display: block;
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
  line-height: 1.5;
}
input[type="text"],
input[type="number"],
input[type="search"],
select,
textarea {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: var(--control-height);
  padding: var(--space-4) var(--space-6);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
}
select {
  text-overflow: ellipsis;
}
input::placeholder,
textarea::placeholder {
  color: var(--color-text-muted);
}
.field textarea {
  min-height: 84px;
  line-height: 1.6;
}
.field textarea.long {
  min-height: 170px;
}
.field textarea.raw-editor {
  font: var(--font-size-xs)/1.55 var(--font-mono);
  min-height: 55vh;
}
.field input[type="color"] {
  width: 56px;
  height: 40px;
  padding: var(--space-1);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
}
.field-inline {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-6);
}
.field-check {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin: var(--space-6) 0;
}
.field-check input {
  accent-color: var(--color-accent);
}
.stepper {
  display: flex;
  align-items: stretch;
  height: var(--control-height);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  overflow: hidden;
}
.stepper button {
  width: 40px;
  flex: none;
  font-size: var(--font-size-2xl);
  line-height: 1;
}
.stepper button:hover {
  background: var(--color-hover);
}
.stepper input {
  min-height: 0;
  border: 0;
  border-radius: 0;
  text-align: center;
  font-family: var(--font-mono);
  -moz-appearance: textfield;
  appearance: textfield;
}
.stepper input::-webkit-outer-spin-button,
.stepper input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.stepper:focus-within {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}
.stepper input:focus-visible {
  outline: none;
}
