:root {
  --bg: #0b0d12;
  --panel: #151922;
  --text: #f4f6fb;
  --muted: #9aa3b2;
  --accent: #4f8cff;
  --felony: #ff4d4d;
  --misdemeanor: #ffb020;
  --infraction: #7a8699;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

/* The hidden attribute must always win over the display rules below
   (.empty/.sheet/.loader set display, which otherwise overrides the
   user-agent [hidden] { display:none } and leaves them stuck visible). */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: #000;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

/* On wide screens, frame the feed as a centered phone-width column. */
body {
  max-width: 500px;
  margin: 0 auto;
  position: relative;
  background: var(--bg);
}

#topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  max-width: 500px;
  margin: 0 auto;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: linear-gradient(180deg, rgba(0,0,0,0.75), rgba(0,0,0,0));
  pointer-events: none;
}
#topbar .brand {
  font-weight: 800;
  font-size: 22px;
  letter-spacing: -0.5px;
  text-shadow: 0 1px 4px rgba(0,0,0,0.6);
}
.area-btn {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(20,25,34,0.7);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 600;
  backdrop-filter: blur(8px);
  cursor: pointer;
  max-width: 60vw;
}
.area-btn .pin { color: var(--accent); font-size: 9px; }
.area-btn #areaLabel { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#feed {
  height: 100dvh;
  overflow-y: scroll;
  scroll-snap-type: y mandatory;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
#feed::-webkit-scrollbar { display: none; }

.card {
  position: relative;
  height: 100dvh;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  background: #0e1118;
}

.card-media { position: absolute; inset: 0; z-index: 0; }
.card-media .mug { width: 100%; height: 100%; object-fit: cover; }
.mug-placeholder {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(120% 80% at 50% 0%, #2a3445 0%, #141823 55%, #0b0d12 100%);
}
.mug-placeholder .initials {
  font-size: 34vw;
  font-weight: 800;
  color: rgba(255,255,255,0.08);
  letter-spacing: -2px;
  user-select: none;
}
.no-photo {
  position: absolute;
  top: calc(50% + 18vw);
  left: 0; right: 0;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.card.has-photo .mug-placeholder,
.card.has-photo .no-photo { display: none; }

.card-overlay {
  position: relative;
  z-index: 1;
  padding: 20px 18px calc(34px + var(--safe-bottom));
  background: linear-gradient(0deg, rgba(0,0,0,0.92) 12%, rgba(0,0,0,0.55) 55%, rgba(0,0,0,0) 100%);
}

.sev-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 4px 9px;
  border-radius: 6px;
  margin-bottom: 10px;
  color: #0b0d12;
}
.sev-felony { background: var(--felony); color: #fff; }
.sev-misdemeanor { background: var(--misdemeanor); }
.sev-infraction { background: var(--infraction); color: #fff; }
.sev-none { display: none; }

.name {
  margin: 0 0 6px;
  font-size: 27px;
  line-height: 1.1;
  font-weight: 800;
  text-shadow: 0 1px 6px rgba(0,0,0,0.6);
}
.meta-line { color: var(--text); font-size: 15px; font-weight: 600; margin-bottom: 10px; }
.meta-line .dot { margin: 0 7px; color: var(--muted); }
.meta-line .loc { color: var(--muted); }

.charges {
  margin: 0 0 12px;
  font-size: 16px;
  line-height: 1.35;
  color: #e7ebf3;
}
.sub { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.sub .bail:not(:empty)::before { content: "Bail: "; }

.footer-line { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--muted); }
.footer-line .ago { color: #cfd6e4; font-weight: 600; }
.footer-line .source { margin-left: auto; opacity: 0.8; }

.swipe-hint {
  position: absolute;
  bottom: calc(8px + var(--safe-bottom));
  left: 0; right: 0;
  text-align: center;
  font-size: 12px;
  color: rgba(255,255,255,0.5);
  z-index: 2;
  animation: bob 1.8s ease-in-out infinite;
  pointer-events: none;
}
.card:not(:first-child) .swipe-hint { display: none; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }

.loader, .empty {
  position: fixed;
  left: 0; right: 0;
  max-width: 500px;
  margin: 0 auto;
  text-align: center;
}
.loader { bottom: 18px; z-index: 15; color: var(--muted); font-size: 14px; }
.empty {
  top: 0; bottom: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px; gap: 8px; z-index: 5;
}
.empty h2 { margin: 0; font-size: 20px; }
.empty p { margin: 0; color: var(--muted); }

.btn {
  appearance: none;
  border: 1px solid rgba(255,255,255,0.2);
  background: var(--panel);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }

.sheet {
  position: fixed;
  inset: 0;
  max-width: 500px;
  margin: 0 auto;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  background: rgba(0,0,0,0.55);
}
.sheet-card {
  width: 100%;
  background: var(--panel);
  border-radius: 18px 18px 0 0;
  padding: 22px 18px calc(22px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.sheet-card h2 { margin: 0; font-size: 19px; }
.muted { color: var(--muted); font-size: 13px; margin: 0; }
.radius { display: flex; flex-direction: column; gap: 8px; font-size: 14px; color: var(--muted); }
.radius input[type=range] { width: 100%; accent-color: var(--accent); }
.sheet-actions { display: flex; gap: 10px; }
.sheet-actions .btn { flex: 1; }
