*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: system-ui, sans-serif;
  overflow: hidden;
  height: 100dvh;
}

body.theme-light {
  background-color: #fff;
  color: #1e1e1e;
}

body.theme-dark {
  background-color: #1e1e1e;
  color: #d4d4d4;
}

body.theme-dark .diagram-inner svg {
  filter: invert(1) hue-rotate(180deg);
}

body.theme-dark .diagram-inner svg image,
body.theme-dark .diagram-inner svg iframe,
body.theme-dark .diagram-inner svg use[href^='#image-'] {
  filter: invert(1) hue-rotate(180deg);
}

.diagram-container {
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  cursor: grab;
  position: relative;
  background-repeat: repeat;
  transition: background-image 0.2s;
  touch-action: none;
}

.diagram-container:active {
  cursor: grabbing;
}

.diagram-container.bg-grid {
  background-image:
    linear-gradient(rgba(0, 0, 0, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 0, 0, 0.08) 1px, transparent 1px);
}

.diagram-container.bg-dotted {
  background-image: radial-gradient(circle, rgba(0, 0, 0, 0.15) 1px, transparent 1px);
}

.diagram-container.bg-blank {
  background-image: none;
}

body.theme-dark .diagram-container.bg-grid {
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.08) 1px, transparent 1px);
}

body.theme-dark .diagram-container.bg-dotted {
  background-image: radial-gradient(circle, rgba(255, 255, 255, 0.15) 1px, transparent 1px);
}

body.theme-dark .diagram-container.bg-blank {
  background-image: none;
}

.diagram-inner {
  transform-origin: 0 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.diagram-inner svg {
  flex-shrink: 0;
  margin-top: 50px;
}

.diagram-inner a {
  fill: blue;
  text-decoration: underline;
  cursor: pointer;
}

.logo {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 10;
  display: flex;
  align-items: center;
  opacity: 0.8;
  transition: opacity 0.15s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.logo:hover {
  opacity: 1;
}

.controls {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

body.theme-light .controls {
  background: rgba(250, 250, 250, 0.92);
}

body.theme-dark .controls {
  background: rgba(37, 37, 37, 0.92);
}

.controls .row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  min-width: 220px;
}

.controls button {
  padding: 4px 10px;
  border: 1px solid;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  transition: background 0.15s;
  outline: none;
  line-height: 1;
}

body.theme-light .controls button {
  background: #fff;
  border-color: #d0d0d0;
  color: #1e1e1e;
}

body.theme-dark .controls button {
  background: #333;
  border-color: #555;
  color: #d4d4d4;
}

.controls button:hover {
  filter: brightness(0.92);
}

body.theme-light .controls button.active {
  background: #bbb !important;
  color: #fff !important;
  border-color: #bbb !important;
}

body.theme-dark .controls button.active {
  background: #555 !important;
  color: #fff !important;
  border-color: #555 !important;
}

.controls .segmented {
  display: inline-flex;
  border-radius: 6px;
  overflow: hidden;
}

.controls .segmented button {
  border-radius: 0;
  border-right: none;
  padding: 4px 8px;
}

.controls .segmented button:first-child {
  border-radius: 6px 0 0 6px;
}

.controls .segmented button:last-child {
  border-radius: 0 6px 6px 0;
  border-right: 1px solid;
}

body.theme-light .controls .segmented button {
  border-color: #d0d0d0;
}

body.theme-dark .controls .segmented button {
  border-color: #555;
}

.controls .zoom-label {
  font-size: 11px;
  opacity: 0.6;
  min-width: 40px;
  text-align: right;
}

.zoom-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 90px;
  height: 4px;
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

body.theme-light .zoom-slider {
  background: #d0d0d0;
}

body.theme-dark .zoom-slider {
  background: #555;
}

.zoom-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  cursor: pointer;
  border: none;
}

body.theme-light .zoom-slider::-webkit-slider-thumb {
  background: #666;
}

body.theme-dark .zoom-slider::-webkit-slider-thumb {
  background: #aaa;
}

.zoom-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  cursor: pointer;
  border: none;
}

body.theme-light .zoom-slider::-moz-range-thumb {
  background: #666;
}

body.theme-dark .zoom-slider::-moz-range-thumb {
  background: #aaa;
}