:root {
  --ink: #102033;
  --muted: #607286;
  --line: #dbe4ed;
  --soft: #f4f8fc;
  --mist: #eaf4ff;
  --blue: #245d9f;
  --orange: #ff7518;
  --orange-dark: #d95500;
  --dark: #0e1825;
  --dark-panel: #142236;
  --danger: #b42318;
  --warn: #9a5b00;
  --shadow: 0 18px 50px rgba(16, 32, 51, 0.12);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--ink);
  background: #fff;
  font-size: 16px;
  line-height: 1.5;
}

.mode-public .member-only {
  display: none !important;
}

[hidden] {
  display: none !important;
}

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

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
  padding: 1rem clamp(1rem, 4vw, 4rem);
  border-bottom: 1px solid rgba(16, 32, 51, 0.08);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  flex-direction: column;
  color: var(--ink);
  text-decoration: none;
  line-height: 1;
}

.brand-mark {
  display: block;
  line-height: 0;
}

.brand-mark img {
  display: block;
  width: 240px;
  max-width: 48vw;
  height: auto;
}

.brand-sub {
  color: var(--orange-dark);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.top-nav {
  display: flex;
  align-items: center;
  gap: clamp(0.8rem, 2vw, 1.8rem);
  font-size: 0.92rem;
  font-weight: 800;
  text-transform: uppercase;
}

.top-nav a {
  color: var(--ink);
  text-decoration: none;
}

.top-nav a:hover,
.top-nav a:focus {
  color: var(--orange-dark);
}

.hero {
  display: grid;
  grid-template-columns: minmax(470px, 1fr) minmax(450px, 570px);
  gap: clamp(1.25rem, 3vw, 2.5rem);
  align-items: center;
  padding: 1.45rem clamp(1rem, 6vw, 6rem) 1.55rem;
  background: linear-gradient(90deg, rgba(226, 240, 255, 0.95), rgba(255, 255, 255, 0.72));
}

.hero h1,
.section-heading h2,
.safety h2 {
  margin: 0;
  max-width: 920px;
  font-size: clamp(2.15rem, 5vw, 5.1rem);
  line-height: 0.98;
  letter-spacing: 0;
}

.hero h1 {
  font-size: 2.55rem;
  line-height: 1.03;
}

.hero-copy {
  align-self: start;
}

.hero p,
.section-heading p {
  max-width: 780px;
  color: var(--muted);
  font-size: 1.05rem;
}

.eyebrow {
  display: inline-block;
  margin-bottom: 0.65rem;
  color: var(--orange-dark);
  font-size: 0.82rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.hero-actions,
.control-actions,
.output-actions,
.sender-actions,
.sender-toolbar,
.console-input {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.button,
button,
.file-button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--orange);
  border-radius: 8px;
  padding: 0.7rem 1rem;
  background: var(--orange);
  color: #fff;
  cursor: pointer;
  font-weight: 900;
  text-decoration: none;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.button.ghost,
button.ghost,
.file-button {
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.workspace-dark .button.ghost,
.workspace-dark button.ghost,
.workspace-dark .file-button {
  border-color: rgba(255, 255, 255, 0.22);
  background: transparent;
  color: #fff;
}

.button.warn,
button.warn {
  border-color: #e6a300;
  background: #e6a300;
}

.button.danger,
button.danger {
  border-color: var(--danger);
  background: var(--danger);
}

.hero-setup {
  min-width: 0;
  border: 1px solid rgba(36, 93, 159, 0.16);
  border-radius: 10px;
  padding: 0.9rem 1rem 1rem;
  background: rgba(255, 255, 255, 0.84);
}

.setup-heading {
  display: flex;
  gap: 1rem;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 0.72rem;
  padding-bottom: 0.45rem;
  border-bottom: 1px solid rgba(36, 93, 159, 0.18);
}

.setup-heading .eyebrow {
  margin-bottom: 0;
  font-size: 1.07rem;
}

.setup-status {
  display: grid;
  grid-template-columns: 58px 138px;
  column-gap: 1.25rem;
  align-items: baseline;
  justify-content: end;
  margin-left: auto;
  color: var(--ink);
  font-size: 0.96rem;
  font-weight: 400;
  white-space: nowrap;
}

.setup-status strong {
  color: var(--ink);
  font-size: 1.07rem;
  font-weight: 900;
  text-transform: none;
}

.setup-status strong.is-connected {
  color: var(--orange-dark);
}

.setup-grid {
  display: grid;
  min-width: 0;
  grid-template-columns: minmax(210px, 1.45fr) minmax(145px, 0.95fr) 105px;
  gap: 0.65rem;
  align-items: end;
}

.hero-setup label {
  margin: 0;
}

.setup-connection {
  display: grid;
  min-width: 0;
  grid-template-columns: minmax(220px, 1fr) 154px;
  gap: 0.65rem;
  align-items: end;
  margin-top: 0.7rem;
}

.setup-connection label {
  margin-bottom: 0;
}

.setup-connection .button {
  width: 100%;
  min-height: 43px;
  padding: 0.52rem 0.65rem;
  font-size: 0.88rem;
  white-space: nowrap;
}

.setup-connection .button.is-disconnect {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

.workspace,
.safety {
  padding: clamp(3rem, 6vw, 5rem) clamp(1rem, 6vw, 6rem);
}

.workspace-dark {
  background: var(--dark);
  color: #fff;
}

.section-heading {
  margin-bottom: 1.6rem;
}

.section-heading h2 {
  font-size: clamp(2rem, 4vw, 3.5rem);
}

.section-heading.invert p {
  color: #b4c5d8;
}

.sender-heading {
  margin-bottom: 1.25rem;
}

.sender-heading-top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.5rem;
}

.sender-connect-panel {
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  min-width: 170px;
}

.sender-connect-button {
  min-width: 170px;
  white-space: nowrap;
}

.sender-connect-button.is-disconnect {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

.sender-connection-status {
  min-width: 170px;
  color: #6b96c8;
  font-size: 1rem;
  font-weight: 900;
  line-height: 1.15;
  text-align: center;
  text-transform: none;
  white-space: nowrap;
}

.sender-connection-status.is-connected {
  color: var(--orange);
}

.sender-heading-meta {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 0.65rem;
}

.sender-heading-notes {
  display: grid;
  gap: 0.22rem;
}

.sender-motion-warning,
.sender-support-note {
  margin: 0;
  color: #b4c5d8;
  font-size: 0.96rem;
}

.sender-support-note {
  max-width: 34rem;
  text-align: left;
}

.pattern-tiles {
  display: grid;
  grid-template-columns: repeat(7, minmax(88px, 1fr));
  gap: 0.65rem;
  margin: 0 0 1.35rem;
}

.pattern-tile {
  display: flex;
  min-height: 106px;
  flex-direction: column;
  gap: 0.42rem;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.65rem 0.4rem;
  background: #fff;
  color: var(--ink);
  box-shadow: none;
  font-size: 0.88rem;
}

.pattern-tile svg {
  width: 64px;
  height: 46px;
  fill: none;
  stroke: var(--blue);
  stroke-width: 2.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.pattern-tile svg circle {
  fill: var(--blue);
  stroke: none;
}

.pattern-tile:hover,
.pattern-tile:focus-visible {
  border-color: rgba(36, 93, 159, 0.7);
  background: var(--mist);
}

.pattern-tile.is-selected {
  border-color: var(--orange);
  background: #fff7f1;
  color: var(--orange-dark);
}

.pattern-tile.is-selected svg {
  stroke: var(--orange-dark);
}

.pattern-tile.is-selected svg circle {
  fill: var(--orange-dark);
}

.pattern-tile.is-disabled,
.pattern-tile:disabled {
  border-color: #e1e7ee;
  background: #f5f7fa;
  color: #9aa7b4;
  cursor: not-allowed;
  opacity: 1;
}

.pattern-tile.is-disabled svg,
.pattern-tile:disabled svg {
  stroke: #b8c2cc;
}

.pattern-tile.is-disabled svg circle,
.pattern-tile:disabled svg circle {
  fill: #b8c2cc;
}

.pattern-tile.is-disabled:hover,
.pattern-tile.is-disabled:focus-visible,
.pattern-tile:disabled:hover,
.pattern-tile:disabled:focus-visible {
  border-color: #e1e7ee;
  background: #f5f7fa;
  color: #9aa7b4;
}

.app-grid {
  display: grid;
  grid-template-columns: minmax(300px, 350px) minmax(0, 1fr);
  gap: 1.4rem;
  align-items: start;
}

.controls,
.preview-panel,
.sender-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  box-shadow: var(--shadow);
}

.controls {
  min-width: 0;
  padding: 0.85rem 0.9rem;
}

.control-group {
  padding: 0.72rem 0;
  border-bottom: 1px solid var(--line);
}

.control-group:first-child {
  padding-top: 0;
}

.control-group:last-of-type {
  border-bottom: 0;
}

.control-group h3,
.preview-toolbar h3,
.sender-card h3 {
  margin: 0 0 0.62rem;
  font-size: 1.05rem;
}

label {
  display: grid;
  gap: 0.24rem;
  margin-bottom: 0.52rem;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 900;
}

label small {
  color: var(--muted);
  font-weight: 700;
}

.field-caption {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 0.65rem;
  width: 100%;
  line-height: 1.15;
}

.field-caption small {
  padding-right: 0.55rem;
  text-align: right;
  white-space: nowrap;
}

input,
select,
textarea {
  min-width: 0;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.75rem;
  background: #fff;
  color: var(--ink);
}

.controls input,
.controls select {
  box-sizing: border-box;
  height: 35px;
  min-height: 35px;
  border-color: #cad7e9;
  border-radius: 0;
  padding: 0.38rem 0.55rem;
  background: #e6eef9;
}

.controls input[type="number"],
.sender-card input[type="number"] {
  text-align: right;
}

.controls input:focus,
.controls select:focus {
  outline: 2px solid rgba(36, 93, 159, 0.3);
  outline-offset: -1px;
  border-color: var(--blue);
}

textarea {
  min-height: 360px;
  resize: vertical;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 0.82rem;
  line-height: 1.45;
}

.two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.48rem;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 24px;
  margin: 0.42rem 0 0;
  cursor: pointer;
  line-height: 1.2;
}

.check-row input {
  position: relative;
  flex: 0 0 auto;
  width: 34px !important;
  min-width: 34px;
  height: 18px !important;
  min-height: 18px !important;
  inline-size: 34px;
  block-size: 18px;
  margin: 0;
  padding: 0;
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid #b9c8d9;
  border-radius: 999px;
  background: #e9eef5;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease;
}

.check-row input::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(15, 36, 57, 0.18);
  transition: transform 0.16s ease;
}

.check-row input:checked {
  border-color: var(--blue);
  background: var(--blue);
}

.check-row input:checked::before {
  transform: translateX(16px);
}

.check-row input:focus-visible {
  outline: 2px solid rgba(36, 93, 159, 0.35);
  outline-offset: 2px;
}

.preview-panel {
  min-width: 0;
  padding: 1rem;
}

.preview-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
}

.metric-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.45rem;
}

.metric-row span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.35rem 0.6rem;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 900;
}

.canvas-wrap {
  height: min(64vh, 620px);
  min-height: 360px;
  margin: 1rem 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background:
    linear-gradient(#f9fbfd 1px, transparent 1px),
    linear-gradient(90deg, #f9fbfd 1px, transparent 1px),
    #fff;
  background-size: 24px 24px;
  overflow: hidden;
}

#previewSvg {
  display: block;
  width: 100%;
  height: 100%;
}

.output-actions {
  justify-content: flex-end;
  margin-bottom: 0.8rem;
}

.sender-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.sender-card {
  padding: 1rem;
  background: var(--dark-panel);
  border-color: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.sender-card label {
  color: #fff;
}

.sender-card input,
.sender-card select,
.sender-card textarea {
  border-color: rgba(255, 255, 255, 0.18);
  background: #0b1420;
  color: #fff;
}

.saved-programs .saved-note {
  max-width: 42rem;
  margin: 0.3rem 0 0;
  color: #b4c5d8;
  font-size: 0.86rem;
}

.saved-actions,
.saved-library {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.saved-actions input {
  width: min(270px, 100%);
}

.saved-library select {
  flex: 1 1 320px;
}

.sender-wide {
  grid-column: 1 / -1;
}

.sender-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.machine-workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 178px;
  gap: 1rem;
  align-items: start;
}

.machine-map {
  height: 245px;
  min-width: 0;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    #08111c;
  background-size: 22px 22px;
}

#machineMapSvg {
  display: block;
  width: 100%;
  height: 100%;
}

#machineMapFrame {
  fill: rgba(36, 93, 159, 0.08);
  stroke: rgba(180, 197, 216, 0.64);
  stroke-width: 2;
}

#machineMapXAxis,
#machineMapYAxis {
  stroke: rgba(255, 119, 28, 0.78);
  stroke-width: 2.5;
  stroke-linecap: round;
}

#machineMapNozzle {
  fill: var(--orange);
  stroke: #fff;
  stroke-width: 2.5;
  filter: drop-shadow(0 0 8px rgba(255, 117, 24, 0.48));
  opacity: 0;
  transition: cx 120ms ease, cy 120ms ease, opacity 120ms ease;
}

.machine-status-column {
  display: grid;
  gap: 0.72rem;
  align-items: start;
}

.stream-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.5rem;
  margin-top: 1rem;
}

.position-panel {
  min-width: 0;
}

.position-panel-heading {
  display: grid;
  gap: 0.1rem;
  margin-bottom: 0.6rem;
}

.position-panel-heading h3 {
  margin: 0;
  font-size: 1.05rem;
}

.position-panel-heading span {
  color: #b4c5d8;
  font-size: 0.72rem;
  font-weight: 800;
  text-align: left;
}

.position-readouts {
  display: grid;
  gap: 0.42rem;
}

.position-row {
  display: grid;
  grid-template-columns: 34px 112px;
  align-items: center;
  justify-content: start;
  min-height: 38px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  background: #0b1420;
}

.position-row span {
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: stretch;
  background: rgba(36, 93, 159, 0.42);
  color: #d9e8fb;
  font-size: 1rem;
  font-weight: 900;
}

.position-row strong {
  padding: 0 0.55rem;
  color: #fff;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 1.58rem;
  font-weight: 800;
  text-align: right;
}

.machine-actions {
  display: grid;
  gap: 0.5rem;
}

.machine-actions .button {
  width: 100%;
  min-height: 34px;
  padding: 0.48rem 0.56rem;
  font-size: 0.72rem;
}

.stream-metrics span {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 0.45rem 0.55rem;
  color: #b4c5d8;
  font-size: 0.76rem;
}

.stream-metrics strong {
  overflow: hidden;
  color: #fff;
  font-size: 0.86rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.coordinate-note {
  margin: 0.85rem 0 0;
  color: #b4c5d8;
  font-size: 0.82rem;
  line-height: 1.55;
}

.coordinate-note code {
  display: inline-block;
  border-radius: 5px;
  padding: 0.05rem 0.3rem;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.jog-grid {
  display: grid;
  grid-template-columns: repeat(var(--jog-cols, 5), 72px);
  grid-template-rows: repeat(2, 72px);
  gap: 0.5rem;
  margin-bottom: 1rem;
  align-items: stretch;
  justify-content: start;
}

.jog-button {
  aspect-ratio: 1 / 1;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border-radius: 10px;
  font-size: 1.05rem;
  font-weight: 900;
}

.jog-y-plus {
  grid-column: 2;
  grid-row: 1;
}

.jog-x-minus {
  grid-column: 1;
  grid-row: 2;
}

.jog-y-minus {
  grid-column: 2;
  grid-row: 2;
}

.jog-x-plus {
  grid-column: 3;
  grid-row: 2;
}

.jog-z-plus,
.jog-z-minus {
  grid-column: 4;
}

.jog-a-plus,
.jog-a-minus {
  grid-column: 5;
}

.jog-b-plus,
.jog-b-minus {
  grid-column: 6;
}

.jog-c-plus,
.jog-c-minus {
  grid-column: 7;
}

.jog-z-plus,
.jog-a-plus,
.jog-b-plus,
.jog-c-plus {
  grid-row: 1;
}

.jog-z-minus,
.jog-a-minus,
.jog-b-minus,
.jog-c-minus {
  grid-row: 2;
}

.file-button {
  position: relative;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.progress {
  height: 10px;
  margin-bottom: 0.8rem;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
}

.progress span {
  display: block;
  width: 0%;
  height: 100%;
  background: var(--orange);
  transition: width 0.2s ease;
}

.console-log {
  min-height: 260px;
  max-height: 380px;
  margin: 0 0 0.8rem;
  overflow: auto;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 10px;
  padding: 0.8rem;
  background: #050a10;
  color: #c8f0d8;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 0.82rem;
}

.console-input input {
  flex: 1 1 260px;
}

.safety {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 2rem;
  background: #fff7f1;
  border-top: 1px solid #ffd9c2;
}

.safety ul {
  margin: 0;
  padding-left: 1.2rem;
}

.safety li + li {
  margin-top: 0.65rem;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 50;
  max-width: min(420px, calc(100vw - 2rem));
  border-radius: 10px;
  padding: 0.85rem 1rem;
  background: var(--dark);
  color: #fff;
  box-shadow: var(--shadow);
}

@media (max-width: 1120px) {
  .hero {
    grid-template-columns: minmax(0, 1fr);
  }

  .hero-setup {
    width: min(100%, 570px);
  }
}

@media (max-width: 980px) {
  .hero,
  .safety {
    grid-template-columns: 1fr;
  }

  .app-grid,
  .sender-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .site-header {
    position: static;
    align-items: flex-start;
    flex-direction: column;
  }

  .top-nav {
    flex-wrap: wrap;
  }

  .sender-wide {
    grid-column: auto;
  }

  .stream-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .setup-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .pattern-tiles {
    grid-template-columns: repeat(4, minmax(88px, 1fr));
  }

  .machine-workspace-grid {
    grid-template-columns: minmax(0, 1fr) 178px;
  }
}

@media (max-width: 620px) {
  .two-col {
    grid-template-columns: 1fr;
  }

  .sender-heading-top,
  .sender-heading-meta {
    flex-direction: column;
    align-items: stretch;
  }

  .sender-connect-panel,
  .sender-support-note {
    justify-content: flex-start;
    text-align: left;
  }

  .setup-grid,
  .setup-connection,
  .pattern-tiles {
    grid-template-columns: 1fr;
  }

  .hero h1 {
    font-size: 1.9rem;
  }

  .section-heading h2 {
    font-size: 1.8rem;
  }

  .preview-toolbar,
  .sender-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .saved-actions,
  .saved-library {
    flex-direction: column;
    align-items: stretch;
  }

  .saved-actions input {
    width: 100%;
  }

  .machine-workspace-grid {
    grid-template-columns: 1fr;
  }

  .machine-map {
    height: 210px;
  }

  .machine-status-column {
    grid-template-columns: 1fr;
  }
}
