:root {
  --green: #00b386; --green-soft: #e6f7f3; --red: #eb5b3c; --red-soft: #fdeeea;
  --ink: #44475b; --ink-strong: #121212; --muted: #7c7e8c; --line: #e9e9eb; --bg: #ffffff;
  --card: #ffffff; --shade: #f8f8f8; --radius: 12px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: Inter, -apple-system, Segoe UI, Roboto, sans-serif; color: var(--ink);
  background: var(--bg); font-size: 14px; -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 20px; }
.hidden { display: none !important; }
.pos { color: var(--green); } .neg { color: var(--red); } .muted { color: var(--muted); }

.topbar { position: sticky; top: 0; z-index: 10; background: #fff; border-bottom: 1px solid var(--line); }
.topbar-inner { display: flex; align-items: center; height: 64px; gap: 32px; }
.logo { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 20px; color: var(--ink-strong); letter-spacing: -.3px; }
.logo-mark { width: 28px; height: 28px; }
.logo span { font-weight: 500; } .logo b { font-weight: 800; }
.nav { display: flex; gap: 24px; flex: 1; }
.nav-link { font-weight: 500; color: var(--muted); padding: 21px 0; border-bottom: 2px solid transparent; }
.nav-link.active { color: var(--ink-strong); border-color: var(--green); }
.top-right { display: flex; gap: 8px; align-items: center; }
.pill { font-size: 12px; font-weight: 600; padding: 6px 10px; border-radius: 99px; background: var(--shade); color: var(--muted); }
.pill.open { background: var(--green-soft); color: var(--green); }
.badge { font-size: 11px; font-weight: 700; padding: 4px 8px; border-radius: 6px; letter-spacing: .4px; }
.badge-warn { background: #fff4e0; color: #b26a00; }

h1 { font-size: 26px; color: var(--ink-strong); margin: 0 0 4px; font-weight: 600; letter-spacing: -.3px; }
h2 { font-size: 18px; color: var(--ink-strong); margin: 0 0 14px; font-weight: 600; }
.section { margin: 28px 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }

/* Home */
.index-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin-top: 24px; }
.index-card .label { font-size: 13px; color: var(--muted); font-weight: 500; }
.index-card .val { font-size: 20px; font-weight: 600; color: var(--ink-strong); margin: 6px 0 2px; }
.index-card .chg { font-size: 13px; font-weight: 500; }

.tabs { display: inline-flex; gap: 6px; background: var(--shade); padding: 4px; border-radius: 99px; margin-bottom: 16px; }
.tab { border: 0; background: transparent; font: inherit; font-weight: 600; font-size: 13px; color: var(--muted);
  padding: 8px 16px; border-radius: 99px; cursor: pointer; }
.tab.active { background: #fff; color: var(--ink-strong); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

.lb { width: 100%; border-collapse: collapse; }
.lb th { text-align: right; font-size: 12px; font-weight: 500; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); }
.lb th:first-child, .lb th:nth-child(2) { text-align: left; }
.lb td { padding: 14px 12px; border-bottom: 1px solid var(--line); text-align: right; font-weight: 500; white-space: nowrap; }
.lb td:first-child, .lb td:nth-child(2) { text-align: left; }
.lb tr.row { cursor: pointer; transition: background .12s; }
.lb tr.row:hover { background: #fafafa; }
.rank { width: 28px; height: 28px; border-radius: 50%; display: inline-grid; place-items: center; background: var(--shade); font-weight: 700; font-size: 12px; }
.rank.r1 { background: #fff4d6; color: #a37400; } .rank.r2 { background: #eef0f3; } .rank.r3 { background: #fbe9df; color: #9a4d1c; }
.algo-name { font-weight: 600; color: var(--ink-strong); }
.algo-tag { font-size: 12px; color: var(--muted); margin-top: 2px; white-space: normal; }
.spark { width: 110px; height: 36px; }
.chip { display: inline-block; font-size: 11px; font-weight: 600; padding: 4px 8px; border-radius: 6px; }
.chip.live { background: var(--green-soft); color: var(--green); }
.chip.off { background: var(--shade); color: var(--muted); }
.table-scroll { overflow-x: auto; }

/* Algo page */
.back { color: var(--muted); font-weight: 500; display: inline-block; margin: 22px 0 14px; }
.algo-grid { display: grid; grid-template-columns: 1fr 340px; gap: 24px; align-items: start; }
.big-val { font-size: 30px; font-weight: 600; color: var(--ink-strong); margin-top: 14px; letter-spacing: -.5px; }
.big-chg { font-weight: 500; margin-top: 4px; }
.chart-box { position: relative; height: 320px; margin: 18px 0 8px; }
.ranges { display: flex; gap: 8px; flex-wrap: wrap; }
.range { border: 1px solid var(--line); background: #fff; font: inherit; font-size: 12px; font-weight: 600; color: var(--muted);
  padding: 6px 12px; border-radius: 99px; cursor: pointer; }
.range.active { border-color: var(--green); color: var(--green); background: var(--green-soft); }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.stat { padding: 14px 16px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.stat:nth-child(3n) { border-right: 0; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 16px; font-weight: 600; color: var(--ink-strong); margin-top: 4px; }

.btn { border: 0; font: inherit; font-weight: 600; font-size: 15px; padding: 13px 16px; border-radius: 8px; cursor: pointer; width: 100%; }
.btn-green { background: var(--green); color: #fff; } .btn-green:hover { filter: brightness(.95); }
.btn-red { background: #fff; color: var(--red); border: 1px solid var(--red); }
.btn-ghost { background: var(--shade); color: var(--ink-strong); }
.btn:disabled { opacity: .6; cursor: wait; }
.side-card { position: sticky; top: 84px; }
.side-card h3 { margin: 0 0 6px; font-size: 16px; color: var(--ink-strong); }
.side-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.side-row:last-of-type { border-bottom: 0; }
.field { margin: 10px 0; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
.field input { width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; font: inherit; color: var(--ink-strong); }
.field input:focus { outline: none; border-color: var(--green); }
.fields-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }

.years { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.year { border-radius: 8px; padding: 8px; text-align: center; font-size: 12px; }
.year b { display: block; font-size: 13px; margin-top: 2px; }
.trades { width: 100%; border-collapse: collapse; font-size: 13px; }
.trades th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding: 8px; border-bottom: 1px solid var(--line); }
.trades td { padding: 9px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.side-l { color: var(--green); font-weight: 600; } .side-s { color: var(--red); font-weight: 600; }
.note { font-size: 12px; color: var(--muted); line-height: 1.5; }
.loading { padding: 60px 0; text-align: center; color: var(--muted); }
.empty { padding: 26px; text-align: center; color: var(--muted); background: var(--shade); border-radius: var(--radius); }
.footer { color: var(--muted); font-size: 12px; padding: 30px 20px 40px; line-height: 1.6; border-top: 1px solid var(--line); margin-top: 40px; }

@media (max-width: 860px) {
  .algo-grid { grid-template-columns: 1fr; }
  .side-card { position: static; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stat:nth-child(3n) { border-right: 1px solid var(--line); }
  .stat:nth-child(2n) { border-right: 0; }
  .hide-sm { display: none; }
}

/* loading bar + modal */
.progress { height: 4px; background: var(--shade); border-radius: 4px; overflow: hidden; margin: 10px 0 4px; max-width: 360px; }
.progress > div { height: 100%; background: var(--green); width: 0; transition: width .2s; }
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: grid; place-items: center; z-index: 50; }
.modal { background: #fff; border-radius: var(--radius); padding: 22px; width: min(360px, 92vw); }
.modal h3 { margin: 0 0 8px; color: var(--ink-strong); }
.src { font-size: 11px; color: var(--muted); }

/* ---- v3: info tips, setup bar, running cards, list picker ---- */
.tip { display: inline-grid; place-items: center; width: 15px; height: 15px; border-radius: 50%; border: 1px solid #c4c6d0;
  color: var(--muted); font-size: 10px; font-weight: 700; font-style: italic; font-family: Georgia, serif; cursor: help;
  position: relative; vertical-align: middle; margin-left: 3px; text-transform: none; letter-spacing: 0; }
.tip:hover, .tip:focus { border-color: var(--green); color: var(--green); outline: none; }
.tip::after { content: attr(data-tip); position: absolute; left: 50%; bottom: calc(100% + 8px); transform: translateX(-50%);
  width: 260px; background: #1c2140; color: #fff; font: 400 12px/1.5 Inter, sans-serif; font-style: normal; text-align: left;
  padding: 10px 12px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.18); opacity: 0; pointer-events: none;
  transition: opacity .12s; z-index: 40; white-space: normal; }
.tip:hover::after, .tip:focus::after { opacity: 1; }
th .tip::after { left: auto; right: -10px; transform: none; }
.side-card .tip::after { left: auto; right: -20px; transform: none; }

.setup { margin: 14px 0 16px; padding: 14px 16px; background: #fbfbfc; }
.setup-row { display: flex; flex-wrap: wrap; gap: 14px 28px; align-items: flex-end; }
.setup-item label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.setup select, .side-card select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font: inherit; color: var(--ink-strong); background: #fff; min-width: 190px; }
.side-card select { width: 100%; min-width: 0; }
.setup-summary { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); font-size: 13px; line-height: 1.6; }
.setup-summary .muted { display: block; font-size: 12px; margin-top: 2px; }

.count { display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; background: var(--green-soft); color: var(--green); font-size: 12px; vertical-align: middle; }
.run-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.run-card { display: block; transition: border-color .12s, transform .12s; }
.run-card:hover { border-color: var(--green); transform: translateY(-1px); }
.run-top { display: flex; align-items: center; gap: 8px; color: var(--ink-strong); }
.dot-live { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.run-on { font-size: 12px; color: var(--muted); margin: 4px 0 10px; }
.run-val { font-size: 18px; font-weight: 600; color: var(--ink-strong); }
.run-val span { font-size: 13px; margin-left: 4px; }

.chip.list { background: #eef0ff; color: #3d4bd9; }
.chip.kind { font-weight: 500; }
.small { font-weight: 400; font-size: 13px; }
.verdict { margin: 14px 0 0; padding: 12px 14px; border-radius: 10px; font-size: 14px; }
.verdict.good { background: var(--green-soft); color: #00775a; }
.verdict.bad { background: #fff4e0; color: #8a5300; }
.running-banner { margin: 14px 0 0; padding: 10px 14px; border-radius: 10px; background: var(--green-soft); color: #00775a; font-size: 13px; }

.edu { background: #f7f8fc; border-radius: var(--radius); padding: 18px; }
.edu-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.edu h4 { margin: 0 0 6px; font-size: 13px; color: var(--ink-strong); }
.edu p { margin: 0; font-size: 13px; line-height: 1.55; }

.list-pick { max-height: 260px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; margin: 8px 0 12px; }
.lp-group { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin: 8px 0 4px; }
.lp { display: flex; align-items: center; gap: 8px; padding: 5px 0; font-size: 13px; cursor: pointer; }
.lp.running { color: var(--muted); }
.mine { margin-top: 12px; }
.link-btn { border: 0; background: none; color: var(--red); font: inherit; font-size: 12px; cursor: pointer; padding: 0 0 0 8px; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #1c2140; color: #fff; padding: 12px 18px; border-radius: 8px; font-weight: 500; z-index: 99; max-width: 90vw; }
@media (max-width: 860px) { .edu-grid { grid-template-columns: 1fr; } .tip::after { width: 220px; } }
.stats { overflow: visible; }
th .tip::after, .lb .tip::after { bottom: auto; top: calc(100% + 8px); }
