/* Almanac app — brand: ink #0c0907, cream #FBF6F2, copper #E0AD9A */
:root {
  color-scheme: light;
  --bg: #FBF6F2;
  --surface: #ffffff;
  --surface-2: #f3ece6;
  --line: #e3d9d1;
  --text: #0c0907;
  --text-2: #55504b;
  --text-3: #8a827b;
  --accent: #8f4f39;
  --accent-ink: #ffffff;
  --series-1: #2a78d6;   /* Almanac / MA50 */
  --series-2: #eb6834;   /* MSCI World / MA200 */
  --series-3: #1baf7a;   /* S&P 500 */
  --price: #0c0907;
  --band: rgba(143, 79, 57, .14);
  --grid: #ece4dd;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0c0907;
    --surface: #16120f;
    --surface-2: #1f1a16;
    --line: #2e2722;
    --text: #FBF6F2;
    --text-2: #c9bfb7;
    --text-3: #8f867f;
    --accent: #E0AD9A;
    --accent-ink: #0c0907;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --price: #FBF6F2;
    --band: rgba(224, 173, 154, .16);
    --grid: #251f1b;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 var(--font);
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}
a { color: inherit; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0; }
h1 { font-size: 26px; }
h2 { font-size: 19px; margin: 28px 0 10px; }
.muted { color: var(--text-3); }
.pad { padding: 20px; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- top bar ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 20px;
  padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-left)) 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none;
  font-family: var(--serif); font-size: 20px; font-weight: 600; }
.brand img { border-radius: 7px; display: block; }
.asof { margin-left: auto; font-size: 12px; color: var(--text-3); white-space: nowrap; }

.tabs { display: flex; gap: 4px; }
.tabs a {
  text-decoration: none; padding: 7px 14px; border-radius: 999px;
  color: var(--text-2); font-weight: 500;
}
.tabs a:hover { background: var(--surface-2); }
.tabs a[aria-current="page"] { background: var(--text); color: var(--bg); }

/* phone: tabs become a bottom bar */
@media (max-width: 640px) {
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    justify-content: space-around; gap: 0;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--bg) 92%, transparent);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
  }
  /* a blurred parent would trap the fixed bar inside the header, so the phone header is solid */
  .top { backdrop-filter: none; -webkit-backdrop-filter: none; background: var(--bg); }
  .tabs a { flex: 1; text-align: center; padding: 9px 0; }
}
@media (min-width: 641px) { body { padding-bottom: 0; } }

main { max-width: 980px; margin: 0 auto; padding: 22px max(16px, env(safe-area-inset-left)) 40px; outline: none; }
.foot { max-width: 980px; margin: 0 auto; padding: 0 16px 28px; font-size: 12px; color: var(--text-3);
  display: flex; gap: 16px; flex-wrap: wrap; justify-content: space-between; }

/* ---------- shared pieces ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--surface); color: var(--text-2);
  border-radius: 999px; padding: 6px 13px; font: inherit; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip .n { opacity: .6; margin-left: 5px; font-variant-numeric: tabular-nums; }

.badge { display: inline-block; font-size: 12px; font-weight: 600; letter-spacing: .02em;
  padding: 2px 9px; border-radius: 999px; border: 1px solid var(--line); color: var(--text-2); white-space: nowrap; }
.badge.buy { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.badge.short { border-color: var(--accent); color: var(--accent); }
.kind { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); }

input[type="search"] {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px;
}
button.link { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; }
a.link { color: var(--accent); text-decoration: none; }
a.link:hover, button.link:hover { text-decoration: underline; }

/* ---------- feed ---------- */
.post h3 { font-size: 17px; margin: 4px 0 8px; }
.post .meta { font-size: 12px; color: var(--text-3); }
.post .body { color: var(--text-2); overflow-wrap: anywhere; }
.post .body.clamp { display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
.post .body strong { color: var(--text); }
.post .actions { margin-top: 10px; display: flex; gap: 16px; font-size: 14px; }

/* ---------- ideas list ---------- */
.idea { display: grid; grid-template-columns: 1fr auto; gap: 4px 14px; text-decoration: none;
  padding: 13px 16px; border-bottom: 1px solid var(--line); }
.idea:last-child { border-bottom: 0; }
.idea:hover { background: var(--surface-2); }
.idea .name { font-weight: 600; }
.idea .sub { grid-column: 1; font-size: 13px; color: var(--text-3); }
.idea .right { grid-row: 1 / span 2; grid-column: 2; text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.idea .right small { color: var(--text-3); font-variant-numeric: tabular-nums; }
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }

/* ---------- case + portfolio ---------- */
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin: 16px 0; }
.fact { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.fact .k { font-size: 12px; color: var(--text-3); }
.fact .v { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.fact .s { font-size: 12px; color: var(--text-3); }
.lede { font-family: var(--serif); font-size: 17px; line-height: 1.55; color: var(--text-2); margin: 14px 0 0; }
.lede.clamp { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }

.chartcard { padding: 12px 8px 6px; }
.chartcard .head { display: flex; align-items: center; gap: 10px; padding: 2px 10px 6px; flex-wrap: wrap; }
.chartcard .head h3 { font-family: var(--font); font-size: 14px; font-weight: 600; }
.chartcard .note { font-size: 12px; color: var(--text-3); padding: 0 10px 8px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin-left: auto; }
.seg button { font: inherit; font-size: 13px; padding: 4px 11px; background: none; border: 0; color: var(--text-2); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--text); color: var(--bg); }
.plot { width: 100%; height: 340px; }
.plot.short { height: 260px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: right; padding: 8px 10px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
th:first-child, td:first-child { text-align: left; }
th { font-size: 12px; font-weight: 600; color: var(--text-3); }
tr:last-child td { border-bottom: 0; }
.tablewrap { overflow-x: auto; }
ol.tranches { margin: 8px 0 0; padding-left: 20px; color: var(--text-2); }
ol.tranches li + li { margin-top: 4px; }
.back { display: inline-block; margin-bottom: 12px; font-size: 14px; }

/* ---------- KPI small multiples ---------- */
.kgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; margin-top: 12px; }
.kplot { height: 190px; }
.klast { margin-left: auto; font-size: 15px; font-weight: 600; }
.chartcard .head h3 { min-width: 0; }
.kflat h3 { font-family: var(--font); font-size: 14px; font-weight: 600; margin-bottom: 10px; }
.kflat .v { font-size: 18px; font-weight: 600; }
.kflat .s { font-size: 12px; color: var(--text-3); margin-top: 8px; }
@media (max-width: 640px) { .wide { display: none; } th, td { padding: 8px 6px; } }

/* ---------- sign-in (hosted) ---------- */
.signedout .tabs, .signedout .asof, .signedout #signout { display: none; }
.login { max-width: 380px; margin: 8vh auto 0; padding: 24px; }
.login label { display: block; font-size: 13px; color: var(--text-2); margin-top: 14px; }
.login input { display: block; width: 100%; margin-top: 5px; font: inherit; font-size: 16px; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
button.primary { margin-top: 18px; width: 100%; font: inherit; font-weight: 600; padding: 11px;
  border: 0; border-radius: 10px; background: var(--text); color: var(--bg); cursor: pointer; }
button.primary:disabled { opacity: .5; }
.login .err { color: var(--accent); min-height: 1.4em; margin: 12px 0 0; font-size: 14px; }
