* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #111; color: #eee;
  font: 16px -apple-system, system-ui, "Apple SD Gothic Neo", sans-serif; }
.hidden { display: none !important; }
.screen { min-height: 100%; }

#setup { max-width: 420px; margin: 0 auto; padding: 24px 16px calc(24px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; }
#setup h1 { text-align: center; margin: 16px 0; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: #bbb; }
label.inline { flex-direction: row; align-items: center; gap: 8px; color: #eee; }
input, select { font-size: 16px; padding: 10px; border-radius: 8px; border: 1px solid #444; background: #222; color: #eee; }
input[type=range] { padding: 0; }
.hint { font-size: 13px; color: #999; margin: 0; }
.msg { color: #f88; min-height: 1.2em; }

button { font-size: 15px; padding: 10px 12px; border-radius: 10px; border: 0; background: #333; color: #eee; cursor: pointer; }
button:disabled { opacity: .4; }
button.big { padding: 16px; font-size: 17px; width: 100%; }
button.primary { background: #2a6df4; }
button.danger { background: #a33; }
button.talk.on { background: #e53; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .7; } }

/* 카메라 모드 */
#camera { position: fixed; inset: 0; }
#preview { width: 100%; height: 100%; object-fit: cover; background: #000; }
.bar { position: absolute; left: 0; right: 0; display: flex; gap: 8px; padding: 10px; flex-wrap: wrap; }
.bar.top { top: env(safe-area-inset-top); }
.bar.bottom { bottom: env(safe-area-inset-bottom); justify-content: center; }
.pill { background: rgba(0,0,0,.6); padding: 4px 10px; border-radius: 99px; font-size: 13px; }
.pill.ok { background: rgba(20,140,60,.8); }
.pill.bad { background: rgba(170,40,40,.8); }
#dim { position: fixed; inset: 0; background: #000; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 40px; z-index: 10; }
#dim span { color: #333; font-size: 12px; }

/* 보기 모드: 2×2 분할 */
#viewer { display: flex; flex-direction: column; }
#grid { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; background: #000; padding-top: env(safe-area-inset-top); }
#grid.single { grid-template-columns: 1fr; }
#grid.expanded .tile:not(.sel) { display: none; }
#empty { grid-column: 1 / -1; aspect-ratio: 16 / 9; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; color: #aaa; padding: 16px; }
#empty small { color: #777; margin-top: 6px; }
.tile { position: relative; aspect-ratio: 16 / 9; background: #000; overflow: hidden; cursor: pointer; outline: 2px solid transparent; outline-offset: -2px; }
.tile.sel { outline-color: #2a6df4; }
.tile.alerting { outline: 3px solid #e53; outline-offset: -3px; animation: pulse 1s infinite; }
.tile video { width: 100%; height: 100%; object-fit: contain; display: block; }
.tname, .tinfo { position: absolute; background: rgba(0,0,0,.6); padding: 2px 8px; border-radius: 99px; font-size: 12px; }
.tname { left: 6px; top: 6px; font-weight: 600; }
.tinfo { right: 6px; bottom: 6px; }
.ttalk { position: absolute; left: 6px; bottom: 6px; background: #e53; padding: 2px 8px; border-radius: 99px; font-size: 12px; }
#camTalk { background: #e53; }
.row.status { flex-wrap: wrap; }
a { color: #6aa0ff; }
.toff { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.7); font-size: 13px; }
#alertBanner { background: #e53; padding: 8px 12px; font-weight: 600; }
.controls { padding: 12px 16px calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px; }
.controls .hint { margin: -4px 0 0; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; min-width: 0; }
.row.status > * { flex: 0 1 auto; }
details { background: #1c1c1c; border-radius: 10px; padding: 10px 12px; }
details > * + * { margin-top: 10px; }
summary { cursor: pointer; }
#log { list-style: none; padding: 0; margin: 8px 0 0; font-size: 13px; max-height: 200px; overflow: auto; }
#log li { padding: 4px 0; border-bottom: 1px solid #2a2a2a; }
