:root {
  --paper: #ffffff;
  --paper-2: #f6f5f2;
  --paper-3: #eeece7;
  --ink: #15161a;
  --ink-2: #4a4c55;
  --ink-3: #8a8d98;
  --line: #e5e3dd;
  --line-2: #d3d0c8;
  --accent: #2743ff;
  --accent-soft: #e9ecff;
  --accent-ink: #1a2fc7;
  --warm: #f4a259;
  --warm-soft: #fff1e2;
  --rose: #e5484d;
  --rose-soft: #fde9ea;
  --shadow: 0 1px 2px rgba(20, 22, 26, 0.04), 0 8px 24px -12px rgba(20, 22, 26, 0.12);
  --shadow-lg: 0 2px 4px rgba(20, 22, 26, 0.05), 0 24px 60px -20px rgba(20, 22, 26, 0.25);
  --radius: 14px;
  --sans: "Karla", ui-sans-serif, system-ui, sans-serif;
  --serif: "Fraunces", Georgia, serif;
  --sidebar: 264px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "ss01", "cv05";
}
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 2px; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
::selection { background: var(--accent-soft); }

#app { display: flex; min-height: 100vh; }

/* ---------- sidebar ---------- */
.sidebar {
  width: var(--sidebar);
  flex: 0 0 var(--sidebar);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 22px 14px 18px 18px;
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, #fbfaf8 0%, #ffffff 40%);
  display: flex;
  flex-direction: column;
  gap: 22px;
  scrollbar-width: thin;
}
.wordmark {
  display: flex; align-items: baseline; gap: 10px; padding: 0 6px;
  font-family: var(--serif); font-size: 26px; font-weight: 500; letter-spacing: -0.01em;
  font-variation-settings: "opsz" 144, "SOFT" 60;
}
.wordmark small { font-family: var(--sans); font-size: 12px; color: var(--ink-3); font-weight: 500; letter-spacing: 0.02em; }
.nav-section { display: flex; flex-direction: column; gap: 2px; }
.nav-title {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3);
  padding: 0 8px 6px;
}
.nav-title button { font-size: 11px; font-weight: 600; color: var(--accent-ink); letter-spacing: 0; text-transform: none; }
.nav-item {
  display: flex; align-items: center; gap: 9px; width: 100%; text-align: left;
  padding: 6px 8px; border-radius: 9px; color: var(--ink-2); font-weight: 500;
  transition: background .12s ease, color .12s ease;
}
.nav-item:hover { background: var(--paper-2); color: var(--ink); }
.nav-item.active { background: var(--ink); color: #fff; }
.nav-item.active .count { color: rgba(255,255,255,.7); }
.nav-item .label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .count { font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.nav-item .avatar { width: 20px; height: 20px; border-radius: 50%; object-fit: cover; background: var(--paper-3); }
.nav-item .dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 8px; }
.sidebar .spacer { flex: 1; }

.sync-box {
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: #fff;
  display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--ink-2);
}
.sync-box .row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sync-box .phase { display: flex; align-items: center; gap: 7px; font-weight: 600; color: var(--ink); }
.sync-box .phase .pulse { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); }
.sync-box .phase.running .pulse { background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
.sync-box .detail { color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sync-box .error { color: var(--rose); white-space: normal; }
.sync-box .actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
@keyframes pulse { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.6); opacity: .5; } }

.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 8px;
  border: 1px solid var(--line-2); background: #fff; font-size: 12.5px; font-weight: 600; color: var(--ink-2);
  transition: all .12s ease; white-space: nowrap;
}
.btn:hover { border-color: var(--ink-3); color: var(--ink); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.primary:hover { background: #000; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.small { padding: 3px 8px; font-size: 12px; }

/* ---------- main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: rgba(255,255,255,.86); backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
  padding: 14px 28px 12px;
  display: flex; flex-direction: column; gap: 10px;
}
.search {
  display: flex; align-items: center; gap: 10px;
  border: 1.5px solid var(--line-2); border-radius: 999px; padding: 8px 10px 8px 16px; background: #fff;
  transition: border-color .12s ease, box-shadow .12s ease;
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.search svg { flex: 0 0 auto; color: var(--ink-3); }
.search input { flex: 1; border: 0; outline: 0; font-size: 16px; background: transparent; }
.search input::placeholder { color: var(--ink-3); }
.seg { display: inline-flex; background: var(--paper-2); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button { padding: 4px 11px; border-radius: 999px; font-size: 12.5px; font-weight: 600; color: var(--ink-3); transition: all .12s ease; }
.seg button.active { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.filters { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px; border-radius: 999px;
  border: 1px solid var(--line-2); background: #fff; font-size: 12.5px; font-weight: 600; color: var(--ink-2);
  transition: all .12s ease;
}
.chip:hover { border-color: var(--ink-3); color: var(--ink); }
.chip.active { background: var(--accent-soft); border-color: transparent; color: var(--accent-ink); }
.chip.clear { border-style: dashed; color: var(--ink-3); }
.filters .grow { flex: 1; }
.filters select {
  border: 1px solid var(--line-2); border-radius: 999px; padding: 4px 28px 4px 11px; background: #fff; font-size: 12.5px; font-weight: 600; color: var(--ink-2);
  appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238a8d98' stroke-width='1.5' fill='none'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 11px center;
}

.heading { padding: 26px 28px 6px; display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.heading h1 { font-family: var(--serif); font-weight: 500; font-size: 30px; margin: 0; letter-spacing: -0.015em; font-variation-settings: "opsz" 144, "SOFT" 30; line-height: 1.15; }
.heading h1 input { font: inherit; border: 0; border-bottom: 1.5px dashed var(--line-2); outline: 0; background: transparent; min-width: 200px; }
.heading .desc { color: var(--ink-2); max-width: 720px; font-size: 15px; }
.heading .meta { color: var(--ink-3); font-size: 13px; font-variant-numeric: tabular-nums; }
.heading .tools { margin-left: auto; display: flex; gap: 6px; }

.feed { padding: 14px 28px 60px; column-gap: 18px; column-width: 350px; column-fill: balance; }
@media (min-width: 1600px) { .feed { column-width: 380px; } }
.empty { padding: 80px 28px; text-align: center; color: var(--ink-3); }
.empty h2 { font-family: var(--serif); font-weight: 500; color: var(--ink-2); font-size: 24px; margin: 0 0 6px; }
.loadmore { display: flex; justify-content: center; padding: 8px 0 40px; }

/* ---------- card ---------- */
.card {
  break-inside: avoid; display: block; margin: 0 0 18px; background: #fff;
  border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 16px 12px;
  box-shadow: var(--shadow); position: relative;
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
  animation: rise .35s ease both;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: var(--line-2); }
.card.pinned { border-color: #f6d9b8; background: linear-gradient(180deg, #fffaf4 0%, #fff 60%); }
.card.archived { opacity: .7; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.card-head .avatar { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; background: var(--paper-3); flex: 0 0 38px; }
.card-head .who { min-width: 0; flex: 1; line-height: 1.25; }
.card-head .name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-head .name button:hover { text-decoration: underline; }
.card-head .handle { color: var(--ink-3); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-head .date { color: var(--ink-3); font-size: 12.5px; white-space: nowrap; }
.card-head .date:hover { color: var(--accent-ink); }
.card-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; line-height: 1.5; }
.card-text.long { max-height: 260px; overflow: hidden; -webkit-mask-image: linear-gradient(180deg, #000 70%, transparent); mask-image: linear-gradient(180deg, #000 70%, transparent); }
.card-text a { color: var(--accent-ink); }
.more { font-size: 13px; font-weight: 600; color: var(--accent-ink); margin-top: 4px; }

.media { display: grid; gap: 4px; margin-top: 10px; border-radius: 10px; overflow: hidden; background: var(--paper-3); }
.media.n2, .media.n4 { grid-template-columns: 1fr 1fr; }
.media.n3 { grid-template-columns: 1fr 1fr; }
.media.n3 > :first-child { grid-row: span 2; }
.media img, .media video { width: 100%; height: 100%; object-fit: cover; display: block; background: var(--paper-3); }
.media.n1 img { max-height: 520px; object-fit: contain; background: var(--paper-2); }
.media.n1 video { max-height: 520px; }
.media .thumb { position: relative; aspect-ratio: 1; }
.media.n1 .thumb { aspect-ratio: auto; }
.media .play { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.18); color: #fff; }
.media .play span { width: 48px; height: 48px; border-radius: 50%; background: rgba(20,22,26,.72); display: grid; place-items: center; backdrop-filter: blur(4px); }

.linkcard { display: flex; gap: 12px; margin-top: 10px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; color: inherit; background: #fff; }
.linkcard:hover { text-decoration: none; border-color: var(--line-2); background: var(--paper-2); }
.linkcard img { width: 96px; height: 96px; object-fit: cover; flex: 0 0 96px; background: var(--paper-3); }
.linkcard.big { flex-direction: column; gap: 0; }
.linkcard.big img { width: 100%; height: auto; aspect-ratio: 1.91; flex: none; }
.linkcard .body { padding: 10px 12px; min-width: 0; }
.linkcard .domain { font-size: 12px; color: var(--ink-3); text-transform: lowercase; }
.linkcard .title { font-weight: 700; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.linkcard .desc { font-size: 13px; color: var(--ink-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-top: 2px; }

.quoted { margin-top: 10px; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--paper-2); font-size: 14px; }
.quoted .q-head { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; font-size: 13px; }
.quoted .q-head img { width: 18px; height: 18px; border-radius: 50%; }
.quoted .q-head b { font-weight: 700; }
.quoted .q-head span { color: var(--ink-3); }
.quoted .q-text { white-space: pre-wrap; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; }
.quoted .media { margin-top: 8px; }

.links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.links a { font-size: 12.5px; padding: 2px 9px; border-radius: 999px; background: var(--paper-2); color: var(--ink-2); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.links a:hover { background: var(--accent-soft); color: var(--accent-ink); text-decoration: none; }

.note { margin-top: 10px; padding: 8px 12px; border-left: 3px solid var(--warm); background: var(--warm-soft); border-radius: 0 8px 8px 0; font-size: 14px; white-space: pre-wrap; }

.card-foot { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.topic {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px;
  background: var(--paper-2); color: var(--ink-2); max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topic:hover { background: var(--accent-soft); color: var(--accent-ink); }
.topic .dot { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 7px; }
.tag { font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 6px; background: #fff; border: 1px solid var(--line-2); color: var(--ink-2); }
.tag:hover { border-color: var(--ink-3); }
.card-foot .stats { margin-left: auto; display: flex; gap: 10px; color: var(--ink-3); font-size: 12px; font-variant-numeric: tabular-nums; }
.card-foot .score { color: var(--accent-ink); font-weight: 700; }

.card-actions {
  position: absolute; top: 10px; right: 10px; display: flex; gap: 2px; padding: 3px; border-radius: 10px;
  background: rgba(255,255,255,.92); border: 1px solid var(--line); box-shadow: var(--shadow);
  opacity: 0; transform: translateY(-4px); transition: all .15s ease;
}
.card:hover .card-actions, .card:focus-within .card-actions { opacity: 1; transform: none; }
.icon-btn { width: 28px; height: 28px; border-radius: 7px; display: grid; place-items: center; color: var(--ink-2); }
.icon-btn:hover { background: var(--paper-2); color: var(--ink); }
.icon-btn.on { color: var(--warm); }
.icon-btn svg { width: 16px; height: 16px; }

/* ---------- drawer ---------- */
.overlay { position: fixed; inset: 0; background: rgba(20,22,26,.28); z-index: 20; animation: fade .18s ease; backdrop-filter: blur(2px); }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); z-index: 21; background: #fff;
  box-shadow: -12px 0 40px -20px rgba(0,0,0,.35); overflow-y: auto; padding: 22px 26px 40px;
  animation: slide .22s cubic-bezier(.2,.8,.2,1);
}
@keyframes slide { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.drawer .close { position: sticky; top: 0; float: right; z-index: 1; }
.drawer .card { box-shadow: none; animation: none; }
.drawer .card:hover { transform: none; }
.drawer .card .card-text.long { max-height: none; mask-image: none; -webkit-mask-image: none; }
.drawer h3 { font-family: var(--serif); font-weight: 500; font-size: 18px; margin: 22px 0 8px; font-variation-settings: "opsz" 48; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field textarea, .field input[type=text] {
  border: 1px solid var(--line-2); border-radius: 10px; padding: 9px 12px; outline: 0; background: #fff; resize: vertical; min-height: 40px;
}
.field textarea:focus, .field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.tagrow { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tagrow .tag button { margin-left: 4px; color: var(--ink-3); }
.tagrow form { display: inline-flex; }
.tagrow input { border: 1px dashed var(--line-2); border-radius: 6px; padding: 3px 8px; font-size: 12.5px; outline: 0; width: 120px; }
.similar { display: flex; flex-direction: column; gap: 8px; }
.similar .sim {
  display: flex; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; text-align: left; width: 100%; align-items: flex-start;
}
.similar .sim:hover { background: var(--paper-2); }
.similar .sim img { width: 26px; height: 26px; border-radius: 50%; flex: none; }
.similar .sim .t { font-size: 13.5px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.similar .sim .s { margin-left: auto; font-size: 12px; color: var(--accent-ink); font-weight: 700; flex: none; }
.drawer select { border: 1px solid var(--line-2); border-radius: 10px; padding: 8px 12px; background: #fff; width: 100%; }

.kbd { font-size: 11px; border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; color: var(--ink-3); background: var(--paper-2); }

@media (max-width: 860px) {
  .sidebar { display: none; }
  .topbar, .heading, .feed { padding-left: 16px; padding-right: 16px; }
}

/* ---------- connect ---------- */
.connect { display: flex; flex-direction: column; gap: 8px; text-align: left; }
.connect h2 { font-family: var(--serif); font-weight: 500; font-size: 26px; margin: 0; color: var(--ink); font-variation-settings: "opsz" 144, "SOFT" 30; }
.connect p { margin: 0; color: var(--ink-2); }
.connect ol { margin: 4px 0 10px; padding-left: 20px; color: var(--ink-2); display: flex; flex-direction: column; gap: 4px; }
.connect ol b { color: var(--ink); font-weight: 600; }
.connect input { border: 1px solid var(--line-2); border-radius: 10px; padding: 9px 12px; outline: 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.connect input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.connect .btn { align-self: flex-start; padding: 8px 16px; font-size: 14px; }
.connect .error { color: var(--rose); font-size: 13px; }
.connect .hint { font-size: 13px; color: var(--ink-3); margin-top: 6px; }
.connect code { font-size: 12px; background: var(--paper-2); padding: 1px 5px; border-radius: 4px; }
.empty .connect { max-width: 560px; margin: 0 auto; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 26px 28px; box-shadow: var(--shadow); }
.connect.compact { gap: 6px; }
.connect.compact input { padding: 6px 9px; font-size: 12px; }
.connect.compact .btn { padding: 5px 10px; font-size: 12.5px; align-self: stretch; justify-content: center; }

/* ---------- hosted gate ---------- */
.gate { min-height: 100vh; width: 100%; display: grid; place-items: center; padding: 24px; background: linear-gradient(180deg, #fbfaf8 0%, #fff 60%); }
.gate .connect { width: min(440px, 100%); background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 28px 30px; box-shadow: var(--shadow-lg); }
.gate-mark { display: flex; align-items: center; gap: 10px; font-family: var(--serif); font-size: 24px; font-weight: 500; margin-bottom: 14px; font-variation-settings: "opsz" 144, "SOFT" 60; }
.connect input[type=email] { font-family: var(--sans); font-size: 15px; }

/* ---------- install panel ---------- */
.panel {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 21;
  width: min(520px, calc(100vw - 32px)); max-height: 86vh; overflow-y: auto;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: 22px 26px 26px; animation: pop .2s cubic-bezier(.2,.8,.2,1);
}
@keyframes pop { from { opacity: 0; transform: translate(-50%, -48%) scale(.98); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }
.panel .close { position: sticky; top: 0; float: right; }
.sync-box .phase.stale { color: var(--rose); }
.sync-box .phase.stale .pulse { background: var(--rose); }
.sync-box .linkish {
  margin-top: 8px; font-size: 12px; font-weight: 600; color: var(--ink-3); text-align: left; padding: 0;
}
.sync-box .linkish:hover { color: var(--accent-ink); text-decoration: underline; }
.connect .btn.primary { align-self: flex-start; }
