:root {
  --bg: #f4f5f7; --surface: #ffffff; --surface-2: #eceef1; --line: #d8dce2;
  --text: #15191e; --muted: #5b6573; --accent: #0b6bcb; --accent-text: #ffffff;
  --ok: #1f7a3f; --warn: #9a5b00; --bad: #b3261e; --cell-empty: #dde1e6; --cell-full: #0b6bcb;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101418; --surface: #181d23; --surface-2: #222933; --line: #2e3643;
    --text: #e8ecf1; --muted: #9aa5b4; --accent: #4ea1ff; --accent-text: #06121f;
    --ok: #5fd08a; --warn: #f0b35a; --bad: #ff7a70; --cell-empty: #2a323d; --cell-full: #4ea1ff;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #101418; --surface: #181d23; --surface-2: #222933; --line: #2e3643;
  --text: #e8ecf1; --muted: #9aa5b4; --accent: #4ea1ff; --accent-text: #06121f;
  --ok: #5fd08a; --warn: #f0b35a; --bad: #ff7a70; --cell-empty: #2a323d; --cell-full: #4ea1ff;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh; min-height: 100dvh;
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
[hidden] { display: none !important; }
button, select, input { font: inherit; font-size: 16px; color: inherit; }

.bar {
  position: sticky; top: 0; z-index: 10; background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: env(safe-area-inset-top) 16px 0;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 56px;
}
.bar > * { margin: 10px 0; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; letter-spacing: .01em; }
.brand img { border-radius: 7px; }
.seg { display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.seg button {
  border: 0; background: transparent; padding: 6px 16px; border-radius: 8px; cursor: pointer;
  color: var(--muted); font-weight: 600;
}
.seg button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgb(0 0 0 / .15); }

main { max-width: 640px; margin: 0 auto; padding: 16px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }

.drop {
  display: flex; flex-direction: column; gap: 4px; align-items: center; text-align: center;
  padding: 28px 16px; border: 2px dashed var(--line); border-radius: var(--radius);
  background: var(--surface); cursor: pointer;
}
.drop.over { border-color: var(--accent); }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop-title { font-weight: 650; font-size: 18px; word-break: break-all; }
.drop-sub { color: var(--muted); font-size: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { display: flex; justify-content: space-between; font-weight: 600; }
.field output { color: var(--muted); font-weight: 500; font-variant-numeric: tabular-nums; }
.field input[type=range] { width: 100%; accent-color: var(--accent); }
select {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface-2);
}
.est { margin: 0; color: var(--muted); font-size: 14px; }
.est.warn { color: var(--warn); }
.hint { margin: 0; color: var(--muted); font-size: 14px; text-align: center; }

button {
  border: 1px solid var(--line); background: var(--surface-2); border-radius: 10px;
  padding: 10px 16px; cursor: pointer; font-weight: 600;
}
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); padding: 13px 18px; }
button.danger { color: var(--bad); }

/* Player: the QR takes all the room there is; white quiet zone always, even in dark mode. */
.play { display: flex; flex-direction: column; gap: 12px; }
.qr-wrap {
  background: #fff; border-radius: 10px; display: flex; align-items: center; justify-content: center;
  width: 100%; aspect-ratio: 1 / 1; max-height: calc(100dvh - 190px); margin: 0 auto;
}
.qr-wrap canvas { width: 100%; height: 100%; image-rendering: pixelated; cursor: pointer; }
.qr-wrap.paused { outline: 3px solid var(--warn); outline-offset: 3px; }
.play-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.play-stats { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.play-btns { display: flex; gap: 8px; }
.play-btns button { min-width: 44px; }

/* Receiver */
.cam {
  position: relative; background: #000; border-radius: var(--radius); overflow: hidden;
  aspect-ratio: 4 / 3; display: flex; align-items: center; justify-content: center;
}
.cam video { width: 100%; height: 100%; object-fit: cover; }
.guide {
  position: absolute; width: 72%; aspect-ratio: 1 / 1; max-height: 90%;
  border: 2px solid rgb(255 255 255 / .7); border-radius: 12px; pointer-events: none;
  box-shadow: 0 0 0 100vmax rgb(0 0 0 / .25);
}
.cam.hit .guide { border-color: #5fd08a; }
.cam-start { position: absolute; }
.cam.live .cam-start { display: none; }
.cam-tools { display: flex; gap: 8px; }
.cam-tools select { flex: 1; min-width: 0; }

.recv-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.recv-name { font-weight: 650; word-break: break-all; }
.badge {
  flex: none; font-size: 13px; font-weight: 650; padding: 3px 9px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted);
}
.badge.ok { color: var(--ok); } .badge.bad { color: var(--bad); } .badge.live { color: var(--accent); }
.progress { height: 8px; background: var(--cell-empty); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent); transition: width .15s; }
.recv-stats { color: var(--muted); font-size: 14px; margin: 8px 0; font-variant-numeric: tabular-nums; }
.grid { width: 100%; height: 0; display: block; }
.done { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.error { color: var(--bad); margin: 10px 0 0; font-weight: 600; }

.foot { margin-top: 28px; color: var(--muted); font-size: 14px; }
.foot summary { cursor: pointer; font-weight: 600; }
.foot a { color: var(--accent); }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; word-break: break-all; }

/* While sending, drop the chrome: the code wants the space. */
body.sending .foot { display: none; }
@media (max-width: 420px) {
  .seg button { padding: 6px 12px; }
  .brand span { display: none; }
}
