:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --surface-hover: #272727;
  --border: #2c2c2c;
  --text: #f1f1f1;
  --text-muted: #aaaaaa;
  --accent: #ff2e4c;
  --science: #3b82f6;
  --travel: #10b981;
  --chip-bg: #272727;
  --chip-active-bg: #f1f1f1;
  --chip-active-text: #0f0f0f;
  --radius: 12px;
}

[data-theme="light"] {
  --bg: #f9f9f9;
  --surface: #ffffff;
  --surface-hover: #f0f0f0;
  --border: #e5e5e5;
  --text: #0f0f0f;
  --text-muted: #606060;
  --chip-bg: #ececec;
  --chip-active-bg: #0f0f0f;
  --chip-active-text: #ffffff;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

/* Top Bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.05rem;
  cursor: pointer;
  white-space: nowrap;
}

.brand-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 22px;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-size: 0.75rem;
}

.search-wrap {
  flex: 1;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0 12px;
}

.search-wrap:focus-within {
  border-color: var(--science);
}

#search-input {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 8px 4px;
  font-size: 0.95rem;
  outline: none;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
}

.icon-btn:hover {
  background: var(--surface-hover);
}

.pill-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

/* Offline Banner */
.offline-banner {
  background: #92400e;
  color: #fef3c7;
  text-align: center;
  padding: 8px 16px;
  font-size: 0.875rem;
}

/* Filter Chips */
.filter-bar {
  position: sticky;
  top: 57px;
  z-index: 90;
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}

.filter-bar::-webkit-scrollbar {
  display: none;
}

.chip {
  flex-shrink: 0;
  background: var(--chip-bg);
  color: var(--text);
  border: none;
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease;
}

.chip:hover {
  filter: brightness(1.1);
}

.chip.active {
  background: var(--chip-active-bg);
  color: var(--chip-active-text);
  font-weight: 600;
}

/* Feed Grid */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}

.feed-status {
  text-align: center;
  color: var(--text-muted);
  padding: 24px 0;
  font-size: 0.95rem;
}

.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 24px 16px;
}

.video-grid.compact {
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}

.video-card {
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-radius: var(--radius);
  transition: transform 0.15s ease;
}

.video-card:hover .thumb-img {
  transform: scale(1.03);
}

.thumb-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}

.thumb-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.25s ease;
}

.thumb-badges {
  position: absolute;
  bottom: 8px;
  right: 8px;
  display: flex;
  gap: 4px;
}

.format-pill {
  background: rgba(0, 0, 0, 0.82);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 5px;
}

.card-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0 2px;
}

.card-title {
  font-size: 0.98rem;
  font-weight: 600;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-sub {
  font-size: 0.82rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
}

.badge-science {
  background: rgba(59, 130, 246, 0.16);
  color: #60a5fa;
}

.badge-travel {
  background: rgba(16, 185, 129, 0.16);
  color: #34d399;
}

[data-theme="light"] .badge-science { color: #1d4ed8; }
[data-theme="light"] .badge-travel { color: #047857; }

/* Watch View */
.watch-view {
  max-width: 1020px;
  margin: 0 auto;
  padding: 16px 16px 64px;
}

.back-btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 16px;
  font-size: 0.88rem;
  cursor: pointer;
  margin-bottom: 14px;
}

.back-btn:hover {
  background: var(--surface-hover);
}

.player-stage {
  width: 100%;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
  transition: max-width 0.2s ease;
}

.player-stage.aspect-wide {
  aspect-ratio: 16 / 9;
}

.player-stage.aspect-short {
  aspect-ratio: 9 / 16;
  max-width: 390px;
  max-height: 76vh;
  margin: 0 auto;
}

.player-mount,
.player-mount iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

.offline-player-notice {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  color: #e5e5e5;
  gap: 8px;
}

.watch-meta {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.watch-meta-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.format-switcher {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.format-btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
}

.format-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.watch-title {
  font-size: 1.35rem;
  line-height: 1.3;
}

.watch-question {
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* Collapsible Story Drawer */
.story-drawer {
  margin-top: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.story-summary {
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}

.story-summary::-webkit-details-marker {
  display: none;
}

.story-drawer[open] .story-chevron {
  transform: rotate(180deg);
}

.story-content {
  padding: 0 16px 18px;
  border-top: 1px solid var(--border);
  font-size: 0.96rem;
}

.story-lead {
  margin-top: 14px;
  white-space: pre-line;
}

.scene-list {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-left: 0;
  list-style: none;
}

.scene-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}

.scene-label {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.related-section {
  margin-top: 32px;
}

.section-heading {
  font-size: 1.1rem;
  margin-bottom: 14px;
}

.muted {
  color: var(--text-muted);
  margin-top: 12px;
}

@media (max-width: 600px) {
  .brand-text { display: none; }
  .watch-title { font-size: 1.15rem; }
}
