/* HNTube: a video-site layout, coloured with Hacker News orange. */

:root {
  --bg: #ffffff;
  --bg-raised: #ffffff;
  --text: #0f0f0f;
  --text-2: #606060;
  --line: #e5e5e5;
  --hover: #f2f2f2;
  --chip: #f2f2f2;
  --chip-active-bg: #0f0f0f;
  --chip-active-text: #ffffff;
  --input-bg: #ffffff;
  --input-line: #d3d3d3;
  --search-btn: #f8f8f8;
  --thumb-bg: #e9e9e9;
  --brand: #ff6600;
  --brand-text: #c24e00;
  --toast-bg: #0f0f0f;
  --toast-text: #ffffff;
  --shadow: 0 4px 32px rgba(0, 0, 0, 0.12);
  --top: 56px;
  --side: 240px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f0f0f;
    --bg-raised: #212121;
    --text: #f1f1f1;
    --text-2: #aaaaaa;
    --line: #303030;
    --hover: #272727;
    --chip: #272727;
    --chip-active-bg: #f1f1f1;
    --chip-active-text: #0f0f0f;
    --input-bg: #121212;
    --input-line: #303030;
    --search-btn: #222222;
    --thumb-bg: #1f1f1f;
    --brand-text: #ff8a3d;
    --toast-bg: #f1f1f1;
    --toast-text: #0f0f0f;
    --shadow: 0 4px 32px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0f0f0f;
  --bg-raised: #212121;
  --text: #f1f1f1;
  --text-2: #aaaaaa;
  --line: #303030;
  --hover: #272727;
  --chip: #272727;
  --chip-active-bg: #f1f1f1;
  --chip-active-text: #0f0f0f;
  --input-bg: #121212;
  --input-line: #303030;
  --search-btn: #222222;
  --thumb-bg: #1f1f1f;
  --brand-text: #ff8a3d;
  --toast-bg: #f1f1f1;
  --toast-text: #0f0f0f;
  --shadow: 0 4px 32px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

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

a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
svg { fill: currentColor; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ---------- top bar ---------- */

.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 30;
  height: var(--top);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 16px;
  background: var(--bg);
}

.top-start, .top-end { display: flex; align-items: center; gap: 4px; flex: none; }

.icon-btn {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: none;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex: none;
}
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn:hover { background: var(--hover); }
.icon-btn:active { background: var(--line); }

.logo { display: flex; align-items: center; gap: 4px; padding: 0 8px 0 12px; height: 40px; }
.logo-mark { width: 30px; height: 22px; }
.logo-mark rect { fill: var(--brand); }
.logo-mark path { fill: #fff; }
.logo-word { font-size: 20px; font-weight: 700; letter-spacing: -0.06em; }

.search { flex: 0 1 640px; display: flex; align-items: center; min-width: 0; }
.search-box {
  flex: 1;
  min-width: 0;
  height: 40px;
  display: flex;
  align-items: center;
  border: 1px solid var(--input-line);
  border-right: 0;
  border-radius: 40px 0 0 40px;
  background: var(--input-bg);
  padding: 0 4px 0 16px;
}
.search-box:focus-within { border-color: #1c62b9; box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.2); }
.search-box input { width: 100%; border: 0; outline: 0; background: none; font-size: 16px; }
.search-go {
  width: 64px;
  height: 40px;
  border: 1px solid var(--input-line);
  border-radius: 0 40px 40px 0;
  background: var(--search-btn);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.search-go svg { width: 24px; height: 24px; }
.search-go:hover { background: var(--hover); }
.search-back, .search-open { display: none; }

#refresh-btn.spinning svg { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- sidebar ---------- */

.sidebar {
  position: fixed;
  top: var(--top);
  bottom: 0;
  left: 0;
  z-index: 20;
  width: var(--side);
  overflow-y: auto;
  padding: 12px;
  background: var(--bg);
  scrollbar-width: thin;
}

.side-nav a, .side-channels a {
  display: flex;
  align-items: center;
  gap: 24px;
  height: 40px;
  padding: 0 12px;
  border-radius: 10px;
  white-space: nowrap;
  overflow: hidden;
}
.side-nav a:hover, .side-channels a:hover { background: var(--hover); }
.side-nav a.active, .side-channels a.active { background: var(--hover); font-weight: 500; }
.side-nav svg { width: 24px; height: 24px; flex: none; }
.side-nav a span, .side-channels a span:not(.avatar) { overflow: hidden; text-overflow: ellipsis; }

.side-channels a { gap: 16px; }
.side-channels .count { margin-left: auto; color: var(--text-2); font-size: 12px; }
.side-channels .more {
  width: 100%;
  border: 0;
  background: none;
  height: 40px;
  padding: 0 12px;
  border-radius: 10px;
  text-align: left;
  cursor: pointer;
  color: var(--text-2);
}
.side-channels .more:hover { background: var(--hover); }

.sidebar hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }
.side-title { font-size: 16px; font-weight: 500; margin: 6px 12px 4px; }
.side-note { color: var(--text-2); font-size: 12px; line-height: 1.6; margin: 8px 12px 24px; }
.side-note a { color: var(--brand-text); }
.side-note #updated { display: block; margin-top: 6px; }

.avatar {
  width: 24px;
  height: 24px;
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  background: var(--avatar, #888);
  text-transform: uppercase;
}

.scrim { position: fixed; inset: 0; z-index: 25; background: rgba(0, 0, 0, 0.5); }

/* ---------- main area ---------- */

main {
  padding-top: var(--top);
  margin-left: var(--side);
  min-height: 100vh;
}
body.side-closed main { margin-left: 0; }
body.side-closed .sidebar { display: none; }
body.watching main { margin-left: 0; }
body.watching .sidebar { display: none; }
/* Opened as a drawer over the page (watch page, or any narrower screen below). */
body.side-open .sidebar { z-index: 26; box-shadow: var(--shadow); }
body.watching.side-open .sidebar { display: block; }

.browse { padding: 0 24px 48px; }

.chips-bar {
  position: sticky;
  top: var(--top);
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  background: var(--bg);
}
.chips { display: flex; gap: 12px; overflow-x: auto; scrollbar-width: none; flex: 1; min-width: 0; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: var(--chip);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.chip:hover { background: var(--line); }
.chip[aria-pressed="true"] { background: var(--chip-active-bg); color: var(--chip-active-text); }
.chip .n { opacity: 0.6; font-weight: 400; margin-left: 4px; }

.sort { display: flex; align-items: center; gap: 8px; color: var(--text-2); flex: none; }
.sort select {
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: var(--chip);
  padding: 0 8px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
}

.view-title { font-size: 20px; font-weight: 700; margin: 8px 0 16px; display: flex; align-items: center; gap: 12px; }
.view-title .avatar { width: 40px; height: 40px; font-size: 18px; }
.view-title small { font-size: 14px; color: var(--text-2); font-weight: 400; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 40px 16px;
  padding-top: 12px;
}

.card { display: block; min-width: 0; }
.thumb {
  position: relative;
  display: block;
  aspect-ratio: 16 / 9;
  border-radius: 12px;
  overflow: hidden;
  background: var(--thumb-bg);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 0.2s; }
.card:hover .thumb img { transform: scale(1.03); }
.thumb .placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 6px;
  padding: 16px;
  text-align: center;
  color: var(--text-2);
  font-weight: 500;
}
.thumb .placeholder svg { width: 48px; height: 48px; color: var(--brand); }

.badge {
  position: absolute;
  padding: 1px 4px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  line-height: 18px;
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
}
.badge.duration { right: 8px; bottom: 8px; }
.badge.front { left: 8px; bottom: 8px; background: var(--brand); text-transform: uppercase; letter-spacing: 0.02em; }
.badge.ext { right: 8px; bottom: 8px; }
.watched-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgba(255, 255, 255, 0.4); }
.watched-bar::after { content: ""; position: absolute; inset: 0; background: var(--brand); }
.card.watched .thumb img { opacity: 0.75; }

.card-body { display: flex; gap: 12px; padding-top: 12px; }
.card-body .avatar { width: 36px; height: 36px; font-size: 15px; margin-top: 2px; }
.card-text { min-width: 0; flex: 1; }
.card-title {
  margin: 0 0 4px;
  font-size: 16px;
  font-weight: 500;
  line-height: 22px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-meta { color: var(--text-2); font-size: 14px; line-height: 20px; }
.card-meta .channel-link:hover { color: var(--text); }
.card-meta div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.new-dot { color: var(--brand-text); font-weight: 600; font-size: 12px; text-transform: uppercase; margin-left: 6px; }

.skeleton .thumb { animation: pulse 1.4s ease-in-out infinite; }
.skeleton .line { height: 14px; border-radius: 4px; background: var(--thumb-bg); margin: 4px 0 10px; animation: pulse 1.4s ease-in-out infinite; }
.skeleton .line.short { width: 60%; }
@keyframes pulse { 50% { opacity: 0.5; } }

.empty { text-align: center; color: var(--text-2); padding: 80px 16px; font-size: 16px; }
.empty b { display: block; color: var(--text); font-size: 20px; margin-bottom: 8px; }

/* ---------- watch page ---------- */

.watch {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 402px;
  gap: 24px;
  max-width: 1754px;
  margin: 0 auto;
  padding: 24px 24px 48px;
}

.player {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
}
.player iframe, .player video { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.player .ext-cover { position: absolute; inset: 0; display: grid; place-items: center; }
.player .ext-cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0.55; }
.player .ext-cover a {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: 24px;
  background: var(--brand);
  color: #fff;
  font-weight: 600;
  font-size: 16px;
}
.player .ext-cover svg { width: 20px; height: 20px; }

.w-title { font-size: 20px; line-height: 28px; font-weight: 700; margin: 12px 0 8px; overflow-wrap: anywhere; }
.w-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.w-channel { display: flex; align-items: center; gap: 12px; min-width: 0; }
.w-channel .avatar { width: 40px; height: 40px; font-size: 18px; }
.w-channel-text { display: flex; flex-direction: column; min-width: 0; }
.w-channel-text b { font-size: 16px; font-weight: 500; }
.w-channel-text small { color: var(--text-2); font-size: 12px; }
.w-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 16px;
  border-radius: 18px;
  background: var(--chip);
  font-weight: 500;
  white-space: nowrap;
}
a.pill:hover { background: var(--line); }
.pill svg { width: 20px; height: 20px; }
.pill-strong { background: var(--brand); color: #fff; }
a.pill-strong:hover { background: #e65c00; }

.w-desc { margin-top: 12px; padding: 12px; border-radius: 12px; background: var(--chip); line-height: 1.6; overflow-wrap: anywhere; }
.w-desc b { font-weight: 500; }
.w-desc a { color: var(--brand-text); }
.w-desc p { margin: 0; }
.w-desc p + p { margin-top: 6px; }

.upnext h2 { font-size: 16px; font-weight: 500; margin: 0 0 12px; }
.mini { display: flex; gap: 8px; margin-bottom: 8px; padding: 4px; border-radius: 10px; }
.mini:hover { background: var(--hover); }
.mini .thumb { width: 168px; flex: none; border-radius: 8px; }
.mini .card-title { font-size: 14px; line-height: 20px; margin-bottom: 4px; }
.mini .card-meta { font-size: 12px; line-height: 18px; }
.mini .card-text { padding-top: 2px; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 24px;
  bottom: 24px;
  z-index: 50;
  max-width: calc(100vw - 48px);
  padding: 12px 16px;
  border-radius: 8px;
  background: var(--toast-bg);
  color: var(--toast-text);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: none; pointer-events: auto; }
.toast button { border: 0; background: none; color: var(--brand); font-weight: 600; margin-left: 12px; cursor: pointer; padding: 0; }

/* ---------- narrower screens ---------- */

@media (max-width: 1312px) {
  /* The sidebar becomes a drawer over the page, as on a phone. */
  main { margin-left: 0; }
  .sidebar { display: none; }
  body.side-open .sidebar, body.side-closed.side-open .sidebar { display: block; }
}

@media (max-width: 1016px) {
  .watch { grid-template-columns: minmax(0, 1fr); }
  .upnext .mini .thumb { width: 168px; }
}

@media (max-width: 656px) {
  .topbar { padding: 0 8px; gap: 4px; }
  .search { display: none; }
  .search-open { display: grid; }
  body.searching .top-start, body.searching .top-end { display: none; }
  body.searching .search { display: flex; flex: 1; gap: 4px; }
  body.searching .search-back { display: grid; }
  .logo { padding-left: 4px; }
  .browse { padding: 0 0 32px; }
  .chips-bar { padding: 12px 16px; }
  .sort span { display: none; }
  .sort select { width: 96px; }
  .view-title { margin: 8px 16px 12px; }
  .grid { grid-template-columns: 1fr; gap: 24px; padding-top: 0; }
  .thumb { border-radius: 0; }
  .card-body { padding: 12px 12px 0; }
  .watch { padding: 0 0 32px; gap: 16px; }
  .player { border-radius: 0; position: sticky; top: var(--top); z-index: 5; }
  .watch-main > :not(.player) { margin-left: 12px; margin-right: 12px; }
  .upnext { padding: 0 8px; }
  .mini .thumb { width: 150px; border-radius: 8px; }
  .toast { left: 16px; right: 16px; bottom: 16px; max-width: none; }
}

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