:root {
  --bg: #ffffff;
  --bg-raised: #ffffff;
  --text: #0f0f0f;
  --text-2: #606060;
  --line: #e5e5e5;
  --chip: #f2f2f2;
  --chip-hover: #e5e5e5;
  --chip-on: #0f0f0f;
  --chip-on-text: #ffffff;
  --hover: #f2f2f2;
  --accent: #ff6600;
  --accent-text: #c2410c;
  --input-bg: #ffffff;
  --input-line: #cccccc;
  --search-btn: #f8f8f8;
  --badge-bg: rgba(0, 0, 0, 0.8);
  --shadow: 0 4px 32px rgba(0, 0, 0, 0.1);
  --bar: #ff6600;
  --bar-dim: #f3d3bd;
  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;
    --chip: #272727;
    --chip-hover: #3f3f3f;
    --chip-on: #f1f1f1;
    --chip-on-text: #0f0f0f;
    --hover: #272727;
    --accent-text: #ff8a3d;
    --input-bg: #121212;
    --input-line: #303030;
    --search-btn: #222222;
    --shadow: 0 4px 32px rgba(0, 0, 0, 0.5);
    --bar-dim: #4a2a14;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0f0f0f;
  --bg-raised: #212121;
  --text: #f1f1f1;
  --text-2: #aaaaaa;
  --line: #303030;
  --chip: #272727;
  --chip-hover: #3f3f3f;
  --chip-on: #f1f1f1;
  --chip-on-text: #0f0f0f;
  --hover: #272727;
  --accent-text: #ff8a3d;
  --input-bg: #121212;
  --input-line: #303030;
  --search-btn: #222222;
  --shadow: 0 4px 32px rgba(0, 0, 0, 0.5);
  --bar-dim: #4a2a14;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 Roboto, "Helvetica Neue", Arial, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
svg { fill: currentColor; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- top bar ---------- */
.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  height: 56px;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 16px;
  background: var(--bg);
}
.topbar-start, .topbar-end { display: flex; align-items: center; gap: 8px; flex: none; }
.icon-btn {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: transparent; cursor: pointer;
}
.icon-btn:hover { background: var(--hover); }
.icon-btn svg { width: 24px; height: 24px; }
.logo { display: flex; align-items: center; gap: 4px; padding: 0 8px; font-size: 20px; letter-spacing: -0.6px; }
.logo svg { width: 30px; height: 30px; }
.logo b { font-weight: 700; }

.search { flex: 0 1 640px; display: flex; min-width: 0; }
.search input {
  flex: 1; min-width: 0; height: 40px;
  padding: 0 16px;
  font: inherit; font-size: 16px; color: var(--text);
  background: var(--input-bg);
  border: 1px solid var(--input-line); border-right: 0;
  border-radius: 40px 0 0 40px;
}
.search input:focus { outline: none; border-color: #1c62b9; }
.search button {
  width: 64px; height: 40px; flex: none;
  display: grid; place-items: center;
  background: var(--search-btn);
  border: 1px solid var(--input-line);
  border-radius: 0 40px 40px 0;
  cursor: pointer;
}
.search button svg { width: 22px; height: 22px; }

/* ---------- sidebar ---------- */
.sidebar {
  position: fixed;
  top: 56px; bottom: 0; left: 0;
  width: 240px;
  z-index: 20;
  overflow-y: auto;
  padding: 12px;
  background: var(--bg);
  scrollbar-width: thin;
}
.nav-section { padding: 12px 0; border-bottom: 1px solid var(--line); }
.nav-section:first-child { padding-top: 0; }
.nav-section:last-child { border-bottom: 0; }
.nav-title { margin: 6px 12px 6px; font-size: 16px; font-weight: 500; }
.nav-item {
  display: flex; align-items: center; gap: 20px;
  height: 40px; padding: 0 12px;
  border-radius: 10px;
  white-space: nowrap;
}
.nav-item:hover { background: var(--hover); }
.nav-item[aria-current="page"] { background: var(--chip); font-weight: 500; }
.nav-item svg { width: 24px; height: 24px; flex: none; }
.nav-item span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.nav-item .count { flex: none; margin-left: auto; color: var(--text-2); font-size: 12px; }
.nav-note { margin: 8px 12px; color: var(--text-2); font-size: 12px; line-height: 1.5; }

body.nav-collapsed .sidebar { display: none; }
body.nav-collapsed main { margin-left: 0; }

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

/* ---------- main ---------- */
main {
  margin-left: 240px;
  padding: 56px 24px 48px;
  min-height: 100vh;
}
main:focus { outline: none; }
body.watching main { margin-left: 0; }
body.watching:not(.nav-open) .sidebar { display: none; }
body.watching.nav-open .sidebar { display: block; box-shadow: var(--shadow); }

.year-grid { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 8px; }
.year-chip { height: 28px; padding: 0 8px; font-size: 13px; }
.year-chip[aria-current="page"] { background: var(--chip-on); color: var(--chip-on-text); }

.loading, .empty { padding: 48px 0; color: var(--text-2); text-align: center; }

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

.page-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 8px 16px; margin: 8px 0 16px; }
.page-head h1 { margin: 0; font-size: 20px; font-weight: 700; }
.page-head p { margin: 0; color: var(--text-2); }
.page-head .sort { margin-left: auto; display: flex; align-items: center; gap: 8px; color: var(--text-2); }
.page-head select {
  height: 32px; padding: 0 8px;
  font: inherit; color: var(--text);
  background: var(--chip); border: 0; border-radius: 8px;
}

/* ---------- grid ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 40px 16px;
}
.card { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.thumb {
  position: relative;
  display: block;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 12px;
  background: var(--chip);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .2s; }
.card:hover .thumb img { transform: scale(1.03); }
.duration, .hn-badge {
  position: absolute; bottom: 6px;
  padding: 1px 4px;
  border-radius: 4px;
  font-size: 12px; font-weight: 500; line-height: 18px;
  color: #fff;
}
.duration { right: 6px; background: var(--badge-bg); }
.ext-badge {
  position: absolute; top: 6px; right: 6px;
  padding: 1px 6px; border-radius: 4px;
  font-size: 12px; font-weight: 500; line-height: 18px;
  color: #fff; background: var(--badge-bg);
}
.hn-badge { left: 6px; background: var(--accent); }
.card-body { display: flex; gap: 12px; }
.avatar {
  flex: none;
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border-radius: 50%;
  font-weight: 500; font-size: 15px; color: #fff;
  text-transform: uppercase;
}
.card-text { min-width: 0; }
.card-title {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
  margin: 0 0 4px;
  font-size: 16px; font-weight: 500; line-height: 22px;
}
.meta { color: var(--text-2); font-size: 14px; line-height: 20px; }
.meta a:hover { color: var(--text); }
.meta .hn { color: var(--accent-text); font-weight: 500; }
.sentinel { display: flex; margin: 32px auto 0; }
.sentinel[hidden] { display: none; }

/* ---------- watch page ---------- */
.watch {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 402px;
  gap: 24px;
  max-width: 1754px;
  margin: 24px auto 0;
}
.player {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 12px;
  background: #000;
}
.player iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.player .poster { width: 100%; height: 100%; object-fit: cover; opacity: .45; display: block; }
.player .offline {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  padding: 16px; text-align: center; color: #fff;
}
.player .offline p { margin: 0; max-width: 460px; }
.player .offline .btn { background: #fff; color: #0f0f0f; }
.watch h1 { margin: 12px 0 8px; font-size: 20px; line-height: 28px; font-weight: 700; overflow-wrap: anywhere; }
.owner { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; }
.owner .avatar { width: 40px; height: 40px; }
.owner-name { font-size: 16px; font-weight: 500; }
.owner-sub { color: var(--text-2); font-size: 12px; }
.actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: 8px; }
.btn {
  height: 36px; padding: 0 16px;
  display: inline-flex; align-items: center; gap: 6px;
  border: 0; border-radius: 18px;
  background: var(--chip);
  font-weight: 500; white-space: nowrap; cursor: pointer;
}
.btn:hover { background: var(--chip-hover); }
.btn svg { width: 20px; height: 20px; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }

.desc {
  margin-top: 12px; padding: 12px;
  border-radius: 12px;
  background: var(--chip);
}
.desc-stats { font-weight: 500; }
.desc-stats .hn { color: var(--accent-text); }
.desc-text { margin: 8px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.desc-text.clamped { max-height: 3.9em; overflow: hidden; }
.linkish { padding: 0; border: 0; background: none; font-weight: 500; cursor: pointer; margin-top: 4px; }

.timeline { margin-top: 24px; }
.timeline h2, .hn-list h2, .side h2 { margin: 0 0 12px; font-size: 18px; font-weight: 700; }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 72px; }
.bar { flex: 1; min-width: 4px; position: relative; border-radius: 3px 3px 0 0; background: var(--bar); }
.bar.none { background: var(--bar-dim); height: 2px !important; }
.bar-labels { display: flex; justify-content: space-between; margin-top: 4px; color: var(--text-2); font-size: 12px; }

.hn-list { margin-top: 24px; }
.hn-head { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 24px; margin-bottom: 16px; }
.hn-head h2 { margin: 0; }
.hn-head select {
  height: 32px; padding: 0 8px;
  font: inherit; color: var(--text);
  background: var(--chip); border: 0; border-radius: 8px;
}
.mention { display: flex; gap: 16px; padding: 12px 0; }
.mention .avatar { width: 40px; height: 40px; }
.mention-body { min-width: 0; flex: 1; }
.mention-top { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; font-size: 13px; }
.mention-top .who { font-weight: 500; }
.mention-top .when { color: var(--text-2); }
.kind {
  padding: 0 6px; border-radius: 4px;
  font-size: 11px; font-weight: 500; line-height: 18px; text-transform: uppercase; letter-spacing: .3px;
  background: var(--chip); color: var(--text-2);
}
.kind.story { background: var(--accent); color: #fff; }
.mention-title { margin: 4px 0 0; font-weight: 500; overflow-wrap: anywhere; }
.mention-title a:hover, .mention-foot a:hover { text-decoration: underline; }
.mention-text { margin: 4px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.mention-foot { margin-top: 6px; color: var(--text-2); font-size: 12px; display: flex; flex-wrap: wrap; gap: 4px 16px; }
.more-btn { margin: 8px 0 0; }

.side { min-width: 0; }
.side-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 24px; }
.side-card { display: flex; gap: 8px; }
.side-card .thumb { flex: none; width: 168px; border-radius: 8px; }
.side-card .card-title { font-size: 14px; line-height: 20px; margin-bottom: 4px; }
.side-card .meta { font-size: 12px; line-height: 18px; }
.side-why { color: var(--text-2); font-size: 12px; margin: -6px 0 12px; }

/* ---------- about ---------- */
.prose { max-width: 760px; margin: 24px auto; font-size: 15px; line-height: 1.65; }
.prose h1 { font-size: 26px; margin: 0 0 16px; }
.prose h2 { font-size: 18px; margin: 28px 0 8px; }
.prose a { color: var(--accent-text); }
.prose code { background: var(--chip); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 20px 0; }
.stat { padding: 14px 16px; border-radius: 12px; background: var(--chip); }
.stat b { display: block; font-size: 24px; }
.stat span { color: var(--text-2); font-size: 13px; }

/* ---------- responsive ---------- */
@media (max-width: 1312px) {
  body:not(.nav-open) .sidebar { display: none; }
  main { margin-left: 0; }
  body.nav-open .sidebar { display: block; box-shadow: var(--shadow); }
}
@media (max-width: 1100px) {
  .watch { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .topbar { padding: 0 8px; gap: 8px; }
  .logo span { display: none; }
  .search button { width: 48px; }
  main { padding: 56px 16px 32px; }
  .chips { margin: 0 -16px; padding: 12px 16px; }
  .grid { grid-template-columns: 1fr; }
  .watch { margin-top: 0; }
  .watch .player { margin: 0 -16px; border-radius: 0; }
  .side-card .thumb { width: 140px; }
  .actions { margin-left: 0; }
}
