  :root {
    color-scheme: light dark;
    --surface: var(--sur);
    --muted: var(--mut);
    --value: var(--a);
    --value-soft: color-mix(in srgb, var(--a) 14%, transparent);
    --invested: var(--mut);
    --loss: var(--bad);
    --gain: var(--ok);
    --focus: var(--a);
    --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
    --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  }
  * { box-sizing: border-box; }
  body {
    margin: 0; background: var(--bg); color: var(--ink);
    font-family: var(--sans); font-size: 15px; line-height: 1.45;
    -webkit-text-size-adjust: 100%;
  }
  main { width: 100%; max-width: 760px; margin: 0 auto; padding: 20px 16px 48px; }
  h1 { font-family: var(--serif); font-weight: 600; font-size: 24px; margin: 4px 0 4px; letter-spacing: -.01em; }
  .sub { color: var(--muted); margin: 0 0 18px; }
  .panel { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 14px; }
  h2 { font-size: 15px; font-weight: 600; margin: 0 0 2px; }
  .hint { color: var(--muted); font-size: 13px; margin: 0 0 12px; }

  .controls { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
  .controls .wide { grid-column: 1 / -1; }
  label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
  input[type=number] {
    width: 100%; padding: 10px 10px; font: inherit; font-size: 16px; color: var(--ink);
    background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  }
  .money { position: relative; }
  .money span { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); }
  .money input { padding-left: 22px; }
  :focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

  .seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
  .seg button {
    font: inherit; font-size: 14px; padding: 8px 14px; border: 0; background: transparent; color: var(--muted); cursor: pointer;
  }
  .seg button[aria-pressed=true] { background: var(--ink); color: var(--surface); }

  .presets { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
  .presets button {
    font: inherit; font-size: 13px; padding: 6px 11px; border-radius: 999px; cursor: pointer;
    border: 1px solid var(--line); background: transparent; color: var(--ink);
  }
  .presets button:hover { border-color: var(--muted); }

  .result-main { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px; }
  .big { font-family: var(--serif); font-size: 40px; font-weight: 600; letter-spacing: -.02em; line-height: 1.1; }
  .delta { font-size: 16px; font-weight: 600; }
  .pos { color: var(--gain); } .neg { color: var(--loss); }
  .stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px 16px; margin-top: 14px; }
  .stat .k { font-size: 12.5px; color: var(--muted); }
  .stat .v { font-family: var(--serif); font-size: 19px; font-weight: 600; }

  .chartwrap { position: relative; width: 100%; min-width: 0; }
  canvas { width: 100%; max-width: 100%; display: block; touch-action: pan-y; }
  #c1 { height: 260px; }
  #c2 { height: 220px; }
  .legend { display: flex; gap: 16px; font-size: 13px; color: var(--muted); margin-top: 6px; flex-wrap: wrap; }
  .legend i { display: inline-block; width: 18px; height: 0; border-top: 3px solid; vertical-align: middle; margin-right: 6px; }
  .tip {
    position: absolute; pointer-events: none; background: var(--ink); color: var(--surface);
    font-size: 12.5px; padding: 6px 9px; border-radius: 6px; white-space: nowrap; display: none; z-index: 2;
  }
  .note { font-size: 12.5px; color: var(--muted); margin-top: 10px; }
  .summary { font-size: 14px; margin: 10px 0 0; }
  @media (min-width: 560px) { .stats { grid-template-columns: repeat(4, 1fr); } .big { font-size: 46px; } }
