/* ---------- Noctis ---------- */
:root {
  --radius: 14px;
  --radius-sm: 8px;
  --gap: 20px;
  --max: 960px;
  --font-head: "Marcellus", Georgia, serif;
  --font-body: "Nunito", -apple-system, "Segoe UI", sans-serif;
  --up: #3ddc84;
  --down: #ff6161;
  --flat: #9aa0a6;
  --baseline: #f5c94b;
}

[data-theme="dark"] {
  --bg: #000000;
  --bg-raised: #0d0d0d;
  --bg-card: #121212;
  --border: #262626;
  --text: #f4f3ef;
  --text-dim: #a3a3a0;
  --text-faint: #6f6f6c;
  --accent: #f4f3ef;
  --accent-contrast: #000000;
  --shadow: 0 1px 0 rgba(255,255,255,0.03) inset;
  --glass-bg-1: rgba(255,255,255,0.07);
  --glass-bg-2: rgba(255,255,255,0.02);
  --glass-border: rgba(255,255,255,0.14);
  --glass-glare: rgba(255,255,255,0.10);
  --glass-shadow: 0 10px 36px rgba(0,0,0,0.45);
}

[data-theme="light"] {
  --bg: #faf9f6;
  --bg-raised: #ffffff;
  --bg-card: #ffffff;
  --border: #e4e2da;
  --text: #14140f;
  --text-dim: #56564f;
  --text-faint: #8a8a80;
  --accent: #14140f;
  --accent-contrast: #faf9f6;
  --shadow: 0 1px 0 rgba(0,0,0,0.02) inset;
  --glass-bg-1: rgba(255,255,255,0.55);
  --glass-bg-2: rgba(255,255,255,0.22);
  --glass-border: rgba(20,20,15,0.10);
  --glass-glare: rgba(255,255,255,0.65);
  --glass-shadow: 0 10px 30px rgba(20,20,15,0.10);
}

* { box-sizing: border-box; }
html { color-scheme: dark; }
[data-theme="light"] html, [data-theme="light"] { color-scheme: light; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: var(--max); margin: 0 auto; padding: 0 20px; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* header */
.top {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.top-in { display: flex; align-items: center; justify-content: space-between; height: 64px; }
.brand { display: flex; align-items: center; }
.logo { height: 34px; width: auto; display: block; }
[data-theme="light"] .logo { filter: invert(1); }
.top-right { display: flex; align-items: center; gap: 10px; }

.select {
  background: var(--bg-raised); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 8px 10px; font-family: var(--font-body); font-size: 14px;
}
.icon-btn {
  width: 38px; height: 38px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--bg-raised); color: var(--text);
  display: grid; place-items: center; cursor: pointer;
}
.icon-btn:hover { border-color: var(--text-faint); }
.i-sun, .i-moon { display: none; }
[data-theme="dark"] .i-sun { display: block; }
[data-theme="light"] .i-moon { display: block; }

/* hero -- liquid glass panel */
.hero {
  position: relative;
  overflow: hidden;
  margin-top: 20px;
  padding: 40px 28px 32px;
  border-radius: 26px;
  border: 1px solid var(--glass-border);
  background: linear-gradient(150deg, var(--glass-bg-1), var(--glass-bg-2));
  backdrop-filter: blur(20px) saturate(150%);
  -webkit-backdrop-filter: blur(20px) saturate(150%);
  box-shadow: var(--glass-shadow), inset 0 1px 0 rgba(255,255,255,0.10);
}
.hero::before {
  content: "";
  position: absolute;
  top: -60%; left: -20%;
  width: 70%; height: 200%;
  background: radial-gradient(closest-side, var(--glass-glare), transparent 70%);
  transform: rotate(18deg);
  opacity: 0.5;
  pointer-events: none;
}
.hero::after {
  content: "";
  position: absolute; inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.04);
  pointer-events: none;
}
.hero > * { position: relative; z-index: 1; }
.eyebrow {
  font-size: 13px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-faint); margin: 0 0 10px;
}
h1#headline {
  font-family: var(--font-head); font-weight: 400;
  font-size: clamp(28px, 5vw, 44px); line-height: 1.15; margin: 0 0 16px;
}
.hero-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.mood {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px; font-weight: 700; font-size: 13px;
  border: 1px solid var(--border);
}
.mood::before { content: ""; width: 8px; height: 8px; border-radius: 999px; background: currentColor; }
.mood.risk-on { color: var(--up); }
.mood.risk-off { color: var(--down); }
.mood.mixed { color: var(--flat); }
.muted { color: var(--text-dim); }
.small { font-size: 13px; }
.lede { font-size: 18px; color: var(--text-dim); max-width: 62ch; margin: 0 0 12px; }
.meta { font-size: 13px; color: var(--text-faint); display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }
.session { padding-left: 8px; margin-left: 4px; border-left: 1px solid var(--border); }
.share-btn {
  margin-left: auto; display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-raised); color: var(--text); border: 1px solid var(--border);
  border-radius: 999px; padding: 7px 14px; font-size: 13px; font-weight: 700;
  cursor: pointer; font-family: var(--font-body);
}
.share-btn:hover { border-color: var(--text-faint); }

/* staleness badge */
.stale-badge {
  display: inline-flex; align-items: center; gap: 6px;
  margin-left: 8px; padding: 4px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700; color: var(--baseline);
  border: 1px solid color-mix(in srgb, var(--baseline) 45%, transparent);
  background: color-mix(in srgb, var(--baseline) 10%, transparent);
}
.stale-badge[hidden] { display: none; }

/* cards */
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 22px; margin-bottom: var(--gap);
}
.card h2 {
  font-family: var(--font-head); font-weight: 400;
  font-size: 20px; margin: 0 0 14px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.card-head h2 { margin: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }
.body { color: var(--text-dim); margin: 0 0 12px; }

/* controls */
.controls { display: flex; gap: 8px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button {
  border: 0; background: transparent; color: var(--text-dim);
  padding: 6px 12px; border-radius: 999px; font-size: 13px; font-family: var(--font-body);
  cursor: pointer;
}
.seg button.on { background: var(--accent); color: var(--accent-contrast); font-weight: 700; }

/* timeline */
.tl { position: relative; height: 100px; }
.tl svg { width: 100%; height: 100%; display: block; }
.tl-dot { cursor: pointer; }
.tl-tip {
  position: absolute; transform: translate(-50%, -110%);
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 6px 10px; font-size: 12px;
  white-space: nowrap; pointer-events: none; opacity: 0; transition: opacity .1s;
}
.tl-tip.show { opacity: 1; }

/* chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: 999px; padding: 6px 10px; font-size: 13px;
}
.chip button {
  border: 0; background: transparent; color: var(--text-faint);
  cursor: pointer; font-size: 14px; line-height: 1; padding: 0;
}

/* macro list */
.macro-item { padding: 10px 0; border-top: 1px solid var(--border); }
.macro-item:first-child { border-top: 0; padding-top: 0; }
.macro-item h3 { margin: 0 0 4px; font-size: 14px; font-weight: 700; }
.macro-item p { margin: 0; color: var(--text-dim); font-size: 14px; }

/* movers table */
table.movers { width: 100%; border-collapse: collapse; }
table.movers th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-faint); font-weight: 600; padding: 8px 8px; cursor: pointer; user-select: none;
}
table.movers td { padding: 12px 8px; border-top: 1px solid var(--border); font-size: 14px; vertical-align: middle; }
table.movers tr.row { cursor: pointer; }
table.movers tr.row:hover td { background: color-mix(in srgb, var(--text) 4%, transparent); }
.tkr { font-weight: 700; }
.pct { font-variant-numeric: tabular-nums; font-weight: 700; }
.pct.up { color: var(--up); }
.pct.down { color: var(--down); }
.conf { font-size: 11px; padding: 3px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--text-dim); }
.star { background: transparent; border: 0; cursor: pointer; font-size: 16px; color: var(--text-faint); padding: 0 4px; }
.star.on { color: #f5c94b; }

/* heatmap -- Finviz-style: tile size scales with turnover, color is always clearly red/green */
.heat { display: flex; flex-wrap: wrap; gap: 6px; align-items: stretch; }
.heat-tile {
  border-radius: var(--radius-sm); padding: 12px 10px; cursor: pointer;
  border: 1px solid rgba(0,0,0,.15); color: #0a0a0a;
  min-width: 92px; display: flex; flex-direction: column; justify-content: center;
}
.heat-tile .t { font-weight: 800; font-size: 14px; }
.heat-tile .p { font-variant-numeric: tabular-nums; font-size: 13px; }

/* watchlist */
.add-row { display: flex; gap: 8px; margin-bottom: 14px; }
.input {
  flex: 1; background: var(--bg-raised); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 12px; font-family: var(--font-body); font-size: 14px;
}
.btn {
  background: var(--accent); color: var(--accent-contrast); border: 0;
  border-radius: var(--radius-sm); padding: 10px 16px; font-weight: 700;
  cursor: pointer; font-family: var(--font-body); font-size: 14px;
}
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.wgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 14px; }
.wtile { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; background: var(--bg-raised); }
.wtile .t { font-weight: 700; }
.empty { color: var(--text-faint); font-size: 14px; padding: 8px 0; }

/* sources & caveats */
.caveats { margin: 14px 0 0; padding-left: 18px; color: var(--text-dim); font-size: 14px; }

/* how it works */
.steps { padding-left: 20px; color: var(--text-dim); }
.steps li { margin-bottom: 8px; }
.steps strong { color: var(--text); }

/* footer -- fades in only when scrolled into view */
.foot {
  padding: 10px 20px 48px; text-align: center;
  opacity: 0; transition: opacity .7s ease;
}
.foot.visible { opacity: 1; }
.foot p { margin: 4px 0; }

/* dialog */
dialog {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-card); color: var(--text); padding: 0;
  width: min(520px, 92vw);
}
dialog::backdrop { background: rgba(0,0,0,.6); }
.dlg { padding: 22px; }
.dlg h3 { font-family: var(--font-head); font-weight: 400; margin: 0 0 8px; font-size: 22px; }
.dlg .row { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.dlg p { color: var(--text-dim); }
.dlg form { margin-top: 14px; text-align: right; }

/* responsive */
@media (max-width: 720px) {
  .grid2 { grid-template-columns: 1fr; }
  .hero { padding: 30px 20px 26px; border-radius: 20px; }
  table.movers thead { display: none; }
  table.movers tr.row { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px 0; border-top: 1px solid var(--border); }
  table.movers td { border-top: none; padding: 2px 0; }
  table.movers td.c-why { grid-column: 1 / -1; color: var(--text-dim); font-size: 13px; }
  .hero-row { flex-wrap: wrap; }
  .share-btn { margin-left: 0; }
}

/* Respect reduced-motion / low-power: browsers that can't do backdrop-filter
   just show the solid gradient beneath, which still looks intentional. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .hero { background: var(--bg-card); }
}
