:root {
  --bg: #f7f5f0;
  --ink: #231f20;
  --muted: #6b6560;
  --line: #d9d4ca;
  --card: #fffdf9;
  --accent: #b8341c;
  --ok: #2f6b3a;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: Pretendard, "Wanted Sans Variable", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-tap-highlight-color: transparent;
}
.top {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; border-bottom: 1px solid var(--line);
}
.ci { height: 28px; width: auto; flex: none; }
h1 { font-size: 18px; margin: 0; flex: 1; font-weight: 700; }
h2 { font-size: 16px; margin: 0; }
.status {
  flex: none; padding: 4px 12px; border-radius: 999px; font-size: 14px; font-weight: 600;
  background: #e9e5dc; color: var(--muted);
}
.status[data-state="watch"] { background: #dcebdd; color: var(--ok); }
.status[data-state="learn"] { background: #efe6c9; color: #6d5a12; }
.status[data-state="alarm"] { background: var(--accent); color: #fff; }

main { max-width: 1100px; margin: 0 auto; padding: 12px 16px 32px; display: grid; gap: 20px; }
@media (min-width: 760px) {
  main { grid-template-columns: minmax(0, 1.5fr) minmax(280px, 1fr); align-items: start; }
  .log { grid-column: 1 / -1; }
}

.stage {
  position: relative; background: #111; border-radius: 10px; overflow: hidden;
  aspect-ratio: 16 / 9; max-height: 62vh; margin: 0 auto;
}
.stage video, .stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.stage canvas { touch-action: none; }
.stage.editing { outline: 3px solid var(--accent); outline-offset: 2px; }
.stage-msg {
  position: absolute; inset: 0; margin: 0; display: grid; place-items: center; text-align: center;
  color: #fff; padding: 16px; background: rgba(0, 0, 0, .55);
}
.stage-msg[hidden] { display: none; }

.meter { position: relative; height: 12px; margin-top: 10px; background: #e9e5dc; border-radius: 6px; overflow: hidden; }
.meter-fill { height: 100%; width: 0; background: var(--ok); }
.meter-fill.over { background: var(--accent); }
.meter-mark { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--ink); left: 0; }
.meter-text { margin: 4px 0 0; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

.controls { display: grid; gap: 10px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row.tight { display: flex; gap: 8px; }
.btn {
  min-height: 48px; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer;
}
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { min-height: 64px; font-size: 20px; background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary.running { background: var(--card); color: var(--ink); border-color: var(--ink); }
.btn.small { min-height: 40px; padding: 6px 12px; font-size: 14px; }
.btn.on { border-color: var(--ink); background: #ece7dc; }
.hint { margin: 0; font-size: 14px; color: var(--muted); }

.settings { border: 1px solid var(--line); border-radius: 10px; padding: 4px 14px; background: var(--card); }
.settings summary { min-height: 44px; display: flex; align-items: center; font-weight: 600; cursor: pointer; }
.settings[open] { padding-bottom: 14px; }
.field { display: grid; gap: 4px; margin-bottom: 14px; }
.field small { color: var(--muted); font-weight: 400; }
.field input[type="range"] { width: 100%; height: 36px; accent-color: var(--ink); }
.field select { min-height: 44px; font: inherit; border-radius: 8px; border: 1px solid var(--line); background: #fff; padding: 0 8px; }

.log-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.count { color: var(--muted); font-weight: 400; font-size: 14px; margin-left: 4px; }
.log-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.log-list button {
  display: block; width: 100%; padding: 0; border: 1px solid var(--line); border-radius: 8px;
  background: var(--card); overflow: hidden; cursor: pointer; font: inherit; color: inherit; text-align: left;
}
.log-list img { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: #111; }
.log-list span { display: block; padding: 6px 8px; font-size: 13px; font-variant-numeric: tabular-nums; }

.alarm {
  position: fixed; inset: 0; z-index: 10; background: #b8341c;
  display: grid; place-items: center; padding: 16px;
}
.alarm[hidden] { display: none; }
.alarm-box { width: min(560px, 100%); display: grid; gap: 12px; color: #fff; text-align: center; }
.alarm-box h2 { font-size: 28px; }
.alarm-time { margin: 0; font-size: 18px; font-variant-numeric: tabular-nums; }
.alarm-box img { width: 100%; max-height: 40vh; object-fit: contain; border-radius: 8px; background: #111; }
.btn.ack { min-height: 88px; font-size: 24px; background: #fff; color: var(--accent); border-color: #fff; }

.viewer { border: 0; border-radius: 12px; padding: 14px; width: min(900px, 94vw); background: var(--card); color: var(--ink); }
.viewer::backdrop { background: rgba(0, 0, 0, .6); }
.viewer img { width: 100%; max-height: 70vh; object-fit: contain; background: #111; border-radius: 8px; }
.viewer p { margin: 8px 0 12px; font-variant-numeric: tabular-nums; }
.viewer .btn { width: 100%; }
