:root {
  --bg: #0b0f14;
  --panel: #131a22;
  --line: #222c38;
  --text: #e8eef5;
  --muted: #8a97a8;
  --accent: #2fd17d;
  --warn: #f5b041;
  --danger: #ff5a5f;
  --btn: #e5484d;
  --btn-dark: #a8262b;
  --radius: 18px;
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

[hidden] { display: none !important; }

.bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 10px;
}
.bar h1 { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }

.pill {
  font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line); color: var(--muted);
}
.pill[data-state="live"] { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.pill[data-state="stale"] { color: var(--warn); }
.pill[data-state="down"] { color: var(--danger); }

main { max-width: 760px; margin: 0 auto; padding: 0 12px 24px; }

.cams { display: grid; gap: 10px; }
@media (min-width: 900px) { main { max-width: 1200px; } .cams { grid-template-columns: 1fr 1fr; } }

.cam {
  position: relative; overflow: hidden; border-radius: var(--radius);
  background: var(--panel) linear-gradient(110deg, #131a22 30%, #1a2330 50%, #131a22 70%);
  background-size: 200% 100%;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--line);
}
.cam:not(.ready) { animation: shimmer 1.4s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

.cam img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity .25s; }
.cam.ready img { opacity: 1; }

.cam figcaption {
  position: absolute; left: 10px; bottom: 10px;
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600;
  padding: 4px 9px; border-radius: 999px;
  background: rgba(0, 0, 0, .55); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.cam .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.cam[data-state="live"] .dot { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.cam[data-state="stale"] .dot { background: var(--warn); }
.cam[data-state="down"] .dot { background: var(--danger); }
.cam .age { color: var(--muted); font-weight: 500; }

.control { display: flex; flex-direction: column; align-items: center; padding-top: 22px; gap: 14px; }

.gate-btn {
  --size: min(46vw, 200px);
  position: relative; width: var(--size); height: var(--size);
  border: 0; border-radius: 50%; background: none; cursor: pointer;
  -webkit-tap-highlight-color: transparent; touch-action: none;
}
.gate-btn .ring { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.gate-btn .ring circle { fill: none; stroke-width: 6; }
.gate-btn .track { stroke: var(--line); }
.gate-btn .progress {
  stroke: var(--accent); stroke-linecap: round;
  stroke-dasharray: 339.3; stroke-dashoffset: 339.3;
}
.gate-btn:disabled .progress { transition: stroke-dashoffset .5s ease-out; stroke-dashoffset: 0; }

.gate-btn .core {
  position: absolute; inset: 12%; border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  background: radial-gradient(circle at 35% 30%, #ff7b80, var(--btn) 45%, var(--btn-dark));
  box-shadow: 0 10px 30px rgba(229, 72, 77, .35), inset 0 -6px 14px rgba(0, 0, 0, .25), inset 0 4px 10px rgba(255, 255, 255, .25);
  transition: transform .15s ease, box-shadow .15s ease;
}
.gate-btn:active .core { transform: scale(.94); box-shadow: 0 4px 14px rgba(229, 72, 77, .3), inset 0 -3px 8px rgba(0, 0, 0, .3); }
.gate-btn.sent .core { background: radial-gradient(circle at 35% 30%, #6ff0a8, var(--accent) 45%, #17924f); }
.gate-btn:disabled { opacity: .55; }

.gate-btn .icon { width: 34%; height: 34%; stroke: #fff; stroke-width: 1.8; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.gate-btn .hint { font-size: 13px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: rgba(255, 255, 255, .9); }

.status { min-height: 22px; font-size: 15px; color: var(--muted); text-align: center; }
.status.ok { color: var(--accent); }
.status.err { color: var(--danger); }

.login {
  max-width: 360px; margin: 12vh auto 0; padding: 28px 22px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 22px;
  display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center;
  -webkit-user-select: auto; user-select: auto;
}
.login .lock { width: 52px; height: 52px; border-radius: 50%; background: #1d2834; display: grid; place-items: center; }
.login .lock svg { width: 26px; height: 26px; stroke: var(--text); stroke-width: 1.8; fill: none; stroke-linecap: round; }
.login h2 { font-size: 22px; }
.login p { color: var(--muted); font-size: 15px; }
.login input {
  width: 100%; font-size: 20px; padding: 13px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: #0e141b; color: var(--text); outline: none;
  -webkit-user-select: text; user-select: text;
}
.login input:focus { border-color: var(--accent); }
.primary {
  width: 100%; font-size: 17px; font-weight: 650; padding: 13px; border: 0; border-radius: 12px;
  background: var(--accent); color: #062312; cursor: pointer;
}
.primary:disabled { opacity: .6; }
.error { color: var(--danger); min-height: 20px; font-size: 14px; }

@media (prefers-reduced-motion: reduce) {
  .cam:not(.ready) { animation: none; }
  .cam img, .gate-btn .core { transition: none; }
}
