/* The spectrum page (radio_astronomy/spectrum.qmd). Colours and typefaces come from
   theme/rsi.scss (the --rsi-* variables). The scene (_scene.svg) is written by
   tools/spectrum/build.py: its shapes carry their own colours, its labels get theirs
   here. */

/* ---------- The scene ----------
   It keeps a width at which its smallest labels (12 units of 1200) are still 11 px.
   On a narrow screen it scrolls sideways inside its own box, like the other
   diagrams; on a wide one it uses the width of the page. */
.diagram.sp-figure > svg {
  min-width: 1100px;
}

/* The figure stands in .column-screen-inset: without a table of contents (toc: false)
   that is the column that reaches the full width of the page. Above 1400 px the scene
   would grow taller than most screens, so it stops there. */
.diagram.sp-figure {
  max-width: 1400px;
}

/* The scene and the instruments reach over the docked sidebar (the page has no table
   of contents); its edge line would run through them and their captions. This
   stylesheet loads only on this page. */
#quarto-sidebar.docked {
  border-right: 0 !important;  /* Quarto sets the line with !important */
}

/* Labels. `.diagram text` in styles.css sets one style for every diagram; the rules
   below are more specific, so they win over it. */
svg.sp-scene text {
  font-family: var(--rsi-font-head);
  font-size: 12px;
  fill: var(--rsi-cream);
}

/* In space and in the air (night and dusk) */
.sp-scene .sp-t-space {
  font-family: var(--rsi-font-mono);
  letter-spacing: .14em;
  fill: var(--rsi-gold);
}

.sp-scene .sp-t-sat {
  font-size: 13px;
  font-weight: 650;
}

.sp-scene .sp-t-window {
  font-size: 13px;
  font-weight: 750;
  letter-spacing: .14em;
}

.sp-scene .sp-t-scale {
  font-family: var(--rsi-font-mono);
  fill: var(--rsi-soft);
}

/* At the horizon the sky turns to gold and cream: dark text there, on a halo of
   cream so that it stays readable over the dawn and over the cursor line. */
.sp-scene .sp-t-ground,
.sp-scene .sp-t-project {
  fill: var(--rsi-navy);
  paint-order: stroke;
  stroke: var(--rsi-cream);
  stroke-width: 3px;
  stroke-linejoin: round;
}

.sp-scene .sp-t-project {
  font-weight: 700;
}

/* In the band */
.sp-scene .sp-t-band {
  font-weight: 650;
  letter-spacing: .08em;
}

/* On the ground (daylight). The axis labels sit on a halo of the ground colour, so
   the hint lines of the everyday things pass behind them. */
.sp-scene .sp-t-axis,
.sp-scene .sp-t-label {
  font-family: var(--rsi-font-mono);
  fill: var(--rsi-muted);
}

.sp-scene .sp-t-axis {
  paint-order: stroke;
  stroke: var(--rsi-cream);
  stroke-width: 4px;
  stroke-linejoin: round;
}

/* "frequency" and "wavelength" beside the two rows of numbers under the band */
.sp-scene .sp-t-row {
  fill: var(--rsi-muted);
}

.sp-scene .sp-t-thing {
  font-size: 13px;
  font-weight: 600;
  fill: var(--rsi-navy);
}

/* With JavaScript a tap on a satellite, an everyday thing or a project mark moves the
   knob to it and shows its card under the picture. The item tapped last (is-current,
   until the knob moves on) has its name in gold: on the night sky in gold, on the light
   ground and on the cream halo at the horizon in the dark gold for text. */
.sp-js .sp-scene .sp-item {
  cursor: pointer;
}

.sp-scene .sp-item.is-current .sp-t-sat {
  fill: var(--rsi-gold);
}

.sp-scene .sp-item.is-current .sp-t-thing,
.sp-scene .sp-item.is-current .sp-t-project {
  fill: var(--rsi-gold-text);
}

/* The way back to the picture from every text block under it ("Show on the spectrum",
   a link the script adds), and from the strip to the card. The page's header (Quarto's
   navbar, pinned, and on a wide screen the sidebar's toggle under it) stands over the
   top of the window; the picture and the card keep its height (--sp-head, set by the
   script) free above them, with and without reduced motion. */
.sp-js .sp-figure,
.sp-js .sp-card {
  scroll-margin-top: var(--sp-head, 0px);
}

/* The link stands close under its own text, and the next block keeps clear of it. */
.sp-show-line {
  margin-top: -.75rem;
  font-size: .95rem;
}

.sp-js .sp-text {
  margin-bottom: 2.75rem;
}

/* ---------- The knob ----------
   Only with JavaScript (the attribute hidden is removed by the script): a range input
   laid over the band. The script places it so that the centre of its thumb runs along
   the axis and stands over the scene's knob, and gives it its sizes: --sp-thumb-w and
   --sp-thumb-h (the thumb, the part a finger takes hold of), --sp-knob-r (the knob's
   radius as drawn) and --sp-knob-y (where the knob's centre lies in the thumb: the
   thumb starts at the knob's top edge, so the project mark above the knob stays
   tappable). The track is invisible and lets the pointer through, so the marks on the
   band can be tapped and a swipe over the band moves the picture; only the thumb takes
   the pointer. With keyboard focus the slider grows upwards by --sp-ring, the room for
   the focus ring around the knob. */
.sp-js .sp-figure {
  position: relative;  /* the slider lies in the picture's box and scrolls with it */
}

/* On a phone the script moves the picture's box sideways to the knob as the page
   loads. The caption (the box's last paragraph) stands in the same box; it stays at the
   box's left edge, as wide as the box, instead of moving out of view with the scene.
   (As a grid, the box gives the caption the scene's width to move in; cqw is the box's
   own width.) */
@supports (container-type: inline-size) {
  .sp-js .sp-figure {
    display: grid;
    container-type: inline-size;
  }

  .sp-js .sp-figure > p:last-child {
    position: sticky;
    left: 0;
    width: 100cqw;
  }
}

.sp-js .sp-slider {
  --sp-ring: 0px;
  --sp-knob: radial-gradient(circle at 50% calc(var(--sp-knob-y) + var(--sp-ring)),
    var(--rsi-gold) calc(var(--sp-knob-r) - 2.5px),
    var(--rsi-navy) calc(var(--sp-knob-r) - 2px) calc(var(--sp-knob-r) - .5px),
    transparent var(--sp-knob-r));
  /* focused: a gold ring with a navy edge, seen on the navy band and on the light
     ground above it */
  --sp-knob-focus: radial-gradient(circle at 50% calc(var(--sp-knob-y) + var(--sp-ring)),
    var(--rsi-gold) calc(var(--sp-knob-r) - 2.5px),
    var(--rsi-navy) calc(var(--sp-knob-r) - 2px) calc(var(--sp-knob-r) - .5px),
    transparent var(--sp-knob-r) calc(var(--sp-knob-r) + 1.5px),
    var(--rsi-gold) calc(var(--sp-knob-r) + 2px) calc(var(--sp-knob-r) + 4px),
    var(--rsi-navy) calc(var(--sp-knob-r) + 4.5px) calc(var(--sp-knob-r) + 5.5px),
    transparent calc(var(--sp-knob-r) + 6px));
  position: absolute;
  height: calc(var(--sp-thumb-h, 44px) + var(--sp-ring));
  margin: calc(-1 * var(--sp-ring)) 0 0;
  padding: 0;
  border: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  -webkit-tap-highlight-color: transparent;
  pointer-events: none;
  touch-action: pan-y;  /* a sideways drag on the thumb moves the knob */
}

.sp-js .sp-slider:focus-visible {
  --sp-ring: 6px;
  outline: none;  /* the thumb shows the focus */
}

.sp-js .sp-slider::-webkit-slider-runnable-track {
  height: calc(var(--sp-thumb-h, 44px) + var(--sp-ring));
  background: transparent;
  border: 0;
}

.sp-js .sp-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: var(--sp-thumb-w, 32px);
  height: calc(var(--sp-thumb-h, 44px) + var(--sp-ring));
  border: 0;
  border-radius: 0;
  background: var(--sp-knob);
  pointer-events: auto;
  cursor: grab;
}

.sp-js .sp-slider:focus-visible::-webkit-slider-thumb {
  background: var(--sp-knob-focus);
}

.sp-js .sp-slider:active::-webkit-slider-thumb {
  cursor: grabbing;
}

/* the same for Firefox (a rule with an unknown pseudo-element is dropped whole) */
.sp-js .sp-slider::-moz-range-track {
  height: calc(var(--sp-thumb-h, 44px) + var(--sp-ring));
  background: transparent;
  border: 0;
}

.sp-js .sp-slider::-moz-range-progress {
  background: transparent;
}

.sp-js .sp-slider::-moz-range-thumb {
  width: var(--sp-thumb-w, 32px);
  height: calc(var(--sp-thumb-h, 44px) + var(--sp-ring));
  border: 0;
  border-radius: 0;
  background: var(--sp-knob);
  pointer-events: auto;
  cursor: grab;
}

.sp-js .sp-slider:focus-visible::-moz-range-thumb {
  background: var(--sp-knob-focus);
}

.sp-js .sp-slider:active::-moz-range-thumb {
  cursor: grabbing;
}

/* ---------- The instruments ----------
   Written by tools/spectrum/build.py into _instruments.html: the three instruments
   under the explanation of the picture, and the strip. The housings carry their own colours;
   the texts get theirs here. Without JavaScript they show the hydrogen line. */
.sp-instruments {
  max-width: 1400px;  /* as wide as the scene above */
  margin: 0 0 2.4rem;  /* the explanation above brings its own margin */
}

/* One under the other below 700 px; from 700 px the counter and the needle meter
   side by side with the oscilloscope under them, drawn at the same scale; from
   1024 px all three in a row, the oscilloscope wider like its housing. Each layout
   keeps the smallest text on the instruments at 9 px or more (a browser test
   measures it at 360, 820, 1024 and 1440 px). */
.sp-panel {
  display: grid;
  grid-template-columns: minmax(0, 28rem);
  justify-content: center;
  gap: 1.6rem;
  --sp-cap-lines: 2;
}

@media (min-width: 700px) {
  .sp-panel {
    grid-template-columns: 1fr 1fr;
    justify-content: stretch;
    gap: 1.25rem;
    max-width: 50rem;
    margin: 0 auto;
    --sp-cap-lines: 4;
  }

  .sp-panel > .sp-scope {
    grid-column: 1 / -1;
    justify-self: center;
    /* as wide as one column, times the wider housing (360 / 320 units) */
    width: min(100%, calc((100% - 1.25rem) / 2 * 1.125));
  }
}

/* Lines kept under each instrument for the longest sentence (about the ionosphere):
   four while a caption is narrower than about 310 px (two columns up to 720 px,
   three up to 1080 px), three when it is wider; the breakpoints leave some margin.
   One under the other, two lines; a longer sentence there only moves what is
   below it. */
@media (min-width: 760px) {
  .sp-panel {
    --sp-cap-lines: 3;
  }
}

@media (min-width: 1024px) {
  .sp-panel {
    grid-template-columns: 1fr 1fr 1.125fr;
    max-width: none;
    --sp-cap-lines: 4;
  }

  .sp-panel > .sp-scope {
    grid-column: auto;
    justify-self: stretch;
    width: auto;
  }
}

@media (min-width: 1120px) {
  .sp-panel {
    --sp-cap-lines: 3;
  }
}

/* more specific than the theme's  main.content figure  (2rem above and below) */
.sp-panel > .sp-inst {
  margin: 0;
}

.sp-inst > svg {
  display: block;
  width: 100%;
  height: auto;
}

/* The sentence under each instrument. Side by side, every caption keeps room for
   the longest sentence it can show (--sp-cap-lines lines), so that the row does not
   jump while the knob moves; a browser test tries the longest ones. */
.sp-inst > figcaption {
  margin-top: .55rem;
  min-height: calc(var(--sp-cap-lines) * 1.45em);
  font-size: .95rem;
  font-style: normal;  /* the theme sets captions in italics; this is the reading */
  line-height: 1.45;
  color: var(--rsi-navy);
}

.sp-inst text,
.sp-strip text {
  font-family: var(--rsi-font-mono);
}

/* On the housing and on the dark displays */
.sp-i-label {
  font-size: 12px;
  letter-spacing: 1.2px;
  fill: var(--rsi-gold);
}

.sp-i-plate {
  font-size: 10px;
  letter-spacing: 1px;
  fill: var(--rsi-soft);
}

.sp-i-tag {
  font-size: 12.5px;
  letter-spacing: 1px;
  fill: var(--rsi-gold);
}

.sp-i-read {
  font-size: 15px;
  fill: var(--rsi-gold);
}

.sp-i-read.sp-i-small {
  font-size: 11px;
}

/* The oscilloscope's housing is wider (360 units), so it is drawn a little smaller
   where it shares a column with the others. */
.sp-scope .sp-i-label {
  font-size: 12.5px;
}

.sp-scope .sp-i-plate {
  font-size: 11.5px;
  letter-spacing: .5px;
}

/* Seven-segment digits and units: what is not lit stays faintly visible, as on a
   real display. The script moves the class "on". */
.sp-cell > * {
  opacity: .07;
}

.sp-cell > .on {
  opacity: 1;
}

.sp-i-unit {
  font-size: 12px;
  fill: var(--rsi-gold);
  opacity: .16;
}

.sp-i-unit.sp-i-small {
  font-size: 11px;
}

.sp-i-unit.on {
  opacity: 1;
}

/* On the cream dial of the needle meter */
.sp-i-dial {
  font-size: 12px;
  fill: var(--rsi-navy);
}

.sp-i-scale {
  font-size: 11px;
  letter-spacing: .8px;
  fill: var(--rsi-navy);
}

.sp-i-db {
  font-size: 10px;
  fill: var(--rsi-muted);
}

/* ---------- The card ----------
   The text of a tapped item, filled in by the script. Without the script it stays
   hidden (attribute hidden); with it, it is shown from the start but empty, and then
   takes no room, so that aria-live announces the first item tapped. Written into
   _card.html, it stands directly under the scene, above the explanation of the
   picture and the instruments, so that it comes into view where the reader tapped:
   the picture keeps only a small margin and the strip's room under it (see the strip
   below). A satellite's drawing in it is at most 300 px wide, on a night-blue panel like
   the sky it flies in; the text at most about 60 characters. The card is only as wide as
   what it shows. */
.sp-js .sp-figure {
  margin-bottom: calc(.5rem + var(--sp-strip-room));
}

.sp-card {
  width: fit-content;
  max-width: 100%;
  margin: 0 0 1.6rem;
  padding: .8rem 1.2rem 1rem;
  border-radius: 10px;
  background: var(--rsi-cream);
  color: var(--rsi-navy);
}

.sp-js .sp-card:empty {
  margin: 0;
  padding: 0;
  border: 0;
}

/* more specific than the theme's  main.content p  (max-width 42em) */
main.content .sp-card > * {
  max-width: 60ch;
}

.sp-card > :last-child {
  margin-bottom: 0;
}

.sp-card strong {
  font-family: var(--rsi-font-head);
}

.sp-card-art {
  width: min(300px, 100%);
  margin-bottom: .8rem;
  border-radius: 8px;
  background: #0C2340;  /* the night sky of the start page, where the satellites fly */
}

.sp-card-art > svg {
  display: block;
  width: 100%;
  height: auto;
}

/* On a narrow screen the drawing stands above the text, in the order of the card's
   content (which a screen reader follows too); from 700 px on the left, the text beside
   it. */
@media (min-width: 700px) {
  .sp-js .sp-card {
    display: flow-root;
  }

  .sp-card > .sp-card-art {
    float: left;
    margin: .2rem 1.5rem 0 0;
  }

  .sp-card > .sp-card-art ~ * {
    margin-left: calc(300px + 1.5rem);
  }
}

/* ---------- The strip ----------
   Only with JavaScript (the attribute hidden is removed by the script): the three
   instruments in short form at the bottom of the screen, while the scene is in view
   and the large instruments are not. After a tap it names the item, as a link to its
   card: below 1000 px on a line of its own above the instruments (--sp-strip-line),
   from 1000 px on their left. Its height is --sp-strip-h: the drawings, 6 px above and below
   them, the 2 px edge and, while the name shows, its line. The page keeps that much
   room at the bottom when it scrolls to a focused element, so nothing ends up under the
   strip. --sp-strip-room, the room under the picture, is the strip with the name's line:
   the same before and after a tap, so a tap moves nothing on the page. (Room that came
   and went with the strip itself would make the text under the picture jump as the
   picture leaves the screen.) */
:root {
  --sp-strip-art: 44px;
  --sp-strip-pad: 16px;
  --sp-strip-line: 0px;
  --sp-strip-base: calc(var(--sp-strip-art) + 14px + env(safe-area-inset-bottom));
  --sp-strip-room: calc(var(--sp-strip-base) + var(--sp-strip-line));
  --sp-strip-h: var(--sp-strip-base);
}

:root:has(.sp-strip-name:not([hidden])) {
  --sp-strip-h: var(--sp-strip-room);
}

@media (max-width: 999.98px) {
  :root {
    --sp-strip-line: 22px;  /* the name's 18 px line and 4 px under it */
  }
}

@media (max-width: 479.98px) {
  :root {
    --sp-strip-art: 40px;
    --sp-strip-pad: 10px;
  }
}

html.sp-js {
  scroll-padding-bottom: var(--sp-strip-h);
}

.sp-js .sp-strip {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 999;  /* under Quarto's overlay of the opened sidebar on phones (1000) */
  padding: 6px var(--sp-strip-pad) calc(6px + env(safe-area-inset-bottom));
  background: var(--rsi-navy);
  border-top: 2px solid #1B3F66;  /* the edge of a housing; the theme has no variable */
  /* The script adds is-visible while the scene is in view and the large instruments
     are not (stripVisible). Otherwise the strip waits below the edge of the screen,
     out of sight; it slides up and back down. */
  transform: translateY(100%);
  visibility: hidden;
  transition: transform .25s ease-in, visibility 0s linear .25s;
}

.sp-js .sp-strip.is-visible {
  transform: none;
  visibility: visible;
  transition: transform .25s ease-out;
}

@media (prefers-reduced-motion: reduce) {
  .sp-js .sp-strip,
  .sp-js .sp-strip.is-visible {
    transition: none;
  }
}

/* Quarto's "Back to top" button (fixed, 50 px above the bottom) would stand on the
   strip, and lifted above it on the scene; while the strip shows, the button waits. */
html.sp-js:has(.sp-strip.is-visible) #quarto-back-to-top {
  visibility: hidden;
}

/* The name of the item tapped last (the script sets its text), a link to its card. */
.sp-js .sp-strip .sp-strip-name {
  display: block;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto 4px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font: 600 14px/18px var(--rsi-font-head);
  color: var(--rsi-gold);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.sp-js .sp-strip .sp-strip-name:hover {
  color: var(--rsi-cream);
}

.sp-js .sp-strip .sp-strip-name[hidden] {
  display: none;
}

@media (min-width: 1000px) {
  .sp-js .sp-strip .sp-strip-name {
    position: absolute;
    left: calc(var(--sp-strip-pad) + 8px);
    top: 50%;
    max-width: calc(50% - 220px);
    margin: 0;
    transform: translateY(-50%);
  }
}

.sp-strip-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
}

.sp-strip svg {
  display: block;
  height: var(--sp-strip-art);
  width: auto;
}

@media (max-width: 479.98px) {
  .sp-strip-row {
    gap: 6px;
  }
}

/* In the strip all units stand in one place; only the one in use is shown. */
.sp-strip .sp-i-unit {
  font-size: 12px;
}

.sp-js .sp-strip .sp-i-unit:not(.on) {
  opacity: 0;
}

.sp-strip .sp-i-read {
  font-size: 13px;
}

/* ---------- The ghost finger ----------
   A fingertip that shows the knob can be dragged (spectrum.js, introFrame): the script
   puts it on the knob and sets its scale and opacity frame by frame. While it holds the
   knob, the knob wears the ring of keyboard focus (.sp-held). A cream disc, see-through,
   with a shadow of the night colour: the theme's colours, mixed with transparent. */
.sp-js .sp-finger {
  position: absolute;
  left: 0;
  top: 0;
  width: 30px;
  height: 30px;
  margin: -15px 0 0 -15px;
  box-sizing: border-box;
  border: 1.5px solid color-mix(in srgb, var(--rsi-cream) 90%, transparent);
  border-radius: 50%;
  background: color-mix(in srgb, var(--rsi-cream) 45%, transparent);
  box-shadow: 0 3px 10px color-mix(in srgb, var(--rsi-night) 50%, transparent);
  opacity: 0;
  pointer-events: none;
}

.sp-js .sp-slider.sp-held {
  --sp-ring: 6px;
}

.sp-js .sp-slider.sp-held::-webkit-slider-thumb {
  background: var(--sp-knob-focus);
}

.sp-js .sp-slider.sp-held::-moz-range-thumb {
  background: var(--sp-knob-focus);
}

.sp-i-strip-label {
  font-size: 11px;
  fill: var(--rsi-soft);
}

/* ---------- On paper ----------
   What works only on a screen stays off the page: the strip (fixed to the bottom of the
   screen, it would stand on every printed page), the hint on how to drag and tap, the
   slider (the knob of the picture still marks the frequency), the "Show on the
   spectrum" links and the ghost finger. */
@media print {
  .sp-js .sp-strip,
  .sp-js .sp-hint,
  .sp-js .sp-slider,
  .sp-js .sp-show-line,
  .sp-js .sp-finger {
    display: none;
  }
}
