:root,
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121212;
  --surface: #1e1e1e;
  --surface-2: #262626;
  --text: #f5f5f5;
  --text-dim: #a8a8a8;
  --accent: #0095f6;
  --border: #2a2a2a;
  --nav-height: 60px;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-2: #efefef;
  --text: #262626;
  --text-dim: #8e8e8e;
  --accent: #0095f6;
  --border: #dbdbdb;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#app {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

#views {
  flex: 1;
  min-height: 0;
  position: relative;
}

.view {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  pointer-events: none;
}

.view.no-transition {
  transition: none;
}

.view.active {
  transform: translateX(0);
  pointer-events: auto;
}

.view.off-left {
  transform: translateX(-100%);
}

/* ---------- Bottom nav ---------- */

#bottom-nav {
  min-height: var(--nav-height);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex: 0 0 auto;
}

.nav-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 6px 0;
}

.nav-btn .icon-filled {
  display: none;
}

.nav-btn.active .icon-outline {
  display: none;
}

.nav-btn.active .icon-filled {
  display: block;
}

.nav-btn.active {
  color: var(--accent);
}

/* ---------- Feed ---------- */

#view-feed {
  padding-bottom: var(--nav-height);
}

.pull-indicator {
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.2s ease, opacity 0.2s ease, padding 0.2s ease;
}

.pull-indicator.visible {
  max-height: 40px;
  opacity: 1;
  padding: 10px 0;
}

.topic-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px;
  padding-bottom: 6px;
}

.topic-chip {
  flex: 0 0 auto;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 13px;
}

.topic-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  font-weight: 600;
}

/* Instagram-style post: avatar+name header, full-bleed square photo, caption below */

.post {
  display: block;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
  margin-bottom: 12px;
  text-decoration: none;
  color: inherit;
}

.post-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px 10px;
}

.avatar {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: #05121f;
}

.post-header-text {
  min-width: 0;
}

.post-username {
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.post-topic {
  font-size: 11px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.post-image {
  display: block;
  width: 100%;
  aspect-ratio: 1/1;
  object-fit: cover;
  background: var(--surface-2);
}

.post-caption {
  padding: 10px 12px 4px;
  font-size: 13.5px;
  line-height: 1.45;
}

.post-caption strong {
  margin-right: 4px;
}

.post-timestamp {
  padding: 0 12px;
  font-size: 10.5px;
  letter-spacing: 0.04em;
  color: var(--text-dim);
}

.state-msg {
  text-align: center;
  color: var(--text-dim);
  padding: 40px 20px;
  font-size: 14px;
}

.stories-host .state-msg {
  padding: 14px 12px;
  font-size: 12px;
}

/* ---------- Reels ---------- */

#view-reels {
  scroll-snap-type: y mandatory;
  background: #000;
}

.reel {
  position: relative;
  height: 100%;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

.reel iframe,
.reel video {
  width: 100%;
  height: 100%;
  border: none;
  object-fit: contain;
}

.reel-touch-catcher {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.reel .reel-overlay {
  position: absolute;
  left: 14px;
  right: 70px;
  bottom: 20px;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
  pointer-events: none;
}

.reel .reel-overlay .channel {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
}

.reel .reel-overlay .title {
  font-size: 13px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.reel .mute-btn {
  position: absolute;
  z-index: 2;
  right: 14px;
  bottom: 24px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border: none;
  font-size: 18px;
  backdrop-filter: blur(4px);
}

/* ---------- Stories (pinned strip at the top of the Feed) ---------- */

.stories-host {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: calc(10px + env(safe-area-inset-top, 0px)) 0 4px;
}

.stories-strip {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  padding: 0 12px 6px;
}

.story-bubble {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 72px;
  background: none;
  border: none;
  color: var(--text);
}

.story-bubble .ring {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  padding: 2.5px;
  background: linear-gradient(135deg, var(--accent), #7cf0c2);
}

.story-bubble .ring.watched {
  background: var(--border);
}

.story-bubble .thumb {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--surface-2) center/cover no-repeat;
  border: 2px solid var(--bg);
}

.story-bubble .label {
  font-size: 11px;
  color: var(--text-dim);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}

/* ---------- Story modal (tap-through) ---------- */

.story-modal {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 50;
  display: flex;
  flex-direction: column;
}

.story-modal.hidden {
  display: none;
}

.story-progress {
  display: flex;
  gap: 4px;
  padding: 10px 10px 0;
  padding-top: calc(10px + env(safe-area-inset-top));
}

.story-progress .bar {
  flex: 1;
  height: 3px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 2px;
  overflow: hidden;
}

.story-progress .bar .fill {
  height: 100%;
  width: 0%;
  background: #fff;
}

.story-progress .bar.done .fill {
  width: 100%;
}

.story-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  color: #fff;
}

.story-header .close-btn {
  background: none;
  border: none;
  color: #fff;
  font-size: 20px;
  padding: 4px 8px;
}

.story-slide {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  background: var(--surface-2) center/cover no-repeat;
  position: relative;
}

.story-slide::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.85), rgba(0, 0, 0, 0.1) 40%);
}

.story-slide .content {
  position: relative;
  padding: 20px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
  color: #fff;
}

.story-slide .content .source {
  font-size: 12px;
  color: var(--accent);
  margin-bottom: 8px;
}

.story-slide .content h2 {
  margin: 0 0 10px;
  font-size: 20px;
  line-height: 1.3;
}

.story-slide .content a {
  color: #fff;
  font-size: 13px;
  text-decoration: underline;
}

.story-tap-zones {
  position: absolute;
  inset: 0;
  display: flex;
}

.story-tap-zones .zone {
  flex: 1;
}

/* ---------- Settings sheet ---------- */

.settings-sheet {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-end;
}

.settings-sheet.hidden {
  display: none;
}

.settings-sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}

.settings-sheet-panel {
  position: relative;
  z-index: 1;
  width: 100%;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}

.settings-sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.settings-sheet-header h3 {
  margin: 0;
  font-size: 16px;
}

.settings-close-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  padding: 4px 8px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 14px;
}

.theme-toggle {
  display: flex;
  gap: 8px;
}

.theme-toggle button {
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 13px;
}

.theme-toggle button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  font-weight: 600;
}
