:root {
  --bg: #f7f8fc;
  --surface: #ffffff;
  --surface-hover: #ffffff;
  --border: #e5e7f0;
  --border-strong: #d3d7e5;
  --text: #12131a;
  --muted: #545a6d;
  --faint: #676d82;
  --violet: #7c5cff;
  --blue: #4f8cff;
  --cyan: #22d3ee;
  --grad: linear-gradient(120deg, #7c5cff 0%, #4f8cff 50%, #22d3ee 100%);
  --grad-btn: linear-gradient(120deg, #6a4cf5 0%, #2f6fe8 100%); /* darker so white text stays readable */
  --grad-soft: linear-gradient(120deg, rgba(124, 92, 255, .10), rgba(34, 211, 238, .10));
  --ink-accent: #4b35d6;
  --shadow: 0 1px 2px rgba(20, 22, 40, .04), 0 8px 24px rgba(20, 22, 40, .05);
  --shadow-hover: 0 2px 4px rgba(20, 22, 40, .04), 0 14px 34px rgba(60, 50, 160, .10);
  --mark: rgba(124, 92, 255, .18);
  --radius: 18px;
  --font-display: "Space Grotesk", Inter, system-ui, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.55 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

/* ---------- Background ---------- */
.bg { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.glow { position: absolute; border-radius: 50%; filter: blur(90px); opacity: .45; }
.glow-1 {
  width: 520px; height: 520px; top: -220px; left: 50%; margin-left: -380px;
  background: radial-gradient(circle, #b9a6ff 0%, transparent 70%);
}
.glow-2 {
  width: 460px; height: 460px; top: -160px; left: 50%; margin-left: -40px;
  background: radial-gradient(circle, #8ee9f7 0%, transparent 70%);
  opacity: .5;
}
.grid-lines {
  position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(40,45,90,.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(40,45,90,.06) 1px, transparent 1px);
  background-size: 48px 48px;
  -webkit-mask-image: radial-gradient(ellipse 80% 55% at 50% 0%, #000 30%, transparent 75%);
          mask-image: radial-gradient(ellipse 80% 55% at 50% 0%, #000 30%, transparent 75%);
}

/* ---------- Top bar ---------- */
.topbar {
  max-width: 1080px; margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) 16px 0;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.brand {
  display: inline-flex; align-items: center; gap: 10px; min-width: 0;
  color: var(--text); text-decoration: none;
  font-family: var(--font-display); font-weight: 600; font-size: 15px;
}
.brand-mark {
  display: grid; place-items: center; flex: none;
  width: 30px; height: 30px; border-radius: 9px;
  background: var(--grad); color: #fff; font-size: 15px; font-weight: 700;
  box-shadow: 0 4px 14px rgba(124, 92, 255, .3);
}
.brand-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.follow {
  flex: none;
  padding: 7px 14px; border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text); text-decoration: none;
  font-size: 13px; font-weight: 500;
  transition: background .15s ease, border-color .15s ease;
}
.follow:hover { border-color: #b9bfd3; box-shadow: var(--shadow); }

/* ---------- Layout ---------- */
.wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: 36px 16px calc(40px + env(safe-area-inset-bottom));
}

/* ---------- Hero ---------- */
.hero { text-align: center; max-width: 640px; margin: 0 auto 32px; }

.avatar-ring {
  width: 84px; height: 84px; margin: 0 auto 18px;
  padding: 2px; border-radius: 50%;
  background: var(--grad);
  box-shadow: 0 10px 30px rgba(124, 92, 255, .22);
}
.avatar {
  width: 100%; height: 100%; border-radius: 50%;
  display: grid; place-items: center;
  background: #ffffff center / cover no-repeat;
  font-family: var(--font-display); font-size: 30px; font-weight: 700;
  color: var(--ink-accent);
}

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px 5px 10px; border-radius: 999px;
  border: 1px solid rgba(124, 92, 255, .25);
  background: rgba(255, 255, 255, .8);
  color: var(--ink-accent);
  font-size: 12px; font-weight: 500; letter-spacing: .02em;
}
.pill svg { width: 14px; height: 14px; fill: #7c5cff; }

h1 {
  margin: 14px 0 0;
  font-family: var(--font-display);
  font-size: clamp(32px, 8vw, 52px);
  font-weight: 700; line-height: 1.05;
  letter-spacing: -0.03em;
  background: linear-gradient(180deg, #12131a 35%, #3d4363 100%);
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
}

.lead {
  margin: 14px auto 0;
  max-width: 480px;
  color: var(--muted);
  font-size: 15.5px;
}

/* ---------- Controls ---------- */
.controls { max-width: 720px; margin: 0 auto; }

.search {
  position: sticky; top: 10px; z-index: 5;
  display: flex; align-items: center;
  border-radius: 16px;
  background: rgba(255, 255, 255, .88);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border: 1px solid var(--border-strong);
  transition: border-color .2s ease, box-shadow .2s ease;
}
.search:focus-within {
  border-color: rgba(124, 92, 255, .7);
  box-shadow: 0 0 0 4px rgba(124, 92, 255, .12), 0 10px 30px rgba(79, 140, 255, .12);
}
.search-icon {
  width: 20px; height: 20px; margin-left: 16px; flex: none;
  fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round;
}
.search input {
  flex: 1; min-width: 0;
  padding: 16px 12px;
  border: 0; outline: 0; background: transparent;
  color: var(--text);
  font: inherit; font-size: 16px; /* 16px stops iOS zoom on focus */
}
.search input::placeholder { color: var(--faint); }
.search input::-webkit-search-cancel-button { display: none; }
.clear {
  display: grid; place-items: center;
  width: 36px; height: 36px; margin-right: 8px;
  border: 0; border-radius: 10px; background: transparent; cursor: pointer;
}
.clear[hidden] { display: none; }
.clear:hover { background: var(--surface-hover); }
.clear svg { width: 18px; height: 18px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }

.filters[hidden] { display: none; }
.filters {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-top: 14px;
}
.chips {
  display: flex; gap: 6px;
  overflow-x: auto; scrollbar-width: none;
  margin: 0 -16px; padding: 2px 16px;
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 16px, #000 calc(100% - 24px), transparent 100%);
          mask-image: linear-gradient(90deg, transparent 0, #000 16px, #000 calc(100% - 24px), transparent 100%);
}
.chips::-webkit-scrollbar { display: none; }

.chip, .sort {
  flex: none;
  padding: 7px 13px; border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font: inherit; font-size: 13px; font-weight: 500;
  white-space: nowrap; cursor: pointer;
  transition: color .15s ease, background .15s ease, border-color .15s ease;
}
.chip:hover, .sort:hover { color: var(--text); border-color: var(--border-strong); }
.chip[aria-pressed="true"] {
  color: var(--ink-accent);
  border-color: rgba(124, 92, 255, .55);
  background: var(--grad-soft);
}
.sort { display: inline-flex; align-items: center; gap: 6px; }
.sort svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: transform .2s ease; }
.sort.is-oldest svg { transform: scaleY(-1); }

.count {
  max-width: 720px; margin: 22px auto 12px;
  color: var(--faint);
  font-size: 13px; letter-spacing: .02em;
}

/* ---------- Cards ---------- */
.list { display: grid; gap: 14px; max-width: 720px; margin: 0 auto; }

.card {
  position: relative;
  display: flex; flex-direction: column;
  padding: 22px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  scroll-margin-top: 100px;
  box-shadow: var(--shadow);
  transition: border-color .2s ease, box-shadow .2s ease, transform .2s ease;
}
.card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-hover); }
.card.is-match {
  border-color: transparent;
  background:
    linear-gradient(#fff, #fff) padding-box,
    var(--grad) border-box;
  box-shadow: 0 12px 34px rgba(124, 92, 255, .16);
}

.card-top {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-bottom: 14px;
}
.tags { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }

.word {
  display: inline-flex; align-items: center;
  padding: 5px 11px; border-radius: 8px;
  background: var(--grad-soft);
  border: 1px solid rgba(124, 92, 255, .22);
  font-family: var(--font-display);
  font-size: 13px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--ink-accent);
}
.new {
  padding: 3px 8px; border-radius: 6px;
  background: rgba(8, 145, 178, .1);
  color: #0e7490;
  font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
}

.share {
  display: grid; place-items: center; flex: none;
  width: 34px; height: 34px; border-radius: 10px;
  border: 1px solid var(--border); background: transparent;
  color: var(--muted); cursor: pointer;
  transition: color .15s ease, border-color .15s ease;
}
.share:hover { color: var(--text); border-color: var(--border-strong); }
.share svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.card h2 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 20px; font-weight: 600; line-height: 1.3;
  letter-spacing: -0.01em;
}
.card p { margin: 0; color: var(--muted); font-size: 15px; white-space: pre-line; }

.meta {
  display: flex; align-items: center; gap: 6px;
  margin-top: 14px;
  color: var(--faint); font-size: 13px;
}
.meta svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

mark { background: var(--mark); color: inherit; border-radius: 4px; padding: 0 2px; }

.actions {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
  margin-top: auto; padding-top: 18px;
}
.actions.single { grid-template-columns: 1fr; }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 14px; border-radius: 12px;
  font-size: 14.5px; font-weight: 600; text-decoration: none; white-space: nowrap;
  transition: transform .12s ease, box-shadow .2s ease, background .15s ease, border-color .15s ease;
}
.btn:active { transform: scale(.98); }
.btn svg { width: 17px; height: 17px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.btn-primary {
  background: var(--grad-btn); color: #fff;
  box-shadow: 0 6px 24px rgba(79, 140, 255, .25);
}
.btn-primary:hover { box-shadow: 0 8px 32px rgba(124, 92, 255, .4); }

.btn-ghost {
  background: #fff;
  border: 1px solid var(--border-strong);
  color: var(--text);
}
.btn-ghost:hover { background: #f3f4fa; border-color: #b9bfd3; }

.btn-missing {
  border: 1px dashed var(--border-strong);
  color: var(--faint); pointer-events: none;
}

/* ---------- Empty ---------- */
.empty { text-align: center; padding: 48px 16px; }
.empty-icon {
  width: 52px; height: 52px; margin: 0 auto 14px;
  display: grid; place-items: center; border-radius: 16px;
  background: var(--grad-soft); border: 1px solid var(--border);
}
.empty-icon svg { width: 22px; height: 22px; fill: none; stroke: #6a4cf5; stroke-width: 2; stroke-linecap: round; }
.empty-title { margin: 0 0 4px; font-family: var(--font-display); font-weight: 600; font-size: 18px; }
.empty-text { margin: 0; color: var(--muted); font-size: 15px; }
.link {
  padding: 0; border: 0; background: none;
  color: var(--ink-accent); font: inherit; font-weight: 500;
  text-decoration: underline; text-underline-offset: 3px; cursor: pointer;
}

/* ---------- Footer ---------- */
.foot {
  margin-top: 56px; padding-top: 24px;
  border-top: 1px solid var(--border);
  text-align: center;
}
.foot a {
  font-family: var(--font-display); font-weight: 600; font-size: 15px;
  text-decoration: none;
  background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.foot p { margin: 6px 0 0; color: var(--faint); font-size: 13px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  padding: 10px 18px; border-radius: 999px;
  background: rgba(18, 19, 26, .92);
  border: 1px solid var(--border-strong);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  color: #fff; font-size: 14px; font-weight: 500;
  opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Responsive ---------- */
@media (max-width: 420px) {
  .card { padding: 18px; }
  .actions { grid-template-columns: 1fr; }
}

@media (max-width: 559px) {
  .filters { flex-direction: column; align-items: stretch; }
  .sort { align-self: flex-start; }
}

@media (min-width: 760px) {
  .wrap { padding-top: 56px; }
  .topbar { padding-left: 24px; padding-right: 24px; }
  .chips { margin: 0; padding: 2px 0; -webkit-mask-image: none; mask-image: none; }
  .list { grid-template-columns: repeat(2, 1fr); max-width: 1000px; }
  .count { max-width: 1000px; }
  .card { padding: 24px; }
  .card:hover { transform: translateY(-2px); }
}

@media (min-width: 1100px) {
  .glow-1 { width: 700px; height: 700px; top: -320px; margin-left: -560px; }
  .glow-2 { width: 620px; height: 620px; top: -260px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
