/*
 * Play in the new room (room2-play.js, room2-caption.js): the caption under the picture while a play
 * runs. The segmented bar, the card (opening, a step, the end), the controls. Colours are the site's
 * tokens (css/site.css), so night mode follows them; a story's colour comes as --r2p-c from the stage.
 */
.r2p {
  --r2p-c: var(--accent);
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px var(--gutter, 20px) 16px;
  background: var(--surface);
  color: var(--text);
  border-top: 1px solid var(--border);
}

/* the bar: one segment a step, filling as the step holds */
.r2p-bar { display: flex; gap: 6px; }
.r2p-seg {
  flex: 1 1 0;
  height: 3px;
  border-radius: 2px;
  background: var(--border);
  overflow: hidden;
}
.r2p-seg > i { display: block; height: 100%; width: 0; background: var(--text); }
.r2p-seg.r2p-now { background: color-mix(in srgb, var(--text) 32%, var(--border)); }   /* the current step, filled or not */

/* the card */
/* the card is as tall as its words, the text right under the title; the box keeps one height so the controls stay put */
.r2p-card { min-height: 0; }
.r2p-controls { margin-top: auto; }
.r2p-in { display: flex; flex-direction: column; gap: 8px; }
.r2p-kicker {
  margin: 0;
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0 2px;
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
  line-height: 1.35;
}
.r2p-dot {
  flex: none;
  align-self: center;
  width: 10px;
  height: 10px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--r2p-c);
}
.r2p-name { color: var(--r2p-c); font-weight: 700; }
.r2p-again { color: var(--text); font-weight: 700; }
.r2p-sep, .r2p-when { color: var(--muted); }
.r2p-head {
  margin: 0;
  font-size: 22px;
  line-height: 1.25;
  font-weight: 650;
  letter-spacing: -0.01em;
  color: var(--text);
  text-wrap: balance;
}
.r2p-prev {
  margin: 4px 0 0;
  display: flex;
  align-items: baseline;
  font-size: 15px;
  line-height: 1.4;
  color: var(--muted);
}
.r2p-prev .r2p-dot { opacity: 0.7; transform: translateY(1px); }

.r2p-stand { margin: 0; font-size: 17px; line-height: 1.45; color: var(--text); }

/* the step's own text: under its title, quiet; the title carries the step (round two, rule 26) */
.r2p-text { margin: -6px 0 0; font-size: 14px; line-height: 1.5; color: var(--muted); }
.r2p-text:empty { display: none; }

/* a story's end card: where it stands, with its date */
.r2p-stand-when { margin: 0; font-size: 13px; font-weight: 600; color: var(--muted); }

/* the opening card's one line: the span's own words as stored */
.r2p-line { margin: 0; font-size: 16px; line-height: 1.4; color: var(--text); text-wrap: pretty; }

/* the end card: where things stand at the span's end, a pill and a dated line a story (Dec 3) */
.r2p-stand-head { margin: 2px 0 0; font-size: 20px; line-height: 1.25; font-weight: 650; color: var(--text); }
.r2p-stands { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.r2p-stand-row { margin: 0; display: flex; flex-direction: column; gap: 3px; }
.r2p-stand-top { margin: 0; display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; }
.r2p-stand-row .r2p-stand { font-size: 15px; line-height: 1.4; }
.r2p-pill {
  display: inline-flex; align-items: center; max-width: 100%;
  min-height: 30px; padding: 4px 12px; box-sizing: border-box;
  border: 1px solid color-mix(in srgb, var(--r2p-c) 45%, transparent);
  border-radius: 15px; background: var(--bg);
  color: var(--r2p-c); font: inherit; font-weight: 650; font-size: 14px; line-height: 1.3; text-align: left;
  cursor: pointer;
}
.r2p-pill:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (hover: hover) { .r2p-pill:hover { border-color: var(--r2p-c); } }

/* the topic's picture on every play's opening card, a topic's and a story's (drawn by R2.head.drawPicture) */
/* every topic's play (Dec 3): beside the words on a computer, a box 112 x 72 so a wide skyline is not a sliver and
   a tall picture does not dominate; on a phone on its own line above them (below), where the card has the room */
.r2p-art { width: 112px; height: 72px; flex: none; display: flex; align-items: center; }
.r2p-art > * { width: auto; max-width: 100%; height: 100%; display: block; }
.r2p-with-art .r2p-in { display: grid; grid-template-columns: 112px 1fr; column-gap: 16px; align-items: center; }
.r2p-with-art .r2p-art { grid-row: 1 / span 3; }
.r2p-with-art .r2p-in > :not(.r2p-art) { grid-column: 2; }   /* a "Previously" line too stays beside the picture */
@media (max-width: 699.98px) {
  .r2p-with-art .r2p-in { display: flex; align-items: stretch; }   /* the words start at the left, as on every other card */
  .r2p-art { width: 100%; height: 64px; margin-bottom: 4px; }
}
@media (max-width: 699.98px) and (max-height: 600px) {
  .r2p-art { height: 44px; }   /* a short phone (320 x 568): smaller, so the words and controls keep their room */
}

/* the end card's choices */
.r2p-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 6px; }
.r2p-act {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 22px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.r2p-act.r2p-main { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

/* the controls: back, pause or play, next, and Close; 44 px at least */
.r2p-controls { display: flex; align-items: center; gap: 12px; }
.r2p-btn {
  min-width: 48px;
  height: 48px;
  padding: 0;
  border-radius: 24px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.r2p-btn svg { display: block; width: 18px; height: 18px; }
.r2p-toggle { font-size: 15px; letter-spacing: -2px; }
.r2p-toggle[data-mode="play"], .r2p-toggle[data-mode="step"] { font-size: 17px; letter-spacing: 0; }
.r2p-close { margin-left: auto; padding: 0 20px; font-size: 16px; font-weight: 600; }
.r2p-btn:disabled { opacity: 0.35; cursor: default; }
.r2p-btn:focus-visible, .r2p-act:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (hover: hover) {
  .r2p-btn:not(:disabled):hover, .r2p-act:not(.r2p-main):hover { background: var(--surface-2); }
}

/* a phone: while a play runs the caption is the reading; an open story's sheet does not cover it */
/*
 * A phone: play takes the whole screen (round two, rule 26). The room is fixed over the page, as tall as
 * the screen that shows (100dvh: Safari's address bar and toolbar come and go; 100vh before it), so the
 * site's footer and anything below never show; the caption takes what the picture leaves, its controls
 * at the bottom above the home bar.
 */
@media (max-width: 699.98px) {
  .r2.r2-playing .r2-reading { display: none; }
  html.r2p-full, html.r2p-full body { overflow: hidden; overscroll-behavior: none; }
  .r2.r2-playing {
    position: fixed;
    inset: 0;
    z-index: 60;
    height: 100vh;
    height: 100dvh;
    margin: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    overflow: hidden;
  }
  .r2.r2-playing .r2-body, .r2.r2-playing .r2-stage { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
  /* One place to read (Dec 3, Mony: "the user is like jumping around visually"): the picture keeps one height
     for the whole play and the caption takes the rest, so the caption's words start at the same y at every step
     and the picture never resizes under them (it followed the caption's height before: up to 72 px a step). The
     picture is the screen less about 400 px for the caption, between 240 and 480 px; a long text scrolls inside
     the caption and its controls stay at its foot. */
  .r2.r2-playing .r2-picture { flex: none; min-height: 0; height: clamp(240px, calc(100vh - 400px), 480px); height: clamp(240px, calc(100dvh - 400px), 480px); }
  .r2.r2-playing .r2-caption { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
  .r2.r2-playing .r2p { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding-bottom: 0; }
  .r2.r2-playing .r2p > * { flex-shrink: 0; }   /* the words scroll; they never squeeze onto each other */
  .r2.r2-playing { padding-top: env(safe-area-inset-top); }
  /* the controls at the caption's foot, whatever the words' length */
  .r2.r2-playing .r2p-controls { margin-top: auto; padding: 14px 0 max(16px, env(safe-area-inset-bottom)); position: sticky; bottom: 0; background: var(--surface); }
  .r2.r2-playing .r2p-head { font-size: 24px; }
}

/* a laptop: the caption is a card under the picture, its words a little larger */
@media (min-width: 900px) {
  .r2p { min-height: 236px; padding: 16px 24px 18px; margin: 0 0 14px var(--pad, 18px); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); max-width: 640px; }
  .r2p-head { font-size: 24px; }
  /* where things stand: two columns, so five stories and the choices fit under the picture */
  .r2p-stands { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 20px; }
  .r2p-stand-row .r2p-stand { font-size: 14px; line-height: 1.35; }
  .r2p-stand-head { font-size: 18px; }
  /* never taller than the screen leaves it: a short laptop scrolls the card, not the page */
  .r2.r2-playing .r2p { max-height: calc(100vh - var(--r2-head, 56px) - 120px); overflow-y: auto; }
}

@media (prefers-reduced-motion: no-preference) {
  .r2p-in { animation: r2p-in 0.25s ease-out; }
  @keyframes r2p-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
}
