:root {
  --bg: #0d1117;
  --card: #161b22;
  --card-border: #21262d;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --red: #f85149;
  --red-soft: rgba(248, 81, 73, .12);
  --green: #3fb950;
  --green-soft: rgba(63, 185, 80, .14);
  --yellow: #d29922;
  --yellow-text: #e3b341;
  --gold: #ffd580;
  --accent: #58a6ff;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Segoe UI",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 12px calc(20px + env(safe-area-inset-bottom));
}

/* ---------- header ---------- */
header { position: sticky; top: 0; z-index: 10; background: var(--bg); padding: 4px 0 8px; }
.title-row { display: flex; align-items: center; justify-content: space-between; }
h1 { font-size: 20px; font-weight: 700; letter-spacing: .5px; }

.pager { display: flex; align-items: center; gap: 8px; }
#page-ind { font-size: 13px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.page-btn {
  width: 30px; height: 30px; border-radius: 8px;
  border: 1px solid var(--card-border); background: var(--card);
  color: var(--text); font-size: 18px; line-height: 1; cursor: pointer;
}
.page-btn:disabled { opacity: .3; }
.page-btn:active { background: var(--card-border); }

/* tabs */
.tabs { display: flex; gap: 6px; margin-top: 8px; }
.tab {
  flex: 0 0 auto; padding: 4px 18px; border-radius: 14px; font-size: 13px;
  background: transparent; border: 1px solid var(--card-border); color: var(--text-dim);
}
.tab.active { background: var(--card); color: var(--text); border-color: #30363d; font-weight: 600; }
.tab-me { margin-left: auto; }
.tab-me.logged { color: var(--gold); border-color: rgba(255,213,128,.35); }
.cal-badge { font-size: 11px; color: var(--gold); margin-left: 2px; }

/* 账户弹层 */
.a-title { font-size: 16px; font-weight: 700; margin: 4px 0 14px; }
.a-user { font-size: 15px; padding: 10px 12px; background: var(--bg);
  border: 1px solid var(--card-border); border-radius: 10px; }
.a-hint { font-size: 12px; color: var(--text-dim); margin: 10px 0 16px; line-height: 1.6; }
.a-input {
  width: 100%; background: var(--bg); border: 1px solid var(--card-border);
  border-radius: 10px; padding: 11px 14px; color: var(--text); font-size: 14px;
  outline: none; margin-bottom: 10px;
}
.a-input:focus { border-color: rgba(88,166,255,.5); }
.a-btn {
  width: 100%; padding: 12px; border: none; border-radius: 10px; cursor: pointer;
  background: linear-gradient(135deg, #58a6ff, #1f6feb); color: #fff;
  font-size: 15px; font-weight: 600; margin-top: 4px;
}
.a-btn:active { opacity: .85; }
.a-error {
  background: var(--red-soft); color: var(--red); font-size: 13px;
  border-radius: 8px; padding: 8px 12px; margin-top: 10px; text-align: center;
}
.a-switch {
  display: block; width: 100%; background: none; border: none;
  color: var(--accent); font-size: 13px; padding: 14px; cursor: pointer;
}

.sub-row {
  display: flex; justify-content: space-between; align-items: center;
  color: var(--text-dim); font-size: 12px; margin-top: 8px;
}
.sort-btn {
  background: none; border: none; color: var(--text-dim); font-size: 12px;
  cursor: pointer; padding: 2px 4px;
}

/* 搜索框 */
.search-row { margin-top: 10px; }
.search-box {
  position: relative; display: flex; align-items: center;
  background: var(--card); border: 1px solid var(--card-border);
  border-radius: 22px; padding: 0 6px 0 14px;
  transition: border-color .2s, box-shadow .2s;
}
.search-box:focus-within {
  border-color: rgba(88, 166, 255, .55);
  box-shadow: 0 0 0 3px rgba(88, 166, 255, .12);
}
.search-ico { color: var(--text-dim); flex: 0 0 auto; }
.search-box input[type="search"] {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text); font-size: 14px; padding: 9px 10px;
  -webkit-appearance: none;
}
.search-box input[type="search"]::placeholder { color: #62707d; }
.search-box input[type="search"]::-webkit-search-cancel-button { display: none; }
.search-box button {
  background: #21262d; border: none; color: var(--text-dim);
  border-radius: 50%; width: 24px; height: 24px; font-size: 12px;
  cursor: pointer; flex: 0 0 auto; line-height: 1;
}
.search-box button:active { color: var(--text); }

/* 收藏星标 */
.fav-btn {
  display: block; margin-left: auto; margin-top: 2px;
  background: none; border: none; font-size: 20px; line-height: 1;
  color: #3d4753; cursor: pointer; padding: 4px 2px;
  transition: color .15s, transform .15s;
}
.fav-btn.on { color: var(--gold); text-shadow: 0 0 8px rgba(255, 213, 128, .45); }
.fav-btn:active { transform: scale(1.3); }
.fav-btn.big { font-size: 24px; margin: 0; }
.d-right { display: flex; align-items: flex-start; gap: 6px; }

/* filter chips */
.filter-chips {
  display: flex; gap: 6px; overflow-x: auto; margin-top: 6px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.filter-chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; font-size: 12px; padding: 2px 12px; border-radius: 12px;
  background: var(--card); border: 1px solid var(--card-border); color: var(--text-dim);
}
.chip.on { background: #30363d; color: var(--text); font-weight: 600; }

.thead {
  display: grid; grid-template-columns: 1fr 88px 96px 96px;
  color: var(--text-dim); font-size: 11px; padding: 8px 12px 4px;
}
.thead span:nth-child(2), .thead span:nth-child(3), .thead span:nth-child(4) { text-align: right; }

/* ---------- cards ---------- */
#cards { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 12px;
  animation: fadein .25s ease;
  cursor: pointer;
}
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

.card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.stock-name { font-size: 16px; font-weight: 700; }

.tag-line { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.tag {
  font-size: 11px; padding: 1px 8px; border-radius: 10px;
  background: #21262d; color: var(--text-dim); white-space: nowrap;
}
.tag.event { background: var(--red-soft); color: var(--red); }
.tag.etf { background: rgba(255,213,128,.14); color: var(--gold); }
.tag.g-up { background: var(--red-soft); color: var(--red); }
.tag.g-down { background: var(--green-soft); color: var(--green); }

.badge-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; min-height: 0; }
.badge-row:not(:empty) { min-height: 20px; }
.badge { font-size: 11px; padding: 1px 8px; border-radius: 10px; font-weight: 600; }
.b-buy { background: rgba(255, 213, 128, .15); color: var(--gold); }
.b-new { background: var(--red-soft); color: var(--red); }
.b-spec { background: rgba(210, 153, 34, .18); color: var(--yellow-text); }

.price-block { text-align: right; white-space: nowrap; }
.price { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.change { font-size: 12px; font-variant-numeric: tabular-nums; }
.up { color: var(--red); }
.down { color: var(--green); }
.flat { color: var(--text-dim); }

.mid { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; margin-top: 10px; align-items: center; }
.boll-line { display: flex; gap: 5px; align-items: center; }
.boll-line .lbl { font-size: 11px; color: var(--text-dim); }
.boll-tag { font-size: 11px; padding: 1px 7px; border-radius: 6px; font-weight: 600; }
.boll-tag.p-down  { background: var(--green-soft); color: var(--green); }
.boll-tag.p-low   { background: rgba(63,185,80,.08); color: #7ee787; }
.boll-tag.p-mid   { background: #21262d; color: var(--text-dim); }
.boll-tag.p-high  { background: rgba(210,153,34,.15); color: var(--yellow-text); }
.boll-tag.p-up    { background: var(--red-soft); color: var(--red); }

.rly-block { text-align: right; }
.rly { font-size: 22px; font-weight: 800; color: var(--red); font-variant-numeric: tabular-nums; }
.rly small { font-size: 12px; font-weight: 600; }
.static-yield { font-size: 11px; color: var(--text-dim); font-variant-numeric: tabular-nums; }

.pct-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.pct-num { font-size: 14px; font-weight: 700; min-width: 38px; text-align: right; font-variant-numeric: tabular-nums; }
.pct-label { font-size: 11px; white-space: nowrap; }
.pct-label.hi { color: var(--red); }
.pct-label.mid { color: var(--yellow-text); }
.pct-label.lo { color: var(--green); }

.bar { flex: 1; height: 6px; border-radius: 3px; background: #21262d; overflow: hidden; position: relative; }
.bar i {
  position: absolute; left: 0; top: 0; bottom: 0; border-radius: 3px;
  background: linear-gradient(90deg, #7ee787, var(--yellow) 55%, var(--red));
}
.bar b { position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: #30363d; }

.p10-ref {
  font-size: 10px; color: var(--text-dim); text-align: right; margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

.zone-row {
  margin-top: 9px; padding-top: 8px; border-top: 1px dashed #21262d;
  display: flex; justify-content: space-between; align-items: center;
  font-size: 12px; color: var(--text-dim);
}
.zone-row .z-title { font-size: 11px; }
.zone-values { display: flex; gap: 4px; font-variant-numeric: tabular-nums; }
.zone-values span b { color: var(--text); font-weight: 600; }
.zone-values span i { font-style: normal; color: var(--accent); font-size: 11px; }
.zsep { color: #30363d; font-style: normal; }

/* ---------- 日历 ---------- */
.cal-date { font-size: 12px; color: var(--gold); margin: 14px 2px 6px; font-weight: 600; }
.cal-date:first-child { margin-top: 4px; }
.cal-item { display: flex; justify-content: space-between; align-items: center; }
.cal-main b { font-size: 14px; margin-right: 6px; }
.cal-sub { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.cal-right { text-align: right; }
.cal-dps { font-size: 13px; color: var(--gold); font-weight: 600; }
.cal-yld { font-size: 11px; color: var(--text-dim); }

/* ---------- 排序菜单 ---------- */
.mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 40;
}
.sort-menu {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: max(20px, env(safe-area-inset-bottom));
  width: min(340px, calc(100vw - 32px)); background: var(--card);
  border: 1px solid var(--card-border); border-radius: 14px; z-index: 50;
  padding: 8px; display: flex; flex-direction: column;
}
.sort-title { text-align: center; font-size: 12px; color: var(--text-dim); padding: 6px; }
.sort-menu button {
  background: none; border: none; color: var(--text); font-size: 14px;
  padding: 11px; border-radius: 8px; cursor: pointer;
}
.sort-menu button:active { background: #21262d; }
.sort-menu .cancel { color: var(--text-dim); border-top: 1px solid var(--card-border); margin-top: 4px; }

/* ---------- 详情抽屉 ---------- */
.sheet {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: 0; width: min(480px, 100vw); max-height: 88vh; overflow-y: auto;
  background: var(--card); border-radius: 16px 16px 0 0; z-index: 50;
  padding: 0 16px calc(24px + env(safe-area-inset-bottom));
  -webkit-overflow-scrolling: touch;
}
.sheet-bar {
  position: sticky; top: 0; height: 28px; display: flex; align-items: center;
  justify-content: center; cursor: pointer; background: var(--card); z-index: 2;
}
.sheet-bar::before {
  content: ""; width: 36px; height: 4px; border-radius: 2px; background: #30363d;
}
.d-head { display: flex; justify-content: space-between; align-items: flex-start; }
.d-name { font-size: 18px; font-weight: 700; }
.d-code { font-size: 12px; color: var(--text-dim); font-weight: 400; }
.d-sec-title {
  font-size: 12px; color: var(--text-dim); margin: 16px 0 8px; font-weight: 600;
  display: flex; justify-content: space-between; align-items: center;
}
.range-chips { display: flex; gap: 4px; }
.range-chips button {
  font-size: 11px; padding: 2px 9px; border-radius: 10px; cursor: pointer;
  background: var(--bg); border: 1px solid var(--card-border); color: var(--text-dim);
}
.range-chips button.on {
  background: #30363d; color: var(--text); border-color: #3d4753; font-weight: 600;
}
#yield-chart { width: 100%; height: 170px; display: block; }
#price-chart { width: 100%; height: 200px; display: block; touch-action: none; }
#price-chart.pending {
  background:
    linear-gradient(90deg, transparent 0, rgba(139,148,158,.07) 50%, transparent 100%) 0 45%/60% 10px no-repeat,
    var(--bg);
  border-radius: 8px;
  animation: shimmer 1.2s infinite;
}
@keyframes shimmer { 50% { opacity: .55; } }

/* 评分 */
.d-score {
  display: flex; gap: 14px; align-items: center; margin-top: 12px;
  background: var(--bg); border: 1px solid var(--card-border); border-radius: 10px; padding: 10px 14px;
}
.d-score.strong { border-color: rgba(255,213,128,.4); }
.d-score-num { font-size: 30px; font-weight: 800; color: var(--text-dim); min-width: 62px; text-align: center; }
.d-score.strong .d-score-num { color: var(--gold); }
.d-score-num small { font-size: 13px; color: var(--text-dim); font-weight: 600; }
.d-score-num.g-gold { color: var(--gold); }
.d-score-num.g-good { color: #7ee787; }
.d-score-num.g-mid { color: var(--yellow-text); }
.d-score-num.g-low { color: var(--text-dim); }
.d-score-sub { font-size: 10px; color: var(--text-dim); font-weight: 400; margin-top: 2px; }
.d-score-rows { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.sc-row { font-size: 12px; color: var(--text-dim); display: flex; justify-content: space-between; }
.sc-row.on { color: var(--text); }
.sc-val { font-variant-numeric: tabular-nums; }
.sc-val i { font-style: normal; font-size: 9px; color: #59636f; }

/* BOLL 轨道 */
.boll-track { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.bt-lbl { font-size: 12px; color: var(--text-dim); width: 16px; }
.bt-rail { flex: 1; height: 8px; border-radius: 4px; background: #21262d; position: relative; }
.bt-rail i { position: absolute; top: -3px; bottom: -3px; width: 2px; background: #8b949e; }
.bt-rail em {
  position: absolute; top: 50%; width: 12px; height: 12px; border-radius: 50%;
  background: var(--gold); transform: translate(-50%, -50%);
  box-shadow: 0 0 6px rgba(255,213,128,.6);
}
.bt-val { font-size: 12px; color: var(--text); width: 48px; text-align: right; font-variant-numeric: tabular-nums; }

/* kv */
.kv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.kv {
  background: var(--bg); border: 1px solid var(--card-border); border-radius: 8px;
  padding: 8px 10px; display: flex; flex-direction: column; gap: 2px;
}
.kv span { font-size: 11px; color: var(--text-dim); }
.kv b { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }

.an-row {
  display: flex; justify-content: space-between; padding: 7px 2px;
  border-bottom: 1px dashed var(--card-border); font-size: 13px;
}
.an-row span { color: var(--text-dim); }
.an-row:last-child { border-bottom: none; }

/* ---------- 状态呼吸灯 / 汇总条 ---------- */
.dot {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: #4d5866; margin-right: 6px; vertical-align: 1px;
}
.dot.live { background: var(--green); animation: pulse 1.6s infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(63,185,80,.5); }
  70% { box-shadow: 0 0 0 6px rgba(63,185,80,0); }
  100% { box-shadow: 0 0 0 0 rgba(63,185,80,0); }
}

.summary-bar {
  display: flex; align-items: center; gap: 8px; margin-top: 8px;
  background: var(--card); border: 1px solid var(--card-border);
  border-radius: 10px; padding: 7px 12px; font-size: 11.5px; color: var(--text-dim);
  overflow-x: auto; white-space: nowrap; scrollbar-width: none;
}
.summary-bar::-webkit-scrollbar { display: none; }
.summary-bar b { color: var(--text); font-variant-numeric: tabular-nums; }
.summary-bar .sep { flex: 0 0 1px; height: 12px; background: var(--card-border); }

/* ---------- 骨架屏 ---------- */
.skel-card {
  background: var(--card); border: 1px solid var(--card-border);
  border-radius: 12px; padding: 14px; margin-bottom: 10px;
}
.skel-row { display: flex; justify-content: space-between; margin-bottom: 10px; }
.skel-row:last-child { margin-bottom: 0; }
.sk {
  display: inline-block; border-radius: 6px; height: 14px;
  background: linear-gradient(90deg, #1c2129 25%, #262d38 50%, #1c2129 75%);
  background-size: 200% 100%; animation: shimmer 1.3s infinite;
}
.sk-name { width: 90px; } .sk-price { width: 64px; }
.sk-tag { width: 140px; } .sk-pct { width: 56px; } .sk-bar { width: 100%; }

/* ---------- 下拉刷新指示 ---------- */
.pull-indicator {
  text-align: center; font-size: 12px; color: var(--text-dim);
  max-height: 0; overflow: hidden; transition: max-height .2s;
}
.pull-indicator.show { max-height: 30px; padding: 6px 0; }
.pull-indicator.ready { color: var(--accent); }

/* ---------- 底部操作条 ---------- */
.bottom-bar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 0;
  width: min(480px, 100vw); height: calc(48px + env(safe-area-inset-bottom));
  padding: 8px 16px env(safe-area-inset-bottom);
  display: flex; align-items: center; justify-content: center; gap: 14px;
  background: rgba(13, 17, 23, .92); backdrop-filter: blur(12px);
  border-top: 1px solid var(--card-border); z-index: 20;
}
#page-ind2 { font-size: 13px; color: var(--text-dim); min-width: 48px; text-align: center; font-variant-numeric: tabular-nums; }
.top-btn {
  position: absolute; right: 14px; width: 32px; height: 32px; border-radius: 50%;
  background: var(--card); border: 1px solid var(--card-border); color: var(--text-dim);
  font-size: 16px; cursor: pointer; opacity: 0; pointer-events: none; transition: opacity .2s;
}
.top-btn.show { opacity: 1; pointer-events: auto; }

#app { padding-bottom: calc(70px + env(safe-area-inset-bottom)); }

/* ---------- 价格变动闪烁 ---------- */
@keyframes flashUp { 0% { background: rgba(248,81,73,.22); } 100% { background: var(--card); } }
@keyframes flashDown { 0% { background: rgba(63,185,80,.20); } 100% { background: var(--card); } }
.card.flash-up { animation: flashUp 1.6s ease-out; }
.card.flash-down { animation: flashDown 1.6s ease-out; }

/* ---------- chips 折叠 ---------- */
.filter-chips.wrapped { flex-wrap: wrap; overflow: visible; }
.chip.more { color: var(--accent); }

/* ---------- 卡片 PE 行 ---------- */
.pe-line { font-size: 11.5px; color: #a5b0bd; font-variant-numeric: tabular-nums; margin-top: 1px; }

/* 术语气泡 toast */
#tip-toast {
  position: fixed; left: 50%; bottom: calc(70px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(360px, calc(100vw - 32px));
  background: rgba(33, 38, 45, .97); border: 1px solid #3d4753;
  color: var(--text); font-size: 12.5px; line-height: 1.55;
  padding: 10px 14px; border-radius: 10px; z-index: 60;
  opacity: 0; pointer-events: none; transition: opacity .2s, bottom .2s;
  box-shadow: 0 4px 18px rgba(0,0,0,.5);
}
#tip-toast.show { opacity: 1; }

/* 可点击解释的术语 */
.q { cursor: pointer; }
.q:active { opacity: .6; }
.boll-line .lbl.q { color: var(--text-dim); }

/* 综合评分胶囊 */
.score-pill {
  font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 8px;
  border: none; cursor: pointer; margin-right: 6px; font-variant-numeric: tabular-nums;
}
.score-pill.s-gold { background: rgba(255,213,128,.18); color: var(--gold); }
.score-pill.s-good { background: rgba(126,231,135,.15); color: #7ee787; }
.score-pill.s-mid  { background: rgba(210,153,34,.16); color: var(--yellow-text); }
.score-pill.s-low  { background: #21262d; color: var(--text-dim); }
.cal-grp {
  font-size: 12px; font-weight: 700; margin: 16px 2px 6px;
  color: var(--text-dim); border-left: 3px solid #3d4753; padding-left: 8px;
}
.cal-grp.g-this { color: var(--gold); border-color: var(--gold); }
.cal-grp.g-next { color: var(--accent); border-color: var(--accent); }
.cal-soon {
  font-size: 10px; background: var(--red-soft); color: var(--red);
  border-radius: 8px; padding: 0 6px; margin-left: 4px;
}

/* footer 上移避开底部条 */
footer { margin-bottom: 4px; }
.loading { text-align: center; color: var(--text-dim); padding: 40px 0; font-size: 13px; }
.hidden { display: none !important; }

footer {
  margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--card-border);
  display: flex; justify-content: space-between;
  color: var(--text-dim); font-size: 11px;
}
#market-status.live { color: var(--green); }
