/* ============================================================================
   r-inline.css: narrated, interactive R activity inside a lesson's .r-box
   (see r-inline.js, r-gate.js and the rollout notes in PILOT_NOTES.md).
   One fixed-height box: script, console (or figure) and, at each question,
   the question card with the student's answer (it closes on Submit; the page's
   model answers are never shown in the player). Light theme, matching the
   lesson pages: orange R box, dark code (#1F1B16) and the slide companion
   player's control bar (#03241F, red play button).
   ============================================================================ */
.r-box.ri-on .ri-static, .r-box.ri-on .ri-merged > h4, .r-box.ri-on .ri-merged > .r-activity-intro,
.r-box.ri-on .ri-merged > .btn-save-r, .r-box.ri-on .ri-merged > .r-activity-status { display: none; }
/* the model answers stay in the page (no-JavaScript version, answer key) but not in the player,
   even after saveRActivity() marks them .show */
.r-box.ri-on .ri-merged .r-answer-reveal { display: none !important; }
.r-box.ri-on.ri-show-static .ri-static { display: block; margin-top: 10px; }
.r-box .ri-static-note { display: none; }
.r-box.ri-on .ri-static-note { display: block; }
.r-box.ri-on .ri-merged { margin: 0; padding: 0; border: 0; }

.ri { --ri-code-bg: #1F1B16; --ri-code-fg: #F5E9DA; --ri-gutter: #7A6F63; --ri-sel: rgba(107,181,166,.30);
  --ri-con-bg: #FFFBF5; --ri-con-fg: #3B3631; --ri-con-cmd: #1D4ED8; --ri-con-msg: #B91C1C;
  --ri-night: #03241F; --ri-red: #CC0033; --ri-mint: #7FD8C3; --ri-ink: #CC0033;
  --ri-mono: 'SFMono-Regular', Menlo, Consolas, 'Liberation Mono', monospace;
  --ri-h: clamp(540px, calc(100vh - 124px), 740px); --ri-code-lines: 4;
  display: flex; flex-direction: column; height: var(--ri-h); margin: 4px 0 0; border: 1px solid #3A322A; border-radius: 10px;
  overflow: hidden; background: var(--ri-code-bg); font-family: 'Open Sans', 'Segoe UI', system-ui, -apple-system, sans-serif; }
@supports (height: 100dvh) { .ri { --ri-h: clamp(540px, calc(100dvh - 124px), 740px); } }
@media (min-width: 769px) {
  .ri { --ri-h: clamp(520px, calc(100vh - 104px), 660px); --ri-code-lines: 5; }
  @supports (height: 100dvh) { .ri { --ri-h: clamp(520px, calc(100dvh - 104px), 660px); } }
}
.ri.ri-qon { --ri-code-lines: 2; }
.ri.ri-figon { --ri-code-lines: 3; }
.ri.ri-figon.ri-qon { --ri-code-lines: 2; }
.ri *, .ri *::before, .ri *::after { box-sizing: border-box; }
.ri-code, .ri-con, .ri-txbody, .ri-qbody { overscroll-behavior: contain; }

/* ---------- stage: script, console or figure, and the question card ---------- */
.ri-stage { position: relative; flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; overflow: hidden;
  background: var(--ri-code-bg); outline: none; }
.ri-stage:focus-visible { box-shadow: inset 0 0 0 3px rgba(234,88,12,.55); }
.ri-bar { flex: none; display: flex; align-items: center; gap: 10px; height: 30px; padding: 0 8px 0 12px; background: #2A241D;
  border-bottom: 1px solid #3A322A; font: 600 11.5px/1 var(--ri-mono); color: #E7D3BC; }
.ri-bar .ri-file { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ri-bar .ri-file::before { content: 'R'; display: inline-block; margin-right: 7px; padding: 2px 5px; border-radius: 3px;
  background: #EA580C; color: #fff; font-size: 9.5px; font-weight: 800; vertical-align: 1px; }
.ri-run { flex: none; display: inline-flex; align-items: center; gap: 5px; padding: 4px 9px; border-radius: 5px;
  background: rgba(255,255,255,.08); color: #E7D3BC; font: 700 11px/1 'Open Sans', sans-serif; transition: background .15s, transform .15s; }
.ri-run svg { width: 10px; height: 10px; fill: #86EFAC; }
.ri-run.press { background: rgba(134,239,172,.30); transform: scale(.94); }
.ri-keycap { position: absolute; right: 70px; top: 34px; z-index: 6; padding: 3px 8px; border-radius: 5px; background: #fff; color: #2D3436;
  font: 700 11px/1.4 'Open Sans', sans-serif; box-shadow: 0 2px 8px rgba(0,0,0,.35); opacity: 0; transform: translateY(-4px);
  transition: opacity .2s, transform .2s; pointer-events: none; }
.ri-keycap.on { opacity: 1; transform: none; }

.ri-code { flex: none; height: calc(var(--ri-code-lines) * 1.62em + 12px); overflow: auto; padding: 6px 0; font: 12.5px/1.62 var(--ri-mono);
  color: var(--ri-code-fg); scrollbar-width: thin; scrollbar-color: #4A4037 transparent; transition: height .3s ease; }
.ri-code .ln { display: flex; position: relative; padding-right: 10px; }
.ri-code .no { flex: 0 0 36px; text-align: right; padding-right: 10px; color: var(--ri-gutter); user-select: none; font-variant-numeric: tabular-nums; }
.ri-code .tx { flex: 1; min-width: 0; white-space: pre; position: relative; z-index: 1; }
.ri-code .hl { position: absolute; left: 36px; top: 0; bottom: 0; width: 0; background: var(--ri-sel); transition: width .38s ease; pointer-events: none; }
.ri-code .ln.sel .hl { width: calc(100% - 36px); }
.ri-code .ln.sel .no { color: #fff; }
.ri-code .cm { color: #FDBA74; font-style: italic; }
.ri-code .kw { color: #FCA5A5; font-weight: 600; }
.ri-code .st { color: #86EFAC; }
.ri-code .fn { color: #93C5FD; }
.ri-code .nu { color: #FCD34D; }
.ri-code .op { color: #FCA5A5; }
/* the student's own code (a question asks for it): hidden until typed at the end of the script */
.ri-code .ln.own:not(.typed) { display: none; }
.ri-code .ln.own .no { color: var(--ri-mint); }
.ri-code .ln.own::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--ri-mint); opacity: .8; }
.ri-code .ln.own.typing .tx { animation: riType var(--ri-type, .8s) steps(24, end) both; }
@keyframes riType { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }

.ri-conbar { flex: none; display: flex; align-items: center; justify-content: space-between; height: 24px; padding: 0 12px; background: #F5E6D3;
  border-top: 1px solid #3A322A; font: 700 10.5px/1 'Open Sans', sans-serif; letter-spacing: .5px; text-transform: uppercase; color: #9A3412; }
.ri-conbar .ri-rv { font-weight: 600; text-transform: none; letter-spacing: 0; color: #B45309; }
.ri-con { flex: 1 1 0; min-height: 0; overflow: auto; padding: 7px 12px; background: var(--ri-con-bg); color: var(--ri-con-fg);
  font: 12px/1.5 var(--ri-mono); scrollbar-width: thin; }
.ri .ri-con pre { margin: 0; font: inherit; white-space: pre; background: none; color: inherit; padding: 0; border-radius: 0; overflow: visible; }
.ri-con pre.cmd { color: var(--ri-con-cmd); }
.ri-con pre.cmd .pr { color: #6B7280; }
.ri-con pre.msg, .ri-con pre.err { color: var(--ri-con-msg); }
.ri-con pre.err { font-weight: 600; }
.ri-con pre.note { color: #9CA3AF; font-style: italic; }
.ri-con pre.in { animation: riLineIn .2s ease both; }
@keyframes riLineIn { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

/* figure: appears only while a scene uses it, in the console's place */
.ri-figpanel { display: none; flex: 1 1 0; min-height: 0; flex-direction: column; align-items: center; background: #fff;
  border-top: 1px solid #3A322A; padding: 6px 10px 8px; overflow: hidden; }
.ri-stage.fig-on .ri-conbar, .ri-stage.fig-on .ri-con { display: none; }
.ri-stage.fig-on .ri-figpanel { display: flex; animation: riFigIn .35s ease both; }
@keyframes riFigIn { from { opacity: 0; } to { opacity: 1; } }
.ri-figpanel .ri-figcap { flex: none; align-self: stretch; font: 700 10.5px/1.3 'Open Sans', sans-serif; letter-spacing: .5px; text-transform: uppercase; color: #9A3412; margin: 0 2px 4px; }
.ri-figpanel .ri-figimg { flex: none; margin: 0 auto; }
.ri-figimg { position: relative; display: block; overflow: hidden; border-radius: 4px; }
.ri-figimg img { display: block; width: 100%; height: auto; border-radius: 4px; }
.ri-figpanel .ri-figimg img { height: 100%; }
.ri-region { position: absolute; border: 3px solid var(--ri-ink, #CC0033); border-radius: 8px; box-shadow: 0 0 0 2000px rgba(255,255,255,.28), 0 0 0 2px rgba(255,255,255,.8) inset;
  pointer-events: none; animation: riRegion .45s ease both; }
@keyframes riRegion { from { opacity: 0; transform: scale(1.04); } to { opacity: 1; transform: none; } }

/* question card: inside the box, under the output the question refers to */
.ri-qcard { flex: 0 1 auto; max-height: 56%; min-height: 0; display: flex; flex-direction: column; background: #FFF7ED;
  border-top: 3px solid #EA580C; animation: riCardIn .35s ease both; }
.ri-qcard[hidden] { display: none; }
.ri.ri-figon .ri-qcard { max-height: 44%; }   /* leave the figure room while both are shown */
@keyframes riCardIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.ri-qcard.waiting { box-shadow: inset 0 0 0 2px #EA580C; }
.ri-qhead { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 14px 0;
  font: 800 11px/1.4 'Open Sans', sans-serif; letter-spacing: .6px; text-transform: uppercase; color: #9A3412; }
.ri-qstate { font-weight: 700; letter-spacing: 0; text-transform: none; font-size: 12px; }
.ri-qstate.ok { color: #15803D; }
.ri-qstate.ok::before { content: '\2713  '; }
.ri-qstate.wait { color: #C2410C; animation: riPulse 1.6s ease-in-out infinite; }
@keyframes riPulse { 50% { opacity: .45; } }
.ri-qbody { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 2px 14px 12px; scrollbar-width: thin; }
.ri-qgroup[hidden] { display: none; }
.r-box .ri-qbody .r-q { margin: 4px 0 6px; font-size: 14px; line-height: 1.5; font-weight: 600; color: #44403C; }
.r-box .ri-qbody textarea { display: block; width: 100%; min-height: 66px; margin: 0; padding: 8px 10px; border: 1px solid #FDBA74; border-radius: 6px;
  background: #fff; font: 14px/1.45 'Open Sans', sans-serif; color: #2D3436; resize: vertical; }
.r-box .ri-qbody textarea:focus { outline: none; border-color: #EA580C; box-shadow: 0 0 0 3px rgba(234,88,12,.15); }
.ri-qact { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin: 6px 0 2px; }
.ri-submit { border: 0; border-radius: 6px; padding: 7px 16px; background: #EA580C; color: #fff; font: 700 13px/1.2 'Open Sans', sans-serif; cursor: pointer; }
.ri-submit:hover:not(:disabled) { background: #C2410C; }
.ri-submit:disabled { background: #D6D3D1; color: #57534E; cursor: default; }
.ri-qhint { font-size: 12px; color: #9A3412; }

/* ink: rings, underlines, highlighter bands, labels, pointer */
.ri-ink { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 5; overflow: visible; }
.ri-ink .ring, .ri-ink .ul { fill: none; stroke: var(--ri-ink); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; transition: opacity .5s; }
.ri-ink .ring { filter: drop-shadow(0 0 1.5px rgba(255,255,255,.8)); }
.ri-ink .hlr { fill: rgba(250,204,21,.42); mix-blend-mode: multiply; }
.ri-ink .hlg { transition: opacity .5s; }
.ri-ink .hlg.grow { transform-box: fill-box; transform-origin: left center; animation: riHl .45s ease-out both; }
@keyframes riHl { from { transform: scaleX(0); } to { transform: none; } }
.ri-ink g { transition: opacity .5s; }
.ri-ink .lbl rect { fill: var(--ri-ink); }
.ri-ink .lbl text { fill: #fff; font: 700 11.5px 'Open Sans', sans-serif; }
.ri-ink .lbl line { stroke: var(--ri-ink); stroke-width: 1.6; }
.ri-ink .lbl { transition: opacity .45s; }
.ri-ink .fade { opacity: .35; }
.ri-pointer { position: absolute; left: 0; top: 0; z-index: 7; width: 22px; height: 22px; margin: -2px 0 0 -2px; pointer-events: none; opacity: 0;
  transition: transform .5s cubic-bezier(.3,.7,.2,1), opacity .3s; filter: drop-shadow(0 2px 3px rgba(0,0,0,.4)); }
.ri-pointer.on { opacity: 1; }
.ri-pointer.on.idle { opacity: .45; }
.ri-instant .ri-pointer, .ri-instant .ri-qcard { transition: none; animation: none; }

/* overlay cards (start, end) */
.ri-over { position: absolute; inset: 0; z-index: 9; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  padding: 18px; text-align: center; background: rgba(3,36,31,.82); color: #fff; backdrop-filter: blur(1.5px); }
.ri-over[hidden] { display: none; }
.ri-over .big { width: 64px; height: 64px; border-radius: 50%; border: 0; background: var(--ri-red); color: #fff; cursor: pointer;
  display: grid; place-items: center; box-shadow: 0 6px 20px rgba(0,0,0,.35); transition: transform .15s; }
.ri-over .big:hover { transform: scale(1.06); }
.ri-over .big svg { width: 28px; height: 28px; margin-left: 3px; }
.ri .ri-over h4 { margin: 2px 0 0; font-size: 17px; font-weight: 700; color: #fff; line-height: 1.35; }
.ri .ri-over p { margin: 0; max-width: 470px; font-size: 13.5px; line-height: 1.55; color: rgba(255,255,255,.88); }
.ri-over .row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 4px; }
.ri-over .row button { border: 1px solid rgba(255,255,255,.35); background: rgba(255,255,255,.1); color: #fff; border-radius: 999px;
  padding: 7px 14px; font: 600 12.5px/1.2 'Open Sans', sans-serif; cursor: pointer; }
.ri-over .row button.primary { background: #EA580C; border-color: #EA580C; }
.ri-over .row button:hover { background: rgba(255,255,255,.2); }
.ri-over .row button.primary:hover { background: #C2410C; }

/* transcript, over the stage */
.ri-tx { position: absolute; inset: 0; z-index: 8; display: flex; flex-direction: column; background: #fff; font-size: 13px; line-height: 1.55; }
.ri-tx[hidden] { display: none; }
.ri-txhead { flex: none; display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; border-bottom: 1px solid #FED7AA; color: #7C2D12; font-size: 13px; }
.ri-txhead button { border: 0; background: none; font-size: 20px; line-height: 1; color: #9A3412; cursor: pointer; padding: 0 4px; }
.ri-txbody { flex: 1 1 0; min-height: 0; overflow: auto; padding: 8px 12px 14px; }
.ri-tx button[data-i] { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 5px 6px; border-radius: 5px; cursor: pointer; font: inherit; color: #44403C; }
.ri-tx button[data-i] b { display: block; font-size: 12.5px; color: #7C2D12; }
.ri-tx button[data-i]:hover { background: #FFF7ED; }
.ri-tx button.now { background: #FFEDD5; }
.ri .ri-tx code { font-family: var(--ri-mono); font-size: 12px; background: #FED7AA; color: #7C2D12; padding: 0 4px; border-radius: 3px; }
.ri-tx .locked { color: #9CA3AF; font-style: italic; padding: 4px 6px; }

/* captions */
.ri-cap { flex: none; min-height: 44px; padding: 7px 14px; background: #10302B; color: rgba(255,255,255,.55); font-size: 13.5px; line-height: 1.5; }
.ri-cap.off { display: none; }
.ri-cap .w.said { color: #fff; }
.ri-cap .w.now { color: var(--ri-mint); }
.ri .ri-cap code { font-family: var(--ri-mono); font-size: .92em; background: rgba(255,255,255,.1); padding: 0 4px; border-radius: 3px; color: inherit; }
.ri-silent { flex: none; padding: 5px 14px; background: #FEF3C7; color: #92400E; font-size: 12.5px; }

/* controls: same vocabulary as the slide companion player */
.ri-ctl { flex: none; display: flex; align-items: center; gap: 4px 6px; padding: 6px 10px; background: var(--ri-night); flex-wrap: wrap; }
.ri-btn { flex: none; display: inline-grid; place-items: center; height: 32px; min-width: 32px; padding: 0 7px; border-radius: 8px;
  border: 1px solid transparent; background: transparent; color: rgba(255,255,255,.82); cursor: pointer; font: 700 12px/1 'Open Sans', sans-serif; }
.ri-btn:hover:not(:disabled) { background: rgba(255,255,255,.08); color: #fff; }
.ri-btn:disabled { opacity: .35; cursor: default; }
.ri-btn:focus-visible { outline: 2px solid var(--ri-mint); outline-offset: 1px; }
.ri-btn svg { width: 17px; height: 17px; }
.ri-btn.play { width: 38px; height: 38px; border-radius: 50%; background: var(--ri-red); color: #fff; }
.ri-btn.play:hover { background: #E0103F; }
.ri-btn.is-on { color: #04231F; background: var(--ri-mint); }
.ri-btn.txt { font-size: 11.5px; padding: 0 9px; }
.ri-segs { flex: 1 1 160px; min-width: 120px; display: flex; gap: 3px; align-items: center; height: 32px; }
.ri-seg { flex: 1 1 0; height: 6px; border: 0; padding: 0; border-radius: 3px; background: rgba(255,255,255,.16); cursor: pointer; position: relative; overflow: hidden; }
.ri-seg i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--ri-red); }
.ri-seg.done i { width: 100%; }
.ri-seg.ask { flex: 0 0 14px; height: 14px; border-radius: 50%; background: #FDBA74; }
.ri-seg.ask i { background: #EA580C; }
.ri-seg.ask.answered { background: var(--ri-mint); }
.ri-seg.ask.answered i { background: var(--ri-mint); }
.ri-seg.answer i { background: var(--ri-mint); }
.ri-seg:disabled { cursor: not-allowed; opacity: .45; background: repeating-linear-gradient(135deg, rgba(255,255,255,.12) 0 3px, rgba(255,255,255,.03) 3px 6px); }
.ri-seg:hover:not(:disabled) { outline: 1px solid rgba(255,255,255,.5); }
.ri-seg:focus-visible { outline: 2px solid var(--ri-mint); }
.ri-meta { flex: 1 0 100%; order: 10; display: flex; justify-content: space-between; gap: 10px; padding: 0 4px; font: 600 11.5px/1.3 'Open Sans', sans-serif;
  color: rgba(255,255,255,.7); font-variant-numeric: tabular-nums; }
.ri-meta .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #fff; }
.ri-meta .tm { flex: none; }

/* under the box: the files row, the run-along line and the text-version toggle */
.r-box.ri-on .r-downloads { margin: 10px 0 0; }
.r-box.ri-on .r-downloads .ri-static-btn { margin-left: auto; border: 0; background: none; padding: 2px 4px; color: #9A3412;
  font: 600 12px/1.4 'Open Sans', sans-serif; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.r-box.ri-on .r-runalong { margin: 6px 2px 0; font-size: 13px; line-height: 1.5; color: #7C2D12; }
.ri-links { display: flex; justify-content: flex-end; margin: 6px 2px 0; }
.ri-links button { border: 0; background: none; padding: 0; color: #9A3412; font: 600 12px/1.4 'Open Sans', sans-serif; cursor: pointer; text-decoration: underline; }

@media (max-width: 760px) {
  .r-box.ri-on { padding-left: 12px; padding-right: 12px; }
  .ri-code { font-size: 11px; }
  .ri-code .no { flex-basis: 28px; padding-right: 7px; }
  .ri-code .hl { left: 28px; }
  .ri-code .ln.sel .hl { width: calc(100% - 28px); }
  .ri-con { font-size: 10.5px; padding: 6px 8px; }
  .ri-cap { font-size: 13px; padding: 7px 10px; min-height: 40px; }
  .ri-btn.play { width: 34px; height: 34px; }
  .ri-meta { font-size: 11px; }
  .ri-qcard { max-height: 62%; }
  .ri-qbody { padding: 2px 10px 10px; }
  .r-box .ri-qbody .r-q { font-size: 13.5px; }
}
/* phones: keep the right end of the controls clear of the site's floating "Get Help" tab
   (site-feedback.js docks it at the right edge below 600 px) */
@media (max-width: 600px) {
  .ri-ctl { padding-right: 40px; }
}
@media (prefers-reduced-motion: reduce) {
  .ri-con pre.in, .ri-region, .ri-stage.fig-on .ri-figpanel, .ri-qcard, .ri-qstate.wait, .ri-code .ln.own.typing .tx, .ri-ink .hlg.grow { animation: none; }
  .ri-pointer, .ri-code .hl, .ri-code { transition: none; }
}
@media print { .ri { display: none !important; } .r-box.ri-on .ri-static, .r-box.ri-on .ri-merged > *:not(.r-answer-reveal) { display: block !important; } }
