:root {
  --bg: #0f1114;
  --surface: #1a1d22;
  --border: #2c3038;
  --text: #e9eaec;
  --muted: #9aa0a8;
  --accent: #3d8bfd;
  --live: #e5484d;
  --ok: #30a46c;
  --warn: #f5a524;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 var(--font); }
[hidden] { display: none !important; }

button, .button {
  font: inherit;
  font-weight: 600;
  min-height: 44px;
  padding: 0 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { background: transparent; border-color: var(--live); color: var(--live); }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Viewer ---------- */

body.viewer { overflow: hidden; overscroll-behavior: none; }

.stage {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  background: #000;
}

.wrapper {
  position: absolute;
  inset: 0;
  transform-origin: 0 0;
  will-change: transform;
}
.wrapper.animating { transition: transform 200ms ease-out; }
@media (prefers-reduced-motion: reduce) { .wrapper.animating { transition: none; } }

.wrapper video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}
.wrapper video.inactive { opacity: 0; }

.live-pill {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  font-size: 13px;
  font-weight: 600;
  pointer-events: none;
}
.live-pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--live); }

.status-card {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(360px, calc(100vw - 32px));
  padding: 20px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: rgba(20, 22, 26, 0.92);
  text-align: center;
  pointer-events: none;
}
.status-card h1 { margin: 0 0 4px; font-size: 20px; }
.status-card p { margin: 0; color: var(--muted); font-size: 15px; }
.status-card button { margin-top: 12px; pointer-events: auto; }
.status-card[data-state="connecting"] h1::after,
.status-card[data-state="reconnecting"] h1::after { content: "..."; }

.toolbar {
  position: absolute;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  display: flex;
  gap: 8px;
  align-items: center;
}
.toolbar button { background: rgba(26, 29, 34, 0.85); font-size: 14px; }
.zoom-level { min-width: 40px; text-align: center; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

body.pseudo-fullscreen .toolbar > :not(#fullscreen) { display: none; }
body.pseudo-fullscreen .live-pill { display: none; }

.toast {
  position: absolute;
  left: 50%;
  bottom: calc(max(12px, env(safe-area-inset-bottom)) + 56px);
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 8px 14px;
  border-radius: var(--radius);
  background: rgba(20, 22, 26, 0.95);
  border: 1px solid var(--border);
  font-size: 14px;
  pointer-events: none;
}

.debug {
  position: absolute;
  top: max(44px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.7);
  font: 12px/1.5 ui-monospace, Menlo, monospace;
  pointer-events: none;
}

/* ---------- Teacher ---------- */

.page { max-width: 960px; margin: 0 auto; padding: 24px 16px 48px; }
.page h1 { font-size: 24px; margin: 0 0 16px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 14px; color: var(--muted); }
.field select, .field input {
  font: inherit;
  min-height: 44px;
  padding: 0 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
.field input { width: 110px; }

.status { font-weight: 700; }
.status[data-state="live"] { color: var(--live); }
.status[data-state="paused"] { color: var(--warn); }
.status[data-state="reconnecting"] { color: var(--warn); }
.error { color: #ff8d8d; margin: 12px 0 0; }
.stats { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; min-height: 1.5em; margin: 8px 0 0; }
.preview { width: 100%; max-height: 360px; background: #000; border-radius: var(--radius); margin-top: 12px; }

.join { display: grid; grid-template-columns: auto 1fr; gap: 24px; align-items: center; }
.join img, .join svg { width: 220px; height: 220px; background: #fff; border-radius: var(--radius); padding: 8px; }
.join-url { font-size: 28px; font-weight: 700; word-break: break-all; }
.viewer-count { font-size: 40px; font-weight: 700; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
@media (max-width: 640px) { .join { grid-template-columns: 1fr; } }

/* ---------- Teacher spotlight ---------- */

.spot-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-bottom: 12px; }
.spot-state { color: var(--muted); flex: 1; }
.preview-wrap {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  cursor: crosshair;
  touch-action: none;
  user-select: none;
}
.preview-wrap .preview { display: block; margin: 0; border-radius: 0; height: 360px; max-height: none; object-fit: contain; }
.preview-wrap.spot-off { cursor: default; pointer-events: none; }
.spot-box, .spot-drag { position: absolute; pointer-events: none; box-sizing: border-box; }
.spot-box { border: 3px solid var(--warn); box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.45); }
.spot-drag { border: 2px dashed #fff; }
.spot-hint { font-size: 14px; margin: 8px 0 0; }
.helper-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-top: 12px; font-size: 14px; }
.helper-monitor { display: flex; gap: 8px; align-items: center; }
.helper-monitor select { font: inherit; min-height: 36px; border-radius: var(--radius); background: var(--bg); color: var(--text); border: 1px solid var(--border); }

body.pip { margin: 0; }
body.pip .spot-panel { margin: 0; border: 0; border-radius: 0; padding: 8px; min-height: 100vh; }
body.pip .preview-wrap .preview { height: calc(100vh - 110px); }
