:root {
  --bg: #0f0f0f;
  --surface: #181818;
  --text: #f1f1f1;
  --text-dim: #aaaaaa;
  --accent: #3ea6ff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background-color: var(--bg);
  background-image: linear-gradient(rgba(15, 15, 15, 0.45), rgba(15, 15, 15, 0.45)), url("bg.avif");
  background-repeat: repeat-y;
  background-size: 100% auto;
  color: var(--text);
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
}

header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(15, 15, 15, 0.1);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  gap: 12px;
}

header h1 {
  font-size: 20px;
  margin: 0;
  flex: 1 1 0;
}

header a {
  color: var(--text);
  text-decoration: none;
}

.search-input {
  flex: 0 0 auto;
  width: min(360px, 40vw);
  background: var(--surface);
  border: 1px solid #2a2a2a;
  color: var(--text);
  border-radius: 20px;
  padding: 8px 16px;
  font-size: 14px;
}

.search-input:focus {
  outline: none;
  border-color: var(--accent);
}

.mode-toggle {
  flex: 1 1 0;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.mode-btn {
  background: var(--surface);
  border: 1px solid #2a2a2a;
  color: var(--text-dim);
  border-radius: 16px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

.mode-btn:hover {
  border-color: var(--accent);
}

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

@media (max-width: 700px) {
  header { flex-wrap: wrap; }
  header h1, .mode-toggle { flex: 0 0 auto; }
  .search-input { flex: 1 1 100%; width: auto; order: 3; }
}

.searching {
  color: var(--text-dim);
  padding: 40px;
  text-align: center;
  grid-column: 1 / -1;
}

.toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 16px;
}

#sort-select {
  background: var(--surface);
  border: 1px solid #2a2a2a;
  color: var(--text);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
}

#sort-select:focus {
  outline: none;
  border-color: var(--accent);
}

main {
  padding: 24px;
  width: 100%;
  margin: 0 auto;
}

.grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 20px;
}

@media (max-width: 1400px) {
  .grid { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 1100px) {
  .grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 800px) {
  .grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 500px) {
  .grid { grid-template-columns: 1fr; }
}

.card {
  cursor: pointer;
  color: inherit;
  text-decoration: none;
  min-width: 0;
}

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

.thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.duration {
  position: absolute;
  right: 6px;
  bottom: 6px;
  background: rgba(0, 0, 0, 0.8);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
}

.card .title {
  margin-top: 8px;
  font-size: 17px;
  font-weight: 600;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card .date {
  color: var(--text-dim);
  font-size: 14px;
  margin-top: 4px;
}

.empty {
  color: var(--text-dim);
  padding: 40px;
  text-align: center;
}

.player-page main {
  max-width: 1000px;
}

video {
  width: 100%;
  display: block;
  background: transparent;
}

.player-wrap {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  background: transparent;
}

.video-area {
  position: relative;
}

#player-audio {
  display: none;
}

.pc-poster {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
  pointer-events: none;
}

.player-wrap.audio-mode .pc-poster {
  display: block;
}

.player-wrap:fullscreen {
  /* Our own `position: relative` above always wins over the browser's
     default fullscreen (position: fixed, full-viewport) styling, since
     author rules beat the UA stylesheet regardless of specificity — so it
     must be restated explicitly here or the element never actually fills
     the screen. */
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  border-radius: 0;
  display: block;
}

.player-wrap:fullscreen .video-area {
  /* Always the full screen — the controls bar below is an overlay on top
     of this, not a sibling sharing the height, so there's no reserved
     strip that shrinks the video's box and forces artificial letterboxing
     when the video's aspect ratio doesn't match the screen's. */
  height: 100%;
}

.player-wrap:fullscreen video {
  height: 100%;
  width: 100%;
  object-fit: contain;
}

.player-wrap:fullscreen .player-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.75), rgba(0, 0, 0, 0.35) 70%, transparent);
}

.player-controls {
  background: #0b0b0b;
  padding: 6px 12px 10px;
  color: var(--text);
  font-size: 13px;
  opacity: 1;
  transition: opacity 0.25s ease;
}

.player-wrap.controls-hidden .player-controls {
  opacity: 0;
  pointer-events: none;
}

.player-wrap.controls-hidden {
  cursor: none;
}

.pc-seek-row {
  padding: 4px 0;
}

.pc-seek {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

.pc-row {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.pc-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}

.pc-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.pc-btn-small {
  font-size: 15px;
  padding: 2px 8px;
  font-weight: 700;
}

.pc-time {
  color: var(--text-dim);
  white-space: nowrap;
}

.pc-volume {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pc-volume input {
  width: 70px;
  accent-color: var(--accent);
}

.pc-speed {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.pc-speed-slider {
  width: 120px;
  accent-color: var(--accent);
}

.pc-speed-label {
  min-width: 52px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  font-weight: 600;
}

.pc-speed-presets {
  display: flex;
  gap: 2px;
}

.pc-preset {
  background: rgba(255, 255, 255, 0.08);
  border: none;
  color: var(--text);
  font-size: 12px;
  padding: 3px 6px;
  border-radius: 4px;
  cursor: pointer;
}

.pc-preset:hover {
  background: var(--accent);
  color: #041016;
}

@media (max-width: 700px) {
  .pc-speed-presets { display: none; }
  .pc-speed { margin-left: 0; }
}

.watch-title {
  font-size: 24px;
  font-weight: 700;
  margin: 16px 0 4px;
}

.watch-meta-row {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.watch-date {
  color: var(--text-dim);
  font-size: 15px;
}

.watch-yt-link {
  color: var(--accent);
  font-size: 14px;
  text-decoration: none;
}

.watch-yt-link:hover {
  text-decoration: underline;
}

.watch-description {
  white-space: pre-line;
  background: var(--surface);
  border-radius: 8px;
  padding: 16px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
}

.watch-description a {
  color: var(--accent);
}
