:root {
  --bg: #080c11;
  --bg-soft: #0d131b;
  --card: #121a24;
  --card-hi: #18222e;
  --line: #22303f;
  --line-soft: #1a2532;
  --text: #e9f0f8;
  --muted: #8595aa;
  --dim: #5d6c80;
  --accent: #3ddc97;
  --accent-dim: rgba(61, 220, 151, .12);
  --up: #ff5269;
  --down: #15c98a;
  --warn: #f0b542;
  --radius: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body {
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
  background-image:
    radial-gradient(120% 60% at 50% -10%, rgba(61, 220, 151, .10), transparent 60%),
    radial-gradient(90% 50% at 100% 0%, rgba(64, 132, 255, .08), transparent 55%);
  background-repeat: no-repeat;
}

.num { font-variant-numeric: tabular-nums; letter-spacing: -.02em; }

/* ---------------------------------------------------------------- 顶栏 */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: rgba(8, 12, 17, .82);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line-soft);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: .02em;
}

.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
}

.asof { font-size: 12px; color: var(--dim); }

.top-right { display: flex; align-items: center; gap: 10px; }

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  display: grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
}
.icon-btn:active { transform: scale(.94); }
.icon-btn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.5; }

/* ---------------------------------------------------------------- 设置面板 */
.sheet { position: fixed; inset: 0; z-index: 50; display: none; }
.sheet.open { display: block; }

.sheet-mask {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .58);
  backdrop-filter: blur(3px);
}

.sheet-panel {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  max-height: 88vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-soft);
  border-top: 1px solid var(--line);
  border-radius: 22px 22px 0 0;
  padding: 16px 16px calc(22px + env(safe-area-inset-bottom));
  animation: sheetUp .22s ease-out;
}
@keyframes sheetUp { from { transform: translateY(26px); opacity: .5; } }

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.sheet-head b { font-size: 16px; }
.sheet-close {
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 14px;
  font-weight: 620;
  padding: 4px 2px;
  cursor: pointer;
}

.sheet-body h4 {
  font-size: 11.5px;
  color: var(--dim);
  letter-spacing: .08em;
  margin: 20px 0 8px;
}
.sheet-body h4:first-child { margin-top: 0; }

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
  padding: 10px 0 12px;
  color: var(--text);
}
.switch-row input {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  width: 46px;
  height: 27px;
  border-radius: 999px;
  background: var(--line);
  position: relative;
  transition: background .2s;
  margin: 0;
  cursor: pointer;
}
.switch-row input::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 21px; height: 21px;
  border-radius: 50%;
  background: #fff;
  transition: transform .2s;
}
.switch-row input:checked { background: var(--accent); }
.switch-row input:checked::after { transform: translateX(19px); }

.hint { font-size: 11.5px; color: var(--dim); line-height: 1.65; margin: 6px 0; }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }

/* ---------------------------------------------------------------- 布局 */
main { max-width: 560px; margin: 0 auto; padding: 14px 14px 8px; }
.view { display: none; }
.view.active { display: block; animation: fade .18s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

.card {
  background: linear-gradient(180deg, var(--card-hi), var(--card));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 10px 24px -18px #000;
}

.card-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12.5px;
  color: var(--muted);
  letter-spacing: .04em;
  margin-bottom: 10px;
}

.card-title b { color: var(--text); font-size: 13.5px; font-weight: 600; letter-spacing: 0; }

/* ---------------------------------------------------------------- 仓位 */
.regime-line { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; }

.regime-pos {
  font-size: 46px;
  font-weight: 720;
  line-height: .95;
  letter-spacing: -.03em;
  color: var(--accent);
}
.regime-pos span { font-size: 18px; font-weight: 600; margin-left: 2px; color: var(--muted); }

.regime-label {
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid rgba(61, 220, 151, .25);
  white-space: nowrap;
}

.regime-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin: 14px 0 12px;
}
.regime-bar i {
  height: 6px;
  border-radius: 4px;
  background: var(--line);
}
.regime-bar i.on { background: var(--accent); box-shadow: 0 0 8px rgba(61, 220, 151, .5); }
.regime-bar i.hot { background: var(--warn); }

.reasons { margin: 0; padding: 0; list-style: none; }
.reasons li {
  position: relative;
  padding-left: 14px;
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 4px;
}
.reasons li::before {
  content: "";
  position: absolute;
  left: 2px; top: 8px;
  width: 4px; height: 4px;
  border-radius: 50%;
  background: var(--dim);
}

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.chip {
  display: flex; align-items: baseline; gap: 6px;
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, .03);
  border: 1px solid var(--line-soft);
  font-size: 12px;
  color: var(--muted);
}
.chip b { font-size: 13px; color: var(--text); font-weight: 600; }

/* ---------------------------------------------------------------- 控件 */
.controls { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) auto; gap: 8px; margin-bottom: 12px; }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label { font-size: 11px; color: var(--dim); padding-left: 2px; }

input, select, button { font-family: inherit; font-size: 15px; }

.field input, .field select {
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  outline: none;
}
.field input:focus, .field select:focus { border-color: var(--accent); }

.btn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .06s ease, background .15s;
}
.btn:active { transform: scale(.97); }
.btn-primary {
  background: linear-gradient(180deg, #45e6a2, #2ec98a);
  border-color: transparent;
  color: #052016;
}
.btn-ghost { background: transparent; color: var(--muted); }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; pointer-events: none; }

/* ---------------------------------------------------------------- 个股 */
.stock {
  border: 1px solid var(--line-soft);
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 8px;
  background: rgba(255, 255, 255, .015);
}
.stock:last-child { margin-bottom: 0; }

.stock-top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.stock-top > div:first-child { min-width: 0; }
.stock-name { font-weight: 620; font-size: 15.5px; overflow-wrap: anywhere; }
.stock-name em { font-style: normal; font-size: 11px; color: var(--dim); margin-left: 6px; font-weight: 400; }
.stock-meta { font-size: 11.5px; color: var(--dim); margin-top: 3px; }

.stock-right { text-align: right; white-space: nowrap; }
.stock-price { font-size: 16px; font-weight: 620; }
.stock-chg { font-size: 12px; }

.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--muted); }

.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.tag {
  font-size: 11.5px;
  padding: 3px 8px;
  border-radius: 7px;
  background: rgba(255, 255, 255, .04);
  color: var(--muted);
  border: 1px solid var(--line-soft);
}
.tag.hl { color: var(--accent); border-color: rgba(61, 220, 151, .3); background: var(--accent-dim); }

.score { display: flex; align-items: center; gap: 8px; margin-top: 9px; }
.score-bar { flex: 1; height: 4px; border-radius: 3px; background: var(--line); overflow: hidden; }
.score-bar i { display: block; height: 100%; border-radius: 3px; background: linear-gradient(90deg, #2ec98a, #7ef0bd); }
.score-num { font-size: 11px; color: var(--dim); min-width: 34px; text-align: right; }

/* ---------------------------------------------------------------- 模拟盘 */
.hero-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hero-item { padding: 4px 0; }
.hero-item span { display: block; font-size: 11.5px; color: var(--dim); }
.hero-item b { font-size: 20px; font-weight: 650; }

.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.metric {
  background: rgba(255, 255, 255, .025);
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  padding: 10px;
}
.metric span { display: block; font-size: 10.5px; color: var(--dim); margin-bottom: 3px; }
.metric b { font-size: 16px; font-weight: 640; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 500; color: var(--dim); font-size: 11.5px; padding: 6px 4px; }
td { padding: 8px 4px; border-top: 1px solid var(--line-soft); }
td.r, th.r { text-align: right; }

.chart { width: 100%; height: 150px; display: block; margin: 6px 0 2px; }
.legend { display: flex; gap: 14px; font-size: 11.5px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 2px; margin-right: 5px; vertical-align: middle; }

/* ---------------------------------------------------------------- 说明 */
.guide h3 {
  font-size: 14.5px;
  margin: 18px 0 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.guide h3::before {
  content: "";
  width: 3px; height: 14px;
  border-radius: 2px;
  background: var(--accent);
}
.guide p, .guide li { font-size: 13px; color: var(--muted); line-height: 1.72; }
.guide ul, .guide ol { padding-left: 18px; margin: 6px 0; }
.guide strong { color: var(--text); font-weight: 620; }
.guide .warnbox {
  border-left: 3px solid var(--warn);
  background: rgba(240, 181, 66, .07);
  padding: 10px 12px;
  border-radius: 0 10px 10px 0;
  font-size: 12.5px;
  color: #d9c9a6;
}
.guide code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  background: rgba(255, 255, 255, .05);
  padding: 1px 5px;
  border-radius: 5px;
}

.empty { text-align: center; color: var(--dim); font-size: 12.5px; padding: 18px 0; }

.notice {
  border-left: 3px solid var(--warn);
  background: rgba(240, 181, 66, .08);
  color: #d8c9a8;
  font-size: 12.5px;
  line-height: 1.65;
  padding: 10px 12px;
  border-radius: 0 10px 10px 0;
  margin-bottom: 10px;
}

/* ---------------------------------------------------------------- 底栏 */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: rgba(10, 15, 21, .92);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--line-soft);
}
.tabbar button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: none;
  border: 0;
  color: var(--dim);
  font-size: 10.5px;
  padding: 4px 0;
  cursor: pointer;
}
.tabbar button svg { width: 21px; height: 21px; stroke: currentColor; fill: none; stroke-width: 1.7; }
.tabbar button.active { color: var(--accent); }

/* ---------------------------------------------------------------- 提示 */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(92px + env(safe-area-inset-bottom));
  transform: translate(-50%, 10px);
  background: #1d2836;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: all .2s ease;
  z-index: 40;
  max-width: 86vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  padding: 22px 0;
}
.spinner {
  width: 14px; height: 14px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f9; --bg-soft: #fff; --card: #fff; --card-hi: #fff;
    --line: #e2e8f0; --line-soft: #eef1f5;
    --text: #101720; --muted: #55637a; --dim: #8391a5;
  }
  .topbar, .tabbar { background: rgba(244, 246, 249, .9); }
  .stock { background: rgba(0, 0, 0, .012); }
  .chip { background: rgba(0, 0, 0, .02); }
  .metric { background: rgba(0, 0, 0, .02); }
}

/* mobile edition: 4 tabs */
.tabbar.three { grid-template-columns: repeat(3, 1fr); }

/* 持仓录入用的多行输入 */
textarea {
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  outline: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 14px;
  line-height: 1.65;
  resize: vertical;
}
textarea:focus { border-color: var(--accent); }

.tag.warn {
  color: var(--warn);
  border-color: rgba(240, 181, 66, .35);
  background: rgba(240, 181, 66, .1);
}
.tag.bad {
  color: var(--up);
  border-color: rgba(255, 82, 105, .35);
  background: rgba(255, 82, 105, .1);
}

.advice-line {
  font-size: 13px;
  line-height: 1.6;
  padding: 9px 0;
  border-bottom: 1px solid var(--line-soft);
}
.advice-line:last-child { border-bottom: 0; }
