:root {
  color-scheme: dark;
  --bg: #101211;
  --rail: #171a18;
  --rail-2: #1d211f;
  --panel: #f7faf6;
  --panel-2: #edf3ee;
  --ink: #101712;
  --muted: #6a756d;
  --soft: #a9b4ad;
  --line: rgba(18, 28, 20, 0.12);
  --dark-line: rgba(255, 255, 255, 0.09);
  --signal: #39d98a;
  --cyan: #4ecbd3;
  --amber: #f2c15c;
  --bad: #ff6b6b;
  --white: #f7faf6;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--white);
  overflow: hidden;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(540px, 1fr) 356px;
  height: 100vh;
  min-height: 0;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.03), transparent 18%),
    var(--bg);
}

.left-rail,
.right-rail {
  background: var(--rail);
  border-right: 1px solid var(--dark-line);
  height: 100vh;
  min-height: 0;
  padding: 22px;
  overflow: auto;
}

.right-rail {
  display: flex;
  flex-direction: column;
  gap: 14px;
  border-right: 0;
  border-left: 1px solid var(--dark-line);
  background: #151816;
  overflow: auto;
}

.brand-block {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 12px;
  align-items: center;
  margin-bottom: 30px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(57, 217, 138, 0.32);
  border-radius: var(--radius);
  background: #0e1511;
}

.brand-mark svg,
button svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand-mark svg {
  color: var(--signal);
  width: 28px;
  height: 28px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
  line-height: 1.1;
  font-weight: 760;
  letter-spacing: 0;
}

.brand-block p,
.stage-header p,
.panel-title-row p,
.device-list dt,
.section-kicker,
.metric span,
.metric small,
.protocol-step span,
.validation-box > span,
.log-list,
table,
.reason-list,
.marker-list {
  color: var(--soft);
}

.brand-block p {
  margin-top: 4px;
  font-size: 13px;
}

.rail-section,
.validation-box {
  margin-top: 22px;
}

.section-kicker {
  margin-bottom: 10px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.connection-card {
  display: grid;
  grid-template-columns: 12px 1fr;
  gap: 10px;
  align-items: start;
  padding: 13px;
  border: 1px solid var(--dark-line);
  border-radius: var(--radius);
  background: var(--rail-2);
}

.connection-dot {
  width: 10px;
  height: 10px;
  margin-top: 4px;
  border-radius: 99px;
  background: var(--amber);
  box-shadow: 0 0 0 5px rgba(242, 193, 92, 0.12);
}

.connection-card[data-status="connected"] .connection-dot {
  background: var(--signal);
  box-shadow: 0 0 0 5px rgba(57, 217, 138, 0.13);
}

.connection-card[data-status="error"] .connection-dot,
.connection-card[data-status="idle"] .connection-dot {
  background: var(--bad);
  box-shadow: 0 0 0 5px rgba(255, 107, 107, 0.13);
}

.connection-card strong {
  display: block;
  color: var(--white);
  font-size: 14px;
}

.connection-card span {
  display: block;
  margin-top: 3px;
  color: var(--soft);
  font-size: 12px;
  line-height: 1.35;
}

.device-list {
  margin: 14px 0 0;
}

.stream-list {
  margin-top: 10px;
  padding: 2px 0;
  border-top: 1px solid var(--dark-line);
  border-bottom: 1px solid var(--dark-line);
}

.device-list div {
  display: grid;
  grid-template-columns: 74px 1fr;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--dark-line);
}

.device-list dt,
.device-list dd {
  margin: 0;
  font-size: 12px;
  line-height: 1.35;
}

.device-list dd {
  color: var(--white);
  overflow-wrap: anywhere;
}

.command-button,
.icon-button,
.protocol-step {
  border: 1px solid var(--dark-line);
  color: var(--white);
  background: #202521;
  border-radius: var(--radius);
}

.command-button {
  display: inline-grid;
  grid-template-columns: 18px auto;
  gap: 8px;
  align-items: center;
  width: 100%;
  min-height: 40px;
  margin: 0 0 8px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 680;
}

.command-button svg {
  width: 18px;
  height: 18px;
}

.command-button:hover,
.protocol-step:hover,
.icon-button:hover {
  border-color: rgba(57, 217, 138, 0.5);
}

.compact-log {
  min-height: 144px;
}

.log-list {
  display: grid;
  gap: 7px;
  max-height: 210px;
  overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  line-height: 1.35;
}

.log-row {
  padding: 7px 8px;
  border: 1px solid var(--dark-line);
  border-radius: 6px;
  background: #111511;
}

.log-row[data-level="error"] {
  color: #ffb3b3;
}

.log-row[data-level="warn"] {
  color: #ffe0a3;
}

.main-stage {
  display: flex;
  flex-direction: column;
  gap: 16px;
  height: 100vh;
  min-width: 0;
  padding: 22px;
  overflow: auto;
}

.stage-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.stage-header h2 {
  color: var(--white);
  font-size: 30px;
  line-height: 1.05;
  font-weight: 760;
  letter-spacing: 0;
}

.stage-header p {
  margin-top: 7px;
  font-size: 13px;
}

.stage-header .stream-notice {
  color: rgba(57, 217, 138, 0.86);
  font-weight: 720;
}

.stage-status-cluster {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.review-mode-card {
  display: grid;
  gap: 4px;
  min-width: 190px;
  padding: 9px 12px;
  border: 1px solid rgba(57, 217, 138, 0.28);
  border-radius: var(--radius);
  background: #121a15;
}

.review-mode-card span {
  color: var(--signal);
  font-size: 11px;
  font-weight: 820;
  text-transform: uppercase;
}

.review-mode-card strong {
  color: var(--white);
  font-size: 14px;
  line-height: 1.15;
}

.review-mode-card em {
  color: var(--soft);
  font-size: 12px;
  font-style: normal;
  font-weight: 680;
}

.review-mode-card[data-mode="demo-cloud"],
.review-mode-card[data-mode="demo-local"] {
  border-color: rgba(242, 193, 92, 0.4);
}

.review-mode-card[data-mode="demo-cloud"] span,
.review-mode-card[data-mode="demo-local"] span {
  color: var(--amber);
}

.review-mode-card[data-mode="real-cloud"] {
  border-color: rgba(78, 203, 211, 0.45);
}

.review-mode-card[data-mode="real-cloud"] span {
  color: var(--cyan);
}

.review-mode-card[data-mode="real-cloud-pending"] {
  border-color: rgba(255, 107, 107, 0.42);
}

.review-mode-card[data-mode="real-cloud-pending"] span {
  color: var(--bad);
}

.quality-pill {
  display: grid;
  grid-template-columns: auto 56px;
  gap: 10px;
  align-items: center;
  min-width: 172px;
  padding: 9px 10px 9px 14px;
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: var(--radius);
  background: #181d1a;
}

.quality-pill span {
  font-size: 13px;
  color: var(--soft);
}

.quality-pill strong {
  display: grid;
  place-items: center;
  min-height: 34px;
  border-radius: 6px;
  color: #07120b;
  background: var(--amber);
  font-size: 14px;
}

.quality-pill[data-severity="good"] strong {
  background: var(--signal);
}

.quality-pill[data-severity="bad"] strong {
  background: var(--bad);
}

.metrics-grid {
  display: grid;
  grid-template-columns: minmax(240px, 1.45fr) repeat(4, minmax(112px, 1fr));
  gap: 10px;
}

.metric {
  min-height: 124px;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.metric.primary {
  display: grid;
  grid-template-columns: 1fr 42%;
  grid-template-rows: auto auto;
  column-gap: 12px;
}

.metric span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

.metric strong {
  display: flex;
  align-items: baseline;
  gap: 7px;
  margin-top: 20px;
  font-size: 42px;
  line-height: 0.9;
  font-weight: 800;
  letter-spacing: 0;
}

.metric:not(.primary) strong {
  font-size: 34px;
}

.metric.phase {
  min-height: 96px;
}

.metric.phase strong {
  margin-top: 16px;
  font-size: 28px;
}

.metric.phase[data-state="unavailable"] {
  border: 1px dashed rgba(18, 28, 20, 0.16);
  background: #eef3ef;
  box-shadow: none;
}

.metric.phase[data-state="unavailable"] strong {
  color: var(--muted);
  font-size: 22px;
}

.metric small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
}

#miniBreathCanvas {
  grid-row: 1 / span 2;
  grid-column: 2;
  align-self: stretch;
  width: 100%;
  height: 82px;
  margin-top: 10px;
}

.wave-panel,
.bottom-strip,
.validation-box {
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.wave-panel {
  min-height: 386px;
  padding: 18px;
}

.phase-wave-panel {
  min-height: 260px;
  padding: 16px 18px;
}

.main-support-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.85fr) minmax(0, 1fr) minmax(0, 1.25fr);
  grid-template-areas:
    "status calibration samples"
    "status calibration markers";
  grid-template-rows: min-content minmax(140px, 1fr);
  gap: 12px;
  align-items: stretch;
}

.main-support-grid .validation-box,
.main-support-grid .bottom-strip {
  min-height: 0;
  margin-top: 0;
}

.panel-title-row,
.strip-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.panel-title-row h3,
.strip-header h3,
.validation-box h3 {
  color: var(--ink);
  font-size: 16px;
  font-weight: 780;
  letter-spacing: 0;
}

.panel-title-row p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.legend {
  display: flex;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}

.legend span {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.legend i {
  display: inline-block;
  width: 18px;
  height: 3px;
  border-radius: 99px;
}

.legend-wave {
  background: var(--signal);
}

.legend-marker {
  background: var(--amber);
}

#waveCanvas {
  display: block;
  width: 100%;
  height: 270px;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(57, 217, 138, 0.05), transparent 40%),
    #fbfdf9;
}

#phaseCanvas {
  display: block;
  width: 100%;
  height: 178px;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(78, 203, 211, 0.06), transparent 44%),
    #fbfdf9;
}

.phase-status {
  display: grid;
  gap: 3px;
  min-width: 150px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfdf9;
  text-align: right;
}

.phase-status strong {
  color: var(--ink);
  font-size: 14px;
  font-weight: 820;
}

.phase-status span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 720;
}

.phase-status[data-state="inhale"] {
  border-color: rgba(57, 217, 138, 0.44);
}

.phase-status[data-state="exhale"] {
  border-color: rgba(78, 203, 211, 0.48);
}

.phase-status[data-state="turn"] {
  border-color: rgba(242, 193, 92, 0.56);
}

.bottom-strip {
  padding: 12px 14px;
}

.status-box {
  grid-area: status;
}

.calibration-box {
  grid-area: calibration;
}

.samples-panel {
  grid-area: samples;
}

.markers-box {
  grid-area: markers;
  min-height: 0;
  padding: 12px;
}

.samples-panel[data-collapsed="true"] .sample-table-wrap {
  display: none;
}

.samples-panel[data-collapsed="false"] {
  grid-area: auto;
  grid-column: 1 / -1;
}

.sample-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
}

.sample-toggle {
  display: inline-grid;
  grid-template-columns: 14px auto;
  gap: 5px;
  align-items: center;
  min-height: 30px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: #fbfdf9;
  font-size: 12px;
  font-weight: 760;
}

.sample-toggle svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  transition: transform 160ms ease;
}

.samples-panel[data-collapsed="false"] .sample-toggle svg {
  transform: rotate(180deg);
}

.toggle-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.toggle-row label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.sample-table-wrap {
  max-height: 154px;
  margin-top: 12px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

th,
td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

th {
  position: sticky;
  top: 0;
  background: var(--panel-2);
  color: #405046;
  font-size: 11px;
  text-transform: uppercase;
}

td {
  color: #253027;
}

.validation-box {
  padding: 16px;
}

.right-rail .validation-box {
  margin-top: 0;
}

.test-box {
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  min-height: auto;
  border: 1px solid rgba(57, 217, 138, 0.38);
  background: #f4fbf6;
}

.calibration-box {
  background: #f1f6f2;
}

.status-compact {
  display: grid;
  grid-template-columns: 108px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  margin-top: 10px;
}

.status-box .score-ring {
  width: 108px;
  height: 108px;
  margin: 0;
}

.status-box .score-ring span {
  font-size: 30px;
}

.status-box .score-ring small {
  margin-top: -24px;
  font-size: 9px;
}

.status-box .reason-list {
  padding-left: 14px;
}

.validation-box .panel-title-row span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
}

.score-ring {
  display: grid;
  place-items: center;
  width: 152px;
  height: 152px;
  margin: 18px auto 12px;
  border-radius: 50%;
  background:
    radial-gradient(circle at center, var(--panel) 0 56%, transparent 57%),
    conic-gradient(var(--signal) calc(var(--score) * 1%), #d9e1db 0);
}

.score-ring span {
  color: var(--ink);
  font-size: 40px;
  line-height: 1;
  font-weight: 820;
}

.score-ring small {
  margin-top: -36px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 720;
  text-transform: uppercase;
}

.reason-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 18px;
  font-size: 12px;
  line-height: 1.35;
}

.calibration-summary {
  margin-top: 10px;
  color: #314038;
  font-size: 12px;
  line-height: 1.35;
}

.calibration-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0 0;
}

.calibration-grid div {
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfdf9;
}

.calibration-grid dt,
.calibration-grid dd {
  margin: 0;
}

.calibration-grid dt {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.calibration-grid dd {
  margin-top: 4px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 820;
}

.calibration-notes {
  margin-top: 12px;
}

.main-support-grid .calibration-notes {
  max-height: 58px;
  overflow: auto;
}

.protocol-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.test-box .protocol-list {
  flex: 0 0 auto;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  min-height: 148px;
  max-height: 232px;
  overflow: auto;
  padding-right: 2px;
}

.protocol-step {
  display: grid;
  grid-template-columns: 82px 1fr;
  gap: 10px;
  align-items: center;
  min-height: 48px;
  padding: 9px 10px;
  color: #eaf5ee;
  background: #17201a;
  text-align: left;
}

.test-box .protocol-step {
  grid-template-columns: 1fr;
  gap: 3px;
  min-height: 54px;
  padding: 9px;
}

.protocol-step strong {
  color: var(--white);
  font-size: 13px;
}

.protocol-step span {
  color: #afbbb3;
  font-size: 12px;
}

.protocol-step.active {
  border-color: rgba(57, 217, 138, 0.7);
  background: #0f2418;
}

.active-test-card {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
}

.active-test-card[data-state="running"] {
  border-color: rgba(57, 217, 138, 0.5);
}

.active-test-card[data-state="done"] {
  border-color: rgba(242, 193, 92, 0.65);
}

.active-test-card[data-state="idle"] .breath-guide,
.active-test-card[data-state="done"] .breath-guide,
.active-test-card[data-state="idle"] .test-clock,
.active-test-card[data-state="idle"] .test-metric-grid,
.active-test-card[data-state="idle"] .test-stop,
.active-test-card[data-state="done"] .test-stop {
  display: none;
}

.active-test-card > strong {
  display: block;
  color: var(--ink);
  font-size: 16px;
  font-weight: 820;
}

.active-test-card > span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.breath-guide {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  margin-top: 12px;
}

.test-box .breath-guide {
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 14px;
}

.breath-orb-shell {
  display: grid;
  place-items: center;
  width: 86px;
  height: 86px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    radial-gradient(circle at center, rgba(57, 217, 138, 0.13), transparent 62%),
    #fbfdf9;
  overflow: hidden;
}

.test-box .breath-orb-shell {
  width: 100%;
  height: 148px;
}

.breath-orb {
  --orb-scale: 0.8;
  --orb-opacity: 0.82;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  color: #06120b;
  background:
    radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.92), transparent 20%),
    var(--signal);
  box-shadow:
    0 0 0 8px rgba(57, 217, 138, 0.12),
    0 14px 30px rgba(20, 148, 90, 0.28);
  opacity: var(--orb-opacity);
  transform: scale(var(--orb-scale));
  transition: transform 180ms linear, opacity 180ms linear, background 180ms linear;
}

.test-box .breath-orb {
  width: 82px;
  height: 82px;
}

.breath-orb[data-mode="hold"] {
  background:
    radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.9), transparent 22%),
    var(--cyan);
  box-shadow:
    0 0 0 8px rgba(78, 203, 211, 0.12),
    0 14px 30px rgba(78, 203, 211, 0.22);
}

.breath-orb[data-mode="fire"] {
  background:
    radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.9), transparent 20%),
    var(--amber);
  box-shadow:
    0 0 0 8px rgba(242, 193, 92, 0.14),
    0 14px 30px rgba(242, 193, 92, 0.24);
}

.breath-orb[data-mode="invalid"] {
  background:
    radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.82), transparent 20%),
    var(--bad);
  box-shadow:
    0 0 0 8px rgba(255, 107, 107, 0.12),
    0 14px 30px rgba(255, 107, 107, 0.18);
}

.breath-orb span {
  font-size: 10px;
  font-weight: 860;
  text-transform: uppercase;
}

.test-box .breath-orb span {
  font-size: 12px;
}

#guideCanvas {
  display: block;
  min-width: 0;
  width: 100%;
  height: 86px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfdf9;
}

.test-box #guideCanvas {
  height: 132px;
}

.test-clock {
  display: grid;
  grid-template-columns: 86px 1fr;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
}

.test-clock span {
  display: grid;
  place-items: center;
  min-height: 42px;
  border-radius: 6px;
  color: #06120b;
  background: var(--signal);
  font-size: 22px;
  line-height: 1;
  font-weight: 840;
}

.test-clock em {
  display: grid;
  place-items: center;
  min-height: 42px;
  border-radius: 6px;
  color: var(--white);
  background: #142119;
  font-size: 14px;
  font-style: normal;
  font-weight: 760;
}

.test-score-card {
  display: grid;
  grid-template-columns: 84px 1fr;
  grid-template-areas:
    "label value"
    "detail detail";
  gap: 4px 10px;
  align-items: center;
  margin-top: 12px;
  padding: 10px;
  border: 1px solid rgba(57, 217, 138, 0.38);
  border-radius: 6px;
  background:
    linear-gradient(135deg, rgba(57, 217, 138, 0.16), rgba(255, 255, 255, 0.74)),
    #fbfdf9;
}

.test-score-card-secondary {
  border-color: rgba(78, 203, 211, 0.42);
  background:
    linear-gradient(135deg, rgba(78, 203, 211, 0.17), rgba(255, 255, 255, 0.75)),
    #fbfdf9;
}

.test-score-card[hidden] {
  display: none;
}

.test-score-card span {
  grid-area: label;
  color: var(--muted);
  font-size: 10px;
  font-weight: 840;
  text-transform: uppercase;
}

.test-score-card strong {
  grid-area: value;
  color: #06120b;
  font-size: 26px;
  line-height: 1;
  font-weight: 880;
  text-align: right;
}

.test-score-card em {
  grid-area: detail;
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
  font-weight: 720;
  line-height: 1.25;
}

.test-metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0 0;
}

.test-metric-grid div {
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfdf9;
}

.test-metric-grid dt,
.test-metric-grid dd {
  margin: 0;
}

.test-metric-grid dt {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.test-metric-grid dd {
  margin-top: 4px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 820;
}

.test-stop {
  margin-top: 10px;
  margin-bottom: 0;
  color: var(--white);
  background: #17201a;
}

.test-history {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.test-history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.test-history-header strong {
  color: var(--ink);
  font-size: 12px;
  font-weight: 840;
}

.test-history-header span {
  min-width: 28px;
  padding: 3px 7px;
  border-radius: 999px;
  color: var(--muted);
  background: #eef4ed;
  font-size: 11px;
  font-weight: 820;
  text-align: center;
}

.test-history ol {
  display: grid;
  gap: 6px;
  max-height: 104px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  overflow: auto;
}

.test-history li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 3px 8px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfdf9;
}

.test-history li strong,
.test-history li span,
.test-history li em {
  min-width: 0;
}

.test-history li strong {
  color: var(--ink);
  font-size: 12px;
  line-height: 1.1;
}

.test-history li span {
  color: var(--signal-strong);
  font-size: 12px;
  font-weight: 860;
  text-align: right;
}

.test-history li em {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 10.5px;
  font-style: normal;
  font-weight: 700;
  line-height: 1.25;
}

.test-history-empty {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
}

.icon-button svg {
  width: 18px;
  height: 18px;
}

.marker-input-row {
  margin-top: 12px;
}

.markers-box .marker-input-row {
  margin-top: 10px;
}

.marker-input-row input {
  width: 100%;
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  background: #fff;
}

.markers-box .marker-input-row input {
  height: 34px;
}

.marker-list {
  display: grid;
  gap: 8px;
  max-height: 118px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
  overflow: auto;
  font-size: 12px;
}

.markers-box .marker-list {
  max-height: 50px;
  margin-top: 8px;
}

.marker-list li {
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: #2b352e;
}

.markers-box .marker-list li {
  padding: 6px;
}

@media (max-width: 1500px) {
  .metrics-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .metric.primary {
    grid-column: span 2;
  }

  .main-support-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-areas:
      "status calibration"
      "samples markers";
    grid-template-rows: auto;
  }

  .samples-panel {
    grid-column: auto;
  }
}

@media (max-width: 1180px) {
  body {
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 240px minmax(0, 1fr);
    height: auto;
    min-height: 100vh;
  }

  .right-rail {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    border-left: 0;
    border-top: 1px solid var(--dark-line);
    height: auto;
    min-height: 0;
    overflow: visible;
  }

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

  .main-support-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-areas:
      "status calibration"
      "samples markers";
  }

  .samples-panel {
    grid-column: auto;
  }
}

@media (max-width: 820px) {
  .app-shell {
    display: block;
  }

  .left-rail,
  .right-rail,
  .main-stage {
    width: 100%;
    height: auto;
    min-height: 0;
    padding: 16px;
    overflow: visible;
  }

  .right-rail {
    display: block;
  }

  .stage-header,
  .panel-title-row,
  .strip-header {
    display: grid;
  }

  .stage-status-cluster {
    justify-content: stretch;
  }

  .review-mode-card,
  .quality-pill {
    width: 100%;
  }

  .stage-header h2 {
    font-size: 25px;
  }

  .metrics-grid,
  .metric.primary,
  .main-support-grid {
    grid-template-columns: 1fr;
    grid-template-areas:
      "status"
      "calibration"
      "samples"
      "markers";
  }

  .samples-panel {
    grid-column: auto;
  }

  #miniBreathCanvas {
    grid-column: 1;
    grid-row: auto;
  }

  .metric strong {
    font-size: 34px;
  }
}

@media (max-width: 520px) {
  .breath-guide,
  .test-clock {
    grid-template-columns: 1fr;
  }

  .breath-orb-shell {
    justify-self: center;
    width: min(140px, 100%);
    height: 104px;
  }

  #guideCanvas {
    height: 100px;
  }
}
