:root {
  --bg: #111; --fg: #f4f4f4; --muted: #a0a0a0; --panel: #1d1d1d; --line: #333;
  --accent: #4fb3ff; --ok: #3ccf7a; --maybe: #f2c14e; --err: #ff6b6b;
}
* { box-sizing: border-box; }
/* every element here toggles with the hidden attribute, and an author display rule (.fallback is grid, .button
   inline-block) beats the browser's own [hidden] rule. One rule for all of them, never per class. */
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--fg);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
.button { display: inline-block; padding: 12px 18px; border-radius: 10px; border: 0; background: var(--accent);
  color: #000; font: inherit; font-weight: 600; text-align: center; text-decoration: none; cursor: pointer; }
.button:disabled { opacity: .4; cursor: default; }
.link { background: none; border: 0; color: var(--accent); font: inherit; cursor: pointer; padding: 8px; }
.danger { color: var(--err); }
.hint { color: var(--muted); font-size: 14px; }
.error { color: var(--err); }

/* camera page */
body.camera { height: 100dvh; overflow: hidden; }
#video { position: fixed; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
.status { position: fixed; left: 16px; right: 16px; bottom: calc(20px + env(safe-area-inset-bottom));
  display: grid; gap: 4px; padding: 10px 16px 12px; border-radius: 12px; overflow: hidden;
  background: rgba(0, 0, 0, .65); backdrop-filter: blur(6px); }
.status-row { display: flex; gap: 10px; align-items: center; font-weight: 600; }
.detail { font-size: 14px; color: var(--fg); min-height: 1.2em; }
.meta { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
/* a bar that runs while a frame is with the server, so "waiting" never looks like "frozen" */
.bar { height: 3px; margin: -10px -16px 6px; background: rgba(255, 255, 255, .08); }
.bar span { display: block; height: 100%; width: 0; background: var(--accent); }
.status[data-busy="1"] .bar span { animation: run var(--expect, 2s) linear forwards; }
@keyframes run { from { width: 0; } to { width: 95%; } }
.meter { display: inline-block; width: 70px; height: 6px; margin-left: 6px; vertical-align: middle;
  border-radius: 3px; background: rgba(255, 255, 255, .15); overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--maybe); }
.status .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.status[data-state="ok"] .dot { background: var(--ok); }
.status[data-state="maybe"] .dot { background: var(--maybe); }
.status[data-state="err"] .dot { background: var(--err); }
.fallback { position: fixed; inset: 0; display: grid; place-content: center; gap: 16px; padding: 24px;
  text-align: center; }
.card { position: fixed; left: 0; right: 0; bottom: 0; max-height: 85dvh; overflow-y: auto; padding: 20px 16px
  calc(24px + env(safe-area-inset-bottom)); background: var(--panel); border-radius: 18px 18px 0 0; }
.card img { width: 100%; max-height: 40dvh; object-fit: contain; border-radius: 8px; background: #000; }
.card h1 { margin: 12px 0 4px; font-size: 22px; }
.card-text p { margin: 0 0 10px; }
.close { position: absolute; top: 8px; right: 10px; width: 40px; height: 40px; border: 0; border-radius: 50%;
  background: rgba(255, 255, 255, .1); color: var(--fg); font-size: 24px; }
.admin-link { position: fixed; top: calc(12px + env(safe-area-inset-top)); right: 12px; padding: 6px 12px;
  border-radius: 8px; background: rgba(0, 0, 0, .5); color: var(--fg); text-decoration: none; font-size: 14px; }

.about-link { position: fixed; top: calc(12px + env(safe-area-inset-top)); left: 12px; padding: 6px 12px; border: 0;
  border-radius: 8px; background: rgba(0, 0, 0, .5); color: var(--fg); font: inherit; font-size: 14px; cursor: pointer; }
.about h1 { margin: 0; font-size: 20px; }
.about p { margin: 0; }
.about ul { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
#about { max-height: 85dvh; overflow-y: auto; }

/* teaching page */
body.admin { max-width: 760px; margin: 0 auto; padding: 0 16px 40px; }
body.admin header { display: flex; align-items: center; gap: 12px; padding: 12px 0; }
body.admin header h1 { flex: 1; font-size: 20px; margin: 0; }
.back { text-decoration: none; }
.panel { display: grid; gap: 12px; padding: 16px; background: var(--panel); border-radius: 12px; }
label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 8px; color: var(--fg); }
input, textarea, select { width: 100%; padding: 10px; border-radius: 8px; border: 1px solid var(--line);
  background: #111; color: var(--fg); font: inherit; }
input[type=checkbox] { width: auto; }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; overflow-x: auto; }
.tabs button { flex: none; padding: 10px 14px; border: 0; border-radius: 8px; background: var(--panel);
  color: var(--muted); font: inherit; }
.tabs button.active { color: var(--fg); background: #2a2a2a; }
.items { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.items li { display: flex; gap: 12px; align-items: center; padding: 8px; background: var(--panel);
  border-radius: 10px; cursor: pointer; }
.items img { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; background: #000; flex: none; }
.items div { display: grid; }
.grid { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.ref { display: grid; gap: 4px; }
.ref img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; background: #000; }
.preview { display: grid; grid-template-columns: 120px 1fr; gap: 12px; align-items: start; }
.preview img { width: 120px; border-radius: 6px; }
.preview h2 { margin: 0; font-size: 18px; }
dialog { width: min(720px, calc(100vw - 32px)); padding: 0; border: 0; border-radius: 12px; background: var(--panel);
  color: var(--fg); }
dialog::backdrop { background: rgba(0, 0, 0, .7); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.crop-stage { position: relative; touch-action: none; user-select: none; line-height: 0; }
/* the picture takes no pointer events and cannot be dragged: a drag that starts on an <img> becomes the browser's
   own image drag, which CANCELS the pointer events after the first move (measured: pointerdown, one pointermove,
   pointercancel) - the stage owns the whole gesture instead */
.crop-stage img { width: 100%; max-height: 65dvh; object-fit: contain; pointer-events: none; -webkit-user-drag: none; }
.crop-rect { position: absolute; border: 2px solid var(--accent); box-shadow: 0 0 0 9999px rgba(0, 0, 0, .55);
  pointer-events: none; }
