/* 合订本: modern cards — soft grey ground, white rounded cards with a light shadow, indigo accent; red/black lists
   keep their own colours. Phones (≤ 820px): a bottom tab bar, the brand and the search on one top row, tables that
   fold the company and the sector under the ticker. */
:root {
  --bg: #f3f4f8; --card: #ffffff; --ink: #0f172a; --muted: #64748b; --line: #e6e8ef; --grid: #eef0f5;
  --soft: #f6f7fb; --accent: #4f46e5; --accent-soft: #eef2ff; --red: #e11d48; --black: #1e293b; --warn: #b45309;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 6px 24px rgba(15, 23, 42, .06);
  --c1: #4f46e5; --c2: #ea580c; --c3: #059669; --c4: #9333ea; --c5: #e11d48; --c6: #0891b2; --c7: #ca8a04; --c8: #64748b;
  --radius: 16px; --tabbar: 0px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0d14; --card: #151823; --ink: #e5e7eb; --muted: #94a3b8; --line: #262a37; --grid: #20242f;
    --soft: #1b1f2c; --accent: #818cf8; --accent-soft: #23264a; --red: #fb7185; --black: #cbd5e1; --warn: #f59e0b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 28px rgba(0, 0, 0, .35);
    --c1: #818cf8; --c2: #fb923c; --c3: #34d399; --c4: #c084fc; --c5: #fb7185; --c6: #22d3ee; --c7: #facc15; --c8: #94a3b8;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased;
  font: 14px/1.55 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 26px; font-weight: 800; letter-spacing: -.01em; margin: 6px 0 18px; }
h1 small, h2 small, h3 small { color: var(--muted); font-weight: normal; font-size: 13px; margin-left: 6px; letter-spacing: 0; }
h2 { font-size: 16px; font-weight: 700; margin: 0 0 12px; }
h3 { font-size: 13px; margin: 14px 0 6px; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
.warn { color: var(--warn); }
.red { color: var(--red); }
.black { color: var(--black); }

/* top bar */
header.top { display: flex; align-items: center; gap: 18px; padding: 10px 28px; position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--card) 85%, transparent); backdrop-filter: saturate(1.6) blur(12px);
  -webkit-backdrop-filter: saturate(1.6) blur(12px); border-bottom: 1px solid var(--line); }
.brand { font-weight: 800; font-size: 19px; letter-spacing: .02em; white-space: nowrap;
  background: linear-gradient(90deg, #4f46e5, #db2777); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand:hover { text-decoration: none; }
nav { display: flex; gap: 4px; }
nav a { display: flex; align-items: center; gap: 6px; padding: 6px 14px; border-radius: 999px; color: var(--muted); white-space: nowrap; }
nav a:hover { color: var(--ink); background: var(--soft); text-decoration: none; }
nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
nav svg { width: 18px; height: 18px; display: none; }
header .search { margin-left: auto; }
input, select, button { font: inherit; color: inherit; }
input, select { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 7px 12px; outline: none;
  transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
header .search input { width: 240px; background: var(--soft); border-color: transparent; border-radius: 999px; padding-left: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='7' cy='7' r='5'/%3E%3Cpath d='m11 11 3.5 3.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 12px center; }
header .search input:focus { background-color: var(--card); }
button { background: var(--accent); color: #fff; border: 0; border-radius: 10px; padding: 7px 16px; cursor: pointer; font-weight: 500;
  transition: filter .15s; }
button:hover { filter: brightness(1.08); }
button.link { background: none; color: var(--muted); padding: 4px; font-weight: normal; }
.who { color: var(--muted); font-size: 13px; white-space: nowrap; }
.logout { margin: 0; }
main { max-width: 1400px; margin: 0 auto; padding: 22px 28px 40px; }
footer { text-align: center; color: var(--muted); font-size: 12px; padding: 20px 20px calc(20px + var(--tabbar)); }

/* cards */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 18px;
  min-width: 0; }
.card-head { display: flex; align-items: center; gap: 10px 12px; flex-wrap: wrap; margin-bottom: 10px; }
.card-head h2 { margin: 0; margin-right: auto; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(520px, 100%), 1fr)); gap: 18px; }
.grid2 > * { min-width: 0; }
.grid2 > .card { margin-bottom: 0; }
.grid2 + .card, .grid2 + .grid2 { margin-top: 18px; }
.empty { color: var(--muted); padding: 10px 0; }

/* tables */
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; border-bottom: 1px solid var(--line);
  padding: 6px 8px; position: sticky; top: 0; background: var(--card); z-index: 1;
  white-space: nowrap; }
table.list td { padding: 7px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.list tbody tr { transition: background .12s; }
table.list tbody tr:hover td { background: var(--soft); }
table.list tr:last-child td { border-bottom: 0; }
table.list .r { text-align: right; font-variant-numeric: tabular-nums; }
table.list .n { color: var(--muted); font-variant-numeric: tabular-nums; }
table.list .sub { display: none; }
tr.nolend td { opacity: .55; }
.tag { font-size: 11px; border: 1px solid var(--warn); color: var(--warn); border-radius: 6px; padding: 0 5px; }
.scroll { max-height: 560px; overflow: auto; }
.scroll.short { max-height: 340px; }
.filter { width: 100%; max-width: 360px; margin-bottom: 12px; }
.bar { display: inline-block; height: 6px; width: calc(var(--w) * 0.6px); border-radius: 3px; margin-right: 8px; vertical-align: middle;
  background: linear-gradient(90deg, var(--accent), #db2777); opacity: .55; }
h2.red, h2.black { display: flex; align-items: center; gap: 8px; }
h2.red::before, h2.black::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

.logo { display: inline-flex; width: 24px; height: 24px; border-radius: 7px; background: #fff; border: 1px solid var(--line);
  align-items: center; justify-content: center; vertical-align: middle; margin-right: 8px; overflow: hidden; flex: none; }
.logo img { width: 20px; height: 20px; object-fit: contain; }
.logo.none { color: #888; font-size: 11px; font-weight: 600; }
.logo.big { width: 52px; height: 52px; border-radius: 14px; box-shadow: var(--shadow); border: 0; }
.logo.big img { width: 42px; height: 42px; }

/* a stock's head and its rank */
.stock-head { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.stock-head > div:not(.rank-badge) { min-width: 0; flex: 1 1 300px; }
.stock-head h1 { margin: 0; }
.stock-head p { margin: 4px 0 0; overflow-wrap: anywhere; }
.rank-badge { display: flex; gap: 12px; align-items: center; background: var(--card); border-radius: 14px; box-shadow: var(--shadow);
  padding: 10px 18px; font-size: 12px; color: var(--muted); }
.rank-badge .pts { font-size: 30px; font-weight: 800; color: var(--ink); font-variant-numeric: tabular-nums; }
.rank-badge.red { box-shadow: var(--shadow), inset 0 0 0 1.5px var(--red); }
.rank-badge.red .pts { color: var(--red); }
.rank-badge.black { box-shadow: var(--shadow), inset 0 0 0 1.5px var(--black); }

.radar-body { display: flex; justify-content: center; }
.radar { width: 100%; max-width: 420px; height: auto; overflow: visible; }
.radar .ring { fill: none; stroke: var(--line); stroke-width: 1; }
.radar .ring.mid { stroke: var(--muted); stroke-dasharray: 4 3; }
.radar .spoke { stroke: var(--line); stroke-width: 1; }
.radar .shape { fill: var(--accent); fill-opacity: .2; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.radar text { font-size: 12px; fill: var(--ink); }
.radar text .up { fill: var(--red); font-weight: 700; }
.radar text .down { fill: var(--muted); font-weight: 700; }

/* controls and charts */
.btns { display: inline-flex; background: var(--soft); border-radius: 10px; padding: 3px; gap: 2px; }
.btns button { background: none; color: var(--muted); border-radius: 8px; padding: 4px 11px; font-weight: 500; }
.btns button.on { background: var(--card); color: var(--accent); box-shadow: 0 1px 3px rgba(15, 23, 42, .12); }
.chk { color: var(--muted); font-size: 13px; display: inline-flex; gap: 4px; align-items: center; }
.chart { width: 100%; min-height: 120px; }
.chart.nodata { min-height: 0; }
.note { color: var(--muted); font-size: 12px; margin: 6px 0 0; }
.ohlc { display: flex; flex-wrap: wrap; gap: 2px 12px; font-size: 12px; color: var(--muted); min-height: 18px; margin: 0 0 4px;
  font-variant-numeric: tabular-nums; }
.ohlc[hidden] { display: none; }
.ohlc b { color: var(--ink); font-weight: 600; }
.ohlc span { color: var(--ink); }
.ohlc .up { color: var(--red); }
.ohlc .down { color: var(--c3); }
.uplot { font-family: inherit; }
.u-legend { font-size: 12px; color: var(--ink); }
.u-select { background: rgba(127, 127, 127, .15); }

.bigsearch { display: flex; gap: 8px; margin-bottom: 18px; }
.bigsearch input { flex: 1; max-width: 520px; font-size: 16px; padding: 10px 14px; }

.macro { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 18px; align-items: start; }
.macro aside { position: sticky; top: 76px; max-height: calc(100vh - 96px); display: flex; flex-direction: column; }
.series-list { overflow: auto; }
.series-list a { display: flex; justify-content: space-between; gap: 8px; padding: 5px 8px; border-radius: 8px; color: var(--ink); font-size: 13px; }
.series-list a:hover { background: var(--soft); text-decoration: none; }
.series-list a.on { background: var(--accent); color: #fff; }
.series-list a.on .muted { color: #e0e7ff; }
.grow { min-width: 0; }

/* sign-in and sign-up */
body.login { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 16px;
  background: radial-gradient(1200px 600px at 20% -10%, color-mix(in srgb, var(--accent) 18%, transparent), transparent),
              radial-gradient(900px 500px at 110% 110%, color-mix(in srgb, #db2777 14%, transparent), transparent), var(--bg); }
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px; padding: 28px; }
.login-card h1 { margin: 0 0 4px; text-align: center; background: linear-gradient(90deg, #4f46e5, #db2777);
  -webkit-background-clip: text; background-clip: text; color: transparent; }
.login-card label { display: flex; flex-direction: column; gap: 5px; color: var(--muted); font-size: 13px; }
.login-card button { padding: 10px; }
.error { color: var(--red); margin: 0; }

.flash { padding: 10px 14px; border-radius: 12px; margin: 0 0 16px; }
.flash.ok { background: color-mix(in srgb, var(--c3) 15%, transparent); }
.flash.bad { background: color-mix(in srgb, var(--red) 15%, transparent); color: var(--red); }
.card.narrow { max-width: 440px; }
form.stack { display: flex; flex-direction: column; gap: 12px; }
form.stack label { display: flex; flex-direction: column; gap: 5px; color: var(--muted); font-size: 13px; }
form.stack button { align-self: flex-start; }
form.inline { display: inline-flex; gap: 6px; align-items: center; margin: 0; }
form.inline input { width: 120px; padding: 4px 8px; }
form.inline select { padding: 4px 6px; }
form.inline button { padding: 4px 10px; }
button.ghost { background: none; color: var(--accent); border: 1px solid var(--line); }
button.danger { background: none; color: var(--red); border: 1px solid var(--line); }

/* 个股筛选 */
.screen { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 18px; align-items: start; }
.screen-panel { position: sticky; top: 76px; max-height: calc(100vh - 96px); overflow: auto; padding: 14px 16px; }
.screen-panel summary { font-weight: 700; font-size: 16px; cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px; }
.screen-panel summary::-webkit-details-marker { display: none; }
.screen-panel summary::after { content: ''; margin-left: auto; width: 8px; height: 8px; border: solid var(--muted);
  border-width: 0 2px 2px 0; transform: rotate(45deg); transition: transform .15s; }
.screen-panel[open] summary::after { transform: rotate(-135deg); }
.screen-panel .count { background: var(--accent); color: #fff; border-radius: 999px; font-size: 11px; padding: 0 7px; line-height: 18px; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 4px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 4px 11px; border-radius: 999px; background: var(--soft);
  color: var(--ink); font-size: 13px; cursor: pointer; border: 1px solid transparent; user-select: none; }
a.chip:hover { text-decoration: none; border-color: var(--accent); color: var(--accent); }
.chip input { display: none; }
.chip:has(input:checked) { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
#screen-form fieldset { border: 0; border-top: 1px solid var(--line); margin: 12px 0 0; padding: 10px 0 0; }
#screen-form legend { font-size: 12px; color: var(--muted); font-weight: 600; padding: 0 6px 0 0; }
.range { display: grid; grid-template-columns: 82px minmax(0, 1fr) 10px minmax(0, 1fr) 52px; gap: 6px; align-items: center; margin: 6px 0; }
.range > span, .range > em { font-size: 13px; color: var(--muted); font-style: normal; }
.range > em { font-size: 12px; }
.range i { color: var(--muted); font-style: normal; text-align: center; }
.range input { width: 100%; padding: 5px 8px; text-align: right; }
.range select { padding: 5px 6px; font-size: 13px; min-width: 0; }
.pick { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); margin: 6px 0; }
.check { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); margin: 8px 0 2px; }
.form-actions { position: sticky; bottom: -14px; background: var(--card); display: flex; align-items: center; gap: 14px;
  padding: 12px 0 14px; margin-top: 8px; border-top: 1px solid var(--line); }
.form-actions button { flex: 0 0 auto; padding: 8px 22px; }
.clear { color: var(--muted); font-size: 13px; }
.screen-results h2 small { display: inline; }
.screen-table th a { color: inherit; }
.screen-table th.on { color: var(--accent); }
.screen-table td.name { max-width: 240px; overflow: hidden; text-overflow: ellipsis; }
.screen-table td.pos { color: var(--red); }
.screen-table td.neg { color: var(--c3); }
.pill { font-size: 10px; border-radius: 4px; padding: 0 4px; vertical-align: 1px; color: #fff; }
.pill.red { background: var(--red); }
.pill.black { background: var(--black); color: var(--card); }

/* phones */
@media (max-width: 820px) {
  :root { --tabbar: calc(58px + env(safe-area-inset-bottom)); --radius: 14px; }
  /* no backdrop-filter here: it would make the header the containing block of the fixed tab bar */
  header.top { gap: 10px; padding: 8px 14px; padding-top: calc(8px + env(safe-area-inset-top)); background: var(--card);
    backdrop-filter: none; -webkit-backdrop-filter: none; }
  .brand { font-size: 18px; }
  header .search { flex: 1; min-width: 0; }
  header .search input { width: 100%; font-size: 16px; padding-top: 6px; padding-bottom: 6px; }   /* 16px: iOS does not zoom */
  .who { max-width: 72px; overflow: hidden; text-overflow: ellipsis; }
  nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; gap: 0; justify-content: space-around;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--card) 90%, transparent); backdrop-filter: saturate(1.6) blur(14px);
    -webkit-backdrop-filter: saturate(1.6) blur(14px); border-top: 1px solid var(--line); }
  nav a { flex: 1; flex-direction: column; gap: 2px; padding: 4px 0; border-radius: 10px; font-size: 11px; }
  nav a.on { background: none; }
  nav svg { display: block; }
  main { padding: 14px 12px 24px; }
  h1 { font-size: 22px; margin: 2px 0 14px; }
  h1 small { display: block; margin: 4px 0 0; }
  .card { padding: 14px; margin-bottom: 14px; }
  .card { overflow-x: auto; }
  .grid2 { gap: 14px; }
  .grid2 + .card, .grid2 + .grid2 { margin-top: 14px; }
  input, select { font-size: 16px; }
  .filter { max-width: none; }
  /* tables fold: the company and the sector go under the ticker */
  table.list .wide { display: none; }
  table.list .sub { display: block; font-size: 12px; color: var(--muted); white-space: normal; line-height: 1.35; margin-top: 1px; }
  table.list td.sym { white-space: normal; }
  td.sym .row { display: flex; align-items: center; }
  table.list td { padding: 8px 6px; }
  /* a stock's head */
  .stock-head { gap: 12px; }
  .stock-head > div:not(.rank-badge) { flex-basis: 0; }
  .stock-head h1 { font-size: 24px; }
  .stock-head h1 small { display: inline; }
  .stock-head p { font-size: 12px; }
  .rank-badge { flex: 1 1 100%; }
  .radar { max-width: none; }
  .radar text { font-size: 16px; }          /* viewBox units: about 12px on a phone */
  .card-head .btns { overflow-x: auto; max-width: 100%; }
  .macro { grid-template-columns: minmax(0, 1fr); }
  .macro aside { position: static; max-height: 320px; }
  .screen { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .screen-panel { position: static; max-height: none; overflow: visible; }
  .range { grid-template-columns: 76px minmax(0, 1fr) 10px minmax(0, 1fr) 48px; }
  .form-actions { bottom: var(--tabbar); margin: 8px -14px -14px; padding: 12px 14px; border-radius: 0 0 var(--radius) var(--radius); }
  .screen-results h2 small { display: block; margin: 4px 0 0; }
}
