/* ---------- colours (light theme by default) ---------- */
:root {
  --bg: #ffffff;
  --surface: #f2f2f2;
  --surface-hover: #e5e5e5;
  --text: #0f0f0f;
  --muted: #606060;
  --accent: #7c3aed;
  --on-accent: #ffffff;
  --border: #d9d9d9;
  --topbar-h: 56px;
  --sidebar-w: 220px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0f0f12;
  --surface: #1c1c22;
  --surface-hover: #2a2a33;
  --text: #f4f4f5;
  --muted: #a1a1aa;
  --accent: #a78bfa;
  --on-accent: #0f0f12;
  --border: #2a2a33;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; }

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

.brand {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: 1.15rem;
  white-space: nowrap;
}

.search {
  flex: 1;
  min-width: 0;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
}

.search input {
  flex: 1;
  min-width: 0;
  padding: 8px 14px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 20px 0 0 20px;
  background: var(--bg);
  color: var(--text);
}

.search button {
  padding: 0 16px;
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 20px 20px 0;
  background: var(--surface);
  cursor: pointer;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
  font-size: 1.2rem;
  cursor: pointer;
}

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

/* ---------- sidebar ---------- */
.sidebar {
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  padding: 12px;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 5;
}

.sidebar a {
  padding: 10px 12px;
  border-radius: 10px;
}

.sidebar a:hover { background: var(--surface); }
.sidebar a.active { background: var(--surface); font-weight: 600; }

main {
  margin-left: var(--sidebar-w);
  padding: 16px 24px 48px;
}

/* ---------- category chips ---------- */
.chips {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 12px;
}

.chip {
  padding: 6px 14px;
  border-radius: 8px;
  background: var(--surface);
  white-space: nowrap;
}

.chip:hover { background: var(--surface-hover); }
.chip.active { background: var(--text); color: var(--bg); }

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

.card { display: flex; flex-direction: column; gap: 10px; }
.card h3 { font-size: 1rem; line-height: 1.3; }

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

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

.thumb-fallback {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  padding: 8px;
  text-align: center;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, #1c1c22, #3f3f46);
}

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

.meta { margin: 2px 0 0; color: var(--muted); font-size: 0.9rem; }

.card.compact { flex-direction: row; }
.card.compact .thumb { width: 168px; flex-shrink: 0; border-radius: 8px; }
.card.compact h3 { font-size: 0.9rem; }

.page-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.page-title { margin: 8px 0 16px; font-size: 1.3rem; }
.empty { color: var(--muted); padding: 32px 0; }
.empty a { color: var(--accent); }

/* ---------- watch page ---------- */
.watch {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 24px;
}

.player {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 12px;
  background: #000;
}

.watch-title { margin: 12px 0 8px; font-size: 1.3rem; }

.watch-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

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

.btn:hover { background: var(--surface-hover); }
.btn.on { background: var(--text); color: var(--bg); }

.description {
  margin-top: 12px;
  padding: 12px;
  border-radius: 12px;
  background: var(--surface);
  line-height: 1.5;
}

.description p { margin: 0 0 6px; }

/* ---------- comments ---------- */
.comments { margin-top: 24px; }
.comments-title { font-size: 1.1rem; margin-bottom: 12px; }

.comment-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: var(--bg);
}

.comment-card:focus-within { border-color: var(--accent); }

.comment-input {
  display: block;
  width: 100%;
  padding: 12px 14px;
  font: inherit;
  resize: vertical;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
}

.comment-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  background: var(--surface);
}

.emoji-bar { display: flex; gap: 2px; }

.emoji-btn {
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 8px;
  background: transparent;
  font-size: 1.15rem;
  cursor: pointer;
}

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

.comment-actions { display: flex; align-items: center; gap: 10px; }
.counter { font-size: 0.8rem; font-variant-numeric: tabular-nums; }

.btn.primary { background: var(--accent); color: var(--on-accent); border-radius: 10px; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.1); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.comment-list { list-style: none; margin: 20px 0 0; padding: 0; display: flex; flex-direction: column; gap: 18px; }
.comment { border-left: 3px solid var(--accent); padding: 2px 0 2px 12px; min-width: 0; }
.comment-head { margin: 0; font-size: 0.9rem; }
.comment-text { margin: 4px 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.4; }

.link-btn {
  padding: 0;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 0.85rem;
  cursor: pointer;
}

.link-btn:hover { color: var(--text); text-decoration: underline; }

.up-next { display: flex; flex-direction: column; gap: 12px; }
.up-next h2 { font-size: 1.1rem; }

/* ---------- smaller screens ---------- */
@media (max-width: 1000px) {
  .watch { grid-template-columns: 1fr; }
}

@media (max-width: 800px) {
  main { margin-left: 0; padding: 12px 16px 40px; }
  .sidebar { transform: translateX(-100%); transition: transform 0.2s; border-right: 1px solid var(--border); }
  body.menu-open .sidebar { transform: none; }
  .topbar { gap: 6px; padding: 0 8px; }
  .icon-btn { flex-shrink: 0; }
  .brand span { display: none; }
  .search button { padding: 0 10px; }
  .grid { grid-template-columns: 1fr; }
}

@media (min-width: 801px) {
  #menu-btn { display: none; }
}

/* ---------- keyboard focus: always visible for keyboard users ---------- */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- featured hero on the home page ---------- */
.hero {
  position: relative;
  overflow: hidden;
  min-height: 300px;
  margin-bottom: 28px;
  border-radius: 18px;
  display: flex;
  align-items: flex-end;
  background: linear-gradient(135deg, #1c1c22, #3f3f46);
}

.hero-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Dark fade so the text is always readable over the image */
.hero::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.85) 0%, rgba(0, 0, 0, 0.55) 45%, rgba(0, 0, 0, 0.1) 100%);
}

.hero-content {
  position: relative;
  z-index: 1;
  max-width: 560px;
  padding: 32px;
  color: #fff;
}

.hero h1 { font-size: 2.2rem; line-height: 1.1; }
.hero-label { margin: 0 0 8px; font-size: 0.85rem; font-weight: 700; letter-spacing: 0.04em; color: var(--accent); }
.hero-meta { margin: 8px 0 0; color: #d4d4d8; font-size: 0.9rem; }
.hero-text { margin: 12px 0 18px; line-height: 1.5; color: #e4e4e7; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.hero .btn:not(.primary) { background: rgba(255, 255, 255, 0.15); color: #fff; }
.hero .btn:not(.primary):hover { background: rgba(255, 255, 255, 0.25); }

.btn.big { padding: 11px 22px; font-size: 1rem; }
a.btn { display: inline-block; }

.row-section { margin-bottom: 32px; }
.section-title { margin: 0 0 14px; font-size: 1.2rem; }

/* ---------- card hover: lift, zoom and a play button ---------- */
.card .thumb img { transition: transform 0.3s ease; }
.card:hover .thumb img { transform: scale(1.05); }
.card:hover h3 { color: var(--accent); }

.play-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  padding-left: 4px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 1.2rem;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.8);
  transition: opacity 0.2s, transform 0.2s;
}

.card:hover .play-icon,
.card:focus-visible .play-icon { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.card.compact .play-icon { width: 36px; height: 36px; font-size: 0.9rem; }

/* red-style progress line under a thumbnail, like on video apps */
.progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 4px;
  background: rgba(255, 255, 255, 0.3);
}

.progress span { display: block; height: 100%; background: var(--accent); }

/* ---------- friendly empty pages ---------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 56px 16px;
  text-align: center;
  color: var(--muted);
}

.empty-icon {
  width: 72px;
  height: 72px;
  display: grid;
  place-items: center;
  margin-bottom: 4px;
  border-radius: 50%;
  background: var(--surface);
  font-size: 2rem;
}

.empty-state p { margin: 0 0 8px; max-width: 360px; }

/* ---------- video stage and overlays (error, up next) ---------- */
.stage { position: relative; }

.stage-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 16px;
  border-radius: 12px;
  text-align: center;
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
}

.stage-overlay p { margin: 0; }
.stage-overlay .meta { color: #d4d4d8; }
.stage-overlay h2 { margin-bottom: 4px; }
.stage-overlay .hero-actions { margin-top: 10px; }
.stage-overlay .btn:not(.primary) { background: rgba(255, 255, 255, 0.15); color: #fff; }
.overlay-kicker { font-size: 0.8rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--accent); }

.shortcuts { margin-top: 8px !important; font-size: 0.8rem; }

/* ---------- toast messages ---------- */
.toast-box {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  padding: 10px 18px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-size: 0.9rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
  animation: toast-in 0.2s ease;
  transition: opacity 0.4s;
}

.toast.hide { opacity: 0; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* ---------- mobile menu backdrop ---------- */
.backdrop { display: none; }

@media (max-width: 800px) {
  body.menu-open .backdrop {
    display: block;
    position: fixed;
    inset: var(--topbar-h) 0 0 0;
    z-index: 4;
    background: rgba(0, 0, 0, 0.5);
  }

  .hero { min-height: 260px; }
  .hero-content { padding: 20px; }
  .hero h1 { font-size: 1.6rem; }
  .hero-text { display: none; }
  .hero::after { background: linear-gradient(0deg, rgba(0, 0, 0, 0.9) 0%, rgba(0, 0, 0, 0.3) 100%); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* Fallback title fades so the hover play button stays clear */
.thumb-fallback { transition: opacity 0.2s; }
.card:hover .thumb-fallback { opacity: 0.35; }

@media (max-width: 800px) {
  .hero-meta { margin-bottom: 14px; }
}

/* ---------- editing a comment ---------- */
.comment-tools { display: flex; gap: 14px; }
.comment.editing { border-left: none; padding-left: 0; }
