:root {
  color-scheme: light;
  --surface: #fff;
  --ink: #182338;
  --muted: #526074;
  --line: #e1e7ef;
  --blue: #245cc4;
  --gain-bar: #f7edcb;
  --loss-bar: #f6e1e5;
  --mono: ui-monospace, "SF Mono", Consolas, monospace;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--surface);
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { overflow: hidden; overscroll-behavior: none; }
body { margin: 0; font-size: 14px; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
h1, h2, p, fieldset { margin: 0; }
:focus-visible { outline: 2px solid #245cc4; outline-offset: 3px; }
[hidden] { display: none !important; }
.skip { position: fixed; z-index: 4; top: 8px; left: 8px; padding: 12px; background: white; transform: translateY(-160%); }
.skip:focus { transform: none; }
.workspace { display: grid; grid-template-columns: 282px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); height: 100dvh; }
.settings { overflow: auto; min-height: 0; padding: 26px 22px; border-right: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; padding-bottom: 22px; margin-bottom: 24px; border-bottom: 1px solid var(--line); }
.brand span { font-size: 17px; font-weight: 750; }
h2 { font-size: 20px; line-height: 1.3; letter-spacing: -.025em; }
.settings h2 { font-size: 15px; margin-bottom: 18px; }
#settings-toggle { display: none; }
#settings { display: grid; gap: 15px; }
.amount-field > label, legend { display: block; font-size: 13px; font-weight: 700; margin-bottom: 7px; }
fieldset { padding: 0; border: 0; min-width: 0; }
legend { padding: 0; }
.amount { background: #fff; border: 1px solid #dbe3ef; border-radius: 8px; min-height: 42px; width: 100%; }
.panel, .metric { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.segmented { display: flex; gap: 3px; background: #f2f5fa; border: 1px solid #e8edf5; padding: 3px; border-radius: 9px; }
.segmented label { flex: 1; position: relative; text-align: center; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented label span, .segmented button { display: block; padding: 8px 10px; border: 0; border-radius: 6px; color: var(--muted); background: transparent; font-size: 12px; white-space: nowrap; }
.segmented input:checked + span, .segmented button[aria-pressed=true] { background: var(--surface); color: var(--blue); font-weight: 700; box-shadow: 0 1px 4px #192e5316; }
.segmented input:focus-visible + span { outline: 2px solid #245cc4; }
.amount { display: flex; align-items: center; padding: 0 10px; gap: 7px; }
.amount:focus-within { outline: 2px solid #245cc4; outline-offset: 2px; }
.amount span { color: var(--muted); font: 12px var(--mono); }
.amount input { border: 0; background: transparent; flex: 1; min-width: 0; padding: 9px 0; outline: none; font-weight: 700; }
.run, .edit-curve { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; padding: 11px 14px; border: none; border-radius: 8px; color: white; background: #245cc4; font-weight: 700; min-height: 44px; }
.run:hover { background: #1d4da8; }
.edit-curve { color: var(--blue); background: white; border: 1px solid #dbe3ef; }
.edit-curve:hover { background: #eff5ff; }
.error { color: #9a3d30; font-size: 12px; margin-top: 10px; line-height: 1.5; }
.curve-dialog { width: min(760px, calc(100% - 24px)); max-height: calc(100dvh - 24px); color: var(--ink); padding: clamp(13px, 4vw, 22px); box-shadow: 0 20px 70px #182e5355; }
.curve-dialog::backdrop { background: #192b457a; }
.curve-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
#curve-help { color: var(--muted); margin: 9px 0 15px; font-size: 13px; line-height: 1.6; }
.curve-preview { margin-bottom: 12px; padding: 5px 8px 9px; background: #f4f7fc; border: 1px solid var(--line); border-radius: 10px; }
#curve-preview { display: block; width: 100%; max-height: 40dvh; user-select: none; touch-action: none; }
#curve-preview-hit { fill: none; stroke: transparent; stroke-width: 24; pointer-events: stroke; cursor: grab; }
.curve-handle { fill: var(--blue); stroke: #f4f7fc; stroke-width: 2.5; cursor: grab; }
.curve-handle:hover, .curve-handle:focus, .curve-handle[data-dragging] { fill: #245cc4; stroke: #aac6ff; stroke-width: 4; outline: none; }
.curve-handle[data-dragging] { cursor: grabbing; }
.curve-start { fill: var(--surface); stroke: var(--blue); stroke-width: 2.5; }
.curve-preview-footer { display: flex; justify-content: space-between; gap: 6px; min-height: 15px; color: var(--muted); font: 10px var(--mono); }
#curve-point-value { color: var(--blue); text-align: right; }
.curve-points { display: grid; gap: 9px; max-height: min(210px, 28dvh); overflow: auto; padding: 3px 5px; }
.curve-row { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr) auto; gap: 8px; align-items: end; }
.curve-row label { display: grid; gap: 4px; min-width: 0; color: var(--muted); font-size: 11px; }
.curve-row input { width: 100%; min-width: 0; min-height: 40px; border: 1px solid #dbe3ef; border-radius: 8px; background: #fff; padding: 0 6px; color: var(--ink); font-size: 13px; }
.curve-row input:read-only { background: #f4f7fc; color: var(--muted); }
.curve-row button, .curve-close, .curve-add { border: 1px solid var(--line); background: #eff3fa; color: var(--blue); border-radius: 8px; }
.curve-row button, .curve-close { width: 34px; height: 40px; font-size: 19px; }
.curve-add { padding: 7px 10px; margin: 10px 0; font-size: 12px; }
.curve-dialog button:disabled { cursor: default; opacity: .45; }
.curve-dialog .error { margin: 0 0 10px; }
.results { display: grid; grid-template-rows: minmax(158px, 1fr) auto; overflow: auto; gap: 14px; min-width: 0; min-height: 0; padding: clamp(16px, 2.2vw, 32px); }
.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.metric { display: grid; align-content: start; gap: 8px; min-width: 0; padding: 17px 15px; }
.metric p { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); }
.metric strong { font-size: clamp(16px, 2.15vw, 29px); line-height: 1.13; font-variant-numeric: tabular-nums; letter-spacing: -.045em; overflow-wrap: anywhere; }
.metric small { color: var(--muted); font-size: 10px; line-height: 1.4; }
.main-metric { background: #eff5ff; border-color: #d7e5fa; }
.main-metric strong { color: var(--blue); }
[data-trend="1"] { color: #245cc4; }
[data-trend="-1"] { color: #a34435; }
.chart-panel { display: grid; grid-template-rows: auto auto auto minmax(0, 1fr) auto; min-width: 0; padding: 20px 20px 12px; }
.chart-heading { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 5px 12px; }
.chart-heading h1 { font-size: 20px; line-height: 1.3; letter-spacing: -.025em; }
.chart-heading a { color: var(--blue); font-size: 12px; text-underline-offset: 2px; white-space: nowrap; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 5px 15px; align-items: center; min-height: 27px; color: var(--muted); font-size: 11px; margin-top: 5px; }
.chart-legend span { display: flex; align-items: center; gap: 6px; }
.chart-legend i { display: inline-block; width: 15px; border-top: 2px solid var(--blue); border-radius: 2px; }
.chart-legend .dash { border-top: 2px dashed var(--muted); border-radius: 0; }
.chart-legend .dot { width: 7px; height: 7px; border: 0; border-radius: 50%; background: var(--blue); }
.chart-legend .bars-key { height: 8px; border: 0; background: linear-gradient(90deg, var(--gain-bar) 50%, var(--loss-bar) 50%); }
.chart-units { display: flex; justify-content: space-between; margin-top: 9px; color: var(--muted); font-size: 11px; }
.chart-units span:first-child { color: var(--blue); }
.chart { position: relative; min-width: 0; min-height: 0; }
#plot { display: block; width: 100%; height: 100%; touch-action: pan-y; }
.gridline { stroke: #e7ecf4; }
.funds-zero { stroke: #cbd4e1; }
.gain-bars { pointer-events: none; }
.gain-bar { fill: var(--gain-bar); }
.loss-bar { fill: var(--loss-bar); }
.axis { fill: #57647a; font: 10px var(--mono); }
.price-axis { fill: var(--blue); }
.curve, .price-curve { fill: none; stroke: var(--blue); stroke-linecap: round; stroke-linejoin: round; }
.curve { stroke-width: 2.4; }
.price-curve { stroke: var(--blue); stroke-width: 1.8; }
.investment-reference { stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 5 5; }
.buy-dot { fill: var(--blue); stroke: var(--surface); stroke-width: .7; }
.price-dot { fill: var(--blue); stroke: var(--surface); stroke-width: 1.3; }
.crosshair { stroke: #607089; stroke-dasharray: 3 3; }
.tooltip { pointer-events: none; position: absolute; top: 0; padding: 8px 10px; border-radius: 8px; background: #152747; color: white; font-size: 11px; line-height: 1.65; white-space: nowrap; box-shadow: 0 4px 12px #15274733; }
.tooltip div:first-child { color: #ffe399; font: 11px var(--mono); margin-bottom: 3px; }
.chart-footer { display: flex; justify-content: space-between; gap: 10px; margin-top: 5px; padding-top: 9px; border-top: 1px solid var(--line); color: var(--muted); font: 10px var(--mono); }
.chart-footer span { overflow-wrap: anywhere; }
.chart-footer span:last-child { text-align: right; }

@media (max-width: 880px) {
  .workspace { grid-template-columns: 235px minmax(0, 1fr); }
  .settings { padding-inline: 15px; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 660px), (max-width: 880px) and (max-height: 500px) {
  .workspace { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .settings { position: relative; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 8px; overflow: visible; padding: 8px 12px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { padding: 0; margin: 0; border: 0; }
  .settings h2 { display: none; }
  #settings-toggle { display: block; background: #eff5ff; border: 1px solid #d7e5fa; border-radius: 8px; color: var(--blue); padding: 7px 10px; font-weight: 700; }
  #settings { position: absolute; inset: calc(100% + 5px) 12px auto; max-width: 400px; max-height: calc(100dvh - 70px); overflow: auto; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 28px #15274726; }
  #settings-toggle[aria-expanded=false] + #settings { display: none; }
  #settings fieldset:last-of-type, #error { grid-column: 1 / -1; }
  .results { padding: 12px; gap: 10px; }
  .chart-panel { padding: 12px 9px 10px; }
  .chart-heading h1 { font-size: 17px; }
  .chart-legend { column-gap: 10px; }
  .metrics { gap: 8px; }
  .metric { padding: 12px; }
  .metric strong { font-size: clamp(18px, 5.3vw, 24px); }
}

.guide-page { overflow: auto; overscroll-behavior: auto; }
.guide-page body { overflow: visible; }
.guide { max-width: 744px; margin: 0 auto; padding: 34px 20px 56px; line-height: 1.65; }
.guide nav { padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.guide h1 { margin: 26px 0 10px; font-size: clamp(26px, 5vw, 40px); line-height: 1.14; letter-spacing: -.035em; }
.guide h2 { margin: 27px 0 8px; }
.guide p + p { margin-top: 10px; }
.guide a { color: var(--blue); text-underline-offset: 3px; }
.guide ol { padding-inline-start: 20px; }
.guide table { width: 100%; border-collapse: collapse; margin-block: 14px; font-variant-numeric: tabular-nums; }
.guide th, .guide td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: right; }
.guide th:first-child, .guide td:first-child { text-align: left; }
.guide .guide-action { display: inline-block; margin-top: 18px; font-weight: 700; }

@media (max-width: 880px) and (max-height: 740px) {
  .results { padding: 8px 12px; gap: 7px; }
  .chart-panel { padding-block: 8px; }
  .metric { padding: 7px 10px; gap: 3px; }
}

@media (min-width: 450px) and (max-height: 500px) and (max-width: 880px) {
  .chart-legend { min-height: 21px; }
  .chart-units { margin-top: 3px; }
  .metrics { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .metric strong { font-size: clamp(16px, 3vw, 22px); }
}
