/* =========================================================================
   CG Live Classroom — v0.2 redesign
   Brand: CLAT navy #1B2D4F + orange #FF6B35, Athletics
   Goal: distraction-free, modern (Meet/Around/Riverside polish), responsive
   ========================================================================= */

#cg-classroom.cg-shell {
  --navy: #1B2D4F;
  --navy-2: #25395f;
  --orange: #FF6B35;
  --orange-2: #ff8657;
  --bg: #0a0e1a;
  --surface: #121a2c;
  --surface-2: #1a2438;
  --surface-3: #243250;
  --border: rgba(255, 255, 255, 0.08);
  --border-2: rgba(255, 255, 255, 0.14);
  --text: #eef2fa;
  --text-2: #aeb9cf;
  --text-3: #7d8aa4;
  --danger: #e3503e;
  --danger-2: #b3372a;
  --good: #34d39a;
  --warn: #f4b740;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.35);

  position: fixed;
  inset: 0;
  z-index: 99999;
  background: var(--bg);
  color: var(--text);
  font-family: "Athletics", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
  isolation: isolate;
}
#cg-classroom.cg-shell * { box-sizing: border-box; }
#cg-classroom.cg-shell button { font-family: inherit; }
.cg-hidden { display: none !important; }

/* Ambient brand glow */
#cg-classroom.cg-shell::before {
  content: "";
  position: absolute;
  inset: -200px;
  background:
    radial-gradient(60% 50% at 15% 10%, rgba(27, 45, 79, 0.55), transparent 60%),
    radial-gradient(45% 45% at 90% 90%, rgba(255, 107, 53, 0.18), transparent 60%);
  pointer-events: none;
  z-index: 0;
}

/* ============================ Login gate ============================ */
.cg-gate-wrap { position: fixed; inset: 0; display: grid; place-items: center; background: #0a0e1a; color: #eef2fa; z-index: 99999; font-family: "Athletics", -apple-system, sans-serif; }
.cg-gate { text-align: center; padding: 48px 32px; background: #121a2c; border: 1px solid rgba(255,255,255,.08); border-radius: 16px; max-width: 420px; }
.cg-gate h2 { margin: 0 0 12px; font-size: 22px; }
.cg-gate a { color: #FF6B35; font-weight: 700; text-decoration: none; }

/* ============================ Pre-join ============================ */
.cg-prejoin {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  overflow-y: auto;
}
.cg-prejoin-card {
  width: min(100%, 1040px) !important;
  max-width: 1040px !important;
  margin: 0 auto !important;
  background: rgba(15, 22, 38, 0.7) !important;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex !important;
  flex-direction: row !important;
  overflow: hidden;
  backdrop-filter: blur(8px);
}
.cg-prejoin-preview {
  position: relative;
  flex: 1 1 0 !important;
  min-width: 0 !important;
  aspect-ratio: 16 / 10;
  background: #000;
  display: grid;
  place-items: center;
}
.cg-prejoin-preview video {
  width: 100% !important; height: 100% !important;
  max-width: none !important;
  object-fit: cover;
  transform: scaleX(-1); /* selfie-mirror */
  background: linear-gradient(135deg, #1a2438, #0a0e1a);
  display: block;
}
.cg-preview-status {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #1a2438, #0a0e1a);
  color: var(--text-2);
  font-size: 14px;
  text-align: center;
  padding: 24px;
  pointer-events: none;
}
.cg-preview-status.cg-fade { opacity: 0; transition: opacity 0.3s; }
.cg-preview-overlay {
  position: absolute;
  inset: auto 12px 12px 12px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}
.cg-preview-name {
  background: rgba(0,0,0,.55);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  backdrop-filter: blur(6px);
}

.cg-prejoin-form {
  flex: 0 0 420px !important;
  max-width: 420px !important;
  padding: 36px 36px 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: rgba(10, 14, 26, 0.55);
  color: var(--text) !important;
}
.cg-prejoin-form h2,
.cg-prejoin-form p,
.cg-prejoin-form label,
.cg-prejoin-form span,
.cg-prejoin-form div { color: inherit; font-family: inherit; }
.cg-prejoin-form a { color: var(--orange) !important; }
.cg-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}
.cg-brand-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--orange);
  box-shadow: 0 0 0 4px rgba(255,107,53,.18);
}
.cg-brand-name { font-weight: 800; letter-spacing: .2px; font-size: 15px; }
.cg-brand-sub { font-size: 12px; color: var(--text-3); letter-spacing: .4px; text-transform: uppercase; }

.cg-prejoin-title { margin: 6px 0 4px !important; font-size: 26px !important; font-weight: 800 !important; letter-spacing: -0.01em !important; color: var(--text) !important; line-height: 1.2 !important; }
.cg-prejoin-lede { margin: 0 0 8px !important; color: var(--text-2) !important; font-size: 14px !important; line-height: 1.5 !important; }
.cg-brand-name { color: var(--text) !important; }
.cg-brand-sub  { color: var(--text-3) !important; }
.cg-fine       { color: var(--text-3) !important; }
.cg-field-label { color: var(--text-3) !important; }

.cg-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.cg-field-label {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-3);
  text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700;
}
.cg-field input,
.cg-field select {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 14px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
  appearance: none;
}
.cg-field select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23aeb9cf' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 38px;
}
.cg-field input:focus,
.cg-field select:focus {
  outline: 0;
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(255,107,53,.18);
}
.cg-field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.cg-btn-primary {
  margin-top: 8px;
  background: linear-gradient(180deg, var(--orange-2), var(--orange));
  color: #fff;
  border: 0;
  border-radius: 12px;
  padding: 14px 22px;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  letter-spacing: .2px;
  box-shadow: 0 6px 18px rgba(255,107,53,.35);
  transition: transform .08s, box-shadow .15s, filter .15s;
}
.cg-btn-primary:hover { filter: brightness(1.05); box-shadow: 0 8px 22px rgba(255,107,53,.45); }
.cg-btn-primary:active { transform: translateY(1px); }
.cg-btn-primary:disabled { opacity: .6; cursor: not-allowed; box-shadow: none; }
.cg-fine { margin: 6px 0 0; color: var(--text-3); font-size: 12px; }

/* ============================ Live ============================ */
.cg-live {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: 1fr 0;            /* stage full-width by default; side opens on demand */
  grid-template-rows: 56px 1fr auto;
  grid-template-areas:
    "topbar topbar"
    "stage  side"
    "controls controls";
  gap: 0;
}
.cg-live.cg-no-side { grid-template-columns: 1fr 0; }
.cg-live.cg-side-open { grid-template-columns: 1fr 320px; }  /* reserve only when chat/people open */

/* --- Top bar --- */
.cg-topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(10,14,26,.65);
  backdrop-filter: blur(10px);
}
.cg-topbar-brand { display: flex; align-items: center; gap: 10px; }
.cg-live-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(227,80,62,.18);
  animation: cg-pulse 1.6s ease-in-out infinite;
}
@keyframes cg-pulse {
  0%,100% { box-shadow: 0 0 0 4px rgba(227,80,62,.18); }
  50%     { box-shadow: 0 0 0 7px rgba(227,80,62,.05); }
}
.cg-topbar-title { font-weight: 700; font-size: 14px; letter-spacing: .2px; }
.cg-topbar-right { display: flex; align-items: center; gap: 8px; }

.cg-icon-btn {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 38px; height: 38px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .08s;
}
.cg-icon-btn:hover { background: var(--surface-3); border-color: var(--border-2); }
.cg-icon-btn:active { transform: translateY(1px); }
.cg-icon-btn.cg-active { background: var(--orange); border-color: transparent; }
.cg-pcount {
  position: absolute; top: -6px; right: -6px;
  min-width: 18px; height: 18px; padding: 0 5px;
  background: var(--orange);
  border-radius: 999px;
  font-size: 11px; font-weight: 800; line-height: 18px;
  text-align: center;
}
.cg-dot-badge {
  position: absolute; top: 8px; right: 8px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--orange);
}

/* Quality dots */
.cg-quality {
  display: inline-flex; align-items: flex-end; gap: 3px;
  height: 38px; padding: 0 10px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.cg-quality i { width: 4px; background: var(--text-3); border-radius: 2px; transition: background .2s; }
.cg-quality i:nth-child(1) { height: 8px; }
.cg-quality i:nth-child(2) { height: 13px; }
.cg-quality i:nth-child(3) { height: 18px; }
.cg-quality[data-q="excellent"] i { background: var(--good); }
.cg-quality[data-q="good"] i:nth-child(1),
.cg-quality[data-q="good"] i:nth-child(2) { background: var(--good); }
.cg-quality[data-q="poor"] i:nth-child(1) { background: var(--warn); }

/* --- Stage --- */
.cg-stagewrap {
  grid-area: stage;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: 18px;
  gap: 14px;
}
.cg-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #000;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}
.cg-stage video {
  width: 100%; height: 100%;
  object-fit: contain;
  background: linear-gradient(135deg, #0d1322, #050810);
}
.cg-stage-empty {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #0d1322, #050810);
  color: var(--text-2);
}
.cg-stage-empty-inner { text-align: center; }
.cg-spinner {
  width: 36px; height: 36px;
  border: 3px solid rgba(255,255,255,.12);
  border-top-color: var(--orange);
  border-radius: 50%;
  margin: 0 auto 14px;
  animation: cg-spin .9s linear infinite;
}
@keyframes cg-spin { to { transform: rotate(360deg); } }
.cg-stage-label {
  position: absolute;
  left: 14px; bottom: 14px;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(6px);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px;
}
.cg-stage-label::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: var(--orange);
}
.cg-state-pills {
  position: absolute; top: 14px; left: 14px;
  display: flex; flex-direction: column; gap: 6px;
  pointer-events: none;
}
.cg-pill {
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-2);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px;
  animation: cg-pill-in .2s ease-out;
}
.cg-pill.cg-pill-callon { background: rgba(255,107,53,.92); border-color: transparent; }
.cg-pill.cg-pill-hand   { background: rgba(244,183,64,.92); color: #181818; border-color: transparent; }
.cg-pill.cg-pill-muted  { background: rgba(0,0,0,.65); }
@keyframes cg-pill-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

/* --- Filmstrip --- */
.cg-strip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  scrollbar-width: thin;
  padding: 2px 2px 8px;
  min-height: 110px;
}
.cg-strip::-webkit-scrollbar { height: 6px; }
.cg-strip::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 3px; }
.cg-tile {
  position: relative;
  flex: 0 0 auto;
  width: 180px; height: 110px;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid transparent;
  transition: border-color .15s, transform .12s;
  cursor: pointer;
}
.cg-tile:hover { transform: translateY(-2px); }
.cg-tile.cg-spot { border-color: var(--orange); box-shadow: 0 0 0 3px rgba(255,107,53,.18); }
.cg-tile.cg-speaking { border-color: var(--good); }
.cg-tile video {
  width: 100%; height: 100%;
  object-fit: cover;
  background: linear-gradient(135deg, #1a2438, #0d1322);
}
.cg-tile-label {
  position: absolute; left: 6px; bottom: 6px; right: 6px;
  display: flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 600;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(4px);
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cg-tile-mic {
  position: absolute; top: 6px; left: 6px;
  width: 22px; height: 22px;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(4px);
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 11px;
}
.cg-tile-mic.cg-on { background: rgba(52,211,154,.95); }
.cg-tile-mic.cg-off { background: rgba(0,0,0,.7); color: #e3503e; }
.cg-hand {
  display: inline-block;
  background: var(--warn);
  color: #181818;
  border-radius: 999px;
  padding: 1px 6px;
  font-size: 11px;
  font-weight: 800;
  animation: cg-hand-wave 1.4s ease-in-out infinite;
}
@keyframes cg-hand-wave {
  0%,100% { transform: rotate(0deg); }
  25% { transform: rotate(14deg); }
  75% { transform: rotate(-14deg); }
}
.cg-tilectl {
  position: absolute; top: 6px; right: 6px;
  display: flex; gap: 4px;
  opacity: 0;
  transition: opacity .15s;
}
.cg-tile:hover .cg-tilectl,
.cg-tile:focus-within .cg-tilectl { opacity: 1; }
.cg-tilectl button {
  width: 28px; height: 28px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(27,45,79,.92);
  color: #fff;
  cursor: pointer;
  display: grid; place-items: center;
  font-size: 0;
  transition: background .12s, transform .08s;
}
.cg-tilectl button:hover { background: var(--orange); }
.cg-tilectl button:active { transform: scale(0.92); }
.cg-tilectl button svg { width: 14px; height: 14px; display: block; }
body:not(.cg-role-faculty) #cg-classroom .cg-tilectl { display: none; }

/* Faculty-only controls visibility */
.cg-faculty-only { display: none !important; }
body.cg-role-faculty .cg-faculty-only { display: inline-flex !important; }
body.cg-role-faculty .cg-controlbar .cg-faculty-only { display: inline-flex !important; }

/* Stage PiP — presenter's camera while screen-sharing */
.cg-stage-pip {
  position: absolute;
  bottom: 16px; right: 16px;
  width: 200px; height: 130px;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid rgba(255,255,255,0.18);
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  z-index: 3;
  cursor: grab;
  transition: opacity .25s;
}
.cg-stage-pip video {
  width: 100%; height: 100%;
  object-fit: cover;
  background: #1a2438;
  display: block;
}
.cg-stage-pip-label {
  position: absolute;
  left: 6px; bottom: 6px;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  pointer-events: none;
}

/* --- Side panel --- */
.cg-side {
  grid-area: side;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  background: rgba(18,26,44,.7);
  backdrop-filter: blur(10px);
  min-height: 0;
  transition: transform .25s ease, opacity .2s;
}
.cg-side.cg-side-collapsed { transform: translateX(100%); opacity: 0; pointer-events: none; }
.cg-live.cg-side-open .cg-side { transform: none; opacity: 1; pointer-events: auto; }
.cg-side-head {
  display: flex; align-items: center;
  padding: 8px 8px 8px 16px;
  border-bottom: 1px solid var(--border);
}
.cg-side-tabs { display: flex; gap: 4px; flex: 1; }
.cg-tab {
  background: transparent; border: 0;
  color: var(--text-2);
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  display: inline-flex; align-items: center; gap: 6px;
}
.cg-tab:hover { color: var(--text); background: var(--surface-2); }
.cg-tab-active { color: var(--text); background: var(--surface-2); }
.cg-tabcount {
  background: var(--surface-3); color: var(--text-2);
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
}
.cg-side-close {
  background: transparent; border: 0; color: var(--text-2);
  width: 32px; height: 32px;
  border-radius: 8px; cursor: pointer;
}
.cg-side-close:hover { background: var(--surface-2); color: var(--text); }

.cg-tab-pane { display: none; flex: 1; min-height: 0; flex-direction: column; }
.cg-tab-pane-active { display: flex; }

.cg-chatlog {
  flex: 1; min-height: 0;
  padding: 14px 16px;
  overflow-y: auto;
  font-size: 13px;
  line-height: 1.55;
}
.cg-chatlog::-webkit-scrollbar { width: 6px; }
.cg-chatlog::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 3px; }
.cg-msg { margin-bottom: 10px; word-wrap: break-word; }
.cg-msg-name { display: block; font-size: 11px; color: var(--orange); font-weight: 700; margin-bottom: 2px; }
.cg-msg-body { color: var(--text); }
.cg-msg-system { color: var(--text-3); font-style: italic; font-size: 12px; }

.cg-chatrow {
  display: flex; align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: rgba(10,14,26,.5);
}
.cg-chatrow input {
  flex: 1;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  border-radius: 999px;
  transition: border-color .15s, box-shadow .15s;
}
.cg-chatrow input:focus {
  outline: 0;
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(255,107,53,.15);
}
.cg-chatrow button {
  width: 38px; height: 38px;
  background: var(--orange);
  color: #fff;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  display: grid; place-items: center;
  transition: filter .15s, transform .08s;
}
.cg-chatrow button:hover { filter: brightness(1.08); }
.cg-chatrow button:active { transform: translateY(1px); }

.cg-roster-list { padding: 12px 16px; overflow-y: auto; flex: 1; min-height: 0; }
.cg-roster-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  margin-bottom: 4px;
  background: transparent;
}
.cg-roster-row:hover { background: var(--surface-2); }
.cg-roster-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--navy);
  display: grid; place-items: center;
  font-size: 12px; font-weight: 800;
  color: #fff;
  flex: 0 0 auto;
}
.cg-roster-name { flex: 1; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cg-roster-role { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700; }
.cg-roster-role.cg-r-faculty { color: var(--orange); }
.cg-roster-row .cg-hand { margin-left: auto; }

/* --- Control bar --- */
.cg-controlbar {
  grid-area: controls;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 18px 18px;
  background: linear-gradient(180deg, transparent, rgba(10,14,26,.85) 50%);
}
.cg-cbtn {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 78px;
  padding: 9px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 14px;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .08s, color .15s;
}
.cg-cbtn:hover { background: var(--surface-3); border-color: var(--border-2); }
.cg-cbtn:active { transform: translateY(1px); }
.cg-cbtn-ico {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  position: relative;
}
.cg-cbtn-ico svg { display: block; }
.cg-cbtn .cg-ico-off { display: none; }
.cg-cbtn.cg-off .cg-ico-on  { display: none; }
.cg-cbtn.cg-off .cg-ico-off { display: block; }
.cg-cbtn.cg-off {
  background: rgba(227,80,62,.18);
  border-color: rgba(227,80,62,.35);
  color: #ff9183;
}
.cg-cbtn.cg-on-accent {
  background: var(--orange);
  border-color: transparent;
  color: #fff;
}
.cg-cbtn-label { font-size: 11px; font-weight: 700; letter-spacing: .2px; }
.cg-cbtn-sep { width: 1px; height: 32px; background: var(--border); margin: 0 6px; }
.cg-cbtn-leave {
  background: var(--danger-2);
  border-color: transparent;
  color: #fff;
}
.cg-cbtn-leave:hover { background: var(--danger); }

/* --- Status (toast under top bar) --- */
.cg-status {
  position: absolute;
  top: 66px; left: 50%;
  transform: translateX(-50%);
  background: rgba(10,14,26,.88);
  border: 1px solid var(--border-2);
  backdrop-filter: blur(10px);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--text-2);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
  z-index: 5;
}
.cg-status.cg-visible { opacity: 1; }

/* ============================ Responsive ============================ */
@media (max-width: 900px) {
  .cg-prejoin-card { flex-direction: column !important; }
  .cg-prejoin-preview { aspect-ratio: 16 / 9; flex: 0 0 auto !important; }
  .cg-prejoin-form { flex: 1 1 auto !important; max-width: none !important; padding: 24px !important; }
  .cg-field-row { grid-template-columns: 1fr; }
  .cg-prejoin-title { font-size: 22px !important; }
}
@media (max-width: 760px) {
  .cg-live {
    grid-template-columns: 1fr;
    grid-template-rows: 52px 1fr auto;
    grid-template-areas:
      "topbar"
      "stage"
      "controls";
  }
  /* position: fixed + dvh so the panel shrinks when the on-screen keyboard
     pushes the visual viewport up. Without dvh the chatrow gets buried
     under the keyboard and the send button is invisible. */
  .cg-side {
    position: fixed !important;
    top: 52px; left: 0; right: 0;
    bottom: 0;
    height: calc(100dvh - 52px);
    border-left: 0;
    border-top: 1px solid var(--border);
    z-index: 100;
  }
  .cg-stagewrap { padding: 10px; gap: 10px; }
  .cg-tile { width: 130px; height: 80px; }
  .cg-strip { min-height: 90px; }
  .cg-controlbar { padding: 10px 8px 14px; gap: 6px; flex-wrap: wrap; }
  .cg-cbtn { min-width: 60px; padding: 8px 10px; }
  .cg-cbtn-label { font-size: 10px; }
  .cg-cbtn-sep { display: none; }
  .cg-topbar { padding: 0 12px; }
  .cg-topbar-title { font-size: 13px; }
  .cg-stage-label { left: 10px; bottom: 10px; font-size: 12px; padding: 5px 10px; }
  .cg-status { top: 60px; }
  .cg-quality { display: none; }
  /* iOS auto-zooms inputs whose font-size is < 16px on focus.
     16px keeps the layout from suddenly enlarging when the user taps the chat. */
  .cg-chatrow { padding: 8px; gap: 8px; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .cg-chatrow input { font-size: 16px !important; padding: 12px 14px; }
  .cg-chatrow button { width: 44px !important; height: 44px !important; flex: 0 0 44px; }
  .cg-chatlog { padding: 12px 14px; font-size: 14px; }
  /* PiP scales down so it doesn't eat the small mobile stage */
  .cg-stage-pip { width: 110px; height: 70px; bottom: 10px; right: 10px; border-radius: 8px; }
  /* Tile controls must be visible without hover on touch — students need access
     to faculty actions immediately on tap. */
  .cg-tilectl { opacity: 1 !important; }
  .cg-tilectl button { width: 32px; height: 32px; }
  .cg-tilectl button svg { width: 16px; height: 16px; }
}
@media (max-width: 420px) {
  .cg-cbtn-label { display: none; }
  .cg-cbtn { min-width: 48px; padding: 10px; border-radius: 12px; }
  .cg-cbtn-ico { width: 22px; height: 22px; }
}

/* Touch/no-hover devices: always show tile controls (mobile + tablet + touch laptops) */
@media (hover: none) {
  .cg-tilectl { opacity: 1 !important; }
  body.cg-role-faculty .cg-tilectl { opacity: 1 !important; }
}

/* =========================================================================
   Phase 7.4 — Participants strip toggle (works in windowed + fullscreen)
   ========================================================================= */

.cg-strip-toggle {
  position: absolute;
  z-index: 6;
  bottom: 8px;
  left: 12px;
  background: rgba(10, 14, 26, 0.92);
  color: var(--text-2);
  border: 1px solid var(--border-2);
  border-radius: 999px;
  padding: 6px 12px 6px 10px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.08s;
  box-shadow: 0 4px 14px rgba(0,0,0,0.35);
}
.cg-strip-toggle:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-2); }
.cg-strip-toggle:active { transform: translateY(1px); }
.cg-strip-toggle .cg-st-ico-hide { display: none; }
.cg-strip-toggle.cg-on .cg-st-ico-show { display: none; }
.cg-strip-toggle.cg-on .cg-st-ico-hide { display: block; }

/* Hidden state — drop the strip out of layout cleanly. */
body.cg-strip-hidden .cg-strip { display: none !important; }

/* In windowed mode, position the toggle inside .cg-stagewrap relative space —
   the cg-stagewrap has position: relative implicitly via flex layout. Pin to
   the strip's bottom-left area. */
.cg-stagewrap { position: relative; }

@media (max-width: 600px) {
  .cg-strip-toggle { font-size: 11px; padding: 5px 10px 5px 8px; }
  .cg-strip-toggle .cg-strip-toggle-label { display: none; }
  /* Icon-only on small screens */
}

/* In FULLSCREEN, the toggle floats with the strip — bottom-left corner,
   just above where the strip column starts (or where it WOULD start if hidden). */
body.cg-fs .cg-strip-toggle,
body.cg-fs-pseudo .cg-strip-toggle {
  bottom: 70px;
  left: 14px;
}
@media (max-width: 600px) {
  body.cg-fs .cg-strip-toggle,
  body.cg-fs-pseudo .cg-strip-toggle {
    bottom: 70px;
    left: 8px;
  }
}

/* When the strip is hidden, the toggle keeps its position. The autohide
   logic also applies. */
body.cg-fs.cg-fs-hide .cg-strip-toggle { transform: translateY(120%); opacity: 0; pointer-events: none; }

/* =========================================================================
   Phase 7 — Fullscreen mode + mobile UX polish
   - Real fullscreen via Fullscreen API: body.cg-fs
   - iOS Safari pseudo-fullscreen fallback: body.cg-fs-pseudo
   - Auto-hide controls after 3s of inactivity: body.cg-fs.cg-fs-hide
   ========================================================================= */

/* Real fullscreen: the browser's own treatment already removes chrome.
   We mainly need to lift the controlbar above video as a floating glass
   bar so the stage really fills the viewport. */
:fullscreen #cg-classroom.cg-shell,
body.cg-fs #cg-classroom.cg-shell,
body.cg-fs-pseudo #cg-classroom.cg-shell {
  position: fixed !important;
  inset: 0 !important;
  z-index: 2147483647 !important; /* highest, beats site chrome */
  background: #000;
}

/* Pseudo-fullscreen (iOS Safari): forces the shell to cover viewport even
   though Safari blocks Fullscreen API on non-video elements. */
body.cg-fs-pseudo { overflow: hidden !important; touch-action: manipulation; }

body.cg-fs .cg-live,
body.cg-fs-pseudo .cg-live {
  /* Recompose layout: stage + controlbar overlay; topbar + filmstrip + side
     turn into glass overlays. */
  grid-template-rows: auto 1fr auto !important;
  height: 100vh; height: 100dvh;
}

/* Stage fills the viewport behind the floating controls. */
body.cg-fs .cg-stagewrap,
body.cg-fs-pseudo .cg-stagewrap {
  padding: 0 !important;
  position: absolute;
  inset: 0;
  z-index: 1;
}
body.cg-fs .cg-stage,
body.cg-fs-pseudo .cg-stage {
  border-radius: 0;
  border: 0;
  box-shadow: none;
  height: 100%;
}

/* Floating top bar: thin gradient strip only over the very top, no blur band
   bleeding into the video. */
body.cg-fs .cg-topbar,
body.cg-fs-pseudo .cg-topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 5;
  background: linear-gradient(180deg, rgba(0,0,0,.6), rgba(0,0,0,0));
  backdrop-filter: none !important;
  border: 0;
  padding: 10px 18px 30px;
  transition: transform .25s ease, opacity .25s ease;
}

/* Filmstrip: tucked in the BOTTOM-LEFT corner as a compact vertical-or-
   horizontal cluster of tiles. NO glass background covering the video —
   only the tiles themselves are visible. Stays out of the central
   speaker's face. */
body.cg-fs .cg-strip,
body.cg-fs-pseudo .cg-strip {
  position: absolute;
  left: 14px;
  bottom: 100px;            /* above the floating controlbar */
  right: auto;
  width: auto;
  max-width: 200px;
  max-height: calc(100vh - 200px);
  z-index: 5;
  padding: 0;
  background: transparent !important;
  backdrop-filter: none !important;
  border-radius: 0;
  display: flex;
  flex-direction: column;   /* vertical stack — keeps central video clean */
  gap: 8px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  transition: transform .25s ease, opacity .25s ease;
}
body.cg-fs .cg-strip::-webkit-scrollbar,
body.cg-fs-pseudo .cg-strip::-webkit-scrollbar { width: 4px; }
body.cg-fs .cg-strip::-webkit-scrollbar-thumb,
body.cg-fs-pseudo .cg-strip::-webkit-scrollbar-thumb { background: rgba(255,255,255,.18); border-radius: 2px; }

/* Smaller, self-contained tiles so they stack neatly + don't crowd faces. */
body.cg-fs .cg-strip .cg-tile,
body.cg-fs-pseudo .cg-strip .cg-tile {
  width: 160px;
  height: 92px;
  flex: 0 0 auto;
  background: #000;
  box-shadow: 0 4px 14px rgba(0,0,0,.45);
  border: 1.5px solid rgba(255,255,255,.08);
}

/* Floating control bar — solid dark pill so the buttons read crisp and the
   blur effect doesn't smear video underneath. */
body.cg-fs .cg-controlbar,
body.cg-fs-pseudo .cg-controlbar {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  z-index: 6;
  background: rgba(10, 14, 26, .94);
  backdrop-filter: none;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 999px;
  padding: 8px 10px;
  box-shadow: 0 14px 40px rgba(0,0,0,.5);
  transition: transform .25s ease, opacity .25s ease;
}

/* State pills (Hand raised, Muted, Live) — top-left during fullscreen. */
body.cg-fs .cg-state-pills,
body.cg-fs-pseudo .cg-state-pills {
  position: absolute;
  top: 64px;
  left: 16px;
  z-index: 5;
  pointer-events: none;
}

/* Chat / People panel — solid dark right-side overlay so text reads
   clearly. Crisp edge instead of a frosted-glass blur over the video. */
body.cg-fs .cg-side,
body.cg-fs-pseudo .cg-side {
  position: absolute;
  top: 64px;
  right: 12px;
  bottom: 96px;
  width: 340px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,.08);
  background: rgba(13, 19, 34, .95) !important;
  backdrop-filter: none !important;
  box-shadow: 0 14px 40px rgba(0,0,0,.5);
  z-index: 7;
}

/* PiP stays in its corner but lifted above the new floating bar. */
body.cg-fs .cg-stage-pip,
body.cg-fs-pseudo .cg-stage-pip {
  bottom: 110px;
  right: 16px;
  z-index: 5;
}

/* Auto-hide: slide controls + topbar + filmstrip off-screen. */
body.cg-fs.cg-fs-hide .cg-controlbar { transform: translate(-50%, 140%); opacity: 0; pointer-events: none; }
body.cg-fs.cg-fs-hide .cg-topbar      { transform: translateY(-100%); opacity: 0; pointer-events: none; }
body.cg-fs.cg-fs-hide .cg-strip       { transform: translateY(150%); opacity: 0; pointer-events: none; }

/* Fullscreen button visual states — on = orange accent. */
.cg-cbtn .cg-ico-off { display: none; }
#cg-fs.cg-cbtn .cg-ico-on  { display: block; }
#cg-fs.cg-cbtn .cg-ico-off { display: none; }
#cg-fs.cg-cbtn.cg-on .cg-ico-on  { display: none; }
#cg-fs.cg-cbtn.cg-on .cg-ico-off { display: block; }
#cg-fs.cg-cbtn.cg-on { background: var(--orange); border-color: transparent; color: #fff; }

/* ──────────────── Fullscreen on tablet / mobile (≤900px) ──────────────── */
@media (max-width: 900px) {
  body.cg-fs .cg-side,
  body.cg-fs-pseudo .cg-side {
    /* Bottom-sheet style: bottom 60% of screen, full width. */
    top: auto !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 65dvh;
    max-height: 65vh;
    border-radius: 18px 18px 0 0;
    transform: translateY(0);
  }
  body.cg-fs .cg-side.cg-side-collapsed,
  body.cg-fs-pseudo .cg-side.cg-side-collapsed { transform: translateY(100%); }
  body.cg-fs .cg-controlbar,
  body.cg-fs-pseudo .cg-controlbar {
    bottom: max(12px, env(safe-area-inset-bottom));
    padding: 6px 8px;
    gap: 4px;
  }
  body.cg-fs .cg-cbtn,
  body.cg-fs-pseudo .cg-cbtn {
    min-width: 52px;
    min-height: 52px;
    padding: 8px;
    border-radius: 999px;
  }
  body.cg-fs .cg-cbtn-label,
  body.cg-fs-pseudo .cg-cbtn-label { display: none; }
  body.cg-fs .cg-cbtn-sep,
  body.cg-fs-pseudo .cg-cbtn-sep { display: none; }
  body.cg-fs .cg-strip,
  body.cg-fs-pseudo .cg-strip {
    bottom: 78px;
    left: 8px;
    max-width: 130px;
    max-height: 50vh;
  }
  body.cg-fs .cg-strip .cg-tile,
  body.cg-fs-pseudo .cg-strip .cg-tile {
    width: 110px;
    height: 65px;
  }
}

/* ──────────────── Windowed mobile (NOT fullscreen) ──────────────── */
/* Make the existing windowed controls equally thumb-friendly. Hand raise
   gets visual prominence (warm border) so students notice it. */
@media (max-width: 600px) {
  .cg-controlbar { padding: 10px 8px 14px; gap: 6px; }
  .cg-cbtn { min-width: 56px; min-height: 52px; padding: 8px 10px; }
  .cg-cbtn-label { font-size: 10px; }
  .cg-cbtn-ico { width: 22px; height: 22px; }
  #cg-raise.cg-cbtn { border-color: rgba(244,183,64,.45); }
  #cg-raise.cg-cbtn.cg-on-accent {
    background: linear-gradient(180deg, #ffd166, #f4b740);
    color: #181818;
    border-color: transparent;
  }
}
