:root {
  --panel: rgba(255, 255, 255, 0.9);
  --panel-line: rgba(45, 58, 66, 0.18);
  --text: #202932;
  --muted: #596673;
  --red: #f03a2f;
  --blue: #087bff;
  --violet: #6554ff;
  --green: #0a9e35;
  --orange: #f05a1a;
  --black: #111820;
  --steel: #d5dde2;
  --safety: #d7a72d;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #eef2ef;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

button,
input {
  font: inherit;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.topbar {
  position: fixed;
  top: 16px;
  left: 16px;
  right: 16px;
  z-index: 5;
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 16px 42px rgba(36, 45, 54, 0.16);
  backdrop-filter: blur(12px);
}

.title-block {
  min-width: 0;
}

.eyebrow {
  display: block;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.15;
  font-weight: 760;
}

.view-tabs {
  display: inline-flex;
  min-width: 260px;
  border: 1px solid rgba(45, 58, 66, 0.2);
  border-radius: 8px;
  padding: 3px;
  background: rgba(246, 248, 247, 0.78);
}

.tab-button {
  min-width: 82px;
  min-height: 36px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.tab-button:hover {
  color: var(--text);
  background: rgba(32, 41, 50, 0.06);
}

.tab-button.is-active {
  color: #121820;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(25, 33, 40, 0.16);
}

.control-strip {
  position: fixed;
  top: 96px;
  right: 16px;
  z-index: 4;
  width: 210px;
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 16px 42px rgba(36, 45, 54, 0.13);
  backdrop-filter: blur(12px);
}

.switch,
.speed-control {
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  color: var(--text);
  font-size: 13px;
  font-weight: 650;
}

.switch input {
  width: 18px;
  height: 18px;
  accent-color: var(--safety);
  cursor: pointer;
}

.speed-control {
  align-items: flex-start;
  flex-direction: column;
  gap: 6px;
}

.speed-control input {
  width: 100%;
  accent-color: var(--safety);
  cursor: pointer;
}

.legend {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 16px;
  z-index: 5;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 10px 12px;
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 16px 42px rgba(36, 45, 54, 0.13);
  backdrop-filter: blur(12px);
}

.legend span {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.key {
  width: 28px;
  height: 4px;
  display: inline-block;
  border-radius: 999px;
  background: currentColor;
}

.key-red {
  color: var(--red);
}

.key-blue {
  color: var(--blue);
}

.key-violet {
  color: var(--violet);
}

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

.key-orange {
  color: var(--orange);
}

.key-black {
  color: var(--black);
}

.key-dashed {
  color: var(--black);
  background: repeating-linear-gradient(
    90deg,
    currentColor 0,
    currentColor 6px,
    transparent 6px,
    transparent 11px
  );
}

#labels {
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.label {
  position: absolute;
  width: max-content;
  min-width: 78px;
  max-width: 168px;
  transform: translate(-50%, -100%);
  padding: 5px 7px;
  border: 1px solid rgba(45, 58, 66, 0.18);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 8px 18px rgba(34, 42, 50, 0.1);
  color: #212a33;
  font-size: 11px;
  font-weight: 750;
  line-height: 1.18;
  text-align: center;
  overflow-wrap: anywhere;
  backdrop-filter: blur(8px);
}

.label.pipe-label {
  min-width: 68px;
  max-width: 140px;
  padding: 4px 6px;
  border-color: rgba(45, 58, 66, 0.12);
  background: rgba(250, 251, 249, 0.78);
  color: #48535f;
  font-size: 10px;
}

.status-pill {
  position: fixed;
  left: 50%;
  bottom: 78px;
  z-index: 4;
  transform: translateX(-50%);
  min-height: 32px;
  max-width: min(360px, calc(100vw - 32px));
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 7px 12px;
  border: 1px solid rgba(45, 58, 66, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  color: #46515d;
  font-size: 12px;
  font-weight: 700;
  box-shadow: 0 12px 28px rgba(36, 45, 54, 0.14);
  backdrop-filter: blur(12px);
}

@media (max-width: 820px) {
  .control-strip {
    top: 96px;
    width: 188px;
  }

  .label.pipe-label {
    display: none !important;
  }
}

@media (max-width: 560px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
  }

  .view-tabs {
    width: 100%;
    min-width: 0;
  }

  .tab-button {
    flex: 1;
    min-width: 0;
  }

  .control-strip {
    top: 140px;
    left: 16px;
    right: 16px;
    width: auto;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: center;
  }

  .speed-control {
    grid-column: 1 / -1;
  }

  .legend {
    justify-content: flex-start;
    max-height: 92px;
    overflow: auto;
  }

  .status-pill {
    bottom: 114px;
  }

  .label {
    min-width: 88px;
    max-width: 132px;
    font-size: 10px;
  }
}

@media (max-width: 520px) {
  .topbar,
  .control-strip,
  .legend {
    left: 10px;
    right: 10px;
  }

  .topbar {
    top: 10px;
    padding: 10px;
  }

  h1 {
    font-size: 17px;
  }

  .control-strip {
    top: 128px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .legend {
    bottom: 10px;
  }
}
