/* camera.js: the teacher's camera beside the voice (decision 15). Nothing here shows on a voice-only class.
   Teacher, wide: «دوربین» is a tile beside the mic with a small self-view in it. Teacher, narrow: «دوربین» is a
   button in the bottom bar and a small card at the top of the page says what the tile would. Student: the video
   takes the place of the big avatar in the stage; «فقط صدا» sits under it. "On" uses the voice-on-air green. */

/* ---------- the teacher's «دوربین» ---------- */
.cam-tile {
  appearance: none;
  display: flex; align-items: center; gap: 14px;
  width: 100%; min-height: 108px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  background: var(--card); color: var(--ink);
  text-align: start;
  cursor: pointer;
  box-shadow: var(--shadow-1);
  touch-action: manipulation;
  transition: background-color .15s, border-color .15s;
}
.cam-ic {
  flex: none; display: grid; place-items: center;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--bg-sunken); color: var(--muted);
}
.cam-ic .ic { width: 26px; height: 26px; }
.cam-prev {
  flex: none; display: block;
  width: 128px; height: 72px;
  border-radius: 10px;
  background: #1b1916;
  object-fit: cover;
  transform: scaleX(-1); /* a self-view is a mirror */
}
.cam-txt { display: flex; flex-direction: column; min-width: 0; line-height: 1.45; }
.cam-txt b { font-size: 17px; font-weight: 800; }
.cam-txt small { color: var(--muted); font-size: 13px; }
.cam-short { display: none; }
.cam-tile[data-state="on"] { background: var(--speak-soft); border-color: var(--speak-line); }
.cam-tile[data-state="on"] b { color: var(--speak-ink); }
.cam-tile:is([data-state="lost"], [data-state="fail"], [data-state="denied"], [data-state="nodevice"]) { border-color: var(--warn-line); }
.cam-tile:is([data-state="lost"], [data-state="fail"], [data-state="denied"], [data-state="nodevice"]) small { color: var(--warn); }
.cam-tile:is([data-state="fail"], [data-state="denied"], [data-state="nodevice"]) .cam-ic { background: var(--warn-soft); color: var(--warn); }
.cam-tile:disabled { cursor: progress; }
@media (hover: hover) {
  .cam-tile:not(:disabled):hover { border-color: var(--accent-line); }
  .cam-tile[data-state="on"]:not(:disabled):hover { border-color: var(--speak); }
}

/* The phone's card (the wide tile says it all). */
.cam-self {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--speak-line);
  border-radius: var(--r-lg);
  background: var(--speak-soft);
}
.cam-self .cam-prev { width: 112px; height: 63px; }
.cam-self b { color: var(--speak-ink); font-size: 15px; }
.cam-self:is([data-state="lost"], [data-state="fail"], [data-state="denied"], [data-state="nodevice"]) { background: var(--warn-soft); border-color: var(--warn-line); }
.cam-self:is([data-state="lost"], [data-state="fail"], [data-state="denied"], [data-state="nodevice"]) b { color: var(--warn); }
.cam-self[data-state="busy"] { background: var(--card); border-color: var(--line); }
.cam-self[data-state="busy"] b { color: var(--ink); }

@media (min-width: 960px) {
  .room[data-role="teacher"] .micbox.has-cam { display: grid; grid-template-columns: minmax(0, 1fr) minmax(220px, 300px); gap: 16px; }
  .cam-self-slot { display: none; }
}
@media (min-width: 960px) and (max-width: 1199px) {
  .room[data-role="teacher"] .micbox.has-cam { grid-template-columns: minmax(0, 1fr) 176px; }
  .cam-tile { flex-direction: column; justify-content: center; gap: 6px; text-align: center; padding: 10px 12px; }
  .cam-txt { align-items: center; }
  .cam-tile .cam-txt small { display: none; }
  .cam-tile .cam-ic { width: 44px; height: 44px; }
  .cam-tile .cam-prev { width: 112px; height: 63px; }
}

/* Narrow: «دوربین» is one more button in the teacher's bottom bar (style.css .tbar-btn). */
@media (max-width: 959px) {
  .micbox .cam-slot { display: flex; }
  .cam-tile {
    flex-direction: column; justify-content: center; gap: 0;
    width: auto; min-width: 64px; min-height: 56px;
    padding: 4px 6px;
    border-radius: 16px;
    box-shadow: none;
    font-size: 12px; font-weight: 700; line-height: 1.4;
    text-align: center;
  }
  .cam-tile .cam-txt, .cam-tile .cam-prev { display: none; }
  .cam-tile .cam-ic { display: contents; color: var(--muted); }
  .cam-tile .cam-ic[hidden] { display: none; }
  .cam-tile .cam-ic .ic { width: 22px; height: 22px; }
  .cam-short { display: block; }
  /* On, the icon is the camera's live preview in miniature. */
  .cam-tile[data-state="on"] .cam-prev, .cam-tile[data-state="lost"] .cam-prev { display: block; width: 36px; height: 22px; border-radius: 5px; }
  .cam-tile[data-state="on"] .cam-short { color: var(--speak-ink); }
  .cam-tile:is([data-state="fail"], [data-state="denied"], [data-state="nodevice"]) .cam-ic { background: none; color: var(--warn); }
}
/* The teacher's bottom bar (narrow): the mic first, always named — «میکروفون» over «روشنه / خاموشه» — then
   «دوربین» and the jumps (hands, people, chat), each a 44px+ target; the mic takes what is left. */
@media (max-width: 959px) {
  .micbox .speak b { display: flex; flex-direction: column; justify-content: center; font-size: 15.5px; line-height: 1.3; }
  .micbox .speak-w { display: block; font-size: 12px; font-weight: 700; color: var(--muted); white-space: nowrap; }
  .micbox .speak[data-state="on"] .speak-w { color: var(--speak-ink); }
}
@media (max-width: 480px) {
  .room[data-role="teacher"] .micbox { gap: 6px; padding-inline: max(10px, env(safe-area-inset-left)); }
  .micbox .speak { gap: 6px; padding: 4px 8px 4px 6px; }
  .micbox .speak-ic { width: 36px; height: 36px; }
  .micbox .speak-ic .ic { width: 20px; height: 20px; }
  .micbox .tbar-jumps { gap: 6px; }
  .micbox .tbar-btn, .micbox .cam-tile { min-width: 52px; padding: 4px 2px; font-size: 11.5px; }
}

/* ---------- the student's stage: the teacher's video, «فقط صدا» ---------- */
.stage-body { display: contents; }
.stage[data-cam="on"] .stage-ring { display: none; }
.cam-view {
  --l: 0;
  position: relative;
  width: min(100%, 640px, calc(44dvh * 16 / 9));
  aspect-ratio: 16 / 9;
  border-radius: var(--r-lg);
  overflow: hidden;
  background: #1b1916;
  box-shadow: 0 0 0 calc(var(--l) * 6px) var(--speak-line);
  transition: box-shadow .12s ease-out;
}
.stage[data-mode="speaking"] .cam-view[data-lvl] { outline: 3px solid var(--speak); outline-offset: 0; }
.cam-view video { display: block; width: 100%; height: 100%; object-fit: contain; background: #1b1916; }
.stage[data-cam="on"] .stage-name { margin-top: 10px; }

.cam-row { display: flex; flex-direction: column; align-items: center; gap: 0; margin-top: 10px; }
.cam-sw { display: flex; align-items: center; gap: 4px; }
.cam-sw > span { font-size: 15px; font-weight: 700; cursor: pointer; padding-inline-end: 6px; }
.cam-note { margin: 0; color: var(--muted); font-size: 13.5px; line-height: 1.6; max-width: 34ch; }
.cam-note:empty { display: none; }
.cam-row[data-state="lost"] .cam-note { color: var(--muted); } /* quiet: the voice is fine */
/* «فقط صدا» on is a calm choice, not a warning: the switch takes the brand colour here. */
.cam-row .switch[aria-pressed="true"]::before { background: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  .cam-view, .cam-tile { transition: none; }
}

/* ---------- the screen share (STAGE.md: the `screen` stage kind) ---------- */
/* Teacher: «اشتراک صفحه» among the class tools; on, it reads like a voice on the air. */
.share-tool[data-on="1"] { background: var(--speak-soft); border-color: var(--speak-line); }
.share-tool[data-on="1"] .tool-ic { background: var(--speak); color: var(--on-solid); }
.share-tool[data-on="1"] small { color: var(--speak-ink); }
.share-tool:is([data-state="lost"], [data-state="fail"]) small { color: var(--warn); }
.share-btn { flex: none; }

/* Student: the screen takes the stage, in its own shape; the camera sits small in its corner (a tap moves it). */
.screen-view {
  --ar: 1.7778;
  position: relative;
  align-self: center;
  width: min(100%, calc((100dvh - 340px) * var(--ar)));
  aspect-ratio: var(--ar);
  border-radius: var(--r-lg);
  overflow: hidden;
  background: #1b1916;
}
.screen-view > video { display: block; width: 100%; height: 100%; object-fit: contain; background: #1b1916; }
.screen-view .cam-view.corner {
  position: absolute; z-index: 1;
  inset-block-end: 8px; inset-inline-start: 8px;
  width: clamp(88px, 24%, 200px);
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .45);
  cursor: pointer;
}
.screen-view .cam-view.corner.other { inset-inline-start: auto; inset-inline-end: 8px; }
.screen-ask {
  appearance: none;
  display: flex; align-items: center; gap: 10px;
  width: 100%; min-height: 56px;
  padding: 12px 16px;
  border: 1px solid var(--accent-line);
  border-radius: var(--r-lg);
  background: var(--accent-soft); color: var(--accent-strong);
  font-weight: 700; font-size: 15px; line-height: 1.5;
  text-align: start;
  cursor: pointer;
  touch-action: manipulation;
}
.screen-ask .ic { width: 24px; height: 24px; }
@media (hover: hover) { .screen-ask:hover { border-color: var(--accent); } }

/* On the stage (stage.js): the camera fills the stage's camera slot (the whole stage, or a corner tile over a page or
   a screen), the screen fills the screen slot in its own shape, «برای دیدن بزن» sits in the middle of the stage. */
.stg-cam .cam-view { width: 100%; height: 100%; aspect-ratio: auto; border-radius: 0; box-shadow: none; }
.stg-screen .screen-view { position: absolute; inset: 0; width: 100%; height: 100%; aspect-ratio: auto; border-radius: 0; }
.stg-screen .screen-ask { position: relative; z-index: 1; width: auto; max-width: calc(100% - 24px); margin: 0 12px; }
