/* FlexText Interlinear — styling loosely modeled on FLEx's interlinear pane. */

:root {
  --blue: #1f4f8f;
  --blue-dark: #163a6b;
  --vern: #00379c;        /* FLEx wordform blue */
  --gloss: #2a6e2a;       /* FLEx word-gloss green */
  --bg: #ffffff;
  --panel: #f4f6f9;
  --border: #cfd6e0;
  --text: #1a1d21;
  --muted: #5b6470;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}

body { display: flex; flex-direction: column; }

main {
  flex: 1;
  overflow-y: auto;
  padding: 12px clamp(10px, 3vw, 28px) 60px;
}

/* ---------- Top bar ---------- */

#topbar {
  background: var(--blue);
  color: #fff;
  padding-top: env(safe-area-inset-top);
  flex: none;
}

.topbar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px clamp(10px, 3vw, 28px);
  flex-wrap: wrap;
}

.app-title {
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: auto;
}

.app-logo { width: 24px; height: 24px; }

.top-tabs { display: flex; gap: 2px; }

.top-tab {
  appearance: none;
  border: none;
  background: rgba(255,255,255,.12);
  color: #fff;
  padding: 7px 16px;
  font-size: 15px;
  cursor: pointer;
  border-radius: 7px 7px 0 0;
  margin-bottom: -8px;
  padding-bottom: 13px;
}

.top-tab[aria-selected="true"] {
  background: var(--bg);
  color: var(--blue-dark);
  font-weight: 600;
}

.doc-title {
  flex: 1 1 140px;
  min-width: 120px;
  border: none;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 16px;
  background: rgba(255,255,255,.92);
}

.icon-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: inherit;
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}
.icon-btn:hover { background: rgba(127,127,127,.18); }

/* ---------- Buttons ---------- */

.primary-btn, .secondary-btn {
  appearance: none;
  font-size: 15px;
  padding: 8px 16px;
  border-radius: 7px;
  cursor: pointer;
  border: 1px solid transparent;
}
.primary-btn { background: var(--blue); color: #fff; }
.primary-btn:hover { background: var(--blue-dark); }
.secondary-btn { background: var(--panel); border-color: var(--border); color: var(--text); }
.secondary-btn:hover { background: #e8ecf2; }
.link-btn {
  appearance: none; border: none; background: none;
  color: var(--blue); cursor: pointer; font-size: 15px; padding: 8px;
}

#topbar .primary-btn { background: #2e7d32; }
#topbar .primary-btn:hover { background: #25652a; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin: 12px 0; align-items: center; }

/* ---------- Texts view ---------- */

.banner {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 10px;
}

.warn-banner, .install-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 12px;
}

.warn-banner {
  background: #fdf3d7;
  border-color: #e4c95b;
  color: #6b5310;
}

.install-banner {
  background: #e8f0fc;
  border-color: #b9cdee;
  color: var(--blue-dark);
}
.install-banner .primary-btn { padding: 6px 14px; flex: none; }
.warn-banner span, .install-banner span { flex: 1; }

.banner-dismiss {
  appearance: none;
  border: none;
  background: none;
  color: inherit;
  opacity: .55;
  font-size: 14px;
  cursor: pointer;
  padding: 4px 6px;
  flex: none;
}
.banner-dismiss:hover { opacity: 1; }

.doc-list { list-style: none; margin: 0; padding: 0; }

.doc-list li {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: 9px;
  margin-bottom: 8px;
  overflow: hidden;
  background: #fff;
}

.doc-open {
  appearance: none; border: none; background: none;
  flex: 1; text-align: left; cursor: pointer;
  padding: 10px 14px;
  display: flex; flex-direction: column; gap: 2px;
}
.doc-open:hover { background: var(--panel); }
.doc-name { font-weight: 600; font-size: 16px; }
.doc-meta { color: var(--muted); font-size: 13px; }
.doc-delete { color: var(--muted); border-left: 1px solid var(--border); border-radius: 0; }
.doc-done { color: var(--muted); border-left: 1px solid var(--border); border-radius: 0; font-size: 22px; line-height: 1; }
.doc-done.on { color: #1f5d22; }   /* text marked completed */
.doc-done:hover { background: var(--panel); }
.doc-pending-del { opacity: .5; }
.doc-pending-del .doc-name { text-decoration: line-through; }

.empty-note { color: var(--muted); margin-top: 24px; text-align: center; }

/* ---------- Baseline tab ---------- */

.tab-hint { color: var(--muted); font-size: 14px; margin: 8px 0; }

.baseline-area {
  width: 100%;
  min-height: 55vh;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  font-size: 19px;
  line-height: 1.9;
  color: var(--vern);
  resize: vertical;
}
.baseline-area:focus { outline: 2px solid var(--blue); }

/* ---------- Segment strips (segmentation mode) ---------- */
#segment-strips { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
/* Text sits IMMEDIATELY UNDER its waveform (Seth): the play button spans both rows on the left;
   the right column stacks wave over text, so eye and ear line up vertically per segment. */
.seg-strip { position: relative; display: grid; grid-template-columns: auto 1fr;
             grid-template-rows: auto auto; gap: 2px 10px;
             border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; background: #fff; }
.seg-strip.seg-pending { border-style: dashed; }
.seg-strip.seg-est { border-style: dashed; }   /* estimated times: playable but unconfirmed */
.seg-setend {
  position: absolute; right: 6px; top: 4px; z-index: 2;
  font-size: 13px; padding: 2px 9px; cursor: pointer;
  border: 1px solid var(--border); border-radius: 6px; background: #fff; opacity: .85;
}
.seg-setend:hover { opacity: 1; background: #eef2f7; }
.seg-play { appearance: none; border: 1px solid var(--border); background: var(--panel);
            border-radius: 7px; min-width: 38px; height: 38px; font-size: 15px; cursor: pointer;
            grid-row: 1 / span 2; align-self: center; }
.seg-play:hover { background: #e8ecf2; }
.seg-wave { grid-column: 2; width: 100%; height: 44px; display: block; cursor: crosshair; touch-action: none; }
.seg-text { grid-column: 2; border: none; border-top: 1px solid var(--border); padding: 6px 2px;
            font-size: 18px; line-height: 1.5; color: var(--vern); min-width: 0; width: 100%; }
/* An EMPTY strip is a real segment whose text just happens to be empty — how silence is marked
   (Enter, let it play through the pause, Enter again). Visually quieter, never hidden. */
.seg-strip.seg-empty .seg-wave { opacity: .55; }
.seg-text:focus { outline: 2px solid var(--blue); border-radius: 4px; }
/* Gloss-tab per-line bar: the same transport, skinnier clothes — a small ▶/⏸ and a thin waveform
   above each interlinear line-group. */
.gseg-bar { display: flex; align-items: center; gap: 8px; margin: 2px 0 4px; }
.gseg-play { appearance: none; border: 1px solid var(--border); background: var(--panel);
             border-radius: 6px; min-width: 30px; height: 26px; font-size: 12px; cursor: pointer; flex: none; }
.gseg-play:hover { background: #e8ecf2; }
.gseg-wavewrap { position: relative; flex: 1; }
.gseg-wave { width: 100%; height: 22px; display: block; cursor: crosshair; touch-action: none; }
.gseg-cursor { position: absolute; top: 0; bottom: 0; width: 2px; background: #c9772a; pointer-events: none; }
/* The join control between line-groups: big enough to tap, positional meaning (it sits between
   the two lines it joins), icon-only per the low-literacy design rule. */
.gseg-join { appearance: none; border: 1px solid var(--border); background: #fff; color: var(--muted);
             border-radius: 6px; min-width: 44px; height: 24px; font-size: 12px; cursor: pointer;
             display: block; margin: 6px 0 0 0; }
.gseg-join:hover { background: #ece3f7; color: #5b3d8a; }
/* The playhead cursor, drawn on whichever strip contains the current time. */
.seg-cursor { position: absolute; width: 2px; background: #c9772a; pointer-events: none; }

/* ---------- Audio player ---------- */

.player {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  padding: 8px 10px 6px;
  margin: 8px 0 4px;
  /* STICKY (Seth): the overview player stays put at the top while the strip stack scrolls under
     it, so the transport and the big-picture waveform are always reachable mid-transcription.
     `main` is the scrolling ancestor; the shadow separates it from strips passing beneath. */
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: 0 3px 10px rgba(20,30,50,.08);
}

.player-wave { min-height: 72px; }

.player-status {
  color: var(--muted);
  font-size: 14px;
  margin: 6px 2px;
}

.player-progress {
  height: 8px;
  background: #dbe3ef;
  border-radius: 5px;
  overflow: hidden;
  margin: 6px 2px 8px;
}

.player-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--blue);
  border-radius: 5px;
  transition: width .25s ease;
}

.player-progress.indeterminate .player-progress-fill {
  width: 30%;
  transition: none;
  animation: progress-slide 1.2s linear infinite;
}

@keyframes progress-slide {
  from { margin-left: -30%; }
  to   { margin-left: 100%; }
}

.player-dl-controls {
  display: flex;
  gap: 8px;
  margin: 0 2px 8px;
}
.player-dl-controls button { padding: 5px 14px; font-size: 14px; }

.player-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.icon-btn2 {
  appearance: none;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 7px;
  padding: 5px 12px;
  font-size: 15px;
  cursor: pointer;
  min-width: 44px;
}
.icon-btn2:hover { background: #eef2f7; }

.player-play { font-size: 17px; }

.player-speed {
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 5px 6px;
  font-size: 14px;
  background: #fff;
}

.player-time {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 14px;
  min-width: 7.5em;
}

.player-zoom-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  flex: 1;
  min-width: 140px;
}
.player-zoom { flex: 1; max-width: 220px; }

.player-remove {
  margin-left: auto;
  color: var(--muted);
  min-width: 34px;
}

.ws-form label.wide input { width: min(34em, 80vw); }

/* ---------- Gloss tab ---------- */

.segment {
  margin: 6px 0 14px;
  padding: 8px 6px 10px;
  border-bottom: 1px solid #e6eaf0;
}

.word-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 2px 10px;
  row-gap: 14px;
}

.segnum {
  color: var(--muted);
  font-size: 13px;
  padding-top: 4px;
  min-width: 1.6em;
  font-weight: 600;
}

.word-cell { display: flex; flex-direction: column; gap: 3px; }

.line-labels {
  display: flex;
  flex-direction: column;
  gap: 3px;
  width: 56px;
  flex: none;
}
.line-label {
  color: var(--muted);
  font-size: 11px;
  font-style: italic;
}
.line-label-word { height: 27px; display: flex; align-items: flex-end; }
.line-label-gloss { height: 26px; display: flex; align-items: center; }

.word-txt {
  color: var(--vern);
  font-size: 19px;
  white-space: nowrap;
  padding: 0 2px;
}
.word-txt.punct { color: var(--text); }
.punct-cell { justify-content: flex-start; }

.gloss-input {
  border: 1px solid transparent;
  border-bottom: 1px dashed var(--border);
  border-radius: 4px;
  padding: 2px 4px;
  font-size: 15px;
  color: var(--gloss);
  min-width: 3ch;
  background: transparent;
}
.gloss-input:hover { border-color: var(--border); }
.gloss-input:focus {
  outline: none;
  border: 1px solid var(--blue);
  background: #fff;
}
.gloss-input::placeholder { color: #b6bdc7; }

.phrase-cell .word-txt {
  background: #eaf1fb;
  border-radius: 5px;
  outline: 1px solid #c4d4ee;
}

.chain-btn {
  appearance: none; border: none; background: none;
  font-size: 11px;
  cursor: pointer;
  opacity: .25;
  padding: 6px 0 0;
  margin: 0 -4px;
  align-self: flex-start;
}
.chain-btn:hover, .chain-btn:focus { opacity: 1; }

.unchain-btn {
  appearance: none; border: none; background: none;
  color: var(--muted); font-size: 11px; cursor: pointer;
  text-align: left; padding: 0 2px;
}
.unchain-btn:hover { color: var(--blue); }

@media (pointer: coarse) {
  .chain-btn { opacity: .55; font-size: 13px; padding-top: 8px; }
}

.free-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-top: 10px;
  padding-left: calc(1.6em + 10px);
}

.free-label {
  color: var(--muted);
  font-size: 11px;
  font-style: italic;
  width: 56px;
  flex: none;
}

/* Blank-line placeholder on the gloss tab (segmentation mode): holds the slot for a timed span
   with no text, so gloss groups stay positionally paired with their waveforms. */
.segment.seg-blank .blank-label {
  color: var(--muted);
  font-style: italic;
  font-size: 12px;
  align-self: center;
}

.free-input {
  flex: 1;
  border: 1px solid transparent;
  border-bottom: 1px dashed var(--border);
  border-radius: 4px;
  padding: 3px 6px;
  font-size: 15px;
  background: transparent;
}
.free-input:hover { border-color: var(--border); }
.free-input:focus { outline: none; border: 1px solid var(--blue); background: #fff; }

/* ---------- Research tab ---------- */

#view-research h2 { font-size: 19px; margin: 18px 0 4px; }
#view-research hr { border: none; border-top: 1px solid var(--border); margin: 26px 0; }
.note { color: var(--muted); font-size: 14px; }

.ws-form fieldset {
  border: 1px solid var(--border);
  border-radius: 9px;
  margin: 12px 0;
  padding: 10px 14px 14px;
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}
.ws-form legend { font-weight: 600; font-size: 14px; padding: 0 6px; }
.ws-form label { display: flex; flex-direction: column; font-size: 13px; color: var(--muted); gap: 3px; }
.ws-form input {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 9px;
  font-size: 15px;
  width: 13em;
  color: var(--text);
}

.check-label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 14px;
  color: var(--muted);
  margin: 4px 0 10px;
  cursor: pointer;
  max-width: 640px;
}
.check-label input { margin-top: 3px; }

.share-link {
  word-break: break-all;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 13px;
  user-select: all;
}

.ws-table { border-collapse: collapse; width: 100%; max-width: 760px; margin-top: 10px; }
.ws-table th, .ws-table td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  font-size: 14px;
  text-align: left;
}
.ws-table th { background: var(--panel); }
.ws-newcode { width: 11em; border: 1px solid var(--border); border-radius: 5px; padding: 4px 7px; }

/* ---------- Language select, help ---------- */

#lang-select {
  appearance: none;
  border: 1px solid rgba(255,255,255,.4);
  background: rgba(255,255,255,.12);
  color: #fff;
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 13px;
  cursor: pointer;
}
#lang-select option { color: var(--text); }

.help-btn {
  border: 1px solid rgba(255,255,255,.45);
  border-radius: 50%;
  width: 30px;
  height: 30px;
  padding: 0;
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  flex: none;
}

.help { max-width: 760px; }
.help h2 { font-size: 22px; margin: 10px 0; }
.help h3 {
  font-size: 17px;
  margin: 22px 0 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
  color: var(--blue-dark);
}
.help ol, .help ul { padding-left: 22px; }
.help li { margin: 7px 0; }
.help code {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 4px;
  font-size: .92em;
}

.toast-btn {
  appearance: none;
  border: 1px solid rgba(255,255,255,.5);
  background: rgba(255,255,255,.14);
  color: #fff;
  border-radius: 6px;
  padding: 4px 12px;
  margin-left: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.toast-btn:hover { background: rgba(255,255,255,.28); }

/* ---------- Toast & modal ---------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #2b2f36;
  color: #fff;
  padding: 10px 18px;
  border-radius: 9px;
  font-size: 15px;
  max-width: min(90vw, 480px);
  box-shadow: 0 4px 18px rgba(0,0,0,.3);
  z-index: 50;
}

.modal {
  position: fixed; inset: 0;
  background: rgba(20,24,30,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 40;
  padding: 16px;
}

.modal-card {
  background: #fff;
  border-radius: 12px;
  padding: 20px 22px;
  width: min(92vw, 360px);
  display: flex; flex-direction: column; gap: 10px;
  box-shadow: 0 10px 40px rgba(0,0,0,.35);
  /* Worst-case stack (text + audio prompt + record + signature + affirm) must stay reachable on a
     small/landscape phone — scroll instead of clipping the buttons off-screen. */
  max-height: 88vh; overflow-y: auto;
}
.modal-card h3 { margin: 0 0 2px; }

/* Invite-consent dialog (who is enrolling this device). */
.invite-who { display: flex; gap: 12px; align-items: center; margin: 6px 0 4px; text-align: left; }
.invite-avatar { border-radius: 50%; flex: none; background: var(--muted); }
.invite-name { font-weight: 600; }

/* Recording-format help modal: wider, scrollable, left-aligned, with the
   archive comparison table (horizontally scrollable on narrow screens). */
.modal-card.help-modal {
  width: min(94vw, 680px);
  max-height: 86vh;
  overflow-y: auto;
  text-align: left;
}
.help-modal .help-body p { margin: 0 0 11px; line-height: 1.5; }
.help-modal .help-scroll { overflow-x: auto; margin: 4px 0 12px; }
.archive-table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
.archive-table th, .archive-table td {
  border: 1px solid var(--border);
  padding: 5px 7px;
  text-align: left;
  vertical-align: top;
}
.archive-table th { background: #eef3f9; white-space: nowrap; }
.archive-table a { color: var(--blue, #1f4f8f); }

/* Recording level meter + clip indicator + optional gain slider (record modal). */
#record-meter {
  height: 12px;
  background: var(--border, #d4dbe4);
  border-radius: 6px;
  overflow: hidden;
  margin: 4px 0 2px;
}
#record-meter-fill {
  height: 100%;
  width: 0%;
  background: #4caf50;
  border-radius: 6px;
  transition: width .05s linear, background-color .1s linear;
}
.meter-warn { color: #c62828; font-weight: 600; margin: 2px 0; }
.record-hint { color: var(--muted); font-style: italic; margin: 2px 0 4px; }

/* Optional microphone-processing options (off by default, each warned). */
.dsp-options { border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px 10px; margin: 10px 0; }
.dsp-options legend { font-size: 13px; color: var(--muted); padding: 0 4px; }
.dsp-options .check-label { display: block; margin: 7px 0; }
.dsp-options em { color: #b0673b; font-style: normal; }

#record-preview, #consent-audio, #consent-assent-preview { width: 100%; }

#record-title-row { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
#record-title {
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 9px 11px;
  font-size: 16px;
  color: var(--text);
}
#record-title:focus { outline: 2px solid var(--blue); }
.primary-btn:disabled { background: #9bb0cc; cursor: not-allowed; }

/* consent modal button groups stack like the rest of the modal card */
#consent-yesno, #consent-record { display: flex; flex-direction: column; gap: 10px; }
#consent-yesno button, #consent-record button { width: 100%; padding: 11px; }
#consent-message { white-space: pre-wrap; }

.rec-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #c62828;
  margin-right: 8px;
  vertical-align: baseline;
}

.send-options { display: flex; gap: 16px; flex-wrap: wrap; width: 100%; }
.send-options .check-label { margin: 2px 0; }

#upload-bar {
  position: fixed;
  left: 0; right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--blue-dark);
  color: #fff;
  padding: 8px clamp(10px, 3vw, 28px);
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  z-index: 45;
  font-size: 14px;
  box-shadow: 0 -2px 12px rgba(0,0,0,.25);
}
.upload-row { display: flex; align-items: center; gap: 10px; }
#upload-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-list { list-style: none; margin: 0; padding: 0; max-height: 40vh; overflow-y: auto; }
.upload-list li { display: flex; align-items: center; gap: 8px; padding: 5px 0; border-top: 1px solid rgba(255,255,255,.18); }
.up-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-state { color: rgba(255,255,255,.82); font-size: 12px; white-space: nowrap; }
#upload-toggle { white-space: nowrap; }
.upload-progress {
  flex: 1;
  max-width: 220px;
  height: 8px;
  background: rgba(255,255,255,.25);
  border-radius: 5px;
  overflow: hidden;
}
#upload-fill { height: 100%; width: 0%; background: #7fd58a; border-radius: 5px; transition: width .25s ease; }
#upload-fill.indeterminate { width: 100%; transition: none; animation: upPulse 1.1s ease-in-out infinite; }
@keyframes upPulse { 0%, 100% { opacity: .4; } 50% { opacity: 1; } }
#upload-bar .icon-btn2 { padding: 4px 10px; font-size: 13px; }
#record-toggle.recording { background: #b3261e; }
#record-toggle.recording:hover { background: #921d17; }
/* Mic still opening. The button must LOOK unavailable, not merely ignore taps — a button that
   swallows presses with no visible reason reads as a broken app, and these users cannot rely on
   the accompanying text. The pulse says "working", not "dead". */
#record-toggle.warming,
#record-toggle:disabled {
  background: #9aa0a6;
  cursor: default;
  opacity: 0.75;
}
#record-toggle.warming { animation: record-warming 1.1s ease-in-out infinite; }
@keyframes record-warming { 0%, 100% { opacity: 0.55; } 50% { opacity: 0.85; } }
@media (prefers-reduced-motion: reduce) {
  #record-toggle.warming { animation: none; }
}
.modal-card .primary-btn, .modal-card .secondary-btn { width: 100%; padding: 11px; }

@media (max-width: 560px) {
  .topbar-row { gap: 6px; }
  .top-tab { padding: 7px 11px 13px; font-size: 14px; }
  #btn-share { font-size: 13px; padding: 7px 9px; }
  .baseline-area { font-size: 17px; }
}

/* Subtle credit/source line on the home screen — muted so it doesn't distract
   everyday users, but discoverable for a developer who might fork/adopt it. */
.site-credit {
  margin: 40px auto 14px;
  padding: 0 16px;
  max-width: 600px;
  text-align: center;
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--muted);
  opacity: 0.85;
}
.site-credit a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.site-credit a:hover { color: var(--blue-dark); }

/* ---------- Record-only mode (Phone Recording / "Text Recorder") ---------- */
.record-screen {
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}
.record-welcome {
  white-space: pre-wrap;
  text-align: center;
  font-size: 20px;
  line-height: 1.45;
  margin: 18px 6px 22px;
  color: var(--text);
}
.record-big {
  font-size: 20px;
  padding: 20px;
  border-radius: 14px;
  margin-bottom: 28px;
}
.record-big .rec-dot { width: 14px; height: 14px; margin-right: 12px; }
.record-list-h { font-size: 15px; color: var(--muted); margin: 0 0 10px; font-weight: 600; }
.rec-item { flex-direction: row; align-items: center; }
.rec-item-main {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 2px;
  padding: 10px 14px;
}
.rec-item-actions { display: flex; align-items: stretch; }
.rec-item-actions .rec-send {
  border: none; border-radius: 0; border-left: 1px solid var(--border);
  white-space: nowrap;
}

/* ---------- Researcher panel (separate view) ---------- */
.rp-head {
  display: flex; align-items: center; gap: 10px;
  background: var(--blue); color: #fff;
  padding: 10px clamp(10px, 3vw, 28px);
  margin: -12px calc(-1 * clamp(10px, 3vw, 28px)) 16px;
}
.rp-title { font-weight: 600; font-size: 17px; }
.rp-spacer { margin-left: auto; }
.rp-exit { color: #fff; font-size: 20px; }
.rp-helpbtn { color: #fff; font-size: 18px; font-weight: 600; }
.rp-help h3 { margin: 16px 0 6px; }
.rp-help h4 { margin: 14px 0 4px; }
.rp-help summary { cursor: pointer; color: var(--blue-dark); font-weight: 600; margin: 8px 0; }
.rp-help details { margin: 8px 0; }
.rp-help-inline { background: none; border: 1px solid var(--border); border-radius: 50%; width: 22px; height: 22px; padding: 0; font-size: 13px; line-height: 1; cursor: pointer; color: var(--muted); vertical-align: middle; }
.wsc-help .wsc-shot { margin: 12px 0; text-align: center; }
.wsc-help .wsc-shot img { max-width: 100%; height: auto; border: 1px solid var(--border); border-radius: 6px; }
.wsc-help figcaption { margin-top: 4px; }
.rp-lock { background: rgba(255,255,255,.15); border-color: rgba(255,255,255,.35); color: #fff; }
.rp-lock:hover { background: rgba(255,255,255,.25); }

.rp-body { max-width: 820px; margin: 0 auto; }
.rp-narrow { max-width: 460px; }
.rp-card {
  background: var(--bg); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px 18px; margin-bottom: 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.rp-card h2 { margin: 0; font-size: 18px; }
.rp-turnstile { min-height: 66px; }
.rp-field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.rp-field > span { font-weight: 500; }
.rp-field input, .rp-field select, .rp-field textarea {
  border: 1px solid var(--border); border-radius: 6px; padding: 8px 9px;
  font-size: 15px; color: var(--text); background: var(--bg);
  width: 100%; box-sizing: border-box;
}
.rp-field input:focus, .rp-field select:focus, .rp-field textarea:focus { outline: 2px solid var(--blue); border-color: var(--blue); }

/* Required-settings validation: red-ring an offending field + show its inline message. */
.rp-field.rp-invalid input, .rp-field.rp-invalid select, .rp-field.rp-invalid textarea { border-color: #d92d20; outline: 1px solid #d92d20; }
.check-label.rp-invalid { color: #d92d20; }
.rp-fielderr { color: #d92d20; font-size: 12px; font-weight: 500; margin-top: 3px; }
/* Read-only account value (Google identity) — plain text, not an editable/autofillable input. */
.rp-readonly { font-size: 15px; color: var(--text); padding: 6px 0; word-break: break-all; }

/* A tab whose panel has a blocked required field gets a red marker dot, so errors on a tab the
   researcher isn't currently looking at are still visible. */
.rp-tab.rp-tab-err::after { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #d92d20; margin-left: 6px; vertical-align: middle; }
/* The persistent "what's blocking + which tab" banner above the tabs. */
.rp-valbanner { background: #fdecea; border: 1px solid #f5c2c0; color: #8a1c14; border-radius: 8px; padding: 10px 12px; margin: 0 0 12px; font-size: 13px; }
.rp-valbanner strong { display: block; margin-bottom: 6px; }
.rp-valbanner ul { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 5px; }
.rp-valbanner li { display: flex; gap: 6px; align-items: baseline; }
.rp-valbanner li::before { content: "•"; color: #8a1c14; }
.rp-valjump { background: none; border: 0; padding: 0; margin: 0; font: inherit; color: #8a1c14; text-decoration: underline; cursor: pointer; text-align: left; }
.rp-valjump:hover { color: #d92d20; }

.rp-live { font-size: 12px; color: var(--muted); background: var(--panel); padding: 7px 11px; border-radius: 7px; margin-bottom: 12px; }
.rp-live-offline { color: #8a4b10; background: #fbe6cf; font-weight: 600; }
.rp-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 14px; }
.rp-metric { background: var(--panel); border-radius: 8px; padding: 12px 14px; }
.rp-metric-l { font-size: 13px; color: var(--muted); }
.rp-metric-n { font-size: 24px; font-weight: 600; }
.rp-metric-n.rp-warn { color: #9a6a00; }

.rp-actions { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }

.rp-inst-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.rp-inst-name { font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* Collapse toggle. A REAL <button> (keyboard + screen reader get it for free) styled to read as the
   card header it replaced — the whole header row is the hit target, which is what makes tapping it
   on a phone practical. No transition on .rp-inst-body on purpose: the dashboard re-renders every
   12s and the state is re-derived, so an animation would replay on every poll. */
.rp-inst-toggle { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; width: 100%;
  background: none; border: 0; padding: 0; margin: 0; font: inherit; color: inherit;
  text-align: left; cursor: pointer; }
.rp-inst-toggle:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; border-radius: 6px; }
.rp-caret { color: var(--muted); font-size: 12px; line-height: 1; transform: rotate(0deg); }
.rp-inst-collapsed .rp-caret { transform: rotate(-90deg); }
.rp-inst-count { margin-left: auto; font-size: 12px; color: var(--muted); font-weight: 400; }

.rp-badge { font-size: 12px; padding: 2px 9px; border-radius: 6px; background: var(--panel); color: var(--muted); font-weight: 400; }
.rp-badge-type, .rp-badge-you { background: #e8f0fc; color: var(--blue-dark); }
.rp-badge-ok { background: #e3f3e4; color: #1f5d22; }
.rp-badge-warn { background: #fdf3d7; color: #6b5310; }
.rp-badge-stale { background: #f7d9d6; color: #a3261f; font-weight: 600; }
/* Report link beside a CONFIRMED stale badge. Researcher panel only — this styling can never
   reach the coworker's app, which has no device tiles at all. */
.rp-report { font-size: 0.85em; color: #a3261f; text-decoration: underline; margin-left: 0.35em; }
.rp-report:hover { color: #7d1c17; }

/* Destructive actions (erase data / delete account / account-switch erase) — visually distinct so a
   reflex tap is less likely, paired with a typed confirm. Works for both primary and link buttons. */
.primary-btn.rp-danger { background: #a3261f; border-color: #a3261f; color: #fff; }
.primary-btn.rp-danger:hover { background: #871c16; border-color: #871c16; }
.primary-btn.rp-danger:disabled { background: #d8a6a2; border-color: #d8a6a2; cursor: default; }
.link-btn.rp-danger { color: #a3261f; }
.rp-sep { border: none; border-top: 1px solid var(--border); margin: 16px 0 12px; }
.rp-cv-src { font-weight: 600; }

/* Converter before/after players: a play button + a (per-channel, when split) waveform. */
.cv-player { display: flex; align-items: center; gap: 10px; margin: 4px 0 2px; }
.cv-play { flex: 0 0 auto; width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--border); background: var(--panel); color: var(--text); cursor: pointer; font-size: 16px; line-height: 1; }
.cv-play:hover { background: var(--card, #eef2f8); }
.cv-wave { flex: 1 1 auto; min-width: 0; }
.cv-cap { margin: 10px 0 2px; font-size: 12px; }

/* Subtle always-on per-app version badge (bottom-right corner). Never intercepts taps. */
.app-version {
  position: fixed;
  right: calc(6px + env(safe-area-inset-right));
  bottom: calc(4px + env(safe-area-inset-bottom));
  font-size: 10px; line-height: 1; letter-spacing: .02em;
  color: var(--muted); opacity: .5;
  pointer-events: none; user-select: none;
  z-index: 30; font-variant-numeric: tabular-nums;
}

.rp-install { border-top: 1px solid var(--border); padding-top: 10px; margin-top: 6px; display: flex; flex-direction: column; gap: 6px; }
.rp-devinfo { font-size: 11px; opacity: .85; }
.rp-devinfo-old { color: #a3261f; opacity: 1; }   /* device hasn't updated (no version reported) */
.rp-devinfo-stale { color: #a3261f; opacity: 1; }  /* running engine is behind the live site */
.rp-wipe-pending { color: #8a4b10; font-weight: 600; }  /* remote wipe requested, awaiting the device */
.rp-wipe-done { color: #1f5d22; font-weight: 600; }     /* device confirmed the wipe */

/* Self-service "Delete all data" — set apart + danger-tinted so it isn't fat-fingered (it's also behind a
   confirm). Bottom of Help (editor) / the record screen (recorder), gated by deleteAllAllowed(). */
.delall-btn { display: block; margin: 28px auto 8px; color: #a3261f; border-color: #a3261f; }

/* "New version ready — exit your open text to finish updating" — shown while editing, tappable to go to
   Texts. Fixed at the BOTTOM so it never covers the top nav; below modals, above page content. */
.update-ready-banner {
  position: fixed; left: 0; right: 0; bottom: 0; width: 100%;
  z-index: 38; border: none; cursor: pointer;
  background: #b26a00; color: #fff; font-size: 14px; font-weight: 600;
  padding: 11px 14px; padding-bottom: calc(11px + env(safe-area-inset-bottom));
  text-align: center; box-shadow: 0 -2px 10px rgba(0,0,0,.28);
}
.rp-install-pending {
  flex-direction: row; align-items: center; justify-content: space-between; gap: 12px;
  background: #fdf8e9; border: 1px solid #e4c95b; border-radius: 8px; padding: 10px 12px;
}
.rp-mono { font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
.rp-fp { color: var(--blue-dark); margin-top: 2px; }
.rp-verify { margin-top: 2px; }
.rp-inv { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.rp-inv li { display: flex; align-items: center; gap: 8px; }
.rp-tag { font-size: 11px; padding: 1px 7px; border-radius: 5px; background: var(--panel); color: var(--muted); white-space: nowrap; }
.rp-tag-uploaded { background: #e3f3e4; color: #1f5d22; }
.rp-tag-changed { background: #fdf3d7; color: #6b5310; }
.rp-tag-local { background: #e8f0fc; color: var(--blue-dark); }
.rp-tag-requested { background: #ece3f7; color: #5b3d8a; }       /* request sent — in flight */
.rp-tag-slow { background: #fbe6cf; color: #8a4b10; }            /* sent, device hasn't synced yet */
.rp-tag-justUploaded { background: #cdeccf; color: #18521b; font-weight: 600; }  /* just confirmed by the device */
.rp-tag-done { background: #e3f3e4; color: #1f5d22; font-weight: 600; }  /* coworker marked the text finished */
.rp-tag-notdone { background: var(--panel); color: var(--muted); }  /* Done feature on, not yet finished */
.rp-pending-del { opacity: .5; text-decoration: line-through; }
.rp-tag-deleting { background: #fdecea; color: #9b2c22; font-weight: 600; text-decoration: none; }
/* A request the device has already picked up: no longer cancellable, so it is a TAG, not a button.
   Deliberately not styled as clickable — offering a cancel that the server will refuse is worse
   than showing none, because the researcher would believe the request was called off. */
.rp-tag-taken { background: #fdf3d7; color: #6b5310; font-weight: 600; text-decoration: none; cursor: help; }
/* The withdraw toggle. Same weight as the action it undoes, so a queued request reads as a pair. */
.rp-cancel { color: #8a4b10; font-weight: 600; }
.rp-pending-del .rp-cancel, .rp-pending-del .rp-tag-taken { text-decoration: none; opacity: 1; }

/* Admin modal — owner-only. Deliberately plainer than the dashboard: these are rare, considered
   actions, so the layout favours reading over density. */
.rp-admin-btn { font-weight: 600; }
.rp-adm-sec { margin: 4px 0 2px; }
.rp-adm-h { font-weight: 700; font-size: 15px; margin-bottom: 4px; }
.rp-adm-list { margin: 10px 0; }
.rp-adm-ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.rp-adm-ul li { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
                padding: 8px 2px; border-bottom: 1px solid var(--border); }
.rp-adm-ul li:last-child { border-bottom: none; }
.rp-adm-note { font-weight: 600; }
.rp-adm-meta { flex: 1 1 auto; }
/* The domains are one-way hashes, so this line explains an otherwise baffling UI: a list that
   cannot show you what is in it. Stated up front rather than left to be discovered. */
.rp-adm-privacy { border-left: 3px solid var(--border); padding-left: 10px; margin: 10px 0 16px; }
.rp-adm-say { margin-top: 10px; padding: 9px 11px; border-radius: 8px; font-size: 14px;
              background: var(--panel); white-space: pre-wrap; }
.rp-adm-say[hidden] { display: none; }
/* Approval log — append-only, so it only grows; scroll it inside the modal. */
.rp-adm-log { margin-top: 8px; max-height: 46vh; overflow-y: auto; }
.rp-adm-logul li { align-items: baseline; }
.rp-log-k { flex: none; }
.rp-log-k-account_signup { background: #e8f0fc; color: var(--blue-dark); }
.rp-log-k-account_auto_approved { background: #e3f3e4; color: #1f5d22; }
.rp-log-k-account_approved { background: #cdeccf; color: #18521b; font-weight: 600; }
.rp-log-k-account_declined { background: #fdecea; color: #9b2c22; font-weight: 600; }
.rp-log-k-domain_added { background: #ece3f7; color: #5b3d8a; }
.rp-log-k-domain_removed { background: #fbe6cf; color: #8a4b10; }
/* States what the log actually covers. Without it, a gap reads as a bug rather than as
   "that happened before I was watching". */
.rp-hist-since { border-left: 3px solid var(--border); padding-left: 10px; margin: 6px 0 12px; }
.rp-adm-ok { background: #e3f3e4; color: #1f5d22; }
.rp-adm-err { background: #fdecea; color: #9b2c22; }

/* (5) The text row, restructured: title + state chip on line one, muted metadata on line two,
   actions grouped on the right. Replaces the single crowded line of text + inline hyperlinks. */
.rp-text-row { display: flex; align-items: flex-start; gap: 10px; padding: 8px 2px;
               border-bottom: 1px solid var(--border); }
.rp-inv .rp-text-row:last-child { border-bottom: none; }
.rp-text-main { flex: 1 1 auto; min-width: 0; }
.rp-text-title { font-weight: 600; overflow-wrap: anywhere; }
.rp-text-title .rp-tag { margin-left: 6px; }
.rp-text-meta { margin-top: 1px; }
.rp-text-meta:empty { display: none; }
.rp-text-actions { flex: none; display: flex; align-items: center; gap: 2px; white-space: nowrap; }
.rp-text-actions .link-btn { padding: 6px 7px; }
/* The pending-delete strikethrough hits the TITLE, not the action buttons — a struck-through
   "Cancel removal" would read as disabled, which is the opposite of what it is. */
.rp-pending-del .rp-text-title { text-decoration: line-through; }
.rp-pending-del .rp-text-actions { text-decoration: none; opacity: 1; }
/* The download-all entry is a <button> restyled to sit in the menu like the links above it. */
.rp-dl-all { appearance: none; border: none; background: none; width: 100%; text-align: left;
             font: inherit; cursor: pointer; border-top: 1px solid var(--border); margin-top: 4px;
             padding-top: 10px; }
.rp-dl-all:disabled { opacity: .6; cursor: wait; }
.rp-dl-loading { display: block; padding: 6px 8px; }
/* History rows carry the same Files control; give it breathing room under the meta line. */
.rp-hist-links .rp-dl { display: inline-block; }
/* Cleanup entry: visually a caution, not a download. */
.rp-dl-clean .rp-dl-name { color: #8a4b10; }
/* In-flight move chip + the clickable done tag. */
.rp-tag-moving { background: #ece3f7; color: #5b3d8a; font-weight: 600; }
.rp-tag-btn { appearance: none; border: none; cursor: pointer; font: inherit; font-size: 11px; }
.rp-tag-btn:hover { outline: 1px solid currentColor; }
.rp-move-opt { display: flex; align-items: center; gap: 8px; }
.rp-histclean { font-size: 13px; }
.rp-log-k-files_trashed { background: #fbe6cf; color: #8a4b10; }
.rp-log-k-text_moved { background: #e8f0fc; color: var(--blue-dark); }

/* Downloads dropdown on a text row. Anchored to the row, floating above it — the inventory list is
   dense, so an inline expansion would shove every following row down on hover. */
.rp-dl { position: relative; display: inline-block; }
.rp-dl-btn { white-space: nowrap; }
.rp-dl-caret { font-size: 9px; opacity: .7; }
.rp-dl-menu {
  position: absolute; z-index: 30; top: calc(100% + 4px); left: 0;
  min-width: 244px; max-width: min(320px, 80vw);
  display: flex; flex-direction: column;
  background: var(--card, #fff); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0,0,0,.18); padding: 6px;
  /* ⚠ ALWAYS drop DOWNWARD, and scroll when tall. An earlier version flipped the menu upward on
     the last row to avoid overflowing the card — which broke exactly when it mattered: with all
     six artifact kinds the menu is ~400px, so flipping up ran it off the TOP of the viewport and
     clipped the first entries. Caught by screenshotting it, not by reading the CSS. */
  max-height: 60vh; overflow-y: auto;
}
.rp-dl-menu[hidden] { display: none; }
.rp-dl-head { font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
              color: var(--muted); padding: 4px 8px 6px; }
.rp-dl-item { display: block; padding: 7px 8px; border-radius: 7px; text-decoration: none; color: inherit; }
.rp-dl-item:hover, .rp-dl-item:focus-visible { background: var(--panel); text-decoration: none; }
.rp-dl-name { display: block; font-weight: 600; font-size: 14px; color: var(--blue-dark); }
/* The sub-line carries the PURPOSE ("import into FLEx", "annotation file, tiers named for
   SayMore") — it is what makes two .eaf exports distinguishable at a glance. */
.rp-dl-sub { display: block; font-size: 12px; color: var(--muted); margin-top: 1px; }

/* History modal — the back-log of texts that are no longer on a device. The kind colours REUSE the
   dashboard's tag palette above on purpose: "uploaded" must look the same here as it does on a live
   row, or the two views read as two unrelated systems. */
.rp-hist-filters { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 12px; }
.rp-hist-f { padding: 4px 10px; border-radius: 999px; }
.rp-hist-f.is-on { background: var(--blue); color: #fff; }
.rp-hist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px;
           /* The log grows without bound; scroll it INSIDE the modal so the filters and the
              Clear/Close buttons never get pushed out of reach. */
           max-height: 55vh; overflow-y: auto; }
.rp-hist-row { padding: 9px 2px; border-bottom: 1px solid var(--border); }
.rp-hist-row:last-child { border-bottom: none; }
.rp-hist-head { display: flex; align-items: baseline; gap: 8px; }
.rp-hist-title { font-weight: 600; overflow-wrap: anywhere; }
.rp-hist-k { flex: none; }
.rp-hist-k-assigned { background: #e8f0fc; color: var(--blue-dark); }
.rp-hist-k-submitted { background: #e3f3e4; color: #1f5d22; }
.rp-hist-k-done { background: #cdeccf; color: #18521b; font-weight: 600; }
.rp-hist-k-deleted { background: #fdecea; color: #9b2c22; font-weight: 600; }
.rp-hist-meta { margin-top: 2px; }
.rp-hist-links { margin-top: 4px; display: flex; flex-wrap: wrap; gap: 12px; font-size: 13px; }
.rp-hist-empty { padding: 18px 2px; }
/* A deleted text is GONE — fade the row so the log reads at a glance, but never strike the title
   through: unlike the dashboard's pending-delete row, this is a record, not an in-flight action. */
.rp-hist-deleted .rp-hist-title { color: var(--muted); }
/* Loud, plain-language warning at the top of a settings group (e.g. website-installed
   devices cannot make archive-quality recordings). Deliberately hard to miss. */
.rp-notice { border: 1px solid #e0b892; border-left: 5px solid #c9772a; background: #fdf6ee;
             border-radius: 9px; padding: 12px 14px; margin-bottom: 18px; font-size: 14px; }
.rp-notice > b { display: block; margin-bottom: 6px; font-size: 15px; color: #8a4b10; }
.rp-notice p { margin: 7px 0; }
.rp-notice p:last-child { margin-bottom: 0; }
/* Compact variant for use inside a modal (e.g. the assignment dialog). */
.rp-notice-sm { font-size: 13px; padding: 10px 12px; margin: 4px 0 14px; }
.rp-notice-sm > b { font-size: 14px; }
.rp-notice-sm code { background: rgba(0,0,0,.06); padding: 1px 4px; border-radius: 4px; }
.rp-as-status { margin: 8px 0 4px; font-size: 13px; line-height: 1.4; white-space: pre-wrap; }
.rp-as-status.rp-as-ok { color: #1f5d22; }
.rp-as-status.rp-as-err { color: #a3261f; }
.rp-probe-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: -2px 0 10px; }
.rp-probe-result { flex-basis: 100%; font-size: 13px; line-height: 1.4; }
.rp-probe-result.rp-as-ok { color: #1f5d22; }
.rp-probe-result.rp-as-err { color: #a3261f; }
.rp-doclink { display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px; border-radius: 50%; background: var(--panel); color: var(--muted); font-weight: 700; font-size: 12px; text-decoration: none; border: 1px solid var(--border, #ccc); }
.rp-inst-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.rp-revoke { color: #a3261f; }
.rp-empty { text-align: center; padding: 20px; }
.rp-linkbox { width: 100%; box-sizing: border-box; font-family: ui-monospace, Menlo, monospace; font-size: 13px; border: 1px solid var(--border); border-radius: 6px; padding: 8px; }

.rp-tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin: 6px 0 12px; overflow-x: auto; flex: 0 0 auto; }
/* The settings modal is a flex-column card with a max-height. Keep the tab bar + chrome from being
   shrunk to nothing (the tab row's overflow-x:auto otherwise lets flexbox collapse it to ~1px when a
   group is taller than the card); scroll the fields area instead so every tab stays reachable. */
.rp-set-head, .rp-enc { flex: 0 0 auto; }
.rp-groups { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.rp-tab { appearance: none; border: none; background: none; padding: 8px 12px; font-size: 14px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.rp-tab.on { color: var(--blue-dark); border-bottom-color: var(--blue); font-weight: 600; }
.rp-fieldset { border: 1px solid var(--border); border-radius: 9px; padding: 10px 14px 14px; display: flex; flex-direction: column; gap: 10px; margin: 0; }
.rp-fieldset legend { font-weight: 600; font-size: 14px; padding: 0 6px; }
.rp-multi { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.check-label.rp-inline { display: inline-flex; margin: 0; max-width: none; }
.rp-enc { color: var(--muted); margin: 6px 0; }

@media (max-width: 560px) {
  .rp-metrics { grid-template-columns: repeat(2, 1fr); }
  .rp-install-pending { flex-direction: column; align-items: stretch; }
  .rp-head { margin: -12px calc(-1 * clamp(10px, 3vw, 28px)) 12px; }
}

/* ---------------- Crowd mode (public crowd-source recorder) ---------------- */
.crowd-screen { text-align: center; }
.crowd-status { font-size: 1.15rem; margin: 18px 0; }
.crowd-thanks {
  width: 72px; height: 72px; line-height: 72px; margin: 24px auto 8px;
  border-radius: 50%; background: var(--ok, #2e7d32); color: #fff;
  font-size: 2rem; text-align: center;
}
.crowd-note { margin-top: 10px; }
/* Turnstile host: invisible in managed mode; if a challenge ever shows it floats
   bottom-center where an embedded iframe can still display it. */
#crowd-turnstile { position: fixed; bottom: 12px; left: 50%; transform: translateX(-50%); z-index: 60; }
/* Embedded (?embed=1): tighter chrome inside a ~480px iframe. */
.crowd-embed #topbar { display: none; }
.crowd-embed .record-screen { padding-top: 8px; }
.crowd-embed .record-welcome { font-size: 1.05rem; margin: 6px 0 14px; }

/* Crowd recorders (researcher panel) */
.rp-crowd-budget { display: inline-block; background: #fbe6cf; color: #8a4b10; border-radius: 6px; padding: 3px 8px; }   /* amber, matches rp-tag-slow palette */
.rp-subs-scroll { overflow-x: auto; }   /* submissions table can outgrow the modal on phones */
/* Disabled link-button (e.g. "Remove from device" gated until the device engine reaches v94) */
.link-btn:disabled { color: var(--muted); cursor: not-allowed; opacity: .6; }
.rp-est-over { color: #a03b00; font-weight: 600; }   /* crowd size estimate exceeding the platform cap */
#cr-maxsec { width: 100%; }
/* Embed mode: html/body/main stretch to 100% height by default, which makes the
   auto-size measurement read "frame height" forever (a one-way ratchet). Let the
   embedded page be exactly as tall as its content. */
.crowd-embed, .crowd-embed body { height: auto; min-height: 0; }
.crowd-embed main { flex: none; height: auto; min-height: 0; }

/* Embed mode: a fixed-overlay modal is a full-page idiom — inside a content-sized
   iframe it can sit half outside the visitor's real viewport. Modals become
   IN-FLOW cards instead: they appear right in the widget, push the frame taller
   (the auto-height messages follow), and are always fully visible. */
.crowd-embed .modal { position: static; inset: auto; background: none; display: block; padding: 0; z-index: auto; }
.crowd-embed .modal-card { margin: 12px auto; width: auto; max-width: 420px; box-shadow: 0 2px 14px rgba(0,0,0,.18); border: 1px solid var(--border); }
/* While a step-card is open, the big Record button yields to it (graceful where :has is unsupported). */
.crowd-embed:has(.modal:not([hidden])) .record-big { display: none; }
/* "more info…" sits on the fieldset border at the RIGHT, mirroring how the legend
   sits on it at the left (a <legend> itself can't flex-justify its contents). */
.rp-fieldset { position: relative; }
.rp-group > .rp-field { margin-bottom: 28px; }   /* breathing room between an outside field (App language) and the codes box */
.rp-legend-help { position: absolute; top: 0; right: 12px; transform: translateY(-55%); background: #fff; padding: 0 6px; font-size: 13px; white-space: nowrap; }
.invite-paste-box { width: 100%; box-sizing: border-box; font-size: 14px; padding: 8px; border: 1px solid var(--border); border-radius: 8px; }

/* "Recorded with: a USB microphone" under the review player. Informational by default; only turns
   warning-coloured when the capture is genuinely not archive grade, so the colour keeps meaning. */
.record-capture-info { margin-top: 6px; font-size: 13px; color: #5b6b7a; }
.record-capture-info.capture-warn { color: #a3261f; font-weight: 600; }

/* ============ Paragraph Analysis satellite (window.__MODE='paragraph') ============
   All classes are pa-* and used ONLY by js/paragraph-ui.js. The bracket tree is structural:
   each .pa-group nests its children, and its LEFT BORDER is the bracket — levels, spans and
   collapse come from the DOM with no absolute-position bookkeeping. */

#pa-main { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.pa-open { max-width: 640px; margin: 8vh auto 0; padding: 0 16px; text-align: center; }
.pa-open h1 { font-size: 26px; margin-bottom: 6px; }
.pa-drop { border: 2px dashed var(--border); border-radius: 14px; padding: 36px 20px; margin: 18px 0; background: var(--panel); }
.pa-drop.over { border-color: var(--blue); background: #e8f0fb; }
.pa-drop .primary-btn { margin-top: 10px; }

.pa-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 8px 12px; border-bottom: 1px solid var(--border); background: var(--panel); position: sticky; top: 0; z-index: 30; }
.pa-title { font-weight: 700; max-width: 26ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pa-tools, .pa-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pa-actions { margin-left: auto; }
.pa-inline { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }

.pa-player { position: sticky; top: 46px; z-index: 29; background: var(--bg); border-bottom: 1px solid var(--border); padding: 6px 12px; }
.pa-ovwrap { position: relative; height: 48px; }
.pa-ovwrap canvas { width: 100%; height: 100%; display: block; touch-action: none; cursor: pointer; }
.pa-cur { position: absolute; top: 0; bottom: 0; width: 2px; background: #c33; pointer-events: none; }
.pa-transport { display: flex; align-items: center; gap: 10px; margin-top: 2px; }

.pa-tree { flex: 1; overflow: auto; padding: 10px 14px 40vh; }
.pa-row { display: flex; align-items: flex-start; gap: 8px; padding: 6px 8px; border-radius: 8px; cursor: pointer; }
.pa-row.on { background: #eef4ff; }
.pa-row.sel, .pa-group.sel > .pa-badge { background: #dbe7fa; outline: 2px solid var(--blue); outline-offset: -2px; }
.pa-cell { flex: 1; min-width: 0; }
.pa-wave { width: 100%; height: 44px; display: block; touch-action: none; cursor: pointer; }
.pa-wave-sm { height: 14px; }
.pa-baseline { font-size: 17px; color: var(--vern); }
.pa-words { display: flex; flex-wrap: wrap; gap: 2px 12px; }
.pa-words .w { display: inline-flex; flex-direction: column; }
.pa-words .wt { color: var(--vern); font-size: 16px; }
.pa-words .wg { color: var(--gloss); font-size: 13px; }
.pa-words .punct .wt { color: var(--muted); }
.pa-free { color: var(--text); font-size: 14px; margin-top: 2px; font-style: italic; }
.pa-rowplay { flex: none; width: 30px; height: 30px; border: 1px solid var(--border); border-radius: 50%; background: var(--bg); cursor: pointer; font-size: 13px; line-height: 1; }
.pa-rowplay:hover { border-color: var(--blue); color: var(--blue); }

/* The bracket: one nested container per group; deeper levels indent naturally. */
.pa-group { border-left: 3px solid var(--blue); border-radius: 6px 0 0 6px; margin: 6px 0 6px 2px; padding-left: 8px; }
.pa-group.pa-head, .pa-row.pa-head { box-shadow: inset 3px 0 0 var(--gloss); }
/* The group HEADING is the group's handle: clicking it selects the group, and Edit/Ungroup act on
   exactly that. So it has to LOOK like a control — a bar with its own surface and a hover state —
   not like a caption (users could not find it when it was plain text). */
.pa-badge { display: flex; align-items: center; gap: 6px; padding: 3px 6px; border-radius: 6px; cursor: pointer; font-size: 13px; color: var(--muted); background: var(--panel); border: 1px solid transparent; }
.pa-badge:hover { border-color: var(--border); background: #e9eff8; }
.pa-closebtn { margin-left: 10px; }
.pa-closebtn:hover { border-color: #a3261f; color: #a3261f; }
.pa-selinfo { font-size: 12px; color: var(--muted); max-width: 24ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* "+ Add" = a sticky stand-in for Shift/Ctrl/Cmd, so touch screens can multi-select at all. */
.pa-multi.on { background: var(--blue); border-color: var(--blue); color: #fff; }
.pa-tip { margin: 0; padding: 5px 14px; font-size: 12.5px; color: var(--muted); background: var(--panel); border-bottom: 1px solid var(--border); }
.pa-caret { border: none; background: none; cursor: pointer; font-size: 13px; padding: 0 2px; color: var(--muted); }
.pa-jt { font-weight: 700; color: var(--blue); }
.pa-rel { font-weight: 600; color: var(--text); }
.pa-rel-empty { font-weight: 400; font-style: italic; }
.pa-summary { padding: 2px 8px 2px 24px; font-style: italic; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Group/edit dialog */
#pa-dialog { position: fixed; inset: 0; background: rgba(20,26,34,.45); z-index: 60; display: flex; align-items: center; justify-content: center; padding: 16px; }
.pa-modal { background: var(--bg); border-radius: 12px; padding: 18px 20px; width: min(440px, 94vw); box-shadow: 0 6px 30px rgba(0,0,0,.25); }
.pa-modal h3 { margin-bottom: 10px; }
.pa-modal-body { display: flex; flex-direction: column; gap: 10px; }
.pa-field { display: flex; flex-direction: column; gap: 4px; }
.pa-field > span { font-size: 13px; color: var(--muted); }
.pa-field select, .pa-field input { padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; font-size: 15px; }
.pa-modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

/* Member list inside the join dialog: HEAD choice + each member's own label, in reading order.
   The head column disappears entirely for a symmetrical join (which has no head by definition). */
.pa-labelhint { margin: 2px 0 0; }
.pa-members { display: flex; flex-direction: column; gap: 4px; max-height: 40vh; overflow: auto; }
.pa-member { display: grid; grid-template-columns: 3.2em minmax(0, 1fr) 12ch; gap: 8px; align-items: center; }
.pa-members.no-head .pa-member { grid-template-columns: minmax(0, 1fr) 12ch; }
.pa-members.no-head .pa-headpick { display: none; }
.pa-headpick { display: flex; justify-content: center; }
.pa-memhead { font-size: 12px; color: var(--muted); }
.pa-memtext { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.pa-memlabel { min-width: 0; padding: 5px 7px; border: 1px solid var(--border); border-radius: 7px; font-size: 14px; }

/* A member's ROLE label, shown at the left edge of that member in the tree (the SSA convention:
   relation labels in a column beside each unit). Sits before the caret/play button so the labels
   line up down the page. */
.pa-nodelabel {
  flex: none; align-self: flex-start; margin-top: 2px;
  font-size: 12px; font-weight: 600; color: var(--blue-dark);
  background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 1px 6px;
  max-width: 16ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
