:root {
  --bg: #f7f7f9;
  --surface: #ffffff;
  --surface-2: #fafafb;
  --border: #e6e6ea;
  --text: #17181c;
  --text-muted: #6f7078;
  --text-faint: #a0a1a8;
  --accent: #3b57e8;
  --accent-weak: #eef0fd;
  --positive: #1c8a4a;
  --positive-weak: #e9f7ef;
  --negative: #c53434;
  --negative-weak: #fbebeb;
  --warning: #a3690a;
  --warning-weak: #fbf2e2;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow: 0 1px 2px rgba(15, 15, 20, 0.04), 0 6px 20px rgba(15, 15, 20, 0.045);
  --font: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101114;
    --surface: #17181d;
    --surface-2: #1c1d23;
    --border: #2a2b32;
    --text: #eceef2;
    --text-muted: #94959e;
    --text-faint: #63646c;
    --accent: #7d90f5;
    --accent-weak: #1c2140;
    --positive: #4fce8a;
    --positive-weak: #142a1e;
    --negative: #ea6b6b;
    --negative-weak: #301717;
    --warning: #dcab52;
    --warning-weak: #2f2510;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}
:root[data-theme="dark"] {
  --bg: #101114;
  --surface: #17181d;
  --surface-2: #1c1d23;
  --border: #2a2b32;
  --text: #eceef2;
  --text-muted: #94959e;
  --text-faint: #63646c;
  --accent: #7d90f5;
  --accent-weak: #1c2140;
  --positive: #4fce8a;
  --positive-weak: #142a1e;
  --negative: #ea6b6b;
  --negative-weak: #301717;
  --warning: #dcab52;
  --warning-weak: #2f2510;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html { color-scheme: light dark; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.shell {
  max-width: 980px;
  margin: 0 auto;
  padding: 28px 24px 100px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Header */
.header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.header .brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.header .brand .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--positive);
  box-shadow: 0 0 0 3px var(--positive-weak);
}
.header h1 {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
}
.header .updated {
  font-size: 12px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

/* Profile summary */
.profile-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 24px;
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
}
.profile-card .avatar-wrap {
  width: 96px; height: 96px; border-radius: var(--radius-md);
  background: var(--surface-2); flex-shrink: 0; overflow: hidden;
  border: 1px solid var(--border);
}
.profile-card img.avatar { width: 100%; height: 100%; object-fit: cover; display: block; }
.profile-card .main { flex: 1; min-width: 240px; display: flex; flex-direction: column; gap: 10px; }
.namerow { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.namerow .display-name { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.namerow .username { color: var(--text-muted); font-size: 14px; }
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 999px;
  line-height: 1;
}
.tag.accent { background: var(--accent-weak); color: var(--accent); }
.tag.negative { background: var(--negative-weak); color: var(--negative); }
.bio { color: var(--text-muted); font-size: 13px; white-space: pre-wrap; max-width: 56ch; }
.meta-line { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-faint); }
.meta-line a { color: var(--accent); text-decoration: none; font-weight: 500; }
.meta-line a:hover { text-decoration: underline; }

.stat-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
  border-top: 1px solid var(--border);
  margin-top: 4px;
  padding-top: 16px;
  gap: 4px;
  width: 100%;
}
.stat-strip .stat { text-align: left; }
.stat-strip .stat .num { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-strip .stat .label { font-size: 11.5px; color: var(--text-faint); margin-top: 1px; text-transform: uppercase; letter-spacing: 0.03em; }

/* Tabs */
.tabs {
  display: flex;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
  width: fit-content;
}
.tab-btn {
  appearance: none; border: none; background: transparent; cursor: pointer;
  font: inherit; font-size: 12.5px; font-weight: 600; color: var(--text-muted);
  padding: 6px 14px; border-radius: 6px; transition: background .12s, color .12s;
}
.tab-btn.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.tab-btn .n { color: var(--text-faint); font-weight: 500; margin-left: 4px; }
.tab-btn.active .n { color: var(--text-muted); }

.panel { display: none; }
.panel.active { display: block; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* Friends grid */
.friends-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1px;
  background: var(--border);
}
.friend-tile {
  background: var(--surface);
  padding: 16px 12px;
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px;
  cursor: pointer; border: none; font: inherit; color: inherit;
  transition: background .12s;
}
.friend-tile:hover { background: var(--surface-2); }
.friend-tile img { width: 56px; height: 56px; border-radius: 10px; background: var(--surface-2); object-fit: cover; }
.friend-tile .fdname { font-weight: 600; font-size: 12.5px; }
.friend-tile .funame { font-size: 11px; color: var(--text-faint); }
.friend-tile .fsince { font-size: 10px; color: var(--text-faint); margin-top: 2px; }

/* Groups */
.list-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 18px; border-bottom: 1px solid var(--border); font-size: 13px;
}
.list-row:last-child { border-bottom: none; }
.list-row a { color: inherit; text-decoration: none; font-weight: 600; }
.list-row a:hover { color: var(--accent); }
.list-row .sub { color: var(--text-faint); font-size: 11.5px; margin-top: 1px; }
.list-row .right { color: var(--text-faint); font-size: 11.5px; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Timeline */
.timeline { display: flex; flex-direction: column; }
.event {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px 18px; border-bottom: 1px solid var(--border); font-size: 13px;
}
.event:last-child { border-bottom: none; }
.event .icon {
  width: 24px; height: 24px; border-radius: 7px; flex-shrink: 0; margin-top: 1px;
  display: flex; align-items: center; justify-content: center;
}
.event .icon svg { width: 13px; height: 13px; }
.event .icon.added { background: var(--positive-weak); color: var(--positive); }
.event .icon.removed { background: var(--negative-weak); color: var(--negative); }
.event .icon.info { background: var(--accent-weak); color: var(--accent); }
.event .icon.warn { background: var(--warning-weak); color: var(--warning); }
.event .body { flex: 1; }
.event .time { font-size: 11px; color: var(--text-faint); margin-top: 2px; font-variant-numeric: tabular-nums; }

.empty { color: var(--text-faint); font-size: 13px; padding: 32px 18px; text-align: center; }

.footnote { font-size: 11.5px; color: var(--text-faint); text-align: center; }

/* Friend detail modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(10, 10, 14, 0.4);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  z-index: 50;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  max-width: 420px; width: 100%;
  padding: 24px;
  position: relative;
}
.modal .close-btn {
  position: absolute; top: 14px; right: 14px;
  width: 28px; height: 28px; border-radius: 8px; border: none;
  background: var(--surface-2); color: var(--text-muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.modal .close-btn:hover { background: var(--border); }
.modal-avatar { width: 76px; height: 76px; border-radius: var(--radius-md); object-fit: cover; background: var(--surface-2); border: 1px solid var(--border); }
.modal .display-name { font-size: 17px; font-weight: 700; margin-top: 14px; }
.modal .username { color: var(--text-muted); font-size: 13px; }
.modal .bio { margin-top: 10px; }
.modal .meta-line { margin-top: 10px; }
.modal .cta {
  margin-top: 18px; display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent); color: white; text-decoration: none;
  font-size: 12.5px; font-weight: 600; padding: 8px 14px; border-radius: var(--radius-sm);
}
.modal .cta:hover { opacity: 0.9; }

@media (max-width: 560px) {
  .shell { padding: 20px 14px 80px; }
  .profile-card { padding: 18px; }
}
