:root {
  --bg: #111827;
  --card: #1f2937;
  --card-border: #374151;
  --text: #ffffff;
  --muted: #9ca3af;
  --accent: #6366f1;
  --accent-soft: #818cf8;
  --border: #374151;
  --radius: 12px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
}

a { color: var(--accent-soft); text-decoration: none; }
a:hover { text-decoration: underline; }

nav {
  background: var(--card);
  border-bottom: 1px solid var(--card-border);
  padding: 0 24px;
  height: 56px;
  display: flex;
  gap: 26px;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 10;
}
nav .logo {
  background: #fff; color: #111827; font-weight: 800; font-size: 18px;
  width: 38px; height: 34px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
}
nav .logo:hover { text-decoration: none; }
nav a { color: var(--muted); font-weight: 600; white-space: nowrap; flex-shrink: 0; }
nav a.active { color: #fff; font-weight: 700; }
nav a:hover { color: #fff; text-decoration: none; }
nav input {
  margin-left: auto;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text);
  width: 230px;
}
nav input:focus { outline: 1px solid var(--accent); }

main { max-width: 720px; margin: 24px auto; padding: 0 14px; }
main.wide { max-width: 1100px; }

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}

.post { border-radius: var(--radius); }
.post .head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.post .head a { font-weight: 600; }
.post .head .dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; flex-shrink: 0; }
.post .head .time { color: var(--muted); font-size: 13px; margin-left: auto; font-style: italic; }
.post .content { line-height: 1.55; overflow-wrap: break-word; word-break: break-word; max-width: 100%; overflow-x: auto; }
.post .content img { max-width: 100%; max-height: 420px; width: auto; border-radius: 10px; cursor: zoom-in; }
.post .content pre, .post .content code { max-width: 100%; white-space: pre-wrap; }
.post .content iframe, .post .content video { max-width: 100%; }

/* images embedded in comments, walls, and revision history must never render at full size.
   .profile-avatar is excluded or its sized-down rule below loses the specificity fight. */
.card img:not(.avatar):not(.profile-avatar):not(.mitem img) {
  max-width: 100%;
  max-height: 420px;
  width: auto;
  height: auto;
  border-radius: 10px;
  cursor: zoom-in;
}
.post .stats {
  color: var(--muted); font-size: 14px; margin-top: 12px; display: flex; gap: 20px; align-items: center;
}
.post .stats svg { width: 16px; height: 16px; vertical-align: -3px; margin-right: 4px; }

.badge {
  font-size: 11px; padding: 2px 9px; border-radius: 999px;
  background: #7f1d1d; color: #fecaca; font-weight: 700;
}
.badge.blue { background: #4f46e5; color: #fff; }
.badge.green { background: #15803d; color: #dcfce7; }
.badge.gold { background: #b45309; color: #fef3c7; }
.badge.red { background: #991b1b; color: #fee2e2; }
.badge.purple { background: #7e22ce; color: #f3e8ff; }
.deleted-note { color: #f87171; font-size: 12px; margin-top: 8px; }

.avatar { width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0; background: var(--border); }

.user-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.user-row:last-child { border-bottom: none; }

button {
  background: var(--accent); color: #fff; border: none;
  padding: 9px 18px; border-radius: 10px; cursor: pointer; font-weight: 600;
}
button:hover { background: var(--accent-soft); }
button.secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.profile-grid { display: grid; grid-template-columns: 340px 1fr; gap: 16px; align-items: start; }
.sticky-col {
  position: sticky; top: 70px;
  /* the column is usually taller than the viewport — let it scroll inside
     its pinned box instead of getting cut off / overlapping the content */
  max-height: calc(100vh - 86px);
  overflow-y: auto;
  scrollbar-width: thin;
}
.follow-tabs { display: flex; gap: 8px; margin-bottom: 8px; }

/* profile header (replaces inline styles so it can scale on mobile) */
.profile-banner { height: 160px; background: #1a1d24 center/cover no-repeat; }
.profile-head { display: flex; align-items: flex-end; gap: 14px; margin-top: -34px; }
.profile-head .profile-avatar {
  width: 76px; height: 76px; border-radius: 50%;
  border: 4px solid var(--card); background: var(--border); flex-shrink: 0;
}
.profile-head h2 { overflow-wrap: anywhere; }

/* tablets: sidebar stacks above content and must stop sticking, otherwise it
   overlaps the cards below it while scrolling */
@media (max-width: 900px) {
  .profile-grid { grid-template-columns: 1fr; }
  .sticky-col { position: static; }
}
@media (max-width: 700px) {
  body { font-size: 14px; }
  nav { padding: 0 10px; gap: 14px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  nav::-webkit-scrollbar { display: none; }
  nav input { display: none; }
  main { margin: 12px auto; padding: 0 8px; }
  .grid2, .live-grid { grid-template-columns: 1fr; }
  .profile-banner { height: 110px; }
  .profile-head { margin-top: -26px; gap: 10px; }
  .profile-head .profile-avatar { width: 58px; height: 58px; border-width: 3px; }
  .statbox { height: auto; }
  #live-feed { height: 300px; }
  button { padding: 8px 14px; }
}
.follow-tabs button { padding: 5px 12px; font-size: 13px; background: var(--bg); color: var(--muted); border: 1px solid var(--border); }
.follow-tabs button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
table { width: 100%; border-collapse: collapse; }
td, th { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--border); font-size: 14px; }

h1 { font-size: 22px; margin: 8px 0 16px; }
h2 { font-size: 17px; margin: 0 0 12px; }
.muted { color: var(--muted); font-size: 13px; }

canvas { display: block; }

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: #1f2937; border-radius: 3px; }
::-webkit-scrollbar-track { background: #4b5563; }

/* live page */
.live-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
#live-feed { height: 460px; overflow-y: auto; }

/* tools dropdown in the shared nav */
.tools { position: relative; flex-shrink: 0; }
.tools-btn {
  background: none; color: var(--muted); font-weight: 600;
  padding: 0; border: none; font-size: 15px; white-space: nowrap;
}
.tools-btn:hover, .tools-btn.on { color: #fff; background: none; }
.tools-menu {
  display: none; position: absolute; top: calc(100% + 10px); left: -12px;
  background: var(--card); border: 1px solid var(--card-border);
  border-radius: 10px; padding: 6px; min-width: 120px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  flex-direction: column; gap: 2px; z-index: 30;
}
.tools.open .tools-menu { display: flex; }
.tools-menu a { padding: 7px 12px; border-radius: 6px; }
.tools-menu a:hover { background: var(--bg); text-decoration: none; }
.tools-menu a.active { color: #fff; }

/* personalised feed page */
.feed-layout { display: grid; grid-template-columns: 1fr 320px; gap: 16px; align-items: start; }
.feed-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 16px; }
.feed-head h2 { margin: 0; }
.feed-actions { display: flex; gap: 8px; margin-left: auto; }
.feed-actions button { padding: 7px 14px; font-size: 14px; }
#feed-status { width: 100%; }
.feed-stats { position: sticky; top: 70px; max-height: calc(100vh - 86px); overflow-y: auto; scrollbar-width: thin; }
.feed-stats h3 { font-size: 13px; color: var(--muted); margin: 16px 0 6px; text-transform: uppercase; letter-spacing: 0.04em; }
.srows { display: grid; gap: 4px; }
.srow { display: flex; justify-content: space-between; font-size: 14px; padding: 4px 0; border-bottom: 1px solid var(--border); }
.sbar { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; align-items: center; font-size: 14px; padding: 3px 0; }
.sbar .fill { grid-column: 1 / -1; height: 5px; border-radius: 3px; display: block; }
.sbar .muted { font-size: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  background: var(--bg); border: 1px solid var(--border); border-radius: 999px;
  padding: 3px 10px; font-size: 13px;
}
.chip i { font-style: normal; color: var(--muted); margin-left: 4px; }
.feed-vote { display: inline-flex; gap: 4px; margin-left: 8px; }
.act {
  background: none; border: 1px solid var(--border); color: var(--muted);
  width: 28px; height: 28px; padding: 4px; border-radius: 8px; cursor: pointer;
}
.act:hover { background: var(--bg); color: var(--text); }
.act svg { width: 100%; height: 100%; display: block; }
.act.up.on { color: #22c55e; border-color: #22c55e; }
.act.down.on { color: #ef4444; border-color: #ef4444; }
.act.mute.on { color: #f59e0b; border-color: #f59e0b; }
.why { margin-top: 8px; }

/* vote panel: intensity + dislike target picker */
.vote-panel {
  margin-top: 8px; padding: 8px 10px; border: 1px dashed var(--border);
  border-radius: 10px; display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center;
}
.vrow { display: flex; gap: 6px; align-items: center; }
.vp {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 500;
}
.vp:hover { border-color: var(--accent); }

/* correction buttons in the stats pane: "model is right" / "model is wrong" */
.corr { display: inline-flex; gap: 3px; margin-left: 6px; }
.cb {
  background: none; border: 1px solid var(--border); color: var(--muted);
  width: 20px; height: 20px; padding: 3px; border-radius: 6px; cursor: pointer; flex-shrink: 0;
}
.cb svg { width: 100%; height: 100%; display: block; }
.cb:hover { color: var(--text); border-color: var(--accent); }
.cb.ok.on { color: #22c55e; border-color: #22c55e; }
.cb.no.on { color: #ef4444; border-color: #ef4444; }

.trait {
  display: flex; align-items: center; gap: 8px; font-size: 14px;
  padding: 5px 0; border-bottom: 1px solid var(--border);
}
.trait span { flex: 1; }
.trait b.pos { color: #22c55e; }
.trait b.neg { color: #ef4444; }
.chip .corr { margin-left: 2px; }

@media (max-width: 800px) {
  .feed-layout { grid-template-columns: 1fr; }
  .feed-stats { position: static; max-height: none; }
}
.evt { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.evt .kind {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  padding: 2px 8px; border-radius: 999px; flex-shrink: 0; width: 74px; text-align: center;
}
.evt .tgt { font-family: ui-monospace, monospace; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.evt .when { margin-left: auto; color: var(--muted); font-size: 12px; flex-shrink: 0; }
.evt.err .tgt { color: #f87171; }
.statline { display: flex; gap: 18px; flex-wrap: wrap; margin-bottom: 4px; }
.statbox { background: var(--bg); border: 1px solid var(--border); border-radius: 12px; padding: 10px 16px; height: 64px; }
.statbox .n { font-size: 22px; font-weight: 700; line-height: 26px; }
.statbox .l { color: var(--muted); font-size: 12px; }
#backlog { height: 150px; }
#donut { height: 180px; }
#throughput { height: 240px; }

#atlas-canvas { width: 100%; height: 640px; background: #0b0e14; border-radius: var(--radius); cursor: grab; }
#atlas-tip {
  position: fixed; pointer-events: none; background: #1a202c; color: #fff;
  padding: 6px 10px; border-radius: 6px; font-size: 12px; display: none; z-index: 50;
}
