:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #131722;
  --muted: #6a6d78;
  --line: #e3e5ea;
  --accent: #2962ff;
  --long: #089981;
  --short: #f23645;
  --warn: #e67700;
  --warn-bg: #fff4e5;
  --bad-bg: #fdecee;
  --ok-bg: #e6f6f3;
  --seg: #eef0f3;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(19, 23, 34, .06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #171a21;
    --text: #e8eaed;
    --muted: #8b90a0;
    --line: #262a33;
    --accent: #4f7dff;
    --long: #22ab94;
    --short: #f7525f;
    --warn: #ffa94d;
    --warn-bg: #2e2416;
    --bad-bg: #2f1a1d;
    --ok-bg: #12261f;
    --seg: #20242c;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}

[hidden] { display: none !important; }

button { font: inherit; color: inherit; cursor: pointer; }

a { color: var(--accent); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}

h1, h2 { margin: 0 0 10px; font-weight: 600; }
h1 { font-size: 20px; }
h2 { font-size: 15px; }

/* ── 登录 ─────────────────────────────────────────── */

.login {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.login-card { width: min(360px, 100%); display: grid; gap: 14px; }

/* ── 布局 ─────────────────────────────────────────── */

.app {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 12px calc(16px + env(safe-area-inset-bottom));
}

.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 2px 10px;
  background: var(--bg);
}

.sym { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.px { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; margin-right: auto; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.on { background: var(--long); }
.dot.off { background: var(--short); }

/* 栅格列一律 minmax(0, 1fr)：默认的 auto 列会被图表画布的宽度撑开，
   手机上整页就横向溢出了。 */
.layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.chart-col, .side-col { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; align-content: start; min-width: 0; }

@media (min-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr) 400px; align-items: start; }
  .chart-col { position: sticky; top: 56px; }
}

/* ── 图表 ─────────────────────────────────────────── */

.chart-card { padding: 10px; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }

.chart { height: 52vh; min-height: 300px; max-height: 620px; }
@media (min-width: 960px) { .chart { height: 62vh; } }

.legend { display: flex; gap: 10px; font-size: 12px; color: var(--muted); }
.legend .k::before { content: ""; display: inline-block; width: 12px; height: 2px; vertical-align: middle; margin-right: 4px; background: currentColor; }
.legend .ema20 { color: #f0a000; }
.legend .ema50 { color: #7e57c2; }
.legend .swing::before { width: 0; height: 0; background: none; border: 4px solid transparent; border-bottom-color: var(--muted); margin-bottom: 4px; }

.chart-mode {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  padding: 6px 10px;
  margin-bottom: 8px;
  border-radius: 8px;
  background: var(--warn-bg);
  color: var(--warn);
}

.note { margin: 6px 2px 0; font-size: 12px; color: var(--muted); }

/* ── 分段按钮 ─────────────────────────────────────── */

.seg { display: inline-flex; background: var(--seg); border-radius: 8px; padding: 2px; }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: 6px; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }

.side { display: flex; }
.side button { flex: 1; padding: 9px; font-size: 16px; }
.side button.long.on { background: var(--long); color: #fff; }
.side button.short.on { background: var(--short); color: #fff; }

/* ── 状态 ─────────────────────────────────────────── */

.status {
  font-size: 13px;
  padding: 8px 12px;
  border-radius: var(--radius);
  background: var(--ok-bg);
  color: var(--text);
}
.status.bad { background: var(--bad-bg); }
.status b { font-weight: 600; }

.position { font-size: 14px; display: flex; flex-wrap: wrap; gap: 4px 14px; }
.position .lbl { color: var(--muted); }

/* ── 表单 ─────────────────────────────────────────── */

.plan { display: grid; gap: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }

.field { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.field > span { display: flex; align-items: center; justify-content: space-between; gap: 6px; }

input, textarea {
  width: 100%;
  font: inherit;
  font-size: 16px; /* 小于 16px 时 iOS 聚焦会放大页面 */
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-variant-numeric: tabular-nums;
}
textarea { resize: vertical; min-height: 52px; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

.pick button { padding: 6px 10px; font-size: 13px; }

.calc { font-size: 14px; min-height: 21px; font-variant-numeric: tabular-nums; }
.calc .bad { color: var(--short); font-weight: 600; }
.calc .muted { color: var(--muted); }

.primary {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  padding: 11px;
  font-size: 16px;
  font-weight: 600;
}
.primary:disabled { opacity: .55; cursor: default; }

.link { border: 0; background: none; color: var(--accent); padding: 0; }
.link.small { font-size: 13px; }

.msg { margin: 0; font-size: 13px; color: var(--short); min-height: 0; }
.msg:empty { display: none; }

/* ── 结果 ─────────────────────────────────────────── */

.result { display: grid; gap: 12px; }
.result .head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.result .when { font-size: 12px; color: var(--muted); }
.result .concl { font-weight: 600; font-size: 16px; margin: 0; }
.result ul.points { margin: 0; padding-left: 18px; display: grid; gap: 6px; }
.result ul.points li { line-height: 1.55; }

.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 12px; font-size: 13px; }
.facts div { display: flex; flex-direction: column; }
.facts .lbl { color: var(--muted); font-size: 12px; }

.levels { border-top: 1px solid var(--line); padding-top: 10px; display: grid; gap: 6px; font-size: 14px; }
.levels .row { display: flex; justify-content: space-between; gap: 10px; }
.levels .row .lbl { color: var(--muted); }
.levels .sw { display: inline-block; width: 14px; height: 0; border-top: 2px dashed; vertical-align: middle; margin-right: 6px; }
.levels .cond { color: var(--muted); font-size: 13px; }
.levels .warn { color: var(--warn); font-size: 13px; }

.badges { display: flex; gap: 6px; flex-wrap: wrap; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--seg); }
.badge.right { background: var(--ok-bg); color: var(--long); }
.badge.left { background: var(--bad-bg); color: var(--short); }

.meta { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }

.spinner { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.spinner::before {
  content: "";
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── 历史 ─────────────────────────────────────────── */

.hist { list-style: none; margin: 0; padding: 0; display: grid; }
.hist li { border-top: 1px solid var(--line); }
.hist li:first-child { border-top: 0; }
.hist button {
  width: 100%;
  text-align: left;
  border: 0;
  background: none;
  padding: 8px 2px;
  display: grid;
  gap: 2px;
}
.hist .l1 { display: flex; gap: 8px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.hist .l1 .s.long { color: var(--long); font-weight: 600; }
.hist .l1 .s.short { color: var(--short); font-weight: 600; }
.hist .l2 { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist .empty { color: var(--muted); font-size: 13px; padding: 4px 0; }

.foot { font-size: 12px; color: var(--muted); text-align: center; padding: 16px 0 4px; }
