:root {
  --bg: #0b0e14;
  --panel: #131822;
  --panel2: #1a2130;
  --border: #232c3d;
  --text: #d7dee9;
  --muted: #7c8aa0;
  --accent: #5b9dff;
  --accent2: #7c5bff;
  --good: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  display: flex;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

/* sidebar */
#sidebar {
  width: 248px;
  flex-shrink: 0;
  background: linear-gradient(180deg, #0d111a, #0b0e14);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  height: 100vh;
  position: sticky;
  top: 0;
}
.brand { display: flex; gap: 11px; align-items: center; margin-bottom: 22px; padding: 0 6px; }
.logo {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: grid; place-items: center; font-size: 18px; color: #fff;
}
.brand-name { font-weight: 700; letter-spacing: .2px; }
.brand-sub { font-size: 11px; color: var(--muted); }
#nav { display: flex; flex-direction: column; gap: 3px; }
.nav-btn {
  text-align: left; background: none; border: none; color: var(--muted);
  padding: 10px 12px; border-radius: 9px; cursor: pointer; font-size: 14px;
  font-family: inherit; display: flex; align-items: center; gap: 7px;
}
.nav-btn:hover { background: var(--panel); color: var(--text); }
.nav-btn.active { background: var(--panel2); color: var(--text); font-weight: 600; }
.nav-btn.nav-off { opacity: .42; }
.nav-btn.nav-off::after { content: " ⌁"; font-size: 10px; }
.badge {
  margin-left: auto; background: var(--accent); color: #04101f; font-size: 11px;
  font-weight: 700; padding: 1px 7px; border-radius: 10px; min-width: 18px; text-align: center;
}
.badge:empty { display: none; }
.side-foot { margin-top: auto; padding: 8px 6px 0; }
.conn { font-size: 11px; color: var(--muted); }
.conn.ok::before { content: "● "; color: var(--good); }
.conn.bad::before { content: "● "; color: var(--bad); }

/* main */
#main { flex: 1; padding: 30px 40px 80px; overflow-y: auto; height: 100vh; max-width: 1100px; }
.view { display: none; animation: fade .2s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }
h1 { font-size: 26px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 12px; }
.lede { color: var(--muted); margin: 0 0 22px; max-width: 760px; }
.muted { color: var(--muted); font-size: 13px; }

/* stat grid */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 26px; }
.stat {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px;
}
.stat .num { font-size: 28px; font-weight: 700; }
.stat .lbl { color: var(--muted); font-size: 12px; margin-top: 2px; }
.stat .bar { height: 4px; background: var(--panel2); border-radius: 3px; margin-top: 10px; overflow: hidden; }
.stat .bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); }

/* digest / what's new */
.trending { margin-bottom: 14px; }
.pill-row { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; margin-bottom: 8px; }
.pill-label { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); width: 92px; }
.pill { background: var(--panel2); border: 1px solid var(--border); border-radius: 20px; padding: 3px 11px; font-size: 12px; }
.pill b { color: var(--accent); margin-left: 3px; }
.pill.p-proj { border-color: var(--accent2); }
.pill.p-proj b { color: var(--accent2); }
.newest-list { display: flex; flex-direction: column; gap: 2px; }
.ni { display: flex; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.ni:first-child { border-top: none; }
.ni .score { margin: 0; height: fit-content; min-width: 32px; text-align: center; }
.ni-body { flex: 1; }
.ni-text { font-size: 13px; margin-bottom: 3px; }
.ni-meta { font-size: 11px; color: var(--muted); }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }

/* tracks / lessons */
.track { margin-bottom: 14px; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--panel); }
.track-head { padding: 14px 18px; cursor: pointer; display: flex; align-items: center; gap: 10px; }
.track-head:hover { background: var(--panel2); }
.track-head .t { font-weight: 600; }
.track-head .b { color: var(--muted); font-size: 13px; font-weight: 400; }
.track-head .prog { margin-left: auto; font-size: 12px; color: var(--muted); }
.track-body { display: none; padding: 4px 18px 14px; }
.track.open .track-body { display: block; }
.module-title { color: var(--accent); font-size: 12px; text-transform: uppercase; letter-spacing: .6px; margin: 14px 0 8px; }
.lesson { border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px; background: var(--panel2); }
.lesson-head { padding: 11px 14px; cursor: pointer; display: flex; align-items: center; gap: 10px; }
.lesson-head:hover { background: #20293a; }
.lesson-head .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border); flex-shrink: 0; }
.dot.read { background: var(--warn); }
.dot.learning { background: var(--accent); }
.dot.mastered { background: var(--good); }
.lesson-head .title { font-weight: 500; }
.lesson-head .summary { color: var(--muted); font-size: 12px; }
.lesson-body { display: none; padding: 4px 16px 16px; }
.lesson.open .lesson-body { display: block; }
.lesson-body h4 { margin: 14px 0 5px; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.lesson-body ul { margin: 4px 0; padding-left: 20px; }
.lesson-body li { margin: 3px 0; }
.mm { background: #10192b; border-left: 3px solid var(--accent2); padding: 10px 14px; border-radius: 6px; margin: 8px 0; font-style: italic; }
.lesson-body p.dd { margin: 6px 0; color: #c3cdda; }
.lesson-body ul.ex li { margin: 5px 0; }
.lesson-body ul.pf li { margin: 5px 0; color: #e8c98a; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { background: var(--bg); border: 1px solid var(--border); border-radius: 20px; padding: 2px 10px; font-size: 11px; color: var(--muted); }
.mark-row { display: flex; gap: 8px; margin-top: 14px; }
.mark-row button { flex: 1; }

/* buttons */
button { font-family: inherit; cursor: pointer; }
.primary, .ghost, .mini {
  border-radius: 8px; border: 1px solid var(--border); background: var(--panel2);
  color: var(--text); padding: 8px 14px; font-size: 13px;
}
.primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); border: none; color: #fff; font-weight: 600; }
.primary:hover, .ghost:hover, .mini:hover { filter: brightness(1.12); }
.mini { padding: 5px 10px; font-size: 12px; }
.mark-row button.sel { outline: 2px solid var(--accent); }

/* review */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 26px; max-width: 640px; }
.card .q { font-size: 19px; margin-bottom: 6px; }
.card .meta { color: var(--muted); font-size: 12px; margin-bottom: 18px; }
.card .a { background: var(--panel2); border-radius: 8px; padding: 14px; margin: 14px 0; }
.grade-row { display: flex; gap: 8px; margin-top: 16px; }
.grade-row button { flex: 1; }
.g0 { border-color: var(--bad) !important; }
.g3 { border-color: var(--warn) !important; }
.g5 { border-color: var(--good) !important; }
.empty { color: var(--muted); padding: 30px; text-align: center; border: 1px dashed var(--border); border-radius: var(--radius); }

/* scan panel */
.scan-top { display: flex; align-items: flex-end; gap: 14px; margin-bottom: 14px; }
.scan-top select { flex: 1; background: var(--bg); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 9px 12px; font-family: inherit; font-size: 14px; }
.fld-label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin-bottom: 5px; }
.status-chip { font-size: 12px; padding: 7px 12px; border-radius: 8px; background: var(--panel2); white-space: nowrap; }
.status-chip.ready { color: var(--good); }
.status-chip.notready { color: var(--warn); }
.scan-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.scan-grid .full { grid-column: 1 / -1; }

/* ingest + corpus */
.ingest .row { display: flex; gap: 10px; margin-bottom: 10px; }
.ingest .row.between { justify-content: space-between; align-items: center; }
input, textarea {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); padding: 9px 12px; font-family: inherit; font-size: 14px; flex: 1; width: 100%;
}
textarea { resize: vertical; }
.post { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.post.archived { opacity: .55; }
.post-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.post-author { font-weight: 600; }
.post-text { margin: 6px 0 10px; }
.score { margin-left: auto; font-size: 12px; padding: 2px 9px; border-radius: 20px; font-weight: 700; }
.score.hi { background: rgba(52,211,153,.15); color: var(--good); }
.score.mid { background: rgba(251,191,36,.15); color: var(--warn); }
.score.lo { background: rgba(124,138,160,.15); color: var(--muted); }
.how { background: var(--panel2); border-radius: 8px; padding: 12px; font-size: 13px; white-space: pre-wrap; }
.post-actions { display: flex; gap: 8px; margin-top: 10px; }

/* upgrades */
.upg { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; display: flex; gap: 14px; align-items: flex-start; }
.upg.applied { border-color: var(--good); }
.upg.dismissed { opacity: .5; }
.upg .body { flex: 1; }
.upg .title { font-weight: 600; margin-bottom: 3px; }
.upg .detail { color: var(--muted); font-size: 13px; }
.upg .src { font-size: 11px; color: var(--muted); margin-top: 6px; }
.effort { font-size: 11px; padding: 2px 8px; border-radius: 20px; background: var(--panel2); color: var(--muted); }
.upg .acts { display: flex; flex-direction: column; gap: 6px; }

/* markdown */
.md { max-width: 780px; }
.md h1 { font-size: 24px; margin-top: 0; }
.md h2 { font-size: 19px; margin: 26px 0 8px; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.md h3 { font-size: 16px; margin: 18px 0 6px; }
.md blockquote { border-left: 3px solid var(--warn); background: var(--panel); margin: 12px 0; padding: 10px 16px; border-radius: 6px; color: var(--muted); }
.md code { background: var(--panel2); padding: 1px 6px; border-radius: 4px; font-size: 13px; }
.md hr { border: none; border-top: 1px solid var(--border); margin: 22px 0; }
.md ul, .md ol { padding-left: 22px; }
.md li { margin: 4px 0; }

/* proposals (review & push) */
.prop { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.prop.confirmed { border-color: var(--good); opacity: .85; }
.prop.dismissed { opacity: .5; }
.prop-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.prop-title { font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.prop-title .score { margin: 0; }
.prop-acts { flex-shrink: 0; display: flex; gap: 6px; align-items: center; }
.prop-tech { color: var(--muted); font-size: 13px; margin: 8px 0; font-style: italic; }
.prop-row { font-size: 12.5px; margin-top: 6px; display: flex; gap: 6px; flex-wrap: wrap; align-items: baseline; }
.prop-row b { color: var(--text); }
.prop-caveat { display: block; color: var(--warn); }
.prop-caveat div { margin-top: 2px; }

/* suggestions */
.sug-row { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-top: 1px solid var(--border); flex-wrap: wrap; }
.sug-row:first-child { border-top: none; }
.sug-proj { font-weight: 600; min-width: 140px; }

/* playbooks */
.pb { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.pb-head { display: flex; justify-content: space-between; gap: 14px; align-items: flex-start; }
.pb-title { font-weight: 600; margin-bottom: 4px; display: flex; align-items: center; gap: 8px; }
.pb-sum { color: var(--muted); font-size: 13px; }
.pb-meta { font-size: 12px; margin-top: 8px; }
.pb-meta b { color: var(--text); }
.pb-caveat { color: var(--warn); }
.pb-install { display: flex; align-items: center; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.pb-install select, .pb-install input { background: var(--bg); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 6px 10px; font-family: inherit; font-size: 13px; }
.pb-body { margin-top: 12px; }

/* briefs */
.brief { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.brief-head { display: flex; justify-content: space-between; gap: 14px; align-items: flex-start; }
.brief-title { font-weight: 600; margin-bottom: 4px; }
.brief-meta { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.brief-acts { display: flex; gap: 6px; flex-shrink: 0; }
.brief-md { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 14px; margin-top: 12px; font-size: 12.5px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; max-height: 460px; overflow-y: auto; font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }

/* config: sources & mapping */
.add-row { display: flex; gap: 10px; align-items: center; }
.add-row select { background: var(--bg); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 9px 12px; font-family: inherit; font-size: 14px; }
.add-row #btn-add-source, .add-row button { flex-shrink: 0; }
.feed-row { display: flex; align-items: center; gap: 12px; padding: 9px 0; border-top: 1px solid var(--border); }
.feed-row:first-child { border-top: none; }
.feed-label { font-weight: 600; min-width: 200px; }
.feed-url { color: var(--muted); font-size: 12px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.map-row { display: flex; gap: 14px; padding: 11px 0; border-top: 1px solid var(--border); align-items: flex-start; }
.map-concept { min-width: 180px; font-weight: 600; padding-top: 4px; }
.map-boxes { display: flex; flex-wrap: wrap; gap: 6px; }
.cbx { display: inline-flex; align-items: center; gap: 5px; background: var(--bg); border: 1px solid var(--border); border-radius: 20px; padding: 4px 11px; font-size: 12px; cursor: pointer; }
.cbx.on { border-color: var(--accent2); background: #161a2e; }
.cbx input { accent-color: var(--accent2); }

/* toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--panel2); border: 1px solid var(--border); padding: 12px 20px; border-radius: 10px;
  opacity: 0; pointer-events: none; transition: all .25s; z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------------- mobile ---------------- */
@media (max-width: 760px) {
  html, body { height: auto; }
  body { flex-direction: column; min-height: 100vh; font-size: 15px; }

  /* sidebar -> sticky top bar with a horizontal scrolling nav */
  #sidebar {
    width: 100%; height: auto; position: sticky; top: 0; z-index: 30;
    padding: calc(10px + env(safe-area-inset-top)) 12px 10px; border-right: none; border-bottom: 1px solid var(--border);
  }
  .brand { margin-bottom: 10px; }
  .logo { width: 30px; height: 30px; font-size: 16px; }
  #nav { flex-direction: row; gap: 5px; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
  #nav::-webkit-scrollbar { height: 0; }
  .nav-btn { white-space: nowrap; padding: 8px 11px; font-size: 13px; flex: 0 0 auto; }
  .side-foot { display: none; }

  /* main fills width, page scrolls naturally */
  #main { height: auto; padding: 18px 14px calc(70px + env(safe-area-inset-bottom)); max-width: 100%; }
  h1 { font-size: 21px; }
  h2 { font-size: 16px; }
  .lede { margin-bottom: 16px; }

  /* collapse every multi-column layout to one column */
  .two-col, .scan-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(auto-fill, minmax(46%, 1fr)); }
  .stat .num { font-size: 22px; }

  /* stack rows that were side-by-side */
  .ingest .row, .ingest .row.between, .add-row, .scan-top { flex-direction: column; align-items: stretch; gap: 8px; }
  .scan-top .status-chip { white-space: normal; }
  .map-row { flex-direction: column; gap: 6px; }
  .map-concept { min-width: 0; }
  .feed-row { flex-wrap: wrap; }
  .feed-label { min-width: 0; }
  .feed-url { flex-basis: 100%; }
  .sug-row .sug-proj { min-width: 0; flex-basis: 100%; }

  /* cards: header + actions stack */
  .pb-head, .brief-head, .prop-head, .post-head { flex-direction: column; align-items: flex-start; gap: 8px; }
  .brief-acts, .prop-acts, .pb-install { flex-wrap: wrap; }
  .score { margin-left: 0; }
  .upg { flex-direction: column; }
  .upg .acts { flex-direction: row; flex-wrap: wrap; }

  /* code/markdown blocks readable, not overflowing */
  .brief-md, .pb-body, .how { font-size: 12px; max-height: 360px; }
  .md { max-width: 100%; }

  /* inputs at 16px so iOS doesn't auto-zoom on focus */
  input, textarea, select, .add-row select, .pb-install select { font-size: 16px; }

  .card { padding: 18px; }
  .card .q { font-size: 17px; }
  .grade-row, .mark-row { flex-wrap: wrap; }
}
