:root {
  --bg: #101215;
  --panel: #171a1f;
  --raise: #1f232a;
  --line: #2a2f37;
  --text: #eef1f5;
  --muted: #8f98a5;
  --accent: #f2b45a;
  --accent-ink: #1b1306;
  --error: #ff7b72;
  --bar-h: 64px;
  --side-w: 290px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.brand { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; margin: 0; white-space: nowrap; }
.brand::first-letter { color: var(--accent); }
.vname { font-size: 14px; font-weight: 500; color: var(--muted); letter-spacing: 0; margin-left: 4px; }
button.primary { background: var(--accent); color: var(--accent-ink); font-weight: 650; padding: 11px 20px; border-radius: 999px; }
button.primary:disabled { opacity: 0.45; }
button.secondary { background: var(--raise); padding: 11px 18px; border-radius: 999px; border: 1px solid var(--line); }
button.icon { padding: 8px; border-radius: 50%; color: var(--muted); display: grid; place-items: center; }
button.icon:hover { background: var(--raise); color: var(--text); }
button.icon.light { color: #fff; }
.error { color: var(--error); font-size: 14px; }

/* ---------------- the code screen */
.gate { min-height: 100%; display: grid; place-items: start center; padding: 14vh 20px 40px; }
.gate-box { width: 100%; max-width: 380px; }
.gate .brand { font-size: 30px; }
.lead { color: var(--muted); margin: 6px 0 20px; }
.where { font-weight: 600; margin: -8px 0 18px; }
.gate label { display: block; color: var(--muted); font-size: 14px; margin-bottom: 14px; }
.gate input { display: block; width: 100%; margin-top: 6px; padding: 12px 14px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--line); outline: none; }
.gate input:focus { border-color: var(--accent); }
input.code { font-size: 24px; letter-spacing: 0.3em; text-align: center; }

/* ---------------- top bar */
.bar { position: sticky; top: 0; z-index: 30; height: var(--bar-h); display: flex; align-items: center; gap: 14px;
  padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  background: rgba(16,18,21,0.92); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-bottom: 1px solid var(--line); }
.search { flex: 1; max-width: 640px; display: flex; align-items: center; gap: 8px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 999px; padding: 0 6px 0 14px; height: 42px; }
.search:focus-within { border-color: var(--accent); }
.search svg { color: var(--muted); width: 18px; height: 18px; }
.search input { flex: 1; min-width: 0; border: 0; background: none; outline: none; height: 100%; }
.smart { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); padding: 6px 10px;
  border-radius: 999px; cursor: pointer; white-space: nowrap; user-select: none; }
.smart input { accent-color: var(--accent); margin: 0; }
.smart:has(input:checked) { background: var(--raise); color: var(--text); }
.sort { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; }
.filters-btn { display: none; align-items: center; gap: 6px; padding: 9px 14px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line); font-weight: 600; }
.badge { background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 700; border-radius: 999px;
  min-width: 20px; height: 20px; display: inline-grid; place-items: center; padding: 0 6px; }

/* ---------------- sidebar / filter sheet */
.body { display: flex; align-items: flex-start; }
.panel { position: sticky; top: var(--bar-h); width: var(--side-w); flex: none; height: calc(100vh - var(--bar-h));
  display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--bg); }
.panel-scroll { flex: 1; overflow-y: auto; padding: 8px 16px 24px; overscroll-behavior: contain; }
.sheet-head, .sheet-foot { display: none; }
.panel section { padding: 14px 0; border-bottom: 1px solid var(--line); }
.panel section:last-child { border-bottom: 0; }
.panel h3 { font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 0 0 10px; }
.segmented { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.segmented button { padding: 6px 14px; border-radius: 999px; color: var(--muted); font-size: 14px; }
.segmented button.on { background: var(--raise); color: var(--text); }
.segmented.small { margin-top: 10px; }
.segmented.small button { font-size: 13px; padding: 5px 12px; }
.check { display: flex; align-items: center; gap: 8px; margin-top: 12px; cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
.dates { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.dates label { font-size: 13px; color: var(--muted); }
.dates input { display: block; width: 100%; margin-top: 4px; padding: 8px; border-radius: 8px; background: var(--panel);
  border: 1px solid var(--line); color-scheme: dark; }

.people { display: grid; grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); gap: 10px 6px; }
.person { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); text-align: center; }
.person .face { width: 48px; height: 48px; border-radius: 50%; background: var(--raise) center/cover; display: grid; place-items: center;
  font-weight: 600; outline: 2px solid transparent; outline-offset: 2px; }
.person .nm { max-width: 64px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person.on { color: var(--text); }
.person.on .face { outline-color: var(--accent); }

.list { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 7px 8px; border-radius: 8px;
  text-align: left; width: 100%; color: var(--text); }
.row:hover { background: var(--panel); }
.row.on { background: var(--raise); box-shadow: inset 3px 0 0 var(--accent); }
.row .n { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.row .tw { display: inline-block; width: 14px; color: var(--muted); transition: transform 0.15s; }
.row.open .tw { transform: rotate(90deg); }
.sub { padding-left: 18px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 5px 11px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); font-size: 13px; }
.chip.on { border-color: var(--accent); background: var(--raise); }
.none { color: var(--muted); font-size: 13px; }

/* ---------------- grid */
.main { flex: 1; min-width: 0; padding: 12px 16px 60px; }
.status { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; min-height: 34px; margin-bottom: 6px; }
.total { color: var(--muted); font-size: 14px; }
.active { display: flex; flex-wrap: wrap; gap: 6px; }
.active button { display: inline-flex; align-items: center; gap: 6px; padding: 4px 6px 4px 11px; border-radius: 999px;
  background: var(--raise); border: 1px solid var(--line); font-size: 13px; }
.active button svg { width: 14px; height: 14px; color: var(--muted); }
.active .clear { padding: 4px 11px; color: var(--accent); background: none; border-color: transparent; }
.group h4 { position: sticky; top: var(--bar-h); z-index: 5; margin: 0; padding: 12px 2px 8px; font-size: 15px; font-weight: 650;
  background: linear-gradient(var(--bg) 70%, transparent); }
.group h4 .n { color: var(--muted); font-weight: 400; font-size: 13px; margin-left: 6px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px; }
.tile { position: relative; aspect-ratio: 1; background: var(--panel); border-radius: 4px; overflow: hidden; padding: 0; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 0.2s, opacity 0.2s; opacity: 0; }
.tile img.ready { opacity: 1; }
.tile:hover img { transform: scale(1.03); }
.tile .vid { position: absolute; right: 6px; bottom: 6px; display: flex; align-items: center; gap: 3px; font-size: 12px; font-weight: 600;
  color: #fff; background: rgba(0,0,0,0.55); padding: 2px 7px 2px 4px; border-radius: 999px; }
.tile .vid svg { width: 14px; height: 14px; fill: #fff; stroke: none; }
.tile .heart { position: absolute; left: 6px; bottom: 6px; color: #fff; filter: drop-shadow(0 1px 2px rgba(0,0,0,0.6)); }
.tile .heart svg { width: 16px; height: 16px; fill: #fff; stroke: none; }
.more { height: 80px; display: grid; place-items: center; color: var(--muted); font-size: 14px; }
.empty { color: var(--muted); text-align: center; padding: 60px 20px; }

/* ---------------- viewer */
.viewer { position: fixed; inset: 0; z-index: 100; background: #000; touch-action: pan-y; }
.stage { position: absolute; inset: 0; display: grid; place-items: center; overflow: hidden; }
.stage img, .stage video { max-width: 100%; max-height: 100%; object-fit: contain; display: block; user-select: none; -webkit-user-drag: none; }
.stage .slide { position: absolute; inset: 0; display: grid; place-items: center; transition: transform 0.25s ease-out; }
.stage .loading { color: #aaa; }
.vbar { position: absolute; left: 0; right: 0; z-index: 3; display: flex; align-items: center; gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 10px max(12px, env(safe-area-inset-left));
  transition: opacity 0.25s; }
.vbar.top { top: 0; background: linear-gradient(rgba(0,0,0,0.6), transparent); }
.vbar.bottom { bottom: 0; justify-content: center; padding-bottom: max(16px, env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0,0,0,0.6)); }
.vtitle { color: #fff; font-weight: 600; text-shadow: 0 1px 4px rgba(0,0,0,0.7); }
.vtitle small { display: block; font-weight: 400; color: rgba(255,255,255,0.75); font-size: 13px; }
.pill { display: inline-flex; align-items: center; gap: 7px; color: #fff; padding: 10px 18px; border-radius: 999px;
  background: rgba(30,33,40,0.75); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); font-weight: 600; }
.pill svg { width: 19px; height: 19px; }
.nav { position: absolute; top: 50%; transform: translateY(-50%); z-index: 3; width: 48px; height: 48px; border-radius: 50%;
  display: grid; place-items: center; color: #fff; background: rgba(30,33,40,0.55); }
.nav.prev { left: 14px; } .nav.next { right: 14px; }
.nav:disabled { opacity: 0; pointer-events: none; }
.viewer.calm .vbar, .viewer.calm .nav { opacity: 0; pointer-events: none; }
.info { position: absolute; z-index: 4; top: 0; right: 0; bottom: 0; width: 340px; background: var(--panel); border-left: 1px solid var(--line);
  overflow-y: auto; padding: max(14px, env(safe-area-inset-top)) 18px 24px; }
.info-head { display: flex; align-items: center; justify-content: space-between; }
.info-head h2 { margin: 0; font-size: 18px; }
.info dl { margin: 10px 0 0; }
.info dt { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; margin-top: 14px; }
.info dd { margin: 3px 0 0; }
.info dd .chip { display: inline-block; margin: 2px 4px 2px 0; }
.toast { position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 200;
  background: var(--raise); border: 1px solid var(--line); padding: 10px 18px; border-radius: 999px; box-shadow: 0 6px 24px rgba(0,0,0,0.4); }

/* ---------------- phones and narrow windows */
@media (max-width: 899px) {
  :root { --bar-h: 58px; }
  .bar { gap: 8px; }
  .brand { font-size: 0; }                        /* just the "P" mark on a phone */
  .brand::first-letter { font-size: 24px; }
  .vname, .sort { display: none; }
  .search { height: 40px; }
  .smart span { display: none; }
  .smart { padding: 6px; }
  .filters-btn { display: inline-flex; padding: 8px 12px; }
  .filters-btn span:not(.badge) { display: none; }
  .panel { position: fixed; z-index: 60; left: 0; right: 0; bottom: 0; top: auto; width: auto; height: 86vh; height: 86dvh;
    border: 0; border-radius: 18px 18px 0 0; background: var(--panel); transform: translateY(100%); transition: transform 0.25s ease-out;
    box-shadow: 0 -10px 40px rgba(0,0,0,0.5); }
  .panel.open { transform: none; }
  .panel section { border-color: var(--line); }
  .sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 12px 4px 18px; }
  .sheet-head h2 { margin: 0; font-size: 18px; }
  .sheet-head::before { content: ""; position: absolute; top: 7px; left: 50%; width: 40px; height: 4px; margin-left: -20px; border-radius: 2px; background: var(--line); }
  .sheet-foot { display: flex; gap: 10px; padding: 12px 16px max(12px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
  .sheet-foot .primary { flex: 1; }
  .scrim { position: fixed; inset: 0; z-index: 55; background: rgba(0,0,0,0.5); }
  .main { padding: 8px 2px 60px; }
  .status { padding: 0 8px; }
  .group h4 { padding: 10px 8px 6px; }
  .tiles { grid-template-columns: repeat(3, 1fr); gap: 2px; }
  .tile { border-radius: 0; }
  .nav { display: none; }
  .info { left: 0; right: 0; top: auto; width: auto; max-height: 62vh; border-left: 0; border-top: 1px solid var(--line); border-radius: 16px 16px 0 0;
    padding-bottom: max(24px, env(safe-area-inset-bottom)); }
}
@media (min-width: 600px) and (max-width: 899px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
