/* signals.carsonwuai.com
 *
 * Design ported from carsonwuai.com/researchlibrary so the subdomain reads as
 * part of the same site: #ececec page, white rounded cards, electric blue
 * accent, all-lowercase, heavy type, left sidebar that becomes a drawer on
 * mobile.
 *
 * One deliberate difference from the library: it sets `body { zoom: 0.75 }` on
 * desktop. That cannot be used here — Lightweight Charts measures real pixel
 * dimensions to size its canvas, and a zoomed body makes the chart and its
 * crosshair disagree with the pointer. The same visual density is reached with
 * the type scale instead.
 */

:root {
  color-scheme: light;

  --site: #ececec;          /* page background */
  --card: #ffffff;
  --blob: #2b2bee;          /* signature electric blue */
  --blob-deep: #1b1b9e;

  --n900: #171717;
  --n800: #262626;
  --n700: #404040;
  --n600: #525252;
  --n500: #737373;
  --n400: #a3a3a3;
  --n300: #d4d4d4;
  --n200: #e5e5e5;
  --n100: #f5f5f5;

  --good: #0ca30c;
  --critical: #d03b3b;
  --warning: #fab219;
  --serious: #ec835a;

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

  --radius: 0.625rem;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, "Noto Sans TC", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  --header-h: 3.25rem;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--site);
  color: var(--n900);
  font-family: var(--sans);
  font-size: 14.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

a { color: inherit; text-decoration: none; }

/* The library is lowercase throughout; index tickers and proper nouns opt out
   via .keep-case so "S&P 500" and "VIX" don't become "s&p 500". */
.lower { text-transform: lowercase; }
.keep-case { text-transform: none; }

/* ---------------------------------------------------------------- header */

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

.site-row {
  max-width: 80rem;             /* max-w-7xl */
  margin: 0 auto;
  padding: 0.7rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: var(--header-h);
}

.site-left { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }

.brand {
  font-size: 0.875rem;
  font-weight: 700;
  text-transform: lowercase;
  letter-spacing: -0.005em;
  white-space: nowrap;
}
.brand:hover { color: var(--blob); }

/* Hamburger — mobile only, matches the library's 20px lucide icon. */
.menu-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  margin-left: -0.5rem;
  border: 0;
  background: transparent;
  color: var(--n900);
  cursor: pointer;
  padding: 0;
}
.menu-btn:hover { color: var(--blob); }
.menu-btn svg { width: 1.25rem; height: 1.25rem; }

/* en / 中文 — two text buttons, not a single toggle. */
.lang {
  display: flex;
  gap: 1rem;
  font-size: 0.875rem;
  font-weight: 700;
  text-transform: lowercase;
}
.lang button {
  border: 0;
  background: transparent;
  padding: 0;
  font: inherit;
  cursor: pointer;
  color: var(--n400);
  transition: color 0.15s;
}
.lang button:hover { color: var(--blob); }
.lang button[aria-pressed="true"] { color: var(--blob); }

/* ----------------------------------------------------------- app shell */

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

aside.sidebar {
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
  width: 18rem;              /* w-72 */
  flex-shrink: 0;
  overflow-y: auto;
  padding: 2rem 1rem;
  display: none;
}

main.content {
  min-width: 0;
  flex: 1;
  padding: 2.5rem 1.5rem;
}

@media (min-width: 768px) {
  aside.sidebar { display: block; }
  main.content { padding: 3rem 1.5rem; }
}

/* ------------------------------------------------------- sidebar nav */

nav.tree {
  font-size: 0.875rem;
  text-transform: lowercase;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

nav.tree .group-label {
  padding: 0 0.5rem 0.25rem;
  margin: 0;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--n400);
}

nav.tree .items { display: flex; flex-direction: column; gap: 0.125rem; }

nav.tree a,
nav.tree button.tree-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  font: inherit;
  cursor: pointer;
  border-radius: 0.25rem;
  padding: 0.25rem 0.5rem;
  line-height: 1.375;
  color: var(--n700);
  transition: color 0.15s;
}
nav.tree a:hover,
nav.tree button.tree-item:hover { color: var(--blob); }
nav.tree a[aria-current="page"],
nav.tree button.tree-item[aria-pressed="true"] {
  font-weight: 700;
  color: var(--blob);
}

nav.tree .num {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--n400);
  margin-right: 0.5rem;
}

nav.tree .meta {
  float: right;
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--n400);
}

.back-link {
  display: block;
  padding: 0 0.5rem;
  font-size: 0.75rem;
  color: var(--n400);
}
.back-link:hover { color: var(--blob); }

/* ------------------------------------------------------ mobile drawer */

.drawer-root { position: fixed; inset: 0; z-index: 30; }
.drawer-root[hidden] { display: none; }
.drawer-scrim { position: absolute; inset: 0; background: rgba(23, 23, 23, 0.3); }
.drawer-panel {
  position: absolute;
  inset-block: 0;
  left: 0;
  width: 18rem;
  max-width: 85vw;
  overflow-y: auto;
  background: var(--site);
  padding: 1.25rem;
  box-shadow: 0 20px 25px -5px rgba(0,0,0,.1), 0 8px 10px -6px rgba(0,0,0,.1);
}
.drawer-close {
  border: 0; background: transparent; padding: 0; cursor: pointer;
  color: var(--n900); margin-bottom: 1rem;
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.75rem; height: 1.75rem;
}
.drawer-close:hover { color: var(--blob); }
.drawer-close svg { width: 1.25rem; height: 1.25rem; }

@media (min-width: 768px) { .drawer-root { display: none; } }

/* ----------------------------------------------------------- content */

.note { max-width: 48rem; text-transform: lowercase; }
.note.wide { max-width: 64rem; }

h1 {
  font-size: 1.875rem;
  line-height: 1.15;
  font-weight: 900;
  letter-spacing: -0.025em;
  margin: 0 0 0.75rem;
}
@media (min-width: 768px) { h1 { font-size: 2.25rem; } }

h2 {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--n400);
  margin: 2.5rem 0 0.75rem;
}

.tagline {
  font-size: 1.0625rem;
  line-height: 1.6;
  font-weight: 700;
  color: var(--n900);
  max-width: 46rem;
  margin: 0 0 1rem;
}

.blurb, .lede {
  max-width: 44rem;
  line-height: 1.7;
  color: var(--n600);
  margin: 0 0 0.5rem;
}

/* "when X, that usually means Y, so watch whether Z." */
.story {
  max-width: 46rem;
  margin: 0.75rem 0 0;
  color: var(--n600);
  line-height: 1.75;
}
.story .j { color: var(--n400); }
.story strong { color: var(--n900); font-weight: 700; }
.story em { color: var(--blob); font-style: normal; font-weight: 700; }

/* when the reading breaks down */
.fails {
  max-width: 46rem;
  margin: 1rem 0 0;
  border-left: 2px solid var(--warning);
  background: var(--card);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 0.75rem 1rem;
  font-size: 0.8125rem;
  color: var(--n600);
  line-height: 1.65;
}
.fails .h {
  display: block;
  font-size: 0.6875rem;
  font-weight: 700;
  color: var(--n400);
  margin-bottom: 0.25rem;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin: 0.75rem 0;
}

.card > h3 { margin: 0 0 0.125rem; font-size: 0.9375rem; font-weight: 700; }
.card > .sub { margin: 0 0 0.75rem; font-size: 0.75rem; color: var(--n400); }

.notice {
  background: var(--card);
  border-radius: var(--radius);
  border-left: 2px solid var(--n300);
  padding: 0.75rem 1rem;
  margin: 0.875rem 0;
  font-size: 0.8125rem;
  color: var(--n600);
  max-width: 46rem;
  line-height: 1.65;
}
.notice.warn { border-left-color: var(--warning); }
.notice.serious { border-left-color: var(--serious); }
.notice.info { border-left-color: var(--blob); }
.notice-title {
  display: block;
  font-weight: 700;
  color: var(--n900);
  margin-bottom: 0.25rem;
  font-size: 0.8125rem;
}
.notice p { margin: 0.375rem 0 0; }
.notice p:first-of-type { margin-top: 0; }
.notice a { color: var(--blob); font-weight: 700; }

/* ------------------------------------------------------------ badges */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
  font-size: 0.6875rem;
  font-weight: 700;
  background: var(--n100);
  color: var(--n600);
  white-space: nowrap;
}
.badge.buy { color: var(--good); background: rgba(12, 163, 12, 0.09); }
.badge.sell { color: var(--critical); background: rgba(208, 59, 59, 0.09); }
.badge.st-confirmed { color: var(--good); background: rgba(12, 163, 12, 0.09); }
.badge.st-directional { color: #9a6100; background: rgba(250, 178, 25, 0.14); }
.badge.st-no_edge { color: var(--n500); }
.badge.st-contrary { color: var(--critical); background: rgba(208, 59, 59, 0.09); }
.badge.st-insufficient { color: var(--n500); }

/* ------------------------------------------------------------ charts */

.chart-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.legend {
  display: flex;
  gap: 0.875rem;
  flex-wrap: wrap;
  font-size: 0.75rem;
  color: var(--n500);
}
.legend .item { display: inline-flex; align-items: center; gap: 0.375rem; }
.legend .swatch { width: 14px; height: 2px; border-radius: 1px; display: inline-block; }
.legend .swatch.dash { height: 0; border-top: 2px dashed currentColor; }
.legend .swatch.dot { width: 8px; height: 8px; border-radius: 50%; }

.chart { width: 100%; }
.chart-price { height: 300px; }
.chart-pane { height: 160px; }

.axis-note {
  font-size: 0.6875rem;
  color: var(--n400);
  margin: 0.5rem 0 0;
  line-height: 1.6;
}

/* ------------------------------------------------------------ tables */

.table-wrap { overflow-x: auto; border-radius: var(--radius); background: var(--card); }

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}
th, td { text-align: left; padding: 0.5rem 0.875rem; white-space: nowrap; }
thead th {
  color: var(--n400);
  font-weight: 700;
  font-size: 0.6875rem;
  position: sticky;
  top: 0;
  background: var(--card);
}
tbody tr { border-top: 1px solid var(--n100); }
td.num { text-align: right; }
td.pos { color: var(--good); }
td.neg { color: var(--critical); }

details.table-view { margin: 0.75rem 0 0; }
details.table-view summary {
  cursor: pointer;
  font-size: 0.8125rem;
  color: var(--n500);
  padding: 0.25rem 0;
  list-style: none;
}
details.table-view summary::-webkit-details-marker { display: none; }
details.table-view summary::before { content: "▸ "; color: var(--n400); }
details.table-view[open] summary::before { content: "▾ "; }
details.table-view summary:hover { color: var(--blob); }
details.table-view[open] summary { margin-bottom: 0.5rem; }

/* -------------------------------------------------------- stat tiles */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: 0.75rem;
  margin: 0.875rem 0;
}
.tile { background: var(--card); border-radius: var(--radius); padding: 0.875rem 1rem; }
.tile .k { font-size: 0.6875rem; color: var(--n400); font-weight: 700; margin-bottom: 0.125rem; }
.tile .v { font-size: 1.375rem; font-weight: 800; letter-spacing: -0.02em; line-height: 1.15; }
.tile .s { font-size: 0.75rem; color: var(--n500); margin-top: 0.125rem; }

/* --------------------------------------------------- overview cards */

.index-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  margin: 1rem 0;
}
@media (min-width: 900px) { .index-grid { grid-template-columns: repeat(3, 1fr); } }

.idx-card { background: var(--card); border-radius: var(--radius); padding: 1rem 1.25rem; }
.idx-card .top { display: flex; justify-content: space-between; align-items: baseline; gap: 0.75rem; }
.idx-card .name { font-weight: 800; font-size: 1rem; }
.idx-card .zh { font-size: 0.75rem; color: var(--n400); font-weight: 400; display: block; }
.idx-card .px { font-size: 1.125rem; font-weight: 800; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 0.15rem 0.875rem; font-size: 0.8125rem; margin: 0.75rem 0; }
.kv dt { color: var(--n400); }
.kv dd { margin: 0; color: var(--n700); }

.group-links { display: flex; flex-wrap: wrap; gap: 0.375rem; margin-top: 0.5rem; }
.group-links a {
  font-size: 0.75rem;
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  color: var(--n600);
  background: var(--n100);
}
.group-links a:hover { color: var(--blob); }

.meta-line { color: var(--n400); font-size: 0.75rem; margin: 0.5rem 0 0; }

/* ------------------------------------------------------- range chips */

.controls { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin: 0 0 1rem; }
.seg { display: inline-flex; gap: 0.25rem; }
.seg button {
  border: 0;
  background: var(--card);
  color: var(--n600);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  cursor: pointer;
  text-transform: lowercase;
}
.seg button:hover { color: var(--blob); }
.seg button[aria-pressed="true"] { background: var(--blob); color: #fff; }
.seg-label { font-size: 0.6875rem; color: var(--n400); font-weight: 700; text-transform: lowercase; }

/* ------------------------------------------------------ signal block */

.signal-head { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.25rem; }
.signal-head .name { font-weight: 800; font-size: 0.9375rem; }

.evidence-line {
  font-size: 0.75rem;
  color: var(--n500);
  margin: 0.625rem 0 0;
  line-height: 1.6;
}

footer.site {
  border-top: 1px solid rgba(229, 229, 229, 0.7);
  margin-top: 3rem;
  padding: 1.25rem 0 0;
  color: var(--n400);
  font-size: 0.75rem;
  max-width: 46rem;
  line-height: 1.65;
}

.loading { color: var(--n400); padding: 2.5rem 0; }
.error { color: var(--critical); background: var(--card); border-radius: var(--radius); padding: 0.75rem 1rem; }

@media (max-width: 767px) {
  main.content { padding: 1.75rem 1.25rem; }
  .chart-price { height: 240px; }
  .chart-pane { height: 140px; }
  h1 { font-size: 1.625rem; }
  .tagline { font-size: 1rem; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  th, td { padding: 0.45rem 0.7rem; }
}
