:root {
  --bg: #0f1115;
  --panel: #171a21;
  --line: #262b35;
  --text: #e8eaed;
  --muted: #9aa2b1;
  --accent: #e8543f;   /* warm ember — matches the house look */
  --ok: #34c759;
  --bad: #ff5b5b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* --- Join gate --- */
.gate {
  position: fixed;
  inset: 0;
  display: flex;         /* card centred when it fits, scrollable when it doesn't */
  overflow-y: auto;
  padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, #1c2029, var(--bg));
}
.gate.hidden { display: none; }
.gate > .card { margin: auto; }

.card {
  width: 100%;
  max-width: 460px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 32px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.card h1 { margin: 0 0 8px; font-size: 28px; letter-spacing: -0.02em; }
.card .sub { color: var(--muted); line-height: 1.5; margin: 0 0 24px; }
.card label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.card input {
  width: 100%;
  padding: 13px 14px;
  background: #0e1015;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  font-size: 16px;
  margin-bottom: 16px;
}
.card input:focus { outline: none; border-color: var(--accent); }
.hint { color: var(--muted); font-size: 13px; margin: 16px 0 0; }
.error { color: var(--bad); font-size: 14px; margin: 12px 0 0; min-height: 1em; }

.card select {
  width: 100%;
  padding: 12px 14px;
  background: #0e1015;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  font-size: 15px;
  margin-bottom: 16px;
}
.card select:focus { outline: none; border-color: var(--accent); }

.setup.hidden { display: none; }
.hidden { display: none !important; }

.preview {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 12px;
  margin-bottom: 18px;
  object-fit: cover;
  transform: scaleX(-1); /* mirror your own preview */
}

/* Host dashboard bits */
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.row-between h1 { margin: 0; }
.linkrow { display: flex; gap: 8px; margin-bottom: 16px; }
.linkrow input { flex: 1; margin-bottom: 0; }
button.small { padding: 8px 14px; font-size: 14px; width: auto; }
button.ghost { background: transparent; border-color: var(--line); color: var(--muted); }
.sep { border: none; border-top: 1px solid var(--line); margin: 22px 0 16px; }
form label:first-child { margin-top: 0; }

button {
  cursor: pointer;
  border: 1px solid var(--line);
  background: #21262f;
  color: var(--text);
  padding: 11px 16px;
  border-radius: 10px;
  font-size: 15px;
  transition: transform 0.05s ease, background 0.15s ease, border-color 0.15s ease;
}
button:hover { border-color: #3a424f; }
button:active { transform: translateY(1px); }
button.off { border-color: var(--accent); background: rgba(232, 84, 63, 0.14); }
button.primary { width: 100%; background: var(--accent); border-color: var(--accent); font-weight: 600; padding: 14px; }
button.primary:hover { filter: brightness(1.05); }
button.danger { background: rgba(255, 91, 91, 0.14); border-color: rgba(255, 91, 91, 0.4); }
button:disabled { opacity: 0.5; cursor: default; }

/* The one button that matters: opens the raw instrument audio to the student.
   OFF = calm/neutral (student hears only clean, filtered audio).
   ON  = loud, pulsing "ON AIR" so you can never forget the room is open. */
button.instrument {
  font-weight: 700;
  font-size: 15px;
  padding: 12px 18px;
  border: 2px solid var(--accent);
  color: #ffd9d1;
  background: rgba(232, 84, 63, 0.12);
}
button.instrument:hover { background: rgba(232, 84, 63, 0.2); }
button.instrument.on-air {
  color: #fff;
  background: var(--accent);
  border-color: #ffd9d1;
  box-shadow: 0 0 0 0 rgba(232, 84, 63, 0.7);
  animation: onair 1.4s ease-out infinite;
}
@keyframes onair {
  0%   { box-shadow: 0 0 0 0 rgba(232, 84, 63, 0.6); }
  70%  { box-shadow: 0 0 0 14px rgba(232, 84, 63, 0); }
  100% { box-shadow: 0 0 0 0 rgba(232, 84, 63, 0); }
}

/* A thin banner along the top edge whenever the instrument mic is live. */
body.on-air .stage::before {
  content: "🎸 INSTRUMENT SOUND IS LIVE — the student can hear your room";
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 10;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #fff;
  padding: 7px;
  background: var(--accent);
}

/* --- Stage --- */
.stage { display: none; height: 100%; flex-direction: column; }
body.in-call .stage { display: flex; }

/* Responsive grid of participant tiles (1–4). */
.grid {
  flex: 1;
  min-height: 0;
  background: #000;
  display: grid;
  gap: 6px;
  padding: 6px;
  grid-template-columns: 1fr;
}
.grid[data-count="2"] { grid-template-columns: 1fr 1fr; }
.grid[data-count="3"], .grid[data-count="4"] { grid-template-columns: 1fr 1fr; grid-auto-rows: 1fr; }

.tile { position: relative; background: #0a0c10; border-radius: 10px; overflow: hidden; min-height: 0; }
.tile video { width: 100%; height: 100%; object-fit: cover; background: #0a0c10; display: block; }
.tile video.mirror { transform: scaleX(-1); } /* mirror your own preview */
.tile .tag {
  position: absolute;
  left: 10px;
  bottom: 10px;
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
}

/* --- Control bar --- */
.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
}
.controls { display: flex; gap: 10px; flex-wrap: wrap; }

.status {
  font-size: 14px;
  color: var(--muted);
  padding-left: 22px;
  position: relative;
}
.status::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
}
.status.ok { color: var(--ok); }
.status.ok::before { background: var(--ok); box-shadow: 0 0 10px var(--ok); }
.status.bad { color: var(--bad); }
.status.bad::before { background: var(--bad); }

/* Viewer mode: the iPad watches only — hide sender-only controls' gaps. */
body.viewer .instrument, body.viewer #micBtn, body.viewer #camBtn { display: none; }

@media (max-width: 640px) {
  .grid, .grid[data-count] { grid-template-columns: 1fr; }
  .bar { justify-content: center; }
}

/* Gate: give the viewer button a little breathing room under the primary one. */
#viewerBtn { margin-top: 10px; width: 100%; }

/* Invite-link row: the link takes the space, the Copy button sizes to its label */
.card .linkrow input { flex: 1 1 auto; min-width: 0; }
.card .linkrow button { flex: 0 0 auto; width: auto; margin: 0; }
.row-between { margin-bottom: 10px; }
.row-between button { white-space: nowrap; flex: 0 0 auto; }

/* --- Participants panel (teacher only), right-hand side of the call --- */
.main-row { flex: 1; min-height: 0; display: flex; }
.main-row .grid { flex: 1; min-width: 0; }
.panel {
  width: 280px;
  flex: 0 0 280px;
  background: var(--panel);
  border-left: 1px solid var(--line);
  padding: 16px;
  overflow-y: auto;
}
.panel h2 { font-size: 15px; margin: 0 0 12px; font-weight: 700; }
.panel h2 span { color: var(--muted); font-weight: 500; }
.panel ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.panel li { background: #0e1015; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.panel .who { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.panel .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel .badge { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 2px 8px; white-space: nowrap; }
.panel .icons { font-size: 12px; color: var(--muted); margin-top: 6px; }
.panel .conn { font-size: 12px; margin-top: 4px; color: var(--muted); }
.panel .conn.ok { color: var(--ok); }
.panel .conn.bad { color: var(--bad); }
@media (max-width: 900px) {
  .main-row { flex-direction: column; }
  .panel { width: auto; flex: 0 0 auto; max-height: 34vh; border-left: none; border-top: 1px solid var(--line); }
}
/* Watch-only button: small, set apart, teacher devices only */
#viewerBtn { margin-top: 18px; width: auto; }
/* Make room for the ON AIR banner instead of covering the videos and panel */
body.on-air .stage { padding-top: 32px; }

/* --- Waiting room, recording, screen share --- */
.main-row { position: relative; }
.wait { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(8, 9, 12, 0.72); z-index: 5; padding: 16px; }
.wait .card { max-width: 440px; text-align: center; }
.wait h2 { margin: 0 0 10px; font-size: 22px; }
.wait .sub { margin: 0; }
.panel li.waiting { border-color: var(--accent); }
.panel .actions { display: flex; gap: 8px; margin-top: 8px; }
.panel .actions button { flex: 1; width: auto; padding: 8px 10px; font-size: 14px; }
.tile.screen video { object-fit: contain; }
.tile.screen video.mirror { transform: none; }
.rec-badge {
  position: fixed; top: 10px; right: 12px; z-index: 11;
  background: rgba(20, 20, 24, 0.9); color: #fff; border: 1px solid var(--bad);
  border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600;
}
body.on-air .rec-badge { top: 42px; }
#recBtn.recording { border-color: var(--bad); background: rgba(255, 91, 91, 0.18); }
.muted { color: var(--muted); font-weight: 400; }
.passmsg { margin: -6px 0 14px; }
#lobbyBox { margin-bottom: 18px; }

/* --- Sound: level meters + "tap to turn on sound" --- */
.tile .meter { position: absolute; right: 10px; bottom: 12px; width: 60px; height: 8px; border-radius: 4px; background: rgba(0,0,0,0.55); overflow: hidden; }
.tile .meter i { display: block; height: 100%; width: 0; background: var(--ok); transition: width 0.15s linear; }
.panel .lvl { display: flex; align-items: center; gap: 6px; margin-top: 6px; font-size: 12px; }
.panel .lvl b { flex: 1; height: 6px; border-radius: 3px; background: #262b35; overflow: hidden; }
.panel .lvl i { display: block; height: 100%; width: 0; background: var(--ok); transition: width 0.15s linear; }
.sound-unlock {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 20;
  font-size: 20px; font-weight: 700; padding: 18px 28px; border-radius: 14px;
  background: var(--accent); border-color: var(--accent); color: #fff;
  box-shadow: 0 10px 40px rgba(0,0,0,0.6);
}
