/* dashboard.carsonwuai.com
   ─────────────────────────────────────────────────────────────────────────────
   Design system lifted from carsonwuai.com/researchlibrary so the two read as
   one property. Tokens come from the portfolio's tailwind theme:

     site background   #ececec   (bg-site)
     signature blue    #2b2bee   (text-blob / bg-blob)
     deep blue         #1b1b9e
     card              #ffffff
     ink               neutral-900
     muted             neutral-400 / neutral-500
     radius            0.625rem
     type              lowercase, 14px base, bold for emphasis

   Layout follows LibraryLayout.tsx: sticky translucent header with backdrop
   blur, a sticky sidebar on desktop, and on mobile a drawer over a dark fade.
   The one deliberate departure is that the menu button sits on the RIGHT
   rather than the left.

   The portfolio applies `zoom: 0.75` to desktop body. That is not copied here:
   lightweight-charts measures its container in real pixels, and a zoomed
   ancestor makes it mis-size on every resize. Sizes below are set directly at
   the scale that zoom produces instead. */

:root {
  color-scheme: light;

  --site: #ececec;
  --card: #ffffff;
  --blob: #2b2bee;
  --blob-deep: #1b1b9e;

  --ink: #18181b;          /* neutral-900 */
  --ink-2: #3f3f46;        /* neutral-700 */
  --muted: #a1a1aa;        /* neutral-400 */
  --muted-2: #71717a;      /* neutral-500 */
  --line: #e4e4e7;         /* neutral-200 */
  --line-soft: rgba(228, 228, 231, 0.7);

  --good: #15803d;
  --critical: #b91c1c;
  --warning: #a16207;

  --series-1: #2b2bee;
  --series-2: #eb6834;
  --series-3: #1baf7a;

  --radius: 0.625rem;
  --shadow-xs: 0 1px 2px 0 rgb(0 0 0 / 0.05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--site);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans TC", sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
::selection { background: var(--blob); color: #fff; }

/* ── header ──────────────────────────────────────────────────────────────── */

header.site {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(236, 236, 236, 0.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.site-row {
  max-width: 80rem;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  font-size: 14px;
  font-weight: 700;
  text-transform: lowercase;
  text-decoration: none;
  transition: color .15s;
}
.brand:hover { color: var(--blob); }
.brand-short { display: none; }

/* Desktop's right-hand element, where researchlibrary puts its language
   toggle. On mobile the menu button takes this slot instead. */
.brand-home {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  text-decoration: none;
  text-transform: lowercase;
  transition: color .15s;
}
.brand-home:hover { color: var(--blob); }

/* ── menu button — right side, mobile only ───────────────────────────────── */

.menu-btn {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 4px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  text-transform: lowercase;
  cursor: pointer;
  line-height: 1;
}
.menu-btn:hover { color: var(--blob); }

/* Three stacked rules, becoming an X when open. */
.menu-btn .bars {
  position: relative;
  display: inline-block;
  width: 20px;
  height: 14px;
}
.menu-btn .bars i {
  position: absolute;
  left: 0;
  width: 20px;
  height: 1.5px;
  background: currentColor;
  border-radius: 1px;
  transition: transform .22s cubic-bezier(.22,.61,.36,1), opacity .15s;
}
.menu-btn .bars i:nth-child(1) { top: 0; }
.menu-btn .bars i:nth-child(2) { top: 6.25px; }
.menu-btn .bars i:nth-child(3) { top: 12.5px; }

.menu-btn[aria-expanded="true"] .bars i:nth-child(1) { transform: translateY(6.25px) rotate(45deg); }
.menu-btn[aria-expanded="true"] .bars i:nth-child(2) { opacity: 0; }
.menu-btn[aria-expanded="true"] .bars i:nth-child(3) { transform: translateY(-6.25px) rotate(-45deg); }

/* ── shell: sidebar + main ───────────────────────────────────────────────── */

.shell {
  max-width: 80rem;
  margin: 0 auto;
  display: flex;
  align-items: flex-start;
}

aside.sidebar {
  position: sticky;
  top: 3.25rem;
  height: calc(100vh - 3.25rem);
  width: 15rem;
  flex-shrink: 0;
  overflow-y: auto;
  padding: 28px 16px;
}

main.note {
  min-width: 0;
  flex: 1;
  padding: 32px 24px 72px;
}

/* ── sidebar nav — Obsidian-style file tree ──────────────────────────────── */

nav.groups {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 14px;
  text-transform: lowercase;
}

nav.groups .nav-label {
  padding: 0 8px 4px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: lowercase;
  margin-top: 18px;
}
nav.groups .nav-label:first-child { margin-top: 0; }

nav.groups a {
  display: block;
  padding: 4px 8px;
  border-radius: 4px;
  color: var(--ink-2);
  text-decoration: none;
  line-height: 1.4;
  transition: color .15s;
}
nav.groups a:hover { color: var(--blob); }
nav.groups a[aria-current="page"] { font-weight: 700; color: var(--blob); }

/* ── mobile drawer ───────────────────────────────────────────────────────── */

.scrim {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(24, 24, 27, 0.3);
  opacity: 0;
  visibility: hidden;
  transition: opacity .22s ease, visibility .22s;
}
.scrim.open { opacity: 1; visibility: visible; }

.drawer {
  position: fixed;
  inset-block: 0;
  right: 0;                       /* opens from the right, matching the button */
  z-index: 31;
  width: 17rem;
  max-width: 82vw;
  overflow-y: auto;
  background: var(--site);
  padding: 20px;
  box-shadow: -6px 0 24px rgb(0 0 0 / 0.14);
  transform: translateX(100%);
  visibility: hidden;
  transition: transform .26s cubic-bezier(.22,.61,.36,1), visibility .26s;
}
.drawer.open { transform: translateX(0); visibility: visible; }

.drawer-close {
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 0;
  margin-bottom: 16px;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.drawer-close:hover { color: var(--blob); }

/* ── type ────────────────────────────────────────────────────────────────── */

h1 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-transform: lowercase;
  margin: 0 0 8px;
}
h2 {
  font-size: 16px;
  font-weight: 700;
  text-transform: lowercase;
  margin: 34px 0 10px;
}
h3 { font-size: 14px; font-weight: 700; margin: 0 0 2px; text-transform: lowercase; }

.blurb { color: var(--muted-2); max-width: 70ch; margin: 0 0 10px; }
.meta-line { color: var(--muted); font-size: 12px; margin: 28px 0 0; }
.meta-line a { color: var(--muted); }
.meta-line a:hover { color: var(--blob); }
p { max-width: 72ch; margin: 0 0 12px; }

/* ── cards ───────────────────────────────────────────────────────────────── */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
  padding: 16px 18px;
  margin: 14px 0;
}
.card > .sub { margin: 0 0 12px; font-size: 12px; color: var(--muted); }

/* ── notices ─────────────────────────────────────────────────────────────── */

.notice {
  border: 1px solid var(--line);
  border-left: 3px solid var(--muted);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin: 14px 0;
  background: var(--card);
  font-size: 13px;
  color: var(--ink-2);
}
.notice strong { color: var(--ink); }
.notice.warn { border-left-color: var(--warning); }
.notice.serious { border-left-color: var(--series-2); }
.notice.info { border-left-color: var(--blob); }
.notice.critical { border-left-color: var(--critical); }
.notice-title {
  display: flex; align-items: center; gap: 7px;
  font-weight: 700; color: var(--ink);
  margin-bottom: 5px; font-size: 13px; text-transform: lowercase;
}
.notice p { margin: 6px 0 0; max-width: 76ch; }
.notice p:first-of-type { margin-top: 0; }

/* ── badges ──────────────────────────────────────────────────────────────── */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  border: 1px solid var(--line); border-radius: 999px;
  padding: 2px 9px; font-size: 11px;
  color: var(--muted-2); background: var(--card);
  white-space: nowrap; text-transform: lowercase;
}
.badge.pv-observed   { color: var(--good);     border-color: color-mix(in srgb, var(--good) 40%, transparent); }
.badge.pv-inferred   { color: var(--warning);  border-color: color-mix(in srgb, var(--warning) 45%, transparent); }
.badge.pv-incomplete { color: var(--critical); border-color: color-mix(in srgb, var(--critical) 45%, transparent); }
.badge.pv-none       { color: var(--muted); }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; flex: none; }

/* ── stat tiles ──────────────────────────────────────────────────────────── */

.tiles {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  margin: 14px 0;
}
.tile {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow-xs);
}
.tile .k {
  font-size: 11px; color: var(--muted); margin-bottom: 4px;
  text-transform: lowercase; font-weight: 700;
}
.tile .v { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.tile .n { font-size: 11.5px; color: var(--muted-2); margin-top: 2px; }

/* ── tables ──────────────────────────────────────────────────────────────── */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  margin: 14px 0;
}
table {
  border-collapse: collapse; width: 100%;
  font-size: 12.5px; font-variant-numeric: tabular-nums;
}
th, td {
  text-align: left; padding: 8px 12px;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
th {
  color: var(--muted); font-weight: 700; font-size: 11px;
  text-transform: lowercase; position: sticky; top: 0; background: var(--card);
}
td.num, th.num { text-align: right; }
tr:last-child td { border-bottom: 0; }
tr.total td { font-weight: 700; border-top: 1px solid var(--muted); }
td a { color: var(--blob); font-weight: 500; }
.pos { color: var(--good); }
.neg { color: var(--critical); }
.muted { color: var(--muted); }

/* ── charts ──────────────────────────────────────────────────────────────── */

.chart-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 16px; flex-wrap: wrap; margin-bottom: 10px;
}
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted-2); }
.legend .item { display: inline-flex; align-items: center; gap: 6px; }
.legend .swatch { width: 14px; height: 2px; border-radius: 1px; display: inline-block; }
.chart { width: 100%; }
.axis-note { font-size: 11px; color: var(--muted); margin-top: 8px; }

/* ── misc ────────────────────────────────────────────────────────────────── */

.formula {
  font-variant-numeric: tabular-nums;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px; margin: 14px 0;
  font-size: 14px; text-align: center;
}

.pagelinks { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin: 14px 0 0; }
.pagelinks a {
  text-decoration: none; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; background: var(--card); box-shadow: var(--shadow-xs);
  font-size: 13px; transition: border-color .15s, color .15s;
}
.pagelinks a:hover { border-color: var(--blob); }
.pagelinks a:hover .t { color: var(--blob); }
.pagelinks .t { font-weight: 700; display: block; text-transform: lowercase; }
.pagelinks .d { color: var(--muted); font-size: 11.5px; }

/* ── learning-log blocks ─────────────────────────────────────────────────── */

p code, li code, .step-calc code {
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.92em;
  background: rgba(43, 43, 238, 0.06);
  padding: 1px 4px;
  border-radius: 4px;
}

/* The analogy is the signature element of the log: a blue-tinted card that
   reads as "the plain-English version" of whatever sits around it. */
.analogy {
  background: color-mix(in srgb, var(--blob) 5%, var(--card));
  border: 1px solid color-mix(in srgb, var(--blob) 22%, transparent);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin: 16px 0;
  max-width: 78ch;
}
.analogy-label,
.takeaways-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--blob);
  text-transform: lowercase;
  margin-bottom: 4px;
}
.analogy-title { font-weight: 700; margin-bottom: 6px; }
.analogy p { margin: 6px 0 0; }
.analogy p:first-of-type { margin-top: 0; }

.takeaways {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px 6px;
  margin: 18px 0;
  max-width: 78ch;
}
.takeaways ul { margin: 6px 0 8px; padding-left: 18px; }
.takeaways li { margin: 0 0 6px; }

.table-wrap.wrap td { white-space: normal; min-width: 9rem; vertical-align: top; line-height: 1.5; }
.table-wrap.wrap td:first-child { font-weight: 700; min-width: 7rem; }
.table-wrap.wrap th { white-space: nowrap; }

.chart-read { font-size: 12.5px; color: var(--ink-2); margin: 10px 0 0; max-width: none; }

ol.steps {
  list-style: none;
  counter-reset: step;
  padding: 0;
  margin: 14px 0;
  display: grid;
  gap: 8px;
}
ol.steps li {
  counter-increment: step;
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px 10px 44px;
}
ol.steps li::before {
  content: counter(step);
  position: absolute;
  left: 14px;
  top: 10px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--blob);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: grid;
  place-items: center;
}
.step-label { font-weight: 700; }
.step-calc { font-size: 12.5px; color: var(--muted-2); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.step-result { font-size: 13px; color: var(--ink); font-variant-numeric: tabular-nums; }

.calc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px 14px;
}
.calc label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted-2);
  text-transform: lowercase;
}
.calc input,
.calc select {
  font: inherit;
  font-size: 14px;
  font-weight: 400;
  color: var(--ink);
  background: var(--site);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 9px;
  width: 100%;
  min-width: 0;
}
.calc input:focus,
.calc select:focus { outline: 2px solid var(--blob); outline-offset: 1px; }
.calc-out { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 10px; }
.calc-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 5px 0;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.calc-row.total { border-top: 1px solid var(--muted); margin-top: 4px; padding-top: 8px; font-size: 14px; }
.calc-note { font-size: 12.5px; color: var(--muted-2); margin: 8px 0 0; max-width: none; }

.pagelinks .n { display: block; font-size: 11px; color: var(--blob); font-weight: 700; }

.next-page {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-decoration: none;
  margin: 36px 0 0;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  transition: border-color .15s;
}
.next-page:hover { border-color: var(--blob); }
.next-page .d { font-size: 11px; color: var(--muted); text-transform: lowercase; }
.next-page .t { font-weight: 700; color: var(--blob); text-transform: lowercase; }

.badge.pv-live    { color: var(--good);  border-color: color-mix(in srgb, var(--good) 40%, transparent); }
.badge.pv-concept { color: var(--blob);  border-color: color-mix(in srgb, var(--blob) 35%, transparent); }

footer.site {
  border-top: 1px solid var(--line-soft);
  margin-top: 40px; padding-top: 16px;
  color: var(--muted); font-size: 11.5px;
}
footer.site p { margin: 4px 0; max-width: none; }

/* ── mobile ──────────────────────────────────────────────────────────────── */

@media (max-width: 767px) {
  body { font-size: 15px; }

  /* The domain alone identifies the site; the full title wrapped the header. */
  .brand-full { display: none; }
  .brand-short { display: inline; }

  .site-row { padding: 10px 16px; }
  .menu-btn { display: inline-flex; }
  .brand-home { display: none; }          /* the brand already IS the domain */

  /* The sidebar becomes the drawer. */
  aside.sidebar { display: none; }
  main.note { padding: 24px 16px 56px; }

  h1 { font-size: 22px; }

  /* Tables scroll inside themselves and bleed to the edge, so a wide table
     never drags the page sideways. */
  .table-wrap {
    margin-left: -16px; margin-right: -16px;
    border-radius: 0; border-left: 0; border-right: 0;
  }
  th, td { padding: 7px 10px; }

  .tiles { grid-template-columns: repeat(auto-fit, minmax(135px, 1fr)); gap: 8px; }
  .tile .v { font-size: 18px; }
  .formula { font-size: 13px; padding: 12px 10px; }
  .pagelinks { grid-template-columns: 1fr; }
}

@media (min-width: 768px) {
  /* No drawer above the breakpoint; the sidebar is always present. */
  .scrim, .drawer { display: none; }
}

@media print {
  header.site, aside.sidebar, .scrim, .drawer { display: none; }
  body { background: #fff; }
}
