/* ==========================================================================
   Demo - hardware demo styles
   Single stylesheet, no build step, no dependencies.

   Tokens and page chrome (header, nav, page-head, footer) are kept in sync
   with scalpelspace.com, whose assets/css/site.css is the source of truth and
   is kept here verbatim as site-reference.css to diff against. The tool
   chrome below - status colours, cards, tabs, the console and the log - is
   shared with blasher.scalpelspace.com so the two tools feel like one set.
   What is only here is the demo grid: charts, an orientation view and live
   readouts.
   ========================================================================== */

/* --- Tokens ------------------------------------------------------------- */

:root {
  --bg: #ffffff;
  --bg-raised: #fafafa;
  --bg-header: rgba(255, 255, 255, 0.8);
  --text: #16161a;
  --text-muted: #5c5c66;
  --text-faint: #85858f;
  --border: #e4e4e9;
  --border-strong: #d0d0d8;
  --accent: #7a00d4;
  --accent-hover: #5c00a8;
  --grad-a: #a800f0;
  --grad-b: #2200cc;
  --shadow-lift: 0 2px 4px rgba(16, 16, 32, 0.06), 0 16px 40px rgba(16, 16, 32, 0.1);

  /*
   * Live-state colours. The parent site has no equivalent: it has no
   * connection to lose, no reading to go stale and no log to colour. Both
   * schemes are tuned to clear 4.5:1 against the surface they sit on, which
   * is why the light values are so much darker than the dark ones.
   */
  --ok: #0a7a3d;
  --warn: #8a5a00;
  --error: #c22626;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
  Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
  "Liberation Mono", monospace;

  --radius: 12px;
  --radius-lg: 16px;
  --container: 1040px;
  /*
   * The app column matches the parent site's rather than blasher's narrower
   * one. Blasher is a form you fill in top to bottom; this page is a wall of
   * live readouts that wants two columns of cards side by side, and at 860px
   * the second column never fits.
   */
  --container-app: 1040px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0c10;
    --bg-raised: #141419;
    --bg-header: rgba(12, 12, 16, 0.8);
    --text: #f2f2f5;
    --text-muted: #a0a0ad;
    --text-faint: #77777f;
    --border: #26262e;
    --border-strong: #35353f;
    --accent: #b46bff;
    --accent-hover: #cb99ff;
    --shadow-lift: 0 2px 4px rgba(0, 0, 0, 0.5), 0 16px 40px rgba(0, 0, 0, 0.45);

    --ok: #3ddc84;
    --warn: #f5b942;
    --error: #ff6b6b;
  }
}

/* --- Base --------------------------------------------------------------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.2;
  letter-spacing: -0.02em;
  font-weight: 650;
}

p {
  margin: 0;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

img {
  max-width: 100%;
  height: auto;
}

code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.1em 0.4em;
}

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

.container {
  width: 100%;
  max-width: var(--container);
  margin: 0 auto;
  padding: 0 24px;
}

.skip-link {
  position: absolute;
  left: -9999px;
}

.skip-link:focus {
  left: 16px;
  top: 16px;
  z-index: 100;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 10px 16px;
}


/*
 * The app toggles panels, fact lists and motion blocks with the `hidden`
 * attribute, and every one of them is a flex or grid container. A class
 * selector beats the UA stylesheet's [hidden] { display: none }, so without
 * this they stay on screen. The parent site needs no equivalent: nothing it
 * hides carries a display rule.
 */
[hidden] {
  display: none !important;
}

/* --- Header ------------------------------------------------------------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg-header);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 64px;
  flex-wrap: wrap;
  padding-top: 10px;
  padding-bottom: 10px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 650;
  font-size: 1.0625rem;
  letter-spacing: -0.01em;
}

.brand:hover {
  color: var(--text);
  text-decoration: none;
}

.brand img {
  width: 28px;
  height: 28px;
  display: block;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.site-nav a {
  color: var(--text-muted);
  font-size: 0.9375rem;
  font-weight: 500;
  padding: 7px 11px;
  border-radius: 8px;
  white-space: nowrap;
}

.site-nav a:hover {
  color: var(--text);
  background: var(--bg-raised);
  text-decoration: none;
}

/*
 * Marks the tab you are on. This subdomain is a separate origin from the rest
 * of the site, so the highlight is what tells you the cross-domain hop landed
 * where you expected.
 */
.site-nav a[aria-current="page"] {
  color: var(--text);
  background: var(--bg-raised);
}

.site-nav .ext::after {
  content: "\2197";
  font-size: 0.75em;
  margin-left: 4px;
  opacity: 0.6;
  vertical-align: 1px;
}

/* --- Main --------------------------------------------------------------- */

main {
  flex: 1 0 auto;
}

.app {
  width: 100%;
  max-width: var(--container-app);
  margin: 0 auto;
  padding: 0 24px clamp(28px, 5vh, 48px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.page-head {
  padding: clamp(48px, 9vh, 80px) 0 8px;
}

.page-head h1 {
  font-size: clamp(1.875rem, 4.5vw, 2.5rem);
}

.page-head .lede {
  margin-top: 14px;
  max-width: 62ch;
  font-size: 1.0625rem;
  color: var(--text-muted);
}

.banner {
  padding: 14px 18px;
  border-radius: var(--radius);
  font-size: 0.9375rem;
}

.banner.error {
  background: var(--bg-raised);
  background: color-mix(in srgb, var(--error) 10%, transparent);
  border: 1px solid var(--error);
}

/* --- Tabs --------------------------------------------------------------- */

/*
 * A centred segmented control: the two modes are the page's main division, so
 * it is sized like a sub-heading rather than a pair of loose filter chips. The
 * track carries the border and the tabs inside it stay transparent until
 * selected, which keeps the pair reading as one control.
 */
.tabs {
  display: flex;
  gap: 4px;
  /*
   * A definite width, not fit-content: sized to content there is no free
   * space for flex: 1 to distribute, so the two halves keep their label
   * widths and the selected pill changes size as you switch. 360 divides
   * into two whole 173px halves, and the outline is an inset shadow rather
   * than a border so it stays out of the box model and cannot reintroduce
   * fractional widths.
   */
  width: min(100%, 360px);
  margin: clamp(10px, 2vh, 20px) auto 6px;
  padding: 5px;
  background: var(--bg-raised);
  box-shadow: inset 0 0 0 1px var(--border);
  border-radius: 999px;
}

/*
 * flex: 1 splits the track evenly, so the selected pill is the same size
 * whichever tab it is on. Sized to content the two differ by the width of
 * their labels, and the pill visibly resized and shifted on every switch.
 *
 * No border, following the parent site's gradient CTA. The base button rule
 * has one, and merely making it transparent left 2px of the box belonging to
 * a border that only complicated the gradient's edge; the padding below is
 * 1px larger to keep the same outer size. A 1.5 line-height then lands the
 * height on a whole 46px instead of 47.2, so the rounded ends sit on the
 * pixel grid rather than being anti-aliased across it.
 */
.tab {
  flex: 1 1 0;
  justify-content: center;
  padding: 11px 28px;
  font-size: 1rem;
  line-height: 1.5;
  font-weight: 600;
  letter-spacing: -0.01em;
  background: transparent;
  border: 0;
  color: var(--text-muted);
}

.tab:hover:not(:disabled) {
  background: var(--bg);
  color: var(--text);
}

/*
 * No background-origin fix needed here, unlike button.primary: .tab drops the
 * border entirely, so the padding box and the border box are the same and the
 * gradient already reaches the real edge.
 */
.tab[aria-selected="true"],
.tab[aria-selected="true"]:hover {
  background: linear-gradient(135deg, var(--grad-a), var(--grad-b));
  color: #ffffff;
}

.tab[aria-selected="true"]:hover {
  filter: brightness(1.12);
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* --- Serial console ----------------------------------------------------- */

.serial-out {
  height: clamp(220px, 42vh, 460px);
  max-height: none;
  margin-bottom: 14px;
}

.serial-out .line.tx {
  color: var(--accent);
}


.send-row {
  gap: 10px;
}

.send-input {
  flex: 1 1 260px;
  min-width: 0;
  font-family: var(--font-mono);
}

.monitor-actions {
  margin-top: 14px;
}

.monitor-stats {
  margin: 0 0 0 auto;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
}

/* --- Cards -------------------------------------------------------------- */

.card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
}

.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.card-head h2 {
  margin: 0;
  font-size: 1.0625rem;
}

/* Pushes the log's Clear button and the connection pill to the far edge. */
.card-head > .push-end {
  margin-left: auto;
}

margin:

0
0
14
px

;
color:
var

(
--text-muted

)
;
font-size:

0.9375
rem

;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.row.options {
  margin-bottom: 16px;
}

/* --- Connection pill ---------------------------------------------------- */

.conn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  font-size: 0.8125rem;
  font-weight: 550;
  color: var(--text-muted);
  white-space: nowrap;
}

.conn .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
}

.conn[data-state="ok"] {
  color: var(--text);
}

.conn[data-state="ok"] .dot {
  background: var(--ok);
  box-shadow: 0 0 8px var(--ok);
}

.conn[data-state="error"] .dot {
  background: var(--error);
}

/* --- Buttons ------------------------------------------------------------ */

/*
 * Pills, matching the parent site's .chip and .promo-cta. Secondary buttons
 * sit on --bg so they read as raised against the card's --bg-raised.
 */
button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 550;
  padding: 9px 20px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease,
  filter 0.18s ease;
}

button:hover:not(:disabled) {
  border-color: var(--border-strong);
  color: var(--text);
}

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

button.primary {
  background: linear-gradient(135deg, var(--grad-a), var(--grad-b));
  background-origin: border-box;
  border-color: transparent;
  color: #ffffff;
  font-weight: 600;
}

button.primary:hover:not(:disabled) {
  color: #ffffff;
  border-color: transparent;
  filter: brightness(1.12);
}

button.big {
  padding: 13px 26px;
  font-size: 1rem;
}

button.small {
  padding: 5px 13px;
  font-size: 0.8125rem;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9375rem;
  color: var(--text-muted);
  cursor: pointer;
}

.check input {
  accent-color: var(--accent);
}

/* --- Fact lists --------------------------------------------------------- */

.facts {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 32px;
  margin: 16px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.facts > div {
  min-width: 150px;
}

.facts dt {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-faint);
}

.facts dd {
  margin: 3px 0 0;
  font-family: var(--font-mono);
  font-size: 0.875rem;
}

/* --- Advanced settings -------------------------------------------------- */

.advanced summary {
  cursor: pointer;
  list-style: none;
}

.advanced summary::-webkit-details-marker {
  display: none;
}

.advanced summary h2 {
  display: inline-block;
  margin: 0;
  font-size: 1.0625rem;
}

.advanced summary::before {
  content: "\25B8";
  color: var(--text-faint);
  margin-right: 8px;
}

.advanced[open] summary::before {
  content: "\25BE";
}

.advanced h3 {
  margin: 22px 0 12px;
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-faint);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px 18px;
  margin-bottom: 16px;
}

.grid label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/*
 * Separated from the line tests above it: those act on the hardware, this one
 * only rewrites the form.
 */
.reset-row {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.reset-hint {
  margin: 0;
  flex: 1 1 260px;
}

.grid label.inline {
  flex-direction: row;
  align-items: center;
  align-self: end;
  padding-bottom: 10px;
}

input[type="text"],
input[type="number"],
select {
  font: inherit;
  font-size: 0.9375rem;
  padding: 8px 11px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

input[type="text"],
input[type="number"] {
  font-family: var(--font-mono);
}

/* --- Log ---------------------------------------------------------------- */

.log {
  margin: 0;
  max-height: 320px;
  overflow: auto;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--bg);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-muted);
}

.log .line.ok {
  color: var(--ok);
}

.log .line.warn {
  color: var(--warn);
}

.log .line.error {
  color: var(--error);
}

/* --- Demo grid ---------------------------------------------------------- */

/*
 * The product panel is a masonry-free two-column grid of independent cards.
 * auto-fit rather than a fixed count: a card is readable at 320px, so the
 * layout collapses to one column on a phone and to two on anything wider
 * without a breakpoint of its own.
 */
.demo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
  align-items: start;
}

.product {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* A status strip above the grid, with no controls under its last paragraph. */
.control-card .hint {
  margin-bottom: 0;
}

.demo-card {
  min-width: 0; /* Grid items default to min-content; canvases are wider. */
}

/* Names the sensor behind a card's numbers, in the card head's spare corner. */
.card-source {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-faint);
  text-align: right;
}

.card-note {
  margin: 14px 0 0;
  font-size: 0.875rem;
}

/*
 * A readout that has not been refreshed within its expected interval. Dimmed
 * rather than blanked: the last known value is still the most useful thing to
 * show, it just should not be mistaken for a current one.
 */
.facts.stale dd {
  opacity: 0.45;
}

.banner.note {
  background: color-mix(in srgb, var(--warn) 10%, transparent);
  border: 1px solid var(--warn);
  margin-bottom: 16px;
}

.mono {
  font-family: var(--font-mono);
}

.command-row {
  margin-bottom: 4px;
}

/* --- Orientation and charts --------------------------------------------- */

.attitude,
.track {
  display: flex;
  justify-content: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/*
 * Both canvases are square, for the same underlying reason: neither has a
 * preferred direction. The board can be rotated to any attitude, and the
 * track needs the same metres per pixel north and east or it would shear.
 * aspect-ratio keeps that true as the column width changes.
 */
.attitude-canvas,
.track-canvas {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
}

.attitude-canvas {
  max-width: 320px;
}

.track-canvas {
  max-width: 300px;
}

.chart {
  display: block;
  width: 100%;
  height: 120px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.chart-short {
  height: 84px;
}

.chart-label {
  margin: 16px 0 6px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-faint);
}

/* --- Motion readouts ---------------------------------------------------- */

.motion-block + .motion-block {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.motion-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.motion-title {
  font-weight: 600;
  font-size: 0.9375rem;
}

.motion-unit {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-faint);
}

.axes {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
}

/*
 * Each axis keeps the colour it is drawn with in the chart and the
 * orientation view, so a trace can be tied to a number without a legend.
 * These three values are the same ones as AXIS_COLORS in src/ui.js, which is
 * where the canvases read them from; they have to be changed together.
 */
.axis {
  flex: 1 1 90px;
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--axis, var(--border-strong));
  border-radius: 8px;
  background: var(--bg);
  min-width: 0;
}

.axis[data-axis="x"] {
  --axis: #e5484d;
}

.axis[data-axis="y"] {
  --axis: #30a46c;
}

.axis[data-axis="z"] {
  --axis: #3b82f6;
}

.axis-name {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-faint);
}

.axis-value {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  margin-left: auto;
}

/* --- LED picker --------------------------------------------------------- */

.led-picker {
  width: 56px;
  height: 38px;
  padding: 3px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--bg);
  cursor: pointer;
}

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.swatch {
  padding: 6px 14px 6px 10px;
  font-size: 0.8125rem;
}

/* Sits on --bg, so a black "Off" swatch needs its own ring to be visible. */
.swatch-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--swatch, transparent);
  box-shadow: inset 0 0 0 1px var(--border-strong);
}

/* --- Supported product tiles -------------------------------------------- */

.repos {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.repo {
  display: block;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--bg);
}

.repo-name {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--accent);
}

.repo p {
  margin-top: 5px;
  font-size: 0.875rem;
  color: var(--text-muted);
}

/*
 * Copied from the parent site's product list rather than shared: these are
 * links out to the docs, firmware and hardware for a board this page can
 * drive, and they should look exactly like the ones on scalpelspace.com.
 */
.links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 9px;
  border: 1px solid var(--border-strong);
  background: var(--bg-raised);
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 550;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.btn:hover {
  border-color: var(--accent);
  color: var(--text);
  text-decoration: none;
}

/* --- Footer ------------------------------------------------------------- */

.site-footer {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  margin-top: 40px;
  padding: 28px 0;
  font-size: 0.875rem;
  color: var(--text-faint);
}

.site-footer .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px 24px;
  flex-wrap: wrap;
}

.footer-links {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
}

.footer-links a {
  color: var(--text-muted);
}

.footer-links a:hover {
  color: var(--text);
}

/* --- Responsive --------------------------------------------------------- */

@media (max-width: 720px) {
  /* Let the header scroll away rather than pin a two-row bar to the top. */
  .site-header {
    position: static;
  }

  .site-header .container {
    justify-content: center;
    gap: 10px;
    min-height: 0;
  }

  .site-nav {
    justify-content: center;
    gap: 0;
  }

  .site-nav a {
    font-size: 0.875rem;
    padding: 6px 7px;
  }

  .site-nav .ext::after {
    margin-left: 2px;
  }

  .card-head > .push-end {
    margin-left: 0;
  }

  /* Two 28px-padded tabs overflow a phone: let the track fill the row. */
  .tabs {
    width: 100%;
  }

  /* Only the side padding needs relaxing; flex: 1 already splits the track. */
  .tab {
    padding: 11px 12px;
  }

  button.big {
    width: 100%;
    justify-content: center;
  }
}

/*
 * A 3-column grid splits evenly instead, which keeps tap targets at a usable
 * size rather than shrinking type to fit.
 */
@media (max-width: 480px) {
  .site-nav {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    justify-items: center;
    width: 100%;
    gap: 2px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
