/* ============================================================
   SY6301 demo shared styles
   ----------------------------------------------------------
   Tokens and components shared by every demo HTML in
   book/_static/demos/. Every selector is scoped under
   `.demo-root` so this file is safe even if Sphinx pulls it
   into the global stylesheet load order on book pages.
   ============================================================ */

.demo-root {
  /* Demo palette tokens (cascade to descendants via `var(...)`). */
  --usafa-navy:    #00205B;
  --usafa-blue:    #1f6098;
  --truth-color:   #14a8c8;
  --meas-color:    #1c2530;
  --est-color:     #1f6098;
  --bound-color:   #cf3a3a;
  --cursor-color:  #00205B;
  --rule:          #d8e2ec;
  --grid:          #eef2f7;
  --bg-soft:       #f6f8fa;

  /* Demo body styling — only inside .demo-root. */
  color: #1c2530;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 13px;
  line-height: 1.45;

  padding: 12px 14px 16px;
  max-width: 1040px;
  margin: 0 auto;
  box-sizing: border-box;
}

/* ------------------------------------------------------------
   Layout
   ------------------------------------------------------------ */
.demo-root .top-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  margin-bottom: 10px;
}
.demo-root .dual-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  margin-bottom: 10px;
}
@media (max-width: 760px) {
  .demo-root .top-grid,
  .demo-root .dual-grid { grid-template-columns: 1fr; }
}

/* ------------------------------------------------------------
   Fieldsets + control rows
   ------------------------------------------------------------ */
.demo-root fieldset {
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 6px 10px 10px;
  margin: 0;
}
.demo-root legend {
  color: var(--usafa-navy);
  font-weight: 600;
  padding: 0 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.demo-root .param-row {
  display: grid;
  grid-template-columns: minmax(110px, auto) 1fr minmax(78px, auto);
  gap: 6px 8px;
  align-items: center;
  margin: 4px 0;
  font-size: 12px;
}
.demo-root .param-row .label { color: #5b6573; font-weight: 500; }
.demo-root .param-row input[type="range"] { width: 100%; min-width: 0; }
.demo-root .param-row .value {
  font-family: 'Menlo', 'Consolas', monospace;
  color: var(--usafa-navy);
  font-weight: 600;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.demo-root .toggle-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-top: 2px;
  font-size: 12px;
}
.demo-root .toggle-row label {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  cursor: pointer;
}
.demo-root .toggle-row input { margin: 0; }

.demo-root .preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 6px 0 4px;
}
.demo-root .btn-row {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  flex-wrap: wrap;
}

/* ------------------------------------------------------------
   Buttons + chips
   ------------------------------------------------------------ */
.demo-root .btn {
  background: var(--usafa-blue);
  color: #fff;
  border: none;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font: inherit;
  font-weight: 500;
  font-size: 12px;
}
.demo-root .btn:hover { background: var(--usafa-navy); }
.demo-root .btn:focus-visible {
  outline: 2px solid var(--usafa-navy);
  outline-offset: 2px;
}

.demo-root .chip {
  background: #e9eef5;
  color: var(--usafa-navy);
  border: 1px solid #d6dfeb;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 3px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  position: relative;
}
.demo-root .chip:hover { background: #d8e2ec; }
.demo-root .chip.active {
  background: var(--usafa-blue);
  color: #fff;
  border-color: var(--usafa-blue);
}
/* Expand chip hit-area to ~44px for finger / Pencil without changing visual size. */
.demo-root .chip::after {
  content: "";
  position: absolute;
  inset: -10px -6px;
}

/* ------------------------------------------------------------
   Plot cards + legends
   ------------------------------------------------------------ */
.demo-root .plot-card {
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 8px 8px 4px;
  margin-bottom: 10px;
}
.demo-root .plot-card svg { display: block; width: 100%; height: auto; }
.demo-root .plot-card h3 {
  margin: 0 0 4px;
  font-size: 11px;
  font-weight: 700;
  color: var(--usafa-navy);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.demo-root .legend-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 11px;
  color: #4a5563;
  margin-top: 2px;
}
.demo-root .legend-strip span::before {
  content: "";
  display: inline-block;
  width: 14px;
  height: 0;
  border-top: 3px solid currentColor;
  margin-right: 5px;
  vertical-align: middle;
}
.demo-root .legend-strip .dashed::before { border-top-style: dashed; }
.demo-root .legend-strip .dot::before {
  border: none;
  width: 7px;
  height: 7px;
  background: currentColor;
  border-radius: 50%;
  margin-right: 5px;
  margin-bottom: -1px;
}
.demo-root .l-truth { color: var(--truth-color); }
.demo-root .l-est   { color: var(--est-color); }
.demo-root .l-meas  { color: var(--meas-color); }
.demo-root .l-bound { color: var(--bound-color); }

/* ------------------------------------------------------------
   Stat cards
   ------------------------------------------------------------ */
.demo-root .stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 4px;
}
.demo-root .stat {
  background: var(--bg-soft);
  border: 1px solid var(--rule);
  border-radius: 5px;
  padding: 5px 8px;
  font-family: 'Menlo', 'Consolas', monospace;
}
.demo-root .stat .lbl {
  font-size: 10px;
  color: #5b6573;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.demo-root .stat .val {
  font-size: 15px;
  font-weight: 700;
  color: var(--usafa-navy);
  font-variant-numeric: tabular-nums;
}
.demo-root .stat .sub {
  font-size: 11px;
  color: #5b6573;
  font-variant-numeric: tabular-nums;
}
.demo-root .stat.ok   .val { color: #1d7a4d; }
.demo-root .stat.warn .val { color: #b35900; }
.demo-root .stat.bad  .val { color: #cf3a3a; }

/* ------------------------------------------------------------
   Animation bar (play / scrub / reset)
   ------------------------------------------------------------ */
.demo-root .anim-bar {
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 6px 10px;
  display: grid;
  grid-template-columns: auto auto 1fr auto auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}
.demo-root .anim-bar .btns { display: flex; gap: 4px; }
.demo-root .anim-bar .speed-chips { display: flex; gap: 4px; }
.demo-root .anim-bar .scrub-row {
  display: flex;
  gap: 8px;
  align-items: center;
  min-width: 0;
}
.demo-root .anim-bar .scrub-row input[type="range"] {
  flex: 1;
  min-width: 0;
}
.demo-root .anim-bar .t-val {
  font-family: 'Menlo', 'Consolas', monospace;
  color: var(--usafa-navy);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  min-width: 70px;
  text-align: right;
}

/* ------------------------------------------------------------
   Mono readout block
   ------------------------------------------------------------ */
.demo-root .readout {
  background: var(--bg-soft);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 8px 10px;
  font-family: 'Menlo', 'Consolas', 'Monaco', monospace;
  font-size: 12px;
  line-height: 1.55;
  margin: 0;
  white-space: pre;
  overflow-x: auto;
}
.demo-root .readout .lbl { color: #5b6573; }
.demo-root .readout .ok  { color: #207144; font-weight: 600; }

/* ============================================================
   Touch / Pencil hit-area helpers (iPad)
   ----------------------------------------------------------
   Draggable SVG handles opt out of the browser's default touch
   gesture (scroll / pinch). Range thumbs grow to 22px for
   fingertip use.
   ============================================================ */
.demo-root .sat-handle,
.demo-root .pin-handle {
  touch-action: none;
}

.demo-root input[type="range"]::-webkit-slider-thumb {
  width: 22px;
  height: 22px;
}
.demo-root input[type="range"]::-moz-range-thumb {
  width: 22px;
  height: 22px;
}

/* ============================================================
   Demo body reset (only fires inside the demo iframe)
   ----------------------------------------------------------
   We can't safely target `html, body` from a file that may be
   pulled into the book's global stylesheet too. Instead we tag
   the demo iframe body via the :has() selector — modern Safari
   / Chrome / Firefox all support it.
   ============================================================ */
body:has(> .demo-root) {
  margin: 0;
  padding: 0;
  background: #fff;
}
