:root {
  --bg: #f6faf4;
  --fg: #1f2d1f;
  --muted: #5b6b5b;
  --accent: #3d8b4f;
  --card: #ffffff;
  --line: #d9e6d6;
  --btn: #2f7a42;
  --on-btn: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121a12;
    --fg: #e6f0e4;
    --muted: #9db09d;
    --accent: #6cc17f;
    --card: #1b261b;
    --line: #2c3b2c;
    --btn: #6cc17f;
    --on-btn: #0f1a0f;
  }
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
}
main { text-align: center; width: 100%; max-width: 36rem; }
.logo { font-size: 4rem; line-height: 1; }
h1 { margin: 0.5rem 0 0.25rem; font-size: clamp(2rem, 6vw, 3rem); }
h1 span { color: var(--accent); }
p { margin: 0; color: var(--muted); font-size: 1.1rem; }
[hidden] { display: none !important; }

/* Child (TV) page: pure black and dim, so it does not draw children's eyes.
   <html class="child"> beats both the light and the dark theme tokens above. */
html.child {
  color-scheme: dark;
  --bg: #000;
  --fg: #444;
  --muted: #333;
  --accent: #2f5a3a;
}
html.child .logo { opacity: 0.3; }
html.child .qr { opacity: 0.6; }

/* Child (TV) page: video. Hidden (but laid out, so the player can load) until the
   first play command; then it covers the screen and the idle content goes away.
   The iframe ignores clicks so nobody can pause it or open YouTube from the TV. */
.video {
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0;
  background: #000;
  visibility: hidden;
}
.video > div { width: 100%; height: 100%; }
.video iframe { display: block; width: 100%; height: 100%; border: 0; pointer-events: none; }
.hint {
  position: absolute;
  left: 50%;
  bottom: 5%;
  transform: translateX(-50%);
  margin: 0;
  padding: 0.5rem 1.25rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.7);
  color: #ddd;
  font-size: 1.25rem;
}
.debug {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 10;
  margin: 0;
  padding: 0.5rem;
  background: rgba(0, 0, 0, 0.7);
  color: #9a9a9a;
  font: 14px/1.3 monospace;
  white-space: pre;
}
html.playing .video { visibility: visible; }
html.playing main { display: none; }

/* Child (TV) page: QR code that opens the master page on a phone.
   The SVG carries its own white background + quiet zone, so it stays
   scannable in dark mode too. */
.qr {
  width: clamp(180px, 22vmin, 320px);
  margin: 2rem auto 0;
  border-radius: 12px;
  overflow: hidden;
}
.qr svg { display: block; width: 100%; height: auto; aspect-ratio: 1 / 1; }

/* Master (phone) page */
.panel {
  margin-top: 1.5rem;
  min-height: 12rem;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: var(--card);
}
.btn {
  min-height: 48px;
  padding: 0 1.5rem;
  border: 0;
  border-radius: 999px;
  background: var(--btn);
  color: var(--on-btn);
  font: inherit;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
}
.field { width: 100%; max-width: 22rem; display: flex; flex-direction: column; gap: 0.35rem; text-align: left; }
.field label { font-size: 0.9rem; color: var(--muted); }
.select {
  min-height: 48px;
  padding: 0 0.75rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  font-size: 1.05rem;
}
.select:disabled { opacity: 0.5; }
.select:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn-secondary { background: transparent; color: var(--fg); border: 1px solid var(--line); }
.controls { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.75rem; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.status { min-height: 1.5em; font-size: 0.95rem; }
.pairing { margin-top: 0.75rem; font-size: 0.95rem; }
.pairing code { color: var(--fg); letter-spacing: 0.1em; }
