:root {
  --bg: #222222;
  --surface: #2b2b2b;
  --surface-2: #383838;
  --border: #444444;
  --text: #f1f1f1;
  --text-muted: #aaaaaa;
  --accent: #ff4e45;

  /* Active chip — pale lavender pill on dark bg */
  --chip-active-bg: #e6e6fa;
  --chip-active-text: #4b0082;
  --chip-active-border: #e6e6fa;

  /* Saved-topic pills — pale mint */
  --pill-bg: rgb(229, 244, 238);
  --pill-text: #047857;
  --pill-border: rgb(229, 244, 238);

  --radius: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; }

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 22px;
  font-weight: 700;
}
.brand-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
}
.tagline {
  text-align: center;
  color: var(--text-muted);
  margin: 6px 0 22px;
  font-size: 14px;
}

.search-row {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}
.search-row input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 13px 16px;
  font-size: 15px;
  outline: none;
}
.search-row input:focus { border-color: #3a4259; }
.search-row button {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 18px;
  font-size: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.search-row button:hover { background: var(--surface-2); }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}
.chip {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
}
.chip:hover { background: var(--surface); }
.chip.active {
  background: var(--chip-active-bg);
  color: var(--chip-active-text);
  border-color: var(--chip-active-border);
}

.section-label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 13px;
  margin: 4px 0 8px;
}

.topics {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 22px;
}
.topic {
  background: var(--pill-bg);
  color: var(--pill-text);
  border: 1px solid var(--pill-border);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.topic .x {
  opacity: 0.55;
  font-size: 14px;
  cursor: pointer;
  padding: 0 2px;
  color: #047857;
}
.topic .x:hover { opacity: 1; color: #b91c1c; }
.topic.add {
  background: transparent;
  color: var(--text-muted);
  border: 1px dashed var(--border);
}
.topic.add:hover { color: var(--text); }

.player {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 22px;
  min-height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}
.player .placeholder {
  text-align: center;
  color: var(--text-muted);
  padding: 30px;
}
.player .placeholder .play-circle {
  display: inline-flex; align-items: center; justify-content: center;
  margin-bottom: 12px;
  color: var(--text-muted);
}
.player .placeholder .play-circle svg {
  width: 48px; height: 48px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
}
.player .placeholder h3 {
  margin: 0 0 6px; color: var(--text); font-weight: 500; font-size: 15px;
}
.player .placeholder p { margin: 0; font-size: 13px; }

.player .frame-wrap {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
}
.player iframe {
  width: 360px;
  max-width: 100%;
  aspect-ratio: 9 / 16;
  border: 0;
  border-radius: 10px;
  background: black;
}
.player .now-playing {
  margin-top: 12px;
  width: 100%;
  max-width: 600px;
  text-align: center;
}
.player .now-playing .t { font-size: 14px; }
.player .now-playing .m { color: var(--text-muted); font-size: 12px; margin-top: 4px; }

.results-meta {
  color: var(--text-muted);
  font-size: 13px;
  margin: 6px 0 12px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.card {
  background: transparent;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  flex-direction: column;
}
.thumb {
  position: relative;
  aspect-ratio: 9 / 16;
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface-2);
}
.thumb img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.thumb .play-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: transparent;
  transition: background 0.15s ease;
}
.card:hover .thumb .play-overlay { background: rgba(0,0,0,0.15); }
.thumb .play-overlay .pc {
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(0,0,0,0.65);
  display: inline-flex; align-items: center; justify-content: center;
  color: white;
}
.thumb .duration {
  position: absolute;
  bottom: 8px; right: 8px;
  background: rgba(0,0,0,0.8);
  color: white;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
}
.thumb .bookmark {
  position: absolute;
  top: 8px; right: 8px;
  width: 30px; height: 30px;
  border-radius: 50%;
  background: rgba(0,0,0,0.6);
  border: none;
  color: white;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}
.thumb .bookmark:hover { background: rgba(0,0,0,0.8); }
.thumb .bookmark.active { color: #ffd43b; }

.card .title {
  font-size: 14px;
  margin: 10px 2px 4px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card .views {
  color: var(--text-muted);
  font-size: 12px;
  margin: 0 2px;
}

.empty, .loading, .error {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 20px;
  font-size: 14px;
}
.error { color: #ff8a8a; }

/* --- Shorts overlay --- */
body.shorts-open { overflow: hidden; }
.shorts-overlay {
  position: fixed; inset: 0;
  background: #000;
  z-index: 1000;
  display: none;
  flex-direction: column;
}
.shorts-overlay.open { display: flex; }

.shorts-list {
  width: 100%;
  height: 100%;
  overflow-y: scroll;
  scroll-snap-type: y mandatory;
  overscroll-behavior: contain;
}

.shorts-item {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  flex: 0 0 auto;
  scroll-snap-align: start;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.shorts-stage {
  width: min(420px, calc((100vh - 40px) * 9 / 16));
  width: min(420px, calc((100dvh - 40px) * 9 / 16));
  aspect-ratio: 9 / 16;
  background: #111;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
  position: relative;
}
.shorts-stage iframe {
  width: 100%; height: 100%; border: 0; display: block; position: absolute; inset: 0;
}
.shorts-stage .thumb {
  position: absolute; inset: 0; z-index: 1;
  background-size: cover; background-position: center;
}
.shorts-stage.active .thumb {
  display: none;
}

.shorts-close {
  position: fixed;
  top: 16px; right: 16px;
  width: 38px; height: 38px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  color: #fff;
  border: none;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  z-index: 100;
}
.shorts-close:hover { background: rgba(255,255,255,0.2); }

.shorts-mute {
  position: fixed;
  top: 16px; left: 16px;
  width: 38px; height: 38px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  color: #fff;
  border: none;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  z-index: 100;
}
.shorts-mute:hover { background: rgba(255,255,255,0.2); }
.shorts-nav {
  position: fixed;
  right: 24px;
  width: 44px; height: 44px;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
  color: #fff;
  border: none;
  font-size: 14px;
  cursor: pointer;
  z-index: 100;
}
.shorts-nav:hover:not(:disabled) { background: rgba(255,255,255,0.22); }
.shorts-nav:disabled { opacity: 0.25; cursor: default; }
.shorts-nav.up { top: calc(50% - 56px); }
.shorts-nav.down { top: calc(50% + 12px); }

.shorts-meta {
  position: absolute;
  bottom: 24px; left: 0; right: 0;
  text-align: center;
  color: #fff;
  padding: 0 24px;
  pointer-events: none;
  z-index: 10;
}
.shorts-meta .t { font-size: 14px; max-width: 480px; margin: 0 auto; text-shadow: 0 1px 3px rgba(0,0,0,0.8); }
.shorts-meta .m { font-size: 12px; opacity: 0.9; margin-top: 4px; text-shadow: 0 1px 3px rgba(0,0,0,0.8); }
.shorts-meta .i { font-size: 11px; opacity: 0.7; margin-top: 8px; text-shadow: 0 1px 3px rgba(0,0,0,0.8); }

@media (max-width: 800px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .player iframe { width: 300px; }
  .shorts-nav { right: 12px; }
}
@media (max-width: 480px) {
  .app { padding: 18px 14px 40px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .search-row button span { display: none; }
}
