:root {
  --bg: #F4F3EE;
  --card: #FFFFFF;
  --ink: #1B1B19;
  --muted: #6B6A64;
  --line: #DDDBD2;
  --amber: #EF9F27;
  --amber-ink: #412402;
  --green: #3B6D11;
  --green-bg: #EAF3DE;
  --red: #A32D2D;
  --red-bg: #FCEBEB;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
}
h2 { font-size: 16px; font-weight: 600; margin: 0 0 6px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: #111110; color: #F4F3EE;
  padding-top: calc(10px + env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 20px; letter-spacing: -0.01em; }
.brand b { color: var(--amber); font-weight: 700; }
.brand.big { font-size: 30px; justify-content: center; margin-bottom: 8px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.topbar select {
  background: #2A2A27; color: #F4F3EE; border: 1px solid #3A3A36;
  border-radius: 8px; padding: 6px 8px; max-width: 180px; font-size: 13px;
}

.pill { font-size: 12px; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.pill-off { background: #2A2A27; color: #B4B2A9; }
.pill-on { background: var(--green-bg); color: var(--green); }
.pill-alert { background: var(--red-bg); color: var(--red); }
.pill-sleep { background: #FAEEDA; color: #633806; }

.layout {
  display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
  gap: 14px; padding: 14px; max-width: 1200px; margin: 0 auto;
}
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; padding: 10px; }
}

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px; display: flex; flex-direction: column; gap: 10px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.camera-name {
  border: none; background: transparent; font: inherit; font-weight: 600; font-size: 16px;
  color: var(--ink); padding: 2px 4px; border-radius: 6px; min-width: 0; flex: 1;
}
.camera-name:focus { outline: 2px solid var(--amber); }

.feed { position: relative; background: #1B1B19; border-radius: 10px; overflow: hidden; aspect-ratio: 4 / 3; }
.feed video, .feed canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.feed canvas { pointer-events: none; }
.feed-message {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  text-align: center; padding: 20px; color: #D3D1C7; font-size: 14px; background: rgba(27,27,25,0.85);
}
.feed-message[hidden] { display: none; }
.speaking-bar {
  position: absolute; left: 10px; right: 10px; bottom: 10px;
  background: rgba(68,68,65,0.95); color: #F1EFE8; font-size: 13px;
  padding: 8px 12px; border-radius: 8px; display: flex; align-items: center; gap: 8px;
}
.speaking-bar[hidden] { display: none; }
.speaking-bar .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); animation: pulse 0.8s infinite alternate; }
@keyframes pulse { from { opacity: 0.3; } to { opacity: 1; } }

.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
@media (max-width: 480px) { .actions { grid-template-columns: repeat(2, 1fr); } }

.btn {
  font: inherit; font-size: 14px; padding: 10px 12px; border-radius: var(--radius);
  border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer;
}
.btn:hover { background: #F4F3EE; }
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--amber); border-color: var(--amber); color: var(--amber-ink); font-weight: 600; }
.btn-primary:hover { background: #F5AE45; }
.btn-primary.armed { background: var(--red); border-color: var(--red); color: #fff; }
.btn-small { padding: 4px 10px; font-size: 13px; }
.btn-wide { width: 100%; padding: 12px; font-size: 16px; }

.talk-box { display: flex; gap: 8px; }
.talk-box[hidden] { display: none; }
.talk-box input { flex: 1; }

input[type="text"], input:not([type]), input[type="time"], input[type="number"], select, textarea {
  font: inherit; font-size: 14px; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; color: var(--ink); width: 100%;
}
textarea { resize: vertical; }
input[type="range"] { width: 100%; accent-color: var(--amber); }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); flex: 1; }
.row { display: flex; gap: 10px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  display: flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--line); font-size: 14px; cursor: pointer; user-select: none;
}
.chip:has(input:checked) { background: #FAEEDA; border-color: var(--amber); color: var(--amber-ink); }
.chip input { margin: 0; accent-color: var(--amber); }

.events { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.events li {
  display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 13px;
}
.events img { width: 64px; height: 48px; object-fit: cover; border-radius: 6px; background: #1B1B19; flex: none; }
.events .when { color: var(--muted); font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; flex: none; }
.events .what { flex: 1; min-width: 0; }
.events .what small { display: block; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.setup {
  position: fixed; inset: 0; background: rgba(17,17,16,0.92); display: flex;
  align-items: center; justify-content: center; padding: 20px; z-index: 10;
}
.setup[hidden] { display: none; }
.setup-card { background: #fff; border-radius: 16px; padding: 24px; max-width: 420px; width: 100%; }
.setup-card p { margin: 0 0 12px; }
.steps { margin: 0 0 18px; padding-left: 22px; color: var(--ink); }
.steps li { margin: 4px 0; }
