:root {
  --bg: #eceae4;
  --bg-glow: #f7f4ee;
  --paper: #f7f5f0;
  --card: #fffcf7;
  --ink: #1c1b19;
  --muted: #7a756c;
  --faint: #b3ada3;
  --line: rgba(28, 27, 25, 0.08);
  --chip: #efe4cc;
  --chip-ink: #5c5344;
  --chip-wash: rgba(255, 252, 247, 0.65);
  --select: #1c1b19;
  --select-soft: rgba(28, 27, 25, 0.06);
  --fill: #f3eee4;
  --stroke: #1c1b19;
  --shadow: 0 12px 40px rgba(40, 34, 24, 0.08);
  --r-xl: 32px;
  --r-lg: 24px;
  --r-md: 18px;
  --r-pill: 999px;
  --glass: rgba(255, 252, 247, 0.48);
  --glass-edge: rgba(255, 255, 255, 0.62);
  --glass-inset: rgba(255, 255, 255, 0.72);
  --glass-float-top: rgba(255, 255, 255, 0.55);
  --glass-float-bot: rgba(255, 252, 247, 0.22);
  --veil: rgba(28, 27, 25, 0.28);
  --danger: #8a3b2a;
  --accent: #e56a1a;
  --accent-ink: #2d1408;
  --accent-soft: rgba(229, 106, 26, 0.16);
  --floor: rgba(40, 34, 24, 0.06);
  --theme-status: #eceae4;
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    system-ui, sans-serif;
  color: var(--ink);
  background-color: var(--bg);
}

html[data-theme="dark"] {
  --bg: #161513;
  --bg-glow: #221f1b;
  --paper: #1f1d1a;
  --card: #2a2722;
  --ink: #f4efe6;
  --muted: #a8a194;
  --faint: #6e695f;
  --line: rgba(244, 239, 230, 0.1);
  --chip: #3d3628;
  --chip-ink: #d9ccb0;
  --chip-wash: rgba(244, 239, 230, 0.08);
  --select: #f4efe6;
  --select-soft: rgba(244, 239, 230, 0.08);
  --fill: #3a342a;
  --stroke: #f4efe6;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  --glass: rgba(42, 39, 34, 0.55);
  --glass-edge: rgba(255, 255, 255, 0.12);
  --glass-inset: rgba(255, 255, 255, 0.08);
  --glass-float-top: rgba(255, 255, 255, 0.1);
  --glass-float-bot: rgba(255, 255, 255, 0.02);
  --veil: rgba(0, 0, 0, 0.52);
  --danger: #e08a78;
  --accent: #f4842a;
  --accent-ink: #2a1408;
  --accent-soft: rgba(244, 132, 42, 0.2);
  --floor: rgba(244, 239, 230, 0.06);
  --theme-status: #161513;
  color-scheme: dark;
}

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

html,
body {
  min-height: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html {
  background: var(--bg);
}

body {
  background: transparent;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(820px 380px at 88% -6%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 62%),
    radial-gradient(1200px 600px at 50% -10%, var(--bg-glow), var(--bg));
}

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

button {
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

@media (prefers-reduced-motion: no-preference) {
  button,
  select {
    transition:
      transform 0.14s cubic-bezier(0.22, 1, 0.36, 1),
      background-color 0.18s ease,
      color 0.18s ease,
      box-shadow 0.18s ease,
      border-color 0.18s ease,
      opacity 0.18s ease,
      filter 0.18s ease;
  }

  button:active:not(:disabled),
  button.is-press:not(:disabled),
  select:active,
  select.is-press {
    transform: scale(0.96);
  }

  .calc-key:active:not(:disabled),
  .calc-key.is-press:not(:disabled) {
    transform: scale(0.94);
  }

  .pipe-engage:active:not(:disabled),
  .pipe-engage.is-press:not(:disabled) {
    transform: translate(-50%, -50%) scale(0.94);
  }
}

@media (hover: hover) and (prefers-reduced-motion: no-preference) {
  button:hover:not(:disabled):not(.tab):not(.kind) {
    filter: brightness(1.06);
  }
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.mark {
  width: 16px;
  height: 16px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.app {
  width: min(1100px, 100%);
  margin: 0 auto;
  padding: 18px 16px 28px;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.brand {
  min-width: 0;
}

.brand h1 {
  font-size: clamp(20px, 5.4vw, 28px);
  font-weight: 700;
  letter-spacing: -0.045em;
  line-height: 1.1;
  white-space: nowrap;
}

.brand p {
  color: var(--muted);
  font-size: 15px;
  letter-spacing: -0.02em;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.precision {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.precision select {
  appearance: none;
  border: 0;
  background: var(--select-soft);
  border-radius: var(--r-pill);
  padding: 8px 28px 8px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 14px) 55%,
    calc(100% - 9px) 55%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}

.status-bar {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  letter-spacing: -0.01em;
}

.workspace {
  position: relative;
  background: var(--card);
  border-radius: var(--r-xl);
  height: min(86vw, 620px);
  min-height: 480px;
  overflow: visible;
  box-shadow: 0 1px 0 var(--line);
}

.workspace svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  overflow: hidden;
}

.triangle-fill {
  fill: var(--fill);
  stroke: var(--stroke);
  stroke-width: 2.5;
  stroke-linejoin: round;
}

.leader {
  fill: none;
  stroke: var(--ink);
  stroke-opacity: 0.28;
  stroke-dasharray: 3 4;
  stroke-width: 1.25;
}

.vertex {
  fill: var(--ink);
  stroke: none;
}

.diagram-msg {
  position: absolute;
  top: 12px;
  left: 16px;
  right: 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  pointer-events: none;
  z-index: 1;
}

.controls {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.view:not([hidden]) {
  display: grid;
  gap: 16px;
}

@media (prefers-reduced-motion: no-preference) {
  .view:not([hidden]) {
    animation: view-in 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  }

  .view:not([hidden])[data-enter] {
    will-change: transform;
  }

  .view:not([hidden])[data-enter="fwd"] {
    animation-name: view-fwd;
  }

  .view:not([hidden])[data-enter="back"] {
    animation-name: view-back;
  }

  .brand p.is-swap {
    animation: label-swap 0.22s cubic-bezier(0.22, 1, 0.36, 1);
  }
}

@keyframes view-in {
  from {
    transform: translateY(10px);
  }
}

@keyframes view-fwd {
  from {
    transform: translateX(18px);
  }
}

@keyframes view-back {
  from {
    transform: translateX(-18px);
  }
}

@keyframes label-swap {
  from {
    transform: translateY(5px);
  }
}

.measure {
  position: absolute;
  width: 152px;
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  padding: 7px 7px 8px 10px;
  border-radius: 16px;
  transform: translate(-50%, -50%);
  z-index: 2;
}

.measure .lab {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--muted);
}

.measure-row {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.measure input {
  flex: 1;
  min-width: 0;
  width: 100%;
  border: 0;
  background: transparent;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.03em;
  outline: none;
}

.measure-row .unit {
  flex-shrink: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.conv {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
  font-weight: 500;
  margin: 4px 0 0;
  min-height: 1.35em;
  overflow-wrap: anywhere;
  position: relative;
  z-index: 0;
}

.meas {
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  text-decoration-line: underline;
  text-decoration-style: dotted;
  text-decoration-color: color-mix(in srgb, currentColor 38%, transparent);
  text-underline-offset: 0.16em;
  text-decoration-thickness: 1px;
}

.meas-round {
  font-size: 0.62em;
  margin-left: 1px;
  color: var(--muted);
  font-weight: 700;
}

.meas-metric,
.meas-sep {
  text-decoration: none;
}

.measure.is-shop {
  cursor: pointer;
  touch-action: manipulation;
}

.measure.is-shop input {
  cursor: pointer;
  touch-action: manipulation;
  text-decoration-line: underline;
  text-decoration-style: dotted;
  text-decoration-color: color-mix(in srgb, var(--muted) 75%, transparent);
  text-underline-offset: 3px;
}

input[data-shop-display] {
  cursor: pointer;
  touch-action: manipulation;
  text-decoration-line: underline;
  text-decoration-style: dotted;
  text-decoration-color: color-mix(in srgb, var(--muted) 70%, transparent);
  text-underline-offset: 3px;
}

@media (hover: hover) {
  .meas:hover,
  .measure.is-shop input:hover,
  input[data-shop-display]:hover {
    text-decoration-color: var(--accent);
  }
}

@media (prefers-reduced-motion: no-preference) {
  html[data-len-flip] .meas,
  html[data-len-flip] .measure.is-shop input,
  html[data-len-flip] input[data-shop-display],
  html[data-len-flip] .if-span-mark {
    animation: meas-flip 0.22s ease;
  }
}

@keyframes meas-flip {
  from {
    opacity: 0.35;
  }
  to {
    opacity: 1;
  }
}

.unit-field {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--paper);
  border-radius: 16px;
  padding-right: 12px;
  position: relative;
  z-index: 1;
}

.unit-field input {
  background: transparent !important;
}

.unit-field .unit {
  flex-shrink: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.pipe-lab {
  fill: var(--muted);
  font-size: 11px;
  font-weight: 650;
  pointer-events: none;
}

.pipe-tag {
  width: max-content;
  min-width: 0;
  min-height: 0;
  height: auto;
  padding: 3px 8px;
  pointer-events: none;
  z-index: 2;
  opacity: 0.5;
  border-radius: var(--r-pill);
  box-shadow: none;
}

.pipe-tag .lab {
  font-size: 11px;
  font-weight: 700;
  color: var(--ink);
  margin: 0;
  white-space: nowrap;
  line-height: 1.2;
}

.pipe-space .controls {
  pointer-events: none;
  z-index: 2;
}

#pipe {
  z-index: 1;
}

#pipe,
#pipe path,
#pipe circle,
#pipe line,
#pipe polygon {
  pointer-events: none;
}

#pipe .station,
#pipe .station * {
  pointer-events: auto;
}

.station {
  cursor: pointer;
}

.station-hit {
  fill: transparent;
}

.station.is-picked .station-halo {
  fill: var(--ink);
}

.station.is-picked .station-lab {
  fill: var(--paper);
}

.station.is-if .station-halo {
  stroke: var(--accent);
  stroke-dasharray: 2.5 2;
}

.if-span {
  pointer-events: none;
}

.if-span-mark,
.if-span-mark * {
  pointer-events: auto;
  touch-action: manipulation;
  cursor: pointer;
}

.if-span-mark .if-span-lab {
  text-decoration: underline dotted;
  text-decoration-color: color-mix(in srgb, var(--muted) 80%, transparent);
  text-underline-offset: 2px;
}

.if-span-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.5;
  stroke-dasharray: 4 5;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-opacity: 0.78;
}

.if-span-pill {
  fill: var(--paper);
  stroke: var(--accent);
  stroke-width: 1.1;
}

.if-span-lab {
  font-size: 11px;
  font-weight: 700;
  fill: var(--ink);
  text-anchor: middle;
  letter-spacing: -0.03em;
}

.pipe-space.is-picking {
  cursor: pointer;
}

.pipe-space.is-picking #pipe {
  z-index: 3;
}

.pipe-space.is-picking #pipe-chips {
  z-index: 0;
}

.pipe-space.is-picking .pipe-tag {
  opacity: 0.28;
  filter: saturate(0.7);
  z-index: 0;
}

.pipe-space.is-picking .leader {
  stroke-opacity: 0.12;
}

.pipe-chrome {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 7;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  pointer-events: none;
}

.pipe-chrome[hidden] {
  display: none;
}

.pipe-tools {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  pointer-events: auto;
}

.pipe-tools > [hidden] {
  display: none;
}

.pipe-dist-btn,
.pipe-frame-btn,
.pipe-done {
  position: static;
  z-index: auto;
  pointer-events: auto;
  touch-action: manipulation;
}

.pipe-chrome .icon-btn {
  width: 40px;
  height: 40px;
  background: color-mix(in srgb, var(--card) 42%, transparent);
  border: 1px solid var(--glass-edge);
  box-shadow: inset 0 1px 0 var(--glass-inset);
}

.pipe-chrome .mark {
  position: relative;
  inset: auto;
  width: 15px;
  height: 15px;
  overflow: visible;
}

@media (prefers-reduced-motion: no-preference) {
  .pipe-chrome:not([hidden]) .icon-btn:not([hidden]) {
    animation: pop-in 0.24s cubic-bezier(0.22, 1, 0.36, 1);
  }

  .pipe-engage:not([hidden]) {
    animation: engage-in 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  }
}

.pipe-dist-btn[aria-pressed="true"] {
  background: color-mix(in srgb, var(--accent) 72%, transparent);
  color: var(--accent-ink);
  border-color: transparent;
}

.measure.is-calc input {
  pointer-events: none;
  color: var(--muted);
  font-weight: 500;
}

.measure.is-user {
  box-shadow: var(--shadow);
}

.measure.is-calc {
  border: 1.5px solid var(--line);
}

.measure.is-on {
  outline: 2px solid var(--ink);
}

.glass {
  background: var(--glass);
  -webkit-backdrop-filter: blur(18px) saturate(1.5);
  backdrop-filter: blur(18px) saturate(1.5);
  border: 1px solid var(--glass-edge);
  box-shadow:
    var(--shadow),
    inset 0 1px 0 var(--glass-inset);
  color: var(--ink);
}

.plus {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 10px;
  border: 0;
  font-size: 18px;
  line-height: 1;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  -webkit-appearance: none;
  appearance: none;
}

.plus:disabled {
  opacity: 0.28;
}

.plus:not(:disabled) {
  background: var(--accent);
  color: var(--accent-ink);
}

.ssa {
  display: none;
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  align-items: center;
  gap: 10px;
  padding: 8px 10px 8px 14px;
  border-radius: var(--r-pill);
  font-size: 13px;
  font-weight: 600;
}

.ssa.is-open {
  display: flex;
}

@media (prefers-reduced-motion: no-preference) {
  .ssa.is-open {
    animation: ssa-in 0.24s cubic-bezier(0.22, 1, 0.36, 1);
  }
}

.ssa-btns {
  display: flex;
  gap: 4px;
}

.ssa-btns button {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  font-weight: 700;
  display: grid;
  place-items: center;
  -webkit-appearance: none;
  appearance: none;
}

.ssa-btns button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
}

.dock {
  display: flex;
  gap: 8px;
  margin: 14px 0 22px;
  position: sticky;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 5;
}

.float,
.compact {
  border: 0;
  border-radius: var(--r-pill);
  font-weight: 650;
  letter-spacing: -0.03em;
}

.float.glass,
.plus.glass,
.compact.glass {
  background: linear-gradient(180deg, var(--glass-float-top), var(--glass-float-bot)),
    var(--glass);
}

.plus.glass:not(:disabled) {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}

.float {
  flex: 1;
  padding: 14px 16px;
  font-size: 16px;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.compact {
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 700;
}

.tabs,
.kind-toggle {
  position: relative;
}

.seg-pill {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 0;
  border-radius: var(--r-pill);
  background: var(--card);
  box-shadow: 0 1px 0 var(--line), inset 0 -2px 0 var(--accent);
  pointer-events: none;
}

.kind-toggle > .seg-pill {
  background: var(--paper);
}

@media (prefers-reduced-motion: no-preference) {
  .seg-pill {
    transition:
      transform 0.38s cubic-bezier(0.22, 1, 0.36, 1),
      width 0.38s cubic-bezier(0.22, 1, 0.36, 1),
      height 0.38s cubic-bezier(0.22, 1, 0.36, 1);
  }
}

.tabs {
  display: flex;
  gap: 0;
  margin: 16px 0;
  padding: 4px;
  background: var(--select-soft);
  border-radius: var(--r-pill);
}

.tab {
  position: relative;
  z-index: 1;
  flex: 1;
  border: 0;
  background: transparent;
  min-height: 40px;
  border-radius: var(--r-pill);
  font-size: 12px;
  font-weight: 650;
  color: var(--muted);
  padding: 0 4px;
}

.tab[aria-selected="true"] {
  color: var(--ink);
}

.view[hidden] {
  display: none !important;
}

.kind-toggle {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
  padding: 4px;
  background: var(--select-soft);
  border-radius: var(--r-pill);
}

.kind {
  position: relative;
  z-index: 1;
  flex: 1;
  border: 0;
  background: transparent;
  min-height: 38px;
  border-radius: var(--r-pill);
  font-size: 14px;
  font-weight: 650;
  color: var(--muted);
}

.kind[aria-pressed="true"] {
  color: var(--ink);
}

.calc-shell {
  display: grid;
  gap: 12px;
}

.calc-display {
  background: var(--paper);
  border-radius: 22px;
  padding: 14px 16px 12px;
  display: grid;
  gap: 4px;
  min-width: 0;
  overflow: hidden;
}

.calc-expr {
  min-height: 1.2em;
  font-size: 13px;
  font-weight: 650;
  color: var(--muted);
  text-align: right;
}

.calc-readout {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  overflow: hidden;
}

.calc-readout input {
  flex: 1;
  border: 0;
  background: transparent;
  min-width: 0;
  width: 100%;
  padding: 0;
  font-size: clamp(22px, 6vw, 34px);
  font-weight: 700;
  letter-spacing: -0.05em;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  overflow: hidden;
}

.calc-readout .unit {
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
  flex-shrink: 0;
}

.unit-reel-view {
  display: block;
  overflow: hidden;
  height: 1.15em;
  min-width: 1.25em;
}

.unit-reel-track {
  display: block;
}

.unit-reel-item {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  height: 1.15em;
  line-height: 1;
}

@media (prefers-reduced-motion: no-preference) {
  .unit-reel-track {
    transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
  }
}

.calc-display .conv {
  text-align: right;
}

.calc-pad {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(6, minmax(52px, auto));
  gap: 8px;
}

.calc-key {
  border: 0;
  min-height: 52px;
  height: 100%;
  width: 100%;
  padding: 0;
  border-radius: clamp(12px, 3.2vw, 18px);
  background: var(--paper);
  color: var(--ink);
  font-size: clamp(16px, 4.8vw, 22px);
  font-weight: 650;
  letter-spacing: -0.03em;
  display: grid;
  place-items: center;
  -webkit-appearance: none;
  appearance: none;
}

.calc-key.fn {
  background: var(--select-soft);
}

.calc-key.op {
  background: var(--chip);
}

.calc-key.eq {
  background: var(--accent);
  color: var(--accent-ink);
}

.calc-key.wide {
  grid-column: span 2;
}

.dist-face {
  margin: 16px 0 0;
}

.station-lab {
  font-size: 11px;
  font-weight: 700;
  fill: var(--ink);
  text-anchor: middle;
  pointer-events: none;
}

.station-halo {
  fill: var(--card);
  stroke: var(--stroke);
  stroke-width: 1.2;
}

.dist-pick {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-items: end;
}

.dist-pick label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 650;
  color: var(--muted);
}

.dist-pick select {
  appearance: none;
  -webkit-appearance: none;
  border: 0;
  background-color: var(--paper);
  border-radius: 16px;
  padding: 16px 40px 16px 16px;
  min-height: 52px;
  font-size: 16px;
  font-weight: 650;
  color: var(--ink);
  width: 100%;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    right 21px center,
    right 16px center;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}

.dist-geom-dock {
  margin: 12px 0 4px;
  flex-wrap: nowrap;
}

.dist-geom-dock .float {
  flex: 1 1 0;
  min-width: 0;
  justify-content: center;
  white-space: nowrap;
}

.dist-list {
  list-style: none;
  display: grid;
  gap: 0;
}

.dist-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: baseline;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.dist-row[data-dist-to] {
  cursor: pointer;
}

.dist-row button {
  border: 0;
  background: none;
  text-align: left;
  padding: 0;
  color: inherit;
  font: inherit;
}

.dist-id {
  font-weight: 700;
  letter-spacing: -0.03em;
}

.dist-hint {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.dist-len {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}

.field {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 650;
  color: var(--muted);
}

.field input,
.field select,
.cage-fields input {
  border: 0;
  background: var(--paper);
  border-radius: 16px;
  padding: 14px;
  font-size: 16px;
  color: var(--ink);
  width: 100%;
}

.field select {
  appearance: none;
  -webkit-appearance: none;
  min-height: 52px;
  padding-right: 40px;
  font-weight: 650;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    right 18px center,
    right 13px center;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}

.weld-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.kind-toggle.weld-process .kind {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  min-height: 46px;
  padding: 6px 4px;
  line-height: 1.1;
}

.kind-toggle.weld-process .kind small {
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.06em;
  opacity: 0.7;
}

.weld-ab-row {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) minmax(92px, 120px);
  gap: 8px;
  align-items: end;
  margin-top: 12px;
}

.weld-ab {
  display: grid;
  place-items: center;
  align-self: end;
  width: 32px;
  height: 32px;
  margin-bottom: 10px;
  border-radius: 50%;
  background: var(--paper);
  font-size: 13px;
  font-weight: 800;
  color: var(--ink);
}

.weld-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0 0;
}

.weld-chip {
  min-width: 44px;
  height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: 999px;
  background: var(--paper);
  font-size: 12px;
  font-weight: 650;
  color: var(--ink);
}

.weld-chip[aria-pressed="true"] {
  background: var(--card);
  box-shadow: inset 0 0 0 1.5px var(--accent);
  color: var(--accent);
}

.weld-match {
  margin: 12px 0 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font-size: 14px;
  font-weight: 750;
}

.weld-hint,
.weld-note {
  margin: 10px 0 0;
  font-size: 12px;
  font-weight: 650;
  color: var(--muted);
  line-height: 1.45;
}

.weld-joints {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 12px;
}

.weld-joint {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 4px 10px;
  border: 0;
  background: var(--paper);
  border-radius: 16px;
  text-align: center;
  color: var(--ink);
}

.weld-joint strong {
  font-size: 11px;
  letter-spacing: -0.03em;
}

.weld-joint .weld-svg {
  width: 100%;
  height: 40px;
}

.weld-joint[aria-pressed="true"] {
  background: color-mix(in srgb, var(--accent) 12%, var(--card));
  box-shadow: inset 0 0 0 2px var(--accent);
}

.workspace.weld-space {
  display: flex;
  flex-direction: column;
  height: min(78vw, 340px);
  min-height: 240px;
  overflow: hidden;
  padding: 14px 14px 8px;
  background-image: radial-gradient(color-mix(in srgb, var(--ink) 12%, transparent) 1px, transparent 1px);
  background-size: 14px 14px;
}

.weld-art-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
  position: relative;
  z-index: 1;
  padding-bottom: 4px;
}

.weld-art-head strong {
  font-size: 16px;
  letter-spacing: -0.03em;
}

.weld-badge {
  flex: 0 0 auto;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--paper);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.workspace.weld-space #weld-art {
  position: relative;
  inset: auto;
  flex: 1;
  min-height: 0;
}

.workspace.weld-space svg,
.weld-joint svg {
  position: relative;
  inset: auto;
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}

.workspace.weld-space svg text {
  font-family: inherit;
}

.weld-plate {
  fill: var(--fill);
  stroke: var(--stroke);
  stroke-width: 1.7;
  stroke-linejoin: round;
}

.weld-soft {
  fill: var(--paper);
  stroke: var(--stroke);
  stroke-width: 1.4;
}

.weld-bead {
  fill: color-mix(in srgb, var(--accent) 82%, var(--card));
  stroke: var(--accent);
  stroke-width: 1.2;
  stroke-linejoin: round;
}

.weld-mark {
  fill: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

.weld-callout {
  fill: var(--muted);
  font-size: 11px;
  font-weight: 650;
}

.weld-cap {
  fill: var(--muted);
  font-size: 10px;
  font-weight: 650;
}

.weld-guide {
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.2;
}

.weld-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.weld-stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  padding: 12px 14px;
  background: var(--paper);
  border-radius: 16px;
}

.weld-stat span {
  font-size: 12px;
  font-weight: 650;
  color: var(--muted);
}

.weld-stat strong {
  font-size: 16px;
  font-weight: 750;
  letter-spacing: -0.03em;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.pipe-space {
  touch-action: pan-y;
  cursor: default;
  overflow: hidden;
  overscroll-behavior: auto;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.pipe-space.is-live {
  touch-action: none;
  cursor: grab;
  overscroll-behavior: none;
}

.pipe-space svg,
.pipe-space .controls {
  touch-action: pan-y;
}

.pipe-space.is-live svg,
.pipe-space.is-live .controls {
  touch-action: none;
}

.pipe-space > button {
  touch-action: manipulation;
  -webkit-user-select: auto;
  user-select: auto;
}

.pipe-engage {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 6;
  transform: translate(-50%, -50%);
  width: 64px;
  height: 64px;
  min-height: 64px;
  padding: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
}

.pipe-engage[hidden] {
  display: none;
}

.pipe-engage svg {
  position: relative;
  inset: auto;
  width: 40px;
  height: 40px;
  display: block;
  overflow: visible;
}

.pipe-space.is-drag {
  cursor: grabbing;
}

.floor-fill {
  fill: var(--floor);
  stroke: none;
}

.floor-grid {
  fill: none;
  stroke: var(--ink);
  stroke-opacity: 0.18;
  stroke-width: 1;
}

.floor-edge {
  fill: none;
  stroke: var(--ink);
  stroke-opacity: 0.3;
  stroke-width: 1.4;
}

.tube {
  fill: none;
  stroke: var(--stroke);
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tube-soft {
  fill: none;
  stroke: var(--fill);
  stroke-linecap: round;
  stroke-linejoin: round;
}

.pipe-dot {
  fill: var(--ink);
}

.pipe-dot.end {
  fill: var(--card);
  stroke: var(--stroke);
  stroke-width: 1.5;
}

.pipe-dot.weld {
  fill: var(--ink);
}

.cage-list {
  list-style: none;
  display: grid;
  gap: 8px;
  overflow: visible;
}

.cage-card {
  background: var(--paper);
  border-radius: 14px;
  padding: 8px 8px 8px 10px;
  display: grid;
  gap: 4px;
  cursor: default;
  user-select: none;
  -webkit-user-select: none;
  transform-origin: center center;
}

.cage-card.is-swapping {
  position: relative;
  z-index: 3;
  box-shadow:
    0 10px 24px color-mix(in srgb, var(--ink) 16%, transparent),
    0 0 0 1.5px color-mix(in srgb, var(--accent) 42%, transparent);
}

.cage-card input {
  cursor: text;
  user-select: text;
  -webkit-user-select: text;
  touch-action: manipulation;
}

.cage-card .icon-btn {
  width: 28px;
  height: 28px;
  font-size: 18px;
}

.cage-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.cage-fields.single {
  grid-template-columns: 1fr;
}

.cage-fields .cage-span {
  grid-column: 1 / -1;
}

.cage-fields label {
  display: grid;
  gap: 2px;
  font-size: 11px;
  font-weight: 650;
  color: var(--muted);
}

.field-lab {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.if-btn {
  width: auto;
  height: auto;
  min-height: 22px;
  padding: 2px 8px;
  font-size: 11px;
  letter-spacing: -0.02em;
}

.if-btn[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}

.if-panel {
  display: grid;
  gap: 8px;
  margin-top: 4px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.if-pick {
  gap: 8px;
}

.if-pick select {
  min-height: 44px;
  padding: 10px 36px 10px 12px;
  border-radius: 12px;
  font-size: 15px;
}

.if-path {
  margin: 0;
}

.if-path .kind {
  min-height: 32px;
  font-size: 12px;
}

.unit-field:has(input[readonly]) {
  opacity: 0.78;
}

.cage-fields .unit-field {
  background: var(--card);
  border-radius: 12px;
  padding-right: 10px;
}

.cage-fields input {
  padding: 8px 10px;
}

.cage-card .conv {
  margin: 0;
  min-height: 0;
  font-size: 10px;
  line-height: 1.3;
}

.cage-dock {
  margin: 8px 0 0;
  position: static;
  flex-wrap: wrap;
  gap: 6px;
}

.cage-dock .float {
  padding: 10px 12px;
  min-height: 44px;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.cage-dock .mark {
  width: 15px;
  height: 15px;
}

.panels {
  display: grid;
  gap: 14px;
}

.panel {
  background: var(--card);
  border-radius: var(--r-xl);
  padding: 16px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.panel-head-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.cage-move {
  display: flex;
  align-items: center;
}

.cage-move .icon-btn:disabled {
  opacity: 0.28;
}

.cage-card header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  min-height: 28px;
}

.cage-card h3 {
  font-size: 13px;
  letter-spacing: -0.03em;
  flex: 1;
  min-width: 0;
}

.panel h2 {
  font-size: 18px;
  letter-spacing: -0.03em;
}

.text-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.empty {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.bank {
  list-style: none;
  display: grid;
  gap: 8px;
}

.meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.saved {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 12px;
  background: var(--paper);
  border-radius: 18px;
  padding: 12px 12px 12px 14px;
}

.saved-info {
  min-width: 0;
  flex: 1;
}

.saved-info h3 {
  font-size: 15px;
  letter-spacing: -0.03em;
}

.saved-info strong {
  display: block;
  margin-top: 4px;
  font-size: 20px;
  letter-spacing: -0.04em;
}

.saved-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  margin-left: auto;
}

.icon-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--select-soft);
  font-size: 20px;
  line-height: 1;
  display: grid;
  place-items: center;
  place-content: center;
  -webkit-appearance: none;
  appearance: none;
}

.icon-btn > * {
  display: block;
  margin: 0;
}

.theme-toggle svg {
  width: 16px;
  height: 16px;
  overflow: visible;
}

.theme-toggle .theme-sun {
  display: none;
}

html[data-theme="dark"] .theme-toggle .theme-sun {
  display: block;
}

html[data-theme="dark"] .theme-toggle .theme-moon {
  display: none;
}

.calc-list {
  list-style: none;
  display: grid;
  gap: 0;
}

.tape-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 36px;
  gap: 8px;
  align-items: center;
  min-height: 56px;
  border-bottom: 1px solid var(--line);
  padding: 8px 0;
  cursor: pointer;
}

.tape-row.is-dragging {
  cursor: grabbing;
  opacity: 0.78;
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.tape-expr {
  font-size: 13px;
  font-weight: 650;
  color: var(--muted);
}

.op-btn,
.icon-btn {
  touch-action: manipulation;
  cursor: pointer;
}

.tape-copy {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.tape-name {
  font-size: 15px;
}

.tape-val {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}

.op-slot {
  width: 36px;
  height: 36px;
}

.op-btn {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 12px;
  background: var(--chip);
  font-size: 18px;
  font-weight: 700;
}

.total {
  margin-top: 8px;
  background: var(--chip);
  border-radius: 20px;
  padding: 14px;
}

.equation {
  color: var(--chip-ink);
  font-size: 14px;
  margin-bottom: 8px;
}

.total-main {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 15px;
}

.total-main strong {
  font-size: 28px;
  letter-spacing: -0.05em;
  color: var(--ink);
  white-space: nowrap;
  flex-shrink: 0;
  margin-left: 12px;
}

.dist-kind {
  margin: 14px 0 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--chip-ink);
}

.total-main + .total-main {
  margin-top: 6px;
}

.total > .equation + .dist-kind {
  margin-top: 0;
}

.alts + .total-main {
  margin-top: 8px;
}

.alts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.alts span {
  background: var(--chip-wash);
  border-radius: var(--r-pill);
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 650;
  color: var(--ink);
}

.work {
  display: grid;
  gap: 4px;
}

.work + .work {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.work-kicker {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: -0.01em;
}

#dist-work .equation {
  margin-bottom: 12px;
}

.work-line {
  font-size: 13px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  line-height: 1.45;
}

.work-pieces {
  margin-top: 8px;
  display: grid;
  gap: 2px;
}

.work-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  align-items: baseline;
  font-size: 13px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.work-note {
  color: var(--chip-ink);
  min-width: 0;
  overflow-wrap: anywhere;
}

.work-sum {
  margin-top: 4px;
  padding-top: 6px;
  border-top: 1px solid var(--line);
  font-weight: 700;
}

.result {
  margin-top: 12px;
}

.result .block {
  background: var(--chip);
  color: var(--chip-ink);
  border-radius: 20px;
  padding: 14px;
}

.result .block h3 {
  color: var(--ink);
  font-size: 22px;
  letter-spacing: -0.04em;
}

.result .grid {
  display: grid;
  gap: 6px;
  margin-top: 10px;
  color: var(--ink);
  font-size: 14px;
}

.result .err {
  color: var(--danger);
  font-size: 14px;
}

.sheet {
  width: min(380px, calc(100vw - 32px));
  border: 0;
  border-radius: 28px;
  padding: 22px 18px 18px;
  background: var(--card);
  position: fixed !important;
  top: 50% !important;
  left: 50% !important;
  right: auto !important;
  bottom: auto !important;
  margin: 0 !important;
  transform: translate(-50%, -50%);
  max-height: calc(100dvh - 48px);
}

.sheet::backdrop {
  background: var(--veil);
}

@media (prefers-reduced-motion: no-preference) {
  .sheet[open] {
    animation: sheet-in 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  }

  .sheet.is-closing {
    animation: sheet-out 0.18s ease forwards;
  }

  .sheet[open]::backdrop {
    animation: veil-in 0.22s ease;
  }

  .sheet.is-closing::backdrop {
    animation: veil-out 0.18s ease forwards;
  }
}

.sheet h2 {
  font-size: 22px;
  letter-spacing: -0.04em;
}

.save-meta {
  color: var(--muted);
  margin: 6px 0 14px;
  font-size: 14px;
}

.sheet label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 650;
  color: var(--muted);
}

.sheet input {
  border: 0;
  background: var(--paper);
  border-radius: 16px;
  padding: 14px;
  font-size: 16px;
  color: var(--ink);
}

.sheet-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.ghost,
.solid {
  flex: 1;
  border: 0;
  border-radius: var(--r-pill);
  padding: 14px;
  font-size: 16px;
  font-weight: 650;
}

.ghost {
  background: var(--select-soft);
}

.solid {
  background: var(--accent);
  color: var(--accent-ink);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(12px);
  background: var(--ink);
  color: var(--paper);
  padding: 10px 14px;
  border-radius: var(--r-pill);
  font-size: 13px;
  font-weight: 650;
  opacity: 0;
  pointer-events: none;
  z-index: 20;
}

@media (prefers-reduced-motion: no-preference) {
  .toast {
    transition: opacity 0.2s ease, transform 0.2s ease;
  }
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 420px) {
  .precision span {
    display: none;
  }

  .tab {
    font-size: 11px;
  }
}

@media (min-width: 860px) {
  .app {
    padding: 28px 24px 40px;
  }

  .workspace {
    height: 620px;
    min-height: 620px;
  }

  .workspace.weld-space {
    height: 340px;
    min-height: 340px;
  }

  .panels {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }

  .dock {
    position: static;
  }
}

@keyframes pop-in {
  from {
    transform: scale(0.86);
  }
}

@keyframes engage-in {
  from {
    transform: translate(-50%, -50%) scale(0.86);
  }
  to {
    transform: translate(-50%, -50%) scale(1);
  }
}

@keyframes ssa-in {
  from {
    transform: translateX(-50%) translateY(8px) scale(0.96);
  }
  to {
    transform: translateX(-50%);
  }
}

@keyframes sheet-in {
  from {
    transform: translate(-50%, calc(-50% + 14px)) scale(0.96);
  }
  to {
    transform: translate(-50%, -50%);
  }
}

@keyframes sheet-out {
  from {
    transform: translate(-50%, -50%);
  }
  to {
    transform: translate(-50%, calc(-50% + 10px)) scale(0.97);
  }
}

@keyframes veil-in {
  from {
    opacity: 0;
  }
}

@keyframes veil-out {
  to {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .result .block {
    animation: view-in 0.22s cubic-bezier(0.22, 1, 0.36, 1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .toast,
  .toast.show,
  .workspace svg,
  button,
  select,
  .view:not([hidden]),
  .sheet[open],
  .sheet.is-closing,
  .sheet[open]::backdrop,
  .sheet.is-closing::backdrop,
  .ssa.is-open,
  .pipe-chrome .icon-btn,
  .pipe-engage,
  .result .block,
  .brand p,
  .seg-pill,
  .unit-reel-track,
  .cage-card {
    transition: none;
    animation: none;
  }
}
