:root {
  --teal: #05a090; --teal-ink: #036b60; --teal-tint: #e3f5f2;
  --navy: #0a2540; --ink: #011412;
  --bg: #f4f6f8; --paper: #ffffff; --text: #1b2733; --muted: #52606d; --line: #dde2e7;
  --up: #05a090; --down: #d9473a; --bh: #8593a3;
  --shadow: 0 1px 2px rgba(10, 37, 64, .06), 0 4px 16px rgba(10, 37, 64, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --teal: #2fd3bd; --teal-ink: #2fd3bd; --teal-tint: #0f3a37;
    --bg: #0b1622; --paper: #102131; --text: #e9f1f5; --muted: #a9bccb; --line: #213649;
    --up: #2fd3bd; --down: #ff6b5a; --bh: #7f93a6;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
}
a { color: var(--teal-ink); }
button, input, select { font: inherit; color: inherit; }

/* header */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 24px; background: var(--navy); color: #fff;
}
.logo { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 700; letter-spacing: .04em; }
.logo img { background: #fff; border-radius: 6px; padding: 3px 5px; height: 30px; width: auto; }
.logo b { font-weight: 500; color: #2fd3bd; letter-spacing: 0; margin-left: 4px; }
.langs { display: flex; gap: 2px; background: rgba(255,255,255,.08); border-radius: 8px; padding: 2px; }
.langs button { border: 0; background: none; color: #cfe0ea; padding: 4px 9px; border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 600; }
.langs button[aria-pressed="true"] { background: #fff; color: var(--navy); }

.hero { max-width: 1280px; margin: 0 auto; padding: 28px 24px 8px; }
.eyebrow { margin: 0; color: var(--teal-ink); font-weight: 600; font-size: 12px; letter-spacing: .1em; text-transform: uppercase; }
.hero h1 { margin: 4px 0 6px; font-size: clamp(24px, 3.2vw, 34px); line-height: 1.15; color: var(--text); text-wrap: balance; }
.lead { margin: 0; color: var(--muted); max-width: 60ch; }

/* layout */
.layout {
  max-width: 1280px; margin: 0 auto; padding: 16px 24px 32px;
  display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 20px; align-items: start;
}
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); }
.results > * + * { margin-top: 16px; }
.results .panel + .panel, #out > * + * { margin-top: 16px; }

/* form */
.form { position: sticky; top: 12px; }
fieldset { border: 0; margin: 0 0 14px; padding: 0 0 14px; border-bottom: 1px solid var(--line); }
legend { font-weight: 700; font-size: 14px; margin-bottom: 8px; padding: 0; }
label { display: block; margin-top: 8px; font-size: 13px; color: var(--muted); }
label > span { display: block; margin-bottom: 3px; font-weight: 500; }
input, select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--text); font-size: 14px; min-height: 38px;
}
input:focus, select:focus { outline: 2px solid var(--teal); outline-offset: -1px; }
input[type=file] { padding: 6px; }
small { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }
small.ok { color: var(--teal-ink); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.desc { font-size: 13px; color: var(--muted); margin: 6px 0 0; }
.params { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }

.seg { display: flex; background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button { flex: 1; border: 0; background: none; padding: 6px 4px; border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 500; color: var(--muted); white-space: nowrap; }
.seg button[aria-selected="true"] { background: var(--paper); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.12); font-weight: 600; }
.seg.small { display: inline-flex; }
.seg.small button { flex: none; padding: 5px 10px; }

.btn {
  display: block; width: 100%; margin-top: 8px; padding: 10px 14px; border-radius: 9px; cursor: pointer;
  border: 1px solid var(--line); background: var(--paper); font-weight: 600; font-size: 14px;
}
.btn:hover { border-color: var(--teal); }
.btn.primary { background: var(--teal); border-color: var(--teal); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #062421; } }
.btn.primary:hover { filter: brightness(1.05); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn.small { display: inline-block; width: auto; margin: 0; padding: 5px 10px; font-size: 13px; }
.status { min-height: 20px; margin-top: 8px; font-size: 13px; color: var(--muted); }
.status.err { color: var(--down); }
.progress { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; margin-top: 6px; }
.progress i { display: block; height: 100%; background: var(--teal); width: 0; transition: width .2s; }

/* results */
.empty { text-align: center; padding: 56px 24px; color: var(--muted); }
.empty svg { width: 120px; color: var(--teal); }
.empty h2 { color: var(--text); margin: 12px 0 4px; font-size: 18px; }
.out-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.out-head h2 { margin: 0; font-size: 18px; }
.out-head h2 small { display: inline; font-weight: 400; margin-left: 6px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.kpi { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); }
.kpi .k { font-size: 12px; color: var(--muted); font-weight: 500; }
.kpi .v { font-size: 22px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi .s { font-size: 12px; color: var(--muted); margin-top: 2px; font-variant-numeric: tabular-nums; }
.pos { color: var(--up); } .neg { color: var(--down); }

.chart-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.chart-head h3 { margin: 0; }
.check { display: inline-flex; align-items: center; gap: 6px; margin: 0; cursor: pointer; }
.check input { width: auto; min-height: 0; }
.chart-box { position: relative; height: 380px; }
h3 { font-size: 15px; margin: 0 0 10px; }

.table-wrap { overflow-x: auto; }
.table-wrap.trades { max-height: 420px; overflow-y: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.tbl th, .tbl td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.tbl th:first-child, .tbl td:first-child { text-align: left; }
.tbl thead th { position: sticky; top: 0; background: var(--paper); color: var(--muted); font-weight: 600; font-size: 12px; }
.tbl tbody tr:hover { background: var(--bg); }
.tbl .best { font-weight: 700; }
.tag { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 11px; background: var(--bg); border: 1px solid var(--line); }
.tag.stop { color: var(--down); } .tag.take { color: var(--up); } .tag.open { color: var(--teal-ink); }
.note { font-size: 12px; color: var(--muted); }

.foot { max-width: 1280px; margin: 0 auto; padding: 8px 24px 40px; font-size: 12px; color: var(--muted); }
.foot p { margin: 4px 0; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 8px 16px; border-radius: 8px; font-size: 14px; z-index: 10; }

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 12px 16px 24px; }
  .form { position: static; }
  .hero { padding: 20px 16px 4px; }
  .top { padding: 10px 16px; }
  .foot { padding: 8px 16px 32px; }
  .chart-box { height: 300px; }
}
@media (max-width: 420px) {
  .logo span { font-size: 13px; }
  .kpi .v { font-size: 19px; }
  .seg button { font-size: 12px; }
}

/* custom strategies */
.custom + .panel, .custom + .custom { margin-top: 16px; }
.rule-group { margin-bottom: 14px; }
.rule-head { font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.rows { display: grid; gap: 6px; margin-bottom: 6px; }
.rule { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 8px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); }
.rule .opnd { display: inline-flex; gap: 4px; align-items: center; }
.rule select, .rule input { width: auto; min-height: 32px; padding: 4px 8px; font-size: 13px; background: var(--paper); }
.rule input[type=number] { width: 68px; }
.rule .op { font-weight: 600; }
.rule .del { margin-left: auto; border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 18px; line-height: 1; padding: 2px 6px; border-radius: 6px; }
.rule .del:hover { color: var(--down); background: var(--paper); }
.btn.ghost { border-style: dashed; background: none; }
.formula-box { margin-top: 6px; border-top: 1px solid var(--line); padding-top: 10px; }
.formula-box summary { cursor: pointer; font-weight: 600; font-size: 13px; }
textarea.code {
  width: 100%; font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); resize: vertical; tab-size: 4;
}
textarea.code:focus { outline: 2px solid var(--teal); outline-offset: -1px; }
textarea.editor { min-height: 360px; white-space: pre; overflow: auto; }
small.warn { color: #b7791f; }
code#funcList { font-size: 12px; word-break: break-word; }
.py-out-head { font-size: 12px; font-weight: 600; color: var(--muted); margin-top: 10px; }
.py-out { margin: 4px 0 0; max-height: 220px; overflow: auto; padding: 8px 10px; border-radius: 8px; background: var(--navy); color: #d6e6ee; font: 12px/1.45 ui-monospace, Menlo, Consolas, monospace; white-space: pre-wrap; min-height: 36px; }
.py-out.err { color: #ffb4aa; }
