:root {
  --paper: #f6f4ef;
  --paper-2: #f1eee7;
  --card: #ffffff;
  --line: #e8e3d8;
  --line-2: #ded8ca;
  --ink: #20201d;
  --ink-soft: #45433d;
  --muted: #8a857a;
  --faint: #b7b1a4;
  --accent: #26324a; /* deep ink navy — UI/brand/chart, NOT gain/loss */
  --up: #0f7a52; /* gains */
  --down: #b23b34; /* losses */
  --alloc-1: #2c2c28;
  --alloc-2: #7a7064;
  --alloc-3: #b6ad9c;
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: "Hanken Grotesk", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --mono: "Spline Sans Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --shadow-sm: 0 1px 2px rgba(40, 36, 28, 0.04);
  --shadow: 0 1px 2px rgba(40, 36, 28, 0.04), 0 10px 28px -16px rgba(40, 36, 28, 0.16);
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  -webkit-text-size-adjust: 100%;
}

.num {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.muted {
  color: var(--muted);
}
.up {
  color: var(--up);
}
.down {
  color: var(--down);
}
[hidden] {
  display: none !important;
}

.section-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

/* gentle entrance */
@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.hero,
.alloc,
.card {
  animation: fade 0.5s ease both;
}
.alloc {
  animation-delay: 0.04s;
}
.holdings {
  animation-delay: 0.08s;
}
.chart-card {
  animation-delay: 0.12s;
}
.news-card {
  animation-delay: 0.16s;
}
@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
  }
}

/* ---------- Layout ---------- */
.app {
  max-width: 1000px;
  margin: 0 auto;
  padding: 28px 28px 64px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

/* ---------- Top bar ---------- */
.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.wordmark {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 20px;
  letter-spacing: 0.01em;
  color: var(--ink);
}
.top-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.updated {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--faint);
}
.freshness {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--muted);
}
.freshness::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--faint);
}
.freshness.live {
  color: var(--up);
}
.freshness.live::before {
  background: var(--up);
  box-shadow: 0 0 0 0 rgba(15, 122, 82, 0.4);
  animation: pulse 2.4s infinite;
}
.freshness.delayed {
  color: #b07d18;
}
.freshness.delayed::before {
  background: #d99e2b;
}
@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(15, 122, 82, 0.35);
  }
  70% {
    box-shadow: 0 0 0 5px rgba(15, 122, 82, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(15, 122, 82, 0);
  }
}

/* ---------- Hero ---------- */
.hero {
  padding: 6px 2px 2px;
}
.hero-label {
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}
.hero-value {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(46px, 8vw, 68px);
  line-height: 1.02;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  margin-top: 8px;
  color: var(--ink);
}
.hero-stats {
  margin-top: 22px;
  display: flex;
  gap: 0;
}
.hstat {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-right: 36px;
}
.hstat-sep {
  padding-left: 36px;
  border-left: 1px solid var(--line);
}
.hstat-label {
  font-size: 11px;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}
.hstat-val {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 21px;
  font-weight: 600;
  color: var(--ink);
  display: inline-flex;
  align-items: baseline;
  gap: 9px;
}
.hero-pl {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 21px;
  font-weight: 600;
}
.hero-pl-pct {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
}
.hero-pl-pct.up {
  background: rgba(15, 122, 82, 0.1);
}
.hero-pl-pct.down {
  background: rgba(178, 59, 52, 0.1);
}
/* per-asset invested figure under the value */
.c-invested {
  display: block;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 3px;
}

/* ---------- Allocation ---------- */
.alloc {
  padding: 0 2px;
}
.alloc-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
}
.alloc-note {
  font-size: 12px;
  color: var(--faint);
}
.alloc-bar {
  display: flex;
  height: 12px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--paper-2);
  box-shadow: inset 0 0 0 1px var(--line);
}
.alloc-seg {
  height: 100%;
}
.alloc-seg + .alloc-seg {
  box-shadow: inset 1px 0 0 rgba(255, 255, 255, 0.6);
}
.alloc-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  margin-top: 12px;
}
.alloc-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-soft);
}
.alloc-item .swatch {
  width: 9px;
  height: 9px;
  border-radius: 2px;
}
.alloc-item .pct {
  font-family: var(--mono);
  color: var(--muted);
}

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 24px;
}
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 16px;
}
.hint,
.chart-note {
  font-size: 12.5px;
  color: var(--faint);
}

/* ---------- Holdings table ---------- */
.htable-wrap {
  overflow-x: auto;
}
.htable {
  width: 100%;
  border-collapse: collapse;
}
.htable th {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: right;
  padding: 0 0 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.htable th.ta-l {
  text-align: left;
}
.hrow {
  cursor: pointer;
  transition: background 0.15s ease;
}
.hrow > td {
  padding: 16px 0;
  text-align: right;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  white-space: nowrap;
}
.hrow:hover {
  background: var(--paper);
}
.hrow.open {
  background: var(--paper);
}
.hrow.open > td {
  border-bottom-color: transparent;
}

/* asset cell */
.c-asset {
  text-align: left !important;
}
.asset-inner {
  display: flex;
  align-items: center;
  gap: 11px;
}
.asset-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex: none;
}
.asset-names {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}
.asset-tk {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.01em;
}
.asset-nm {
  font-size: 12.5px;
  color: var(--muted);
}
.asset-mobile {
  display: none;
  margin-top: 4px;
  font-size: 12px;
}
.c-value .pl-m {
  display: none;
}
.am-price {
  color: var(--ink-soft);
}
.am-chg {
  font-weight: 600;
}
.caret {
  margin-left: 4px;
  color: var(--faint);
  font-size: 13px;
  transition: transform 0.2s ease;
}
.hrow.open .caret {
  transform: rotate(90deg);
  color: var(--muted);
}

.c-price .num,
.c-units,
.c-avg,
.c-value .num,
.c-pl .num {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 14.5px;
}
.c-value .num {
  font-weight: 600;
}
.cell-main {
  display: block;
}
.cell-sub {
  display: block;
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 600;
  margin-top: 3px;
}

/* lots row */
.lrow > td {
  padding: 0;
  border-bottom: 1px solid var(--line);
}
.lots {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.28s ease;
}
.hrow.open + .lrow .lots {
  grid-template-rows: 1fr;
}
.lots-inner {
  overflow: hidden;
}
.lots-pad {
  padding: 4px 0 16px 21px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.lot {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  padding: 9px 12px 9px 14px;
  border-left: 2px solid var(--line-2);
  border-radius: 0 8px 8px 0;
  transition: background 0.15s ease;
}
.lot:hover {
  background: var(--card);
}
.lot-left {
  min-width: 0;
}
.lot-date {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--ink-soft);
}
.lot-age {
  color: var(--faint);
  font-size: 11.5px;
  margin-left: 6px;
}
.lot-detail {
  font-size: 12px;
  color: var(--muted);
  margin-top: 3px;
}
.lot-right {
  text-align: right;
  white-space: nowrap;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}
.lot-pl {
  font-size: 13.5px;
  font-weight: 600;
}
.lot-pct {
  font-size: 11.5px;
  font-weight: 600;
  margin-left: 6px;
}

/* ---------- Chart ---------- */
.controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.tabs {
  display: inline-flex;
  gap: 2px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 3px;
}
.tab {
  background: transparent;
  border: none;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.tab:hover {
  color: var(--ink);
}
.tab.active {
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}
.chart-wrap {
  position: relative;
  height: 320px;
}
.chart-note {
  margin-top: 14px;
}

/* ---------- News ---------- */
.news {
  display: flex;
  flex-direction: column;
}
.news-item {
  display: block;
  padding: 15px 0;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
  color: var(--ink);
  transition: opacity 0.15s ease;
}
.news-item:first-child {
  padding-top: 2px;
}
.news-item:last-child {
  border-bottom: none;
  padding-bottom: 2px;
}
.news-item:hover .news-title {
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: var(--line-2);
}
.news-title {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 17px;
  line-height: 1.35;
  letter-spacing: -0.005em;
}
.news-meta {
  margin-top: 6px;
  font-size: 12.5px;
  color: var(--muted);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.news-cur {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-soft);
  background: var(--paper);
  border: 1px solid var(--line);
  padding: 1px 6px;
  border-radius: 5px;
}
.news-empty {
  color: var(--muted);
  font-size: 14px;
  padding: 8px 0;
  line-height: 1.5;
}

.foot {
  text-align: center;
  font-size: 12px;
  color: var(--faint);
}

/* ---------- Stale dimming ---------- */
body.is-stale .live-value {
  opacity: 0.42;
  transition: opacity 0.25s ease;
}

/* ---------- Gate ---------- */
.gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(120% 80% at 50% 0%, #fbfaf6 0%, var(--paper) 60%);
  padding: 24px;
}
.gate-card {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 34px 30px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.gate-title {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 26px;
  letter-spacing: 0.01em;
}
.gate-sub {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 8px;
}
.gate-input {
  background: var(--paper);
  border: 1px solid var(--line-2);
  border-radius: 10px;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  padding: 13px 14px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.gate-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(38, 50, 74, 0.1);
}
.gate-btn {
  background: var(--accent);
  border: none;
  color: #fff;
  font-family: var(--sans);
  font-weight: 600;
  font-size: 14.5px;
  padding: 13px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.gate-btn:hover {
  background: #1c283d;
}
.gate-btn:disabled {
  opacity: 0.55;
  cursor: default;
}
.gate-error {
  color: var(--down);
  font-size: 13px;
  min-height: 16px;
}

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .app {
    padding: 20px 16px 48px;
    gap: 22px;
  }
  .hero-stats {
    flex-direction: column;
    gap: 16px;
  }
  .hstat {
    padding-right: 0;
  }
  .hstat-sep {
    padding-left: 0;
    border-left: none;
  }
  .hide-sm {
    display: none;
  }
  .asset-mobile {
    display: block;
  }
  .c-value .pl-m {
    display: block;
    margin-top: 5px;
    line-height: 1.35;
  }
  .pl-m .plm-amt,
  .pl-m .plm-pct {
    display: block;
  }
  .c-value .num {
    font-size: 15px;
  }
  .c-invested {
    display: none;
  }
  /* allow the holdings table to use full card width on mobile */
  .htable,
  .htable-wrap {
    width: 100%;
  }
  .hrow > td {
    padding: 14px 0;
  }
  .lots-pad {
    padding-left: 0;
  }
}
