:root {
  --bg: #0b0e13;
  --panel: #131822;
  --panel-2: #1a2130;
  --line: #242d3d;
  --text: #e6edf7;
  --muted: #8b98ad;
  --accent: #4ade80;
  --accent-dim: #1c7a45;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body { min-height: 100dvh; }
.hidden { display: none !important; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.err { color: var(--bad); min-height: 1.4em; margin: 8px 0 0; font-size: 13px; }

/* ---------------------------------------------------------------- login --- */
.gate {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 24px;
}
.gate form {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 32px 28px;
  width: min(360px, 100%);
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}
.gate h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: 0.02em; }
.gate h1 span { color: var(--accent); }
.gate p.muted { margin: 0 0 20px; font-size: 13px; }
.gate input {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  margin-bottom: 12px;
}
.gate input:focus { outline: none; border-color: var(--accent-dim); }
.gate button {
  width: 100%;
  padding: 12px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: #06240f;
  font-weight: 650;
  font-size: 15px;
  cursor: pointer;
}
.gate button:hover { filter: brightness(1.08); }

/* ---------------------------------------------------------------- shell --- */
#app { max-width: 1200px; margin: 0 auto; padding: 16px 16px 64px; }

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 8px 0 16px;
}
header h1 { font-size: 19px; margin: 0; letter-spacing: 0.02em; font-weight: 700; }
header h1 span { color: var(--accent); }

.statusline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
  font-family: var(--mono);
  white-space: nowrap;
}
.pill::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}
.pill.ok { color: var(--accent); border-color: #1f5c3c; }
.pill.ok::before { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.pill.warn { color: var(--warn); border-color: #5c4a1f; }
.pill.warn::before { background: var(--warn); }
.pill.bad { color: var(--bad); border-color: #5c2020; }
.pill.bad::before { background: var(--bad); }

/* ---------------------------------------------------------------- tabs ---- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; }
.tab {
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 10px 16px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 550;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------------------------------------------------------------- viewer -- */
.viewer {
  position: relative;
  background: #05070a;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 4 / 3;
  /* Never let one 4:3 frame own the whole viewport: the stats row and the
     sleep toggle have to stay visible without scrolling. */
  max-height: min(62vh, 620px);
  margin: 0 auto;
  width: 100%;
  display: grid;
  place-items: center;
}
.viewer img, .viewer video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.viewer img.stale { opacity: 0.45; filter: saturate(0.4); }
.viewer .empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 13px;
  pointer-events: none;
}
.viewer .overlay {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  font-family: var(--mono);
  font-size: 11.5px;
  color: #cfe6d8;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
}
.viewer.playback { margin-top: 14px; background: #05070a; max-height: min(56vh, 560px); }

/* ---------------------------------------------------------------- stats --- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin: 14px 0;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.stat label { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 4px; }
.stat b { font-family: var(--mono); font-size: 15px; font-weight: 600; }

/* ---------------------------------------------------------------- buttons - */
button { font-family: inherit; }
button.primary {
  background: var(--accent);
  color: #06240f;
  border: 0;
  border-radius: var(--radius);
  padding: 10px 18px;
  font-weight: 650;
  cursor: pointer;
  font-size: 14px;
}
button.primary:hover { filter: brightness(1.08); }
button.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: var(--radius);
  padding: 8px 14px;
  cursor: pointer;
  font-size: 13px;
}
button.ghost:hover { color: var(--text); border-color: var(--accent-dim); }
button.wide { width: 100%; }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; margin-top: 12px; }
/* Sticky here caused the save bar to float over the resolution dropdown
   mid-form. A short form does not need it; a separator reads better. */
.row.sticky {
  position: static;
  background: transparent;
  padding: 4px 2px 20px;
  border-top: 1px solid var(--line);
  margin-top: 4px;
  padding-top: 16px;
}

/* ---------------------------------------------------------------- timeline */
.timeline-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.timeline-bar input[type="datetime-local"] {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-family: var(--mono);
  font-size: 13px;
}

.scrub-wrap { margin-bottom: 14px; }
.scrub {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: crosshair;
  touch-action: none;
}
.scrub canvas { display: block; width: 100%; height: 64px; }
.scrub .cursor {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
  pointer-events: none;
  transform: translateX(-1px);
  display: none;
}
.filmstrip {
  display: flex;
  gap: 2px;
  margin-top: 6px;
  height: 46px;
  overflow: hidden;
  border-radius: 6px;
}
.filmstrip img {
  flex: 1 1 0;
  min-width: 0;
  height: 100%;
  object-fit: cover;
  opacity: 0.75;
  border-radius: 3px;
}
.filmstrip img:hover { opacity: 1; }

/* ---------------------------------------------------------------- forms --- */
fieldset {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 16px 18px 20px;
  margin: 0 0 14px;
}
legend {
  padding: 0 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  font-weight: 600;
}
label { display: block; margin: 14px 0; font-size: 14px; }
label small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
label output {
  float: right;
  font-family: var(--mono);
  color: var(--accent);
  font-size: 13px;
}
label.check { display: flex; align-items: center; gap: 10px; margin: 12px 0; }
label.check.inline { display: inline-flex; margin: 0; }
label.check span, label.inline span { font-size: 14px; }

input[type="range"] {
  width: 100%;
  margin: 8px 0 0;
  accent-color: var(--accent);
  height: 22px;
}
input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  margin: 0;
}
select {
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 14px;
}

#settings-msg { font-size: 13px; font-family: var(--mono); }
#settings-msg.ok { color: var(--accent); }
#settings-msg.bad { color: var(--bad); }

@media (max-width: 640px) {
  #app { padding: 12px 12px 48px; }
  .viewer { aspect-ratio: 1 / 1; max-height: 48vh; }
  .filmstrip { height: 34px; }
  .tab { padding: 10px 10px; font-size: 13px; }
}
