/* =====================================================================
   📝 ANSWERING A LEFT QUESTION — the teacher's recorder (consult-answer.js)

   ONE stylesheet, byte for byte the same in polymathlc/tutor,
   polymathlc/anskey, polymathlc/cer and polymathlc/math, because the
   module it styles is too. Every
   measurement leans on the family's own tokens (both apps declare the
   same --ink / --line / --accent / --radius set), with a fallback so a
   page without them still reads.

   The window is a full-screen sheet ABOVE everything else in either app
   (the consult room is 1400 here, Ans Key's highest modal 1200), because
   it is a recording studio: a toast or a pop-up landing over the page
   while the camera is rolling would be in the video. It never prints.
   ===================================================================== */

.caBack {
  position: fixed;
  inset: 0;
  z-index: 1500;
  background: rgba(20, 20, 18, 0.46);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  font-family: var(--font, 'Century Gothic', 'Segoe UI', sans-serif);
  color: var(--ink, #1A1A1A);
  animation: caFade 0.18s ease-out both;
}
@keyframes caFade { from { opacity: 0; } to { opacity: 1; } }
/* The sheet takes focus so Escape reaches it; the ring would be drawn round
   the whole screen, which says nothing. The buttons inside keep theirs. */
.caBack:focus { outline: none; }

.caCard {
  width: min(1240px, 100%);
  height: min(860px, 100%);
  background: var(--bg, #FFFFFF);
  border: 1px solid var(--line, #ECECEA);
  border-radius: var(--radius, 14px);
  box-shadow: var(--shadow-modal, 0 10px 30px rgba(0,0,0,0.12));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  outline: none;
}

/* ---------------- The heading ---------------- */
.caHead {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 20px 14px;
  border-bottom: 1px solid var(--line, #ECECEA);
}
.caWho { flex: 1 1 auto; min-width: 0; }
.caTitle {
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.caWhere {
  margin-top: 3px;
  font-size: 0.8rem;
  color: var(--ink-faint, #8A8A84);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.caClose { flex: 0 0 auto; }

/* ---------------- The body: tools beside the page ---------------- */
.caBody {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  gap: 0;
}
.caSide {
  flex: 0 0 320px;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 20px 20px;
  border-right: 1px solid var(--line, #ECECEA);
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.caLabel {
  display: block;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint, #8A8A84);
  margin-bottom: 6px;
}

.caQuestion {
  background: var(--bg-viewer, #F7F6F3);
  border: 1px solid var(--line, #ECECEA);
  border-radius: var(--radius-sm, 10px);
  padding: 12px 14px;
}
.caQText {
  font-size: 0.95rem;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.caDone {
  background: #EEF7EE;
  border: 1px solid #CFE7CF;
  border-radius: var(--radius-sm, 10px);
  padding: 10px 14px;
}
.caHint {
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--ink-soft, #55554F);
}

.caTools { display: flex; flex-direction: column; gap: 14px; }

/* the pens: a swatch you can see, lit when it is the one in hand */
.caPens { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.caPens .caPen {
  width: 32px; height: 32px;
  min-width: 32px;
  padding: 0;
  border-radius: 50%;
  background: var(--pen, #E5484D);
  border: 3px solid var(--bg, #FFFFFF);
  box-shadow: 0 0 0 1px var(--line, #ECECEA);
  cursor: pointer;
}
.caPens .caPen.on { box-shadow: 0 0 0 2px var(--ink, #1A1A1A); }
.caPens .caUndo, .caPens .caClear { margin-left: 2px; }

.caCamRow { display: flex; gap: 8px; }
.caCamBtn.on { background: var(--accent, #FFE0B2); border-color: var(--accent-strong, #FFCC80); }

.caNote {
  display: block;
  width: 100%;
  box-sizing: border-box;
  margin-top: 2px;
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.45;
  color: var(--ink, #1A1A1A);
  background: var(--bg, #FFFFFF);
  border: 1px solid var(--line, #ECECEA);
  border-radius: var(--radius-sm, 10px);
  padding: 9px 11px;
  resize: vertical;
  text-transform: none;
  letter-spacing: normal;
  font-weight: 400;
}
.caNote:focus { outline: 2px solid var(--accent-strong, #FFCC80); outline-offset: 1px; }

.caRecRow { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.caRec.recording {
  background: var(--danger, #E53935);
  border-color: var(--danger, #E53935);
  color: #FFFFFF;
}
.caRec.recording::before {
  content: '';
  display: inline-block;
  width: 8px; height: 8px;
  margin-right: 7px;
  border-radius: 50%;
  background: #FFFFFF;
  vertical-align: middle;
  animation: caBlink 1.2s ease-in-out infinite;
}
@keyframes caBlink { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }
.caClock {
  font-variant-numeric: tabular-nums;
  font-size: 0.95rem;
  color: var(--ink-soft, #55554F);
}

.caReview { display: flex; flex-direction: column; gap: 10px; }
.caReview[hidden] { display: none; }
.caPlayback {
  width: 100%;
  max-height: 220px;
  background: #111;
  border-radius: var(--radius-sm, 10px);
}

.caStatus {
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--ink-soft, #55554F);
}

/* ---------------- The page being written on ---------------- */
.caStageWrap {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: var(--bg-viewer, #F3F2F0);
}
.caStage {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  background: #FFFFFF;
  border-radius: 6px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 6px 18px rgba(0,0,0,0.08);
  cursor: crosshair;
  touch-action: none;
}
.caRecording .caStage { box-shadow: 0 0 0 3px var(--danger, #E53935), 0 6px 18px rgba(0,0,0,0.12); }

/* the camera preview — mirrored for the teacher, never in the file */
.caCamPreview {
  position: absolute;
  right: 26px; bottom: 26px;
  width: 168px;
  border-radius: 10px;
  background: #111;
  box-shadow: 0 2px 10px rgba(0,0,0,0.25);
  transform: scaleX(-1);
  pointer-events: none;
}
.caCamPreview[hidden] { display: none; }
/* opacity, never display:none — a video that is not displayed may stop
   handing frames to the canvas the recording draws it into */
.caRecording .caCamPreview { opacity: 0; }

/* ---------------- 📚 The archive: the teacher's list, the student's shelf ----------------
   A centred window rather than a full-screen sheet — it is a list to read,
   not a studio. It sits UNDER the recorder (1500), so 📝 Answer from the
   list opens over it, and the player sits over the list. */
.caLogBack, .caPlayBack {
  position: fixed;
  inset: 0;
  z-index: 1450;
  background: rgba(20, 20, 18, 0.40);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  font-family: var(--font, 'Century Gothic', 'Segoe UI', sans-serif);
  color: var(--ink, #1A1A1A);
  animation: caFade 0.18s ease-out both;
}
.caPlayBack { z-index: 1460; background: rgba(20, 20, 18, 0.62); }
.caLogBack:focus, .caPlayBack:focus { outline: none; }
.caLogCard, .caPlayCard {
  width: min(760px, 100%);
  max-height: min(820px, 100%);
  background: var(--bg, #FFFFFF);
  border: 1px solid var(--line, #ECECEA);
  border-radius: var(--radius, 14px);
  box-shadow: var(--shadow-modal, 0 10px 30px rgba(0,0,0,0.12));
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.caPlayCard { width: min(900px, 100%); }
.caLogCard .caWhere { white-space: normal; }

.caLogBar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line, #ECECEA);
}
.caChips { display: flex; flex-wrap: wrap; gap: 6px; }
.caChip.btn { border-radius: 999px; }
.caChip.on {
  background: var(--accent, #1F6F78);
  border-color: var(--accent, #1F6F78);
  color: #FFFFFF;
}
.caSearch {
  flex: 1 1 200px;
  min-width: 0;
  padding: 8px 12px;
  font: inherit;
  font-size: 0.9rem;
  border: 1px solid var(--line, #ECECEA);
  border-radius: 10px;
  background: var(--bg, #FFFFFF);
  color: inherit;
}

/* The list scrolls; the heading and the search stay where they are.
   min-height: 0, or a flex child refuses to shrink and never scrolls. */
.caLogList {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 14px 20px 20px;
  -webkit-overflow-scrolling: touch;
}
.caLogList > * + * { margin-top: 10px; }
.caEmpty {
  margin: 28px 8px;
  text-align: center;
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--ink-faint, #8A8A84);
}
.caLibHead {
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint, #8A8A84);
  padding: 6px 2px 0;
}
.caLibHead:not(:first-child) { margin-top: 18px; }
.caLogRow {
  padding: 13px 15px;
  border: 1px solid var(--line, #ECECEA);
  border-radius: 12px;
  background: var(--bg, #FFFFFF);
}
.caLogRow.caFresh, .caLogRow.caState-ringing, .caLogRow.caState-question {
  border-color: rgba(31, 111, 120, 0.45);
  background: rgba(31, 111, 120, 0.05);
}
.caLogTop { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; }
.caLogWho { font-weight: 700; font-size: 0.95rem; min-width: 0; overflow-wrap: anywhere; }
.caLogWhen { margin-left: auto; font-size: 0.78rem; color: var(--ink-faint, #8A8A84); white-space: nowrap; }
.caPill {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 999px;
  background: #F1F1EE;
  color: #55554F;
  white-space: nowrap;
}
.caPill-ringing, .caPill-live { background: #DCFCE7; color: #166534; }
.caPill-question, .caPill-later { background: #FEF3C7; color: #92400E; }
.caPill-answered { background: #DBEAFE; color: #1E40AF; }
.caPill-missed { background: #FEE2E2; color: #991B1B; }
.caLogWhere { margin-top: 4px; font-size: 0.8rem; color: var(--ink-faint, #8A8A84); overflow-wrap: anywhere; }
.caLogQ { margin-top: 8px; font-size: 0.9rem; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.caLogNote { margin-top: 6px; font-size: 0.84rem; line-height: 1.5; color: #55554F; white-space: pre-wrap; overflow-wrap: anywhere; }
.caMuted { color: var(--ink-faint, #8A8A84); font-size: 0.84rem; }
.caLogActs { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 11px; }
/* 🗑 Delete sits apart, on the right, so it is never the button a hand
   reaches for when it means ▶ Watch or Join. Asking turns the row red. */
.caLogActs .caDel { margin-left: auto; color: #991B1B; }
.caLogActs .caDel:hover { background: #FEE2E2; border-color: #FCA5A5; }
.caLogRow.caAsking { border-color: #FCA5A5; background: #FEF2F2; }
.caDelAsk { flex: 1 1 220px; font-size: 0.86rem; line-height: 1.45; color: #991B1B; font-weight: 600; }
.caLogActs .caDelYes { background: var(--danger, #E53935); border-color: var(--danger, #E53935); color: #FFFFFF; font-weight: 700; }
.caLogActs .caDelYes:hover { filter: brightness(0.94); }

/* ---------------- The player ---------------- */
.caPlayMedia {
  display: block;
  width: 100%;
  max-height: 64vh;
  background: #000000;
}
audio.caPlayMedia { background: transparent; margin: 16px 0 4px; }
.caPlayQ, .caPlayNote {
  margin: 0;
  padding: 12px 20px 0;
  font-size: 0.9rem;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.caPlayNote { color: #55554F; }
.caPlayCard > :last-child { padding-bottom: 18px; }

/* ---------------- Phones and narrow tablets ---------------- */
@media (max-width: 820px) {
  .caBack { padding: 0; }
  .caCard { width: 100%; height: 100%; border-radius: 0; border: 0; }
  .caBody { flex-direction: column; }
  .caSide {
    flex: 0 0 auto;
    max-height: 46%;
    border-right: 0;
    border-bottom: 1px solid var(--line, #ECECEA);
    order: 2;
  }
  .caStageWrap { order: 1; padding: 10px; }
  .caCamPreview { width: 110px; right: 16px; bottom: 16px; }
  .caLogBack, .caPlayBack { padding: 0; }
  .caLogCard, .caPlayCard { width: 100%; max-height: 100%; height: 100%; border-radius: 0; border: 0; }
  .caLogBar, .caLogList { padding-left: 16px; padding-right: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .caBack, .caLogBack, .caPlayBack, .caRec.recording::before { animation: none; }
}

@media print {
  .caBack, .caLogBack, .caPlayBack { display: none !important; }
}

/* ---- ✍️ Asking from the window (Ans Key and the two portals) ---- */
.caAsk {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 20px 14px;
  border-bottom: 1px solid var(--line, #ECECEA);
  background: var(--bg, #FFFFFF);
}
.caAskText {
  width: 100%;
  box-sizing: border-box;
  min-height: 72px;
  resize: vertical;
  padding: 10px 12px;
  font: inherit;
  font-size: 0.95rem;
  color: var(--ink, #1A1A1A);
  background: var(--bg, #FFFFFF);
  border: 1px solid var(--line, #ECECEA);
  border-radius: var(--radius-sm, 10px);
}
.caAskText:focus { outline: 2px solid var(--accent-strong, #FFCC80); outline-offset: 1px; }
.caAskRow { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.caAskRow .btnPrimary { margin-left: auto; }
.caAskThumb { display: inline-flex; align-items: center; gap: 4px; }
.caAskThumb img {
  height: 44px;
  max-width: 90px;
  object-fit: cover;
  border: 1px solid var(--line, #ECECEA);
  border-radius: 6px;
}
.caAskSaid { min-height: 1.2em; font-size: 0.85rem; color: var(--ink-soft, #55554F); }

/* ---- 🌐 In the Science and Maths portals ----
   Those two pages have their own design tokens under the same names
   (a dark sidebar, other accents) and none of the `.btn` family. The bridge
   puts `caPortal` on <html>, and every consult window then carries its own
   tokens and buttons, so it looks the same as in Study Buddy and Ans Key
   whatever the page around it calls `--bg`. */
.caPortal .caBack, .caPortal .caLogBack, .caPortal .caPlayBack {
  --bg: #FFFFFF; --bg-viewer: #F4F3F0;
  --ink: #1A1A1A; --ink-soft: #55554F; --ink-faint: #8A8A84;
  --accent: #FFE0B2; --accent-strong: #FFCC80;
  --line: #ECECEA; --danger: #C62828;
  --radius: 14px; --radius-sm: 10px;
  --font: 'Century Gothic', 'Segoe UI', sans-serif;
  --shadow-modal: 0 10px 30px rgba(0,0,0,0.12);
  line-height: 1.4;
  text-align: left;
}
.caPortal .caBack .btn, .caPortal .caLogBack .btn, .caPortal .caPlayBack .btn {
  font-family: var(--font); font-size: 0.88rem; font-weight: 600;
  color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 10px 16px; cursor: pointer;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
  width: auto; height: auto; line-height: 1.2;
}
.caPortal .caBack .btn:disabled, .caPortal .caLogBack .btn:disabled, .caPortal .caPlayBack .btn:disabled { opacity: .5; cursor: default; }
.caPortal .caBack .btnSm, .caPortal .caLogBack .btnSm, .caPortal .caPlayBack .btnSm { padding: 6px 12px; font-size: 0.8rem; }
.caPortal .caBack .btnPrimary, .caPortal .caLogBack .btnPrimary, .caPortal .caPlayBack .btnPrimary { background: var(--accent); border-color: var(--accent-strong); }
.caPortal .caBack .btnGhost, .caPortal .caLogBack .btnGhost, .caPortal .caPlayBack .btnGhost { background: transparent; box-shadow: none; }
.caPortal .caBack .btnDanger, .caPortal .caLogBack .btnDanger { color: var(--danger); }
.caPortal .caBack .caPens .caPen { width: 32px; height: 32px; padding: 0; border-radius: 50%; background: var(--pen, #E5484D); border: 3px solid var(--bg); box-shadow: 0 0 0 1px var(--line); }
.caPortal .caBack .caPens .caPen.on { box-shadow: 0 0 0 2px var(--ink, #1A1A1A); }
.caPortal .caLogBack .caChip.on { background: #1F6F78; border-color: #1F6F78; color: #FFFFFF; }
