/* ---- Group Jam ------------------------------------------------------

   Two surfaces: a host control pane and a student HUD. Both are fixed
   panels rather than part of the quiz flow, because the quiz page they
   sit over is the same page a student uses alone — nothing about its
   layout changes when a jam starts.

   All animation is CSS. A requestAnimationFrame loop driving a meter is
   one more thing to stop when the room closes, and this way the meter
   keeps animating correctly even while the main thread is busy scoring.
   Everything respects prefers-reduced-motion at the bottom of the file. */

.jam-host-pane {
  position: fixed;
  /* Clear of the annotation toolbar, which is docked to the right edge —
     at 18px the pane sits underneath it and its buttons are unreachable. */
  right: 96px;
  bottom: 18px;
  width: 320px;
  max-height: 70vh;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 10px 34px rgba(20, 16, 30, 0.16);
  z-index: 9996;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-size: 13.5px;
}
.jam-host-head {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}
.jam-host-head strong { font-size: 14px; }
.jam-host-body { padding: 12px 16px; overflow-y: auto; flex: 1; }
.jam-host-foot { padding: 12px 16px; border-top: 1px solid var(--border); }

/* "X of Y locked in" — the number the host actually watches, so it gets
   to be the biggest thing in the pane. */
.jam-tally {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}
.jam-tally-num { font-size: 26px; font-weight: 700; color: var(--purple-dark); line-height: 1; }
.jam-tally-label { font-size: 12.5px; color: var(--text-muted); }
.jam-tally-bar {
  height: 7px;
  border-radius: 999px;
  background: var(--purple-track);
  overflow: hidden;
  margin: 9px 0 14px;
}
.jam-tally-bar > span {
  display: block;
  height: 100%;
  background: var(--purple);
  border-radius: 999px;
  transition: width .35s cubic-bezier(.2,.8,.2,1);
}

.jam-peer {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
}
.jam-peer:last-child { border-bottom: none; }
.jam-peer-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-muted); flex: none;
}
.jam-peer.online .jam-peer-dot { background: var(--green-text); }
.jam-peer.answered .jam-peer-dot { background: var(--purple); }
.jam-peer-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.jam-peer-score { font-weight: 700; color: var(--purple-dark); font-variant-numeric: tabular-nums; }
.jam-peer-state { font-size: 11.5px; color: var(--text-muted); }

.jam-empty { color: var(--text-muted); font-size: 12.5px; line-height: 1.55; }

/* The dot carries the student's ink colour as an inline style, so it
   beats the online/answered rules above. That is intended — the colour
   is the same one their strokes are, and matching the two is the whole
   way a teacher knows whose line is whose. Presence is shown by fading
   the whole row instead. */
.jam-peer:not(.online) { opacity: .5; }
.jam-peer.muted .jam-peer-name { text-decoration: line-through; opacity: .7; }

.jam-peer-acts { display: inline-flex; gap: 4px; flex: none; margin-left: 4px; }
.jam-mini {
  border: 1px solid var(--border);
  background: var(--surface, #fff);
  border-radius: 6px;
  width: 22px; height: 22px;
  font-size: 11px; line-height: 1;
  cursor: pointer; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
}
.jam-mini:hover { border-color: var(--purple); }
.jam-mini.on { background: var(--purple); border-color: var(--purple); color: #fff; }
.jam-mini.off { opacity: .55; }
.jam-mini.danger:hover { border-color: #e11d48; color: #e11d48; }

/* ---- Room code ---- */

.jam-code-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.jam-code-label { font-size: 11.5px; color: var(--text-muted); }
.jam-code {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 17px; font-weight: 700; letter-spacing: .14em;
  color: var(--purple-dark);
  background: var(--purple-pale, #f4f0fd);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 3px 10px;
  cursor: pointer;
}
.jam-code:hover { border-color: var(--purple); }
.jam-code.copied { background: var(--green-text, #16a34a); color: #fff; }
.jam-code-lock { font-size: 12px; }

/* ---- Attendance ----
   Present when the room was launched from a class. Deliberately quiet:
   it is a register, checked occasionally, not the thing the teacher is
   running the lesson from. */

.jam-absent {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.jam-absent-head {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.jam-absent-list { display: flex; flex-wrap: wrap; gap: 4px; }
.jam-absent-chip {
  font-size: 10.5px;
  line-height: 1;
  padding: 3px 7px;
  border-radius: 999px;
  color: var(--text-muted);
  background: var(--gray-pill, #f1f1f4);
  border: 1px solid var(--border);
}
.jam-absent-all { font-size: 11.5px; color: var(--green-text, #16a34a); }

/* ---- Who can draw ---- */

.jam-pen-block { margin: 4px 0 12px; }
.jam-pen-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-muted); margin-bottom: 5px;
}
.jam-pen-modes { display: flex; gap: 4px; }
.jam-pen-mode {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--surface, #fff);
  border-radius: 7px;
  padding: 5px 4px;
  font-size: 10.5px; line-height: 1.25;
  cursor: pointer;
  color: var(--text-muted);
}
.jam-pen-mode:hover { border-color: var(--purple); }
.jam-pen-mode.on {
  background: var(--purple); border-color: var(--purple);
  color: #fff; font-weight: 600;
}

/* ---- Student HUD ---- */

.jam-hud {
  position: fixed;
  left: 18px;
  bottom: 18px;
  width: 260px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 10px 34px rgba(20, 16, 30, 0.16);
  z-index: 9996;
  padding: 14px 16px;
}
.jam-hud-score {
  font-size: 30px;
  font-weight: 700;
  color: var(--purple-dark);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.jam-hud-label { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ---- Fire meter ----
   Segments light up as the streak builds. The glow is on a pseudo
   element so it can pulse without the segment itself moving, which
   would nudge the layout every frame. */

.jam-fire {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.jam-fire-segs { display: flex; gap: 4px; flex: 1; }
.jam-fire-seg {
  height: 9px;
  flex: 1;
  border-radius: 999px;
  background: var(--gray-pill);
  position: relative;
  transition: background .25s ease;
}
.jam-fire-seg.lit { background: linear-gradient(90deg, #ffb020, #ff5a1f); }
.jam-fire-seg.lit::after {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 999px;
  background: inherit;
  filter: blur(5px);
  opacity: .55;
  animation: jam-flicker 1.1s ease-in-out infinite alternate;
}
@keyframes jam-flicker {
  from { opacity: .30; }
  to   { opacity: .75; }
}

.jam-mult {
  font-weight: 800;
  font-size: 15px;
  color: var(--text-muted);
  min-width: 26px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.jam-mult.hot {
  color: #ff5a1f;
  animation: jam-pop .45s cubic-bezier(.2,1.4,.3,1);
}
@keyframes jam-pop {
  0%   { transform: scale(1); }
  45%  { transform: scale(1.45); }
  100% { transform: scale(1); }
}

/* Award / reset flashes on the panel edge. */
.jam-hud.awarded { animation: jam-award .5s ease; }
.jam-hud.missed  { animation: jam-miss .5s ease; }
@keyframes jam-award {
  0%   { box-shadow: 0 10px 34px rgba(20,16,30,.16), 0 0 0 0 rgba(255,90,31,.55); }
  100% { box-shadow: 0 10px 34px rgba(20,16,30,.16), 0 0 0 16px rgba(255,90,31,0); }
}
@keyframes jam-miss {
  0%   { box-shadow: 0 10px 34px rgba(20,16,30,.16), 0 0 0 0 rgba(192,57,43,.5); }
  100% { box-shadow: 0 10px 34px rgba(20,16,30,.16), 0 0 0 16px rgba(192,57,43,0); }
}

.jam-gate-closed {
  margin-top: 10px;
  font-size: 12px;
  color: var(--red-text);
  background: var(--red-bg);
  border-radius: 8px;
  padding: 6px 9px;
  line-height: 1.45;
}

/* The student's own ink colour, next to their name. Same swatch as the
   chips below and as their strokes on the board — one colour, three
   places, so "which one am I" is never a question. */
.jam-you-dot {
  display: inline-block;
  width: 8px; height: 8px; border-radius: 50%;
  vertical-align: baseline;
  margin-right: 3px;
}

.jam-roster { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 9px; }
.jam-roster-chip {
  font-size: 10.5px;
  line-height: 1;
  padding: 3px 7px;
  border-radius: 999px;
  color: #fff;
  background: var(--chip, #7c3aed);
  max-width: 92px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* Someone the teacher has paused. Shown rather than hidden: a student
   wondering why their friend stopped drawing should be able to see that
   it was a decision, not a fault. */
.jam-roster-chip.off { opacity: .4; text-decoration: line-through; }

/* A connection that is taking too long. Wider and wordier than the pen
   notice on purpose: this one is asking the student to DO something
   (switch network, ask the teacher), so it has to carry a sentence
   rather than a label. Amber for the same reason as the pen notice —
   the session is still trying, so this is not yet a failure. */
.jam-stall-notice {
  margin-top: 10px;
  font-size: 11.5px;
  color: #92400e;
  background: #fef3c7;
  border-radius: 8px;
  padding: 8px 10px;
  line-height: 1.5;
  max-width: 240px;
}

/* Why this device's pen is down. Amber, not red — this is a rule in
   force, not an error, and colouring it like a failure invites the
   student to try to fix it. */
.jam-pen-notice {
  margin-top: 10px;
  font-size: 12px;
  color: #92400e;
  background: #fef3c7;
  border-radius: 8px;
  padding: 6px 9px;
  line-height: 1.45;
}

/* ---- Connection pip ----
   Sits above the score, small and quiet. It is background information
   almost all of the time and must not compete with the number the
   student is actually watching — but it has to be already familiar by
   the time it turns amber, which it cannot be if it only appears then. */

.jam-hud-head { display: flex; justify-content: flex-end; margin-bottom: 2px; }

.jam-conn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 10.5px;
  line-height: 1;
  color: var(--text-muted);
}
.jam-conn-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-muted);
  flex: none;
}
.jam-conn.ok .jam-conn-dot { background: #16a34a; }
.jam-conn.wait .jam-conn-dot { background: #d97706; }
.jam-conn.bad .jam-conn-dot { background: #dc2626; }
.jam-conn.wait .jam-conn-text { color: #92400e; }
.jam-conn.bad .jam-conn-text { color: #b91c1c; }

/* Only the waiting state pulses. A steady green that breathes would draw
   the eye to the one state nobody needs to look at, and a red that
   pulses reads as an alarm for something the student cannot act on. */
.jam-conn.wait .jam-conn-dot { animation: jam-conn-pulse 1.1s ease-in-out infinite; }
@keyframes jam-conn-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: .35; }
}
@media (prefers-reduced-motion: reduce) {
  .jam-conn.wait .jam-conn-dot { animation: none; }
}

/* The student's own place, sat next to their score. Shown even when the
   full ranking is private — withholding a student's own standing would
   read as a fault rather than as the teacher's decision. */
.jam-hud-rank {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-left: 6px;
  vertical-align: 3px;
  font-variant-numeric: tabular-nums;
}

/* ---- Leaderboard visibility (host) ---- */

.jam-boardvis {
  display: flex; align-items: center; gap: 7px;
  font-size: 12.5px; cursor: pointer; margin-bottom: 3px;
}
.jam-boardvis input { cursor: pointer; }
.jam-boardvis-note {
  font-size: 11px; color: var(--text-muted);
  line-height: 1.45; margin-bottom: 10px;
}

/* ---- A private round result, on a student's screen ---- */

.jam-private-result { text-align: center; padding: 14px 0 6px; }
.jam-private-score {
  font-size: 44px; font-weight: 800; line-height: 1;
  color: var(--purple-dark); font-variant-numeric: tabular-nums;
}
.jam-private-sub { font-size: 13px; color: var(--text-muted); margin-top: 6px; }
.jam-private-rank {
  display: inline-block; margin-top: 12px;
  font-size: 15px; font-weight: 700;
  color: var(--purple-dark);
  background: var(--purple-pale, #f4f0fd);
  border: 1px solid var(--border);
  border-radius: 999px; padding: 4px 14px;
}
.jam-class-line {
  margin-top: 14px; text-align: center;
  font-size: 13px; color: var(--text-muted); line-height: 1.5;
}

/* ---- Scoreboard ---- */

.jam-board-row {
  display: grid;
  grid-template-columns: 130px 1fr 58px;
  align-items: center;
  gap: 10px;
  margin-bottom: 9px;
  font-size: 13px;
}
.jam-board-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.jam-board-track {
  display: flex;
  height: 20px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--gray-pill);
}
/* Correct and incorrect as one stacked bar: the split reads as a
   proportion at a glance, which two separate bars would not. */
.jam-board-correct { background: var(--green-text); transition: width .5s cubic-bezier(.2,.8,.2,1); }
.jam-board-wrong { background: #e08b7f; transition: width .5s cubic-bezier(.2,.8,.2,1); }
.jam-board-score { text-align: right; font-weight: 700; color: var(--purple-dark); font-variant-numeric: tabular-nums; }
.jam-board-legend { font-size: 12px; color: var(--text-muted); margin-bottom: 12px; }
.jam-board-legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; }

@media (prefers-reduced-motion: reduce) {
  .jam-fire-seg.lit::after,
  .jam-mult.hot,
  .jam-hud.awarded,
  .jam-hud.missed { animation: none; }
  .jam-tally-bar > span,
  .jam-board-correct,
  .jam-board-wrong { transition: none; }
}

/* Replaces the range input for a locked student: same footprint and fill
   so the layout does not shift when a jam starts, but nothing to grab. */
.q-slider-locked {
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(
    to right,
    var(--purple) 0%,
    var(--purple) var(--fill, 0%),
    var(--purple-track) var(--fill, 0%),
    var(--purple-track) 100%
  );
}
