:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --line: #e4e7ec;
  --text: #1b1f24;
  --muted: #6b7280;
  --accent: #2563eb;
  --news: #2563eb;
  --did: #16a34a;
  --worry: #ea8a2f;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 16px/1.45 -apple-system, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: env(safe-area-inset-bottom);
}
.screen { max-width: 680px; margin: 0 auto; padding: 16px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.err { color: #d92d20; min-height: 1em; }

/* Auth */
#auth { display: flex; min-height: 100dvh; align-items: center; }
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 16px; padding: 24px; width: 100%;
  box-shadow: 0 6px 24px rgba(16,24,40,.06);
}
.card h1 { margin: 0 0 4px; }
input, textarea, button {
  font: inherit; width: 100%; margin-top: 10px;
  padding: 12px; border-radius: 12px; border: 1px solid var(--line);
  background: #fff; color: var(--text);
}
.row { display: flex; gap: 10px; }
.row > * { margin-top: 10px; }
button {
  background: var(--accent); color: #fff; border: none;
  font-weight: 600; cursor: pointer;
}
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
button.small { width: auto; padding: 6px 12px; margin: 0; }

/* App */
header {
  display: flex; justify-content: space-between; align-items: center;
  padding-top: env(safe-area-inset-top);
}

/* --- Stories bar --- */
#stories {
  display: flex; gap: 14px; overflow-x: auto; padding: 14px 2px;
  scrollbar-width: none;
}
#stories::-webkit-scrollbar { display: none; }
.story { flex: 0 0 auto; text-align: center; width: 72px; cursor: pointer; }
.story .ring {
  width: 64px; height: 64px; border-radius: 50%;
  padding: 3px; margin: 0 auto;
  background: var(--line);
}
.story.has .ring {
  background: conic-gradient(from 210deg, var(--accent), var(--did), var(--worry), var(--accent));
}
.story .av {
  width: 100%; height: 100%; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 22px; color: #fff;
  border: 3px solid var(--card);
  background-size: cover; background-position: center;
}
.story .nm {
  display: block; margin-top: 6px; font-size: 12px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* --- Dense feed (cards) --- */
main#feed {
  columns: 2; column-gap: 12px; padding-bottom: 190px;
}
.post {
  break-inside: avoid; display: inline-block; width: 100%;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px; margin-bottom: 12px;
  border-left: 4px solid var(--line);
  box-shadow: 0 2px 8px rgba(16,24,40,.04);
}
.post.news { border-left-color: var(--news); }
.post.did { border-left-color: var(--did); }
.post.worry { border-left-color: var(--worry); }
.post .meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.post .badge { font-weight: 600; }
.post.news .badge { color: var(--news); }
.post.did .badge { color: var(--did); }
.post.worry .badge { color: var(--worry); }
.post p { margin: 8px 0 0; white-space: pre-wrap; font-size: 14px; }
.post img { width: 100%; border-radius: 10px; margin-top: 10px; }

/* --- Profile screen --- */
#profile header strong { font-size: 17px; }
#p-hero { text-align: center; padding: 18px 0 8px; }
#p-hero .big {
  width: 96px; height: 96px; border-radius: 50%; margin: 0 auto 10px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 36px; color: #fff;
  background-size: cover; background-position: center;
}
#p-hero h2 { margin: 0; }
#p-hero .count { color: var(--muted); font-size: 14px; }
#p-hero button.play { width: auto; margin-top: 12px; padding: 8px 20px; }
#p-feed { padding-bottom: 40px; }
#p-feed .post { display: block; columns: auto; }

/* Composer pinned to bottom */
#composer {
  position: fixed; bottom: 0; left: 0; right: 0;
  max-width: 680px; margin: 0 auto;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
}
.types { display: flex; gap: 14px; font-size: 14px; }
.types label { display: flex; align-items: center; gap: 4px; }
.types input { width: auto; margin: 0; }
#c-text { margin-top: 8px; }
#composer .row button { width: auto; }
#c-photo { border: none; padding: 6px 0; }

/* --- Full-screen story viewer (stays dark/vivid) --- */
#viewer {
  position: fixed; inset: 0; z-index: 100;
  background: #000; display: flex; flex-direction: column;
}
#v-bars { display: flex; gap: 4px; padding: 10px 10px 0; padding-top: calc(10px + env(safe-area-inset-top)); }
#v-bars .b { flex: 1; height: 3px; border-radius: 3px; background: rgba(255,255,255,.3); overflow: hidden; }
#v-bars .b > i { display: block; height: 100%; width: 0; background: #fff; }
#v-bars .b.done > i { width: 100%; }
#v-bars .b.active > i { animation: fill 5s linear forwards; }
#viewer.paused #v-bars .b.active > i { animation-play-state: paused; }
@keyframes fill { to { width: 100%; } }

#v-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px; color: #fff;
}
#v-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; background-size: cover; background-position: center;
}
#v-name { font-weight: 600; }
#v-time { color: rgba(255,255,255,.7); font-size: 13px; }
#v-close { margin-left: auto; width: auto; background: none; color: #fff; font-size: 20px; padding: 0 6px; }

#v-stage {
  flex: 1; position: relative;
  display: flex; align-items: center; justify-content: center;
  background-size: cover; background-position: center;
  padding: 20px;
}
#v-stage::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(0,0,0,.25), rgba(0,0,0,.55));
  pointer-events: none;
}
#v-text {
  position: relative; z-index: 1; color: #fff;
  font-size: 24px; line-height: 1.35; font-weight: 600;
  text-align: center; max-width: 90%;
  text-shadow: 0 2px 12px rgba(0,0,0,.6); white-space: pre-wrap;
}
.v-tap { position: absolute; top: 70px; bottom: 120px; width: 35%; z-index: 2; }
#v-tap-prev { left: 0; }
#v-tap-next { right: 0; width: 65%; }

/* Comments footer inside viewer */
#v-foot {
  position: relative; z-index: 5;
  background: rgba(0,0,0,.55); backdrop-filter: blur(8px);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  color: #fff;
}
#v-ctoggle {
  width: auto; background: none; color: #fff; padding: 4px 0; margin: 0;
  font-size: 14px; opacity: .9;
}
#v-comments {
  max-height: 38vh; overflow-y: auto; margin: 6px 0;
}
#v-comments .cm { padding: 6px 0; border-top: 1px solid rgba(255,255,255,.12); font-size: 14px; }
#v-comments .cm b { font-weight: 600; }
#v-comments .cm .t { color: rgba(255,255,255,.6); font-size: 12px; margin-left: 6px; }
#v-comments .empty { color: rgba(255,255,255,.6); font-size: 14px; padding: 8px 0; }
#v-cform { display: flex; gap: 8px; }
#v-cform input {
  margin: 0; background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.2); color: #fff;
}
#v-cform input::placeholder { color: rgba(255,255,255,.6); }
#v-cform button { width: auto; margin: 0; }

/* comment count on feed cards */
.post .cc { color: var(--muted); font-size: 13px; margin-top: 8px; }
