/* ChelsTube — a quiet YouTube clone for one viewer. */

:root {
  --bg: #0f0f0f;
  --surface: #272727;
  --panel: #212121;
  --hover: #3f3f3f;
  --text: #f1f1f1;
  --text-2: #aaaaaa;
  --red: #f03;
  --hairline: #303030;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Roboto", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }

/* ---------- masthead ---------- */

.masthead {
  height: 56px;
  display: flex;
  align-items: center;
  padding: 0 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 5px;
}

.brand-mark { display: block; }

.brand-word {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -1px;
  line-height: 1;
}

.brand-thin { font-weight: 400; color: var(--text-2); }

/* ---------- page layout ---------- */

.watch {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 24px 64px;
}

/* The player stays docked at the top of the screen while the rest of the page
   scrolls; its opaque background hides whatever passes beneath it. */
.player-dock {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bg);
  padding: 12px 0 16px;
}

/* One stage below the player shared by the description (the scrollable
   content) and the playlist panel, which overlays it while open. */
.stage {
  position: relative;
  min-height: 560px;
}

.under { min-width: 0; }

/* ---------- player ---------- */

.player {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
}

.player video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* Purely decorative: the video's own click handler does the toggling, so this
   overlay never intercepts clicks (a second click of a double-click has to
   reach the video for fullscreen to work from the playing state). */
.big-play {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  transition: opacity 0.15s;
  pointer-events: none;
}

.big-play svg { filter: drop-shadow(0 0 4px rgba(0, 0, 0, 0.5)); }

.player:not(.paused) .big-play { opacity: 0; }

.spinner {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  animation: spin 0.9s linear infinite;
  display: none;
}

.player.buffering .spinner { display: block; }

@keyframes spin { to { transform: rotate(360deg); } }

.player-error {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.85);
  padding: 16px;
  text-align: center;
  color: var(--text-2);
  font-size: 15px;
}

/* The hidden attribute alone would lose to the display: grid above and keep an
   85% black scrim over every video; make hiding explicit. */
.player-error[hidden] { display: none; }

/* ---------- controls ---------- */

.controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 48px 12px 4px;
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.75));
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}

.player:hover .controls,
.player.paused .controls,
.player:focus-within .controls { opacity: 1; pointer-events: auto; }

.timeline {
  height: 12px;
  display: flex;
  align-items: flex-end;
  margin-bottom: 2px;
  cursor: pointer;
}

.tl-track {
  position: relative;
  width: 100%;
  height: 3px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
  transition: height 0.1s;
}

.timeline:hover .tl-track { height: 5px; }

.tl-buffered, .tl-played {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 2px;
  width: 0;
}

.tl-buffered { background: rgba(255, 255, 255, 0.4); }
.tl-played { background: var(--red); }

.tl-dot {
  position: absolute;
  right: -6px;
  top: 50%;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--red);
  transform: translateY(-50%) scale(0);
  transition: transform 0.1s;
}

.timeline:hover .tl-dot { transform: translateY(-50%) scale(1); }

.controls-row {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 48px;
}

.ctl {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
}

.ctl:hover { background: rgba(255, 255, 255, 0.1); }

.ic { width: 24px; height: 24px; fill: #fff; }
.ic path, .ic rect { fill: #fff; }

.ic-pause, .ic-collapse { display: none; }
.player:not(.paused) .ic-play { display: none; }
.player:not(.paused) .ic-pause { display: block; }
.player.fullscreen .ic-expand { display: none; }
.player.fullscreen .ic-collapse { display: block; }

.ic-vol-lo, .ic-vol-off { display: none; }
.player.vol-hi .ic-vol-hi { display: block; }
.player.vol-hi .ic-vol-lo, .player.vol-hi .ic-vol-off { display: none; }
.player.vol-lo .ic-vol-lo { display: block; }
.player.vol-lo .ic-vol-hi, .player.vol-lo .ic-vol-off { display: none; }
.player.vol-off .ic-vol-off { display: block; }
.player.vol-off .ic-vol-hi, .player.vol-off .ic-vol-lo { display: none; }
.ic .wave { fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; }

.volume { display: flex; align-items: center; }

#volume {
  -webkit-appearance: none;
  appearance: none;
  width: 64px;
  height: 3px;
  margin: 0 8px;
  background: linear-gradient(to right, #fff var(--vol, 100%), rgba(255, 255, 255, 0.3) var(--vol, 100%));
  border-radius: 2px;
  cursor: pointer;
}

#volume::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
}

#volume::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: 0;
  border-radius: 50%;
  background: #fff;
}

.time { font-size: 12px; color: #fff; margin-left: 10px; white-space: nowrap; }

.spacer { flex: 1; }

.ctl-text { width: auto; padding: 0 10px; font-size: 14px; font-weight: 500; }

.speed-wrap { position: relative; }

.speed-menu {
  position: absolute;
  right: 0;
  bottom: 48px;
  min-width: 200px;
  background: rgba(28, 28, 28, 0.95);
  border-radius: 12px;
  padding: 8px 0;
  box-shadow: 0 4px 32px rgba(0, 0, 0, 0.8);
}

.speed-title {
  display: block;
  padding: 6px 16px 10px;
  font-size: 13px;
  font-weight: 500;
  border-bottom: 1px solid #3d3d3d;
}

.speed-list button {
  display: flex;
  justify-content: space-between;
  width: 100%;
  padding: 8px 16px;
  font-size: 13px;
  color: var(--text-2);
}

.speed-list button:hover { background: rgba(255, 255, 255, 0.1); color: var(--text); }
.speed-list button.on { color: #fff; font-weight: 500; }
.speed-list button.on::after { content: "✓"; margin-left: 16px; }

/* ---------- under the player ---------- */

.video-title {
  font-size: 20px;
  font-weight: 400;
  line-height: 1.4;
  margin: 16px 0 8px;
}

.meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.meta-info { color: var(--text-2); font-size: 14px; }
.sep { margin: 0 4px; }

.meta-actions { display: flex; gap: 8px; }

.pill {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 16px;
  border-radius: 18px;
  background: var(--surface);
  font-size: 14px;
  font-weight: 500;
  transition: background 0.1s;
}

.pill:hover { background: var(--hover); }
.pill .ic { width: 20px; height: 20px; }

#btn-like.liked .ic path { fill: #fff; }

.channel-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 8px 0 16px;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--red);
  color: #fff;
  font-size: 15px;
  font-weight: 500;
  display: grid;
  place-items: center;
  flex: none;
}

.channel-name { font-size: 15px; font-weight: 500; }
.channel-sub { font-size: 12px; color: var(--text-2); margin-top: 2px; }

/* ---------- description ---------- */

.description {
  background: var(--surface);
  border-radius: 12px;
  padding: 12px 16px 14px;
  position: relative;
}

.desc-meta { font-size: 13px; font-weight: 500; margin-bottom: 6px; }

.desc-text {
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-line;
}

.description.clamped .desc-text {
  max-height: 40px;
  overflow: hidden;
}

.desc-yt {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  width: fit-content;
}

.desc-yt:hover { color: var(--text); }

.desc-more {
  margin-top: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
}

.desc-more:hover { color: var(--text); }

/* ---------- playlist panel ---------- */

/* Open: the playlist covers the description (absolutely positioned over the
   same stage) and scrolls internally. Closed: it's gone — the description
   becomes the scrollable content and a small fixed bar brings the playlist
   back in front of it. */
.playlist-panel {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: var(--panel);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.playlist-panel.closed { display: none; }

.pl-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 16px 16px 12px;
}

.pl-actions { display: flex; align-items: center; gap: 4px; }

.pl-close {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 50%;
}

.pl-close:hover { background: rgba(255, 255, 255, 0.1); }

.pl-title { margin: 0; font-size: 16px; font-weight: 500; }
.pl-sub { display: block; margin-top: 4px; font-size: 12px; color: var(--text-2); }

.pl-yt {
  flex: none;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--text-2);
  font-size: 16px;
}

.pl-yt:hover { background: rgba(255, 255, 255, 0.1); color: var(--text); }

.pl-list {
  list-style: none;
  margin: 0;
  padding: 0 12px 12px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: #555 transparent;
}

.pl-item {
  display: grid;
  grid-template-columns: 24px 160px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  width: 100%;
  padding: 8px;
  border-radius: 10px;
  text-align: left;
}

.pl-item:hover { background: rgba(255, 255, 255, 0.08); }
.pl-item.active { background: rgba(255, 255, 255, 0.14); }

.pl-index {
  font-size: 12px;
  color: var(--text-2);
  text-align: center;
}

.eq {
  display: none;
  align-items: flex-end;
  justify-content: center;
  gap: 2px;
  height: 14px;
}

.eq i {
  width: 4px;
  height: 100%;
  background: var(--red);
  border-radius: 1px;
  transform-origin: bottom;
  transform: scaleY(0.3);
}

.eq i:nth-child(2) { transform: scaleY(0.9); }
.eq i:nth-child(3) { transform: scaleY(0.55); }

.pl-item.active .pl-index { display: none; }
.pl-item.active .eq { display: flex; }

.is-playing .eq i { animation: eq 0.9s ease-in-out infinite alternate; }
.is-playing .eq i:nth-child(1) { animation-delay: -0.6s; }
.is-playing .eq i:nth-child(2) { animation-delay: -0.3s; }
.is-playing .eq i:nth-child(3) { animation-delay: -0.9s; }

@keyframes eq { from { transform: scaleY(0.3); } to { transform: scaleY(1); } }

.pl-thumb-wrap {
  position: relative;
  width: 160px;
  aspect-ratio: 16 / 9;
  border-radius: 8px;
  overflow: hidden;
  background: #000;
  flex: none;
}

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

.pl-dur {
  position: absolute;
  right: 4px;
  bottom: 4px;
  background: rgba(0, 0, 0, 0.8);
  border-radius: 4px;
  padding: 2px 5px;
  font-size: 11px;
  font-weight: 500;
  color: #fff;
}

.pl-prog {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: rgba(255, 255, 255, 0.25);
  display: none;
}

.pl-item.active .pl-prog { display: block; }

.pl-prog i {
  display: block;
  height: 100%;
  background: var(--red);
  width: 0;
}

.pl-title-line {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.pl-channel { display: block; margin-top: 4px; font-size: 12px; color: var(--text-2); }

/* ---------- floating playlist bar (playlist closed) ---------- */

.playlist-bar {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  border-radius: 24px;
  background: var(--panel);
  border: 1px solid var(--hairline);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.6);
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}

.playlist-bar svg { width: 18px; height: 18px; fill: var(--text-2); }
.playlist-bar:hover { background: var(--hover); }

/* display: flex above would defeat the hidden attribute (the scrim bug) —
   hiding is explicit. */
.playlist-bar[hidden] { display: none; }

/* ---------- responsive ---------- */

@media (max-width: 700px) {
  /* Edge to edge on phones: no horizontal margins or padding anywhere. */
  .watch { padding: 0 0 32px; }
  .player-dock { padding: 8px 0 12px; }
  .player { border-radius: 0; }
  .masthead { padding: 0; }
  .stage { min-height: 480px; }
  .pl-item { grid-template-columns: 24px 140px minmax(0, 1fr); }
  .pl-thumb-wrap { width: 140px; }
  .video-title { font-size: 17px; }
  .playlist-bar { bottom: 12px; padding: 10px 16px; }
}
