:root {
  --bg: #fbfaf7;
  --panel: #ffffff;
  --panel-2: #f5f3ee;
  --line: #e7e3da;
  --text: #191817;
  --dim: #6d6a62;
  --faint: #9b978d;
  --accent: #b8860b;
  --accent-soft: #fdf6e3;
  --pos: #1d7a4f;
  --neg: #b0413e;
  --radius: 14px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121211;
    --panel: #1b1b19;
    --panel-2: #232320;
    --line: #2e2e2a;
    --text: #ecebe6;
    --dim: #9a968c;
    --faint: #6e6b63;
    --accent: #e0b04a;
    --accent-soft: #241f13;
    --pos: #5fc28d;
    --neg: #e0817e;
  }
}

:root[data-theme="dark"] {
  --bg: #121211;
  --panel: #1b1b19;
  --panel-2: #232320;
  --line: #2e2e2a;
  --text: #ecebe6;
  --dim: #9a968c;
  --faint: #6e6b63;
  --accent: #e0b04a;
  --accent-soft: #241f13;
  --pos: #5fc28d;
  --neg: #e0817e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: 940px;
  margin: 0 auto;
  padding: 40px 16px 80px;
}

.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

/* ---------- заголовок ---------- */

/* Одна кнопка-переключатель: показывает иконку той темы, в которую переключит.
   Живет в углу блока итога, поверх его световой рамки. */
.theme {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  color: var(--dim);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, transform 0.15s;
}

.theme:hover {
  color: var(--accent);
  border-color: var(--accent);
  transform: rotate(-18deg);
}

.theme:active { transform: scale(0.94); }
.theme:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.theme .icon {
  grid-area: 1 / 1;
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* В светлой теме предлагаем луну, в темной — солнце. */
.theme .sun { display: none; }
.theme .moon { display: block; }
:root[data-theme="dark"] .theme .sun { display: block; }
:root[data-theme="dark"] .theme .moon { display: none; }

/* ---------- итог портфеля ---------- */

.total {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 76px 22px 24px;
  margin-bottom: 26px;
}

.total .label {
  font-size: 11.5px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--faint);
}

.total .big {
  font-size: clamp(30px, 8vw, 44px);
  font-weight: 600;
  letter-spacing: -0.025em;
  margin: 6px 0 2px;
  line-height: 1.1;
}

.total .breakdown {
  color: var(--dim);
  font-size: 13.5px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
}

/* ---------- карточки фондов ---------- */

.funds { display: flex; flex-direction: column; gap: 12px; }

.fund {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.2s;
}

.fund.open { border-color: var(--accent); }
.fund:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.fund.empty { cursor: default; }

/* ---------- световая рамка за курсором ---------- */

/*
 * Кольцо толщиной в пиксель поверх собственной рамки карточки: градиент светится
 * там, где курсор, и гаснет к краям. Координаты приходят из JS в --mx/--my.
 * Две маски вырезают середину, оставляя только кромку, — поэтому текст не задет.
 */
.spot { position: relative; }

.spot::before {
  content: "";
  position: absolute;
  /* Строго по внутреннему краю: карточка режет все, что вылезает за границу. */
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: radial-gradient(170px circle at var(--mx) var(--my), var(--accent), transparent 72%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  mask-composite: exclude;
  opacity: 0;
  transition: opacity 0.3s ease-out;
  pointer-events: none;
  z-index: 1;
}

/* Курсора нет — эффекта нет: на тач-экранах подсветка залипала бы на карточке. */
@media (hover: hover) and (pointer: fine) {
  .spot.lit::before { opacity: 0.75; }
}

@media (prefers-reduced-motion: reduce) {
  .spot::before { transition: none; }
}

/* Все, что нужно щелкать самостоятельно, забирает курсор себе. */
.fund input, .fund a, .fund .tablewrap, .fund .chart-box { cursor: auto; }
.fund a { cursor: pointer; }

.fund.empty { opacity: 0.6; }

.fund-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  /* Справа место под шеврон в углу. */
  padding: 16px 38px 0 20px;
  flex-wrap: wrap;
}

/* Ручка перетаскивания: на виду только при наведении, чтобы не шуметь. */
.grip {
  flex: none;
  display: grid;
  place-items: center;
  width: 14px;
  margin-left: -4px;
  color: var(--faint);
  cursor: grab;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
  /* Иначе жест по ручке пролистывал бы страницу. */
  touch-action: none;
}

.grip svg { width: 10px; height: 16px; fill: currentColor; }
.fund:hover .grip { opacity: 1; }
.grip:hover { color: var(--accent); }
.grip:active { cursor: grabbing; }

@media (hover: none) {
  .grip { opacity: 1; }
}

.fund.dragging {
  border-color: var(--accent);
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.18);
  cursor: grabbing;
}
.fund.dragging .grip { opacity: 1; color: var(--accent); }

.code {
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 5px;
  padding: 2px 6px;
}

.fund-head h2 { font-size: 15.5px; font-weight: 600; margin: 0; }
.fund-head .pos { color: var(--faint); font-size: 12.5px; margin-left: auto; }
.fund-head .pos .num { color: var(--dim); }

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1px;
  background: var(--line);
  margin: 16px 0 0;
  border-top: 1px solid var(--line);
}

.metric { background: var(--panel); padding: 13px 20px; }
.metric .k { font-size: 11.5px; color: var(--faint); margin-bottom: 3px; }
.metric .v { font-size: 17px; font-weight: 600; letter-spacing: -0.015em; }
.metric .v small { font-size: 12px; font-weight: 400; color: var(--dim); }

/* Значение и подпись даты в одной плитке: подпись появляется с графиком. */
.metric .stack { display: flex; align-items: baseline; flex-wrap: wrap; gap: 3px 8px; }
.metric .meta { font-size: 12.5px; font-weight: 400; color: var(--dim); white-space: nowrap; }
.metric .meta.up { color: var(--pos); }
.metric .meta.down { color: var(--neg); }
.metric.mine { background: var(--panel-2); }
.metric.mine .v { color: var(--accent); }

input.units {
  font: inherit;
  font-size: 17px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  width: 100%;
  max-width: 150px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 3px 8px;
}
input.units:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input.units::-webkit-outer-spin-button, input.units::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* ---------- состав ---------- */

/* Единственный указатель на раскрытие: поворачивается, а не меняет символ. */
.chev {
  /* В углу, а не в потоке шапки: на узком экране статистика переносится на две
     строки, и шеврон в потоке оставался бы висеть один на третьей. */
  position: absolute;
  top: 18px;
  right: 18px;
  font-size: 11px;
  line-height: 1;
  color: var(--faint);
  transition: transform 0.28s cubic-bezier(0.22, 0.61, 0.36, 1), color 0.2s;
}
.chev::before { content: "\25b8"; display: block; }
.fund:hover .chev { color: var(--dim); }
.fund.open .chev { transform: rotate(90deg); color: var(--accent); }

/* ---------- раскрытие карточки ---------- */

/*
 * Затвор: сетка в одну строку, высота которой идет от 0fr к 1fr. В отличие от
 * height: auto это анимируется, и содержимое не нужно измерять.
 */
.shutter {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.34s cubic-bezier(0.22, 0.61, 0.36, 1);
}

.fund.open .shutter { grid-template-rows: 1fr; }

.panel {
  min-height: 0;
  overflow: hidden;
}

/* Первый блок панели примыкает к метрикам — своя рамка сверху у него есть. */
.panel > :first-child { border-top: 1px solid var(--line); }

/* Содержимое подтягивается следом за высотой, с небольшим запаздыванием. */
.panel > * {
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.22s ease-out, transform 0.28s cubic-bezier(0.22, 0.61, 0.36, 1);
}

.fund.open .panel > * {
  opacity: 1;
  transform: none;
  transition-delay: 0.1s;
}

@media (prefers-reduced-motion: reduce) {
  .shutter,
  .panel > *,
  .chev { transition: none; }
}

/* ---------- график стоимости пая ---------- */

.chart-box {
  border-top: 1px solid var(--line);
  padding: 14px 20px 10px;
  background: var(--panel-2);
}

.chart-track { touch-action: pan-y; }

svg.chart { display: block; width: 100%; height: 150px; overflow: visible; }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }

.chart-area {
  fill: var(--accent);
  stroke: none;
  opacity: 0.09;
}

.chart-dot { fill: var(--accent); }

/* До прорисовки линии заливки и точки нет: они догоняют ее к концу хода. */
svg.chart .chart-area,
svg.chart .chart-dot { transition: opacity 0.4s ease-out 0.3s; }
svg.chart:not(.drawn) .chart-area,
svg.chart:not(.drawn) .chart-dot { opacity: 0; transition: none; }
.chart-hover { fill: var(--panel); stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
.chart-cursor { stroke: var(--faint); stroke-width: 1; stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; }

.chart-scale {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--faint);
  margin-top: 2px;
}

.tablewrap { overflow-x: auto; border-top: 1px solid var(--line); }

table { border-collapse: collapse; width: 100%; font-size: 13px; }

th {
  text-align: left;
  font-weight: 500;
  font-size: 11.5px;
  color: var(--faint);
  padding: 9px 12px;
  background: var(--panel-2);
  white-space: nowrap;
  position: sticky;
  top: 0;
}

td { padding: 8px 12px; border-top: 1px solid var(--line); white-space: nowrap; }
td.name { white-space: normal; min-width: 190px; }
th.r, td.r { text-align: right; }
td.tick { font-family: var(--mono); font-size: 12px; color: var(--dim); }

/* Дорожка задает масштаб, полоса внутри — доля относительно крупнейшей позиции.
   Число рядом всегда настоящий процент. */
th.pct-head { text-align: right; }

td.pct { text-align: right; }

.pct-box {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 9px;
}

.track {
  flex: none;
  width: 58px;
  height: 6px;
  border-radius: 3px;
  background: var(--line);
  overflow: hidden;
}

.track .bar {
  display: block;
  height: 100%;
  min-width: 2px;
  border-radius: 3px;
  background: var(--accent);
  opacity: 0.85;
  transition: width 0.2s ease-out, opacity 0.12s;
}

.pct-text {
  flex: none;
  width: 46px;
  text-align: right;
}
td.big { font-weight: 600; }
tr.unpriced td { color: var(--faint); font-style: italic; }

@media (hover: hover) and (pointer: fine) {
  tbody tr { transition: background-color 0.12s; }
  tbody tr:hover { background: var(--panel-2); }
  tbody tr:hover .track .bar { opacity: 1; }
}


tfoot td {
  background: var(--panel-2);
  font-weight: 600;
  border-top: 1px solid var(--line);
}

.note {
  padding: 11px 20px;
  font-size: 12.5px;
  color: var(--dim);
  border-top: 1px solid var(--line);
}

footer {
  margin-top: 34px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  color: var(--faint);
  font-size: 12.5px;
}
footer p { margin: 0 0 7px; }
footer a { color: var(--dim); }

@media (max-width: 560px) {
  .wrap { padding: 26px 12px 60px; }
  /* На узком экране в таблицу помещается только «на вас»: остальное прячем. */
  td, th { padding: 8px 9px; }
  td.name { min-width: 118px; }
  .metric, .note, .chart-box { padding-left: 15px; padding-right: 15px; }
  .fund-head { padding: 15px 34px 0 15px; }
  .grip { margin-left: -2px; }
  .chev { top: 17px; right: 15px; }
  .total { padding: 18px 62px 18px 16px; }
  .theme { top: 13px; right: 13px; }
  svg.chart { height: 120px; }
  .metric .meta .from { display: none; }
  .track { width: 42px; }
  .pct-box { gap: 7px; }
  .hide-sm { display: none; }
}

.about {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin: 22px 0 0;
  font-size: 13px;
}
.about a { color: var(--dim); text-decoration: none; }
.about a:hover { color: var(--accent); text-decoration: underline; }
