:root {
  --bg: #f6f5f2;
  --ink: #16181d;
  --muted: #5d636e;
  --line: #dcdad4;
  --field: #ffffff;
  --accent: #1f6feb;
  --accent-ink: #ffffff;
  --live: #e5484d;
  --relay: #f5a524;
  --error: #c8312f;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0f12;
    --ink: #eceef2;
    --muted: #9198a4;
    --line: #262a31;
    --field: #16191e;
    --accent: #4c8dff;
    --accent-ink: #ffffff;
    --error: #ff6b66;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }

/* ---------------------------------------------------------------- home */
.home {
  max-width: 440px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom));
  min-height: 100%;
  display: flex;
  flex-direction: column;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; color: var(--muted); }
.brand img { border-radius: 7px; }

h1 { font-size: 34px; line-height: 1.1; letter-spacing: -0.02em; margin: 44px 0 8px; font-weight: 700; }
.connect { display: flex; flex-direction: column; }
.connect h2 { margin-top: 40px; }
.lede { margin: 0 0 28px; color: var(--muted); }
label { font-size: 13px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
input#id, input#pin {
  width: 100%;
  font-size: 26px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.06em;
  padding: 10px 0 10px;
  margin-bottom: 22px;
  background: transparent;
  border: 0;
  border-bottom: 2px solid var(--line);
  border-radius: 0;
  outline: none;
  transition: border-color .15s;
}
input#id:focus, input#pin:focus { border-bottom-color: var(--accent); }
input::placeholder { color: var(--muted); opacity: .45; letter-spacing: 0.02em; }
.check {
  display: flex; align-items: center; gap: 10px;
  text-transform: none; letter-spacing: 0; font-size: 15px; font-weight: 400; color: var(--ink);
  margin: 0 0 18px; min-height: 44px;
}
.check input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); }
.error { color: var(--error); margin: 0 0 14px; font-weight: 500; }
#watch {
  height: 54px;
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  font-size: 18px;
  cursor: pointer;
}
#watch:active { filter: brightness(.92); }

.saved { margin-top: 24px; }
h2 { font-size: 13px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); margin: 0 0 4px; }
.saved ul { list-style: none; margin: 0; padding: 0; }
.saved li { display: flex; align-items: center; border-bottom: 1px solid var(--line); }
.saved li:last-child { border-bottom: 0; }
.cam {
  flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 14px 0; cursor: pointer;
  display: flex; flex-direction: column;
}
.cam .n { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cam .i { color: var(--muted); font-size: 15px; font-variant-numeric: tabular-nums; }
.forget { background: none; border: 0; color: var(--muted); font-size: 15px; padding: 14px 0 14px 16px; cursor: pointer; }

.foot { margin-top: auto; padding-top: 40px; color: var(--muted); font-size: 13px; }

/* ---------------------------------------------------------------- watching */
.stage { position: fixed; inset: 0; background: #000; color: #fff; overflow: hidden; touch-action: none; }
.frame { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
#pic { max-width: 100%; max-height: 100%; object-fit: contain; transform-origin: 0 0; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.top {
  position: absolute; left: 0; right: 0; top: 0;
  display: flex; align-items: center; gap: 4px;
  padding: max(6px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) 18px max(8px, env(safe-area-inset-left));
  background: linear-gradient(rgba(0,0,0,.55), rgba(0,0,0,0));
  transition: opacity .3s;
}
.stage.calm .top, .stage.calm .relay { opacity: 0; }
.back { width: 44px; height: 44px; border: 0; background: none; color: #fff; font-size: 34px; line-height: 1; cursor: pointer; }
.title { display: flex; flex-direction: column; min-width: 0; }
#cam { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.camid { font-size: 13px; opacity: .7; font-variant-numeric: tabular-nums; }
.status {
  position: absolute; left: 16px; right: 16px; top: 50%; transform: translateY(-50%);
  margin: 0; text-align: center; font-size: 17px; color: rgba(255,255,255,.85);
}
.relay {
  position: absolute; margin: 0;
  left: max(16px, env(safe-area-inset-left)); bottom: max(14px, env(safe-area-inset-bottom));
  color: var(--relay); font-size: 14px; font-weight: 600;
  transition: opacity .3s;
}
