:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1c1f24;
  --muted: #5d6470;
  --border: #d8dce2;
  --accent: #9d2235; /* cardinal */
  --accent-text: #ffffff;
  --green: #1f8a4c;
  --green-bg: #e6f4ec;
  --yellow: #b7791f;
  --yellow-bg: #fdf3dc;
  --red: #c53030;
  --red-bg: #fde8e8;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 4px 14px rgb(0 0 0 / 0.06);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121418;
    --surface: #1c1f25;
    --text: #e8eaed;
    --muted: #9aa1ac;
    --border: #2f343c;
    --accent: #d0435a;
    --green: #3ccf7a;
    --green-bg: #15301f;
    --yellow: #f0b43c;
    --yellow-bg: #33290f;
    --red: #f26464;
    --red-bg: #3a1a1a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1 { font-size: 1.6rem; margin: 0 0 0.75rem; }

button, .button {
  font: inherit;
  font-size: 0.95rem;
  padding: 0.5rem 0.9rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  line-height: 1.3;
}
button:hover, .button:hover { border-color: var(--muted); }
button:disabled { opacity: 0.6; cursor: progress; }
button:focus-visible, .button:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.danger { background: var(--red); border-color: var(--red); color: #fff; font-weight: 600; }
button.big { font-size: 1.1rem; padding: 0.75rem 1.4rem; }
.button.disabled { opacity: 0.55; }

input {
  font: inherit;
  width: 100%;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}
label { display: block; font-weight: 600; margin: 0.9rem 0 0.3rem; }
.code-input { font-family: ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace; letter-spacing: 0.12em; text-transform: uppercase; }

.muted { color: var(--muted); }
.error { color: var(--red); font-weight: 600; margin: 0.75rem 0 0; }
.hint { color: var(--muted); font-size: 0.9rem; }

/* ---------------------------------------------------------------- narrow pages */

.page-narrow main.card {
  max-width: 560px;
  margin: 2rem auto;
  padding: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
@media (max-width: 600px) {
  .page-narrow main.card { margin: 0; border-radius: 0; border-left: 0; border-right: 0; min-height: 100vh; padding: 1.25rem 1rem; }
}
.page-narrow form button.primary { margin-top: 1.2rem; width: 100%; font-size: 1.05rem; padding: 0.7rem; }

.lead { margin-top: 0; }
.facts { padding-left: 1.2rem; margin: 0 0 0.5rem; }
.facts li { margin-bottom: 0.4rem; }

.help { margin-top: 1rem; border: 1px solid var(--border); border-radius: 8px; padding: 0.6rem 0.8rem; }
.help summary { cursor: pointer; font-weight: 600; }
.help ol { margin: 0.6rem 0 0.2rem; padding-left: 1.3rem; }
kbd { font-family: inherit; border: 1px solid var(--border); border-radius: 4px; padding: 0 0.3rem; }

.banner { padding: 0.8rem 1rem; border-radius: 8px; font-weight: 600; margin: 0 0 1rem; }
.banner-live { background: var(--green-bg); color: var(--green); border: 1px solid var(--green); display: flex; align-items: center; gap: 0.6rem; }
.banner-off { background: var(--bg); color: var(--muted); border: 1px solid var(--border); }
.banner-warn { background: var(--yellow-bg); color: var(--yellow); border: 1px solid var(--yellow); margin: 0.75rem 1rem 0; }
.dot { width: 0.7rem; height: 0.7rem; border-radius: 50%; background: var(--green); flex: none; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .dot { animation: none; } }

.status-line { margin: 0.3rem 0; }
#stop-btn { margin: 0.8rem 0 0.4rem; }
.preview { margin: 1rem 0 0; }
.preview canvas { width: 100%; height: auto; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); display: block; }
.preview figcaption { color: var(--muted); font-size: 0.85rem; margin-top: 0.3rem; }

/* Off-screen <video> used only as a frame source for capture. */
.capture-video { position: fixed; right: 0; bottom: 0; width: 2px; height: 2px; opacity: 0; pointer-events: none; }

/* ---------------------------------------------------------------- admin */

.topbar { background: var(--surface); border-bottom: 1px solid var(--border); padding: 0.75rem 1rem; position: sticky; top: 0; z-index: 5; }
.topbar-row, .session-row { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.session-row { margin-top: 0.6rem; }
.brand { font-size: 1.15rem; margin: 0; }
.counts { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; flex: 1; }
.tools { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.check { display: inline-flex; align-items: center; gap: 0.35rem; font-weight: 400; margin: 0; }
.check input { width: auto; }
.label { color: var(--muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; }
.code { font-family: ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace; font-size: 1.5rem; font-weight: 700; letter-spacing: 0.08em; }
.join-url { font-family: ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace; overflow-wrap: anywhere; }
.spacer { flex: 1; }

.empty { color: var(--muted); text-align: center; margin: 3rem 1rem; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 0.75rem;
  padding: 1rem;
}

.tile {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.tile.state-green { border-color: var(--green); }
.tile.state-yellow { border-color: var(--yellow); background: var(--yellow-bg); }
.tile.state-red { border-color: var(--red); background: var(--red-bg); }
.tile.state-red img { opacity: 0.45; filter: grayscale(1); }

.tile-view { padding: 0; border: 0; border-radius: 0; background: #000; aspect-ratio: 16 / 10; position: relative; display: block; width: 100%; cursor: zoom-in; }
.tile-view img { width: 100%; height: 100%; object-fit: contain; display: block; }
.tile:not(.has-frame) .tile-view img { display: none; }
.tile-placeholder { position: absolute; inset: 0; display: grid; place-items: center; color: #aaa; font-size: 0.9rem; }
.tile.has-frame .tile-placeholder { display: none; }

.tile-info { display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto auto; column-gap: 0.5rem; padding: 0.45rem 0.6rem; align-items: center; }
.tile-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-age { grid-column: 1; grid-row: 2; font-size: 0.82rem; color: var(--muted); }
.state-green .tile-age { color: var(--green); }
.state-yellow .tile-age { color: var(--yellow); }
.state-red .tile-age { color: var(--red); font-weight: 600; }
.tile-remove { grid-column: 2; grid-row: 1 / span 2; font-size: 0.8rem; padding: 0.3rem 0.55rem; }

.stats { color: var(--muted); font-size: 0.85rem; padding: 0 1rem 1rem; font-variant-numeric: tabular-nums; }

dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 0; }
dialog::backdrop { background: rgb(0 0 0 / 0.75); }
.viewer { width: min(96vw, 1400px); max-height: 94vh; }
.viewer img { display: block; width: 100%; max-height: calc(94vh - 3.5rem); object-fit: contain; background: #000; }
.viewer-bar { display: flex; align-items: center; gap: 0.75rem; padding: 0.6rem 0.9rem; }

.presenter { text-align: center; padding: 2rem 3rem; }
.presenter-label { margin: 0; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.presenter-code { font-family: ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace; font-size: clamp(3rem, 12vw, 9rem); font-weight: 800; letter-spacing: 0.08em; margin: 0.5rem 0; }
.presenter-url { font-size: clamp(1rem, 3vw, 2rem); overflow-wrap: anywhere; margin: 0 0 1.5rem; }

.toast { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 0.6rem 1rem; border-radius: 8px; z-index: 20; }
