:root {
  --bg: #2b3a4a;
  --surface: #34465a;
  --text: #eef3f8;
  --muted: #9fb0c2;
  --accent: #8ec5ff;
  --accent-ink: #16222f;
  --line: #46596e;
  --topbar-h: 96px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Space Grotesk", system-ui, sans-serif;
  overscroll-behavior: none;
}
button { font-family: inherit; color: inherit; background: none; border: none; cursor: pointer; }

/* ---------- top bar ---------- */
#topbar {
  position: fixed; inset: 0 0 auto 0; z-index: 30;
  background: rgba(43,58,74,.86);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px 8px;
}
.wordmark { background: none; border: 0; padding: 0; cursor: pointer; font: inherit; text-align: left; font-weight: 700; font-size: 19px; letter-spacing: -0.02em; }
.wordmark::after { content: ""; display: inline-block; width: 7px; height: 7px; background: var(--accent); margin-left: 5px; border-radius: 50%; vertical-align: 2px; }
.topbar-actions { display: flex; gap: 6px; }
.topbar-actions button {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 10px; color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
}
.topbar-actions button.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
#saved-count { font-size: 13px; font-weight: 500; }
#search-row { padding: 0 16px 8px; }
#search-input {
  width: 100%; padding: 10px 12px; font-size: 15px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; outline: none;
  font-family: inherit;
}
#search-input:focus { border-color: var(--accent); }
#chips {
  display: flex; gap: 8px; overflow-x: auto; padding: 2px 16px 10px;
  scrollbar-width: none;
}
#chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; padding: 6px 12px; font-size: 13px; font-weight: 500;
  color: var(--muted); border: 1px solid var(--line); border-radius: 999px;
  white-space: nowrap;
}
.chip.active { background: var(--text); color: #16222f; border-color: var(--text); }

/* ---------- feed ---------- */
#feed {
  height: 100dvh;
  overflow-y: scroll;
  scroll-snap-type: y mandatory;
  scrollbar-width: none;
}
#feed::-webkit-scrollbar { display: none; }
.card {
  position: relative;
  height: 100dvh;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  display: flex; align-items: center; justify-content: center;
}
.stage {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: #141e29;
}
.facade { position: absolute; inset: 0; width: 100%; height: 100%; background: #141e29; overflow: hidden; }
.facade::before { content: ""; position: absolute; inset: -48px; background-image: var(--thumb); background-size: cover; background-position: center; filter: blur(34px) brightness(.5); transform: scale(1.15); }
.facade img { position: relative; z-index: 1; width: 100%; height: 100%; object-fit: contain; }
.facade iframe { position: absolute; inset: 0; z-index: 2; width: 100%; height: 100%; border: 0; }
.play-badge { position: relative; z-index: 1;
  transition: background-color .15s ease;
  position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%);
  width: 76px; height: 76px; border-radius: 50%;
  background: rgba(0,0,0,.55); color: #fff;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid rgba(255,255,255,.35);
}
.facade:hover .play-badge { background: rgba(0,0,0,.75); }
.card-info {
  position: absolute; left: 0; right: 76px; bottom: 0; z-index: 5;
  padding: 16px 16px calc(44px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(20,30,41,.8) 42%);
  opacity: 0; transform: translateY(14px);
  transition: opacity .28s ease, transform .28s ease;
}
.card.is-active .card-info { opacity: 1; transform: none; }
.card-title { font-size: 17px; font-weight: 500; line-height: 1.3; letter-spacing: -0.01em; }
.card-channel { margin-top: 4px; font-size: 13px; color: var(--muted); }
.card-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.card-tags .chip { padding: 4px 10px; font-size: 12px; color: var(--text); border-color: rgba(255,255,255,.3); }
.card-rail {
  position: absolute; right: 10px; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 6;
  display: flex; flex-direction: column; gap: 18px;
}
.rail-btn { color: #fff; opacity: .92; display: flex; padding: 6px; }
.rail-btn.saved svg { fill: var(--accent); stroke: var(--accent); }

/* intro card */
.intro-card { text-align: left; padding: 0 28px; }
.intro-card .inner { max-width: 420px; }
.intro-kicker { font-size: 13px; font-weight: 500; color: var(--accent); letter-spacing: .04em; }
.intro-card h1 { margin-top: 12px; font-size: 34px; line-height: 1.12; letter-spacing: -0.03em; font-weight: 700; }
.intro-card p { margin-top: 14px; font-size: 15px; line-height: 1.55; color: var(--muted); }
.intro-card .hint { margin-top: 26px; display: flex; align-items: center; gap: 10px; color: var(--text); font-size: 14px; font-weight: 500; }
.intro-card .hint svg { animation: bob 1.6s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(3px); } 50% { transform: translateY(-3px); } }
.intro-stats { margin-top: 20px; font-size: 13px; color: var(--muted); }
.intro-fineprint { margin-top: 26px; font-size: 12px; line-height: 1.5; color: #9fb0c2; }

/* empty state */
.empty-card p { color: var(--muted); font-size: 15px; text-align: center; padding: 0 32px; }

/* ---------- saved view ---------- */
#saved-view {
  min-height: 100dvh;
  padding: calc(var(--topbar-h) + 24px) 16px 60px;
  max-width: 720px; margin: 0 auto;
}
#saved-view h2 { font-size: 24px; letter-spacing: -0.02em; }
.saved-sub { margin-top: 4px; font-size: 13px; color: var(--muted); }
#saved-grid { margin-top: 20px; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.saved-item { text-align: left; }
.saved-item img { width: 100%; aspect-ratio: 16/9; object-fit: cover; border-radius: 6px; display: block; }
.saved-item h4 { margin-top: 8px; font-size: 13px; font-weight: 500; line-height: 1.3; }
.saved-item p { margin-top: 3px; font-size: 11px; color: var(--muted); }
.saved-item .unsave { margin-top: 6px; font-size: 11px; color: var(--accent); padding: 0; }
.fineprint { margin-top: 36px; font-size: 12px; line-height: 1.55; color: #9fb0c2; }

/* ---------- desktop ---------- */
@media (min-width: 720px) {
  body { display: flex; justify-content: center; }
  #topbar { left: 50%; transform: translateX(-50%); width: 480px; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
  #feed { width: 480px; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
  #saved-view { width: 480px; }
}
@media (max-height: 560px) {
  .card-rail { bottom: 16px; }
}

/* tag toast (swipe between tags) */
#tag-toast {
  position: fixed; top: calc(var(--topbar-h) + 12px); left: 50%; z-index: 40;
  transform: translate(-50%, -8px);
  background: var(--text); color: #16222f;
  padding: 8px 16px; border-radius: 999px;
  font-size: 14px; font-weight: 500;
  opacity: 0; pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
#tag-toast.show { opacity: 1; transform: translate(-50%, 0); }

.home-btn { display: inline-block; margin: 0 0 16px; padding: 8px 14px; border-radius: 999px; border: 1px solid rgba(255,255,255,.25); background: rgba(255,255,255,.08); color: inherit; font: inherit; font-size: 14px; cursor: pointer; }
.home-btn:hover { background: rgba(255,255,255,.16); }

/* design pass: house slate + accessibility */
h1, h2, h3 { text-wrap: balance; }
p { text-wrap: pretty; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

/* persistent clinical disclaimer strip (safety gate 5b.3) */
#disclaimer {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: min(480px, 100%); z-index: 25;
  padding: 16px 12px calc(7px + env(safe-area-inset-bottom));
  font-size: 10.5px; line-height: 1.35; text-align: center;
  color: var(--muted);
  background: linear-gradient(transparent, rgba(20,30,41,.92) 55%);
  pointer-events: none;
}
body:has(.card[data-playing="1"]) #disclaimer { display: none; }
