:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --line: #e2e5ea;
  --text: #1c2330;
  --muted: #667085;
  --accent: #3b5bdb;
  --accent-ink: #ffffff;
  --live: #d92d20;
  --ok: #12805c;
  --warn: #b54708;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
a { color: var(--accent); }
[hidden] { display: none !important; }
.icon { width: 18px; height: 18px; flex: none; vertical-align: -3px; }
.hands { color: var(--warn); }
.hands .icon { width: 15px; height: 15px; margin-right: 4px; }

/* ── Top bar ─────────────────────────────────────────────── */
.topbar { display: flex; align-items: center; gap: 20px; padding: 0 24px; height: 56px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; letter-spacing: .2px; }
.brand span { color: var(--accent); }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a { padding: 8px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500; }
.topbar nav a.active { background: #eef1fd; color: var(--accent); }
.topbar .who { color: var(--muted); font-size: 14px; }
.page { max-width: 1180px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }

/* ── Controls ────────────────────────────────────────────── */
button, .btn { font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--surface); color: var(--text); padding: 7px 12px; border-radius: 8px; font-weight: 500; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
button:hover, .btn:hover { border-color: #c3c9d4; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.danger { color: var(--live); border-color: #f3c5c1; }
button.danger.solid { background: var(--live); border-color: var(--live); color: #fff; }
button.small, .btn.small { padding: 4px 9px; font-size: 13px; }
button.link { border: 0; background: none; color: var(--accent); padding: 0; }
input, select { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); width: 100%; }
input:focus, select:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
.field { margin-bottom: 14px; }
.field small { display: block; color: var(--muted); margin-top: 4px; font-size: 12.5px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: auto; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ── Surfaces ────────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.card .meta { color: var(--muted); font-size: 13.5px; margin: 6px 0 14px; }
.card-head { display: flex; justify-content: space-between; align-items: start; gap: 10px; }
.card-head h3 { margin: 0; font-size: 16px; }
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 600; background: #fafbfc; }
tr:last-child td { border-bottom: 0; }
td .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.empty { padding: 36px; text-align: center; color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
.kv { display: grid; grid-template-columns: 220px 1fr; gap: 10px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 600; background: #eef0f3; color: var(--muted); white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.live { background: #fdecea; color: var(--live); }
.pill.ok { background: #e3f5ee; color: var(--ok); }
.pill.warn { background: #fdf0e1; color: var(--warn); }
.pill.live::before { animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .pill.live::before { animation: none; } }

dialog { border: 1px solid var(--line); border-radius: 12px; padding: 22px; width: min(540px, 92vw); box-shadow: 0 20px 60px rgba(16, 24, 40, .25); color: var(--text); }
dialog::backdrop { background: rgba(16, 24, 40, .45); }
dialog h2 { font-size: 18px; margin-bottom: 16px; }
dialog .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.form-error { color: var(--live); font-size: 13.5px; min-height: 18px; margin-top: 6px; }

#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: #1c2330; color: #fff; padding: 10px 14px; border-radius: 8px; max-width: 380px; font-size: 14px; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); }
.toast.error { background: #b42318; }

/* ── Login / join gate ───────────────────────────────────── */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.gate .card { width: min(400px, 100%); padding: 28px; }
.gate h1 { margin-bottom: 4px; }
.gate p { color: var(--muted); margin: 0 0 20px; }
.gate button.primary { width: 100%; justify-content: center; padding: 10px; }

/* ── Classroom ───────────────────────────────────────────── */
body.room { background: #0e1116; color: #e8eaed; height: 100vh; display: grid; grid-template-rows: 52px 1fr 68px; overflow: hidden; }
.room-bar { display: flex; align-items: center; gap: 12px; padding: 0 18px; border-bottom: 1px solid #232832; }
.room-bar .title { font-weight: 600; flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0; }
.room-bar .title span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-bar .conn { color: #9aa3b2; font-size: 13px; }
.room .pill { background: #232832; color: #9aa3b2; }
.room .pill.live { background: #3a1512; color: #ff7b72; }
.room .pill.ok { background: #10301f; color: #56d39b; }
.room .pill.warn { background: #3a2a10; color: #f0b25a; }
.room-main { display: grid; grid-template-columns: 1fr 300px; min-height: 0; }
.room-main.solo { grid-template-columns: 1fr; }
.stage-wrap { position: relative; min-height: 0; padding: 12px; overflow: auto; }
.stage { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; align-content: start; }
.tile { position: relative; background: #1a1f28; border-radius: 10px; overflow: hidden; aspect-ratio: 16 / 9; display: grid; place-items: center; border: 2px solid transparent; }
.tile.featured { grid-column: 1 / -1; grid-row: 1; order: -1; max-height: calc(100vh - 220px); width: 100%; justify-self: center; }
/* Picture-in-picture: the presenter's camera shares the featured tile's grid cell and sits in its corner. */
.tile.pip { grid-column: 1 / -1; grid-row: 1; order: -1; align-self: end; justify-self: end; width: clamp(120px, 22%, 300px); margin: 12px; z-index: 2; border-color: rgba(255, 255, 255, .35); box-shadow: 0 6px 24px rgba(0, 0, 0, .55); }
.tile.pip .avatar { width: 40px; height: 40px; font-size: 17px; }
.tile.pip .label { font-size: 11.5px; left: 6px; bottom: 6px; }
.tile.speaking { border-color: #4c7cf3; }
.tile video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
.tile.screen video { object-fit: contain; }
.tile.local:not(.screen) video { transform: scaleX(-1); }
.tile.novideo video { display: none; }
.tile .avatar { width: 64px; height: 64px; border-radius: 50%; background: #2c3442; display: grid; place-items: center; font-size: 26px; font-weight: 600; color: #b9c2d0; }
.tile .label { position: absolute; left: 8px; bottom: 8px; padding: 3px 9px; border-radius: 6px; background: rgba(0, 0, 0, .6); font-size: 12.5px; max-width: calc(100% - 16px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.yt { width: 100%; height: 100%; border: 0; border-radius: 10px; background: #000; }
.overlay { position: absolute; inset: 0; display: grid; place-items: center; background: #0e1116; z-index: 5; padding: 20px; }
.overlay .box { text-align: center; max-width: 420px; }
.overlay h2 { font-size: 20px; margin-bottom: 8px; }
.overlay p { color: #9aa3b2; margin: 0 0 18px; }
.overlay input { margin-bottom: 12px; background: #1a1f28; border-color: #2c3442; color: #e8eaed; }
.side { border-left: 1px solid #232832; padding: 14px; overflow: auto; }
.side h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: #9aa3b2; margin: 0 0 8px; }
.side section { margin-bottom: 22px; }
.side .person { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 7px 0; border-bottom: 1px solid #1c212a; font-size: 14px; }
.side .person span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side h2.with-icon { display: flex; align-items: center; gap: 6px; }
.side h2.with-icon .icon { width: 15px; height: 15px; }
.side h2.raised, .side .who .icon { color: #f0b25a; }
.side .who { display: flex; align-items: center; gap: 6px; min-width: 0; }
.side .who .icon { width: 15px; height: 15px; }
.room button.hand .icon { width: 20px; height: 20px; }
.room button.hand.raised { background: #3a2a10; border-color: #8a5f17; color: #f5c069; }
.room button.hand.raised .icon { fill: rgba(245, 192, 105, .25); }
.side .none { color: #6b7483; font-size: 13.5px; }
.side .stat { display: flex; justify-content: space-between; padding: 4px 0; font-size: 14px; color: #c5ccd8; }
.side input { background: #1a1f28; border-color: #2c3442; color: #c5ccd8; font-size: 13px; }
.controls { display: flex; align-items: center; justify-content: center; gap: 10px; border-top: 1px solid #232832; padding: 0 16px; }
.controls .spacer { flex: 1; }
.room button, .room .btn { background: #232832; border-color: #2f3644; color: #e8eaed; }
.room button:hover, .room .btn:hover { border-color: #46506380; background: #2a303b; }
.room button.off { background: #3a1512; border-color: #5a211c; color: #ff9d96; }
.room button.primary { background: var(--accent); border-color: var(--accent); }
.room button.danger.solid { background: var(--live); border-color: var(--live); color: #fff; }
.banner { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); background: #3a2a10; color: #f0b25a; padding: 7px 14px; border-radius: 8px; font-size: 13.5px; z-index: 4; }

@media (max-width: 820px) {
  .room-main { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .side { border-left: 0; border-top: 1px solid #232832; max-height: 34vh; }
  .kv { grid-template-columns: 1fr; }
  .topbar { padding: 0 12px; gap: 10px; }
  .page { padding: 16px 12px; }
}
