:root {
  --bg: #141519;
  --surface: #1d1f24;
  --surface-2: #24262d;
  --ink: #edeef2;
  --dim: #9ba1ad;
  --faint: #6b7280;
  --line: #2b2e36;
  --line-lit: #3a3e48;
  --red: #e5493d;
  --red-top: #f15d4f;
  --red-soft: rgba(229, 73, 61, 0.14);
  --green: #5dbb84;
  --green-soft: rgba(93, 187, 132, 0.14);
  --amber: #d9a44e;
  --amber-soft: rgba(217, 164, 78, 0.14);
  --blue: #7ea7d8;
  --blue-soft: rgba(126, 167, 216, 0.14);
  --radius: 12px;
}
* { box-sizing: border-box; }
html { color-scheme: dark; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
::selection { background: var(--red-soft); }

.wrap { max-width: 1120px; margin: 0 auto; padding: 1.5rem 1.4rem 4.5rem; }

/* ---------- Top bar ---------- */
.topbar { display: flex; align-items: center; gap: 1rem; padding: .2rem 0 1.6rem; }
.brand {
  display: flex; align-items: center; gap: .6rem;
  font-weight: 700; font-size: 1.05rem; letter-spacing: -.01em; text-decoration: none;
}
.dot {
  width: .62rem; height: .62rem; border-radius: 50%; background: var(--red);
  box-shadow: 0 0 0 3px var(--red-soft), 0 0 12px rgba(229,73,61,.5);
}
.topbar .grow { flex: 1; }
.search {
  background: var(--surface); border: 1px solid var(--line); color: var(--ink);
  border-radius: 9px; padding: .45rem .8rem; font: inherit; font-size: .88rem;
  width: 220px; transition: border-color .15s ease, width .2s ease;
}
.search:focus { outline: none; border-color: var(--line-lit); width: 260px; }
.search::placeholder { color: var(--faint); }
.count { color: var(--faint); font-size: .85rem; font-variant-numeric: tabular-nums; }

/* ---------- Buttons ---------- */
button, .btn {
  background: var(--surface-2); color: var(--ink); border: 1px solid var(--line);
  border-radius: 9px; padding: .45rem .9rem; font: inherit; font-size: .87rem;
  cursor: pointer; text-decoration: none; display: inline-flex; align-items: center;
  gap: .4rem; transition: border-color .12s ease, background .12s ease, transform .06s ease;
}
button:hover, .btn:hover { border-color: var(--line-lit); background: #2a2d35; }
button:active, .btn:active { transform: translateY(1px); }
.btn-red {
  background: linear-gradient(180deg, var(--red-top), var(--red));
  border-color: transparent; color: #fff; font-weight: 600;
  box-shadow: 0 2px 10px rgba(229,73,61,.3);
}
.btn-red:hover { background: linear-gradient(180deg, #f4695c, var(--red-top)); border-color: transparent; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--dim); }
.btn-ghost:hover { background: var(--surface-2); border-color: transparent; color: var(--ink); }

/* ---------- Library grid ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 1.1rem; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  overflow: hidden; display: flex; flex-direction: column;
  transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.card:hover {
  transform: translateY(-2px); border-color: var(--line-lit);
  box-shadow: 0 10px 28px rgba(0,0,0,.35);
}
.card .thumb {
  aspect-ratio: 16/9; background: var(--surface-2) center/cover no-repeat;
  display: flex; align-items: flex-start; justify-content: flex-start;
  position: relative; text-decoration: none; padding: .55rem;
}
.card .thumb::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(180deg, transparent 55%, rgba(0,0,0,.35));
  opacity: 0; transition: opacity .15s ease;
}
.card:hover .thumb::after { opacity: 1; }
.card .thumb .dur {
  position: absolute; right: .55rem; bottom: .55rem; z-index: 1;
  background: rgba(0,0,0,.75); backdrop-filter: blur(4px);
  color: #fff; font-size: .73rem; font-weight: 500;
  padding: .12rem .45rem; border-radius: 6px; font-variant-numeric: tabular-nums;
}
.card .meta { padding: .75rem .9rem .85rem; display: flex; flex-direction: column; gap: .35rem; }
.card .title {
  font-weight: 600; font-size: .94rem; text-decoration: none;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.card .title:hover { color: var(--red-top); }
.card .sub { color: var(--faint); font-size: .78rem; display: flex; gap: .55rem; flex-wrap: wrap; align-items: center; }
.card .actions {
  display: flex; gap: .35rem; margin-top: .45rem;
  opacity: .55; transition: opacity .15s ease;
}
.card:hover .actions { opacity: 1; }
.card .actions button { padding: .28rem .6rem; font-size: .77rem; border-radius: 7px; }

.pill {
  font-size: .68rem; font-weight: 600; letter-spacing: .02em;
  padding: .12rem .5rem; border-radius: 99px; background: var(--surface-2); color: var(--dim);
}
.pill.public { background: var(--green-soft); color: var(--green); }
.pill.password { background: var(--amber-soft); color: var(--amber); }
.pill.private { background: var(--red-soft); color: var(--red-top); }
.pill.processing, .pill.uploading { background: var(--blue-soft); color: var(--blue); }
.pill.failed { background: var(--red-soft); color: var(--red-top); }

.empty { color: var(--faint); text-align: center; padding: 5rem 1rem; }
.empty .dot { display: inline-block; margin-bottom: 1rem; }
.empty p { margin: .25rem 0; }

/* ---------- Watch page ---------- */
body.watchpage {
  background:
    radial-gradient(55% 38% at 50% -5%, rgba(229, 73, 61, 0.09), transparent 70%),
    var(--bg);
  min-height: 100vh;
}
.watch { max-width: 1240px; margin: 0 auto; }
.watch .topbar { justify-content: center; padding-bottom: 1.2rem; }

.watchgrid {
  display: grid; grid-template-columns: minmax(0, 1fr) 340px;
  gap: 1.15rem; align-items: start;
}
.watchmain { min-width: 0; }

.sidebar {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  display: flex; flex-direction: column;
  position: sticky; top: 1rem;
  height: calc(100vh - 8rem); min-height: 420px; max-height: 760px;
  overflow: hidden;
}
.tabs {
  display: flex; gap: 3px; padding: 8px; border-bottom: 1px solid var(--line);
}
.tabs button {
  flex: 1; background: transparent; border: none; color: var(--dim);
  font-size: .86rem; font-weight: 600; padding: .45rem .5rem; border-radius: 8px;
}
.tabs button:hover { background: var(--surface-2); color: var(--ink); }
.tabs button.active { background: var(--red); color: #fff; }
.pane {
  display: flex; flex-direction: column; flex: 1; min-height: 0;
  padding: .9rem;
}
.pane[hidden] { display: none; }
.reactrow { display: flex; justify-content: center; padding-bottom: .5rem; }

@media (max-width: 940px) {
  .watchgrid { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; max-height: none; min-height: 0; }
  .comments { max-height: 340px; }
  .transcript { max-height: 340px; }
}
.player-shell {
  border-radius: 16px; overflow: hidden; background: #000;
  border: 1px solid var(--line);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  max-height: 72vh; margin: 0 auto;
  aspect-ratio: 16/9;
}
.player { width: 100%; height: 100%; aspect-ratio: 16/9; background: #000; display: block; object-fit: contain; }
.processing-msg { display: flex; align-items: center; justify-content: center; color: var(--faint); }

.infobar {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: .95rem 1.15rem; margin-top: 1.15rem;
}
.infobar h1 { font-size: 1.05rem; letter-spacing: -.01em; margin: 0 0 .2rem; }
.infobar .sub { color: var(--faint); font-size: .82rem; display: flex; gap: .45rem; align-items: center; flex-wrap: wrap; }
.infobar .actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }

.watch .desc {
  color: var(--dim); margin-top: .9rem; white-space: pre-wrap; font-size: .92rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: .9rem 1.15rem;
}
.powered { text-align: center; color: var(--faint); font-size: .8rem; margin-top: 2rem; }
.powered span { color: var(--dim); font-weight: 600; }

/* ---------- Watch page panels (analytics / transcript / comments) ---------- */
.panelcard {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 1rem 1.15rem; margin-top: 1rem;
}
.panelhead { display: flex; align-items: center; gap: .8rem; }
.panelhead h2 { font-size: .95rem; margin: 0; letter-spacing: -.01em; }
.panelhead .btn-ghost { margin-left: auto; padding: .25rem .6rem; font-size: .8rem; }
.panelsub { color: var(--faint); font-size: .82rem; }

.histo {
  display: flex; align-items: flex-end; gap: 1px; height: 64px; margin-top: .9rem;
  background: rgba(255,255,255,.03); border-radius: 8px; padding: 4px; overflow: hidden;
}
.histo span {
  flex: 1; min-height: 2px; border-radius: 2px 2px 0 0;
  background: linear-gradient(180deg, var(--red-top), var(--red));
  opacity: .85;
}

.transcript { flex: 1; min-height: 0; overflow-y: auto; }
.cue {
  display: flex; gap: .7rem; padding: .3rem .5rem; border-radius: 8px;
  font-size: .88rem; color: var(--dim); cursor: pointer; line-height: 1.45;
}
.cue span { color: var(--faint); font-size: .78rem; min-width: 2.6rem; padding-top: .1rem; font-variant-numeric: tabular-nums; }
.cue:hover { background: var(--surface-2); color: var(--ink); }
.cue.active { background: var(--red-soft); color: var(--ink); }
.cue.active span { color: var(--red-top); }

.reactbar { margin-left: auto; display: flex; gap: 2px; }
.emoji {
  background: transparent; border: none; padding: .15rem .3rem; font-size: 1rem;
  border-radius: 7px; cursor: pointer; transition: transform .1s ease, background .1s ease;
}
.emoji:hover { background: var(--surface-2); transform: scale(1.2); border: none; }
.reactions { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .6rem; }
.reactions:empty { display: none; }
.rchip {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 99px;
  padding: .12rem .55rem; font-size: .82rem; cursor: pointer;
}
.rchip:hover { border-color: var(--line-lit); }

.comments {
  flex: 1; min-height: 0; overflow-y: auto;
  margin-top: .5rem; display: flex; flex-direction: column; gap: .7rem;
}
.firstcomment { text-align: center; padding: 2.5rem 0; }
.comment { border-left: 2px solid var(--line-lit); padding-left: .75rem; }
.chead { display: flex; align-items: center; gap: .5rem; font-size: .84rem; }
.tchip {
  background: var(--red-soft); color: var(--red-top); border: none; border-radius: 6px;
  padding: .05rem .4rem; font-size: .75rem; font-weight: 600; cursor: pointer;
}
.cdel { background: none; border: none; color: var(--faint); cursor: pointer; padding: 0 .2rem; margin-left: auto; font-size: .8rem; }
.cdel:hover { color: var(--red-top); background: none; border: none; }
.cbody { color: var(--dim); font-size: .9rem; margin-top: .15rem; white-space: pre-wrap; }

.commentform {
  margin-top: .7rem; padding-top: .7rem; border-top: 1px solid var(--line);
  display: flex; flex-direction: column; gap: .5rem;
}
.commentform input[type=text] {
  background: var(--bg); color: var(--ink); border: 1px solid var(--line);
  border-radius: 9px; padding: .5rem .7rem; font: inherit; font-size: .88rem;
}
.commentform input:focus { outline: none; border-color: var(--line-lit); }
.commentrow { display: flex; gap: .5rem; align-items: center; justify-content: flex-end; }
.attime { display: flex; gap: .3rem; align-items: center; color: var(--faint); font-size: .78rem; white-space: nowrap; }
.attime input { accent-color: var(--red); }

.speed {
  display: inline-flex; gap: 3px; padding: 3px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
}
.speed button {
  border: none; background: transparent; color: var(--dim);
  padding: .3rem .65rem; border-radius: 7px; font-size: .82rem; font-weight: 600;
}
.speed button:hover { background: var(--surface-2); color: var(--ink); }
.speed button.active { background: var(--red); color: #fff; }

/* ---------- Auth / unlock ---------- */
.authbox {
  max-width: 380px; margin: 16vh auto 0;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; padding: 1.8rem;
  box-shadow: 0 18px 50px rgba(0,0,0,.4);
}
.authbox h1 {
  font-size: 1.1rem; margin: 0 0 1.1rem;
  display: flex; align-items: center; gap: .6rem; letter-spacing: -.01em;
}
.authbox input[type=password], .authbox input[type=text] {
  width: 100%; background: var(--bg); color: var(--ink); border: 1px solid var(--line);
  border-radius: 9px; padding: .6rem .75rem; font: inherit; margin-bottom: .9rem;
  transition: border-color .15s ease;
}
.authbox input:focus { outline: none; border-color: var(--line-lit); }
.authbox button { width: 100%; justify-content: center; padding: .55rem; }
.authbox .err { color: var(--red-top); font-size: .85rem; margin-bottom: .9rem; }

/* ---------- Dialog / toast ---------- */
dialog {
  background: var(--surface); color: var(--ink); border: 1px solid var(--line);
  border-radius: 14px; padding: 1.4rem; max-width: 440px; width: 92vw;
  box-shadow: 0 24px 60px rgba(0,0,0,.5);
}
dialog::backdrop { background: rgba(0,0,0,.6); backdrop-filter: blur(2px); }
dialog h2 { margin: 0 0 .4rem; font-size: 1rem; }
dialog label { display: block; font-size: .82rem; color: var(--dim); margin: .7rem 0 .25rem; }
dialog input[type=text], dialog input[type=password], dialog select, dialog textarea {
  width: 100%; background: var(--bg); color: var(--ink); border: 1px solid var(--line);
  border-radius: 9px; padding: .5rem .65rem; font: inherit; transition: border-color .15s ease;
}
dialog input:focus, dialog select:focus { outline: none; border-color: var(--line-lit); }
dialog .check { display: flex; align-items: center; gap: .5rem; margin-top: .9rem; font-size: .88rem; color: var(--dim); }
dialog .check input { accent-color: var(--red); }
dialog .row { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1.2rem; }

.toast {
  position: fixed; bottom: 1.4rem; left: 50%; transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--line-lit); color: var(--ink);
  padding: .6rem 1.1rem; border-radius: 10px; font-size: .88rem; display: none;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
}

@media (max-width: 560px) {
  .wrap { padding: 1rem .9rem 3rem; }
  .search { width: 140px; }
  .search:focus { width: 160px; }
}
