/* ==========================================================================
   Card viewer demonstrations

   The little working recreations on the card viewer page. They are not the
   viewer: they are a handful of invented readings and the same idea, small
   enough to sit inside a paragraph of prose.

   Reads semantic tokens only. No hex value appears in this file and none may
   be added.

   Unlayered on purpose. tokens.css declares the cascade layers and this file
   is loaded from the page body rather than the shared head, so leaving it out
   of a layer is what keeps it winning over components.css without a single
   !important.
   ========================================================================== */

/* --------------------------------------------------------------------------
   The five bands, derived from the three glucose tokens and nothing else.

   The product has three signal colours. A range sheet has five bands. Rather
   than invent two more colours, the two outer bands are mixes of the two they
   sit beyond, so an urgent reading reads as "further along the same axis"
   rather than as a new idea.
   -------------------------------------------------------------------------- */
.vdemo {
  --vd-vlow:  var(--glucose-low);
  --vd-low:   color-mix(in srgb, var(--glucose-low) 45%, var(--glucose-high));
  --vd-ok:    var(--glucose-ok);
  --vd-high:  var(--glucose-high);
  /* Mixing the top band the same way the bottom one is mixed produced two
     near-identical oranges, so "a bit low" and "needs attention, high" were the
     same colour in the legend. The deep orange is the one token on the site
     that is already darker than both and still reads as the far end of the
     amber axis. */
  --vd-vhigh: var(--signal-orange);

  position: relative;
  margin-top: var(--step-6);
  padding: var(--step-5);
  padding-bottom: var(--step-7);
  background: var(--color-surface-alt);
  border: var(--hairline) solid var(--color-border);
  border-radius: var(--radius-card);
}

/* The corner stamp. It says what the box is once, quietly, so the prose never
   has to stop and explain that this one is a recreation. */
.vdemo::after {
  content: 'DEMO';
  position: absolute;
  right: var(--step-4);
  bottom: var(--step-3);
  font-family: var(--font-mono);
  font-size: var(--size-2xs);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--color-text-faint);
  opacity: 0.55;
  pointer-events: none;
}

@media (min-width: 48rem) {
  .vdemo { padding: var(--step-6); padding-bottom: var(--step-7); }
}

/* --------------------------------------------------------------------------
   The enclosure

   A bezel around a screen. The rule the rest of this block exists to keep: the
   sheen, the chamfer and the lamp all live on the BEZEL. Nothing at all is
   drawn over the active display area, because a reflection over a glucose
   reading sits on the one thing the box is for.
   -------------------------------------------------------------------------- */
.vd-enclosure {
  position: relative;
  isolation: isolate;
  padding: var(--step-4);
  padding-top: var(--step-6);
  border-radius: 14px;
  background:
    linear-gradient(157deg, rgba(216, 232, 255, 0.10) 0, transparent 46%, rgba(0, 0, 0, 0.22) 100%),
    linear-gradient(180deg, var(--sk-metal-hi) 0, var(--sk-metal) 22%, var(--sk-metal-lo) 100%);
  box-shadow: var(--sk-bevel), var(--sk-lift);
  /* The screen inside stops growing at the device's own logical width, so a
     stretched enclosure is bezel with nothing behind it: half a metre of it at
     the widest layout. The box shrinks to what it contains and centres. */
  inline-size: fit-content;
  margin-inline: auto;
}

/* Below this the screen is the one filling the width, and a fit-content box
   around it would leave the enclosure narrower than the column it sits in. */
@media (max-width: 37.5rem) {
  .vd-enclosure { inline-size: 100%; }
}

/* The chamfer, on the bezel only: it stops at the screen's edge because the
   screen paints over it. */
.vd-enclosure::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 1px rgba(216, 232, 255, 0.09);
  background: linear-gradient(180deg, rgba(216, 232, 255, 0.12), transparent 20%);
  pointer-events: none;
}

/* The status lamp, in a recessed socket on the bezel. */
.vd-lamp {
  position: absolute;
  top: calc(var(--step-3) + 2px);
  right: var(--step-4);
  z-index: 2;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--color-accent);
  box-shadow:
    0 0 4px var(--color-accent),
    0 0 12px var(--color-glow-strong),
    inset 0 -1px 2px rgba(0, 0, 0, 0.5),
    0 0 0 3px rgba(0, 0, 0, 0.55);
}

/* Roughly a third of a hertz, and held steady when motion is unwelcome. */
@media (prefers-reduced-motion: no-preference) {
  .vd-lamp { animation: vd-breathe 3.2s ease-in-out infinite; }
}

@keyframes vd-breathe {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.55; }
}

/* The active display area. Recessed, near-black, and the topmost thing in the
   enclosure's stacking context. */
.vd-screen {
  position: relative;
  z-index: 1;
  padding: var(--step-4);
  border-radius: 8px;
  background: var(--sk-glass);
  box-shadow: var(--sk-recess);
}

/* Only a raster upscale needs this, and there is none in these demonstrations
   today. It is here so one added later is crisp rather than smeared. */
.vd-screen img { image-rendering: pixelated; }

.vd-screen-face {
  display: grid;
  place-items: center;
  /* Scales by ratio, and stops shrinking at the device's own logical width
     rather than carrying on down into an unreadable strip. */
  aspect-ratio: 4 / 3;
  min-width: min(320px, 100%);
  max-height: 26rem;
}

/* --------------------------------------------------------------------------
   The state line

   The current state of the demonstration in words, beside the frame rather
   than inside it. It is the equivalent of looking at the screen.
   -------------------------------------------------------------------------- */
.vd-state {
  margin-top: var(--step-4);
  font-size: var(--size-xs);
  line-height: var(--leading-body);
  color: var(--color-text-muted);
}

/* --------------------------------------------------------------------------
   The control panel

   Visually separate and deliberately flat, so it reads as a set of web
   controls sitting under an instrument rather than as part of one.
   -------------------------------------------------------------------------- */
.vd-panel {
  margin-top: var(--step-5);
  padding: var(--step-4);
  background: var(--color-page);
  border: var(--hairline) solid var(--color-border);
  border-radius: var(--radius-sm);
}

.vd-slider { display: flex; align-items: center; gap: var(--step-3); }

.vd-value {
  min-width: 3ch;
  font-family: var(--font-mono);
  font-size: var(--size-sm);
  color: var(--color-text);
  text-align: right;
}

.vd-panel input[type='range'] {
  flex: 1 1 auto;
  min-width: 0;
  height: 1.5rem;
  appearance: none;
  background: transparent;
  cursor: pointer;
}

.vd-panel input[type='range']::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--color-surface-alt);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.8);
}

.vd-panel input[type='range']::-moz-range-track {
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--color-surface-alt);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.8);
}

.vd-panel input[type='range']::-webkit-slider-thumb {
  appearance: none;
  margin-top: -7px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid var(--sk-metal-deep);
  background: linear-gradient(180deg, #9aa5b7 0%, #6b7688 45%, #39435a 100%);
  box-shadow: 0 1px 0 rgba(216, 232, 255, 0.16), 0 2px 5px rgba(0, 0, 0, 0.7);
}

.vd-panel input[type='range']::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid var(--sk-metal-deep);
  background: linear-gradient(180deg, #9aa5b7 0%, #6b7688 45%, #39435a 100%);
  box-shadow: 0 1px 0 rgba(216, 232, 255, 0.16), 0 2px 5px rgba(0, 0, 0, 0.7);
}

.vd-panel input[type='range']:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
  border-radius: var(--radius-pill);
  box-shadow: 0 0 0 4px var(--color-glow);
}

/* --------------------------------------------------------------------------
   Preset keycaps
   -------------------------------------------------------------------------- */
.vd-presets {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--step-3);
  margin-top: var(--step-5);
}

.vd-presets-label {
  font-family: var(--font-mono);
  font-size: var(--size-2xs);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--color-text-faint);
}

.vd-key {
  min-height: 2.25rem;
  padding: var(--step-2) var(--step-4);
  font: inherit;
  font-size: var(--size-xs);
  font-weight: 600;
  color: var(--color-text);
  cursor: pointer;
  border: var(--hairline) solid var(--sk-metal-deep);
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, var(--sk-metal-hi) 0, var(--sk-metal-lo) 100%);
  box-shadow:
    inset 0 1px 0 rgba(216, 232, 255, 0.18),
    0 1px 2px rgba(0, 0, 0, 0.6),
    0 3px 8px rgba(0, 0, 0, 0.45);
}

@media (prefers-reduced-motion: no-preference) {
  .vd-key { transition: transform var(--dur-fast) var(--ease-out); }
}

.vd-key:active {
  transform: translateY(2px);
  box-shadow: inset 0 3px 7px rgba(0, 0, 0, 0.75);
}

/* Backlit when it is the set currently loaded. The pressed state carries a
   word and a border as well as the light. */
.vd-key[aria-pressed='true'] {
  color: var(--color-accent);
  border-color: var(--color-accent);
  box-shadow: inset 0 1px 0 rgba(216, 232, 255, 0.18), 0 0 14px var(--color-glow);
}

.vd-key:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
}

/* Under a laptop width the panel is one column of full-width controls. */
@media (max-width: 50rem) {
  .vd-controls { flex-direction: column; align-items: stretch; }
  .vd-control { max-width: none; }
  .vd-key { flex: 1 1 auto; }
}

@media (forced-colors: active) {
  .vd-enclosure, .vd-screen, .vd-panel, .vd-key { border: 1px solid; box-shadow: none; }
  .vd-enclosure::before { display: none; }
}

.vdemo-title {
  font-family: var(--font-mono);
  font-size: var(--size-2xs);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--color-text-faint);
  margin-bottom: var(--step-4);
}

/* --------------------------------------------------------------------------
   Controls
   -------------------------------------------------------------------------- */
.vd-controls {
  display: flex;
  flex-wrap: wrap;
  gap: var(--step-4);
  margin-top: var(--step-5);
}

.vd-control {
  display: flex;
  flex-direction: column;
  gap: var(--step-2);
  /* Capped rather than stretched. A number box that grows to half the width of
     a laptop reads as a search field, not as a threshold. */
  flex: 1 1 7rem;
  min-width: 7rem;
  max-width: 11rem;
}

.vd-control label {
  font-size: var(--size-xs);
  color: var(--color-text-muted);
}

.vdemo .vd-swatch {
  display: inline-block;
  width: 0.625rem;
  height: 0.625rem;
  border-radius: 50%;
  margin-right: var(--step-2);
  vertical-align: baseline;
}

.vd-control input {
  width: 100%;
  padding: var(--step-2) var(--step-3);
  font: inherit;
  font-family: var(--font-mono);
  font-size: var(--size-sm);
  color: var(--color-text);
  background: var(--color-page);
  border: var(--hairline) solid var(--color-border-strong);
  border-radius: var(--radius-input);
}

.vd-control input:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
}

.vd-units {
  margin-top: var(--step-4);
  font-family: var(--font-mono);
  font-size: var(--size-2xs);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--color-text-faint);
}

/* --------------------------------------------------------------------------
   The one-day timeline
   -------------------------------------------------------------------------- */
.vd-chart {
  display: block;
  width: 100%;
  height: auto;
  background: transparent;
  touch-action: pan-y;
}

.vd-chart:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
}

.vd-band { fill: var(--vd-ok); opacity: 0.1; }
.vd-gridline { stroke: var(--color-border); stroke-width: 1; }
.vd-limit { stroke: var(--color-text-faint); stroke-width: 1; stroke-dasharray: 6 6; opacity: 0.7; }

.vd-seg { fill: none; stroke-width: 3.5; stroke-linecap: round; stroke-linejoin: round; }
.vd-b-vlow  { stroke: var(--vd-vlow); }
.vd-b-low   { stroke: var(--vd-low); }
.vd-b-ok    { stroke: var(--vd-ok); }
.vd-b-high  { stroke: var(--vd-high); }
.vd-b-vhigh { stroke: var(--vd-vhigh); }

.vd-cursor-line { stroke: var(--color-text-faint); stroke-width: 1; }
.vd-cursor-dot { stroke: var(--color-page); stroke-width: 3; }
.vd-f-vlow  { fill: var(--vd-vlow); }
.vd-f-low   { fill: var(--vd-low); }
.vd-f-ok    { fill: var(--vd-ok); }
.vd-f-high  { fill: var(--vd-high); }
.vd-f-vhigh { fill: var(--vd-vhigh); }

/* Hour labels live in HTML rather than inside the drawing. Text set in viewBox
   units is legible on a laptop and roughly six pixels tall on a phone, which is
   the whole reason this row exists. */
.vd-hours {
  display: flex;
  justify-content: space-between;
  margin-top: var(--step-2);
  font-family: var(--font-mono);
  font-size: var(--size-2xs);
  color: var(--color-text-faint);
}

/* The readout doubles as the tooltip and as the live region a keyboard reader
   hears, so there is only ever one thing to keep correct. */
.vd-readout {
  display: flex;
  align-items: baseline;
  gap: var(--step-3);
  margin-top: var(--step-4);
  min-height: 2rem;
  font-family: var(--font-mono);
  font-size: var(--size-sm);
  color: var(--color-text-muted);
}

.vd-readout strong {
  font-family: var(--font-display);
  font-size: var(--size-xl);
  font-weight: 700;
  line-height: 1;
}

.vd-t-vlow  { color: var(--vd-vlow); }
.vd-t-low   { color: var(--vd-low); }
.vd-t-ok    { color: var(--vd-ok); }
.vd-t-high  { color: var(--vd-high); }
.vd-t-vhigh { color: var(--vd-vhigh); }

/* --------------------------------------------------------------------------
   Time in range
   -------------------------------------------------------------------------- */
.vd-bar {
  display: flex;
  width: 100%;
  height: 2.75rem;
  overflow: hidden;
  border-radius: var(--radius-pill);
  background: var(--color-page);
}

.vd-bar > span {
  display: block;
  height: 100%;
  min-width: 0;
}

.vd-s-vlow  { background: var(--vd-vlow); }
.vd-s-low   { background: var(--vd-low); }
.vd-s-ok    { background: var(--vd-ok); }
.vd-s-high  { background: var(--vd-high); }
.vd-s-vhigh { background: var(--vd-vhigh); }

.vd-legend {
  display: grid;
  gap: var(--step-2) var(--step-5);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 17rem), 1fr));
  margin-top: var(--step-5);
  font-size: var(--size-sm);
  color: var(--color-text-muted);
}

.vd-legend li { display: flex; align-items: center; gap: var(--step-2); }
.vd-legend .vd-swatch { flex: none; }
.vd-legend .vd-pct {
  margin-left: auto;
  font-family: var(--font-mono);
  white-space: nowrap;
  color: var(--color-text);
}
.vd-legend .vd-range {
  font-family: var(--font-mono);
  white-space: nowrap;
  font-size: var(--size-2xs);
  color: var(--color-text-faint);
}

/* --------------------------------------------------------------------------
   The summary card
   -------------------------------------------------------------------------- */
.vd-figures {
  display: grid;
  gap: var(--step-4);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 8rem), 1fr));
}

.vd-figure {
  padding: var(--step-4);
  background: var(--color-page);
  border-radius: var(--radius-sm);
}

.vd-figure dt {
  font-family: var(--font-mono);
  font-size: var(--size-2xs);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--color-text-faint);
}

.vd-figure dd {
  margin: var(--step-2) 0 0;
  font-family: var(--font-display);
  font-size: var(--size-xl);
  font-weight: 700;
  line-height: 1;
  /* No colour here on purpose. The band classes carry it, and a colour set on
     the element would outrank them. */
}

.vd-figure .vd-sub {
  display: block;
  margin-top: var(--step-2);
  font-family: var(--font-body);
  font-size: var(--size-xs);
  font-weight: 400;
  color: var(--color-text-faint);
}

/* --------------------------------------------------------------------------
   The big-number face, for the spare-monitor section
   -------------------------------------------------------------------------- */
.vd-face {
  display: grid;
  place-items: center;
  gap: var(--step-3);
  padding: var(--step-6) var(--step-4);
  background: var(--color-page);
  border-radius: var(--radius-sm);
  text-align: center;
}

.vd-face-value {
  display: flex;
  align-items: center;
  gap: var(--step-4);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(3.5rem, 18vi, 7rem);
  line-height: 0.9;
  letter-spacing: var(--tracking-tight);
}

.vd-face-arrow { font-size: 0.5em; font-weight: 400; }

.vd-face-meta {
  font-family: var(--font-mono);
  font-size: var(--size-2xs);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--color-text-faint);
}

/* Nothing here animates, so there is no reduced version worth keeping. This
   only removes the one colour transition. */
@media (prefers-reduced-motion: reduce) {
  .vd-bar > span, .vd-seg { transition: none; }
}

/* --------------------------------------------------------------------------
   Flat again, to match the home page.

   The demonstration boxes, the enclosure and the fifteen preset keys had all
   become gradient plates, which is a treatment the home page uses nowhere. The
   screen inside the enclosure is untouched: it is the one thing here that is
   meant to read as a display.

   The selectors are doubled because the surfaces sheet loaded after this one
   owns the same single-class rules.
   -------------------------------------------------------------------------- */
.vdemo.vdemo {
  background-image: none;
  background-color: var(--color-surface-alt);
  border: var(--hairline) solid var(--color-border);
  box-shadow: none;
}

.vd-enclosure.vd-enclosure {
  background-image: none;
  background-color: var(--color-surface-high);
  border: var(--hairline) solid var(--color-border);
  box-shadow: none;
}

.vd-enclosure.vd-enclosure::before { content: none; }

.vd-key.vd-key {
  background-image: none;
  background-color: var(--color-surface-high);
  border: var(--hairline) solid var(--color-border-strong);
  box-shadow: none;
  text-shadow: none;
}

.vd-key.vd-key:active { box-shadow: none; }

.vd-key.vd-key[aria-pressed='true'] {
  color: var(--color-accent);
  border-color: var(--color-accent);
  box-shadow: none;
}

/* --------------------------------------------------------------------------
   The narrowest screens.

   At 320 the three nested paddings - demo box, bezel, screen - left the legend
   a 123px column, and its percentage sat outside it. The paddings give most of
   that back and the legend row is allowed to take two lines, so nothing is
   clipped. The hour labels drop to three: five of them met edge to edge with
   no gap at all, which reads as one smear of digits rather than an axis.
   -------------------------------------------------------------------------- */
@media (max-width: 22.5rem) {
  .vdemo.vdemo { padding: var(--step-3); padding-bottom: var(--step-6); }
  .vd-enclosure.vd-enclosure { padding: var(--step-3); padding-top: var(--step-5); }
  .vd-screen.vd-screen { padding: var(--step-3); }

  .vd-legend li { flex-wrap: wrap; }
  .vd-legend .vd-pct { margin-left: auto; }

  .vd-hours > :nth-child(2),
  .vd-hours > :nth-child(4) { display: none; }
}
