:root {
  --bg: #0e0e11;
  --panel: #17171b;
  --panel-2: #1e1e24;
  --line: #26262d;
  --line-soft: #1f1f25;
  --ink: #ececef;
  --ink-dim: #b6b6be;
  --muted: #82828d;
  --accent: #ff6b3d;
  --star: #f2b23c;
  --danger: #e5484d;
  --topbar-h: 54px;
  --radius: 10px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
::selection { background: rgba(255, 107, 61, 0.32); }
code, kbd { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.88em; }

/* ---------- topbar ---------- */

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 0 14px; height: var(--topbar-h); flex: none;
  background: rgba(14, 14, 17, 0.86);
  backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--line-soft);
  padding-top: env(safe-area-inset-top);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; letter-spacing: -0.015em; flex: none; }
.mark {
  width: 15px; height: 15px; border-radius: 4px; background: var(--accent);
  box-shadow: inset 0 0 0 2.5px var(--bg), 0 0 0 1.5px var(--accent);
}
.search { position: relative; flex: 1; max-width: 460px; margin: 0; }
.search svg {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  width: 14px; height: 14px; fill: none; stroke: var(--muted); stroke-width: 1.5; stroke-linecap: round;
  pointer-events: none;
}
.search input {
  width: 100%; height: 32px; padding: 0 10px 0 30px;
  font: inherit; color: var(--ink);
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; outline: none;
}
.search input::placeholder { color: #66666f; }
.search input:focus { border-color: #3a3a44; background: var(--panel-2); }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; }

.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; flex: none; }
.chip-link {
  display: grid; place-items: center; min-width: 32px; height: 32px; padding: 0 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  color: var(--muted); font-size: 12.5px;
}
.chip-link:hover { color: var(--ink); border-color: #3a3a44; }
.chip-link.on { color: var(--star); border-color: rgba(242,178,60,0.4); background: rgba(242,178,60,0.1); }

/* ---------- tag bar ---------- */

.tagbar {
  flex: none; display: flex; align-items: center; gap: 6px;
  padding: 10px 20px; overflow-x: auto;
  border-bottom: 1px solid var(--line-soft);
  scrollbar-width: none;
}
.tagbar::-webkit-scrollbar { display: none; }
.tag-chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; white-space: nowrap;
  background: var(--panel); border: 1px solid var(--line); color: var(--ink-dim); font-size: 12px;
}
.tag-chip:hover { border-color: #3a3a44; color: var(--ink); }
.tag-chip.on { background: rgba(255,107,61,0.15); border-color: rgba(255,107,61,0.45); color: #ffa484; }
.tag-chip .n { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.tag-chip.on .n { color: rgba(255,164,132,0.7); }
.tagbar .clear { flex: none; color: var(--accent); font-size: 12px; padding: 4px 6px; }

/* ---------- library ---------- */

.library { flex: 1; padding: 20px 20px 60px; }
.group { margin-bottom: 34px; }
.group-head { display: flex; align-items: baseline; gap: 10px; margin: 0 2px 12px; }
.group-title {
  font-size: 14.5px; font-weight: 600; letter-spacing: -0.01em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60%;
}
.group-title:hover { color: var(--accent); }
.group-channel { font-size: 12.5px; color: var(--muted); }
.group-count { margin-left: auto; font-size: 11.5px; color: #5f5f69; font-variant-numeric: tabular-nums; white-space: nowrap; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(228px, 1fr)); gap: 12px; }

.card {
  position: relative; display: block; border-radius: var(--radius); overflow: hidden;
  background: var(--panel); border: 1px solid var(--line-soft);
  aspect-ratio: 16 / 9;
  transition: transform 120ms ease, border-color 120ms ease;
}
.card:hover { transform: translateY(-2px); border-color: #3a3a44; }
.card img { width: 100%; height: 100%; object-fit: cover; display: block; background: #08080a; }
.card .time {
  position: absolute; left: 7px; bottom: 7px; padding: 2px 6px; border-radius: 5px;
  background: rgba(6,6,8,0.82); color: #fff; font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.card .star { position: absolute; right: 7px; top: 7px; color: var(--star); font-size: 13px; text-shadow: 0 1px 3px rgba(0,0,0,0.6); }
.card .tags {
  position: absolute; right: 7px; bottom: 7px; z-index: 2;
  max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding: 2px 7px; border-radius: 5px;
  background: rgba(255,107,61,0.9); color: #fff; font-size: 10.5px; font-weight: 600;
}
.card .cap {
  position: absolute; inset: auto 0 0 0; padding: 20px 96px 7px 52px;
  background: linear-gradient(to top, rgba(6,6,8,0.85), transparent);
  font-size: 11px; color: #d8d8de;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  opacity: 0; transition: opacity 120ms ease;
}
.card:hover .cap { opacity: 1; }

/* ---------- empty ---------- */

.empty { max-width: 480px; margin: 12vh auto 0; text-align: center; color: var(--muted); }
.empty h2 { margin: 0 0 8px; font-size: 18px; color: var(--ink); font-weight: 600; letter-spacing: -0.01em; }
.empty p { margin: 0 0 14px; line-height: 1.65; }
.empty ol { text-align: left; margin: 0 auto; padding-left: 20px; font-size: 13px; line-height: 2; }
.empty code, .empty kbd {
  background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; color: var(--ink-dim);
}
.empty a { color: var(--accent); }

/* ---------- status bar ---------- */

.statusbar {
  position: sticky; bottom: 0; flex: none;
  display: flex; align-items: center; gap: 6px; padding: 0 12px; height: 28px;
  background: var(--panel); border-top: 1px solid var(--line-soft);
  font-size: 11.5px; color: var(--ink-dim); font-variant-numeric: tabular-nums;
  padding-bottom: env(safe-area-inset-bottom);
}
.statusbar .sep { color: #3c3c45; }
.statusbar .muted { color: var(--muted); }
.statusbar .grow { flex: 1; }
.statusbar a.muted:hover { color: var(--accent); }

/* ---------- detail ---------- */

.detail { flex: 1; display: grid; grid-template-columns: 1fr 340px; min-height: 0; }
.stage { margin: 0; display: grid; place-items: center; padding: 28px; min-width: 0; background: #08080a; }
.stage img { max-width: 100%; max-height: calc(100vh - var(--topbar-h) - 56px); object-fit: contain; border-radius: 6px; }
.side {
  border-left: 1px solid var(--line); background: var(--panel);
  padding: 24px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px;
}
.lb-title { margin: 0; font-size: 16px; font-weight: 620; line-height: 1.35; letter-spacing: -0.01em; }
.lb-channel { display: inline-block; margin-top: 3px; font-size: 12.5px; color: var(--muted); }
.lb-channel:hover { color: var(--accent); }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.actions .wide { grid-column: 1 / -1; }
.btn, .cta {
  display: grid; place-items: center; padding: 9px 10px; border-radius: 8px;
  font-size: 12.5px; text-align: center; border: 1px solid var(--line); background: var(--panel-2); color: var(--ink-dim);
}
.btn:hover { color: var(--ink); border-color: #3a3a44; }
.cta { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.cta:hover { background: #ff7d54; }
.btn.danger:hover { color: var(--danger); border-color: rgba(229,72,77,0.45); }
.btn.star.on { color: var(--star); border-color: rgba(242,178,60,0.4); }
.actions form { display: contents; }

.tags-edit { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.lb-tag {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 5px 3px 9px; border-radius: 999px;
  background: rgba(255,107,61,0.14); border: 1px solid rgba(255,107,61,0.34);
  color: #ffa484; font-size: 12px;
}
.lb-tag button { border: 0; background: none; padding: 0; color: inherit; opacity: 0.6; font-size: 13px; line-height: 1; }
.lb-tag button:hover { opacity: 1; }
.tag-input {
  flex: 1; min-width: 120px; padding: 5px 9px; font: inherit; font-size: 12px;
  background: var(--panel-2); color: var(--ink);
  border: 1px dashed var(--line); border-radius: 999px; outline: none;
}
.tag-input:focus { border-style: solid; border-color: #3a3a44; }
.tag-input::placeholder { color: #5f5f69; }

.quote {
  margin: 0; padding: 10px 12px; border-left: 2px solid var(--accent);
  background: rgba(255,107,61,0.06); border-radius: 0 6px 6px 0;
  font-size: 13px; line-height: 1.55; color: var(--ink-dim); font-style: italic;
}
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: 12.5px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; color: var(--ink-dim); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.back { color: var(--muted); font-size: 12.5px; margin-top: auto; padding-top: 8px; }
.back:hover { color: var(--accent); }

/* ---------- auth ---------- */

.auth { flex: 1; display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 26px 24px;
}
.auth-card .brand { font-size: 15px; }
.auth-lede { margin: -4px 0 0; color: var(--muted); font-size: 13px; }
.auth-error {
  margin: 0; padding: 8px 10px; border-radius: 8px; font-size: 12.5px;
  background: rgba(229,72,77,0.12); border: 1px solid rgba(229,72,77,0.3); color: #ffb0b2;
}
.auth-card label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.auth-card input {
  padding: 9px 11px; font: inherit; font-size: 14px; color: var(--ink);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; outline: none;
}
.auth-card input:focus { border-color: #3a3a44; }
.auth-card .cta { padding: 10px; }

/* ---------- settings ---------- */

.settings-page { flex: 1; width: 100%; max-width: 620px; margin: 0 auto; padding: 28px 20px 60px; display: flex; flex-direction: column; gap: 22px; }
.settings-page h1 { margin: 0; font-size: 22px; letter-spacing: -0.02em; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.panel h2 { margin: 0; font-size: 14px; font-weight: 600; }
.panel .muted { color: var(--muted); font-size: 12.5px; margin: 0; line-height: 1.6; }
.panel .cta, .panel .btn { justify-self: start; }
.panel > .cta { max-width: 180px; }
.new-token { display: flex; flex-direction: column; gap: 6px; padding: 12px; border-radius: 8px; background: rgba(255,107,61,0.08); border: 1px solid rgba(255,107,61,0.3); }
.new-token code { display: block; overflow-wrap: anywhere; font-size: 12px; color: #ffa484; }
.token-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.token-list li { display: flex; align-items: center; gap: 10px; padding: 9px 11px; background: var(--panel-2); border-radius: 8px; font-size: 12.5px; }
.token-name { font-weight: 600; }
.token-list .muted { margin-left: auto; }
.settings-page .actions { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }

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

.toast {
  position: fixed; left: 50%; bottom: 46px; transform: translateX(-50%); z-index: 60;
  padding: 9px 15px; border-radius: 8px;
  background: var(--panel-2); border: 1px solid var(--line);
  box-shadow: 0 10px 30px rgba(0,0,0,0.5); font-size: 12.5px;
}

@media (max-width: 800px) {
  .detail { grid-template-columns: 1fr; }
  .side { border-left: 0; border-top: 1px solid var(--line); }
  .stage { padding: 14px; }
  .stage img { max-height: 56vh; }
  .chip-link.desktop-only { display: none; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
  .library { padding: 14px 14px 50px; }
  .tagbar { padding: 9px 14px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

.password-form { display: flex; flex-direction: column; gap: 10px; }
.password-form label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.password-form input {
  padding: 8px 10px; font: inherit; font-size: 13px; color: var(--ink);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; outline: none;
}
.password-form input:focus { border-color: #3a3a44; }
.password-form .cta { max-width: 180px; }
.auth-note {
  margin: 0; padding: 8px 10px; border-radius: 8px; font-size: 12.5px;
  background: rgba(76,195,138,0.12); border: 1px solid rgba(76,195,138,0.3); color: #8fe0bb;
}
