:root {
  --bg: #0d0820;
  --panel: rgba(255, 255, 255, .045);
  --border: rgba(255, 255, 255, .09);
  --text: #f4f1ff;
  --muted: #b6acd6;
  --accent: #a78bfa;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { overflow-x: clip; }
body {
  margin: 0; min-height: 100vh; color: var(--text); background: var(--bg);
  font-family: "Inter", "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  line-height: 1.5; -webkit-font-smoothing: antialiased; overflow-x: clip;
}
[hidden] { display: none !important; }
.glow { position: fixed; border-radius: 50%; filter: blur(110px); pointer-events: none; z-index: -1; }
.glow.a { width: 640px; height: 640px; background: #6d28d9; opacity: .32; top: -260px; right: -180px; }
.glow.b { width: 520px; height: 520px; background: #be185d; opacity: .16; bottom: -220px; left: -200px; }

/* Header */
.top {
  position: sticky; top: 0; z-index: 30; height: 68px; padding: 0 max(20px, env(safe-area-inset-right)) 0 max(20px, env(safe-area-inset-left));
  display: flex; align-items: center; justify-content: space-between;
  backdrop-filter: blur(16px) saturate(140%); background: rgba(13, 8, 32, .7); border-bottom: 1px solid rgba(255,255,255,.06);
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; font-weight: 700; font-size: 1.15rem; }
.brand img { height: 34px; width: auto; }
.top-actions { display: flex; align-items: center; gap: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 18px; border-radius: 999px;
  font: inherit; font-weight: 600; font-size: .95rem; cursor: pointer; border: 1px solid transparent; color: #fff;
  transition: transform .15s, box-shadow .2s, background .2s;
}
.btn:hover { transform: translateY(-1px); }
.btn svg { width: 20px; height: 20px; fill: currentColor; }
.btn.primary { background: linear-gradient(135deg, #7c3aed, #c026d3); box-shadow: 0 10px 28px -10px rgba(168, 85, 247, .8); }
.btn.ghost { background: rgba(255,255,255,.06); border-color: rgba(255,255,255,.14); }
.btn.ghost:hover { background: rgba(255,255,255,.1); }
.btn:disabled { opacity: .6; cursor: default; transform: none; }

/* Signed out */
.welcome { max-width: 460px; margin: 8vh auto 0; padding: 0 24px; text-align: center; animation: rise .7s cubic-bezier(.2,.8,.2,1); }
.welcome img { margin: 0 auto 8px; width: 200px; height: auto; filter: drop-shadow(0 30px 40px rgba(30,10,80,.7)); animation: float 6s ease-in-out infinite; }
.welcome h1 { font-size: 2.1rem; letter-spacing: -.02em; margin: 0 0 10px; }
.welcome p { color: var(--muted); margin: 0 0 28px; }
.welcome .cb-signin-buttons { max-width: 320px; margin: 0 auto; }
@keyframes float { 50% { transform: translateY(-12px); } }
@keyframes rise { from { opacity: 0; transform: translateY(20px); } }

/* Layout */
.shell { display: grid; grid-template-columns: 240px 1fr; gap: 28px; width: min(1440px, 100%); margin: 0 auto; padding: 24px 24px 80px; }
.folders { position: sticky; top: 92px; align-self: start; display: grid; gap: 2px; max-height: calc(100vh - 110px); overflow: auto; padding-right: 4px; }
.folders .group { margin: 16px 12px 6px; font-size: .74rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: #8c81b3; }
.folder {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; border: 0; background: none;
  font: inherit; font-size: .95rem; color: var(--muted); text-align: left; cursor: pointer; transition: background .15s, color .15s;
}
.folder:hover { background: rgba(255,255,255,.05); color: var(--text); }
.folder.on { background: rgba(167,139,250,.16); color: var(--text); font-weight: 600; }
.folder .dot { width: 12px; height: 12px; border-radius: 4px; flex: none; background: var(--c, #6d4aff); box-shadow: 0 0 12px -2px var(--c, #6d4aff); }
.folder svg { width: 18px; height: 18px; fill: currentColor; flex: none; }
.folder span.name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.view-head { display: flex; align-items: baseline; gap: 14px; margin: 4px 0 20px; }
.view-head h1 { margin: 0; font-size: 1.7rem; letter-spacing: -.02em; }
#view-note { color: var(--muted); font-size: .92rem; }

/* Cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 20px; }
.card {
  position: relative; display: flex; flex-direction: column; min-width: 0; border-radius: 20px; overflow: hidden;
  background: var(--panel); border: 1px solid var(--border);
  transition: transform .25s cubic-bezier(.2,.8,.2,1), box-shadow .25s, border-color .25s;
}
.card:hover { transform: translateY(-4px); border-color: rgba(167,139,250,.35); box-shadow: 0 24px 50px -24px rgba(124, 58, 237, .65); }
.card.enter { animation: card-in .7s cubic-bezier(.2,.8,.2,1) both; animation-delay: var(--delay, 0ms); }
.card.leave { animation: card-out .35s ease-in forwards; pointer-events: none; }
@keyframes card-in {
  0% { opacity: 0; transform: translateY(28px) scale(.94); filter: blur(8px); }
  60% { filter: blur(0); }
  100% { opacity: 1; transform: none; filter: none; }
}
@keyframes card-out { to { opacity: 0; transform: scale(.9) translateY(10px); filter: blur(4px); } }

.thumb { position: relative; display: block; aspect-ratio: 16 / 10; overflow: hidden; background: #1b1238; }
.thumb > img { width: 100%; height: 100%; object-fit: cover; opacity: 0; transform: scale(1.06); transition: opacity .5s, transform .8s cubic-bezier(.2,.8,.2,1); }
.thumb > img.loaded { opacity: 1; transform: none; }
.card:hover .thumb > img.loaded { transform: scale(1.04); }
.site-tile {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: radial-gradient(circle at 30% 20%, hsl(var(--h) 70% 45% / .55), transparent 60%), linear-gradient(135deg, hsl(var(--h) 55% 22%), hsl(calc(var(--h) + 40) 50% 14%));
}
.site-tile .logo {
  width: 72px; height: 72px; border-radius: 20px; display: grid; place-items: center; overflow: hidden;
  background: rgba(255,255,255,.92); box-shadow: 0 16px 34px -12px rgba(0,0,0,.6);
  font-size: 2rem; font-weight: 800; color: hsl(var(--h) 60% 35%);
}
.site-tile .logo img { width: 70%; height: 70%; object-fit: contain; }
.badge {
  position: absolute; left: 10px; top: 10px; padding: 3px 10px; border-radius: 999px; font-size: .74rem; font-weight: 700; color: #fff;
  background: var(--c); box-shadow: 0 4px 12px rgba(0,0,0,.35);
}
.kind { position: absolute; right: 10px; bottom: 10px; padding: 3px 10px; border-radius: 999px; font-size: .74rem; font-weight: 600; background: rgba(13,8,32,.72); backdrop-filter: blur(8px); }
.fav-mark { position: absolute; right: 10px; top: 10px; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: rgba(13,8,32,.6); }
.fav-mark svg { width: 16px; height: 16px; fill: #fbbf24; }

.body { display: flex; flex-direction: column; gap: 6px; padding: 14px 16px 8px; flex: 1; min-width: 0; }
.body h3 { margin: 0; font-size: 1rem; line-height: 1.35; font-weight: 650; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.body h3 a { color: inherit; text-decoration: none; }
.body h3 a:hover { text-decoration: underline; text-decoration-color: rgba(167,139,250,.6); }
.meta { display: flex; align-items: center; gap: 6px; font-size: .82rem; color: var(--muted); min-width: 0; }
.meta img { width: 16px; height: 16px; border-radius: 4px; flex: none; }
.meta .site { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; border-radius: 999px; background: rgba(255,255,255,.06); font-size: .76rem; color: var(--muted); max-width: 100%; }
.chip i { width: 8px; height: 8px; border-radius: 3px; background: var(--c); flex: none; }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note { margin: 2px 0 0; font-size: .86rem; color: #d5cdf0; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-line; overflow-wrap: anywhere; }

.tools { display: flex; justify-content: flex-end; gap: 2px; padding: 0 8px 8px; }
.tool {
  width: 36px; height: 36px; border-radius: 10px; border: 0; background: none; color: var(--muted); cursor: pointer;
  display: grid; place-items: center; transition: background .15s, color .15s, transform .15s;
}
.tool:hover { background: rgba(255,255,255,.08); color: var(--text); }
.tool:active { transform: scale(.9); }
.tool svg { width: 20px; height: 20px; fill: currentColor; }
.tool.on { color: #fbbf24; }
.tool.danger:hover { color: #fca5a5; background: rgba(239,68,68,.14); }

/* Loading placeholders */
.skeleton { pointer-events: none; }
.skeleton .thumb, .skeleton .line {
  background: linear-gradient(100deg, rgba(255,255,255,.04) 30%, rgba(255,255,255,.11) 50%, rgba(255,255,255,.04) 70%);
  background-size: 300% 100%; animation: shimmer 1.4s linear infinite;
}
.skeleton .line { height: 12px; border-radius: 6px; }
.skeleton .line.w1 { width: 85%; }
.skeleton .line.w2 { width: 55%; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

.empty { text-align: center; padding: 60px 20px; color: var(--muted); animation: rise .5s; }
.empty strong { display: block; font-size: 1.2rem; color: var(--text); margin-bottom: 6px; }
#sentinel { height: 1px; }
.end { grid-column: 1 / -1; text-align: center; color: #8c81b3; font-size: .85rem; padding: 18px 0 0; }

/* Add / edit dialog */
.editor {
  width: min(520px, calc(100% - 32px)); padding: 0; border: 1px solid rgba(255,255,255,.12); border-radius: 24px;
  color: var(--text); background: #1a1136; box-shadow: 0 40px 80px -20px rgba(0,0,0,.8);
}
.editor[open] { animation: pop .3s cubic-bezier(.2,.8,.2,1); }
.editor::backdrop { background: rgba(5, 2, 15, .6); backdrop-filter: blur(4px); }
@keyframes pop { from { opacity: 0; transform: translateY(16px) scale(.97); } }
.editor form { display: grid; gap: 14px; padding: 24px; }
.editor h2 { margin: 0 0 4px; font-size: 1.3rem; }
.editor label { display: grid; gap: 6px; font-size: .85rem; font-weight: 600; color: var(--muted); }
.editor input:not([type=checkbox]), .editor select, .editor textarea {
  width: 100%; padding: 11px 14px; border-radius: 12px; border: 1px solid rgba(255,255,255,.14);
  background: rgba(255,255,255,.05); color: var(--text); font: inherit; font-size: .98rem; font-weight: 400;
}
.editor input:focus, .editor select, .editor textarea:focus { outline: none; }
.editor input:focus, .editor select:focus, .editor textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(167,139,250,.25); }
.editor input[readonly] { opacity: .7; }
.editor select option { background: #1a1136; }
.editor textarea { resize: vertical; min-height: 70px; }
.editor .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.editor .check { display: flex; align-items: center; gap: 10px; font-size: .95rem; color: var(--text); font-weight: 500; }
.editor .check input { width: 18px; height: 18px; accent-color: #8b5cf6; }
.editor .hint { margin: 0; font-size: .82rem; color: #8c81b3; }
.editor .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; gap: 12px; padding: 12px 14px 80px; }
  .folders {
    position: sticky; top: 68px; z-index: 20; display: flex; gap: 6px; overflow-x: auto; max-height: none;
    margin: 0 -14px; padding: 10px 14px; background: rgba(13, 8, 32, .85); backdrop-filter: blur(14px); scrollbar-width: none;
  }
  .folders::-webkit-scrollbar { display: none; }
  .folders .group { display: none; }
  .folder { flex: none; padding: 8px 14px; border-radius: 999px; background: rgba(255,255,255,.05); }
  .grid { grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 12px; }
  .body { padding: 10px 12px 4px; }
  .body h3 { font-size: .92rem; }
  .note { display: none; }
  .tool { width: 32px; height: 32px; }
}
@media (max-width: 560px) {
  .brand span, .top .brand { font-size: 0; gap: 0; }
  #add span { display: none; }
  #add { padding: 10px; }
  .editor .row { grid-template-columns: 1fr; }
  .view-head h1 { font-size: 1.35rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .thumb > img { opacity: 1; transform: none; }
}
