/* 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); }
}
/* On a phone the mic button keeps its word «روشنه / خاموشه»; «میکروفون» folds away earlier with one more button. */
@media (max-width: 480px) {
  .micbox.has-cam .speak-w { display: none; }
}
@media (max-width: 380px) {
  .micbox.has-cam .tbar-btn, .micbox.has-cam .cam-tile { min-width: 56px; }
}

/* ---------- 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); }

/* A laptop: the video beside the floor and the button (like a phone on its side). */
@media (min-width: 960px) {
  .room[data-role="student"][data-cam="on"] .room-main {
    display: grid;
    grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
    align-items: center;
    gap: 14px 32px;
  }
  .room[data-role="student"][data-cam="on"] .room-main > * { grid-column: 2; }
  .room[data-role="student"][data-cam="on"] .room-main > .stage { grid-column: 1; grid-row: 1 / span 8; padding: 0; align-self: start; }
  .room[data-role="student"][data-cam="on"] .thumb { width: 100%; }
  .room[data-role="student"][data-cam="on"] .cam-view { width: min(100%, 640px, calc((100dvh - 260px) * 16 / 9)); }
}
/* A phone on its side: the video fills the stage's column, short enough to leave «فقط صدا» in view. */
@media (max-width: 959px) and (max-height: 540px) and (orientation: landscape) {
  .cam-view { width: min(100%, calc((100dvh - 200px) * 16 / 9)); }
  .stage[data-cam="on"] .stage-name { margin-top: 6px; font-size: 16px; }
  .cam-row { margin-top: 4px; }
}
@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); } }

/* A laptop: the screen across the card, the words and the button under it side by side. */
@media (min-width: 960px) {
  .room[data-role="student"][data-screen="on"] .room-main {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: center;
    gap: 14px 32px;
  }
  .room[data-role="student"][data-screen="on"] .room-main > * { grid-column: 2; }
  .room[data-role="student"][data-screen="on"] .room-main > .screen-view { grid-column: 1 / -1; grid-row: 1; justify-self: center; }
  .room[data-role="student"][data-screen="on"] .room-main > .stage { grid-column: 1; grid-row: 2 / span 6; padding: 0; }
  .room[data-role="student"][data-screen="on"] .thumb { width: 100%; }
}
/* A phone on its side: the screen fills the height, the rest in a narrow column beside it. */
@media (max-width: 959px) and (max-height: 540px) and (orientation: landscape) {
  .room[data-role="student"][data-screen="on"] .room-main { grid-template-columns: minmax(0, 1fr) 230px; gap: 8px 16px; }
  .room[data-role="student"][data-screen="on"] .room-main > .screen-view {
    grid-column: 1; grid-row: 1 / span 8; align-self: start;
    width: min(100%, calc((100dvh - 90px) * var(--ar)));
    position: sticky; top: 12px;
  }
  .room[data-role="student"][data-screen="on"] .room-main > .stage { grid-column: 2; grid-row: auto; position: static; }
}
