:root {
  --bg: #15201C; --surface: #1F2D28; --surface-2: #2A3A34;
  --text: #EFE9DD; --text-dim: #A9B3AC;
  --accent: #F0A45D; --on-accent: #1A1206;
  --live: #6FD08C; --stale: #FF6B5E; --warn-bg: rgba(255, 107, 94, .14);
  --black: #000; --cam-dim: #3A3F3C;
  --font-head: "Bricolage Grotesque", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html { color-scheme: dark; }
body {
  margin: 0; min-height: 100dvh; background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overflow-x: hidden;
}
body.cam-run { background: var(--black); }
h1, h2 { font-family: var(--font-head); font-weight: 700; margin: 0; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.125rem; font-weight: 600; }
p { margin: 0 0 8px; }
.dim { color: var(--text-dim); }
.num { font-variant-numeric: tabular-nums; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
svg.i { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.bar { display: flex; align-items: center; justify-content: space-between; min-height: 56px; padding: 4px 12px; }
.btn, .icon-btn {
  min-height: 48px; border: 0; border-radius: 16px; font: inherit; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; color: var(--text); background: var(--surface-2);
}
.btn { padding: 0 20px; width: 100%; }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.icon-btn { width: 48px; padding: 0; background: transparent; }

.pad { padding: 0 12px 24px; display: grid; gap: 12px; max-width: 560px; margin: 0 auto; }
.card { background: var(--surface); border-radius: 20px; padding: 16px; display: grid; gap: 12px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; }

/* viewer */
.stage { position: relative; aspect-ratio: 4 / 3; border-radius: 20px; overflow: hidden; background: var(--surface); }
.stage img { width: 100%; height: 100%; object-fit: cover; display: block; }
.stage.stale img { filter: grayscale(1) blur(6px) brightness(.6); }
.badge {
  position: absolute; left: 12px; top: 12px; display: flex; align-items: center; gap: 8px;
  background: rgba(0, 0, 0, .6); border-radius: 20px; padding: 4px 12px; font-size: .875rem; font-weight: 600;
}
.badge i { width: 8px; height: 8px; border-radius: 50%; background: var(--live); }
.badge.live i { animation: breathe 2s ease-in-out infinite; }
.badge:not(.live) i { background: var(--stale); }
@keyframes breathe { 50% { opacity: .45; } }
.overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 4px; padding: 16px; background: var(--warn-bg); color: var(--stale);
}
.overlay strong { font: 700 1.5rem var(--font-head); }
.overlay span { color: var(--text); }
.meter { position: relative; height: 8px; border-radius: 4px; background: var(--surface-2); }
.meter i { position: absolute; inset: 0 auto 0 0; background: var(--live); border-radius: 4px; transition: width .3s; }
.meter b { position: absolute; top: -4px; width: 2px; height: 16px; background: var(--accent); }
input[type=checkbox][role=switch] { appearance: none; width: 52px; height: 32px; border-radius: 16px; background: var(--surface-2); position: relative; margin: 0; cursor: pointer; flex: none; }
input[type=checkbox][role=switch]::after { content: ""; position: absolute; top: 4px; left: 4px; width: 24px; height: 24px; border-radius: 50%; background: var(--text); transition: transform .15s; }
input[type=checkbox][role=switch]:checked { background: var(--accent); }
input[type=checkbox][role=switch]:checked::after { transform: translateX(20px); background: var(--on-accent); }
input[type=range] { width: 100%; height: 48px; accent-color: var(--accent); margin: 0; }
.err { color: var(--stale); }

/* history */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.list button { width: 100%; min-height: 64px; display: flex; gap: 12px; align-items: center; text-align: left; padding: 8px; border: 0; border-radius: 16px; background: var(--surface); color: inherit; font: inherit; cursor: pointer; }
.list img { width: 72px; height: 54px; border-radius: 8px; object-fit: cover; background: var(--surface-2); }
dialog { border: 0; padding: 0; background: var(--black); color: var(--text); width: min(96vw, 720px); border-radius: 20px; overflow: hidden; }
dialog::backdrop { background: rgba(0, 0, 0, .8); }
dialog img { width: 100%; display: block; }
dialog .bar { background: var(--surface); }

/* camera */
.qr { background: #fff; padding: 12px; border-radius: 16px; width: 224px; margin: 0 auto; }
.qr svg { width: 100%; height: auto; display: block; }
.run { min-height: 100dvh; background: var(--black); color: var(--cam-dim); display: flex; flex-direction: column; justify-content: space-between; padding: 16px; }
.run .ctl { display: grid; gap: 12px; }
.run .ctl .btn { background: var(--surface); }
video.hidden { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

@media (prefers-reduced-motion: reduce) {
  .badge.live i { animation: none; }
  .meter i, input[type=checkbox][role=switch]::after { transition: none; }
}
