:root {
  --bg: #07080d;
  --card: #12151c;
  --card-2: #171b24;
  --line: #2a3140;
  --text: #f2f4f8;
  --muted: #8b93a7;
  --soft: #c5ccda;
  --x: #ff5a7a;
  --y: #3ee0a0;
  --z: #5aa9ff;
  --min: #8eb7ff;
  --max: #ffc56d;
  --sans: "Segoe UI", "Avenir Next", system-ui, sans-serif;
  --mono: "Cascadia Mono", "SF Mono", ui-monospace, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(900px 420px at 0% -10%, rgba(90, 169, 255, 0.08), transparent 55%),
    radial-gradient(700px 380px at 100% 0%, rgba(255, 90, 122, 0.06), transparent 50%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
}

body {
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
}

button, summary { touch-action: manipulation; }

button {
  font: inherit;
  color: var(--text);
  background: #1c212c;
  border: 1px solid #343b4a;
  border-radius: 999px;
  min-height: 44px;
  padding: 10px 14px;
  cursor: pointer;
}

button.primary {
  background: #f2f4f8;
  color: #12141a;
  border-color: #f2f4f8;
  font-weight: 650;
}

a.chrome-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 52px;
  padding: 12px 16px;
  border-radius: 999px;
  background: #e10600;
  color: #fff;
  font-weight: 750;
  text-decoration: none;
}

a.chrome-link[hidden] { display: none; }

button[aria-pressed="true"] {
  background: #243044;
  border-color: #7eb6ff;
  color: #f4f7fb;
}

button.primary[aria-pressed="true"] {
  background: #d7efe4;
  border-color: #3ee0a0;
  color: #10241c;
}

button:disabled { opacity: 0.45; cursor: default; }

button:focus-visible,
summary:focus-visible {
  outline: 2px solid #d7deea;
  outline-offset: 2px;
}

.wrap {
  width: min(1120px, calc(100% - 28px));
  margin: 0 auto;
  padding: 22px 0 36px;
  display: grid;
  gap: 14px;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.mark { width: 44px; height: 44px; flex: none; }

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1, h2, p { margin: 0; }

h1 {
  font-size: 1.7rem;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.top-meta {
  display: flex;
  gap: 8px;
  align-items: stretch;
  flex-wrap: wrap;
}

.pill, .stat {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 12px;
  border-radius: 14px;
  background: #12151c;
  border: 1px solid var(--line);
}

.pill::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #8b93a7;
}

.pill.live::before {
  background: #3ee0a0;
  box-shadow: 0 0 8px #3ee0a0;
  animation: pulse 1.4s ease-in-out infinite;
}

.pill.sim::before { background: var(--max); }
.pill.paused::before { background: #d7deea; }
.pill.absent::before { background: var(--x); }

.stat {
  flex-direction: column;
  align-items: flex-start;
  gap: 0;
  min-width: 92px;
}

.stat span {
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.stat strong, .value, .peaks strong, .plot-readout {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.view-note, .banner, .orient, .fine, .persist-note, .desc, .dir, .panel-head p {
  color: var(--soft);
}

.banner {
  background: #161b26;
  border: 1px solid #343b4a;
  border-radius: 14px;
  padding: 12px 14px;
}

.banner[hidden] { display: none; }

.axes {
  display: grid;
  gap: 12px;
}

.card, .panel, .help {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.025), transparent 42%), var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
}

.card {
  padding: 16px;
  border-top: 2px solid var(--axis, var(--line));
}

.card[data-axis="x"] { --axis: var(--x); }
.card[data-axis="y"] { --axis: var(--y); }
.card[data-axis="z"] { --axis: var(--z); }

.card.is-flash { animation: flash 0.7s ease; }

.card-head, .panel-head, .readout, .peaks, .meter-scale {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.card-head { align-items: flex-start; }

.kicker {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--axis);
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin: 0 0 2px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--axis, currentColor);
  flex: none;
}

.legend .dot.x { background: var(--x); }
.legend .dot.y { background: var(--y); }
.legend .dot.z { background: var(--z); }

h2 {
  font-size: 1.25rem;
  letter-spacing: -0.03em;
}

.desc { margin-top: 6px; font-size: 0.92rem; }

.flash-tag {
  display: none;
  margin: 0;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--max);
  color: #1a1408;
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.flash-tag.is-on { display: inline-flex; }

.readout { align-items: flex-end; margin-top: 14px; }

.value {
  font-size: clamp(2.1rem, 5vw, 2.75rem);
  font-weight: 700;
  letter-spacing: -0.05em;
  line-height: 0.95;
}

.readout-side { text-align: right; }

.unit, .sub, .lbl, time, em {
  display: block;
  font-style: normal;
}

.unit {
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sub { color: var(--soft); font-family: var(--mono); }

.dir { min-height: 1.45em; margin-top: 6px; font-size: 0.92rem; }

.meter { margin-top: 12px; }

.meter-track {
  position: relative;
  height: 16px;
  border-radius: 999px;
  background: #0b0d12;
  border: 1px solid #242a36;
  overflow: hidden;
}

.meter-tick, .meter-peak, .meter-fill, .meter-thumb {
  position: absolute;
  top: 0;
}

.meter-tick {
  width: 1px;
  height: 100%;
  background: #3a4254;
}

.meter-tick.zero { background: #8b93a7; }

.meter-fill {
  height: 100%;
  background: var(--axis);
  opacity: 0.85;
}

.meter-peak {
  display: none;
  width: 2px;
  height: 100%;
  transform: translateX(-50%);
}

.meter-peak.is-on { display: block; }
.meter-peak.min { background: var(--min); }
.meter-peak.max { background: var(--max); }

.meter-thumb {
  width: 14px;
  height: 14px;
  box-sizing: border-box;
  top: 50%;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--axis);
  transform: translate(-50%, -50%);
}

.meter-scale {
  margin-top: 4px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.72rem;
}

.peaks { margin-top: 12px; }

.peak-min, .peak-max {
  background: #0d1016;
  border-radius: 12px;
  padding: 8px 10px;
  flex: 1;
  border: 1px solid transparent;
}

.peak-min.is-hot { border-color: var(--min); }
.peak-max.is-hot { border-color: var(--max); }

.lbl {
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 2px;
}

.peak-min .lbl { color: var(--min); }
.peak-max .lbl { color: var(--max); }

.peaks strong { font-size: 0.98rem; }

.peaks em, .peaks time {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.75rem;
}

canvas[data-chart] {
  width: 100%;
  height: 84px;
  display: block;
  margin-top: 10px;
}

.panel { padding: 16px; }

.panel-head {
  align-items: flex-end;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.panel-head p { max-width: 62ch; font-size: 0.92rem; }

.plot-frame {
  height: min(440px, 86vw);
  border-radius: 16px;
  background: #0c0e14;
  border: 1px solid #242a36;
  overflow: hidden;
}

#plot { width: 100%; height: 100%; display: block; }

.plot-readout {
  margin-top: 10px;
  font-size: 0.95rem;
}

.peg, .orient, .fine, .persist-note { margin-top: 6px; font-size: 0.92rem; }

.peg { color: var(--max); }
.peg[hidden], .fine[hidden] { display: none; }

.legend ul {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
  display: grid;
  gap: 12px;
}

.legend li { display: flex; gap: 10px; align-items: flex-start; }

.log {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
  display: grid;
  gap: 6px;
}

.log li {
  padding: 8px 10px;
  border-radius: 10px;
  background: #0d1016;
  font-family: var(--mono);
  font-size: 0.82rem;
}

.log li.empty {
  font-family: var(--sans);
  color: var(--muted);
  font-size: 0.92rem;
}

.help { padding: 0; }

.help summary {
  cursor: pointer;
  padding: 16px;
  font-weight: 650;
  list-style: none;
}

.help summary::-webkit-details-marker { display: none; }

.help-body { padding: 0 16px 16px; color: var(--soft); }

.help-body ol { margin: 8px 0 0; padding-left: 1.2rem; display: grid; gap: 8px; }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.report {
  width: 100%;
  min-height: 150px;
  margin: 0;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid #343b4a;
  background: #0d1016;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.45;
  resize: vertical;
}

.report[hidden] { display: none; }

.segment {
  display: flex;
  border: 1px solid #343b4a;
  border-radius: 999px;
  overflow: hidden;
}

.segment button {
  border: 0;
  border-radius: 0;
  min-width: 96px;
}

.screen-nav {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  background: rgba(7, 8, 13, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.screen-nav button,
.expand {
  flex: none;
  min-height: 40px;
  padding: 8px 12px;
  font-size: 0.86rem;
}

.card-head .expand { margin-left: auto; }

.expand { margin-right: 8px; }

body[data-screen="x"] .wrap > :not(.axes),
body[data-screen="y"] .wrap > :not(.axes),
body[data-screen="z"] .wrap > :not(.axes),
body[data-screen="plot"] .wrap > :not(.plot-panel),
body[data-screen="puro"] .wrap > :not(.puro) {
  display: none;
}

body[data-screen="x"] .card:not([data-axis="x"]),
body[data-screen="y"] .card:not([data-axis="y"]),
body[data-screen="z"] .card:not([data-axis="z"]) {
  display: none;
}

body[data-screen="x"] .axes,
body[data-screen="y"] .axes,
body[data-screen="z"] .axes {
  display: block;
}

body:not([data-screen="all"]) .wrap {
  width: min(1200px, 100%);
  padding-top: 8px;
}

body:not([data-screen="all"]) .card,
body[data-screen="plot"] .plot-panel {
  min-height: calc(100dvh - 74px);
}

body:not([data-screen="all"]) canvas[data-chart] {
  height: min(48dvh, 460px);
}

body[data-screen="plot"] .plot-frame {
  height: calc(100dvh - 210px);
}

body[data-screen="x"] .expand[data-screen="x"],
body[data-screen="y"] .expand[data-screen="y"],
body[data-screen="z"] .expand[data-screen="z"],
body[data-screen="plot"] .expand[data-screen="plot"] {
  display: none;
}

body[data-screen="puro"] {
  height: 100dvh;
  height: 100svh;
  overflow: hidden;
  padding: 0;
  background: #090807;
}

body[data-screen="puro"] .puro {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  width: min(520px, 100%);
  height: 100dvh;
  height: 100svh;
  margin: 0 auto;
  overflow: hidden;
  padding:
    calc(6px + env(safe-area-inset-top))
    calc(12px + env(safe-area-inset-right))
    calc(8px + env(safe-area-inset-bottom))
    calc(12px + env(safe-area-inset-left));
  color: #f4efe6;
  background:
    radial-gradient(900px 420px at 50% 28%, rgba(225, 6, 0, 0.14), transparent 62%),
    #090807;
}

body[data-screen="puro"] em {
  display: inline;
}

.puro-quiet {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 14px;
  margin: 0;
}

.puro-bar {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-top: 6px;
}

.hud {
  margin: 0;
  min-width: 0;
  white-space: nowrap;
}

.hud strong {
  font-family: var(--mono);
  font-size: 1.45rem;
  font-weight: 560;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.04em;
  line-height: 1;
}

.hud em {
  display: inline;
  margin-left: 4px;
  color: #e10600;
  font-style: normal;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
}

.hud.spd { text-align: right; }

.puro-live {
  margin: 0;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #e10600;
  font-size: 0.62rem;
  line-height: 1;
  white-space: nowrap;
}

.puro-dial {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  container-type: size;
  display: grid;
  place-items: center;
}

.puro-square {
  width: min(100cqw, 100cqh);
  height: min(100cqw, 100cqh);
}

#puro-plot {
  width: 100%;
  height: 100%;
  display: block;
}

.puro-charts {
  display: grid;
  gap: 2px;
  margin-top: 2px;
}

.trace-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "name value"
    "peak value";
  align-items: center;
  column-gap: 10px;
}

.trace-name {
  grid-area: name;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.trace-name.x { color: #ff5a7a; }
.trace-name.y { color: #3ee0a0; }
.trace-name.z { color: #5aa9ff; }

.trace-head small {
  grid-area: peak;
  color: #8d8680;
  font-family: var(--mono);
  font-size: 0.68rem;
  text-align: left;
  white-space: nowrap;
}

.trace-value {
  grid-area: value;
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 4px;
  margin: 0;
}

.trace-value strong {
  font-family: var(--mono);
  font-size: 1rem;
  font-weight: 560;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}

.trace-value em {
  display: inline;
  color: #e10600;
  font-style: normal;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
}

.puro-charts canvas {
  display: block;
  width: 100%;
  height: 52px;
  margin-top: 1px;
}

.puro-actions {
  display: flex;
  gap: 12px;
  margin: 0;
}

body[data-screen="puro"] .puro-actions button {
  width: auto;
  height: auto;
  min-height: 0;
  margin: 0;
  padding: 2px 0;
  background: none;
  border: 0;
  border-radius: 0;
  color: #6f6862;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

body[data-screen="puro"] #btn-cal:disabled {
  opacity: 0.35;
}

@media (min-width: 980px) {
  .axes { grid-template-columns: repeat(3, 1fr); }
  .legend ul { grid-template-columns: 1fr; }
}

@media (max-height: 520px) and (orientation: landscape) {
  .plot-frame { height: 230px; }
  .axes { grid-template-columns: repeat(3, 1fr); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

@keyframes flash {
  0% { box-shadow: inset 0 0 0 1px var(--axis); }
  100% { box-shadow: inset 0 0 0 1px transparent; }
}

@media (prefers-reduced-motion: reduce) {
  .pill.live::before, .card.is-flash { animation: none; }
}
