:root {
  --bg: #2a2a2a;
  --card: #333333;
  --ink: #f4f4f4;
  --muted: #c8c8c8;
  --line: #4a4a4a;
  --accent: #e8e8e8;
  --warn: #f0d9a8;
  --warn-bg: #3d3528;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color-scheme: dark;
}
a { color: var(--accent); }
html { scroll-padding-top: 4.5rem; }
header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.5rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem 1rem;
  flex-wrap: wrap;
}
header .brand { color: var(--ink); text-decoration: none; font-weight: 650; }
header img {
  display: block;
  width: min(200px, 46vw);
  height: auto;
}
header nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
header nav.hub-nav .btn {
  white-space: normal;
  max-width: 14rem;
  line-height: 1.2;
  font-size: 0.82rem;
}
.wrap { max-width: 1200px; margin: 0 auto; padding: 1rem 1.25rem 2.5rem; }
#portfolios { scroll-margin-top: 4.5rem; }
a.btn {
  display: inline-block;
  background: #3a3a3a;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.35rem 0.9rem;
  text-decoration: none;
  font-weight: 650;
}
a.btn:hover { background: #444444; }
a.btn.active { background: #4a4a4a; border-color: #6a6a6a; }
td.wrap-cell { white-space: normal; max-width: 16rem; }
h1 { font-size: 1.35rem; margin: 0.2rem 0 0.4rem; color: var(--ink); }
.muted { color: var(--muted); font-size: 0.92rem; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.9rem 1rem 1.1rem;
  margin: 0.9rem 0;
}
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem 1rem;
  align-items: center;
  margin: 0.4rem 0 0.7rem;
}
.controls label { font-size: 0.9rem; color: var(--muted); }
select, button {
  background: #3a3a3a;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.28rem 0.5rem;
  font: inherit;
}
button { cursor: pointer; }
.ticks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.85rem;
  margin: 0.35rem 0 0.7rem;
}
.ticks label { font-size: 0.9rem; color: var(--muted); display: inline-flex; align-items: center; gap: 0.25rem; }
.swatch {
  display: inline-block;
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 2px;
  flex: 0 0 auto;
}
.table-wrap { overflow-x: auto; }
table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.88rem;
  color: var(--ink);
}
th, td {
  border-bottom: 1px solid var(--line);
  padding: 0.38rem 0.5rem;
  text-align: left;
  white-space: nowrap;
}
th { color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
th.day, td.day { background: #243044; }
th.day-start, td.day-start { border-left: 3px solid #3d6ea8; }
th.day-sep, td.day-sep {
  width: 0.45rem;
  min-width: 0.45rem;
  padding: 0;
  border-left: 3px solid #5b8ec9;
  background: #1b2838;
}
td.day-pos { color: #1b8a3a; font-weight: 600; }
td.day-neg { color: #c0392b; font-weight: 600; }
.chart-box { position: relative; width: 100%; height: 360px; }
.chart-box canvas { width: 100%; height: 100%; display: block; }
.pie-layout {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem 1.5rem;
}
.pie-box { position: relative; width: 280px; height: 280px; flex: 0 0 auto; }
.pie-box canvas { width: 100%; height: 100%; display: block; }
.pie-legend {
  list-style: none;
  margin: 0;
  padding: 0;
  min-width: 10rem;
}
.pie-legend li {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--muted);
  font-size: 0.9rem;
  padding: 0.12rem 0;
}
.pie-legend .pct {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.tooltip {
  position: absolute;
  pointer-events: none;
  display: none;
  background: #1a1a1a;
  color: #f4f4f4;
  font-size: 0.78rem;
  padding: 0.4rem 0.55rem;
  border-radius: 6px;
  max-width: 16rem;
  z-index: 3;
}
.warn {
  background: var(--warn-bg);
  color: var(--warn);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  margin: 0.4rem 0;
}
.back { margin-bottom: 0.6rem; }
.back a { color: var(--muted); }
footer { color: var(--muted); font-size: 0.8rem; margin-top: 1.2rem; }
.val-gain { color: #1b8a3a; }
.val-loss { color: #c0392b; }
td.val-gain, .day-line.val-gain span:not(.day-prefix) { color: #1b8a3a; }
td.val-loss, .day-line.val-loss span:not(.day-prefix) { color: #c0392b; }
.book-title { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.ccy { position: relative; }
.ccy-btn {
  height: 32px; min-width: 64px; padding: 0 10px;
  background: var(--card); color: var(--ink); border: 1px solid var(--line);
  border-radius: 2px; font: inherit; font-weight: 600; cursor: pointer;
}
.ccy-menu {
  position: absolute; right: 0; top: 36px; z-index: 20; margin: 0; padding: 4px;
  list-style: none; background: var(--card); border: 1px solid var(--line); min-width: 76px;
}
.ccy-menu[hidden] { display: none; }
.ccy-menu button {
  display: block; width: 100%; height: 32px; background: transparent; color: var(--muted);
  border: 0; text-align: left; padding: 0 10px; cursor: pointer;
}
.ccy-menu button[aria-current="true"] { color: var(--ink); background: #3c3c3c; }
.metric-strip {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
  margin: 0.6rem 0 1rem;
}
.metric-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 9px 12px;
}
.metric-label {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 4px;
}
.metric-value { font-size: 15px; font-weight: 600; }
.book-cards { display: none; }
.book-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
}
.book-split .card { margin: 0; }
tr.holding-row { cursor: pointer; }
tr.holding-more[hidden] { display: none; }
tr.holding-more td { background: #2e2e2e; white-space: normal; }
.row-more { display: flex; flex-wrap: wrap; gap: 8px 22px; align-items: center; }
.row-more a { color: var(--ink); }
.arrow-cell { width: 28px; text-align: center; }
.chevron {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(45deg);
  margin-top: -3px;
}
tr.holding-row.open .chevron, article.holding-card.open .chevron {
  transform: rotate(-135deg);
  margin-top: 3px;
}
.holding-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 6px 12px 4px;
  margin-bottom: 8px;
  cursor: pointer;
}
.card-row-1, .card-row-2, .card-row-3 {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 8px;
}
.card-row-1 { align-items: baseline; margin-bottom: 6px; }
.card-row-3 { justify-content: flex-end; }
.card-corner { display: flex; align-items: center; gap: 8px; }
.holding-symbol { font-weight: 600; }
.holding-company { color: var(--muted); font-size: 11px; margin-left: 6px; }
.holding-price, .holding-val { font-size: 17px; font-weight: 600; }
.holding-pl { font-size: 15px; font-weight: 600; margin-left: 8px; }
.day-line { display: flex; flex-direction: column; align-items: flex-end; font-size: 15px; font-weight: 600; }
.day-prefix { font-size: 12px; font-weight: 500; color: var(--muted); }
.card-more { display: none; margin-top: 8px; padding-top: 8px; border-top: 1px solid #3d3d3d; }
.holding-card.open .card-more { display: block; }
.more-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 18px; }
.more-grid > div { display: flex; justify-content: space-between; gap: 8px; }
.more-lbl { color: var(--muted); }
.card-links { display: flex; gap: 16px; padding-top: 6px; }
.card-links a { color: var(--ink); }
@media (max-width: 700px) {
  .chart-box { height: 280px; }
  th, td { font-size: 0.8rem; }
  .page-portfolio .metric-strip { grid-template-columns: 1fr 1fr; }
  .page-portfolio .book-table { display: none; }
  .page-portfolio .book-cards { display: block; }
  .page-portfolio .book-split { grid-template-columns: 1fr; }
  .page-portfolio .header-inner { align-items: stretch; }
  .page-portfolio header nav { width: 100%; }
  .page-portfolio header nav a.btn { flex: 1; text-align: center; min-height: 44px; line-height: 44px; padding: 0; }
  .page-portfolio header nav { display: flex; }
}
