:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #14202b;
  --muted: #55636f;
  --line: #d5dce2;
  --primary: #0b7a3b;
  --primary-text: #ffffff;
  --danger: #c62828;
  --danger-text: #ffffff;
  --warn-bg: #fff4d6;
  --warn-text: #5a4300;
  --err-bg: #fde4e4;
  --err-text: #7a1111;
  --accent: #1456c9;
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419;
    --card: #1a222b;
    --text: #eef2f6;
    --muted: #a7b3be;
    --line: #2f3b47;
    --primary: #2fb36a;
    --primary-text: #04170c;
    --warn-bg: #3b3011;
    --warn-text: #ffe29a;
    --err-bg: #421616;
    --err-text: #ffc9c9;
    --accent: #7fa8ff;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Myanmar", "Myanmar Text", "Padauk", sans-serif;
  font-size: 18px;
  line-height: 1.5;
  padding-bottom: env(safe-area-inset-bottom);
}
body.is-active { padding-bottom: calc(110px + env(safe-area-inset-bottom)); }

.en { display: block; }
.my { display: block; font-size: 0.86em; opacity: 0.92; line-height: 1.6; }

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 1.05rem; margin: 0; flex: 1; line-height: 1.3; }
.topbar a.back { font-size: 1.6rem; text-decoration: none; color: var(--accent); min-width: 44px; min-height: 44px; display: grid; place-items: center; }
.topbar select { width: auto; min-height: 44px; font-size: 0.95rem; padding: 4px 8px; }

main { max-width: 640px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card h2 { margin: 0 0 8px; font-size: 1.25rem; }
.card h3 { margin: 16px 0 4px; font-size: 1.05rem; }
.card p { margin: 6px 0; }
.muted { color: var(--muted); font-size: 0.92rem; }
.bullets { padding-left: 22px; margin: 8px 0 16px; }
.bullets li { margin: 6px 0; }

label { display: block; margin: 12px 0 4px; font-weight: 600; }
input, select {
  width: 100%; min-height: 56px; padding: 10px 14px;
  font: inherit; color: var(--text); background: var(--bg);
  border: 2px solid var(--line); border-radius: 12px;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px;
}
.code-input { font-size: 2rem; text-align: center; letter-spacing: 0.35em; font-variant-numeric: tabular-nums; }

.btn {
  display: block; width: 100%; min-height: 64px; margin: 10px 0 0;
  padding: 12px 16px; font: inherit; font-weight: 700; font-size: 1.1rem;
  border: 2px solid transparent; border-radius: var(--radius);
  cursor: pointer; text-align: center; text-decoration: none;
  background: var(--card); color: var(--text); border-color: var(--line);
}
.btn:active { transform: scale(0.99); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.btn.danger { background: var(--danger); color: var(--danger-text); border-color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.light { background: #fff; color: #7a0c0c; border-color: #fff; min-height: 52px; margin: 0; }
.btn.small { min-height: 48px; font-size: 1rem; margin-top: 6px; }
.btn.big { min-height: 72px; font-size: 1.25rem; }
.btn.role { text-align: left; padding: 18px; }
.btn.role .en { font-size: 1.2rem; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid2 .btn { margin: 0; }

.notice { padding: 12px 14px; border-radius: 12px; margin: 10px 0; font-weight: 600; }
.notice.warn { background: var(--warn-bg); color: var(--warn-text); }
.notice.error { background: var(--err-bg); color: var(--err-text); }

/* ---- active indicator (Device A) ---- */
.active-banner {
  position: sticky; top: 0; z-index: 60;
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px; background: var(--danger); color: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}
.active-banner .banner-title { font-size: 1.2rem; font-weight: 800; line-height: 1.25; }
.active-banner .banner-sub { font-size: 0.9rem; opacity: 0.95; }
.rec-banner {
  position: sticky; top: 0; z-index: 59;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px; background: #5c0a0a; color: #fff; font-weight: 800;
  border-top: 2px solid #fff;
}
.rec-banner > div { flex: 1; min-width: 160px; }
.dot {
  flex: none; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.8);
  animation: pulse 1.4s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.8); }
  70% { box-shadow: 0 0 0 12px rgba(255, 255, 255, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0); }
}
@media (prefers-reduced-motion: reduce) { .dot { animation: none; } }

.stopbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 70;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--bg); border-top: 1px solid var(--line);
}
.stopbar .btn { max-width: 608px; margin: 0 auto; min-height: 76px; font-size: 1.35rem; }

.preview-wrap, .video-wrap { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; }
.preview-wrap video { width: 100%; max-height: 46vh; display: block; background: #000; object-fit: contain; }
.mirror { transform: scaleX(-1); }
.meter { height: 10px; background: #222; }
.meter-bar { height: 100%; width: 0; background: #3ddc84; transition: width 0.1s linear; }
.meter-label { padding: 4px 10px; font-size: 0.8rem; color: #ddd; background: #111; }

.video-wrap video { width: 100%; aspect-ratio: 16 / 10; max-height: 62vh; display: block; background: #000; object-fit: contain; }
.live-badge, .rec-badge {
  position: absolute; top: 10px; left: 10px; display: flex; align-items: center; gap: 8px;
  background: rgba(198, 40, 40, 0.92); color: #fff; font-weight: 800; padding: 6px 12px; border-radius: 999px; font-size: 0.95rem;
}
.live-badge .en, .live-badge .my, .rec-badge .en, .rec-badge .my { display: inline; font-size: 1em; }
.rec-badge { left: auto; right: 10px; background: #000; border: 2px solid #ff4d4d; }
.novideo { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; text-align: center; padding: 16px; }
.tap-audio { position: absolute; left: 12px; right: 12px; bottom: 12px; margin: 0; min-height: 60px; }

.kv { display: grid; grid-template-columns: 1fr; gap: 2px; margin: 0; }
.kv-row { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); align-items: baseline; }
.kv-row:last-child { border-bottom: 0; }
.kv-row dt { color: var(--muted); font-size: 0.95rem; margin: 0; }
.kv-row dd { margin: 0; font-weight: 700; text-align: right; word-break: break-word; font-variant-numeric: tabular-nums; }
.kv-row dd.warn { color: var(--danger); }

.pair { text-align: center; }
.code-big { font-size: 2.8rem; font-weight: 800; letter-spacing: 0.12em; font-variant-numeric: tabular-nums; margin: 4px 0; }
.qr { background: #fff; padding: 8px; border-radius: 12px; display: inline-block; }
.qr img { width: 210px; height: 210px; display: block; }

.list { list-style: none; padding: 0; margin: 0; }
.list li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list .who { font-weight: 700; word-break: break-word; }
.list .state { font-size: 0.85rem; color: var(--muted); }
.badge { display: inline-block; font-size: 0.72rem; font-weight: 700; padding: 1px 7px; border-radius: 999px;
  background: var(--accent, #2f6fed); color: #fff; vertical-align: middle; }
.list .btn { width: auto; margin: 0; min-height: 48px; font-size: 0.95rem; }

details.card summary { cursor: pointer; font-weight: 700; min-height: 44px; display: flex; align-items: center; }
details.card[open] summary { margin-bottom: 8px; }
.log { list-style: none; padding: 0; margin: 0; max-height: 280px; overflow: auto; font-size: 0.9rem; }
.log li { display: flex; gap: 10px; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.log time { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }

.overlay {
  position: fixed; inset: 0; z-index: 100; background: rgba(0, 0, 0, 0.7);
  display: flex; align-items: center; justify-content: center; padding: 16px; overflow: auto;
}
.overlay.rec { z-index: 110; background: rgba(60, 0, 0, 0.88); }
.dialog { background: var(--card); color: var(--text); width: 100%; max-width: 480px; border-radius: 20px; padding: 20px; border: 3px solid var(--line); }
.overlay.rec .dialog { border-color: var(--danger); }
.dialog h2 { margin: 0 0 8px; }
.dialog .big { font-size: 1.25rem; font-weight: 700; }

.spinner { width: 48px; height: 48px; border: 6px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; margin: 12px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }
.center { text-align: center; }
.consent-big { font-size: 1.35rem; font-weight: 800; line-height: 1.4; }
.consent-line { font-weight: 700; padding: 12px; border-left: 6px solid var(--danger); background: var(--bg); border-radius: 8px; }
a.link { color: var(--accent); }
footer { text-align: center; padding: 8px 16px 24px; }
