:root {
  --ink: #17212d;
  --muted: #687481;
  --line: #dfe4e8;
  --line-strong: #c3cbd2;
  --paper: #fbfcfd;
  --panel: #ffffff;
  --x: #d43d06;
  --y: #087d77;
  --z: #6f2cff;
  --good: #087d55;
  --warn: #b45c00;
  --danger: #bd2c36;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(180deg, rgba(226, 232, 237, 0.45), transparent 170px),
    var(--paper);
}

.masthead,
main,
footer {
  width: min(1880px, calc(100% - 48px));
  margin-inline: auto;
}

.masthead {
  min-height: 116px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.eyebrow,
.section-kicker {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 750;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1, h2 { margin: 0; letter-spacing: -0.035em; font-weight: 650; }
h1 { font-size: clamp(1.75rem, 3vw, 2.65rem); }
h2 { font-size: clamp(1.3rem, 2vw, 1.8rem); }

.connection {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 650;
}

.connection-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9ca7b0;
  box-shadow: 0 0 0 4px rgba(156, 167, 176, 0.14);
}
.connection[data-state="live"] { color: var(--good); }
.connection[data-state="live"] .connection-dot { background: #12a36f; box-shadow: 0 0 0 4px rgba(18, 163, 111, 0.14); }
.connection[data-state="error"] { color: var(--danger); }
.connection[data-state="error"] .connection-dot { background: var(--danger); }

.device-bar {
  display: grid;
  grid-template-columns: 0.7fr 1.4fr 1fr 0.8fr auto;
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--line);
}

.device-bar > div {
  min-width: 0;
  padding: 13px 16px;
  background: var(--panel);
  font-size: 0.82rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.device-bar > div:not(.calibration-state) { display: flex; flex-direction: column; gap: 2px; }
.meta-label { color: var(--muted); font-size: 0.66rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.calibration-state { display: grid; place-items: center; color: var(--warn); font-weight: 700; }
.calibration-state.verified { color: var(--good); }

.readouts {
  display: grid;
  grid-template-columns: repeat(8, minmax(115px, 1fr));
  gap: 8px;
  margin-block: 12px 34px;
}

.readout {
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-top: 2px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel);
}
.readout.axis-x { border-top-color: var(--x); }
.readout.axis-y { border-top-color: var(--y); }
.readout.axis-z { border-top-color: var(--z); }
.readout > span { display: block; color: var(--muted); font-size: 0.66rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.readout strong { display: block; overflow: hidden; margin-top: 5px; font: 650 0.9rem/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; text-overflow: ellipsis; white-space: nowrap; }
.readout small { color: #8a949e; font-size: 0.65rem; }

.plot-section { margin-bottom: 54px; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin: 0 0 14px 52px; }
.spectrum-heading { align-items: center; }
.controls { display: flex; flex-wrap: wrap; align-items: end; justify-content: flex-end; gap: 8px; }
.field-label { display: grid; gap: 4px; color: var(--muted); font-size: 0.66rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; }
select, button, .toggle {
  min-height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font: 600 0.76rem/1 inherit;
}
select { padding: 0 30px 0 10px; }
button { padding: 0 12px; cursor: pointer; }
button:hover { border-color: #88939d; background: #f5f7f8; }
.toggle { display: flex; align-items: center; gap: 7px; padding: 0 10px; cursor: pointer; text-transform: none; letter-spacing: 0; }
.toggle input { accent-color: #253442; }

.plot-stack {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}
.plot-row { position: relative; display: grid; grid-template-columns: 48px minmax(0, 1fr); min-height: 205px; border-bottom: 1px solid var(--line); }
.plot-row:last-child { border-bottom: 0; }
.axis-tag { display: grid; place-items: center; border-right: 1px solid var(--line); font: 750 0.82rem/1 ui-monospace, monospace; }
.axis-tag.axis-x { color: var(--x); background: rgba(212, 61, 6, 0.035); }
.axis-tag.axis-y { color: var(--y); background: rgba(8, 125, 119, 0.035); }
.axis-tag.axis-z { color: var(--z); background: rgba(111, 44, 255, 0.035); }
.plot { min-width: 0; min-height: 204px; }
.uplot { font-family: inherit; }
.uplot .u-axis { color: var(--muted); }
.u-legend { display: none !important; }
.spectrum-status { margin: 8px 0 0 52px; color: var(--muted); font-size: 0.72rem; }

footer {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding-block: 22px 36px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.72rem;
}

@media (max-width: 1180px) {
  .readouts { grid-template-columns: repeat(4, 1fr); }
  .device-bar { grid-template-columns: repeat(2, 1fr); }
  .device-bar .calibration-state { grid-column: 1 / -1; }
  .section-heading { align-items: flex-start; flex-direction: column; }
  .controls { justify-content: flex-start; }
}

@media (max-width: 680px) {
  .masthead, main, footer { width: min(100% - 20px, 1880px); }
  .masthead { min-height: 94px; }
  .readouts { grid-template-columns: repeat(2, 1fr); }
  .device-bar { grid-template-columns: 1fr; }
  .device-bar .calibration-state { grid-column: auto; }
  .section-heading { margin-left: 0; }
  .plot-row { grid-template-columns: 32px minmax(0, 1fr); min-height: 178px; }
  .plot { min-height: 177px; }
  .axis-tag { font-size: 0.7rem; }
  .spectrum-status { margin-left: 32px; }
  footer { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; }
}
