/* The Relecture's bar: replay.js builds its markup and timeline.js draws its bands. Loaded after app.css, whose tokens
   (--panel, --tap, --mark-*, --clip, --now, --dock ...) and button styles it builds on; app.css keeps what is the camera's
   (the picture's width while a recording plays) and the list of passages under the bar.
   The cascade is the order here: the base rules, then what a window of 60rem or more adds (docking), what a narrower one
   changes, and what a finger needs, last, as it was when these rules were app.css's own. */

/* Relecture: the time under the line, then the bands (timeline.js draws them), then play and the date to jump to. */
/* Its state is three attributes, set by app.js and read here and nowhere else:
   data-mode    live (only the bands, the line on now) or replay (a recording plays),
   data-layout  column (the camera's column) or docked (across the window's bottom, where the style sheet allows),
   data-clip    on the controls: whether a piece can be downloaded. */
/* A grid so that, docked, the same parts can sit side by side. Here each has the whole width, one under the other.
   It is also a container: what fits on a row follows its own width, not the window's (a column, or the window). */
.replay { display: grid; grid-template-columns: minmax(0, 1fr) auto; margin-top: .5rem; container: replay / inline-size; }
.replay > * { grid-column: 1 / -1; min-width: 0; }
/* The time and the buttons that change the whole view share the first row: the time has what they leave. */
.replay > .replay-clock { grid-area: 1 / 1; }
.replay > .replay-actions { grid-area: 1 / 2; display: flex; align-items: center; gap: .5rem; margin: 0 0 .25rem .5rem; }
.replay-actions button { width: auto; min-height: 2.25rem; padding: .25rem .75rem; font-size: .875rem; }
/* The way back to the live picture is a way out, not the main thing to press: an ordinary button, its dot the colour
   of the line that follows now (not red: that is an alarm's mark on the bands). */
.replay-live .icon { color: var(--now); }
/* Only where there is more width to give: see the window of 60rem or more below. */
.replay-actions .replay-wide { display: none; }
.replay-clock { margin: 0 0 .25rem; font-size: 1.125rem; font-weight: 700; font-variant-numeric: tabular-nums; text-align: center; }
/* What happened under the line, if anything did: always a line high, so the buttons below never jump. */
.replay-event { min-height: 1.45em; margin: .25rem 0 0; text-align: center; }
/* Previous event, play, next event, speed; the date to jump to has the row below to itself. */
.replay-controls { display: grid; grid-template-columns: auto 1fr auto auto; gap: .5rem; margin-top: .25rem; }
.replay-controls select {
  min-height: 3rem;
  padding: .5rem;
  border: 1px solid var(--field-line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  font: inherit;
}
.replay-controls button { width: auto; min-width: 3.5rem; }
.replay-controls #replay-play { width: 100%; }
/* Not in a recording: the bands, the line on now and the ways to jump. Nothing to play, pause, speed up or cut, and
   no live picture to go back to. */
/* Nor the filter: in the live picture the feed's own is the one to use (the same state), and a second copy made the
   docked bar taller and the screen say everything twice. In a recording it comes back, as the legend of the bands. */
.replay[data-mode="live"] > .replay-filter,
.replay[data-mode="live"] > .replay-legend, .replay[data-mode="live"] > .replay-export, .replay[data-mode="live"] #replay-live,
.replay[data-mode="live"] #replay-play, .replay[data-mode="live"] #replay-speed, .replay[data-mode="live"] #replay-clip { display: none; }
.replay[data-mode="live"] > .replay-controls { grid-template-columns: auto auto 1fr; }
.replay[data-mode="live"] .replay-controls .replay-jump { grid-column: auto; }
/* A date field is as wide as its widest date unless told it may shrink: on a phone it pushed past the frame. */
.replay-controls .replay-jump { grid-column: 1 / -1; min-width: 0; }
/* The date field and its French words over it (replay.js): the field's own text is hidden until it has the focus, when
   the words go and the field is there to be typed in. Its calendar icon stays: it is not text. */
.replay-jump { position: relative; display: grid; }
.replay-jump > input { width: 100%; min-width: 0; }
.replay-jump > input:not(:focus) { color: transparent; }
.replay-jump > input:focus + .replay-jump-text { display: none; }
.replay-jump-text { position: absolute; inset: 0 2.5rem 0 0; display: flex; align-items: center; padding-inline: .75rem; overflow: hidden; color: var(--text); font-variant-numeric: tabular-nums; white-space: nowrap; pointer-events: none; }
/* Where a piece can be downloaded, its button ends the date's row, under the speed. */
.replay-controls[data-clip="on"] .replay-jump { grid-column: 1 / 4; }
/* With the room (a tablet, a column wider than a phone's two): the transport and the date are one row, not two. */
@container replay (min-width: 44rem) {
  .replay[data-mode="replay"] > .replay-controls { grid-template-columns: auto minmax(8rem, 1fr) auto auto minmax(13rem, 16rem); }
  .replay[data-mode="replay"] > .replay-controls[data-clip="on"] { grid-template-columns: auto minmax(8rem, 1fr) auto auto minmax(13rem, 16rem) auto; }
  .replay[data-mode="replay"] .replay-controls .replay-jump, .replay[data-mode="replay"] .replay-controls[data-clip="on"] .replay-jump { grid-column: auto; }
}

/* A piece to download: its two ends, what is picked, then the download. One under the other here, a row when docked. */
.replay-export { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; align-items: center; margin-top: .5rem; }
.replay-export p { grid-column: 1 / -1; margin: 0; text-align: center; }

/* Its own width decides where the zoom buttons go, not the window's: docked, it has the window; else, a column. */
.timeline { display: grid; gap: 2px; border-radius: var(--radius); overflow: hidden; background: var(--bg); user-select: none; -webkit-user-select: none; container-type: inline-size; }
.timeline:focus-visible { outline: var(--focus); outline-offset: 2px; }
/* A finger moving sideways moves time; up or down, it still scrolls the page. */
.timeline-band { display: block; width: 100%; cursor: ew-resize; touch-action: pan-y; }
/* Over a mark (timeline.js sets it): a click opens that event, so the hand, not the drag arrows. */
.timeline-band[data-over="mark"] { cursor: pointer; }
.timeline-minutes { height: 4rem; }
.timeline-hours { height: 2.75rem; }
.timeline-days { height: 2.5rem; }
/* Each band's zoom, over its right end: the future side, where there is the least to hide. No label is written
   under them (timeline.js). */
.timeline-row { position: relative; }
.timeline-zoom { position: absolute; top: 2px; right: 2px; display: flex; gap: 2px; }
.timeline-zoom button {
  width: 2rem;
  min-height: 0;
  height: 2rem;
  margin: 0;
  padding: 0;
  border-radius: var(--radius-sm);
  --fill: rgb(20 24 29 / .85);
  /* Quiet until pointed at: six of them stand beside three bands, and the bands are what is looked at. */
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
}
@media (hover: hover) {
  .timeline-zoom button:hover:not(:disabled) { color: var(--text); }
}
/* The ring inside the button: the band clips what is outside it (.timeline hides its overflow). */
.timeline-zoom button:focus-visible { outline-offset: -2px; }
/* With the width for it (the same 600 px from which the bands show more columns), the buttons leave the band and
   stand beside it, as high as it is: nothing of the band is under them. */
@container (min-width: 600px) {
  .timeline-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px; }
  .timeline-zoom { position: static; }
  .timeline-zoom button { height: auto; border-radius: 0; --fill: var(--panel); }
}

/* The feed's filter beside the bands (feed.js builds it): the stations, then a chip for each kind, which is also what
   each colour on the bands is. Compact: a row of small chips, the kind's colour before its name. */
.replay-filter { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: .25rem .5rem; margin: .375rem 0 0; font-size: .8125rem; }
.replay-filter .events-station { flex: none; }
.replay-filter .events-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: .125rem .25rem; margin: 0; }
.replay-filter .feed-chip .n { display: none; }
/* The ticket looked up and the piece picked, only while there is one: they are not kinds, so they are not switches. */
.replay-legend { display: flex; flex-wrap: wrap; justify-content: center; gap: .125rem .25rem; margin: .125rem 0 0; font-size: .8125rem; }
.replay-legend:not(:has(> :not([hidden]))) { display: none; }
.replay-legend > * { white-space: nowrap; padding: .125rem .5rem; }
.replay-legend span::before { content: ""; display: inline-block; width: .25rem; height: .875rem; margin-right: .375rem; border-radius: 1px; vertical-align: -.125rem; }
.legend-ticket::before { background: var(--mark-ticket); }
/* Back to the history of the ticket looked up: on one column it is far below the Relecture. */
.replay > .replay-history { width: auto; justify-self: center; min-height: 2.5rem; margin: .375rem 0 0; padding: .25rem .75rem; font-size: .875rem; }
.replay-legend .legend-clip::before { width: .875rem; background: var(--clip); opacity: .6; }

/* A window of 60rem or more: the history is beside the bar, and the bands can be docked across the window's bottom. */
@media (min-width: 60rem) {
  /* The history is beside the Relecture here: no way back to it is needed. */
  .replay > .replay-history { display: none; }

  /* The Relecture's bands across the whole window, docked at its bottom, when asked: the time and what happened
     there on one row, the bands, then the buttons and the date on one row. */
  .replay-actions .replay-wide { display: block; }
  .replay[data-layout="docked"] {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 50;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    margin: 0;
    padding: .5rem max(1.5rem, env(safe-area-inset-right)) max(.75rem, env(safe-area-inset-bottom)) max(1.5rem, env(safe-area-inset-left));
    border-top: 1px solid var(--line);
    background: var(--bg);
    box-shadow: 0 -.5rem 1.5rem rgba(0, 0, 0, .5);
  }
  .replay[data-layout="docked"] > .replay-clock { grid-area: 1 / 2; margin: 0 1rem .25rem; }
  .replay[data-layout="docked"] > .replay-actions { grid-area: 1 / 3; justify-self: end; margin-left: 0; }
  .replay[data-layout="docked"] > .replay-event { grid-area: 1 / 1; margin: 0 0 .25rem; text-align: left; }
  .replay[data-layout="docked"] > .replay-controls { grid-template-columns: auto minmax(10rem, 22rem) auto auto minmax(13rem, 18rem); justify-content: center; }
  .replay[data-layout="docked"] > .replay-controls[data-clip="on"] { grid-template-columns: auto minmax(10rem, 22rem) auto auto minmax(13rem, 18rem) auto; }
  /* In the live picture the docked bar is kept low: the buttons, the clock and the fold button on one row, then the bands. */
  .replay[data-layout="docked"][data-mode="live"] > .replay-controls { grid-area: 1 / 1; grid-template-columns: auto auto minmax(12rem, 16rem); justify-content: start; margin: 0 0 .25rem; }
  .replay[data-layout="docked"][data-mode="live"] > .replay-event { display: none; }
  .replay[data-layout="docked"][data-mode="live"] .replay-controls button, .replay[data-layout="docked"][data-mode="live"] .replay-controls input { min-height: 2.25rem; padding-block: .125rem; }
  .replay[data-layout="docked"][data-mode="live"] .timeline-minutes { height: 2.5rem; }
  .replay[data-layout="docked"][data-mode="live"] .timeline-hours { height: 1.75rem; }
  .replay[data-layout="docked"][data-mode="live"] .timeline-days { height: 1.5rem; }
  .replay[data-layout="docked"] .replay-controls .replay-jump, .replay[data-layout="docked"] .replay-controls[data-clip="on"] .replay-jump { grid-column: auto; }
  .replay[data-layout="docked"] > .replay-export { grid-template-columns: auto auto minmax(0, 1fr) auto auto; margin-top: .25rem; }
  .replay[data-layout="docked"] .replay-export button { width: auto; }
  .replay[data-layout="docked"] .replay-export #export-summary { grid-column: auto; text-align: left; }
  .replay[data-layout="docked"] .timeline-minutes { height: 3.5rem; }
  .replay[data-layout="docked"] .timeline-hours { height: 2.25rem; }
  .replay[data-layout="docked"] .timeline-days { height: 2rem; }
}

/* A narrower window (a phone, a tablet upright). */
@media (max-width: 59.99rem) {
  /* The bands sit between the camera and everything else. While nothing is replayed only the minutes show, under
     the clock and over the ways to jump: the hours and the days come with the Relecture. The bands lay themselves
     out again when their box changes (timeline.js), so nothing else is needed. */
  .replay[data-mode="live"] .timeline-row:nth-child(n+2) { display: none; }

  /* In the live picture the row of actions would hold nothing (no Direct, no width to change): no gap for it. */
  .replay[data-mode="live"] > .replay-actions { display: none; }
}

/* Under a finger the small buttons grow to what a finger needs (--tap); under a mouse they keep the room they save. */
@media (pointer: coarse) {
  .replay > .replay-history, .replay-actions button, .replay-legend button { min-height: var(--tap); }
  /* A band's zoom buttons take the band's whole height, and are as wide as a finger, with a finger's room between them. */
  .timeline-zoom { bottom: 2px; gap: .5rem; }
  .timeline-zoom button { width: var(--tap); height: auto; }
  /* Docked in the live picture the bar is kept low under a mouse; a finger still gets its 44 px. */
  .replay[data-layout="docked"][data-mode="live"] .replay-controls button, .replay[data-layout="docked"][data-mode="live"] .replay-controls input { min-height: var(--tap); }
}
