.viz-root {
  color-scheme: light;
  --surface-1:      #fcfcfb;
  --page:           #f9f9f7;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --gridline:       #e1e0d9;
  --baseline:       #c3c2b7;
  --border:         rgba(11, 11, 11, 0.10);
  --series-1:       #2a78d6;  /* מקדמה */
  --series-2:       #eb6834;  /* קרן */
  --series-3:       #1baf7a;  /* ריבית */
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .viz-root {
    color-scheme: dark;
    --surface-1:      #1a1a19;
    --page:           #0d0d0d;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --gridline:       #2c2c2a;
    --baseline:       #383835;
    --border:         rgba(255, 255, 255, 0.10);
    --series-1:       #3987e5;
    --series-2:       #d95926;
    --series-3:       #199e70;
  }
}
:root[data-theme="dark"] .viz-root {
  color-scheme: dark;
  --surface-1:      #1a1a19;
  --page:           #0d0d0d;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --gridline:       #2c2c2a;
  --baseline:       #383835;
  --border:         rgba(255, 255, 255, 0.10);
  --series-1:       #3987e5;
  --series-2:       #d95926;
  --series-3:       #199e70;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
}
:root { color-scheme: light dark; }
@media (prefers-color-scheme: dark) { body { background: #0d0d0d; color: #fff; } }

main {
  max-width: 860px;
  margin: 0 auto;
  padding: 2rem 1rem 4rem;
  display: grid;
  gap: 1rem;
}

.head { margin-bottom: .25rem; }
h1 { font-size: 1.5rem; margin: 0 0 .35rem; letter-spacing: -0.01em; }
h2 { font-size: 1rem; margin: 0 0 .2rem; }
.sub { color: var(--text-secondary); font-size: .875rem; margin: 0; }

.panel {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.15rem 1.25rem;
}

/* ---------- controls ---------- */
.controls { display: grid; gap: 1.05rem; }
.field label {
  display: block;
  font-size: .8rem;
  color: var(--text-secondary);
  margin-bottom: .45rem;
  font-weight: 500;
}
.hint { color: var(--text-muted); font-weight: 400; }
.row { display: flex; align-items: center; gap: .85rem; }

.legend-label {
  display: block;
  font-size: .8rem;
  color: var(--text-secondary);
  margin-bottom: .45rem;
  font-weight: 500;
}

/* segmented control: which side of the calculation is the answer */
.modes { display: flex; gap: 2px; background: var(--page); border-radius: 9px; padding: 2px; }
.modes .mode { flex: 1; }
.modes input { position: absolute; opacity: 0; pointer-events: none; }
.modes span {
  display: block;
  text-align: center;
  padding: .45rem .6rem;
  border-radius: 7px;
  font-size: .85rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
}
.modes span:hover { color: var(--text-primary); }
.modes input:checked + span {
  background: var(--surface-1);
  color: var(--text-primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .10);
}
.modes input:focus-visible + span { outline: 2px solid var(--series-1); outline-offset: 2px; }

input[type="range"] {
  flex: 1;
  min-width: 0;
  accent-color: var(--series-1);
  height: 1.5rem;
}
.num {
  width: 7.5rem;
  flex: none;
  padding: .4rem .55rem;
  font: inherit;
  font-size: .9rem;
  font-variant-numeric: tabular-nums;
  text-align: start;
  color: var(--text-primary);
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.num:focus-visible, input[type="range"]:focus-visible, .toggle:focus-visible {
  outline: 2px solid var(--series-1);
  outline-offset: 2px;
}

/* ---------- figures ---------- */
.label {
  font-size: .8rem;
  color: var(--text-secondary);
  margin: 0 0 .3rem;
  font-weight: 500;
}
.hero { text-align: center; padding: 1.6rem 1.25rem; }
.hero-figure {
  font-size: 3rem;
  font-weight: 600;
  line-height: 1.1;
  margin: 0;
  letter-spacing: -0.02em;
}
.hero-note { color: var(--text-muted); font-size: .8rem; margin: .45rem 0 0; }

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.tile .value { font-size: 1.4rem; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
.tile-note { color: var(--text-muted); font-size: .75rem; margin: .3rem 0 0; }
@media (max-width: 640px) {
  .tiles { grid-template-columns: 1fr; }
  .hero-figure { font-size: 2.25rem; }
}

.notes:empty { display: none; }
.notes p {
  margin: 0 0 .4rem;
  padding: .6rem .8rem;
  border-radius: 8px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: .82rem;
}

/* ---------- charts ---------- */
.chart-card h2 + .sub { margin-bottom: .9rem; }
.chart-wrap { position: relative; }
#curve { display: block; width: 100%; height: 240px; overflow: visible; }

.tooltip {
  position: absolute;
  pointer-events: none;
  transform: translate(-50%, -135%);
  background: var(--surface-1);
  border: 1px solid var(--border);
  box-shadow: 0 2px 10px rgba(0, 0, 0, .12);
  border-radius: 8px;
  padding: .45rem .6rem;
  font-size: .78rem;
  white-space: nowrap;
  color: var(--text-primary);
}
.tooltip b { font-variant-numeric: tabular-nums; font-weight: 600; }
.tooltip span { color: var(--text-secondary); }

/* single stacked bar: 2px surface gaps do the separating */
.stack {
  display: flex;
  gap: 2px;
  height: 24px;
  margin: .25rem 0 1rem;
}
.stack > i { display: block; min-width: 2px; }
/* logical radii so the bar's leading end is rounded under rtl */
.stack > i:first-child {
  border-start-start-radius: 4px;
  border-end-start-radius: 4px;
}
.stack > i:last-child {
  border-start-end-radius: 4px;
  border-end-end-radius: 4px;
}

.legend { list-style: none; padding: 0; margin: 0; display: grid; gap: .5rem; }
.legend li { display: flex; align-items: center; gap: .55rem; font-size: .85rem; }
.legend .swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend .name { color: var(--text-secondary); }
.legend .amount { margin-inline-start: auto; font-variant-numeric: tabular-nums; font-weight: 600; }
.legend .pct { color: var(--text-muted); font-variant-numeric: tabular-nums; min-width: 3.2rem; text-align: start; }

/* ---------- table ---------- */
.toggle {
  font: inherit;
  font-size: .85rem;
  font-weight: 500;
  color: var(--text-primary);
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .5rem .9rem;
  cursor: pointer;
}
.toggle:hover { border-color: var(--text-muted); }
.table-scroll { overflow-x: auto; margin-top: 1rem; }
table { border-collapse: collapse; width: 100%; font-size: .82rem; }
th, td {
  text-align: start;
  padding: .4rem .6rem;
  border-bottom: 1px solid var(--gridline);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
th { color: var(--text-secondary); font-weight: 600; }
td { color: var(--text-primary); }
